2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* -------------------------------------------------------------------------- **
25 * March/April 1998 CRH
26 * - Many of the functions in this module overwrite string buffers passed to
27 * them. This causes a variety of problems and is, generally speaking,
28 * dangerous and scarry. See the kludge notes in name_map_mangle()
30 * - It seems that something is calling name_map_mangle() twice. The
31 * first call is probably some sort of test. Names which contain
32 * illegal characters are being doubly mangled. I'm not sure, but
33 * I'm guessing the problem is in server.c.
35 * -------------------------------------------------------------------------- **
38 /* -------------------------------------------------------------------------- **
41 * March/April 1998 CRH
42 * Updated a bit. Rewrote is_mangled() to be a bit more selective.
43 * Rewrote the mangled name cache. Added comments here and there.
45 * -------------------------------------------------------------------------- **
51 /* -------------------------------------------------------------------------- **
52 * External Variables...
55 extern int DEBUGLEVEL
; /* Global debug level. */
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().
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().
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 /* -------------------------------------------------------------------------- **
137 /* ************************************************************************** **
138 * Initialize the static character test array.
144 * Notes: This function changes (loads) the contents of the <chartest>
145 * array. The scope of <chartest> is this file.
147 * ************************************************************************** **
149 static void init_chartest( void )
151 char *illegalchars
= "*\\/?<>|\":";
154 memset( (char *)chartest
, '\0', 256 );
156 for( s
= (unsigned char *)illegalchars
; *s
; s
++ )
157 chartest
[*s
] = ILLEGAL_MASK
;
159 for( s
= (unsigned char *)basechars
; *s
; s
++ )
160 chartest
[*s
] |= BASECHAR_MASK
;
162 ct_initialized
= True
;
163 } /* init_chartest */
165 /* ************************************************************************** **
166 * Return True if a name is a special msdos reserved name.
168 * Input: fname - String containing the name to be tested.
170 * Output: True, if the name matches one of the list of reserved names.
172 * Notes: This is a static function called by is_8_3(), below.
174 * ************************************************************************** **
176 static BOOL
is_reserved_msdos( char *fname
)
181 StrnCpy (upperFname
, fname
, 12);
183 /* lpt1.txt and con.txt etc are also illegal */
184 p
= strchr(upperFname
,'.');
188 strupper( upperFname
);
190 switch( upperFname
[0] )
193 if( 0 == strcmp( p
, "UX" ) )
197 if( (0 == strcmp( p
, "LOCK$" ))
198 || (0 == strcmp( p
, "ON" ))
199 || (0 == strcmp( p
, "OM1" ))
200 || (0 == strcmp( p
, "OM2" ))
201 || (0 == strcmp( p
, "OM3" ))
202 || (0 == strcmp( p
, "OM4" ))
207 if( (0 == strcmp( p
, "PT1" ))
208 || (0 == strcmp( p
, "PT2" ))
209 || (0 == strcmp( p
, "PT3" ))
214 if( 0 == strcmp( p
, "UL" ) )
218 if( 0 == strcmp( p
, "RN" ) )
224 } /* is_reserved_msdos */
226 /* ************************************************************************** **
227 * Determine whether or not a given name contains illegal characters, even
230 * Input: name - The name to be tested.
232 * Output: True if an illegal character was found in <name>, else False.
234 * Notes: This is used to test a name on the host system, long or short,
235 * for characters that would be illegal on most client systems,
236 * particularly DOS and Windows systems. Unix and AmigaOS, for
237 * example, allow a filenames which contain such oddities as
238 * quotes ("). If a name is found which does contain an illegal
239 * character, it is mangled even if it conforms to the 8.3
242 * ************************************************************************** **
244 static BOOL
is_illegal_name( char *name
)
252 if( !ct_initialized
)
255 s
= (unsigned char *)name
;
258 skip
= get_character_len( *s
);
265 if( isillegal( *s
) )
273 } /* is_illegal_name */
275 /* ************************************************************************** **
276 * Return True if the name *could be* a mangled name.
278 * Input: s - A path name - in UNIX pathname format.
280 * Output: True if the name matches the pattern described below in the
283 * Notes: The input name is *not* tested for 8.3 compliance. This must be
284 * done separately. This function returns true if the name contains
285 * a magic character followed by excactly two characters from the
286 * basechars list (above), which in turn are followed either by the
287 * nul (end of string) byte or a dot (extension) or by a '/' (end of
290 * ************************************************************************** **
292 BOOL
is_mangled( char *s
)
296 if( !ct_initialized
)
299 magic
= strchr( s
, magic_char
);
300 while( magic
&& magic
[1] && magic
[2] ) /* 3 chars, 1st is magic. */
302 if( ('.' == magic
[3] || '/' == magic
[3] || !(magic
[3])) /* Ends with '.' or nul or '/' ? */
303 && isbasechar( toupper(magic
[1]) ) /* is 2nd char basechar? */
304 && isbasechar( toupper(magic
[2]) ) ) /* is 3rd char basechar? */
305 return( True
); /* If all above, then true, */
306 magic
= strchr( magic
+1, magic_char
); /* else seek next magic. */
311 /* ************************************************************************** **
312 * Return True if the name is a valid DOS name in 8.3 DOS format.
314 * Input: fname - File name to be checked.
315 * check_case - If True, and if case_mangle is True, then the
316 * name will be checked to see if all characters
317 * are the correct case. See case_mangle and
318 * case_default above.
320 * Output: True if the name is a valid DOS name, else FALSE.
322 * ************************************************************************** **
324 BOOL
is_8_3( char *fname
, BOOL check_case
)
331 char *slash_pos
= strrchr( fname
, '/' );
333 /* If there is a directory path, skip it. */
335 fname
= slash_pos
+ 1;
336 len
= strlen( fname
);
338 DEBUG( 5, ( "Checking %s for 8.3\n", fname
) );
340 /* Can't be 0 chars or longer than 12 chars */
341 if( (len
== 0) || (len
> 12) )
344 /* Mustn't be an MS-DOS Special file such as lpt1 or even lpt1.txt */
345 if( is_reserved_msdos( fname
) )
348 /* Check that all characters are the correct case, if asked to do so. */
349 if( check_case
&& case_mangle
)
351 switch( case_default
)
354 if( strhasupper( fname
) )
358 if( strhaslower( fname
) )
364 /* Can't contain invalid dos chars */
365 /* Windows use the ANSI charset.
366 But filenames are translated in the PC charset.
367 This Translation may be more or less relaxed depending
368 the Windows application. */
370 /* %%% A nice improvment to name mangling would be to translate
371 filename to ANSI charset on the smb server host */
377 if( (skip
= get_character_len( *p
)) != 0 )
381 if( *p
== '.' && !dot_pos
)
384 if( !isdoschar( *p
) )
390 /* no dot and less than 9 means OK */
394 l
= PTR_DIFF( dot_pos
, fname
);
396 /* base must be at least 1 char except special cases . and .. */
398 return( 0 == strcmp( fname
, "." ) || 0 == strcmp( fname
, ".." ) );
400 /* base can't be greater than 8 */
404 /* see smb.conf(5) for a description of the 'strip dot' parameter. */
407 && !strchr( dot_pos
+ 1, '.' ) )
413 /* extension must be between 1 and 3 */
414 if( (len
- l
< 2 ) || (len
- l
> 4) )
417 /* extensions may not have a dot */
418 if( strchr( dot_pos
+1, '.' ) )
421 /* must be in 8.3 format */
426 /* ************************************************************************** **
427 * Compare two cache keys and return a value indicating their ordinal
430 * Input: ItemPtr - Pointer to a comparison key. In this case, this will
431 * be a mangled name string.
432 * NodePtr - Pointer to a node in the cache. The node structure
433 * will be followed in memory by a mangled name string.
435 * Output: A signed integer, as follows:
436 * (x < 0) <==> Key1 less than Key2
437 * (x == 0) <==> Key1 equals Key2
438 * (x > 0) <==> Key1 greater than Key2
440 * Notes: This is a ubiqx-style comparison routine. See ubi_BinTree for
443 * ************************************************************************** **
445 static signed int cache_compare( ubi_btItemPtr ItemPtr
, ubi_btNodePtr NodePtr
)
447 char *Key1
= (char *)ItemPtr
;
448 char *Key2
= (char *)(((ubi_cacheEntryPtr
)NodePtr
) + 1);
450 return( StrCaseCmp( Key1
, Key2
) );
451 } /* cache_compare */
453 /* ************************************************************************** **
454 * Free a cache entry.
456 * Input: WarrenZevon - Pointer to the entry that is to be returned to
460 * Notes: This function gets around the possibility that the standard
461 * free() function may be implemented as a macro, or other evil
462 * subversions (oh, so much fun).
464 * ************************************************************************** **
466 static void cache_free_entry( ubi_trNodePtr WarrenZevon
)
468 ZERO_STRUCTP(WarrenZevon
);
470 } /* cache_free_entry */
472 /* ************************************************************************** **
473 * Initializes or clears the mangled cache.
478 * Notes: There is a section below that is commented out. It shows how
479 * one might use lp_ calls to set the maximum memory and entry size
480 * of the cache. You might also want to remove the constants used
481 * in ubi_cacheInit() and replace them with lp_ calls. If so, then
482 * the calls to ubi_cacheSetMax*() would be moved into the else
483 * clause. Another option would be to pass in the max_entries and
484 * max_memory values as parameters. crh 09-Apr-1998.
486 * ************************************************************************** **
488 void reset_mangled_cache( void )
490 if( !mc_initialized
)
492 (void)ubi_cacheInit( mangled_cache
,
495 MANGLED_CACHE_MAX_ENTRIES
,
496 MANGLED_CACHE_MAX_MEMORY
);
497 mc_initialized
= True
;
501 (void)ubi_cacheClear( mangled_cache
);
505 (void)ubi_cacheSetMaxEntries( mangled_cache, lp_mangled_cache_entries() );
506 (void)ubi_cacheSetMaxMemory( mangled_cache, lp_mangled_cache_memory() );
508 } /* reset_mangled_cache */
511 /* ************************************************************************** **
512 * Add a mangled name into the cache.
514 * Notes: If the mangled cache has not been initialized, then the
515 * function will simply fail. It could initialize the cache,
516 * but that's not the way it was done before I changed the
517 * cache mechanism, so I'm sticking with the old method.
519 * If the extension of the raw name maps directly to the
520 * extension of the mangled name, then we'll store both names
521 * *without* extensions. That way, we can provide consistent
522 * reverse mangling for all names that match. The test here is
523 * a bit more careful than the one done in earlier versions of
526 * - the extension must exist on the raw name,
527 * - it must be all lower case
528 * - it must match the mangled extension (to prove that no
529 * mangling occurred).
533 * ************************************************************************** **
535 static void cache_mangled_name( char *mangled_name
, char *raw_name
)
537 ubi_cacheEntryPtr new_entry
;
544 /* If the cache isn't initialized, give up. */
545 if( !mc_initialized
)
548 /* Init the string lengths. */
549 mangled_len
= strlen( mangled_name
);
550 raw_len
= strlen( raw_name
);
552 /* See if the extensions are unmangled. If so, store the entry
553 * without the extension, thus creating a "group" reverse map.
555 s1
= strrchr( mangled_name
, '.' );
556 if( s1
&& (s2
= strrchr( raw_name
, '.' )) )
559 while( s1
[i
] && (tolower( s1
[1] ) == s2
[i
]) )
561 if( !s1
[i
] && !s2
[i
] )
568 /* Allocate a new cache entry. If the allocation fails, just return. */
569 i
= sizeof( ubi_cacheEntry
) + mangled_len
+ raw_len
+ 2;
570 new_entry
= malloc( i
);
574 /* Fill the new cache entry, and add it to the cache. */
575 s1
= (char *)(new_entry
+ 1);
576 s2
= (char *)&(s1
[mangled_len
+ 1]);
577 (void)StrnCpy( s1
, mangled_name
, mangled_len
);
578 (void)StrnCpy( s2
, raw_name
, raw_len
);
580 /* possibly delete an old entry - this avoids a memory leak in the
581 ubi code to do with overwriting existing entries.
583 remove this test when ubi gets fixed */
584 if (ubi_cacheGet(mangled_cache
, s1
)) {
585 ubi_cacheDelete(mangled_cache
, s1
);
588 ubi_cachePut( mangled_cache
, i
, new_entry
, s1
);
589 } /* cache_mangled_name */
591 /* ************************************************************************** **
592 * Check for a name on the mangled name stack
594 * Input: s - Input *and* output string buffer.
596 * Output: True if the name was found in the cache, else False.
598 * Notes: If a reverse map is found, the function will overwrite the string
599 * space indicated by the input pointer <s>. This is frightening.
600 * It should be rewritten to return NULL if the long name was not
601 * found, and a pointer to the long name if it was found.
603 * ************************************************************************** **
606 BOOL
check_mangled_cache( char *s
)
608 ubi_cacheEntryPtr FoundPtr
;
609 char *ext_start
= NULL
;
611 char *saved_ext
= NULL
;
613 /* If the cache isn't initialized, give up. */
614 if( !mc_initialized
)
617 FoundPtr
= ubi_cacheGet( mangled_cache
, (ubi_trItemPtr
)s
);
619 /* If we didn't find the name *with* the extension, try without. */
622 ext_start
= strrchr( s
, '.' );
625 if((saved_ext
= strdup(ext_start
)) == NULL
)
629 FoundPtr
= ubi_cacheGet( mangled_cache
, (ubi_trItemPtr
)s
);
631 * At this point s is the name without the
632 * extension. We re-add the extension if saved_ext
633 * is not null, before freeing saved_ext.
638 /* Okay, if we haven't found it we're done. */
643 /* Replace the saved_ext as it was truncated. */
644 (void)pstrcat( s
, saved_ext
);
650 /* If we *did* find it, we need to copy it into the string buffer. */
651 found_name
= (char *)(FoundPtr
+ 1);
652 found_name
+= (strlen( found_name
) + 1);
654 DEBUG( 3, ("Found %s on mangled stack ", s
) );
656 (void)pstrcpy( s
, found_name
);
659 /* Replace the saved_ext as it was truncated. */
660 (void)pstrcat( s
, saved_ext
);
664 DEBUG( 3, ("as %s\n", s
) );
667 } /* check_mangled_cache */
670 /* ************************************************************************** **
671 * Used only in do_fwd_mangled_map(), below.
672 * ************************************************************************** **
674 static char *map_filename( char *s
, /* This is null terminated */
675 char *pattern
, /* This isn't. */
676 int len
) /* This is the length of pattern. */
678 static pstring matching_bit
; /* The bit of the string which matches */
679 /* a * in pattern if indeed there is a * */
680 char *sp
; /* Pointer into s. */
681 char *pp
; /* Pointer into p. */
682 char *match_start
; /* Where the matching bit starts. */
685 StrnCpy( pat
, pattern
, len
); /* Get pattern into a proper string! */
686 pstrcpy( matching_bit
, "" ); /* Match but no star gets this. */
687 pp
= pat
; /* Initialize the pointers. */
690 if( strequal(s
, ".") || strequal(s
, ".."))
692 return NULL
; /* Do not map '.' and '..' */
695 if( (len
== 1) && (*pattern
== '*') )
697 return NULL
; /* Impossible, too ambiguous for */
700 while( (*sp
) /* Not the end of the string. */
701 && (*pp
) /* Not the end of the pattern. */
702 && (*sp
== *pp
) /* The two match. */
703 && (*pp
!= '*') ) /* No wildcard. */
705 sp
++; /* Keep looking. */
709 if( !*sp
&& !*pp
) /* End of pattern. */
710 return( matching_bit
); /* Simple match. Return empty string. */
714 pp
++; /* Always interrested in the chacter */
716 if( !*pp
) /* It is at the end of the pattern. */
718 StrnCpy( matching_bit
, s
, sp
-s
);
719 return( matching_bit
);
723 /* The next character in pattern must match a character further */
724 /* along s than sp so look for that character. */
726 while( (*sp
) /* Not the end of s. */
727 && (*sp
!= *pp
) ) /* Not the same */
728 sp
++; /* Keep looking. */
729 if( !*sp
) /* Got to the end without a match. */
732 } /* Still hope for a match. */
735 /* Now sp should point to a matching character. */
736 StrnCpy(matching_bit
, match_start
, sp
-match_start
);
737 /* Back to needing a stright match again. */
738 while( (*sp
) /* Not the end of the string. */
739 && (*pp
) /* Not the end of the pattern. */
740 && (*sp
== *pp
) ) /* The two match. */
742 sp
++; /* Keep looking. */
745 if( !*sp
&& !*pp
) /* Both at end so it matched */
746 return( matching_bit
);
752 return( NULL
); /* No match. */
756 /* ************************************************************************** **
757 * MangledMap is a series of name pairs in () separated by spaces.
758 * If s matches the first of the pair then the name given is the
759 * second of the pair. A * means any number of any character and if
760 * present in the second of the pair as well as the first the
761 * matching part of the first string takes the place of the * in the
764 * I wanted this so that we could have RCS files which can be used
765 * by UNIX and DOS programs. My mapping string is (RCS rcs) which
766 * converts the UNIX RCS file subdirectory to lowercase thus
767 * preventing mangling.
769 * (I think Andrew wrote the above, but I'm not sure. -- CRH)
771 * See 'mangled map' in smb.conf(5).
773 * ************************************************************************** **
775 static void do_fwd_mangled_map(char *s
, char *MangledMap
)
777 char *start
=MangledMap
; /* Use this to search for mappings. */
778 char *end
; /* Used to find the end of strings. */
780 pstring new_string
; /* Make up the result here. */
781 char *np
; /* Points into new_string. */
783 DEBUG( 5, ("Mangled Mapping '%s' map '%s'\n", s
, MangledMap
) );
786 while( (*start
) && (*start
!= '(') )
789 continue; /* Always check for the end. */
790 start
++; /* Skip the ( */
791 end
= start
; /* Search for the ' ' or a ')' */
792 DEBUG( 5, ("Start of first in pair '%s'\n", start
) );
793 while( (*end
) && !((*end
== ' ') || (*end
== ')')) )
798 continue; /* Always check for the end. */
800 DEBUG( 5, ("End of first in pair '%s'\n", end
) );
801 if( (match_string
= map_filename( s
, start
, end
-start
)) )
803 DEBUG( 5, ("Found a match\n") );
805 start
= end
+ 1; /* Point to start of what it is to become. */
806 DEBUG( 5, ("Start of second in pair '%s'\n", start
) );
809 while( (*end
) /* Not the end of string. */
810 && (*end
!= ')') /* Not the end of the pattern. */
811 && (*end
!= '*') ) /* Not a wildcard. */
816 continue; /* Always check for the end. */
820 pstrcpy( np
, match_string
);
821 np
+= strlen( match_string
);
822 end
++; /* Skip the '*' */
823 while( (*end
) /* Not the end of string. */
824 && (*end
!= ')') /* Not the end of the pattern. */
825 && (*end
!= '*') ) /* Not a wildcard. */
831 continue; /* Always check for the end. */
833 *np
++ = '\0'; /* NULL terminate it. */
834 DEBUG(5,("End of second in pair '%s'\n", end
));
835 pstrcpy( s
, new_string
); /* Substitute with the new name. */
836 DEBUG( 5, ("s is now '%s'\n", s
) );
838 start
= end
; /* Skip a bit which cannot be wanted anymore. */
841 } /* do_fwd_mangled_map */
843 /*****************************************************************************
844 * do the actual mangling to 8.3 format
845 * the buffer must be able to hold 13 characters (including the null)
846 *****************************************************************************
848 void mangle_name_83( char *s
)
862 if( p
&& (strlen(p
+1) < (size_t)4) )
864 BOOL all_normal
= ( strisnormal(p
+1) ); /* XXXXXXXXX */
866 if( all_normal
&& p
[1] != 0 )
869 csum
= str_checksum( s
);
873 csum
= str_checksum(s
);
876 csum
= str_checksum(s
);
880 DEBUG( 5, ("Mangling name %s to ",s
) );
885 safe_strcpy( extension
, "___", 3 );
889 while( *p
&& extlen
< 3 )
891 skip
= get_character_len( *p
);
897 extension
[extlen
++] = p
[0];
898 extension
[extlen
++] = p
[1];
902 extension
[extlen
++] = mangle( (unsigned char)*p
);
907 extension
[extlen
++] = p
[0];
911 if( isdoschar (*p
) && *p
!= '.' )
912 extension
[extlen
++] = p
[0];
917 extension
[extlen
] = 0;
923 while( *p
&& baselen
< 5 )
925 skip
= get_character_len(*p
);
931 base
[baselen
++] = p
[0];
932 base
[baselen
++] = p
[1];
936 base
[baselen
++] = mangle( (unsigned char)*p
);
941 base
[baselen
++] = p
[0];
945 if( isdoschar( *p
) && *p
!= '.' )
946 base
[baselen
++] = p
[0];
953 csum
= csum
% (MANGLE_BASE
*MANGLE_BASE
);
955 (void)slprintf(s
, 12, "%s%c%c%c",
956 base
, magic_char
, mangle( csum
/MANGLE_BASE
), mangle( csum
) );
960 (void)pstrcat( s
, "." );
961 (void)pstrcat( s
, extension
);
964 DEBUG( 5, ( "%s\n", s
) );
966 } /* mangle_name_83 */
968 /*****************************************************************************
969 * Convert a filename to DOS format. Return True if successful.
971 * Input: OutName - Source *and* destination buffer.
973 * NOTE that OutName must point to a memory space that
974 * is at least 13 bytes in size!
976 * need83 - If False, name mangling will be skipped unless the
977 * name contains illegal characters. Mapping will still
978 * be done, if appropriate. This is probably used to
979 * signal that a client does not require name mangling,
980 * thus skipping the name mangling even on shares which
981 * have name-mangling turned on.
982 * cache83 - If False, the mangled name cache will not be updated.
983 * This is usually used to prevent that we overwrite
984 * a conflicting cache entry prematurely, i.e. before
985 * we know whether the client is really interested in the
986 * current name. (See PR#13758). UKD.
987 * snum - Share number. This identifies the share in which the
990 * Output: Returns False only if the name wanted mangling but the share does
991 * not have name mangling turned on.
993 * ****************************************************************************
995 BOOL
name_map_mangle(char *OutName
, BOOL need83
, BOOL cache83
, int snum
)
998 DEBUG(5,("name_map_mangle( %s, need83 = %s, cache83 = %s, %d )\n", OutName
,
999 need83
? "TRUE" : "FALSE", cache83
? "TRUE" : "FALSE", snum
));
1001 #ifdef MANGLE_LONG_FILENAMES
1002 if( !need83
&& is_illegal_name(OutName
) )
1006 /* apply any name mappings */
1007 map
= lp_mangled_map(snum
);
1010 do_fwd_mangled_map( OutName
, map
);
1013 /* check if it's already in 8.3 format */
1014 if (need83
&& !is_8_3(OutName
, True
)) {
1017 if (!lp_manglednames(snum
)) {
1021 /* mangle it into 8.3 */
1023 tmp
= strdup(OutName
);
1025 mangle_name_83(OutName
);
1028 cache_mangled_name(OutName
, tmp
);
1033 DEBUG(5,("name_map_mangle() ==> [%s]\n", OutName
));
1035 } /* name_map_mangle */