Improved stat cache code by uppercasing any search name that gets added to
authorJeremy Allison <jra@samba.org>
Thu, 10 Sep 1998 00:35:10 +0000 (00:35 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 10 Sep 1998 00:35:10 +0000 (00:35 +0000)
it if we're in case insensitive mode, and then doing a memcmp rather
than a StrnCaseCmp (which is *horribly* slow) on every lookup.
Fixed bug with refusing NT SMB's (use *brackets* where needed :-).
Jeremy.

source/smbd/filename.c
source/smbd/negprot.c

index 0910e03ee3409c7c6cc071bb7273cd4727212983..caba4064d7b081a2be3b56f3e81d1ab52aaa5c11 100644 (file)
@@ -114,27 +114,18 @@ typedef struct {
 
 static ubi_dlList stat_cache = { NULL, (ubi_dlNodePtr)&stat_cache, 0};
 
-/****************************************************************************
- Compare two names in the stat cache - to check if we already have such an
- entry.
-*****************************************************************************/
-
-static BOOL stat_name_equal( char *s1, char *s2)
-{
-  return (case_sensitive ? (strcmp( s1, s2) == 0) : (StrCaseCmp(s1, s2) == 0));
-}
-
 /****************************************************************************
  Compare a pathname to a name in the stat cache - of a given length.
  Note - this code always checks that the next character in the pathname
  is either a '/' character, or a '\0' character - to ensure we only
- match *full* pathname components.
+ match *full* pathname components. Note we don't need to handle case
+ here, if we're case insensitive the stat cache orig names are all upper
+ case.
 *****************************************************************************/
 
 static BOOL stat_name_equal_len( char *stat_name, char *orig_name, int len)
 {
-  BOOL matched = (case_sensitive ? (strncmp( stat_name, orig_name, len) == 0) :
-                           (StrnCaseCmp(stat_name, orig_name, len) == 0));
+  BOOL matched = (memcmp( stat_name, orig_name, len) == 0);
   if(orig_name[len] != '/' && orig_name[len] != '\0')
     return False;
 
@@ -159,7 +150,7 @@ static void stat_cache_add( char *full_orig_name, char *orig_translated_path)
   /*
    * Don't cache trivial valid directory entries.
    */
-  if(strequal(full_orig_name, ".") || strequal(full_orig_name, ".."))
+  if((strcmp(full_orig_name, ".") == 0) || (strcmp(full_orig_name, "..") == 0))
     return;
 
   /*
@@ -189,6 +180,8 @@ static void stat_cache_add( char *full_orig_name, char *orig_translated_path)
    */
 
   StrnCpy(orig_name, full_orig_name, namelen);
+  if(!case_sensitive)
+    strupper( orig_name );
 
   /*
    * Check this name doesn't exist in the cache before we 
@@ -197,7 +190,7 @@ static void stat_cache_add( char *full_orig_name, char *orig_translated_path)
 
   for( scp = (stat_cache_entry *)ubi_dlFirst( &stat_cache); scp; 
                         scp = (stat_cache_entry *)ubi_dlNext( scp )) {
-    if(stat_name_equal( scp->orig_name, orig_name) &&
+    if((strcmp( scp->orig_name, orig_name) == 0) &&
        (strcmp( scp->translated_name, translated_path) == 0)) {
       /*
        * Name does exist - promote it.
@@ -239,6 +232,7 @@ static BOOL stat_cache_lookup( char *name, char *dirpath, char **start, SMB_STRU
 {
   stat_cache_entry *scp;
   stat_cache_entry *longest_hit = NULL;
+  pstring chk_name;
   int namelen;
 
   if (!lp_stat_cache()) return False;
@@ -251,15 +245,19 @@ static BOOL stat_cache_lookup( char *name, char *dirpath, char **start, SMB_STRU
   /*
    * Don't lookup trivial valid directory entries.
    */
-  if(strequal(name, ".") || strequal(name, "..")) {
+  if((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
     global_stat_cache_misses++;
     return False;
   }
 
+  pstrcpy(chk_name, name);
+  if(!case_sensitive)
+    strupper( chk_name );
+
   for( scp = (stat_cache_entry *)ubi_dlFirst( &stat_cache); scp; 
                         scp = (stat_cache_entry *)ubi_dlNext( scp )) {
     if(scp->name_len <= namelen) {
-      if(stat_name_equal_len(scp->orig_name, name, scp->name_len)) {
+      if(stat_name_equal_len(scp->orig_name, chk_name, scp->name_len)) {
         if((longest_hit == NULL) || (longest_hit->name_len <= scp->name_len))
           longest_hit = scp;
       }
index b1e8a65c949f8cc9fb85fa498bb0187965d8e2f3..6a9cc9fb9bd6e6faf355f6528ba5e8600b3bd061 100644 (file)
@@ -156,8 +156,8 @@ reply for the nt protocol
 static int reply_nt1(char *outbuf)
 {
   /* dual names + lock_and_read + nt SMBs + remote API calls */
-  int capabilities = CAP_NT_FIND|CAP_LOCK_AND_READ|CAP_RPC_REMOTE_APIS |
-                     lp_nt_smb_support() ? CAP_NT_SMBS : 0;
+  int capabilities = CAP_NT_FIND|CAP_LOCK_AND_READ|
+                     (lp_nt_smb_support() ? CAP_NT_SMBS | CAP_RPC_REMOTE_APIS : 0);
 
 /*
   other valid capabilities which we may support at some time...