]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
MFH: Set the volume creation time from the first stat call done in openvol -before...
[netatalk.git] / etc / afpd / volume.c
index 280f71b0b5ab52c20ea8889725fa5ac077eacf87..68fb8351b3cd744458e63d49525d396073e1d1e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: volume.c,v 1.40 2002-10-16 16:19:34 jmarcus Exp $
+ * $Id: volume.c,v 1.36.2.5 2003-09-18 19:24:54 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -293,15 +293,19 @@ static __inline__ char *get_codepage_path(const char *path, const char *name)
 
 /* handle all the options. tmp can't be NULL. */
 static void volset(struct vol_option *options, char *volname, int vlen,
-                   const char *nlspath, const char *tmp, AFPObj *obj,
+                  const char *nlspath, const char *tmp, AFPObj *obj,
                   struct passwd *pwd)
 {
     char *val;
 
+    LOG(log_debug, logtype_afpd, "Parsing volset %s", tmp);
+
     val = strchr(tmp, ':');
-    LOG(log_debug, logtype_afpd, "Parsing volset %s", val);
+    if (!val) {
+        /* we'll assume it's a volume name. */
+        strncpy(volname, tmp, vlen);
 
-    if (optionok(tmp, "allow:", val)) {
+    } else if (optionok(tmp, "allow:", val)) {
         if (options[VOLOPT_ALLOW].c_value)
             free(options[VOLOPT_ALLOW].c_value);
         options[VOLOPT_ALLOW].c_value = strdup(val + 1);
@@ -386,7 +390,7 @@ static void volset(struct vol_option *options, char *volname, int vlen,
             free(options[VOLOPT_DBPATH].c_value);
 
        volxlate(obj, t, MAXPATHLEN, val, pwd, NULL);
-        options[VOLOPT_DBPATH].c_value = strdup(t + 1);
+       options[VOLOPT_DBPATH].c_value = strdup(t + 1);
 #endif /* CNID_DB */
     } else if (optionok(tmp, "umask:", val)) {
        options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
@@ -414,13 +418,10 @@ static void volset(struct vol_option *options, char *volname, int vlen,
 
 #endif /* FORCE_UIDGID */
 
-    } else if (val) {
+    } else {
         /* ignore unknown options */
         LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
 
-    } else {
-        /* we'll assume it's a volume name. */
-        strncpy(volname, tmp, vlen);
     }
 }
 
@@ -537,7 +538,7 @@ FILE        *fp;
     int                c;
 
     p = buf;
-    while ((( c = getc( fp )) != EOF ) && ( size > 0 )) {
+    while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
         if ( c == '\n' || c == '\r' ) {
             *p++ = '\n';
             break;
@@ -640,10 +641,6 @@ int                        user;
     } else {
         memcpy(em->em_creator, creator, sizeof( em->em_creator ));
     }
-
-    if ( !*ext ) {
-        defextmap = em;
-    }
 }
 
 /* -------------------------- */
@@ -658,16 +655,17 @@ static void sortextmap( void)
 {
     struct extmap      *em;
 
+    extmap_cnt = 0;
     if ((em = extmap) == NULL) {
         return;
     }
-    extmap_cnt = 0;
     while (em->em_ext) {
         em++;
         extmap_cnt++;
     }
     if (extmap_cnt) {
         qsort(extmap, extmap_cnt, sizeof(struct extmap), extmap_cmp);
+        defextmap = extmap;
     }
 }
 
@@ -707,7 +705,7 @@ struct passwd *pwent;
         strcat( path, p2 );
     }
 
-    if (( fp = fopen( path, "r" )) == NULL ) {
+    if (NULL == ( fp = fopen( path, "r" )) ) {
         return( -1 );
     }
 
@@ -729,7 +727,7 @@ struct passwd *pwent;
                                    path + VOLOPT_DEFAULT_LEN) < 0)
                         break;
                     volset(save_options, tmp, sizeof(tmp) - 1,
-                           obj->options.nlspath, path + VOLOPT_DEFAULT_LEN,
+                          obj->options.nlspath, path + VOLOPT_DEFAULT_LEN,
                           obj, pwent);
                 }
             }
@@ -792,7 +790,7 @@ struct passwd *pwent;
                     break;
 
                 volset(options, volname, sizeof(volname) - 1,
-                       obj->options.nlspath, tmp, obj, pwent);
+                      obj->options.nlspath, tmp, obj, pwent);
             }
 
             /* check allow/deny lists:
@@ -954,7 +952,7 @@ int         *buflen;
         ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
         memcpy(ad_entry( &ad, ADEID_NAME ), slash,
                ad_getentrylen( &ad, ADEID_NAME ));
-       ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
+        ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
         ad_flush(&ad, ADFLAGS_HF);
     }
 
@@ -990,15 +988,9 @@ int                *buflen;
              *       it's passed in that way as it's possible to mount
              *       a read-write filesystem under a read-only one. */
             if ((vol->v_flags & AFPVOL_RO) ||
-                    ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
+                    ((utime(vol->v_path, NULL) < 0) && (errno == EROFS)))
                 ashort |= VOLPBIT_ATTR_RO;
-            }
-#ifdef WITH_CATSEARCH
-            ashort |= VOLPBIT_ATTR_CATSEARCH;
-#endif
-            if (afp_version >= 30) {
-                ashort |= VOLPBIT_ATTR_UTF8;
-            }
+                ashort |= VOLPBIT_ATTR_CATSEARCH;
             ashort = htons(ashort);
             memcpy(data, &ashort, sizeof( ashort ));
             data += sizeof( ashort );
@@ -1222,14 +1214,14 @@ int             ibuflen, *rbuflen;
     }
 
     if (( volume->v_flags & AFPVOL_OPEN  ) == 0 ) {
-        /* FIXME unix name != mac name */
-        if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
+        if ((dir = dirnew(strlen(volume->v_name) + 1)) == NULL) {
             LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
             ret = AFPERR_MISC;
             goto openvol_err;
         }
         dir->d_did = DIRDID_ROOT;
         dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
+        strcpy( dir->d_name, volume->v_name );
         volume->v_dir = volume->v_root = dir;
         volume->v_flags |= AFPVOL_OPEN;
     }
@@ -1294,7 +1286,7 @@ int               ibuflen, *rbuflen;
     *rbuflen = 0;
     ibuf += 2;
     memcpy(&vid, ibuf, sizeof( vid ));
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid )) ) {
         return( AFPERR_PARAM );
     }
 
@@ -1310,7 +1302,6 @@ int               ibuflen, *rbuflen;
             curdir = ovol->v_dir;
         }
     }
-
     dirfree( vol->v_root );
     vol->v_dir = NULL;
 #ifdef CNID_DB
@@ -1352,7 +1343,7 @@ struct extmap *getextmap(const char *path)
     char         *p;
     struct extmap *em;
 
-    if (( p = strrchr( path, '.' )) == NULL ) {
+    if (NULL == ( p = strrchr( path, '.' )) ) {
         return( defextmap );
     }
     p++;
@@ -1447,7 +1438,7 @@ int               ibuflen, *rbuflen;
     memcpy(&bitmap, ibuf, sizeof( bitmap ));
     bitmap = ntohs( bitmap );
 
-    if (( vol = getvolbyvid( vid )) == NULL ) {
+    if (NULL == ( vol = getvolbyvid( vid )) ) {
         *rbuflen = 0;
         return( AFPERR_PARAM );
     }