]> arthur.barton.de Git - netatalk.git/commitdiff
Default adouble:ea, check for EA, fallback to v2. loglevel support multiple statement...
authorFrank Lahm <franklahm@googlemail.com>
Wed, 15 Feb 2012 11:43:36 +0000 (12:43 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Feb 2012 11:43:36 +0000 (12:43 +0100)
etc/afpd/file.c
etc/afpd/volume.c
include/atalk/adouble.h
libatalk/util/logger.c

index c8101048e038ecbc52c1acd6db978047435c2234..ce2ab545efd90edb12b869e7c4dfd80a0c3c230c 100644 (file)
@@ -79,6 +79,7 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a
     void                *ad_finder = NULL;
     int                 chk_ext = 0;
 
+    if (adp)
         ad_finder = ad_entry(adp, ADEID_FINDERI);
 
     if (ad_finder) {
index 54f52c8e25e721a698f8c4407b4169ab150c7546..0a86cfd2c859b61f933d840bcd773458c2efa733 100644 (file)
@@ -38,6 +38,7 @@
 #include <atalk/fce_api.h>
 #include <atalk/errchk.h>
 #include <atalk/iniparser.h>
+#include <atalk/unix.h>
 
 #ifdef CNID_DB
 #include <atalk/cnid.h>
@@ -117,7 +118,7 @@ static const _special_folder special_folders[] = {
 static void handle_special_folders (const struct vol *);
 static void deletevol(struct vol *vol);
 static void volume_free(struct vol *vol);
-static void check_ea_sys_support(struct vol *vol);
+static void check_ea_support(struct vol *vol);
 static char *get_vol_uuid(const AFPObj *obj, const char *volname);
 
 static void volfree(struct vol_option *options, const struct vol_option *save)
@@ -305,7 +306,7 @@ static void setoption(struct vol_option *options, const struct vol_option *save,
 {
     if (options[opt].c_value && (!save || options[opt].c_value != save[opt].c_value))
         free(options[opt].c_value);
-    options[opt].c_value = strdup(val + 1);
+    options[opt].c_value = strdup(val);
 }
 
 /* Parse iniconfig and initalize volume options */
@@ -729,8 +730,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
     volume->v_fperm |= volume->v_perm;
 
     /* Check EA support on volume */
-    if (volume->v_vfs_ea == AFPVOL_EA_AUTO)
-        check_ea_sys_support(volume);
+    if (volume->v_vfs_ea == AFPVOL_EA_AUTO || volume->v_adouble == AD_VERSION_EA)
+        check_ea_support(volume);
     initvol_vfs(volume);
 
     /* get/store uuid from file in afpd master*/
@@ -938,8 +939,6 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p
 
     LOG(log_debug, logtype_afpd, "readvolfile: BEGIN");
 
-    p1->mtime = 0;
-
     memset(default_options, 0, sizeof(default_options));
 
     /* Enable some default options for all volumes */
@@ -1588,7 +1587,7 @@ void load_volumes(AFPObj *obj)
 
     /* try putting a read lock on the volume file twice, sleep 1 second if first attempt fails */
 
-    fd = open(obj->options.configfile, O_RDWR);
+    fd = open(obj->options.configfile, O_RDONLY);
 
     while (retries < 2) {
         if ((read_lock(fd, 0, SEEK_SET, 0)) != 0) {
@@ -1785,49 +1784,67 @@ static int volume_openDB(const AFPObj *obj, struct vol *volume)
 }
 
 /*
-  Check if the underlying filesystem supports EAs for ea:sys volumes.
+  Check if the underlying filesystem supports EAs.
   If not, switch to ea:ad.
   As we can't check (requires write access) on ro-volumes, we switch ea:auto
   volumes that are options:ro to ea:none.
 */
-static void check_ea_sys_support(struct vol *vol)
+static int do_check_ea_support(const struct vol *vol)
 {
-    uid_t process_uid = 0;
+    int haseas;
     char eaname[] = {"org.netatalk.supports-eas.XXXXXX"};
     const char *eacontent = "yes";
 
-    if (vol->v_vfs_ea == AFPVOL_EA_AUTO) {
+    if ((vol->v_flags & AFPVOL_RO) == AFPVOL_RO) {
+        LOG(log_note, logtype_afpd, "read-only volume '%s', can't test for EA support, assuming yes", vol->v_localname);
+        return 1;
+    }
+
+    mktemp(eaname);
+
+    become_root();
+
+    if ((sys_setxattr(vol->v_path, eaname, eacontent, 4, 0)) == 0) {
+        sys_removexattr(vol->v_path, eaname);
+        haseas = 1;
+    } else {
+        LOG(log_warning, logtype_afpd, "volume \"%s\" does not support Extended Attributes",
+            vol->v_localname);
+        haseas = 0;
+    }
+
+    unbecome_root();
+
+    return haseas;
+}
 
+static void check_ea_support(struct vol *vol)
+{
+    int haseas;
+    char eaname[] = {"org.netatalk.supports-eas.XXXXXX"};
+    const char *eacontent = "yes";
+
+    haseas = do_check_ea_support(vol);
+
+    if (vol->v_vfs_ea == AFPVOL_EA_AUTO) {
         if ((vol->v_flags & AFPVOL_RO) == AFPVOL_RO) {
             LOG(log_info, logtype_afpd, "read-only volume '%s', can't test for EA support, disabling EAs", vol->v_localname);
             vol->v_vfs_ea = AFPVOL_EA_NONE;
             return;
         }
 
-        mktemp(eaname);
-
-        process_uid = geteuid();
-        if (process_uid)
-            if (seteuid(0) == -1) {
-                LOG(log_error, logtype_afpd, "check_ea_sys_support: can't seteuid(0): %s", strerror(errno));
-                exit(EXITERR_SYS);
-            }
-
-        if ((sys_setxattr(vol->v_path, eaname, eacontent, 4, 0)) == 0) {
-            sys_removexattr(vol->v_path, eaname);
+        if (haseas) {
             vol->v_vfs_ea = AFPVOL_EA_SYS;
         } else {
             LOG(log_warning, logtype_afpd, "volume \"%s\" does not support Extended Attributes, using ea:ad instead",
                 vol->v_localname);
             vol->v_vfs_ea = AFPVOL_EA_AD;
         }
+    }
 
-        if (process_uid) {
-            if (seteuid(process_uid) == -1) {
-                LOG(log_error, logtype_afpd, "can't seteuid back %s", strerror(errno));
-                exit(EXITERR_SYS);
-            }
-        }
+    if (vol->v_adouble == AD_VERSION_EA) {
+        if (!haseas)
+            vol->v_adouble = AD_VERSION2;
     }
 }
 
index c130a5e985209f6f2988fbaff2838249b6a3b3b4..9291e9c261bac90caab9b237d72782f4f7644616 100644 (file)
@@ -53,7 +53,7 @@
 #define AD_VERSION_EA   0x00020002
 
 /* default */
-#define AD_VERSION      AD_VERSION2
+#define AD_VERSION      AD_VERSION_EA
 
 /*
  * AppleDouble entry IDs.
index b96b2181c506e5f7314010155e0df54e486e0218..6d3be477980dd65c787322c6a6bbf7312a314c86 100644 (file)
@@ -627,24 +627,29 @@ void setuplog(const char *logstr, const char *logfile)
 
     save = ptr = strdup(logstr);
 
-    while (*ptr) {
-        while (*ptr && isspace(*ptr))
-            ptr++;
+    ptr = strtok(ptr, ",");
 
-        logtype = ptr;
-        ptr = strpbrk(ptr, ":");
-        if (!ptr)
-            break;
-        *ptr = 0;
+    while (ptr) {
+        while (*ptr) {
+            while (*ptr && isspace(*ptr))
+                ptr++;
+
+            logtype = ptr;
+            ptr = strpbrk(ptr, ":");
+            if (!ptr)
+                break;
+            *ptr = 0;
 
-        ptr++;
-        loglevel = ptr;
-        while (*ptr && !isspace(*ptr))
             ptr++;
-        c = *ptr;
-        *ptr = 0;
-        setuplog_internal(loglevel, logtype, logfile);
-        *ptr = c;
+            loglevel = ptr;
+            while (*ptr && !isspace(*ptr))
+                ptr++;
+            c = *ptr;
+            *ptr = 0;
+            setuplog_internal(loglevel, logtype, logfile);
+            *ptr = c;
+        }
+        ptr = strtok(NULL, ",");
     }
 
     free(save);