]> 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 007540f06c3d709f5cd376011fc6a05e33a53769..43fb6d150312f4bd118e4b9d6677b50626c511e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.31 2002-04-29 06:56:02 morgana 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 */
@@ -417,7 +416,31 @@ struct dir *dir;
 #endif /* ! REMOVE_NODES */
 }
 
+/* ---------------------------------------
+ * remove the node and its childs from the tree
+ *
+ * FIXME what about opened forks with refs to it?
+ * it's an afp specs violation because you can't delete
+ * an opened forks. Now afpd doesn't care about forks opened by other 
+ * process. It's fixable within afpd if fnctl_lock, doable with smb and
+ * next to impossible for nfs and local filesystem access.
+ */
+static void dir_invalidate( vol, dir )
+const struct vol *vol;
+struct dir *dir;
+{
+       if (curdir == dir) {
+           /* v_root can't be deleted */
+               if (movecwd(vol, vol->v_root) < 0) 
+                       printf("Yuup cant change dir to v_root\n");
+       }
+       /* FIXME */
+    dirchildremove(dir->d_parent, dir);
+       dir_remove( vol, dir );
+}
 
+/* ------------------------------------ */
 static struct dir *dir_insert(vol, dir)
             const struct vol *vol;
 struct dir *dir;
@@ -743,9 +766,11 @@ char       **cpath;
     struct dir         *cdir;
     static char                path[ MAXPATHLEN + 1];
     char               *data, *p;
+    char        *u;
     int                        extend = 0;
     int                        len;
-
+       int                     olen = 0;
+       
     data = *cpath;
     if ( *data++ != 2 ) {                      /* path type */
         return( NULL );
@@ -753,11 +778,37 @@ char      **cpath;
     len = (unsigned char) *data++;
     *cpath += len + 2;
     *path = '\0';
+    u = NULL;
 
     for ( ;; ) {
         if ( len == 0 ) {
             if ( !extend && movecwd( vol, dir ) < 0 ) {
-                return( NULL );
+               /* it's tricky:
+                  movecwd failed so dir is not there anymore.
+                  FIXME Is it true with other errors?
+                  if path == '\0' ==> the cpath parameter is that dir,
+                  and maybe we are trying to recreate it! So we can't 
+                  fail here.
+                  
+               */
+                   if ( dir->d_did == DIRDID_ROOT_PARENT) 
+                               return NULL;                    
+               cdir = dir->d_parent;
+               dir_invalidate(vol, dir);
+               if (*path != '\0' || u == NULL) {
+                       /* FIXME: if path != '\0' then extend != 0 ?
+                        * u == NUL ==> cpath is something like:
+                        * toto\0\0\0
+                       */
+                       return NULL;
+               }
+               if (movecwd(vol, cdir) < 0) {
+                       printf("can't change to parent\n");
+                       return NULL; /* give up the whole tree is out of synch*/
+               }
+                               /* restore the previous token */
+                       strncpy(path, u, olen);
+                       path[olen] = '\0';
             }
             return( path );
         }
@@ -766,6 +817,7 @@ char        **cpath;
             data++;
             len--;
         }
+       u = NULL;
 
         while ( *data == '\0' && len > 0 ) {
             if ( dir->d_parent == NULL ) {
@@ -778,6 +830,10 @@ char       **cpath;
 
         /* would this be faster with strlen + strncpy? */
         p = path;
+        if (len > 0) {
+               u = data;
+               olen = len;
+               }        
         while ( *data != '\0' && len > 0 ) {
             *p++ = *data++;
             len--;
@@ -809,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 :
@@ -817,7 +873,16 @@ char       **cpath;
                 }
                 if ( cdir == NULL ) {
                     ++extend;
+                    /* if dir == curdir it always succeed,
+                       even if curdir is deleted. 
+                       it's not a pb because it will failed in extenddir
+                    */
                     if ( movecwd( vol, dir ) < 0 ) {
+                       /* dir is not valid anymore 
+                          we delete dir from the cache and abort.
+                       */
+                       if ( dir->d_did != DIRDID_ROOT_PARENT) 
+                           dir_invalidate(vol, dir);
                         return( NULL );
                     }
                     cdir = extenddir( vol, dir, path );
@@ -833,7 +898,7 @@ char        **cpath;
                 }
 
             } else {
-                dir = cdir;
+                dir = cdir;    
                 *path = '\0';
             }
         }
@@ -895,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;
@@ -928,6 +984,7 @@ int getdirparams(const struct vol *vol,
                 ashort = htons(ATTRBIT_INVISIBLE);
             } else
                 ashort = 0;
+            ashort |= htons(ATTRBIT_SHARED);
             memcpy( data, &ashort, sizeof( ashort ));
             data += sizeof( ashort );
             break;
@@ -1043,15 +1100,8 @@ int getdirparams(const struct vol *vol,
             break;
 
         case DIRPBIT_ACCESS :
-            utommode( st, &ma );
-#ifndef SENDFILE_FLAVOR_LINUX /* ignore this section if it's linux */
-#ifdef HAVE_ACCESS
-            accessmode( upath, &ma, dir );
-#endif /* HAVE_ACCESS */
-#endif /* SENDFILE_FLAVOR_LINUX */
-#ifdef AFS     /* If only AFS defined, access() works only for AFS filesystems */ 
-            afsmode( upath, &ma, dir );
-#endif /* AFS */
+            accessmode( upath, &ma, dir , st);
+
             *data++ = ma.ma_user;
             *data++ = ma.ma_world;
             *data++ = ma.ma_group;
@@ -1075,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;
@@ -1128,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 );
     }
 
@@ -1140,6 +1187,10 @@ int              ibuflen, *rbuflen;
         return( AFPERR_NOOBJ );
     }
 
+    if ( *path != '\0' ) {
+        return( AFPERR_BADTYPE ); /* not a directory */
+    }
+
     /*
      * If ibuf is odd, make it even.
      */
@@ -1153,27 +1204,30 @@ int             ibuflen, *rbuflen;
     return( rc );
 }
 
-int setdirparams(const struct vol *vol,
+/*
+ * cf AFP3.0.pdf page 244 for change_mdate and change_parent_mdate logic  
+ *
+ * assume path == '\0' eg. it's a directory in canonical form
+*/
+int setdirparams(const struct vol *vol, 
                  char *path, u_int16_t bitmap, char *buf )
 {
     struct maccess     ma;
     struct adouble     ad;
     struct utimbuf      ut;
+    struct timeval      tv;
+
     char                *upath;
     int                        bit = 0, aint, isad = 1;
     u_int16_t          ashort, bshort;
     int                 err = AFP_OK;
-#ifdef FORCE_UIDGID
-    uidgidset          *uidgid;
-
-    memset(&uidgid, 0, sizeof(uidgid));
-#endif /* FORCE_UIDGID */
+    int                 change_mdate = 0;
+    int                 change_parent_mdate = 0;
+    int                 newdate = 0;
 
     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) {
         /*
@@ -1187,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;
         }
 
@@ -1214,6 +1265,7 @@ int setdirparams(const struct vol *vol,
 
         switch( bit ) {
         case DIRPBIT_ATTR :
+            change_mdate = 1;
             if (isad) {
                 memcpy( &ashort, buf, sizeof( ashort ));
                 ad_getattr(&ad, &bshort);
@@ -1223,11 +1275,14 @@ int setdirparams(const struct vol *vol,
                     bshort &= ~ashort;
                 }
                 ad_setattr(&ad, bshort);
+                if ((ashort & htons(ATTRBIT_INVISIBLE)))
+                  change_parent_mdate = 1;
             }
             buf += sizeof( ashort );
             break;
 
         case DIRPBIT_CDATE :
+            change_mdate = 1;
             if (isad) {
                 memcpy(&aint, buf, sizeof(aint));
                 ad_setdate(&ad, AD_DATE_CREATE, aint);
@@ -1236,15 +1291,12 @@ int setdirparams(const struct vol *vol,
             break;
 
         case DIRPBIT_MDATE :
-            memcpy(&aint, buf, sizeof(aint));
-            if (isad)
-                ad_setdate(&ad, AD_DATE_MODIFY, aint);
-            ut.actime = ut.modtime = AD_DATE_TO_UNIX(aint);
-            utime(upath, &ut);
-            buf += sizeof( aint );
+            memcpy(&newdate, buf, sizeof(newdate));
+            buf += sizeof( newdate );
             break;
 
         case DIRPBIT_BDATE :
+            change_mdate = 1;
             if (isad) {
                 memcpy(&aint, buf, sizeof(aint));
                 ad_setdate(&ad, AD_DATE_BACKUP, aint);
@@ -1253,6 +1305,7 @@ int setdirparams(const struct vol *vol,
             break;
 
         case DIRPBIT_FINFO :
+            change_mdate = 1;
             /*
              * Alright, we admit it, this is *really* sick!
              * The 4 bytes that we don't copy, when we're dealing
@@ -1273,6 +1326,7 @@ int setdirparams(const struct vol *vol,
             break;
 
         case DIRPBIT_UID :     /* What kind of loser mounts as root? */
+            change_parent_mdate = 1;
             memcpy( &aint, buf, sizeof(aint));
             buf += sizeof( aint );
             if ( (curdir->d_did == DIRDID_ROOT) &&
@@ -1316,6 +1370,7 @@ int setdirparams(const struct vol *vol,
             }
             break;
         case DIRPBIT_GID :
+            change_parent_mdate = 1;
             memcpy( &aint, buf, sizeof( aint ));
             buf += sizeof( aint );
             if (curdir->d_did == DIRDID_ROOT)
@@ -1362,6 +1417,8 @@ int setdirparams(const struct vol *vol,
             break;
 
         case DIRPBIT_ACCESS :
+            change_mdate = 1;
+            change_parent_mdate = 1;
             ma.ma_user = *buf++;
             ma.ma_world = *buf++;
             ma.ma_group = *buf++;
@@ -1385,56 +1442,71 @@ int setdirparams(const struct vol *vol,
                 err = AFPERR_PARAM;
                 goto setdirparam_done;
             }
-        }
 #endif /* 0 */
 
-        if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
+            if ( setdirmode( mtoumode( &ma ), vol_noadouble(vol),
                          (vol->v_flags & AFPVOL_DROPBOX)) < 0 ) {
-            switch ( errno ) {
-            case EPERM :
-            case EACCES :
-                err = AFPERR_ACCESS;
-                goto setdirparam_done;
-            case EROFS :
-                err = AFPERR_VLOCK;
-                goto setdirparam_done;
-            default :
-                LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
-                    strerror(errno) );
-                err = AFPERR_PARAM;
-                goto setdirparam_done;
+                switch ( errno ) {
+                case EPERM :
+                case EACCES :
+                    err = AFPERR_ACCESS;
+                    goto setdirparam_done;
+                case EROFS :
+                    err = AFPERR_VLOCK;
+                    goto setdirparam_done;
+                default :
+                    LOG(log_error, logtype_afpd, "setdirparam: setdirmode: %s",
+                        strerror(errno) );
+                    err = AFPERR_PARAM;
+                    goto setdirparam_done;
+                }
             }
-        }
-        break;
+            break;
 
         /* Ignore what the client thinks we should do to the
            ProDOS information block.  Skip over the data and
            report nothing amiss. <shirsch@ibm.net> */
-    case DIRPBIT_PDINFO :
-        buf += 6;
-        break;
+        case DIRPBIT_PDINFO :
+            buf += 6;
+            break;
 
-    default :
-        err = AFPERR_BITMAP;
-        goto setdirparam_done;
-        break;
+        default :
+            err = AFPERR_BITMAP;
+            goto setdirparam_done;
+            break;
+        }
+
+        bitmap = bitmap>>1;
+        bit++;
     }
 
-    bitmap = bitmap>>1;
-    bit++;
-}
+setdirparam_done:
+    if (change_mdate && newdate == 0 && gettimeofday(&tv, NULL) == 0) {
+       newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
+    }
+    if (newdate) {
+       if (isad)
+          ad_setdate(&ad, AD_DATE_MODIFY, newdate);
+       ut.actime = ut.modtime = AD_DATE_TO_UNIX(newdate);
+       utime(upath, &ut);
+    }
 
+    if ( isad ) {
+        ad_flush( &ad, ADFLAGS_HF );
+        ad_close( &ad, ADFLAGS_HF );
+    }
 
-setdirparam_done:
-if ( isad ) {
-    ad_flush( &ad, ADFLAGS_HF );
-    ad_close( &ad, ADFLAGS_HF );
-}
+    if (change_parent_mdate && curdir->d_did != DIRDID_ROOT
+            && gettimeofday(&tv, NULL) == 0) {
+       if (!movecwd(vol, curdir->d_parent)) {
+           newdate = AD_DATE_FROM_UNIX(tv.tv_sec);
+           bitmap = 1<<DIRPBIT_MDATE;
+           setdirparams(vol, "", bitmap, (char *)&newdate);
+           /* should we reset curdir ?*/
+       }
+    }
 
-#ifdef FORCE_UIDGID
-restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
-return err;
+    return err;
 }
 
 int afp_createdir(obj, ibuf, ibuflen, rbuf, rbuflen )
@@ -1449,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;
@@ -1469,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 );
     }
 
@@ -1477,38 +1544,24 @@ int             ibuflen, *rbuflen;
         switch( errno ) {
         case EACCES:
             return( AFPERR_ACCESS );
-        case EEXIST:
+        case EEXIST:                           /* FIXME this on is impossible? */
             return( AFPERR_EXIST );
         default:
             return( AFPERR_NOOBJ );
         }
     }
-
+    /* FIXME check done elswhere? cname was able to move curdir to it! */
+       if (*path == '\0')
+               return AFPERR_EXIST;
     upath = mtoupath(vol, path);
-
-    /* check for illegal bits in the unix filename */
-    if (!wincheck(vol, upath))
-        return AFPERR_PARAM;
-
-    if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/'))
-        return AFPERR_PARAM;
-
-    if (!validupath(vol, upath))
-        return AFPERR_EXIST;
-
-    /* check for vetoed filenames */
-    if (veto_file(vol->v_veto, upath))
-        return AFPERR_EXIST;
-
-#ifdef FORCE_UIDGID
-    save_uidgid ( &uidgid );
-    set_uidgid  ( vol );
-#endif /* FORCE_UIDGID */
+    {
+    int ret;
+        if (0 != (ret = check_name(vol, upath))) {
+            return  ret;
+        }
+    }
 
     if ( ad_mkdir( upath, DIRBITS | 0777 ) < 0 ) {
-#ifdef FORCE_UIDGID
-        restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
         switch ( errno ) {
         case ENOENT :
             return( AFPERR_NOOBJ );
@@ -1527,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 );
     }
 
@@ -1553,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 );
     }
 
@@ -1569,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 );
 }
 
@@ -1669,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 );
@@ -1685,20 +1718,13 @@ 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 ) {
 
         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;
         }
     }
@@ -1716,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;
             }
 
@@ -1728,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 );
                 }
             }
@@ -1755,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 );
         }
     }
@@ -1787,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;
             }
 
@@ -1797,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 );
                 }
             }
@@ -1820,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 );
         }
     }
@@ -1863,9 +1835,6 @@ int pathlen;
 #endif /* CNID_DB */
     dir_remove( vol, fdir );
 
-#ifdef FORCE_UIDGID
-    restore_uidgid ( &uidgid );
-#endif /* FORCE_UIDGID */
     return( AFP_OK );
 }
 
@@ -1996,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 );
     }
 
@@ -2018,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;
@@ -2037,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 );
     }
 
@@ -2066,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;
 }