]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/unix.c
Merge sf/master
[netatalk.git] / etc / afpd / unix.c
index 0f69f210d437e3ff5e71b89bfeda4b18dac08ad9..f604d79b8258a44ccdb5b228d18c543f40bda77c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: unix.c,v 1.58 2009-10-27 23:35:17 didg Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
@@ -32,25 +30,23 @@ char *strchr (), *strrchr ();
 #include <errno.h>
 #include <limits.h>
 #include <sys/param.h>
-#include <sys/stat.h>
 #include <atalk/logger.h>
 #include <atalk/adouble.h>
 #include <atalk/vfs.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
 #include <atalk/unix.h>
+#include <atalk/acl.h>
 
 #include "auth.h"
 #include "directory.h"
 #include "volume.h"
 #include "unix.h"
 #include "fork.h"
-
-#ifdef HAVE_NFSv4_ACLS
-extern void acltoownermode(char *path, struct stat *st,uid_t uid, struct maccess *ma);
+#ifdef HAVE_ACLS
+#include "acls.h"
 #endif
 
-
 /*
  * Get the free space on a partition.
  */
@@ -161,6 +157,7 @@ mode_t mode;
 }
 
 #ifdef accessmode
+
 #undef accessmode
 #endif
 /*
@@ -173,20 +170,18 @@ mode_t mode;
  * dir parameter is used by AFS
  */
 void accessmode(char *path, struct maccess *ma, struct dir *dir _U_, struct stat *st)
-
 {
-struct stat     sb;
+    struct stat     sb;
 
     ma->ma_user = ma->ma_owner = ma->ma_world = ma->ma_group = 0;
     if (!st) {
-        if (stat(path, &sb) != 0)
+        if (lstat(path, &sb) != 0)
             return;
         st = &sb;
     }
     utommode( st, ma );
-#ifdef HAVE_NFSv4_ACLS
-    /* 10.5 Finder looks at OS 9 mode, so we must do some mapping */
-    acltoownermode( path, st, uuid, ma);
+#ifdef HAVE_ACLS
+    acltoownermode(path, st, ma);
 #endif
 }
 
@@ -282,7 +277,7 @@ int setdeskmode(const mode_t mode)
             *m = '\0';
             strcat( modbuf, subp->d_name );
             /* XXX: need to preserve special modes */
-            if (stat(modbuf, &st) < 0) {
+            if (lstat(modbuf, &st) < 0) {
                 LOG(log_error, logtype_afpd, "setdeskmode: stat %s: %s",fullpathname(modbuf), strerror(errno) );
                 continue;
             }
@@ -339,6 +334,10 @@ int setdirunixmode(const struct vol *vol, const char *name, mode_t mode)
 {
 
     int dropbox = (vol->v_flags & AFPVOL_DROPBOX);
+
+    LOG(log_debug, logtype_afpd, "setdirunixmode('%s', mode:%04o) {v_dperm:%04o}",
+        fullpathname(name), mode, vol->v_dperm);
+
     mode |= vol->v_dperm;
 
     if (dir_rx_set(mode)) {
@@ -385,7 +384,7 @@ int setdirmode(const struct vol *vol, const char *name, mode_t mode)
         if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) {
             continue;
         }
-        if ( stat( dirp->d_name, &st ) < 0 ) {
+        if ( lstat( dirp->d_name, &st ) < 0 ) {
             LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s",dirp->d_name, strerror(errno) );
             continue;
         }
@@ -486,7 +485,7 @@ int setfilowner(const struct vol *vol, const uid_t uid, const gid_t gid, struct
         return -1;
     }
 
-    if ( chown( path->u_name, uid, gid ) < 0 && errno != EPERM ) {
+    if ( lchown( path->u_name, uid, gid ) < 0 && errno != EPERM ) {
         LOG(log_debug, logtype_afpd, "setfilowner: chown %d/%d %s: %s",
             uid, gid, path->u_name, strerror(errno) );
        return -1;
@@ -520,13 +519,13 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const
         if ( *dirp->d_name == '.' && (!osx || dirp->d_name[1] != '_')) {
             continue;
         }
-        if ( stat( dirp->d_name, &st ) < 0 ) {
+        if ( lstat( dirp->d_name, &st ) < 0 ) {
             LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s",
                 fullpathname(dirp->d_name), strerror(errno) );
             continue;
         }
         if (( st.st_mode & S_IFMT ) == S_IFREG ) {
-            if ( chown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) {
+            if ( lchown( dirp->d_name, uid, gid ) < 0 && errno != EPERM ) {
                 LOG(log_debug, logtype_afpd, "setdirowner: chown %s: %s",
                     fullpathname(dirp->d_name), strerror(errno) );
                 /* return ( -1 ); Sometimes this is okay */
@@ -539,10 +538,10 @@ int setdirowner(const struct vol *vol, const char *name, const uid_t uid, const
         return -1;
     }
     
-    if ( stat( ".", &st ) < 0 ) {
+    if ( lstat( ".", &st ) < 0 ) {
         return( -1 );
     }
-    if ( gid && gid != st.st_gid && chown( ".", uid, gid ) < 0 && errno != EPERM ) {
+    if ( gid && gid != st.st_gid && lchown( ".", uid, gid ) < 0 && errno != EPERM ) {
         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
             uid, gid, fullpathname("."), strerror(errno) );
     }
@@ -566,7 +565,7 @@ static int recursive_chown(const char *path, uid_t uid, gid_t gid) {
        return -1;
     }
 
-    if (stat(path, &sbuf) < 0) {
+    if (lstat(path, &sbuf) < 0) {
        LOG(log_error, logtype_afpd, "cannot chown() file [%s] (uid = %d): %s", path, uid, strerror(errno));
        return -1;
     }