]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/unix.c
Symlink patch from Anton Starikov
[netatalk.git] / etc / afpd / unix.c
index 5ab23eeafe453de2a3b1865b7bb9c628f6f699e1..29ec76a15fada1133f1438268810e8016c6705e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: unix.c,v 1.55 2009-10-14 15:04:01 franklahm Exp $
+ * $Id: unix.c,v 1.59.2.1 2010-01-02 10:22:32 franklahm Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -30,15 +30,14 @@ char *strchr (), *strrchr ();
 #endif /* STDC_HEADERS */
 
 #include <errno.h>
-#include <dirent.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 "auth.h"
 #include "directory.h"
@@ -179,7 +178,7 @@ 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;
     }
@@ -282,7 +281,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;
             }
@@ -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;
         }
@@ -520,7 +519,7 @@ 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;
@@ -539,7 +538,7 @@ 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 ) {
@@ -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;
     }
@@ -597,45 +596,3 @@ recursive_chown_end:
 }
 #endif
 
-/* This is equivalent of unix rename(). */
-int unix_rename(const char *oldpath, const char *newpath)
-{
-#if 0
-       char pd_name[PATH_MAX+1];
-       int i;
-        struct stat pd_stat;
-        uid_t uid;
-#endif
-
-       if (rename(oldpath, newpath) < 0)
-               return -1;
-#if 0
-       for (i = 0; i <= PATH_MAX && newpath[i] != '\0'; i++)
-               pd_name[i] = newpath[i];
-       pd_name[i] = '\0';
-
-       while (i > 0 && pd_name[i] != '/') i--;
-       if (pd_name[i] == '/') i++;
-
-        pd_name[i++] = '.'; pd_name[i++] = '\0';
-
-        if (stat(pd_name, &pd_stat) < 0) {
-           LOG(log_error, logtype_afpd, "stat() of parent dir failed: pd_name = %s, uid = %d: %s",
-               pd_name, geteuid(), strerror(errno));
-               return 0;
-       }
-
-       /* So we have SGID bit set... */
-        if ((S_ISGID & pd_stat.st_mode)        != 0) {
-            uid = geteuid();
-            if (seteuid(0) < 0)
-               LOG(log_error, logtype_afpd, "seteuid() failed: %s", strerror(errno));
-            if (recursive_chown(newpath, uid, pd_stat.st_gid) < 0)
-               LOG(log_error, logtype_afpd, "chown() of parent dir failed: newpath=%s, uid=%d: %s",
-                   pd_name, geteuid(), strerror(errno));
-            seteuid(uid);
-       }
-#endif
-       return 0;
-}
-