]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
add dperm and fperm permissions default
[netatalk.git] / etc / afpd / volume.c
index bc11c4d04e60bb902e40707589842460d93993ff..53a0bc23ee4c123fd106dc4058e729cf05edf03a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: volume.c,v 1.51.2.7.2.33.2.10 2005-09-28 09:53:47 didg Exp $
+ * $Id: volume.c,v 1.51.2.7.2.33.2.19 2009-01-28 05:37:58 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -114,13 +114,13 @@ m=u -> map both ways
 
 #define VOLOPT_FORCEUID  19  /* force uid for username x */
 #define VOLOPT_FORCEGID  20  /* force gid for group x */
-#define VOLOPT_UMASK     21
-#define VOLOPT_DFLTPERM  22
-#else 
-#define VOLOPT_UMASK     19
-#define VOLOPT_DFLTPERM  20
 #endif /* FORCE_UIDGID */
 
+#define VOLOPT_UMASK     21
+#define VOLOPT_DPERM     22  /* dperm default directories perms */
+#define VOLOPT_FPERM     23  /* dperm default files perms */
+#define VOLOPT_DFLTPERM  24  /* perm */
+
 #define VOLOPT_MAX       (VOLOPT_DFLTPERM +1)
 
 #define VOLOPT_NUM        (VOLOPT_MAX + 1)
@@ -171,6 +171,8 @@ static const _vol_opt_name vol_opt_names[] = {
                                          * maybe because it will be mounted later in preexec */
     {AFPVOL_UNIX_PRIV,  "UNIXPRIV"},    /* support unix privileges */
     {AFPVOL_NODEV,      "NODEV"},       /* always use 0 for device number in cnid calls */
+    {AFPVOL_EILSEQ,     "ILLEGALSEQ"},  /* encode illegal sequence */
+    {AFPVOL_CACHE,      "CACHEID"},     /* Use adouble v2 CNID caching, default don't use it */
     {0, NULL}
 };
 
@@ -185,7 +187,7 @@ static const _vol_opt_name vol_opt_casefold[] = {
 static void handle_special_folders (const struct vol *);
 static int savevoloptions (const struct vol *);
 
-static __inline__ void volfree(struct vol_option *options,
+static void volfree(struct vol_option *options,
                                const struct vol_option *save)
 {
     int i;
@@ -451,6 +453,8 @@ static void volset(struct vol_option *options, struct vol_option *save,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX;
             else if (strcasecmp(p, "usedots") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS;
+            else if (strcasecmp(p, "invisibledots") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS | AFPVOL_INV_DOTS;
             else if (strcasecmp(p, "limitsize") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
             /* support for either "dropbox" or "dropkludge" */
@@ -470,6 +474,8 @@ static void volset(struct vol_option *options, struct vol_option *save,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
             else if (strcasecmp(p, "nodev") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_NODEV;
+            else if (strcasecmp(p, "illegalseq") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_EILSEQ;
             else if (strcasecmp(p, "cachecnid") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_CACHE;
 
@@ -483,6 +489,10 @@ static void volset(struct vol_option *options, struct vol_option *save,
        options[VOLOPT_UMASK].i_value = (int)strtol(val +1, NULL, 8);
     } else if (optionok(tmp, "perm:", val)) {
         options[VOLOPT_DFLTPERM].i_value = (int)strtol(val+1, NULL, 8);
+    } else if (optionok(tmp, "dperm:", val)) {
+        options[VOLOPT_DPERM].i_value = (int)strtol(val+1, NULL, 8);
+    } else if (optionok(tmp, "fperm:", val)) {
+        options[VOLOPT_FPERM].i_value = (int)strtol(val+1, NULL, 8);
     } else if (optionok(tmp, "mapchars:",val)) {
         setoption(options, save, VOLOPT_MAPCHARS, val);
 
@@ -534,7 +544,11 @@ static void showvol(const ucs2_t *name)
 */
 static int validupath_adouble(const struct vol *vol, const char *name) 
 {
-    return (vol->v_flags & AFPVOL_USEDOTS) ? strncasecmp(name,".Apple", 6) && strcasecmp(name, ".Parent")
+    return (vol->v_flags & AFPVOL_USEDOTS) ? 
+        strcasecmp(name,".AppleDB") &&
+        strcasecmp(name,".AppleDouble") &&
+        strcasecmp(name,".AppleDesktop") &&
+        strcasecmp(name,".Parent")
                                            : name[0] != '.';
 }                                           
 
@@ -641,6 +655,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
             volume->v_ad_options |= ADVOL_CACHE;
         if ((volume->v_flags & AFPVOL_UNIX_PRIV))
             volume->v_ad_options |= ADVOL_UNIXPRIV;
+        if ((volume->v_flags & AFPVOL_INV_DOTS))
+            volume->v_ad_options |= ADVOL_INVDOTS;
 
         if (options[VOLOPT_PASSWORD].c_value)
             volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
@@ -663,6 +679,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
        if (options[VOLOPT_UMASK].i_value)
            volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
 
+       if (options[VOLOPT_DPERM].i_value)
+
        if (options[VOLOPT_DFLTPERM].i_value)
            volume->v_perm = (mode_t)options[VOLOPT_DFLTPERM].i_value;
 
@@ -699,6 +717,8 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
                 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path,  name);
         }
     }
+    volume->v_dperm |= volume->v_perm;
+    volume->v_fperm |= volume->v_perm;
 
     initvoladouble(volume);
     volume->v_next = Volumes;
@@ -716,7 +736,7 @@ FILE        *fp;
     int                c;
 
     p = buf;
-    while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
+    while ((EOF != ( c = getc( fp )) ) && ( size > 1 )) {
         if ( c == '\n' || c == '\r' ) {
             *p++ = '\n';
             break;
@@ -2178,14 +2198,14 @@ static int create_special_folder (const struct vol *vol, const struct _special_f
                ad_getattr(&ad, &attr);
                attr |= htons( ntohs( attr ) | ATTRBIT_INVISIBLE );
                ad_setattr(&ad, attr);
-#if 0          
+
                /* do the same with the finder info */
                if (ad_entry(&ad, ADEID_FINDERI)) {
                        memcpy(&attr, ad_entry(&ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF, sizeof(attr));
                        attr   |= htons(FINDERINFO_INVISIBLE);
                        memcpy(ad_entry(&ad, ADEID_FINDERI) + FINDERINFO_FRFLAGOFF,&attr, sizeof(attr));
                }
-#endif    
+
                ad_flush( &ad, ADFLAGS_HF );
                ad_close( &ad, ADFLAGS_HF );
        }
@@ -2309,13 +2329,10 @@ static int savevoloptions (const struct vol *vol)
         LOG(log_debug, logtype_afpd,"Error writing .volinfo file: buffer too small, %s", buf);
 
 
-   if (write( fd, buf, strlen(buf)) < 0) {
+   if (write( fd, buf, strlen(buf)) < 0 || ftruncate(fd, strlen(buf)) < 0 ) {
        LOG(log_debug, logtype_afpd,"Error writing .volinfo file: %s", strerror(errno));
-       goto done;
    }
-   ftruncate(fd, strlen(buf));
 
-done:
    lock.l_type = F_UNLCK;
    fcntl(fd, F_SETLK, &lock);
    close (fd);