]> arthur.barton.de Git - netatalk.git/commitdiff
mv unix_rename from etc/afpd/unix.c to libatalk/vfs/unix.c.
authorfranklahm <franklahm>
Tue, 27 Oct 2009 10:24:02 +0000 (10:24 +0000)
committerfranklahm <franklahm>
Tue, 27 Oct 2009 10:24:02 +0000 (10:24 +0000)
Untabify and reindent libatalk/vfs/unix.c.

etc/afpd/unix.c
libatalk/vfs/unix.c

index 0ffdd40e7813673742dae66acf0898d3faefca68..de281ff5b53e972fffc359c823993ade7aae82c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: unix.c,v 1.56 2009-10-15 12:06:07 franklahm Exp $
+ * $Id: unix.c,v 1.57 2009-10-27 10:24:02 franklahm Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -598,45 +598,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;
-}
-
index 3b71dec206a8a59c0c11603395f4a58b5575d5c7..789a13ecd10b1e7ab4eba4898fd3de27c8f74046 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: unix.c,v 1.5 2009-10-16 00:57:12 didg Exp $
+ * $Id: unix.c,v 1.6 2009-10-27 10:24:02 franklahm Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -26,7 +26,7 @@
 
 /* -----------------------------
    a dropbox is a folder where w is set but not r eg:
-   rwx-wx-wx or rwx-wx-- 
+   rwx-wx-wx or rwx-wx--
    rwx----wx (is not asked by a Mac with OS >= 8.0 ?)
 */
 int stickydirmode(const char *name, const mode_t mode, const int dropbox, const mode_t v_umask)
@@ -60,8 +60,8 @@ int stickydirmode(const char *name, const mode_t mode, const int dropbox, const
      *  Ignore EPERM errors:  We may be dealing with a directory that is
      *  group writable, in which case chmod will fail.
      */
-    if ( (chmod( name, (DIRBITS | mode) & ~v_umask ) < 0) && errno != EPERM && 
-               !(errno == ENOENT && (dropbox & AFPVOL_NOADOUBLE)) )  
+    if ( (chmod( name, (DIRBITS | mode) & ~v_umask ) < 0) && errno != EPERM &&
+         !(errno == ENOENT && (dropbox & AFPVOL_NOADOUBLE)) )
     {
         LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", fullpathname(name), strerror(errno) );
         retval = -1;
@@ -79,33 +79,33 @@ int dir_rx_set(mode_t mode)
 /* --------------------- */
 int setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
 {
-struct stat sb;
-mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO;  /* rwx for owner group and other, by default */
+    struct stat sb;
+    mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO;  /* rwx for owner group and other, by default */
 
     if (!st) {
         if (stat(name, &sb) != 0)
             return -1;
         st = &sb;
     }
-   
-   mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
-   if ( chmod( name,  mode & ~v_umask ) < 0 && errno != EPERM ) {
-       return -1;
-   }
-   return 0;
+
+    mode |= st->st_mode & ~mask; /* keep other bits from previous mode */
+    if ( chmod( name,  mode & ~v_umask ) < 0 && errno != EPERM ) {
+        return -1;
+    }
+    return 0;
 }
 
 /* -------------------
    system rmdir with afp error code.
    ENOENT is not an error.
- */
+*/
 int netatalk_rmdir(const char *name)
 {
     if (rmdir(name) < 0) {
         switch ( errno ) {
         case ENOENT :
             break;
-        case ENOTEMPTY : 
+        case ENOTEMPTY :
             return AFPERR_DIRNEMPT;
         case EPERM:
         case EACCES :
@@ -122,7 +122,7 @@ int netatalk_rmdir(const char *name)
 /* -------------------
    system unlink with afp error code.
    ENOENT is not an error.
- */
+*/
 int netatalk_unlink(const char *name)
 {
     if (unlink(name) < 0) {
@@ -212,10 +212,52 @@ exit:
         if (!ret && err) {
             /* don't bother to report an error if there's already one */
             LOG(log_error, logtype_afpd, "copy_file('%s'/'%s'): close '%s' error: %s",
-                    src, dst, dst, strerror(errno));
+                src, dst, dst, strerror(errno));
             ret = -1;
         }
     }
 
     return ret;
 }
+
+/* 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;
+}