]> arthur.barton.de Git - netatalk.git/commitdiff
Send optional AFP messages for vetoed files
authorRalph Boehme <sloowfranklin@gmail.com>
Thu, 25 Jul 2013 16:31:11 +0000 (18:31 +0200)
committerRalph Boehme <sloowfranklin@gmail.com>
Tue, 30 Jul 2013 09:31:34 +0000 (11:31 +0200)
New option "veto messages" can be used to enable sending messages.
Then whenever a client tries to access any file or directory
with a vetoed name, it will be sent an AFP message indicating
the name and the directory.

Feature request #81.

NEWS
doc/manpages/man5/afp.conf.5.xml
etc/afpd/directory.c
etc/afpd/messages.c
include/atalk/globals.h
libatalk/util/netatalk_conf.c
man/man5/afp.conf.5.in

diff --git a/NEWS b/NEWS
index 01a61c95c726940c30622445d4fc88df99a79108..1c071750b8981ed739cd7084ac8561d178bf37d1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,11 @@ Changes in 3.0.5
 * NEW: New global/volume option "ignored attributes"
 * FIX: "afp listen" option failed to take IPv6 addresses. Bug #515.
 * FIX: Fix a possible crash in set_groups. Bug #518.
+* NEW: Send optional AFP messages for vetoed files, new option
+       "veto messages" can be used to enable sending messages.
+       Then whenever a client tries to access any file or directory
+       with a vetoed name, it will be sent an AFP message indicating
+       the name and the directory. From FR #81.
 
 Changes in 3.0.4
 ================
index e67d651c360c626b4b11f9b51216829232af1010..48df77b1fd3fbf2d66b095fe9f425904a2498fe1 100644 (file)
           </listitem>
         </varlistentry>
 
+        <varlistentry>
+          <term>veto message = <replaceable>BOOLEAN</replaceable> (default:
+          <emphasis>no</emphasis>) <type>(G)</type></term>
+
+          <listitem>
+            <para>Use section <option>name</option> as option preset for all
+            volumes (when set in the [Global] section) or for one volume (when
+            set in that volume's section).</para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term>vol dbpath = <replaceable>path</replaceable>
           <type>(G)</type></term>
index 0bbfade20bbf355e0707ef8d206239e180f8355f..c1160af22c86cb119e8f33875a4ace21091b596f 100644 (file)
@@ -1172,6 +1172,14 @@ struct path *cname(struct vol *vol, struct dir *dir, char **cpath)
             /* the name is illegal */
             LOG(log_info, logtype_afpd, "cname: illegal path: '%s'", ret.u_name);
             afp_errno = AFPERR_PARAM;
+            if (vol->v_obj->options.flags & OPTION_VETOMSG) {
+                bstring message = bformat("Attempt to access vetoed file or directory \"%s\" in directory \"%s\"",
+                                          ret.u_name, bdata(dir->d_u_name));
+                if (setmessage(bdata(message)) == 0)
+                    /* Client may make multiple attempts, only send the message the first time */
+                    kill(getpid(), SIGUSR2);
+                bdestroy(message);
+            }
             return NULL;
         }
 
index 3c85f6a3a505c7fe9ae4c5ade65a5c44f997e708..5bd965bd2a55fd569942f550173b80a44e27c1a5 100644 (file)
 static char servermesg[MAXPATHLEN] = "";
 static char localized_message[MAXPATHLEN] = "";
 
-void setmessage(const char *message)
+/*!
+ * Copy AFP message to message buffer
+ * @param message (r) message to send
+ * @returns 0 if this message is being set the first time, return 1 if the preceeding
+ *          message was the same
+ */
+int setmessage(const char *message)
 {
+    if (strncmp(message, servermesg, MAXMESGSIZE) == 0)
+        return 1;
     strlcpy(servermesg, message, MAXMESGSIZE);
+    return 0;
 }
 
 void readmessage(AFPObj *obj)
@@ -177,6 +186,6 @@ int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, siz
        *rbuflen += 1;
     }
     *rbuflen += outlen;
-    *message = 0;
+//    *message = 0;
     return AFP_OK;
 }
index d863df0c5fc084b1a2b4d2895ab74899bd36c06f..61cf247fe9987ce9f1cbe74d621c7eac4ed981cb 100644 (file)
@@ -48,7 +48,7 @@
 #define OPTION_CLOSEVOL      (1 << 1)
 #define OPTION_SERVERNOTIF   (1 << 2)
 #define OPTION_NOSENDFILE    (1 << 3)
-/* #define OPTION_CUSTOMICON    (1 << 4) */
+#define OPTION_VETOMSG       (1 << 4) /* whether to send an AFP message for veto file access */
 #define OPTION_AFP_READ_LOCK (1 << 5) /* whether to do AFP spec conforming read locks (default: no) */
 #define OPTION_ANNOUNCESSH   (1 << 6)
 #define OPTION_UUID          (1 << 7)
@@ -162,7 +162,7 @@ extern const char         *Cnid_port;
 extern int  get_afp_errno   (const int param);
 extern void afp_options_init (struct afp_options *);
 extern void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av);
-extern void setmessage (const char *);
+extern int setmessage (const char *);
 extern void readmessage (AFPObj *);
 
 /* afp_util.c */
index 70e1d6be34343236ac1cf4e84a97698594823f00..4ffbde6455595fd824bc1eaeb1dc3c3436422ddc 100644 (file)
@@ -1756,6 +1756,8 @@ int afp_config_parse(AFPObj *AFPObj, char *processname)
         options->flags |= OPTION_DBUS_AFPSTATS;
     if (atalk_iniparser_getboolean(config, INISEC_GLOBAL, "afp read locks", 0))
         options->flags |= OPTION_AFP_READ_LOCK;
+    if (atalk_iniparser_getboolean(config, INISEC_GLOBAL, "veto message", 0))
+        options->flags |= OPTION_VETOMSG;
     if (!atalk_iniparser_getboolean(config, INISEC_GLOBAL, "save password", 1))
         options->passwdbits |= PASSWD_NOSAVE;
     if (atalk_iniparser_getboolean(config, INISEC_GLOBAL, "set password", 0))
index 017a6fa4939abbd8800718bac051d97bfcf9d89a..d9ecb39f406005a2a8a0076c110bc2db65bc7490 100644 (file)
@@ -595,6 +595,13 @@ solaris share reservations = \fIBOOLEAN\fR (default: \fIyes\fR) \fB(G)\fR
 Use share reservations on Solaris\&. Solaris CIFS server uses this too, so this makes a lock coherent multi protocol server\&.
 .RE
 .PP
+veto message = \fIBOOLEAN\fR (default: \fIno\fR) \fB(G)\fR
+.RS 4
+Use section
+\fBname\fR
+as option preset for all volumes (when set in the [Global] section) or for one volume (when set in that volume\*(Aqs section)\&.
+.RE
+.PP
 vol dbpath = \fIpath\fR \fB(G)\fR
 .RS 4
 Sets the database information to be stored in path\&. You have to specify a writable location, even if the volume is read only\&. The default is