]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
/tmp/log
[netatalk.git] / etc / afpd / volume.c
index 97a60ea2a9aad9d628b9001bcc1225ed58d839a7..f5ef2d5acd6547d0bdbc94015995cca2afc02ee5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: volume.c,v 1.36 2002-09-29 23:31:24 sibaz Exp $
+ * $Id: volume.c,v 1.46 2003-01-12 14:40:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -293,7 +293,8 @@ 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)
+                   const char *nlspath, const char *tmp, AFPObj *obj,
+                  struct passwd *pwd)
 {
     char *val;
 
@@ -374,16 +375,20 @@ static void volset(struct vol_option *options, char *volname, int vlen,
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
             else if (strcasecmp(p, "nofileid") == 0)
                 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOFILEID;
+            else if (strcasecmp(p, "utf8") == 0)
+                options[VOLOPT_FLAGS].i_value |= AFPVOL_UTF8;
 
             p = strtok(NULL, ",");
         }
 
 #ifdef CNID_DB
     } else if (optionok(tmp, "dbpath:", val)) {
+       char t[MAXPATHLEN + 1];
         if (options[VOLOPT_DBPATH].c_value)
             free(options[VOLOPT_DBPATH].c_value);
 
-        options[VOLOPT_DBPATH].c_value = strdup(val + 1);
+       volxlate(obj, t, MAXPATHLEN, val, pwd, NULL);
+        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);
@@ -534,7 +539,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;
@@ -601,7 +606,6 @@ int                 user;
             LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
             return;
         }
-
     }
     ext++;
     for ( em = extmap, cnt = 0; em->em_ext; em++, cnt++) {
@@ -638,10 +642,6 @@ int                        user;
     } else {
         memcpy(em->em_creator, creator, sizeof( em->em_creator ));
     }
-
-    if ( !*ext ) {
-        defextmap = em;
-    }
 }
 
 /* -------------------------- */
@@ -656,16 +656,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;
     }
 }
 
@@ -705,7 +706,7 @@ struct passwd *pwent;
         strcat( path, p2 );
     }
 
-    if (( fp = fopen( path, "r" )) == NULL ) {
+    if (NULL == ( fp = fopen( path, "r" )) ) {
         return( -1 );
     }
 
@@ -727,7 +728,8 @@ 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);
                 }
             }
             break;
@@ -789,7 +791,7 @@ struct passwd *pwent;
                     break;
 
                 volset(options, volname, sizeof(volname) - 1,
-                       obj->options.nlspath, tmp);
+                       obj->options.nlspath, tmp, obj, pwent);
             }
 
             /* check allow/deny lists:
@@ -951,6 +953,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_flush(&ad, ADFLAGS_HF);
     }
 
@@ -986,11 +989,13 @@ 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
+            }
+            ashort |= VOLPBIT_ATTR_CATSEARCH;
+            if (afp_version >= 30) {
+                ashort |= VOLPBIT_ATTR_UTF8;
+            }
             ashort = htons(ashort);
             memcpy(data, &ashort, sizeof( ashort ));
             data += sizeof( ashort );
@@ -1212,16 +1217,23 @@ int             ibuflen, *rbuflen;
         ret = AFPERR_ACCESS;
         goto openvol_err;
     }
-
+    /* FIXME 
+    */
+    if (afp_version >= 30) {
+        volume->max_filename = 255;
+    }
+    else {
+        volume->max_filename = MACFILELEN;
+    }
     if (( volume->v_flags & AFPVOL_OPEN  ) == 0 ) {
-        if ((dir = dirnew(strlen(volume->v_name) + 1)) == NULL) {
+        /* FIXME unix name != mac name */
+        if ((dir = dirnew(volume->v_name, volume->v_name) ) == 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;
     }
@@ -1286,7 +1298,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 );
     }
 
@@ -1302,7 +1314,6 @@ int               ibuflen, *rbuflen;
             curdir = ovol->v_dir;
         }
     }
-
     dirfree( vol->v_root );
     vol->v_dir = NULL;
 #ifdef CNID_DB
@@ -1344,7 +1355,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++;
@@ -1384,7 +1395,8 @@ AFPObj *obj;
         if ( (vol->v_flags & AFPVOL_OPEN)  && vol->v_time + 30 < tv.tv_sec) {
             if ( !stat( vol->v_path, &st ) && vol->v_time != st.st_mtime ) {
                 vol->v_time = st.st_mtime;
-                obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
+                if (!obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED))
+                    return -1;
                 return 1;
             }
         }
@@ -1439,7 +1451,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 );
     }