]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/desktop.c
Add advanced option "chmod request" controlling ACLs
[netatalk.git] / etc / afpd / desktop.c
index c437b7e6b4adb92f2a2c03388b401b3ad2eb8082..5c56977acd3fd30e6dea0659b40b68b19ac68898 100644 (file)
@@ -31,6 +31,7 @@
 #include <atalk/netatalk_conf.h>
 #include <atalk/unix.h>
 #include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
 #include <atalk/errchk.h>
 
 #include "volume.h"
@@ -61,7 +62,7 @@ int setdeskmode(const struct vol *vol, const mode_t mode)
     bstring dtpath = bfromcstr(vol->v_dbpath);
     bcatcstr(dtpath, "/" APPLEDESKTOP);
 
-    EC_NEG1( chdir(bdata(dtpath)) );
+    EC_NEG1( chdir(cfrombstr(dtpath)) );
 
     if (( desk = opendir( "." )) == NULL ) {
         if ( chdir( wd ) < 0 ) {
@@ -94,17 +95,29 @@ int setdeskmode(const struct vol *vol, const mode_t mode)
             }
 
             if (S_ISDIR(st.st_mode)) {
-                if ( chmod_acl( modbuf,  (DIRBITS | mode)) < 0 && errno != EPERM ) {
+                if (ochmod(modbuf,
+                           DIRBITS | mode,
+                           &st,
+                           vol_syml_opt(vol) | vol_chmod_opt(vol)
+                        ) < 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 ) {
+            } else if (ochmod(modbuf,
+                           mode & ~EXEC_MODE,
+                           &st,
+                           vol_syml_opt(vol) | vol_chmod_opt(vol)
+                        ) < 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 ) {
+        if (ochmod(deskp->d_name,
+                   DIRBITS | mode,
+                   NULL,
+                   vol_syml_opt(vol) | vol_chmod_opt(vol)
+                ) < 0 && errno != EPERM) {
             LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(deskp->d_name), strerror(errno) );
         }
     }
@@ -114,7 +127,11 @@ int setdeskmode(const struct vol *vol, const mode_t mode)
         EC_FAIL;
     }
     /* XXX: need to preserve special modes */
-    if ( chmod_acl(bdata(dtpath),  (DIRBITS | mode)) < 0 && errno != EPERM ) {
+    if (ochmod(bdata(dtpath),
+               DIRBITS | mode,
+               NULL,
+               vol_syml_opt(vol) | vol_chmod_opt(vol)
+            ) < 0 && errno != EPERM) {
         LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s", bdata(dtpath), strerror(errno));
     }
 
@@ -138,7 +155,7 @@ int setdeskowner(const struct vol *vol, uid_t uid, gid_t gid)
     bstring dtpath = bfromcstr(vol->v_dbpath);
     bcatcstr(dtpath, "/" APPLEDESKTOP);
 
-    EC_NEG1( chdir(bdata(dtpath)) );
+    EC_NEG1( chdir(cfrombstr(dtpath)) );
     
     if (( desk = opendir( "." )) == NULL ) {
         if ( chdir( wd ) < 0 ) {
@@ -182,7 +199,7 @@ int setdeskowner(const struct vol *vol, uid_t uid, gid_t gid)
         LOG(log_error, logtype_afpd, "setdeskowner: chdir %s: %s", wd, strerror(errno) );
         EC_FAIL;
     }
-    if (chown(bdata(dtpath), uid, gid ) < 0 && errno != EPERM ) {
+    if (chown(cfrombstr(dtpath), uid, gid ) < 0 && errno != EPERM ) {
         LOG(log_error, logtype_afpd, "setdeskowner: chown %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
     }
 
@@ -203,11 +220,11 @@ static void create_appledesktop_folder(const struct vol * vol)
     dtpath = bfromcstr(vol->v_dbpath);
     bcatcstr(dtpath, "/" APPLEDESKTOP);
 
-    if (lstat(bdata(dtpath), &st) != 0) {
+    if (lstat(cfrombstr(dtpath), &st) != 0) {
 
         become_root();
 
-        if (lstat(bdata(olddtpath), &st) == 0) {
+        if (lstat(cfrombstr(olddtpath), &st) == 0) {
             cmd_argv[0] = "mv";
             cmd_argv[1] = bdata(olddtpath);
             cmd_argv[2] = bdata(dtpath);
@@ -215,10 +232,10 @@ static void create_appledesktop_folder(const struct vol * vol)
             if (run_cmd("mv", cmd_argv) != 0) {
                 LOG(log_error, logtype_afpd, "moving .AppleDesktop from \"%s\" to \"%s\" failed",
                     bdata(olddtpath), bdata(dtpath));
-                mkdir(bdata(dtpath), 0777);
+                mkdir(cfrombstr(dtpath), 0777);
             }
         } else {
-            mkdir(bdata(dtpath), 0777);
+            mkdir(cfrombstr(dtpath), 0777);
         }
 
         unbecome_root();
@@ -830,7 +847,7 @@ static int ad_addcomment(const AFPObj *obj, struct vol *vol, struct path *path,
     }
     
     isadir = path_isadir(path);
-    if (isadir || !(of = of_findname(path))) {
+    if (isadir || !(of = of_findname(vol, path))) {
         ad_init(&ad, vol);
         adp = &ad;
     } else
@@ -905,7 +922,7 @@ static int ad_getcomment(struct vol *vol, struct path *path, char *rbuf, size_t
 
     upath = path->u_name;
     isadir = path_isadir(path);
-    if (isadir || !(of = of_findname(path))) {
+    if (isadir || !(of = of_findname(vol, path))) {
         ad_init(&ad, vol);
         adp = &ad;
     } else
@@ -982,7 +999,7 @@ static int ad_rmvcomment(const AFPObj *obj, struct vol *vol, struct path *path)
     }
 
     isadir = path_isadir(path);
-    if (isadir || !(of = of_findname(path))) {
+    if (isadir || !(of = of_findname(vol, path))) {
         ad_init(&ad, vol);
         adp = &ad;
     } else