]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/directory.c
Back-port from HEAD: Do directory name matching using strcmp(), not
[netatalk.git] / etc / afpd / directory.c
index 02fb04fe842f571092a31eb9fba433d89b4093d1..43fb6d150312f4bd118e4b9d6677b50626c511e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.38 2002-08-29 18:57:26 didg Exp $
+ * $Id: directory.c,v 1.41.2.2 2002-11-07 17:10:02 srittau Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -59,10 +59,6 @@ char *strchr (), *strrchr ();
 #include "globals.h"
 #include "unix.h"
 
-#ifdef FORCE_UIDGID
-#include "uid.h"
-#endif /* FORCE_UIDGID */
-
 struct dir     *curdir;
 
 #define SENTINEL (&sentinel)
@@ -139,7 +135,8 @@ u_int32_t   did;
     char *ptr;
     static char buffer[12 + MAXPATHLEN + 1];
     int buflen = 12 + MAXPATHLEN + 1;
-
+    char *mpath;
+    
     ret = dirsearch(vol, did);
     if (ret != NULL)
         return ret;
@@ -149,10 +146,11 @@ u_int32_t did;
         return NULL;
     }
     ptr = path + MAXPATHLEN;
-    len = strlen(upath);
+    mpath = utompath(vol, upath);
+    len = strlen(mpath);
     pathlen = len;          /* no 0 in the last part */
     len++;
-    strcpy(ptr - len, upath);
+    strcpy(ptr - len, mpath);
     ptr -= len;
     while (1) {
         ret = dirsearch(vol,id);
@@ -161,11 +159,12 @@ u_int32_t did;
         }
         if ((upath = cnid_resolve(vol->v_db, &id, buffer, buflen)) == NULL)
             return NULL;
-        len = strlen(upath) + 1;
+        mpath = utompath(vol, upath);
+        len = strlen(mpath) + 1;
         pathlen += len;
         if (pathlen > 255)
             return NULL;
-        strcpy(ptr - len, upath);
+        strcpy(ptr - len, mpath);
         ptr -= len;
     }
     /* fill the cache */
@@ -866,7 +865,7 @@ char        **cpath;
             if ( !extend ) {
                 cdir = dir->d_child;
                 while (cdir) {
-                    if ( strcasecmp( cdir->d_name, path ) == 0 ) {
+                    if ( strcmp( cdir->d_name, path ) == 0 ) {
                         break;
                     }
                     cdir = (cdir == dir->d_child->d_prev) ? NULL :
@@ -882,7 +881,8 @@ char        **cpath;
                        /* dir is not valid anymore 
                           we delete dir from the cache and abort.
                        */
-                       dir_invalidate(vol, dir);
+                       if ( dir->d_did != DIRDID_ROOT_PARENT) 
+                           dir_invalidate(vol, dir);
                         return( NULL );
                     }
                     cdir = extenddir( vol, dir, path );
@@ -960,18 +960,9 @@ int getdirparams(const struct vol *vol,
     int                        bit = 0, isad = 1;
     u_int32_t           aint;
     u_int16_t          ashort;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
 
     memset(&ad, 0, sizeof(ad));
 
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-    set_uidgid ( vol );
-#endif /* FORCE_UIDGID */
-
     if ( ad_open( upath, ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
                   DIRBITS | 0777, &ad) < 0 ) {
         isad = 0;
@@ -1134,9 +1125,6 @@ int getdirparams(const struct vol *vol,
             if ( isad ) {
                 ad_close( &ad, ADFLAGS_HF );
             }
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_BITMAP );
         }
         bitmap = bitmap>>1;
@@ -1187,7 +1175,7 @@ int               ibuflen, *rbuflen;
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( int );
 
-    if (( dir = dirsearch( vol, did )) == NULL ) {
+    if (( dir = dirlookup( vol, did )) == NULL ) {
         return( AFPERR_NOOBJ );
     }
 
@@ -1236,17 +1224,9 @@ int setdirparams(const struct vol *vol,
     int                 change_mdate = 0;
     int                 change_parent_mdate = 0;
     int                 newdate = 0;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
 
     upath = mtoupath(vol, path);
     memset(&ad, 0, sizeof(ad));
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
 
     if (ad_open( upath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
                  O_RDWR|O_CREAT, 0666, &ad) < 0) {
@@ -1261,9 +1241,6 @@ int setdirparams(const struct vol *vol,
         if (!vol_noadouble(vol) && (bitmap &
                                     ~((1<<DIRPBIT_ACCESS)|(1<<DIRPBIT_UID)|(1<<DIRPBIT_GID)|
                                       (1<<DIRPBIT_MDATE)|(1<<DIRPBIT_PDINFO)))) {
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return AFPERR_ACCESS;
         }
 
@@ -1519,10 +1496,6 @@ setdirparam_done:
         ad_close( &ad, ADFLAGS_HF );
     }
 
-#ifdef FORCE_UIDGID
-    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
-
     if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
             && gettimeofday(&tv, NULL) == 0) {
        if (!movecwd(vol, curdir->d_parent)) {
@@ -1548,11 +1521,6 @@ int              ibuflen, *rbuflen;
     char               *path, *upath;
     u_int32_t          did;
     u_int16_t          vid;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
 
     *rbuflen = 0;
     ibuf += 2;
@@ -1568,7 +1536,7 @@ int               ibuflen, *rbuflen;
 
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( did );
-    if (( dir = dirsearch( vol, did )) == NULL ) {
+    if (( dir = dirlookup( vol, did )) == NULL ) {
         return( AFPERR_NOOBJ );
     }
 
@@ -1593,15 +1561,7 @@ int              ibuflen, *rbuflen;
         }
     }
 
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-    set_uidgid  ( vol );
-#endif /* FORCE_UIDGID */
-
     if ( ad_mkdir( upath, DIRBITS | 0777 ) < 0 ) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         switch ( errno ) {
         case ENOENT :
             return( AFPERR_NOOBJ );
@@ -1620,24 +1580,15 @@ int             ibuflen, *rbuflen;
     }
 
     if (stat(upath, &st) < 0) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return AFPERR_MISC;
     }
 
     if ((dir = adddir( vol, curdir, path, strlen( path ), upath,
                        strlen(upath), &st)) == NULL) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return AFPERR_MISC;
     }
 
     if ( movecwd( vol, dir ) < 0 ) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return( AFPERR_PARAM );
     }
 
@@ -1646,9 +1597,6 @@ int               ibuflen, *rbuflen;
                  O_RDWR|O_CREAT, 0666, &ad ) < 0)  {
         if (vol_noadouble(vol))
             goto createdir_done;
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return( AFPERR_ACCESS );
     }
 
@@ -1662,9 +1610,6 @@ createdir_done:
     memcpy( rbuf, &dir->d_did, sizeof( u_int32_t ));
     *rbuflen = sizeof( u_int32_t );
     setvoltime(obj, vol );
-#ifdef FORCE_UIDGID
-    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
     return( AFP_OK );
 }
 
@@ -1762,11 +1707,6 @@ int pathlen;
     DIR *dp;
     struct adouble     ad;
     u_int16_t          ashort;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
 
     if ( curdir->d_parent == NULL ) {
         return( AFPERR_ACCESS );
@@ -1778,11 +1718,6 @@ int pathlen;
 
     fdir = curdir;
 
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-    set_uidgid  ( vol );
-#endif /* FORCE_UIDGID */
-
     memset(&ad, 0, sizeof(ad));
     if ( ad_open( ".", ADFLAGS_HF|ADFLAGS_DIR, O_RDONLY,
                   DIRBITS | 0777, &ad) == 0 ) {
@@ -1790,9 +1725,6 @@ int pathlen;
         ad_getattr(&ad, &ashort);
         ad_close( &ad, ADFLAGS_HF );
         if ((ashort & htons(ATTRBIT_NODELETE))) {
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return  AFPERR_OLOCK;
         }
     }
@@ -1810,9 +1742,6 @@ int pathlen;
              * note: this will not fail with dangling symlinks */
             if (stat(de->d_name, &st) == 0) {
                 closedir(dp);
-#ifdef FORCE_UIDGID
-                restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                 return AFPERR_DIRNEMPT;
             }
 
@@ -1822,21 +1751,12 @@ int pathlen;
                 switch (errno) {
                 case EPERM:
                 case EACCES :
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return( AFPERR_ACCESS );
                 case EROFS:
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return AFPERR_VLOCK;
                 case ENOENT :
                     continue;
                 default :
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return( AFPERR_PARAM );
                 }
             }
@@ -1849,25 +1769,13 @@ int pathlen;
         case ENOENT :
             break;
         case ENOTEMPTY :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_DIRNEMPT );
         case EROFS:
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return AFPERR_VLOCK;
         case EPERM:
         case EACCES :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_ACCESS );
         default :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_PARAM );
         }
     }
@@ -1881,9 +1789,6 @@ int pathlen;
 
             /* bail if it's not a symlink */
             if ((lstat(de->d_name, &st) == 0) && !S_ISLNK(st.st_mode)) {
-#ifdef FORCE_UIDGID
-                restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                 return AFPERR_DIRNEMPT;
             }
 
@@ -1891,21 +1796,12 @@ int pathlen;
                 switch (errno) {
                 case EPERM:
                 case EACCES :
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return( AFPERR_ACCESS );
                 case EROFS:
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return AFPERR_VLOCK;
                 case ENOENT :
                     continue;
                 default :
-#ifdef FORCE_UIDGID
-                    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
                     return( AFPERR_PARAM );
                 }
             }
@@ -1914,39 +1810,21 @@ int pathlen;
     }
 
     if ( movecwd( vol, curdir->d_parent ) < 0 ) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return( AFPERR_NOOBJ );
     }
 
     if ( rmdir(mtoupath(vol, fdir->d_name)) < 0 ) {
         switch ( errno ) {
         case ENOENT :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_NOOBJ );
         case ENOTEMPTY :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_DIRNEMPT );
         case EPERM:
         case EACCES :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_ACCESS );
         case EROFS:
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return AFPERR_VLOCK;
         default :
-#ifdef FORCE_UIDGID
-            restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
             return( AFPERR_PARAM );
         }
     }
@@ -1957,9 +1835,6 @@ int pathlen;
 #endif /* CNID_DB */
     dir_remove( vol, fdir );
 
-#ifdef FORCE_UIDGID
-    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
     return( AFP_OK );
 }
 
@@ -2090,7 +1965,7 @@ int               ibuflen, *rbuflen;
 
     memcpy( &did, ibuf, sizeof( did ));
     ibuf += sizeof( did );
-    if (( dir = dirsearch( vol, did )) == NULL ) {
+    if (( dir = dirlookup( vol, did )) == NULL ) {
         return( AFPERR_PARAM );
     }
 
@@ -2112,11 +1987,6 @@ int              ibuflen, *rbuflen;
     char               *path, *upath;
     u_int32_t          did;
     u_int16_t          vid;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
 
     *rbuflen = 0;
     ibuf += 2;
@@ -2131,7 +2001,7 @@ int               ibuflen, *rbuflen;
     memcpy(&did, ibuf, sizeof(did));
     ibuf += sizeof(did);
 
-    if (( parentdir = dirsearch( vol, did )) == NULL ) {
+    if (( parentdir = dirlookup( vol, did )) == NULL ) {
         return( AFPERR_NOOBJ );
     }
 
@@ -2160,24 +2030,13 @@ int             ibuflen, *rbuflen;
         dir = (dir == parentdir->d_child->d_prev) ? NULL : dir->d_next;
     }
 
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-    set_uidgid  ( vol );
-#endif /* FORCE_UIDGID */
-
     /* we don't already have a did. add one in. */
     if ((dir = adddir(vol, parentdir, path, strlen(path),
                       upath, strlen(upath), &st)) == NULL) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         return AFPERR_MISC;
     }
 
     memcpy(rbuf, &dir->d_did, sizeof(dir->d_did));
     *rbuflen = sizeof(dir->d_did);
-#ifdef FORCE_UIDGID
-    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
     return AFP_OK;
 }