/* return the methods for this mangling implementation */ const struct mangle_fns *mangle_hash_init(void) { mangle_reset(); if (chartest == NULL) { init_chartest(); } /* Create the in-memory tdb using our custom hash function. */ tdb_mangled_cache = tdb_open_ex("mangled_cache", 1031, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644, NULL, fast_string_hash); return &mangle_hash_fns; }
/* ************************************************************************** ** * Return True if the name *could be* a mangled name. * * Input: s - A path name - in UNIX pathname format. * * Output: True if the name matches the pattern described below in the * notes, else False. * * Notes: The input name is *not* tested for 8.3 compliance. This must be * done separately. This function returns true if the name contains * a magic character followed by excactly two characters from the * basechars list (above), which in turn are followed either by the * nul (end of string) byte or a dot (extension) or by a '/' (end of * a directory name). * * ************************************************************************** ** */ static BOOL is_mangled(const char *s, int snum) { char *magic; magic_char = lp_magicchar(snum); if( !ct_initialized ) init_chartest(); magic = strchr_m( s, magic_char ); while( magic && magic[1] && magic[2] ) { /* 3 chars, 1st is magic. */ if( ('.' == magic[3] || '/' == magic[3] || !(magic[3])) /* Ends with '.' or nul or '/' ? */ && isbasechar( toupper_ascii(magic[1]) ) /* is 2nd char basechar? */ && isbasechar( toupper_ascii(magic[2]) ) ) /* is 3rd char basechar? */ return( True ); /* If all above, then true, */ magic = strchr_m( magic+1, magic_char ); /* else seek next magic. */ } return( False ); }
static bool is_mangled(const char *s, const struct share_params *p) { char *magic; char magic_char; magic_char = lp_magicchar(p); if (chartest == NULL) { init_chartest(); } magic = strchr_m( s, magic_char ); while( magic && magic[1] && magic[2] ) { /* 3 chars, 1st is magic. */ if( ('.' == magic[3] || '/' == magic[3] || !(magic[3])) /* Ends with '.' or nul or '/' ? */ && isbasechar( toupper_m(magic[1]) ) /* is 2nd char basechar? */ && isbasechar( toupper_m(magic[2]) ) ) /* is 3rd char basechar? */ return( True ); /* If all above, then true, */ magic = strchr_m( magic+1, magic_char ); /* else seek next magic. */ } return( False ); }
/* ************************************************************************** ** * Return True if the name is a valid DOS name in 8.3 DOS format. * * Input: fname - File name to be checked. * check_case - If True, then the * name will be checked to see if all characters * are the correct case. * * Output: True if the name is a valid DOS name, else FALSE. * * ************************************************************************** ** */ int is_8_3( char *fname) { int len; int l, i; char *p; char *dot_pos; char *slash_pos = strrchr( fname, '/' ); /* If there is a directory path, skip it. */ if (slash_pos) fname = slash_pos + 1; len = strlen(fname); /* Can't be 0 chars or longer than 12 chars */ if ((len == 0) || (len > 12)) return FALSE; /* Mustn't be an MS-DOS Special file such as lpt1 or even lpt1.txt */ if (is_reserved_msdos(fname)) return FALSE; init_chartest(); for (i = 0; i < strlen(fname); i++) { if (isillegal(fname[i])) { Syslog('+', "Illegal character in filename"); return FALSE; } } /* Can't contain invalid dos chars */ p = fname; dot_pos = NULL; while (*p) { if (*p == '.' && !dot_pos) dot_pos = (char *)p; 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) return(0 == strcmp( fname, "." ) || 0 == strcmp( fname, ".." )); /* base can't be greater than 8 */ if (l > 8) return FALSE; if (len - l == 1 && !strchr( dot_pos + 1, '.' )) { *dot_pos = 0; return TRUE; } /* extension must be between 1 and 3 */ if ((len - l < 2 ) || (len - l > 4)) return FALSE; /* extensions may not have a dot */ if (strchr( dot_pos+1, '.' )) return FALSE; /* must be in 8.3 format */ return TRUE; }