Implemented new name mangle algorithm
This commit is contained in:
parent
d728493cff
commit
40317d6cfe
@ -16,6 +16,15 @@ v0.35.06
|
|||||||
Added better support for 8.3 and long filenames by creating
|
Added better support for 8.3 and long filenames by creating
|
||||||
hard links in the download directories.
|
hard links in the download directories.
|
||||||
|
|
||||||
|
common.a:
|
||||||
|
Changed the LFN name mangle functions to prevent 8.3 name
|
||||||
|
collisions. Now the basepart is 4 characters followed by the
|
||||||
|
tilde char and then a 3 characters code calculated from the
|
||||||
|
16 bits crc of the original filename. Original this was base 5
|
||||||
|
followed by a tilde and 2 characters code calculated from the
|
||||||
|
checksum of the string modulo 1849. Both methods are different
|
||||||
|
then what MS does.
|
||||||
|
|
||||||
mbsebbs:
|
mbsebbs:
|
||||||
Several user input functions don't allow comma's anymore.
|
Several user input functions don't allow comma's anymore.
|
||||||
Uploaded files will now also have a 8.3 hard link to the long
|
Uploaded files will now also have a 8.3 hard link to the long
|
||||||
|
57
lib/mangle.c
57
lib/mangle.c
@ -42,7 +42,6 @@
|
|||||||
* Prototype functions
|
* Prototype functions
|
||||||
*/
|
*/
|
||||||
int strhaslower(const char *);
|
int strhaslower(const char *);
|
||||||
int str_checksum(const char *);
|
|
||||||
char *safe_strcpy(char *, const char *, size_t);
|
char *safe_strcpy(char *, const char *, size_t);
|
||||||
static void init_chartest(void);
|
static void init_chartest(void);
|
||||||
static int is_reserved_msdos(char *);
|
static int is_reserved_msdos(char *);
|
||||||
@ -112,34 +111,6 @@ int strhaslower(const char *s)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* Provide a checksum on a string
|
|
||||||
*
|
|
||||||
* Input: s - the null-terminated character string for which the checksum
|
|
||||||
* will be calculated.
|
|
||||||
*
|
|
||||||
* Output: The checksum value calculated for s.
|
|
||||||
*
|
|
||||||
* ****************************************************************************
|
|
||||||
*/
|
|
||||||
int str_checksum(const char *s)
|
|
||||||
{
|
|
||||||
int res = 0;
|
|
||||||
int c;
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
while(*s) {
|
|
||||||
c = *s;
|
|
||||||
res ^= (c << (i % 15)) ^ (c >> (15-(i%15)));
|
|
||||||
s++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
// Syslog('f', "str_cksum(%s) %d", s, res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
safe string copy into a known length string. maxlength does not
|
safe string copy into a known length string. maxlength does not
|
||||||
include the terminating zero.
|
include the terminating zero.
|
||||||
@ -347,7 +318,7 @@ int is_8_3( char *fname)
|
|||||||
*/
|
*/
|
||||||
void mangle_name_83(char *s)
|
void mangle_name_83(char *s)
|
||||||
{
|
{
|
||||||
int csum, crc16, i;
|
int crc16, i;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
char extension[4];
|
char extension[4];
|
||||||
char base[9];
|
char base[9];
|
||||||
@ -379,6 +350,9 @@ void mangle_name_83(char *s)
|
|||||||
} else if (strcmp(q = s + strlen(s) - strlen(".conf"), ".conf") == 0) {
|
} else if (strcmp(q = s + strlen(s) - strlen(".conf"), ".conf") == 0) {
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
q = (char *)"cnf";
|
q = (char *)"cnf";
|
||||||
|
} else if (strcmp(q = s + strlen(s) - strlen(".mpeg"), ".mpeg") == 0) {
|
||||||
|
*q = '\0';
|
||||||
|
q = (char *)"mpg";
|
||||||
} else {
|
} else {
|
||||||
q = NULL;
|
q = NULL;
|
||||||
}
|
}
|
||||||
@ -404,15 +378,12 @@ void mangle_name_83(char *s)
|
|||||||
|
|
||||||
if (all_normal && p[1] != 0) {
|
if (all_normal && p[1] != 0) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
csum = str_checksum(s);
|
|
||||||
crc16 = crc16xmodem(s, strlen(s));
|
crc16 = crc16xmodem(s, strlen(s));
|
||||||
*p = '.';
|
*p = '.';
|
||||||
} else {
|
} else {
|
||||||
csum = str_checksum(s);
|
|
||||||
crc16 = crc16xmodem(s, strlen(s));
|
crc16 = crc16xmodem(s, strlen(s));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
csum = str_checksum(s);
|
|
||||||
crc16 = crc16xmodem(s, strlen(s));
|
crc16 = crc16xmodem(s, strlen(s));
|
||||||
}
|
}
|
||||||
// Syslog('f', "crc16xmodem(%s) %d", s, crc16);
|
// Syslog('f', "crc16xmodem(%s) %d", s, crc16);
|
||||||
@ -435,20 +406,23 @@ void mangle_name_83(char *s)
|
|||||||
|
|
||||||
p = s;
|
p = s;
|
||||||
|
|
||||||
while (*p && baselen < 5) {
|
/*
|
||||||
|
* Changed to baselen 4, original this is 5.
|
||||||
|
* 24-11-2002 MB.
|
||||||
|
*/
|
||||||
|
while (*p && baselen < 4) {
|
||||||
if (*p != '.' )
|
if (*p != '.' )
|
||||||
base[baselen++] = p[0];
|
base[baselen++] = p[0];
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
base[baselen] = 0;
|
base[baselen] = 0;
|
||||||
|
|
||||||
csum = csum % (MANGLE_BASE * MANGLE_BASE);
|
if (crc16 > (MANGLE_BASE * MANGLE_BASE * MANGLE_BASE))
|
||||||
crc16 = crc16 % (MANGLE_BASE * MANGLE_BASE);
|
Syslog('!', "WARNING: mangle_name_83() crc16 overflow");
|
||||||
sprintf(s, "%s%c%c%c", base, magic_char, mangle(csum / MANGLE_BASE), mangle(csum));
|
crc16 = crc16 % (MANGLE_BASE * MANGLE_BASE * MANGLE_BASE);
|
||||||
Syslog('f', "csum %4d mangle old %c%c%c crc16 %4d mangle new %c%c%c",
|
sprintf(s, "%s%c%c%c%c", base, magic_char,
|
||||||
csum, magic_char, mangle(csum / MANGLE_BASE), mangle(csum),
|
mangle(crc16 / (MANGLE_BASE * MANGLE_BASE)), mangle(crc16 / MANGLE_BASE), mangle(crc16));
|
||||||
crc16, magic_char, mangle(crc16 / MANGLE_BASE), mangle(crc16));
|
if ( *extension ) {
|
||||||
if( *extension ) {
|
|
||||||
(void)strcat(s, ".");
|
(void)strcat(s, ".");
|
||||||
(void)strcat(s, extension);
|
(void)strcat(s, extension);
|
||||||
}
|
}
|
||||||
@ -477,6 +451,7 @@ void name_mangle(char *OutName)
|
|||||||
*/
|
*/
|
||||||
if (!is_8_3(OutName)) {
|
if (!is_8_3(OutName)) {
|
||||||
mangle_name_83(OutName);
|
mangle_name_83(OutName);
|
||||||
|
Syslog('f',"name_mangle(%s) ==> [%s]", p, OutName);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* No mangling needed, convert to uppercase
|
* No mangling needed, convert to uppercase
|
||||||
|
Reference in New Issue
Block a user