2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Simo Sorce 2001
6 Copyright (C) Andrew Bartlett 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* -------------------------------------------------------------------------- **
26 * March/April 1998 CRH
27 * - Many of the functions in this module overwrite string buffers passed to
28 * them. This causes a variety of problems and is, generally speaking,
29 * dangerous and scarry. See the kludge notes in name_map_mangle()
31 * - It seems that something is calling name_map_mangle() twice. The
32 * first call is probably some sort of test. Names which contain
33 * illegal characters are being doubly mangled. I'm not sure, but
34 * I'm guessing the problem is in server.c.
36 * -------------------------------------------------------------------------- **
39 /* -------------------------------------------------------------------------- **
42 * March/April 1998 CRH
43 * Updated a bit. Rewrote is_mangled() to be a bit more selective.
44 * Rewrote the mangled name cache. Added comments here and there.
46 * -------------------------------------------------------------------------- **
52 /* -------------------------------------------------------------------------- **
53 * External Variables...
56 extern int case_default; /* Are conforming 8.3 names all upper or lower? */
57 extern BOOL case_mangle; /* If true, all chars in 8.3 should be same case. */
59 /* -------------------------------------------------------------------------- **
62 * magic_char - This is the magic char used for mangling. It's
63 * global. There is a call to lp_magicchar() in server.c
64 * that is used to override the initial value.
66 * MANGLE_BASE - This is the number of characters we use for name mangling.
68 * basechars - The set characters used for name mangling. This
69 * is static (scope is this file only).
71 * mangle() - Macro used to select a character from basechars (i.e.,
72 * mangle(n) will return the nth digit, modulo MANGLE_BASE).
74 * chartest - array 0..255. The index range is the set of all possible
75 * values of a byte. For each byte value, the content is a
76 * two nibble pair. See BASECHAR_MASK and ILLEGAL_MASK,
79 * ct_initialized - False until the chartest array has been initialized via
80 * a call to init_chartest().
82 * BASECHAR_MASK - Masks the upper nibble of a one-byte value.
84 * ILLEGAL_MASK - Masks the lower nibble of a one-byte value.
86 * isbasecahr() - Given a character, check the chartest array to see
87 * if that character is in the basechars set. This is
88 * faster than using strchr_m().
90 * isillegal() - Given a character, check the chartest array to see
91 * if that character is in the illegal characters set.
92 * This is faster than using strchr_m().
94 * mangled_cache - Cache header used for storing mangled -> original
97 * mc_initialized - False until the mangled_cache structure has been
98 * initialized via a call to reset_mangled_cache().
100 * MANGLED_CACHE_MAX_ENTRIES - Default maximum number of entries for the
101 * cache. A value of 0 indicates "infinite".
103 * MANGLED_CACHE_MAX_MEMORY - Default maximum amount of memory for the
104 * cache. When the cache was kept as an array of 256
105 * byte strings, the default cache size was 50 entries.
106 * This required a fixed 12.5Kbytes of memory. The
107 * mangled stack parameter is no longer used (though
108 * this might change). We're now using a fixed 16Kbyte
109 * maximum cache size. This will probably be much more
113 char magic_char = '~';
115 static char basechars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
116 #define MANGLE_BASE (sizeof(basechars)/sizeof(char)-1)
118 static unsigned char chartest[256] = { 0 };
119 static BOOL ct_initialized = False;
121 #define mangle(V) ((char)(basechars[(V) % MANGLE_BASE]))
122 #define BASECHAR_MASK 0xf0
123 #define ILLEGAL_MASK 0x0f
124 #define isbasechar(C) ( (chartest[ ((C) & 0xff) ]) & BASECHAR_MASK )
125 #define isillegal(C) ( (chartest[ ((C) & 0xff) ]) & ILLEGAL_MASK )
127 static ubi_cacheRoot mangled_cache[1] = { { { 0, 0, 0, 0 }, 0, 0, 0, 0, 0, 0 } };
128 static BOOL mc_initialized = False;
129 #define MANGLED_CACHE_MAX_ENTRIES 0
130 #define MANGLED_CACHE_MAX_MEMORY 16384
133 /* -------------------------------------------------------------------------- **
134 * External Variables...
137 extern int case_default; /* Are conforming 8.3 names all upper or lower? */
138 extern BOOL case_mangle; /* If true, all chars in 8.3 should be same case. */
140 /* -------------------------------------------------------------------- */
142 NTSTATUS has_valid_chars(const smb_ucs2_t *s)
144 if (!s || !*s) return NT_STATUS_INVALID_PARAMETER;
146 DEBUG(10,("has_valid_chars: testing\n")); /* [%s]\n", s)); */
148 /* CHECK: this should not be necessary if the ms wild chars
149 are not valid in valid.dat --- simo */
150 if (ms_has_wild_w(s)) return NT_STATUS_UNSUCCESSFUL;
153 if(!isvalid83_w(*s)) return NT_STATUS_UNSUCCESSFUL;
160 /* return False if something fail and
161 * return 2 alloced unicode strings that contain prefix and extension
163 static NTSTATUS mangle_get_prefix(const smb_ucs2_t *ucs2_string, smb_ucs2_t **prefix, smb_ucs2_t **extension)
169 *prefix = strdup_w(ucs2_string);
172 DEBUG(0,("mangle_get_prefix: out of memory!\n"));
173 return NT_STATUS_NO_MEMORY;
175 if ((p = strrchr_w(*prefix, UCS2_CHAR('.'))))
177 ext_len = strlen_w(p+1);
178 if ((ext_len > 0) && (ext_len < 4) && (p != *prefix) &&
179 (NT_STATUS_IS_OK(has_valid_chars(p+1)))) /* check extension */
182 *extension = strdup_w(p+1);
185 DEBUG(0,("mangle_get_prefix: out of memory!\n"));
187 return NT_STATUS_NO_MEMORY;
194 /* ************************************************************************** **
195 * Return NT_STATUS_UNSUCCESSFUL if a name is a special msdos reserved name.
197 * Input: fname - String containing the name to be tested.
199 * Output: NT_STATUS_UNSUCCESSFUL, if the name matches one of the list of reserved names.
201 * Notes: This is a static function called by is_8_3(), below.
203 * ************************************************************************** **
205 static NTSTATUS is_valid_name(const smb_ucs2_t *fname)
208 NTSTATUS ret = NT_STATUS_OK;
210 if (!fname || !*fname) return NT_STATUS_INVALID_PARAMETER;
212 DEBUG(10,("is_valid_name: testing\n")); /* [%s]\n", s)); */
214 if (*fname == UCS2_CHAR('.')) return NT_STATUS_UNSUCCESSFUL;
216 ret = has_valid_chars(fname);
217 if (NT_STATUS_IS_ERR(ret)) return ret;
219 str = strdup_w(fname);
220 p = strchr_w(str, UCS2_CHAR('.'));
228 if(strcmp_wa(p, "UX") == 0)
229 ret = NT_STATUS_UNSUCCESSFUL;
232 if((strcmp_wa(p, "LOCK$") == 0)
233 || (strcmp_wa(p, "ON") == 0)
234 || (strcmp_wa(p, "OM1") == 0)
235 || (strcmp_wa(p, "OM2") == 0)
236 || (strcmp_wa(p, "OM3") == 0)
237 || (strcmp_wa(p, "OM4") == 0)
239 ret = NT_STATUS_UNSUCCESSFUL;
242 if((strcmp_wa(p, "PT1") == 0)
243 || (strcmp_wa(p, "PT2") == 0)
244 || (strcmp_wa(p, "PT3") == 0)
246 ret = NT_STATUS_UNSUCCESSFUL;
249 if(strcmp_wa(p, "UL") == 0)
250 ret = NT_STATUS_UNSUCCESSFUL;
253 if(strcmp_wa(p, "RN") == 0)
254 ret = NT_STATUS_UNSUCCESSFUL;
264 static NTSTATUS is_8_3_w(const smb_ucs2_t *fname)
266 smb_ucs2_t *pref = 0, *ext = 0;
268 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
270 if (!fname || !*fname) return NT_STATUS_INVALID_PARAMETER;
272 DEBUG(10,("is_8_3_w: testing\n")); /* [%s]\n", fname)); */
274 if (strlen_w(fname) > 12) return NT_STATUS_UNSUCCESSFUL;
276 if (strcmp_wa(fname, ".") == 0 || strcmp_wa(fname, "..") == 0)
279 if (NT_STATUS_IS_ERR(is_valid_name(fname))) goto done;
281 if (NT_STATUS_IS_ERR(mangle_get_prefix(fname, &pref, &ext))) goto done;
282 plen = strlen_w(pref);
284 if (strchr_wa(pref, '.')) goto done;
285 if (plen < 1 || plen > 8) goto done;
286 if (ext) if (strlen_w(ext) > 3) goto done;
296 BOOL is_8_3(const char *fname, BOOL check_case)
299 smb_ucs2_t *ucs2name;
300 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
302 if (!fname || !*fname) return False;
303 if ((f = strrchr(fname, '/')) == NULL) f = fname;
306 DEBUG(10,("is_8_3: testing [%s]\n", f));
308 if (strlen(f) > 12) return False;
310 ucs2name = acnv_uxu2(f);
313 DEBUG(0,("is_8_3: internal error acnv_uxu2() failed!\n"));
317 ret = is_8_3_w(ucs2name);
322 DEBUG(10,("is_8_3: returning -> %s\n", NT_STATUS_IS_OK(ret)?"True":"False"));
324 if (!NT_STATUS_IS_OK(ret)) {
333 /* -------------------------------------------------------------------------- **
337 /* ************************************************************************** **
338 * Initialize the static character test array.
344 * Notes: This function changes (loads) the contents of the <chartest>
345 * array. The scope of <chartest> is this file.
347 * ************************************************************************** **
349 static void init_chartest( void )
351 char *illegalchars = "*\\/?<>|\":";
354 memset( (char *)chartest, '\0', 256 );
356 for( s = (unsigned char *)illegalchars; *s; s++ )
357 chartest[*s] = ILLEGAL_MASK;
359 for( s = (unsigned char *)basechars; *s; s++ )
360 chartest[*s] |= BASECHAR_MASK;
362 ct_initialized = True;
363 } /* init_chartest */
366 /* ************************************************************************** **
367 * Return True if the name *could be* a mangled name.
369 * Input: s - A path name - in UNIX pathname format.
371 * Output: True if the name matches the pattern described below in the
374 * Notes: The input name is *not* tested for 8.3 compliance. This must be
375 * done separately. This function returns true if the name contains
376 * a magic character followed by excactly two characters from the
377 * basechars list (above), which in turn are followed either by the
378 * nul (end of string) byte or a dot (extension) or by a '/' (end of
381 * ************************************************************************** **
383 BOOL is_mangled( char *s )
387 if( !ct_initialized )
390 magic = strchr_m( s, magic_char );
391 while( magic && magic[1] && magic[2] ) /* 3 chars, 1st is magic. */
393 if( ('.' == magic[3] || '/' == magic[3] || !(magic[3])) /* Ends with '.' or nul or '/' ? */
394 && isbasechar( toupper(magic[1]) ) /* is 2nd char basechar? */
395 && isbasechar( toupper(magic[2]) ) ) /* is 3rd char basechar? */
396 return( True ); /* If all above, then true, */
397 magic = strchr_m( magic+1, magic_char ); /* else seek next magic. */
403 /* ************************************************************************** **
404 * Compare two cache keys and return a value indicating their ordinal
407 * Input: ItemPtr - Pointer to a comparison key. In this case, this will
408 * be a mangled name string.
409 * NodePtr - Pointer to a node in the cache. The node structure
410 * will be followed in memory by a mangled name string.
412 * Output: A signed integer, as follows:
413 * (x < 0) <==> Key1 less than Key2
414 * (x == 0) <==> Key1 equals Key2
415 * (x > 0) <==> Key1 greater than Key2
417 * Notes: This is a ubiqx-style comparison routine. See ubi_BinTree for
420 * ************************************************************************** **
422 static signed int cache_compare( ubi_btItemPtr ItemPtr, ubi_btNodePtr NodePtr )
424 char *Key1 = (char *)ItemPtr;
425 char *Key2 = (char *)(((ubi_cacheEntryPtr)NodePtr) + 1);
427 return( StrCaseCmp( Key1, Key2 ) );
428 } /* cache_compare */
430 /* ************************************************************************** **
431 * Free a cache entry.
433 * Input: WarrenZevon - Pointer to the entry that is to be returned to
437 * Notes: This function gets around the possibility that the standard
438 * free() function may be implemented as a macro, or other evil
439 * subversions (oh, so much fun).
441 * ************************************************************************** **
443 static void cache_free_entry( ubi_trNodePtr WarrenZevon )
445 ZERO_STRUCTP(WarrenZevon);
446 SAFE_FREE( WarrenZevon );
447 } /* cache_free_entry */
449 /* ************************************************************************** **
450 * Initializes or clears the mangled cache.
455 * Notes: There is a section below that is commented out. It shows how
456 * one might use lp_ calls to set the maximum memory and entry size
457 * of the cache. You might also want to remove the constants used
458 * in ubi_cacheInit() and replace them with lp_ calls. If so, then
459 * the calls to ubi_cacheSetMax*() would be moved into the else
460 * clause. Another option would be to pass in the max_entries and
461 * max_memory values as parameters. crh 09-Apr-1998.
463 * ************************************************************************** **
465 void reset_mangled_cache( void )
467 if( !mc_initialized )
469 (void)ubi_cacheInit( mangled_cache,
472 MANGLED_CACHE_MAX_ENTRIES,
473 MANGLED_CACHE_MAX_MEMORY );
474 mc_initialized = True;
478 (void)ubi_cacheClear( mangled_cache );
482 (void)ubi_cacheSetMaxEntries( mangled_cache, lp_mangled_cache_entries() );
483 (void)ubi_cacheSetMaxMemory( mangled_cache, lp_mangled_cache_memory() );
485 } /* reset_mangled_cache */
488 /* ************************************************************************** **
489 * Add a mangled name into the cache.
491 * Notes: If the mangled cache has not been initialized, then the
492 * function will simply fail. It could initialize the cache,
493 * but that's not the way it was done before I changed the
494 * cache mechanism, so I'm sticking with the old method.
496 * If the extension of the raw name maps directly to the
497 * extension of the mangled name, then we'll store both names
498 * *without* extensions. That way, we can provide consistent
499 * reverse mangling for all names that match. The test here is
500 * a bit more careful than the one done in earlier versions of
503 * - the extension must exist on the raw name,
504 * - it must be all lower case
505 * - it must match the mangled extension (to prove that no
506 * mangling occurred).
510 * ************************************************************************** **
512 static void cache_mangled_name( char *mangled_name, char *raw_name )
514 ubi_cacheEntryPtr new_entry;
521 /* If the cache isn't initialized, give up. */
522 if( !mc_initialized )
525 /* Init the string lengths. */
526 mangled_len = strlen( mangled_name );
527 raw_len = strlen( raw_name );
529 /* See if the extensions are unmangled. If so, store the entry
530 * without the extension, thus creating a "group" reverse map.
532 s1 = strrchr( mangled_name, '.' );
533 if( s1 && (s2 = strrchr( raw_name, '.' )) )
536 while( s1[i] && (tolower( s1[i] ) == s2[i]) )
538 if( !s1[i] && !s2[i] )
545 /* Allocate a new cache entry. If the allocation fails, just return. */
546 i = sizeof( ubi_cacheEntry ) + mangled_len + raw_len + 2;
547 new_entry = malloc( i );
551 /* Fill the new cache entry, and add it to the cache. */
552 s1 = (char *)(new_entry + 1);
553 s2 = (char *)&(s1[mangled_len + 1]);
554 (void)StrnCpy( s1, mangled_name, mangled_len );
555 (void)StrnCpy( s2, raw_name, raw_len );
556 ubi_cachePut( mangled_cache, i, new_entry, s1 );
557 } /* cache_mangled_name */
559 /* ************************************************************************** **
560 * Check for a name on the mangled name stack
562 * Input: s - Input *and* output string buffer.
564 * Output: True if the name was found in the cache, else False.
566 * Notes: If a reverse map is found, the function will overwrite the string
567 * space indicated by the input pointer <s>. This is frightening.
568 * It should be rewritten to return NULL if the long name was not
569 * found, and a pointer to the long name if it was found.
571 * ************************************************************************** **
574 BOOL check_mangled_cache( char *s )
576 ubi_cacheEntryPtr FoundPtr;
577 char *ext_start = NULL;
579 char *saved_ext = NULL;
581 /* If the cache isn't initialized, give up. */
582 if( !mc_initialized )
585 FoundPtr = ubi_cacheGet( mangled_cache, (ubi_trItemPtr)s );
587 /* If we didn't find the name *with* the extension, try without. */
590 ext_start = strrchr( s, '.' );
593 if((saved_ext = strdup(ext_start)) == NULL)
597 FoundPtr = ubi_cacheGet( mangled_cache, (ubi_trItemPtr)s );
599 * At this point s is the name without the
600 * extension. We re-add the extension if saved_ext
601 * is not null, before freeing saved_ext.
606 /* Okay, if we haven't found it we're done. */
611 /* Replace the saved_ext as it was truncated. */
612 (void)pstrcat( s, saved_ext );
613 SAFE_FREE(saved_ext);
618 /* If we *did* find it, we need to copy it into the string buffer. */
619 found_name = (char *)(FoundPtr + 1);
620 found_name += (strlen( found_name ) + 1);
622 DEBUG( 3, ("Found %s on mangled stack ", s) );
624 (void)pstrcpy( s, found_name );
627 /* Replace the saved_ext as it was truncated. */
628 (void)pstrcat( s, saved_ext );
629 SAFE_FREE(saved_ext);
632 DEBUG( 3, ("as %s\n", s) );
635 } /* check_mangled_cache */
638 /* ************************************************************************** **
639 * Used only in do_fwd_mangled_map(), below.
640 * ************************************************************************** **
642 static char *map_filename( char *s, /* This is null terminated */
643 char *pattern, /* This isn't. */
644 int len ) /* This is the length of pattern. */
646 static pstring matching_bit; /* The bit of the string which matches */
647 /* a * in pattern if indeed there is a * */
648 char *sp; /* Pointer into s. */
649 char *pp; /* Pointer into p. */
650 char *match_start; /* Where the matching bit starts. */
653 StrnCpy( pat, pattern, len ); /* Get pattern into a proper string! */
654 pstrcpy( matching_bit, "" ); /* Match but no star gets this. */
655 pp = pat; /* Initialize the pointers. */
658 if( strequal(s, ".") || strequal(s, ".."))
660 return NULL; /* Do not map '.' and '..' */
663 if( (len == 1) && (*pattern == '*') )
665 return NULL; /* Impossible, too ambiguous for */
668 while( (*sp) /* Not the end of the string. */
669 && (*pp) /* Not the end of the pattern. */
670 && (*sp == *pp) /* The two match. */
671 && (*pp != '*') ) /* No wildcard. */
673 sp++; /* Keep looking. */
677 if( !*sp && !*pp ) /* End of pattern. */
678 return( matching_bit ); /* Simple match. Return empty string. */
682 pp++; /* Always interrested in the chacter */
684 if( !*pp ) /* It is at the end of the pattern. */
686 StrnCpy( matching_bit, s, sp-s );
687 return( matching_bit );
691 /* The next character in pattern must match a character further */
692 /* along s than sp so look for that character. */
694 while( (*sp) /* Not the end of s. */
695 && (*sp != *pp) ) /* Not the same */
696 sp++; /* Keep looking. */
697 if( !*sp ) /* Got to the end without a match. */
700 } /* Still hope for a match. */
703 /* Now sp should point to a matching character. */
704 StrnCpy(matching_bit, match_start, sp-match_start);
705 /* Back to needing a stright match again. */
706 while( (*sp) /* Not the end of the string. */
707 && (*pp) /* Not the end of the pattern. */
708 && (*sp == *pp) ) /* The two match. */
710 sp++; /* Keep looking. */
713 if( !*sp && !*pp ) /* Both at end so it matched */
714 return( matching_bit );
720 return( NULL ); /* No match. */
724 /* ************************************************************************** **
725 * MangledMap is a series of name pairs in () separated by spaces.
726 * If s matches the first of the pair then the name given is the
727 * second of the pair. A * means any number of any character and if
728 * present in the second of the pair as well as the first the
729 * matching part of the first string takes the place of the * in the
732 * I wanted this so that we could have RCS files which can be used
733 * by UNIX and DOS programs. My mapping string is (RCS rcs) which
734 * converts the UNIX RCS file subdirectory to lowercase thus
735 * preventing mangling.
737 * (I think Andrew wrote the above, but I'm not sure. -- CRH)
739 * See 'mangled map' in smb.conf(5).
741 * ************************************************************************** **
743 static void do_fwd_mangled_map(char *s, char *MangledMap)
745 char *start=MangledMap; /* Use this to search for mappings. */
746 char *end; /* Used to find the end of strings. */
748 pstring new_string; /* Make up the result here. */
749 char *np; /* Points into new_string. */
751 DEBUG( 5, ("Mangled Mapping '%s' map '%s'\n", s, MangledMap) );
754 while( (*start) && (*start != '(') )
757 continue; /* Always check for the end. */
758 start++; /* Skip the ( */
759 end = start; /* Search for the ' ' or a ')' */
760 DEBUG( 5, ("Start of first in pair '%s'\n", start) );
761 while( (*end) && !((*end == ' ') || (*end == ')')) )
766 continue; /* Always check for the end. */
768 DEBUG( 5, ("End of first in pair '%s'\n", end) );
769 if( (match_string = map_filename( s, start, end-start )) )
771 DEBUG( 5, ("Found a match\n") );
773 start = end + 1; /* Point to start of what it is to become. */
774 DEBUG( 5, ("Start of second in pair '%s'\n", start) );
777 while( (*end) /* Not the end of string. */
778 && (*end != ')') /* Not the end of the pattern. */
779 && (*end != '*') ) /* Not a wildcard. */
784 continue; /* Always check for the end. */
788 pstrcpy( np, match_string );
789 np += strlen( match_string );
790 end++; /* Skip the '*' */
791 while( (*end) /* Not the end of string. */
792 && (*end != ')') /* Not the end of the pattern. */
793 && (*end != '*') ) /* Not a wildcard. */
799 continue; /* Always check for the end. */
801 *np++ = '\0'; /* NULL terminate it. */
802 DEBUG(5,("End of second in pair '%s'\n", end));
803 pstrcpy( s, new_string ); /* Substitute with the new name. */
804 DEBUG( 5, ("s is now '%s'\n", s) );
806 start = end; /* Skip a bit which cannot be wanted anymore. */
809 } /* do_fwd_mangled_map */
811 /*****************************************************************************
812 * do the actual mangling to 8.3 format
813 * the buffer must be able to hold 13 characters (including the null)
814 *****************************************************************************
816 void mangle_name_83( char *s)
829 if( p && (strlen(p+1) < (size_t)4) )
831 BOOL all_normal = ( strisnormal(p+1) ); /* XXXXXXXXX */
833 if( all_normal && p[1] != 0 )
836 csum = str_checksum( s );
840 csum = str_checksum(s);
843 csum = str_checksum(s);
847 DEBUG( 5, ("Mangling name %s to ",s) );
852 safe_strcpy( extension, "___", 3 );
856 while( *p && extlen < 3 )
859 extension[extlen++] = p[0];
863 extension[extlen] = 0;
869 while( *p && baselen < 5 )
872 base[baselen++] = p[0];
878 csum = csum % (MANGLE_BASE*MANGLE_BASE);
880 (void)slprintf(s, 12, "%s%c%c%c",
881 base, magic_char, mangle( csum/MANGLE_BASE ), mangle( csum ) );
885 (void)pstrcat( s, "." );
886 (void)pstrcat( s, extension );
889 DEBUG( 5, ( "%s\n", s ) );
891 } /* mangle_name_83 */
893 /*****************************************************************************
894 * Convert a filename to DOS format. Return True if successful.
896 * Input: OutName - Source *and* destination buffer.
898 * NOTE that OutName must point to a memory space that
899 * is at least 13 bytes in size!
901 * need83 - If False, name mangling will be skipped unless the
902 * name contains illegal characters. Mapping will still
903 * be done, if appropriate. This is probably used to
904 * signal that a client does not require name mangling,
905 * thus skipping the name mangling even on shares which
906 * have name-mangling turned on.
907 * cache83 - If False, the mangled name cache will not be updated.
908 * This is usually used to prevent that we overwrite
909 * a conflicting cache entry prematurely, i.e. before
910 * we know whether the client is really interested in the
911 * current name. (See PR#13758). UKD.
912 * snum - Share number. This identifies the share in which the
915 * Output: Returns False only if the name wanted mangling but the share does
916 * not have name mangling turned on.
918 * ****************************************************************************
920 BOOL name_map_mangle(char *OutName, BOOL need83, BOOL cache83, int snum)
923 smb_ucs2_t *OutName_ucs2;
924 DEBUG(5,("name_map_mangle( %s, need83 = %s, cache83 = %s, %d )\n", OutName,
925 need83 ? "True" : "False", cache83 ? "True" : "False", snum));
927 if (push_ucs2_allocate((void **)&OutName_ucs2, OutName) < 0) {
928 DEBUG(0, ("push_ucs2_allocate failed!\n"));
932 /* apply any name mappings */
933 map = lp_mangled_map(snum);
936 do_fwd_mangled_map( OutName, map );
939 /* check if it's already in 8.3 format */
940 if (need83 && !NT_STATUS_IS_OK(is_8_3_w(OutName_ucs2))) {
943 if (!lp_manglednames(snum)) {
947 /* mangle it into 8.3 */
949 tmp = strdup(OutName);
951 mangle_name_83(OutName);
954 cache_mangled_name(OutName, tmp);
959 DEBUG(5,("name_map_mangle() ==> [%s]\n", OutName));
960 SAFE_FREE(OutName_ucs2);
962 } /* name_map_mangle */