]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/status.c
bugfix: close the right fork in renamefile, copy and paste error...
[netatalk.git] / etc / afpd / status.c
index 07ef932bc1f74561db887e8531342e4a7242a514..97f0138e2680fc8d2ff9023e5295723bd1bdc009 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: status.c,v 1.6 2001-12-10 20:16:54 srittau Exp $
+ * $Id: status.c,v 1.9 2002-12-07 02:55:00 rlewczuk Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <sys/types.h>
+#include <atalk/logger.h>
 
 #ifdef BSD4_4
 #include <sys/param.h>
@@ -34,7 +35,7 @@
 #include "afp_config.h"
 #include "icon.h"
 
-static void status_flags(char *data, const int ipok,
+static void status_flags(char *data, const int notif, const int ipok,
                          const unsigned char passwdbits)
 {
     u_int16_t           status;
@@ -49,7 +50,14 @@ static void status_flags(char *data, const int ipok,
     if (ipok)
         status |= AFPSRVRINFO_TCPIP;
     status |= AFPSRVRINFO_SRVMSGS;
-    status |= AFPSRVRINFO_SRVNOTIFY;
+    /* Allow the user to decide if we should support server notifications.
+     * With this turned off, the clients will poll for directory changes every
+     * 10 seconds.  This might be too costly to network resources, so make
+     * this an optional thing.  Default will be to _not_ support server
+     * notifications. */
+    if (notif) {
+        status |= AFPSRVRINFO_SRVNOTIFY;
+    }
     status |= AFPSRVRINFO_FASTBOZO;
     status = htons(status);
     memcpy(data + AFPSTATUS_FLAGOFF, &status, sizeof(status));
@@ -114,9 +122,10 @@ static void status_machine(char *data)
 
 /* server signature is a 16-byte quantity */
 static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi,
-                                  const char *hostname)
+                                  const struct afp_options *options)
 {
     char                 *status;
+    char                *usersign, *ifaddr;
     int                  i;
     u_int16_t            offset, sigoff;
     long                 hostid;
@@ -135,6 +144,26 @@ static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi,
     /* jump to server signature offset */
     data += offset;
 
+    /* Signature type is user string */
+    if (strncmp(options->signature, "user", 4) == 0) {
+        if (strlen(options->signature) <= 5) {
+           LOG(log_warning, logtype_afpd, "Signature %s id not valid. Switching back to hostid.",
+                           options->signature);
+           goto server_signature_hostid;
+    }
+    usersign = options->signature + 5;
+        if (strlen(usersign) < 3) 
+           LOG(log_warning, logtype_afpd, "Signature %s is very short !", 
+                           options->signature);
+    
+        memset(data, 0, 16);
+        strncpy(data, usersign, 16);
+       data += 16;
+        goto server_signature_done;
+    } /* signature = user */
+
+    /* If signature type is a standard hostid... */
+server_signature_hostid:
     /* 16-byte signature consists of copies of the hostid */
 #if defined(BSD4_4) && defined(USE_GETHOSTID)
     mib[0] = CTL_KERN;
@@ -150,7 +179,7 @@ static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi,
         else {
             struct hostent *host;
 
-            if ((host = gethostbyname(hostname)))
+            if ((host = gethostbyname(options->hostname)))
                 hostid = ((struct in_addr *) host->h_addr)->s_addr;
         }
     }
@@ -163,8 +192,9 @@ static u_int16_t status_signature(char *data, int *servoffset, DSI *dsi,
     for (i = 0; i < 16; i += sizeof(hostid)) {
         memcpy(data, &hostid, sizeof(hostid));
         data += sizeof(hostid);
-    }
+     }
 
+server_signature_done:
     /* calculate net address offset */
     *servoffset += sizeof(offset);
     offset = htons(data - status);
@@ -318,7 +348,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
      * (16-bytes), network addresses, volume icon/mask 
      */
 
-    status_flags(status, options->fqdn ||
+    status_flags(status, options->server_notif, options->fqdn ||
                  (dsiconfig && dsi->server.sin_addr.s_addr),
                  options->passwdbits);
     /* returns offset to signature offset */
@@ -332,7 +362,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
     else
         status_icon(status, apple_atalk_icon, sizeof(apple_atalk_icon), c);
 
-    sigoff = status_signature(status, &c, dsi, options->hostname);
+    sigoff = status_signature(status, &c, dsi, options);
 
     /* returns length */
     c = status_netaddress(status, c, asp, dsi, options->fqdn);