]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
dirent.h is included in directory.h
[netatalk.git] / etc / afpd / volume.c
index 6d7799176b8e61b2b39f16a5a7b02a2f51ebc98a..fb57115f0681280c459f85e1ae75de2a048f01db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: volume.c,v 1.86 2009-04-28 13:01:24 franklahm Exp $
+ * $Id: volume.c,v 1.96 2009-10-27 23:35:17 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -12,7 +12,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <dirent.h>
 #include <pwd.h>
 #include <grp.h>
 #include <utime.h>
@@ -56,6 +55,8 @@ char *strchr (), *strrchr ();
 #include "unix.h"
 #include "mangle.h"
 #include "fork.h"
+#include "hash.h"
+#include "afp_vfs.h"
 
 extern int afprun(int root, char *cmd, int *outfd);
 
@@ -125,6 +126,7 @@ m=u -> map both ways
 #define VOLOPT_DPERM     24  /* dperm default directories perms */
 #define VOLOPT_FPERM     25  /* fperm default files perms */
 #define VOLOPT_DFLTPERM  26  /* perm */
+#define VOLOPT_EA_VFS    27  /* Extended Attributes vfs indirection */
 
 #define VOLOPT_MAX       (VOLOPT_DFLTPERM +1)
 
@@ -133,10 +135,11 @@ m=u -> map both ways
 #define VOLPASSLEN  8
 #define VOLOPT_DEFAULT     ":DEFAULT:"
 #define VOLOPT_DEFAULT_LEN 9
-  struct vol_option {
-      char *c_value;
-      int i_value;
-  };
+
+struct vol_option {
+    char *c_value;
+    int i_value;
+};
 
 typedef struct _special_folder {
         const char *name;
@@ -180,9 +183,9 @@ static const _vol_opt_name vol_opt_names[] = {
     {AFPVOL_NODEV,      "NODEV"},       /* always use 0 for device number in cnid calls */
     {AFPVOL_CASEINSEN,  "CASEINSENSITIVE"}, /* volume is case insensitive */
     {AFPVOL_EILSEQ,     "ILLEGALSEQ"},     /* encode illegal sequence */
-    {AFPVOL_CACHE,      "CACHEID"},     /* Use adouble v2 CNID caching, default don't use it */
-    {AFPVOL_EXT_ATTRS,  "EXT_ATTRS"},   /* Vol supports Extened Attributes */
+    {AFPVOL_CACHE,      "CACHEID"},     /* Use adouble v2 CNID caching. Default: yes */
     {AFPVOL_ACLS,       "ACLS"},        /* Vol supports ACLs */
+    {AFPVOL_TM,         "TM"},          /* Set "kSupportsTMLockSteal" is volume attributes */
     {0, NULL}
 };
 
@@ -447,8 +450,6 @@ static void volset(struct vol_option *options, struct vol_option *save,
             options[VOLOPT_ADOUBLE].i_value = AD_VERSION2;
         else if (strcasecmp(val + 1, "osx") == 0)
             options[VOLOPT_ADOUBLE].i_value = AD_VERSION2_OSX;
-        else if (strcasecmp(val + 1, "ads") == 0)
-            options[VOLOPT_ADOUBLE].i_value = AD_VERSION1_ADS;
         else if (strcasecmp(val + 1, "sfm") == 0)
             options[VOLOPT_ADOUBLE].i_value = AD_VERSION1_SFM;
 #endif
@@ -492,8 +493,6 @@ static void volset(struct vol_option *options, struct vol_option *save,
                options[VOLOPT_ROOTPREEXEC].i_value = 1;
             else if (strcasecmp(p, "upriv") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
-            else if (strcasecmp(p, "extattrs") == 0)
-                options[VOLOPT_FLAGS].i_value |= AFPVOL_EXT_ATTRS;
             else if (strcasecmp(p, "acls") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_ACLS;
             else if (strcasecmp(p, "nodev") == 0)
@@ -502,8 +501,10 @@ static void volset(struct vol_option *options, struct vol_option *save,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_CASEINSEN;
             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;
+            else if (strcasecmp(p, "nocnidcache") == 0)
+                options[VOLOPT_FLAGS].i_value &= ~AFPVOL_CACHE;
+            else if (strcasecmp(p, "tm") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_TM;
 
             p = strtok(NULL, ",");
         }
@@ -552,6 +553,12 @@ static void volset(struct vol_option *options, struct vol_option *save,
     } else if (optionok(tmp, "denied_hosts:", val)) {
         setoption(options, save, VOLOPT_DENIED_HOSTS, val);
 
+    } else if (optionok(tmp, "ea:", val)) {
+        if (strcasecmp(val + 1, "ad") == 0) /* the default anyway */
+            options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_AD;
+        else if (strcasecmp(val + 1, "solaris") == 0)
+            options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_SOLARIS;
+
     } else {
         /* ignore unknown options */
         LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
@@ -705,6 +712,7 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
     /* os X start at 1 and use network order ie. 1 2 3 */
     volume->v_vid = ++lastvid;
     volume->v_vid = htons(volume->v_vid);
+    volume->v_vfs_ea = AFPVOL_EA_AD;
 
     /* handle options */
     if (options) {
@@ -713,6 +721,9 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
 
         /* shift in some flags */
         volume->v_flags = options[VOLOPT_FLAGS].i_value;
+        
+        if (options[VOLOPT_EA_VFS].i_value != AFPVOL_EA_AD)
+            volume->v_vfs_ea = options[VOLOPT_EA_VFS].i_value;
 
         volume->v_ad_options = 0;
         if ((volume->v_flags & AFPVOL_NODEV))
@@ -798,10 +809,7 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
 }
 
 /* ---------------- */
-static char *myfgets( buf, size, fp )
-char   *buf;
-int            size;
-FILE   *fp;
+static char *myfgets( char *buf, int size, FILE *fp)
 {
     char       *p;
     int                c;
@@ -853,9 +861,7 @@ FILE        *fp;
 
 #endif
 
-static int accessvol(args, name)
-const char *args;
-const char *name;
+static int accessvol(const char *args, const char *name)
 {
     char buf[MAXPATHLEN + 1], *p;
     struct group *gr;
@@ -879,11 +885,7 @@ const char *name;
     return 0;
 }
 
-static int hostaccessvol(type, volname, args, obj)
-int type;
-char *volname;
-const char *args;
-const AFPObj *obj;
+static int hostaccessvol(int type, char *volname, const char *args, const AFPObj *obj)
 {
     char buf[MAXPATHLEN + 1], *p, *b;
     DSI *dsi = obj->handle;
@@ -928,9 +930,7 @@ const AFPObj *obj;
     return 0;
 }
 
-static void setextmap( ext, type, creator, user)
-char           *ext, *type, *creator;
-int                    user;
+static void setextmap(char *ext, char *type, char *creator, int user)
 {
     struct extmap      *em;
     int                 cnt;
@@ -1056,12 +1056,7 @@ static int volfile_changed(struct afp_volume_name *p)
  *                           [codepage:<file>] [casefold:<num>]
  *             <extension> TYPE [CREATOR]
  */
-static int readvolfile(obj, p1, p2, user, pwent)
-AFPObj      *obj;
-struct afp_volume_name         *p1;
-char        *p2;
-int            user;
-struct passwd *pwent;
+static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, char *p2, int user, struct passwd *pwent)
 {
     FILE               *fp;
     char               path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
@@ -1096,6 +1091,10 @@ struct passwd *pwent;
     }
 
     memset(save_options, 0, sizeof(save_options));
+
+    /* Enable some default options for all volumes */
+    save_options[VOLOPT_FLAGS].i_value |= AFPVOL_CACHE;
+
     while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
         initline( strlen( buf ), buf );
         parseline( sizeof( path ) - 1, path );
@@ -1302,10 +1301,9 @@ struct vol *vol, *ovol, *nvol;
     }
 }
 
-static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
-struct vol     *vol;
-u_int32_t      *bfree, *btotal, *bsize;
-VolSpace    *xbfree, *xbtotal;
+static int getvolspace(struct vol *vol,
+  u_int32_t *bfree, u_int32_t *btotal,
+  VolSpace *xbfree, VolSpace *xbtotal, u_int32_t *bsize)
 {
     int                spaceflag, rc;
     u_int32_t   maxsize;
@@ -1375,12 +1373,7 @@ static void vol_setdate(u_int16_t id, struct adouble *adp, time_t date)
 }
 
 /* ----------------------- */
-static int getvolparams( bitmap, vol, st, buf, buflen )
-u_int16_t      bitmap;
-struct vol     *vol;
-struct stat    *st;
-char   *buf;
-int            *buflen;
+static int getvolparams( u_int16_t bitmap, struct vol *vol, struct stat *st, char *buf, size_t *buflen)
 {
     struct adouble     ad;
     int                        bit = 0, isad = 1;
@@ -1458,16 +1451,17 @@ int             *buflen;
                 ashort |= VOLPBIT_ATTR_RO;
             }
             ashort |= VOLPBIT_ATTR_CATSEARCH;
+            ashort |= VOLPBIT_ATTR_EXT_ATTRS;
             if (afp_version >= 30) {
                 ashort |= VOLPBIT_ATTR_UTF8;
-               if (vol->v_flags & AFPVOL_UNIX_PRIV)
-                   ashort |= VOLPBIT_ATTR_UNIXPRIV;
+                if (vol->v_flags & AFPVOL_UNIX_PRIV)
+                    ashort |= VOLPBIT_ATTR_UNIXPRIV;
+                if (vol->v_flags & AFPVOL_TM)
+                    ashort |= VOLPBIT_ATTR_TM;
             }
             if (afp_version >= 32) {
-               if (vol->v_flags & AFPVOL_EXT_ATTRS)
-                   ashort |= VOLPBIT_ATTR_EXT_ATTRS;
                if (vol->v_flags & AFPVOL_ACLS)
-                   ashort |= VOLPBIT_ATTR_ACLS;
+                ashort |= VOLPBIT_ATTR_ACLS;
             }
             ashort = htons(ashort);
             memcpy(data, &ashort, sizeof( ashort ));
@@ -1582,10 +1576,11 @@ int             *buflen;
 }
 
 /* ------------------------- */
-static int stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, int *rbuflen)
+static int stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, size_t *rbuflen)
 {
     struct stat        st;
-    int                buflen, ret;
+    int                ret;
+    size_t     buflen;
 
     if ( stat( vol->v_path, &st ) < 0 ) {
         *rbuflen = 0;
@@ -1676,10 +1671,7 @@ void load_volumes(AFPObj *obj)
 }
 
 /* ------------------------------- */
-int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj  *obj;
-char   *ibuf _U_, *rbuf;
-int    ibuflen _U_, *rbuflen;
+int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct timeval     tv;
     struct stat                st;
@@ -1742,7 +1734,7 @@ int       ibuflen _U_, *rbuflen;
 
     *rbuflen = data - rbuf;
     data = rbuf;
-    if ( gettimeofday( &tv, 0 ) < 0 ) {
+    if ( gettimeofday( &tv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_getsrvrparms(%s): gettimeofday: %s", volume->v_path, strerror(errno) );
         *rbuflen = 0;
         return AFPERR_PARAM;
@@ -1757,10 +1749,7 @@ int      ibuflen _U_, *rbuflen;
 /* ------------------------- 
  * we are the user here
 */
-int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj  *obj;
-char   *ibuf, *rbuf;
-int    ibuflen _U_, *rbuflen;
+int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
 {
     struct stat        st;
     char       *volname;
@@ -1917,8 +1906,7 @@ int       ibuflen _U_, *rbuflen;
     curdir = volume->v_dir;
     if (volume->v_cnidscheme == NULL) {
         volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME);
-        LOG(log_warning, logtype_afpd, "Warning: No CNID scheme for volume %s. Using default.",
-               volume->v_path);
+        LOG(log_info, logtype_afpd, "Volume %s use CNID scheme %s.", volume->v_path, volume->v_cnidscheme);
     }
     if (volume->v_dbpath)
         volume->v_cdb = cnid_open (volume->v_dbpath, volume->v_umask, volume->v_cnidscheme, (volume->v_flags & AFPVOL_NODEV));
@@ -2074,10 +2062,7 @@ static void deletevol(struct vol *vol)
 }
 
 /* ------------------------- */
-int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj  *obj _U_;
-char   *ibuf, *rbuf _U_;
-int    ibuflen _U_, *rbuflen;
+int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol *vol;
     u_int16_t  vid;
@@ -2150,9 +2135,18 @@ struct extmap *getdefextmap(void)
 
 /* --------------------------
    poll if a volume is changed by other processes.
+   return 
+    0 no attention msg sent
+    1 attention msg sent
+   -1 error (socket closed)
+   
+   Note: if attention return -1 no packet has been
+   sent because the buffer is full, we don't care
+   either there's no reader or there's a lot of
+   traffic and another pollvoltime will follow
 */
-int  pollvoltime(obj)
-AFPObj *obj;
+int  pollvoltime(AFPObj *obj)
+
 {
     struct vol      *vol;
     struct timeval   tv;
@@ -2161,7 +2155,7 @@ AFPObj *obj;
     if (!(afp_version > 21 && obj->options.server_notif)) 
          return 0;
 
-    if ( gettimeofday( &tv, 0 ) < 0 ) 
+    if ( gettimeofday( &tv, NULL ) < 0 ) 
          return 0;
 
     for ( vol = Volumes; vol; vol = vol->v_next ) {
@@ -2178,9 +2172,7 @@ AFPObj *obj;
 }
 
 /* ------------------------- */
-void setvoltime(obj, vol )
-AFPObj *obj;
-struct vol     *vol;
+void setvoltime(AFPObj *obj, struct vol *vol)
 {
     struct timeval     tv;
 
@@ -2190,7 +2182,7 @@ struct vol        *vol;
      * the afpd processes would come closer)
      * [RS] */
 
-    if ( gettimeofday( &tv, 0 ) < 0 ) {
+    if ( gettimeofday( &tv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "setvoltime(%s): gettimeofday: %s", vol->v_path, strerror(errno) );
         return;
     }
@@ -2203,7 +2195,9 @@ struct vol        *vol;
     /* a little granularity */
     if (vol->v_mtime < tv.tv_sec) {
         vol->v_mtime = tv.tv_sec;
-        /* or finder doesn't update free space */
+        /* or finder doesn't update free space 
+         * XXX is it still true with newer OSX?
+        */
         if (afp_version > 21 && obj->options.server_notif) {
             obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
         }
@@ -2211,10 +2205,7 @@ struct vol       *vol;
 }
 
 /* ------------------------- */
-int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj  *obj _U_;
-char   *ibuf, *rbuf;
-int    ibuflen _U_, *rbuflen;
+int afp_getvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,char *rbuf, size_t *rbuflen)
 {
     struct vol *vol;
     u_int16_t  vid, bitmap;
@@ -2234,10 +2225,7 @@ int      ibuflen _U_, *rbuflen;
 }
 
 /* ------------------------- */
-int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
-AFPObj  *obj _U_;
-char   *ibuf, *rbuf _U_;
-int    ibuflen _U_, *rbuflen;
+int afp_setvolparams(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_,  size_t *rbuflen)
 {
     struct adouble ad;
     struct vol *vol;
@@ -2462,9 +2450,6 @@ static int savevoloptions (const struct vol *vol)
         case AD_VERSION2_OSX:
             strlcat(buf, "ADOUBLE_VER:osx\n", sizeof(buf));
             break;
-        case AD_VERSION1_ADS:
-            strlcat(buf, "ADOUBLE_VER:ads\n", sizeof(buf));
-            break;
         case AD_VERSION1_SFM:
             strlcat(buf, "ADOUBLE_VER:sfm\n", sizeof(buf));
             break;