svn commit: samba r6965 - in branches/SAMBA_3_0/source: lib smbd

jra at samba.org jra at samba.org
Wed May 25 00:51:39 GMT 2005


Author: jra
Date: 2005-05-25 00:51:39 +0000 (Wed, 25 May 2005)
New Revision: 6965

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6965

Log:
Remove some dead code from util_unistr.c.
Start of fix for #2735 - we are not mangling some
names we should. More fixes to follow.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/lib/util_unistr.c
   branches/SAMBA_3_0/source/smbd/mangle_hash.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/util_unistr.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_unistr.c	2005-05-24 23:53:56 UTC (rev 6964)
+++ branches/SAMBA_3_0/source/lib/util_unistr.c	2005-05-25 00:51:39 UTC (rev 6965)
@@ -255,22 +255,6 @@
 }
 
 /*******************************************************************
- Return a DOS codepage version of a little-endian unicode string.
- len is the filename length (ignoring any terminating zero) in uin16
- units. Always null terminates.
- Hack alert: uses fixed buffer(s).
-********************************************************************/
-char *dos_unistrn2(const uint16 *src, int len)
-{
-	static char lbufs[8][MAXUNI];
-	static int nexti;
-	char *lbuf = lbufs[nexti];
-	nexti = (nexti+1)%8;
-	pull_ucs2(NULL, lbuf, src, MAXUNI-3, len*2, STR_NOALIGN);
-	return lbuf;
-}
-
-/*******************************************************************
  Convert a (little-endian) UNISTR2 structure to an ASCII string
 ********************************************************************/
 void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen)

Modified: branches/SAMBA_3_0/source/smbd/mangle_hash.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/mangle_hash.c	2005-05-24 23:53:56 UTC (rev 6964)
+++ branches/SAMBA_3_0/source/smbd/mangle_hash.c	2005-05-25 00:51:39 UTC (rev 6965)
@@ -20,36 +20,8 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-
-/* -------------------------------------------------------------------------- **
- * Notable problems...
- *
- *  March/April 1998  CRH
- *  - Many of the functions in this module overwrite string buffers passed to
- *    them.  This causes a variety of problems and is, generally speaking,
- *    dangerous and scarry.  See the kludge notes in name_map()
- *    below.
- *  - It seems that something is calling name_map() twice.  The
- *    first call is probably some sort of test.  Names which contain
- *    illegal characters are being doubly mangled.  I'm not sure, but
- *    I'm guessing the problem is in server.c.
- *
- * -------------------------------------------------------------------------- **
- */
-
-/* -------------------------------------------------------------------------- **
- * History...
- *
- *  March/April 1998  CRH
- *  Updated a bit.  Rewrote is_mangled() to be a bit more selective.
- *  Rewrote the mangled name cache.  Added comments here and there.
- *  &c.
- * -------------------------------------------------------------------------- **
- */
-
 #include "includes.h"
 
-
 /* -------------------------------------------------------------------------- **
  * Other stuff...
  *
@@ -67,24 +39,17 @@
  *
  * chartest       - array 0..255.  The index range is the set of all possible
  *                  values of a byte.  For each byte value, the content is a
- *                  two nibble pair.  See BASECHAR_MASK and ILLEGAL_MASK,
- *                  below.
+ *                  two nibble pair.  See BASECHAR_MASK below.
  *
  * ct_initialized - False until the chartest array has been initialized via
  *                  a call to init_chartest().
  *
  * BASECHAR_MASK  - Masks the upper nibble of a one-byte value.
  *
- * ILLEGAL_MASK   - Masks the lower nibble of a one-byte value.
- *
  * isbasecahr()   - Given a character, check the chartest array to see
  *                  if that character is in the basechars set.  This is
  *                  faster than using strchr_m().
  *
- * isillegal()    - Given a character, check the chartest array to see
- *                  if that character is in the illegal characters set.
- *                  This is faster than using strchr_m().
- *
  */
 
 char magic_char = '~';
@@ -97,9 +62,7 @@
 
 #define mangle(V) ((char)(basechars[(V) % MANGLE_BASE]))
 #define BASECHAR_MASK 0xf0
-#define ILLEGAL_MASK  0x0f
 #define isbasechar(C) ( (chartest[ ((C) & 0xff) ]) & BASECHAR_MASK )
-#define isillegal(C) ( (chartest[ ((C) & 0xff) ]) & ILLEGAL_MASK )
 
 static TDB_CONTEXT *tdb_mangled_cache;
 
@@ -107,23 +70,44 @@
 
 static NTSTATUS has_valid_83_chars(const smb_ucs2_t *s, BOOL allow_wildcards)
 {
-	if (!s || !*s)
+	if (!*s) {
 		return NT_STATUS_INVALID_PARAMETER;
+	}
 
-	/* CHECK: this should not be necessary if the ms wild chars
-	   are not valid in valid.dat  --- simo */
-	if (!allow_wildcards && ms_has_wild_w(s))
+	if (!allow_wildcards && ms_has_wild_w(s)) {
 		return NT_STATUS_UNSUCCESSFUL;
+	}
 
 	while (*s) {
-		if(!isvalid83_w(*s))
+		if(!isvalid83_w(*s)) {
 			return NT_STATUS_UNSUCCESSFUL;
+		}
 		s++;
 	}
 
 	return NT_STATUS_OK;
 }
 
+static NTSTATUS has_illegal_chars(const smb_ucs2_t *s, BOOL allow_wildcards)
+{
+	if (!allow_wildcards && ms_has_wild_w(s)) {
+		return NT_STATUS_UNSUCCESSFUL;
+	}
+
+	while (*s) {
+		switch(*s) {
+			case UCS2_CHAR('\\'):
+			case UCS2_CHAR('/'):
+			case UCS2_CHAR('|'):
+			case UCS2_CHAR(':'):
+				return NT_STATUS_UNSUCCESSFUL;
+		}
+		s++;
+	}
+
+	return NT_STATUS_OK;
+}
+
 /* return False if something fail and
  * return 2 alloced unicode strings that contain prefix and extension
  */
@@ -156,10 +140,11 @@
 
 /* ************************************************************************** **
  * Return NT_STATUS_UNSUCCESSFUL if a name is a special msdos reserved name.
+ * or contains illegal characters.
  *
  *  Input:  fname - String containing the name to be tested.
  *
- *  Output: NT_STATUS_UNSUCCESSFUL, if the name matches one of the list of reserved names.
+ *  Output: NT_STATUS_UNSUCCESSFUL, if the condition above is true.
  *
  *  Notes:  This is a static function called by is_8_3(), below.
  *
@@ -188,6 +173,10 @@
 			return ret;
 	}
 
+	ret = has_illegal_chars(fname, allow_wildcards);
+	if (!NT_STATUS_IS_OK(ret))
+		return ret;
+
 	str = strdup_w(fname);
 	p = strchr_w(str, UCS2_CHAR('.'));
 	if (p && p[1] == UCS2_CHAR(0)) {
@@ -333,16 +322,13 @@
  */
 static void init_chartest( void )
 {
-	const char          *illegalchars = "*\\/?<>|\":";
 	const unsigned char *s;
   
 	memset( (char *)chartest, '\0', 256 );
 
-	for( s = (const unsigned char *)illegalchars; *s; s++ )
-		chartest[*s] = ILLEGAL_MASK;
-
-	for( s = (const unsigned char *)basechars; *s; s++ )
+	for( s = (const unsigned char *)basechars; *s; s++ ) {
 		chartest[*s] |= BASECHAR_MASK;
+	}
 
 	ct_initialized = True;
 }
@@ -566,7 +552,7 @@
 	p = s;
 
 	while( *p && baselen < 5 ) {
-		if (*p != '.') {
+		if (isbasechar(*p)) {
 			base[baselen++] = p[0];
 		}
 		p++;



More information about the samba-cvs mailing list