]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/unix.c
afpd: umask handling, bug #576
[netatalk.git] / etc / afpd / unix.c
index 397b99fb3c174319de362de90457c038e60d43c2..e928fda93f7f70624a367c544d36d4f7c3189e95 100644 (file)
@@ -158,7 +158,7 @@ void accessmode(const AFPObj *obj, const struct vol *vol, char *path, struct mac
 
     ma->ma_user = ma->ma_owner = ma->ma_world = ma->ma_group = 0;
     if (!st) {
-        if (lstat(path, &sb) != 0)
+        if (ostat(path, &sb, vol_syml_opt(vol)) != 0)
             return;
         st = &sb;
     }
@@ -203,88 +203,11 @@ mode_t mtoumode(struct maccess *ma)
     return( mode );
 }
 
-#define EXEC_MODE (S_IXGRP | S_IXUSR | S_IXOTH)
-
-int setdeskmode(const mode_t mode)
-{
-    char               wd[ MAXPATHLEN + 1];
-    struct stat         st;
-    char               modbuf[ 12 + 1], *m;
-    struct dirent      *deskp, *subp;
-    DIR                        *desk, *sub;
-
-    if (!dir_rx_set(mode)) {
-        /* want to remove read and search access to owner it will screw the volume */
-        return -1 ;
-    }
-    if ( getcwd( wd , MAXPATHLEN) == NULL ) {
-        return( -1 );
-    }
-    if ( chdir( ".AppleDesktop" ) < 0 ) {
-        return( -1 );
-    }
-    if (( desk = opendir( "." )) == NULL ) {
-        if ( chdir( wd ) < 0 ) {
-            LOG(log_error, logtype_afpd, "setdeskmode: chdir %s: %s", wd, strerror(errno) );
-        }
-        return( -1 );
-    }
-    for ( deskp = readdir( desk ); deskp != NULL; deskp = readdir( desk )) {
-        if ( strcmp( deskp->d_name, "." ) == 0 ||
-                strcmp( deskp->d_name, ".." ) == 0 || strlen( deskp->d_name ) > 2 ) {
-            continue;
-        }
-        strcpy( modbuf, deskp->d_name );
-        strcat( modbuf, "/" );
-        m = strchr( modbuf, '\0' );
-        if (( sub = opendir( deskp->d_name )) == NULL ) {
-            continue;
-        }
-        for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) {
-            if ( strcmp( subp->d_name, "." ) == 0 ||
-                    strcmp( subp->d_name, ".." ) == 0 ) {
-                continue;
-            }
-            *m = '\0';
-            strcat( modbuf, subp->d_name );
-            /* XXX: need to preserve special modes */
-            if (lstat(modbuf, &st) < 0) {
-                LOG(log_error, logtype_afpd, "setdeskmode: stat %s: %s",fullpathname(modbuf), strerror(errno) );
-                continue;
-            }
-
-            if (S_ISDIR(st.st_mode)) {
-                if ( chmod_acl( modbuf,  (DIRBITS | mode)) < 0 && errno != EPERM ) {
-                     LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) );
-                }
-            } else if ( chmod_acl( modbuf,  mode & ~EXEC_MODE ) < 0 && errno != EPERM ) {
-                LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) );
-            }
-
-        }
-        closedir( sub );
-        /* XXX: need to preserve special modes */
-        if ( chmod_acl( deskp->d_name,  (DIRBITS | mode)) < 0 && errno != EPERM ) {
-            LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(deskp->d_name), strerror(errno) );
-        }
-    }
-    closedir( desk );
-    if ( chdir( wd ) < 0 ) {
-        LOG(log_error, logtype_afpd, "setdeskmode: chdir %s: %s", wd, strerror(errno) );
-        return -1;
-    }
-    /* XXX: need to preserve special modes */
-    if ( chmod_acl( ".AppleDesktop",  (DIRBITS | mode)) < 0 && errno != EPERM ) {
-        LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s", fullpathname(".AppleDesktop"),strerror(errno) );
-    }
-    return( 0 );
-}
-
 /* --------------------- */
 int setfilunixmode (const struct vol *vol, struct path* path, mode_t mode)
 {
     if (!path->st_valid) {
-        of_stat(path);
+        of_stat(vol, path);
     }
 
     if (path->st_errno) {
@@ -293,7 +216,7 @@ int setfilunixmode (const struct vol *vol, struct path* path, mode_t mode)
         
     mode |= vol->v_fperm;
 
-    if (setfilmode( path->u_name, mode, &path->st, vol->v_umask) < 0)
+    if (setfilmode(vol, path->u_name, mode, &path->st) < 0)
         return -1;
     /* we need to set write perm if read set for resource fork */
     return vol->vfs->vfs_setfilmode(vol, path->u_name, mode, &path->st);
@@ -301,94 +224,37 @@ int setfilunixmode (const struct vol *vol, struct path* path, mode_t mode)
 
 
 /* --------------------- */
-int setdirunixmode(const struct vol *vol, const char *name, mode_t mode)
+int setdirunixmode(const struct vol *vol, char *name, mode_t mode)
 {
     LOG(log_debug, logtype_afpd, "setdirunixmode('%s', mode:%04o) {v_dperm:%04o}",
         fullpathname(name), mode, vol->v_dperm);
 
-    mode |= vol->v_dperm;
+    mode |= vol->v_dperm | DIRBITS;
+    mode &= ~vol->v_umask;
 
     if (dir_rx_set(mode)) {
        /* extending right? dir first then .AppleDouble in rf_setdirmode */
-       if (chmod_acl(name, (DIRBITS | mode) & ~vol->v_umask) < 0 )
+        if (ochmod(name, mode, NULL,
+                   vol_syml_opt(vol) | vol_chmod_opt(vol)
+                ) < 0)
                return -1;
     }
     if (vol->vfs->vfs_setdirunixmode(vol, name, mode, NULL) < 0) {
         return  -1 ;
     }
     if (!dir_rx_set(mode)) {
-       if (chmod_acl(name, (DIRBITS | mode) & ~vol->v_umask) < 0 )
+        if (ochmod(name, mode, NULL,
+                   vol_syml_opt(vol) | vol_chmod_opt(vol)
+                ) < 0)
             return -1;
     }
     return 0;
 }
 
-/* ----------------------------- */
-int setdeskowner(const uid_t uid, const gid_t gid)
-{
-    char               wd[ MAXPATHLEN + 1];
-    char               modbuf[12 + 1], *m;
-    struct dirent      *deskp, *subp;
-    DIR                        *desk, *sub;
-
-    if ( getcwd( wd, MAXPATHLEN ) == NULL ) {
-        return( -1 );
-    }
-    if ( chdir( ".AppleDesktop" ) < 0 ) {
-        return( -1 );
-    }
-    if (( desk = opendir( "." )) == NULL ) {
-        if ( chdir( wd ) < 0 ) {
-            LOG(log_error, logtype_afpd, "setdeskowner: chdir %s: %s", wd, strerror(errno) );
-        }
-        return( -1 );
-    }
-    for ( deskp = readdir( desk ); deskp != NULL; deskp = readdir( desk )) {
-        if ( strcmp( deskp->d_name, "." ) == 0 ||
-                strcmp( deskp->d_name, ".." ) == 0 ||
-                strlen( deskp->d_name ) > 2 ) {
-            continue;
-        }
-        strcpy( modbuf, deskp->d_name );
-        strcat( modbuf, "/" );
-        m = strchr( modbuf, '\0' );
-        if (( sub = opendir( deskp->d_name )) == NULL ) {
-            continue;
-        }
-        for ( subp = readdir( sub ); subp != NULL; subp = readdir( sub )) {
-            if ( strcmp( subp->d_name, "." ) == 0 ||
-                    strcmp( subp->d_name, ".." ) == 0 ) {
-                continue;
-            }
-            *m = '\0';
-            strcat( modbuf, subp->d_name );
-            /* XXX: add special any uid, ignore group bits */
-            if ( chown( modbuf, uid, gid ) < 0 && errno != EPERM ) {
-                LOG(log_error, logtype_afpd, "setdeskown: chown %s: %s", fullpathname(modbuf), strerror(errno) );
-            }
-        }
-        closedir( sub );
-        /* XXX: add special any uid, ignore group bits */
-        if ( chown( deskp->d_name, uid, gid ) < 0 && errno != EPERM ) {
-            LOG(log_error, logtype_afpd, "setdeskowner: chown %s: %s",
-                deskp->d_name, strerror(errno) );
-        }
-    }
-    closedir( desk );
-    if ( chdir( wd ) < 0 ) {
-        LOG(log_error, logtype_afpd, "setdeskowner: chdir %s: %s", wd, strerror(errno) );
-        return -1;
-    }
-    if ( chown( ".AppleDesktop", uid, gid ) < 0 && errno != EPERM ) {
-        LOG(log_error, logtype_afpd, "setdeskowner: chown %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
-    }
-    return( 0 );
-}
-
 /* ----------------------------- */
 int setfilowner(const struct vol *vol, const uid_t uid, const gid_t gid, struct path* path)
 {
-    if (lchown(path->u_name, uid, gid) < 0 && errno != EPERM) {
+    if (ochown( path->u_name, uid, gid, vol_syml_opt(vol)) < 0 && errno != EPERM ) {
         LOG(log_debug, logtype_afpd, "setfilowner: chown %d/%d %s: %s",
             uid, gid, path->u_name, strerror(errno));
         return -1;
@@ -410,7 +276,7 @@ int setfilowner(const struct vol *vol, const uid_t uid, const gid_t gid, struct
  * co-opting some bits. */
 int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const gid_t gid)
 {
-    if (lchown(name, uid, gid ) < 0 && errno != EPERM ) {
+    if (ochown(name, uid, gid, vol_syml_opt(vol)) < 0 && errno != EPERM ) {
         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
             uid, gid, fullpathname(name), strerror(errno) );
     }
@@ -420,4 +286,3 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const
 
     return( 0 );
 }
-