From f9bbcb3fb3effdeb9f9f42de77bbde9f2789efdc Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 7 Nov 1997 03:06:24 +0000 Subject: Modified Files: mangle.c server.c proto.h mangle.c I am planning to replace the mangled_stack array with a proper stack, but found many style inconsistencies (no, really). As you might expect, I have standardized on my own preferences. ;) I also found a potential problem in create_mangled_stack (which I've renamed as reset_mangled_stack). If the stack size were passed into the function as 0 or less, there was the possibility that the array would have been freed twice. I doubt that this ever happens, but I don't like to leave holes. Of course, the fix will be irrelevent once I replace the array with a linked-list-based stack. server.c Changed the call to create_mangled_stack() to a call to reset_mangled_stack(). proto.h Regenerated to match the above changes. (A real comment! How unusual!) (This used to be commit 34d1b3e4fa7a1158f3a3c5c47adf0417c7144095) --- source3/smbd/mangle.c | 557 ++++++++++++++++++++++++++++---------------------- 1 file changed, 316 insertions(+), 241 deletions(-) (limited to 'source3/smbd/mangle.c') diff --git a/source3/smbd/mangle.c b/source3/smbd/mangle.c index 829e307a85..bf26475715 100644 --- a/source3/smbd/mangle.c +++ b/source3/smbd/mangle.c @@ -26,27 +26,33 @@ extern int case_default; extern BOOL case_mangle; /**************************************************************************** -provide a checksum on a string -****************************************************************************/ + * Provide a checksum on a string + * + * Input: s - the nul-terminated character string for which the checksum + * will be calculated. + * Output: The checksum value calculated for s. + * + ****************************************************************************/ int str_checksum(char *s) -{ + { int res = 0; int c; int i=0; - while (*s) + + while( *s ) { - c = *s; - res ^= (c << (i % 15)) ^ (c >> (15-(i%15))); - s++; i++; + c = *s; + res ^= (c << (i % 15)) ^ (c >> (15-(i%15))); + s++; i++; } return(res); -} + } /* str_checksum */ /**************************************************************************** return True if a name is a special msdos reserved name ****************************************************************************/ static BOOL is_reserved_msdos(char *fname) -{ + { char upperFname[13]; char *p; @@ -72,7 +78,7 @@ static BOOL is_reserved_msdos(char *fname) return (True) ; return (False); -} + } /* is_reserved_msdos */ @@ -80,34 +86,37 @@ static BOOL is_reserved_msdos(char *fname) return True if a name is in 8.3 dos format ****************************************************************************/ BOOL is_8_3(char *fname, BOOL check_case) -{ + { int len; char *dot_pos; char *slash_pos = strrchr(fname,'/'); int l; - if (slash_pos) fname = slash_pos+1; + if( slash_pos ) + fname = slash_pos+1; len = strlen(fname); DEBUG(5,("checking %s for 8.3\n",fname)); - if (check_case && case_mangle) + if( check_case && case_mangle ) + { switch (case_default) { case CASE_LOWER: - if (strhasupper(fname)) return(False); - break; + if (strhasupper(fname)) return(False); + break; case CASE_UPPER: - if (strhaslower(fname)) return(False); - break; + if (strhaslower(fname)) return(False); + break; } + } /* can't be longer than 12 chars */ - if (len == 0 || len > 12) + if( len == 0 || len > 12 ) return(False); /* can't be an MS-DOS Special file such as lpt1 or even lpt1.txt */ - if (is_reserved_msdos(fname)) + if( is_reserved_msdos(fname) ) return(False); /* can't contain invalid dos chars */ @@ -121,184 +130,218 @@ BOOL is_8_3(char *fname, BOOL check_case) dot_pos = strchr(fname,'.'); - { + { char *p = fname; + if(lp_client_code_page() == KANJI_CODEPAGE) - { + { dot_pos = 0; while (*p) - { + { if (is_shift_jis (*p)) p += 2; else if (is_kana (*p)) p ++; else - { + { if (*p == '.' && !dot_pos) dot_pos = (char *) p; if (!isdoschar(*p)) return(False); p++; + } } - } - } + } else - { - while (*p) { + while (*p) + { if (!isdoschar(*p)) return(False); p++; - } + } + } } - } /* no dot and less than 9 means OK */ if (!dot_pos) return(len <= 8); - + l = PTR_DIFF(dot_pos,fname); /* base must be at least 1 char except special cases . and .. */ - if (l == 0) + if( l == 0 ) return(strcmp(fname,".") == 0 || strcmp(fname,"..") == 0); /* base can't be greater than 8 */ - if (l > 8) + if( l > 8 ) return(False); - if (lp_strip_dot() && + if( lp_strip_dot() && len - l == 1 && - !strchr(dot_pos+1,'.')) + !strchr(dot_pos+1,'.') ) { - *dot_pos = 0; - return(True); + *dot_pos = 0; + return(True); } /* extension must be between 1 and 3 */ - if ( (len - l < 2 ) || (len - l > 4) ) + if( (len - l < 2 ) || (len - l > 4) ) return(False); /* extension can't have a dot */ - if (strchr(dot_pos+1,'.')) + if( strchr(dot_pos+1,'.') ) return(False); /* must be in 8.3 format */ return(True); -} + } /* is_8_3 */ + +/* -------------------------------------------------------------------------- ** + * This section creates and maintains a stack of name mangling results. + * The original comments read: "keep a stack of name mangling results - just + * so file moves and copies have a chance of working" (whatever that means). + * + * There are three functions to manage the stack: + * reset_mangled_stack() - + * push_mangled_name() - + * check_mangled_stack() - + */ - - -/* -keep a stack of name mangling results - just -so file moves and copies have a chance of working -*/ fstring *mangled_stack = NULL; int mangled_stack_size = 0; int mangled_stack_len = 0; /**************************************************************************** -create the mangled stack -****************************************************************************/ -void create_mangled_stack(int size) -{ - if (mangled_stack) + * create the mangled stack CRH + ****************************************************************************/ +void reset_mangled_stack( int size ) + { + if( mangled_stack ) + { + free(mangled_stack); + mangled_stack_size = 0; + mangled_stack_len = 0; + } + + if( size > 0 ) { - free(mangled_stack); - mangled_stack_size = 0; - mangled_stack_len = 0; + mangled_stack = (fstring *)malloc( sizeof(fstring) * size ); + if( mangled_stack ) + mangled_stack_size = size; } - if (size > 0) - mangled_stack = (fstring *)malloc(sizeof(fstring)*size); - if (mangled_stack) mangled_stack_size = size; -} + else + mangled_stack = NULL; + } /* create_mangled_stack */ /**************************************************************************** -push a mangled name onto the stack -****************************************************************************/ + * push a mangled name onto the stack CRH + ****************************************************************************/ static void push_mangled_name(char *s) -{ + { int i; char *p; - if (!mangled_stack) + /* If the stack doesn't exist... Fail. */ + if( !mangled_stack ) return; - for (i=0;i is already on the stack, move it to the top. */ + for( i=0; i wasn't already there, add it to the top of the stack. */ + memmove( mangled_stack[1], mangled_stack[0], + sizeof(fstring) * MIN(mangled_stack_len, mangled_stack_size-1) ); + strcpy( mangled_stack[0], s ); + mangled_stack_len = MIN( mangled_stack_size, mangled_stack_len+1 ); + + /* Hmmm... + * Find the last dot '.' in the name, + * if there are any upper case characters past the last dot + * and there are no more than three characters past the last dot + * then terminate the name *at* the last dot. + */ + p = strrchr( mangled_stack[0], '.' ); + if( p && (!strhasupper(p+1)) && (strlen(p+1) < (size_t)4) ) *p = 0; - mangled_stack_len = MIN(mangled_stack_size,mangled_stack_len+1); -} + + } /* push_mangled_name */ /**************************************************************************** -check for a name on the mangled name stack -****************************************************************************/ + * check for a name on the mangled name stack CRH + ****************************************************************************/ BOOL check_mangled_stack(char *s) -{ + { int i; pstring tmpname; char extension[5]; - char *p = strrchr(s,'.'); + char *p = strrchr( s, '.' ); BOOL check_extension = False; extension[0] = 0; - if (!mangled_stack) return(False); + /* If the stack doesn't exist, fail. */ + if( !mangled_stack ) + return(False); - if (p) + /* If there is a file extension, then we need to play with it, too. */ + if( p ) { - check_extension = True; - StrnCpy(extension,p,4); - strlower(extension); /* XXXXXXX */ + check_extension = True; + StrnCpy( extension, p, 4 ); + strlower( extension ); /* XXXXXXX */ } - for (i=0;i