]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/volume.c
Merge branch 'release-3-0-alpha3'
[netatalk.git] / etc / afpd / volume.c
index af492528763925836011bd22e3e10ef402b8bfe6..3b02b2390a467dd81de3319fa757ceb709434844 100644 (file)
 
 extern int afprun(int root, char *cmd, int *outfd);
 
-static void showvol(const ucs2_t *name)
-{
-    struct vol  *volume = getvolumes();
-
-    for ( ; volume; volume = volume->v_next ) {
-        if (volume->v_hide && !strcasecmp_w( volume->v_name, name ) ) {
-            volume->v_hide = 0;
-            return;
-        }
-    }
-}
-
-static void closevol(struct vol *vol)
-{
-    if (!vol)
-        return;
-
-    vol->v_flags &= ~AFPVOL_OPEN;
-
-    of_closevol(vol);
-
-    dir_free( vol->v_root );
-    vol->v_root = NULL;
-    if (vol->v_cdb != NULL) {
-        cnid_close(vol->v_cdb);
-        vol->v_cdb = NULL;
-    }
-
-    if (vol->v_postexec) {
-        afprun(0, vol->v_postexec, NULL);
-    }
-    if (vol->v_root_postexec) {
-        afprun(1, vol->v_root_postexec, NULL);
-    }
-
-    if (vol->v_deleted) {
-        showvol(vol->v_name);
-        volume_free(vol);
-        volume_unlink(vol);
-        free(vol);
-    }
-}
-
 /*!
  * Read band-size info from Info.plist XML file of an TM sparsebundle
  *
@@ -364,7 +321,7 @@ static int getvolparams(const AFPObj *obj, uint16_t bitmap, struct vol *vol, str
      * .Parent file here if it doesn't exist. */
 
     /* Convert adouble:v2 to adouble:ea on the fly */
-    (void)ad_convert(vol->v_path, st, vol);
+    (void)ad_convert(vol->v_path, st, vol, NULL);
 
     ad_init(&ad, vol);
     if (ad_open(&ad, vol->v_path, ADFLAGS_HF | ADFLAGS_DIR | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) != 0 ) {
@@ -586,7 +543,7 @@ int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf
     int         vcnt;
     size_t      len;
 
-    load_volumes(obj, of_closevol);
+    load_volumes(obj, closevol);
 
     data = rbuf + 5;
     for ( vcnt = 0, volume = getvolumes(); volume; volume = volume->v_next ) {
@@ -606,9 +563,6 @@ int afp_getsrvrparms(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf
                 continue;   /* no r-x access */
             }
         }
-        if (volume->v_hide) {
-            continue;       /* config file changed but the volume was mounted */
-        }
 
         if (utf8_encoding(obj)) {
             len = ucs2_to_charset_allocate(CH_UTF8_MAC, &namebuf, volume->v_u8mname);
@@ -687,22 +641,14 @@ static int volume_openDB(const AFPObj *obj, struct vol *volume)
         flags |= CNID_FLAG_NODEV;
     }
 
-    if (volume->v_cnidscheme == NULL) {
-        volume->v_cnidscheme = strdup(DEFAULT_CNID_SCHEME);
-        LOG(log_info, logtype_afpd, "Volume %s use CNID scheme %s.",
-            volume->v_path, volume->v_cnidscheme);
-    }
-
-    LOG(log_info, logtype_afpd, "CNID server: %s:%s",
-        volume->v_cnidserver ? volume->v_cnidserver : obj->options.Cnid_srv,
-        volume->v_cnidport ? volume->v_cnidport : obj->options.Cnid_port);
+    LOG(log_debug, logtype_afpd, "CNID server: %s:%s", volume->v_cnidserver, volume->v_cnidport);
 
     volume->v_cdb = cnid_open(volume->v_path,
                               volume->v_umask,
                               volume->v_cnidscheme,
                               flags,
-                              volume->v_cnidserver ? volume->v_cnidserver : obj->options.Cnid_srv,
-                              volume->v_cnidport ? volume->v_cnidport : obj->options.Cnid_port);
+                              volume->v_cnidserver,
+                              volume->v_cnidport);
 
     if ( ! volume->v_cdb && ! (flags & CNID_FLAG_MEMORY)) {
         /* The first attempt failed and it wasn't yet an attempt to open in-memory */
@@ -775,7 +721,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
     if ((len + 1) & 1) /* pad to an even boundary */
         ibuf++;
 
-    load_volumes(obj, of_closevol);
+    load_volumes(obj, closevol);
 
     for ( volume = getvolumes(); volume; volume = volume->v_next ) {
         if ( strcasecmp_w( (ucs2_t*) volname, volume->v_name ) == 0 ) {
@@ -925,6 +871,11 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
                 goto openvol_err;
             }
         }
+
+        const char *msg;
+        if ((msg = iniparser_getstring(obj->iniconfig, volume->v_configname, "login message",  NULL)) != NULL)
+            setmessage(msg);
+
         return( AFP_OK );
     }
 
@@ -943,21 +894,45 @@ openvol_err:
     return ret;
 }
 
+void closevol(const AFPObj *obj, struct vol *vol)
+{
+    if (!vol)
+        return;
+
+    vol->v_flags &= ~AFPVOL_OPEN;
+
+    of_closevol(obj, vol);
+
+    dir_free( vol->v_root );
+    vol->v_root = NULL;
+    if (vol->v_cdb != NULL) {
+        cnid_close(vol->v_cdb);
+        vol->v_cdb = NULL;
+    }
+
+    if (vol->v_postexec) {
+        afprun(0, vol->v_postexec, NULL);
+    }
+    if (vol->v_root_postexec) {
+        afprun(1, vol->v_root_postexec, NULL);
+    }
+}
+
 /* ------------------------- */
-void close_all_vol(void)
+void close_all_vol(const AFPObj *obj)
 {
     struct vol  *ovol;
     curdir = NULL;
     for ( ovol = getvolumes(); ovol; ovol = ovol->v_next ) {
         if ( (ovol->v_flags & AFPVOL_OPEN) ) {
             ovol->v_flags &= ~AFPVOL_OPEN;
-            closevol(ovol);
+            closevol(obj, ovol);
         }
     }
 }
 
 /* ------------------------- */
-int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
+int afp_closevol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
 {
     struct vol  *vol;
     uint16_t   vid;
@@ -970,7 +945,8 @@ int afp_closevol(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_
     }
 
     (void)chdir("/");
-    closevol(vol);
+    curdir = NULL;
+    closevol(obj, vol);
 
     return( AFP_OK );
 }