]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/util/volinfo.c
Merge master
[netatalk.git] / libatalk / util / volinfo.c
index 62afbc6559b490aa0d6c62a76380bc170aefe0c5..52360b1ece0330089386c5383f9cc619c74403e3 100644 (file)
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-
+#include <unistd.h>
+#include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#ifdef STDC_HEADERS
 #include <string.h>
-#endif
 #include <sys/param.h>
 
 #include <atalk/adouble.h>
@@ -40,6 +36,7 @@
 #include <atalk/logger.h>
 #include <atalk/volinfo.h>
 #include <atalk/volume.h>
+#include <atalk/compat.h>
 #ifdef CNID_DB
 #include <atalk/cnid.h>
 #endif /* CNID_DB*/
@@ -54,7 +51,6 @@ static const vol_opt_name_t vol_opt_names[] = {
     {AFPVOL_USEDOTS,    "USEDOTS"},     /* use real dots */
     {AFPVOL_LIMITSIZE,  "LIMITSIZE"},   /* limit size for older macs */
     {AFPVOL_MAPASCII,   "MAPASCII"},    /* map the ascii range as well */
-    {AFPVOL_DROPBOX,    "DROPBOX"},     /* dropkludge dropbox support */
     {AFPVOL_NOFILEID,   "NOFILEID"},    /* don't advertise createid resolveid and deleteid calls */
     {AFPVOL_NOSTAT,     "NOSTAT"},      /* advertise the volume even if we can't stat() it
                                          * maybe because it will be mounted later in preexec */
@@ -299,21 +295,14 @@ static int parseline ( char *buf, struct volinfo *vol)
           strcpy(vol->v_dbpath, value);
         break;
       case ADOUBLE_VER:
-        if (strcasecmp(value, "v1") == 0) {
-            vol->v_adouble = AD_VERSION1;
-            vol->ad_path = ad_path;
-        }
-#if AD_VERSION == AD_VERSION2
-        else if (strcasecmp(value, "v2") == 0) {
+        if (strcasecmp(value, "v2") == 0) {
             vol->ad_path = ad_path;
             vol->v_adouble = AD_VERSION2;
-        }
-        else if (strcasecmp(value, "osx") == 0) {
-            vol->v_adouble = AD_VERSION2_OSX;
-            vol->ad_path = ad_path_osx;
-        }
-#endif
-        else  {
+        } else if (strcasecmp(value, "ea") == 0) {
+            vol->ad_path = ad_path_ea;
+            vol->v_adouble = AD_VERSION_EA;
+        } else {
+
            fprintf (stderr, "unknown adouble version: %s, %s", buf, value);
            return -1;
         }
@@ -475,6 +464,7 @@ int closevolinfo(struct volinfo *volinfo)
  */
 int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_port)
 {
+    uid_t process_uid;
     char buf[16348];
     char item[MAXPATHLEN];
     int fd;
@@ -487,11 +477,31 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat (item, "/.AppleDesktop/", sizeof(item));
     strlcat (item, VOLINFOFILE, sizeof(item));
 
-    if ((fd = open( item, O_RDWR | O_CREAT , 0666)) <0 ) {
-        LOG(log_debug, logtype_afpd,"Error opening %s: %s", item, strerror(errno));
+    process_uid = geteuid();
+    if (process_uid) {
+        if (seteuid(0) == -1) {
+            process_uid = 0;
+        }
+    }
+
+    if ((fd = open(item, O_RDWR | O_CREAT , 0666)) <0 ) {
+        LOG(log_debug, logtype_default,"Error opening %s: %s", item, strerror(errno));
+        if (process_uid) {
+            if (seteuid(process_uid) == -1) {
+                LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+                exit(EXITERR_SYS);
+            }
+        }
         return (-1);
     }
 
+    if (process_uid) {
+        if (seteuid(process_uid) == -1) {
+            LOG(log_error, logtype_default, "can't seteuid back %s", strerror(errno));
+            exit(EXITERR_SYS);
+        }
+    }
+
     /* try to get a lock */
     lock.l_start  = 0;
     lock.l_whence = SEEK_SET;
@@ -503,7 +513,7 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
             /* ignore, other process already writing the file */
             return 0;
         } else {
-            LOG(log_error, logtype_cnid, "savevoloptions: cannot get lock: %s", strerror(errno));
+            LOG(log_error, logtype_default, "savevoloptions: cannot get lock: %s", strerror(errno));
             return (-1);
         }
     }
@@ -514,17 +524,11 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat(buf, item, sizeof(buf));
 
     switch (vol->v_adouble) {
-        case AD_VERSION1:
-            strlcat(buf, "ADOUBLE_VER:v1\n", sizeof(buf));
-            break;
         case AD_VERSION2:
             strlcat(buf, "ADOUBLE_VER:v2\n", sizeof(buf));
             break;
-        case AD_VERSION2_OSX:
-            strlcat(buf, "ADOUBLE_VER:osx\n", sizeof(buf));
-            break;
-        case AD_VERSION1_SFM:
-            strlcat(buf, "ADOUBLE_VER:sfm\n", sizeof(buf));
+        case AD_VERSION_EA:
+            strlcat(buf, "ADOUBLE_VER:ea\n", sizeof(buf));
             break;
     }
 
@@ -589,9 +593,9 @@ int savevolinfo(const struct vol *vol, const char *Cnid_srv, const char *Cnid_po
     strlcat(buf, item, sizeof(buf));
 
     if (strlen(buf) >= sizeof(buf)-1)
-        LOG(log_debug, logtype_afpd,"Error writing .volinfo file: buffer too small, %s", buf);
+        LOG(log_debug, logtype_default, "Error writing .volinfo file: buffer too small, %s", buf);
    if (write( fd, buf, strlen(buf)) < 0 || ftruncate(fd, strlen(buf)) < 0 ) {
-       LOG(log_debug, logtype_afpd,"Error writing .volinfo file: %s", strerror(errno));
+       LOG(log_debug, logtype_default, "Error writing .volinfo file: %s", strerror(errno));
    }
 
    lock.l_type = F_UNLCK;