]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
1) try a better workaround for deadlocks when both the server and the client are...
[netatalk.git] / etc / afpd / volume.c
index 9c5272458c9b108fee8834aeaa3c4fe2c974978a..ee13de809423526767a645abcbaaf7e1fd3abb29 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: volume.c,v 1.68 2006-09-29 09:39:16 didg Exp $
+ * $Id: volume.c,v 1.95 2009-10-25 06:12:51 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -43,6 +43,7 @@ char *strchr (), *strrchr ();
 #include <atalk/adouble.h>
 #include <atalk/afp.h>
 #include <atalk/util.h>
+#include <atalk/volinfo.h>
 #include <atalk/logger.h>
 #ifdef CNID_DB
 #include <atalk/cnid.h>
@@ -53,7 +54,10 @@ char *strchr (), *strrchr ();
 #include "file.h"
 #include "volume.h"
 #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);
 
@@ -115,13 +119,16 @@ 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_ALLOWED_HOSTS 22
+#define VOLOPT_DENIED_HOSTS  23
+#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)
 
 #define VOLOPT_NUM        (VOLOPT_MAX + 1)
@@ -129,10 +136,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;
@@ -156,6 +164,8 @@ typedef struct _volopt_name {
        const char      *name;
 } _vol_opt_name;
 
+
+/* Keep in sync with libatalk/util/volinfo.c ! */
 static const _vol_opt_name vol_opt_names[] = {
     {AFPVOL_A2VOL,      "PRODOS"},      /* prodos volume */
     {AFPVOL_CRLF,       "CRLF"},        /* cr/lf translation */
@@ -174,7 +184,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_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}
 };
 
@@ -189,8 +201,9 @@ static const _vol_opt_name vol_opt_casefold[] = {
 static void handle_special_folders (const struct vol *);
 static int savevoloptions (const struct vol *);
 static void deletevol(struct vol *vol);
+static void volume_free(struct vol *vol);
 
-static __inline__ void volfree(struct vol_option *options,
+static void volfree(struct vol_option *options,
                                const struct vol_option *save)
 {
     int i;
@@ -315,7 +328,11 @@ static char *volxlate(AFPObj *obj, char *dest, size_t destlen,
             } else
                 q = obj->options.hostname;
         } else if (is_var(p, "$u")) {
-            q = obj->username;
+            char* sep = NULL;
+            if ( obj->options.ntseparator && (sep = strchr(obj->username, obj->options.ntseparator[0])) != NULL)
+                q = sep+1;
+            else
+                q = obj->username;
         } else if (is_var(p, "$v")) {
             if (volname) {
                 q = volname;
@@ -434,8 +451,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
@@ -479,14 +494,18 @@ 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, "acls") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_ACLS;
             else if (strcasecmp(p, "nodev") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_NODEV;
             else if (strcasecmp(p, "caseinsensitive") == 0)
                 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, ",");
         }
@@ -496,6 +515,10 @@ static void volset(struct vol_option *options, struct vol_option *save,
 
     } else if (optionok(tmp, "umask:", val)) {
        options[VOLOPT_UMASK].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, "perm:", val)) {
         options[VOLOPT_DFLTPERM].i_value = (int)strtol(val+1, NULL, 8);
     } else if (optionok(tmp, "mapchars:",val)) {
@@ -525,6 +548,18 @@ static void volset(struct vol_option *options, struct vol_option *save,
     } else if (optionok(tmp, "postexec:", val)) {
         setoption(options, save, VOLOPT_POSTEXEC, val);
 
+    } else if (optionok(tmp, "allowed_hosts:", val)) {
+        setoption(options, save, VOLOPT_ALLOWED_HOSTS, val);
+
+    } 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);
@@ -537,7 +572,7 @@ static void showvol(const ucs2_t *name)
 {
     struct vol *volume;
     for ( volume = Volumes; volume; volume = volume->v_next ) {
-        if (volume->v_hide && !strcasecmp_w( volume->v_name, name ) ) {
+      if (volume->v_hide && !strcasecmp_w( volume->v_name, name ) ) {
             volume->v_hide = 0;
             return;
         }
@@ -552,9 +587,12 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
                     )
 {
     struct vol *volume;
-    int                vlen;
+    int         suffixlen, vlen, tmpvlen, u8mvlen, macvlen;
     int         hide = 0;
-    ucs2_t     tmpname[512];
+    char        tmpname[AFPVOL_U8MNAMELEN+1];
+    ucs2_t      u8mtmpname[(AFPVOL_U8MNAMELEN+1)*2], mactmpname[(AFPVOL_MACNAMELEN+1)*2];
+    char        suffix[6]; /* max is #FFFF */
+    u_int16_t   flags;
 
     if ( name == NULL || *name == '\0' ) {
         if ((name = strrchr( path, '/' )) == NULL) {
@@ -566,18 +604,67 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
             return -1;
     }
 
+    /* suffix for mangling use (lastvid + 1)   */
+    /* because v_vid has not been decided yet. */
+    suffixlen = sprintf(suffix, "%c%X", MANGLE_CHAR, lastvid + 1 );
+
     vlen = strlen( name );
-    if ( vlen > AFPVOL_NAMELEN ) {
-        vlen = AFPVOL_NAMELEN;
-        name[AFPVOL_NAMELEN] = '\0';
+
+    /* Unicode Volume Name */
+    /* Firstly convert name from unixcharset to UTF8-MAC */
+    flags = CONV_IGNORE;
+    tmpvlen = convert_charset(obj->options.unixcharset, CH_UTF8_MAC, 0, name, vlen, tmpname, AFPVOL_U8MNAMELEN, &flags);
+    if (tmpvlen <= 0) {
+        strcpy(tmpname, "???");
+        tmpvlen = 3;
+    }
+
+    /* Do we have to mangle ? */
+    if ( (flags & CONV_REQMANGLE) || (tmpvlen > obj->options.volnamelen)) {
+        if (tmpvlen + suffixlen > obj->options.volnamelen) {
+            flags = CONV_FORCE;
+            tmpvlen = convert_charset(obj->options.unixcharset, CH_UTF8_MAC, 0, name, vlen, tmpname, obj->options.volnamelen - suffixlen, &flags);
+            tmpname[tmpvlen != (size_t)-1 ? tmpvlen : 0] = 0;
+        }
+        strcat(tmpname, suffix);
+        tmpvlen = strlen(tmpname);
     }
 
-    /* convert name to UCS2 first */
-    if ( 0 >= ( vlen = convert_string(obj->options.unixcharset, CH_UCS2, name, vlen, tmpname, 512)) )
+    /* Secondly convert name from UTF8-MAC to UCS2 */
+    if ( 0 >= ( u8mvlen = convert_string(CH_UTF8_MAC, CH_UCS2, tmpname, tmpvlen, u8mtmpname, AFPVOL_U8MNAMELEN*2)) )
         return -1;
 
+    LOG(log_debug, logtype_afpd, "createvol: Volume '%s' -> UTF8-MAC Name: '%s'", name, tmpname);
+
+    /* Maccharset Volume Name */
+    /* Firsty convert name from unixcharset to maccharset */
+    flags = CONV_IGNORE;
+    tmpvlen = convert_charset(obj->options.unixcharset, obj->options.maccharset, 0, name, vlen, tmpname, AFPVOL_U8MNAMELEN, &flags);
+    if (tmpvlen <= 0) {
+        strcpy(tmpname, "???");
+        tmpvlen = 3;
+    }
+
+    /* Do we have to mangle ? */
+    if ( (flags & CONV_REQMANGLE) || (tmpvlen > AFPVOL_MACNAMELEN)) {
+        if (tmpvlen + suffixlen > AFPVOL_MACNAMELEN) {
+            flags = CONV_FORCE;
+            tmpvlen = convert_charset(obj->options.unixcharset, obj->options.maccharset, 0, name, vlen, tmpname, AFPVOL_MACNAMELEN - suffixlen, &flags);
+            tmpname[tmpvlen != (size_t)-1 ? tmpvlen : 0] = 0;
+        }
+        strcat(tmpname, suffix);
+        tmpvlen = strlen(tmpname);
+    }
+
+    /* Secondly convert name from maccharset to UCS2 */
+    if ( 0 >= ( macvlen = convert_string(obj->options.maccharset, CH_UCS2, tmpname, tmpvlen, mactmpname, AFPVOL_U8MNAMELEN*2)) )
+        return -1;
+
+    LOG(log_debug, logtype_afpd, "createvol: Volume '%s' ->  Longname: '%s'", name, tmpname);
+
+    /* check duplicate */
     for ( volume = Volumes; volume; volume = volume->v_next ) {
-        if ( strcasecmp_w( volume->v_name, tmpname ) == 0 ) {
+      if (( strcasecmp_w( volume->v_u8mname, u8mtmpname ) == 0 ) || ( strcasecmp_w( volume->v_macname, mactmpname ) == 0 )){
            if (volume->v_deleted) {
                volume->v_new = hide = 1;
            }
@@ -587,22 +674,36 @@ static int creatvol(AFPObj *obj, struct passwd *pwd,
         }
     }
 
-
     if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
         LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
         return -1;
     }
-    if ( NULL == ( volume->v_name = strdup_w(tmpname))) {
+    if ( NULL == ( volume->v_localname = strdup(name))) {
+        LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
+        free(volume);
+        return -1;
+    }
+
+    if ( NULL == ( volume->v_u8mname = strdup_w(u8mtmpname))) {
         LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
+        volume_free(volume);
+        free(volume);
+        return -1;
+    }
+    if ( NULL == ( volume->v_macname = strdup_w(mactmpname))) {
+        LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
+        volume_free(volume);
         free(volume);
         return -1;
     }
     if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
         LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
-        free(volume->v_name);
+        volume_free(volume);
         free(volume);
         return -1;
     }
+
+    volume->v_name = utf8_encoding()?volume->v_u8mname:volume->v_macname;
     volume->v_hide = hide;
     strcpy( volume->v_path, path );
 
@@ -612,6 +713,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) {
@@ -620,6 +722,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))
@@ -652,6 +757,12 @@ 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)
+           volume->v_dperm = (mode_t)options[VOLOPT_DPERM].i_value;
+
+       if (options[VOLOPT_FPERM].i_value)
+           volume->v_fperm = (mode_t)options[VOLOPT_FPERM].i_value;
+
        if (options[VOLOPT_DFLTPERM].i_value)
            volume->v_perm = (mode_t)options[VOLOPT_DFLTPERM].i_value;
 
@@ -690,6 +801,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;
 
     volume->v_next = Volumes;
     Volumes = volume;
@@ -697,17 +810,19 @@ 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;
 
     p = buf;
-    while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
+    while ((EOF != ( c = getc( fp )) ) && ( size > 1 )) {
         if ( c == '\n' || c == '\r' ) {
+            if (p != buf && *(p -1) == '\\') {
+                p--;
+                size++;
+                continue;
+            }
             *p++ = '\n';
             break;
         } else {
@@ -747,9 +862,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;
@@ -773,9 +886,52 @@ const char *name;
     return 0;
 }
 
-static void setextmap( ext, type, creator, user)
-char           *ext, *type, *creator;
-int                    user;
+static int hostaccessvol(int type, char *volname, const char *args, const AFPObj *obj)
+{
+    char buf[MAXPATHLEN + 1], *p, *b;
+    DSI *dsi = obj->handle;
+
+    if (!args)
+        return -1;
+
+    strlcpy(buf, args, sizeof(buf));
+    if ((p = strtok_r(buf, ",", &b)) == NULL) /* nothing, return okay */
+        return -1;
+
+    while (p) {
+        if (obj->proto == AFPPROTO_DSI) {
+            struct in_addr mask, net;
+            char *net_char, *mask_char;
+            int mask_int;
+
+            net_char = strtok(p, "/");
+            mask_char = strtok(NULL,"/");
+            if (mask_char == NULL) {
+                mask_int = 32;
+            } else {
+                mask_int = atoi(mask_char);
+            }
+           
+            // convert the integer netmask to a bitmask in network order
+            mask.s_addr = htonl(-1 - ((1 << (32 - mask_int)) - 1));
+            net.s_addr = inet_addr(net_char) & mask.s_addr;
+
+            if ((dsi->client.sin_addr.s_addr & mask.s_addr) == net.s_addr) {
+                   if (type == VOLOPT_DENIED_HOSTS)
+                       LOG(log_info, logtype_afpd, "AFP access denied for client IP '%s' to volume '%s' by denied list",
+                           inet_ntoa(dsi->client.sin_addr), volname);
+                   return 1;
+           }
+        }
+        p = strtok_r(NULL, ",", &b);
+    }
+    if (type == VOLOPT_ALLOWED_HOSTS)
+       LOG(log_info, logtype_afpd, "AFP access denied for client IP '%s' to volume '%s', not in allowed list",
+           inet_ntoa(dsi->client.sin_addr), volname);
+    return 0;
+}
+
+static void setextmap(char *ext, char *type, char *creator, int user)
 {
     struct extmap      *em;
     int                 cnt;
@@ -901,16 +1057,11 @@ 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],
-    volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
+    volname[ AFPVOL_U8MNAMELEN + 1 ], buf[ BUFSIZ ],
     type[ 5 ], creator[ 5 ];
     char               *u, *p;
     struct passwd      *pw;
@@ -941,6 +1092,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 );
@@ -1028,7 +1183,9 @@ struct passwd *pwent;
                allow -> either no list (-1), or in list (1)
                deny -> either no list (-1), or not in list (0) */
             if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
-                    (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
+               (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1) &&
+               hostaccessvol(VOLOPT_ALLOWED_HOSTS, volname, options[VOLOPT_ALLOWED_HOSTS].c_value, obj) &&
+               (hostaccessvol(VOLOPT_DENIED_HOSTS, volname, options[VOLOPT_DENIED_HOSTS].c_value, obj) < 1)) {
 
                 /* handle read-only behaviour. semantics:
                  * 1) neither the rolist nor the rwlist exist -> rw
@@ -1070,8 +1227,12 @@ struct passwd *pwent;
 /* ------------------------------- */
 static void volume_free(struct vol *vol)
 {
-    free(vol->v_name);
-    vol->v_name = NULL;
+    free(vol->v_localname);
+    vol->v_localname = NULL;
+    free(vol->v_u8mname);
+    vol->v_u8mname = NULL;
+    free(vol->v_macname);
+    vol->v_macname = NULL;
     free(vol->v_path);
     free(vol->v_password);
     free(vol->v_veto);
@@ -1103,7 +1264,7 @@ static void free_volumes(void )
     for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
         nvol = vol->v_next;
 
-        if (vol->v_name == NULL) {
+        if (vol->v_localname == NULL) {
            if (Volumes == vol) {
                Volumes = nvol;
                ovol = Volumes;
@@ -1141,10 +1302,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;
@@ -1214,12 +1374,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;
@@ -1230,6 +1385,8 @@ int               *buflen;
     char               *data, *nameoff = NULL;
     char                *slash;
 
+    LOG(log_debug, logtype_afpd, "getvolparams: Volume '%s'", vol->v_localname);
+
     /* courtesy of jallison@whistle.com:
      * For MacOS8.x support we need to create the
      * .Parent file here if it doesn't exist. */
@@ -1295,10 +1452,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_ACLS)
+                ashort |= VOLPBIT_ATTR_ACLS;
             }
             ashort = htons(ashort);
             memcpy(data, &ashort, sizeof( ashort ));
@@ -1395,8 +1559,8 @@ int               *buflen;
     if ( nameoff ) {
         ashort = htons( data - buf );
         memcpy(nameoff, &ashort, sizeof( ashort ));
-        /* name is always in mac charset, FIXME mangle if length > 27 char */
-       aint = ucs2_to_charset( vol->v_maccharset, vol->v_name, data+1, 255);
+        /* name is always in mac charset */
+       aint = ucs2_to_charset( vol->v_maccharset, vol->v_macname, data+1, AFPVOL_MACNAMELEN + 1);
        if ( aint <= 0 ) {
            *buflen = 0;
             return AFPERR_MISC;
@@ -1413,10 +1577,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;
@@ -1507,10 +1672,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;
@@ -1543,8 +1705,13 @@ int      ibuflen _U_, *rbuflen;
         if (volume->v_hide) {
             continue;          /* config file changed but the volume was mounted */
         }
-       len = ucs2_to_charset_allocate((utf8_encoding()?CH_UTF8_MAC:obj->options.maccharset),
-                                       &namebuf, volume->v_name);
+
+       if (utf8_encoding()) {
+           len = ucs2_to_charset_allocate(CH_UTF8_MAC, &namebuf, volume->v_u8mname);
+       } else {
+           len = ucs2_to_charset_allocate(obj->options.maccharset, &namebuf, volume->v_macname);
+       }
+
        if (len == (size_t)-1)
                continue;
 
@@ -1568,7 +1735,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;
@@ -1583,10 +1750,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;
@@ -1599,6 +1763,7 @@ int       ibuflen _U_, *rbuflen;
     char        path[ MAXPATHLEN + 1];
     char        *vol_uname;
     char        *vol_mname;
+    char        *volname_tmp;
 
     ibuf += 2;
     memcpy(&bitmap, ibuf, sizeof( bitmap ));
@@ -1611,8 +1776,16 @@ int      ibuflen _U_, *rbuflen;
 
     len = (unsigned char)*ibuf++;
     volname = obj->oldtmp;
-    namelen = convert_string( (utf8_encoding()?CH_UTF8_MAC:obj->options.maccharset), CH_UCS2,
-                              ibuf, len, volname, sizeof(obj->oldtmp));
+
+    if ((volname_tmp = strchr(volname,'+')) != NULL)
+        volname = volname_tmp+1;
+
+    if (utf8_encoding()) {
+      namelen = convert_string(CH_UTF8_MAC, CH_UCS2, ibuf, len, volname, sizeof(obj->oldtmp));
+    } else {
+      namelen = convert_string(obj->options.maccharset, CH_UCS2, ibuf, len, volname, sizeof(obj->oldtmp));
+    }
+
     if ( namelen <= 0){
         *rbuflen = 0;
         return AFPERR_PARAM;
@@ -1652,7 +1825,7 @@ int       ibuflen _U_, *rbuflen;
     /* initialize volume variables
      * FIXME file size
     */
-    if (afp_version >= 30) {
+    if (utf8_encoding()) {
         volume->max_filename = 255;
     }
     else {
@@ -1695,8 +1868,11 @@ int      ibuflen _U_, *rbuflen;
         goto openvol_err;
     }
 
-    len = convert_string_allocate( CH_UCS2, (utf8_encoding()?CH_UTF8_MAC:obj->options.maccharset),
-                                      volume->v_name, namelen, &vol_mname);
+    if (utf8_encoding()) {
+        len = convert_string_allocate(CH_UCS2, CH_UTF8_MAC, volume->v_u8mname, namelen, &vol_mname);
+    } else {
+        len = convert_string_allocate(CH_UCS2, obj->options.maccharset, volume->v_macname, namelen, &vol_mname);
+    }
     if ( !vol_mname || len <= 0) {
         ret = AFPERR_MISC;
         goto openvol_err;
@@ -1731,8 +1907,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));
@@ -1880,7 +2055,7 @@ static void deletevol(struct vol *vol)
 
     closevol(vol);
     if (vol->v_deleted) {
-       showvol(vol->v_name);
+      showvol(vol->v_name);
        volume_free(vol);
        volume_unlink(vol);
        free(vol);
@@ -1888,10 +2063,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;
@@ -1964,9 +2136,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;
@@ -1975,7 +2156,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 ) {
@@ -1992,9 +2173,7 @@ AFPObj *obj;
 }
 
 /* ------------------------- */
-void setvoltime(obj, vol )
-AFPObj *obj;
-struct vol     *vol;
+void setvoltime(AFPObj *obj, struct vol *vol)
 {
     struct timeval     tv;
 
@@ -2004,7 +2183,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;
     }
@@ -2017,7 +2196,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);
         }
@@ -2025,10 +2206,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;
@@ -2048,10 +2226,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;
@@ -2276,9 +2451,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;
@@ -2329,13 +2501,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);