]> arthur.barton.de Git - netatalk.git/commitdiff
Configure option allowing to set a server signature manually. Useful when
authorrlewczuk <rlewczuk>
Sat, 7 Dec 2002 02:39:57 +0000 (02:39 +0000)
committerrlewczuk <rlewczuk>
Sat, 7 Dec 2002 02:39:57 +0000 (02:39 +0000)
running multiple instances of afpd on one machine (eg. HA clusters).

config/afpd.conf.tmpl
etc/afpd/afp_options.c
etc/afpd/globals.h
etc/afpd/status.c

index f8eef31513bf92d7fe5db9a9fa11dd7421590527..fd07efe403b13a2a136b0e9577122f5add49388a 100644 (file)
 #                    -setuplog "afpdaemon log_maxdebug /var/log/netatalk-afp.log"
 #                    -unsetuplog "default level file" 
 #                    -setuplog "default log_maxdebug"
-
+#
+#     -signature { user:<text> | host }
+#                         Specify a server signature. This option is useful while
+#                         running multiple independent instances of afpd on one 
+#                         machine (eg. in clustered environments, to provide fault
+#                         isolation etc.). "host" signature type allows afpd generating
+#                         signature automatically (based on machine primary IP address).
+#                         "user" signature type allows administrator to set up a signature
+#                         string manually. Examples: three servers running on one machine:
+#           first       -signature user:USERS
+#           second      -signature user:USERS
+#           third       -signature user:ADMINS
+#                First two servers will act as one logical AFP service - if user logs in to 
+#                first one and then  connects to second one, session will be automatically 
+#                redirected to the first one. But if client connects to first and then to third, 
+#                will be asked for password twice and will see  resources of both servers. 
+#                Traditional method of signature generation causes two independent afpd instances
+#                to have the same signature and thus cause clients to be redirected automatically
+#                to server (s)he logged in first.
 #              
 # Some examples:
 #
index f56b7ea1ec9f1153a0a934003eced527d6433f34..eba6c660e97dbabb0e459b016c5cf7c473605bd9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_options.c,v 1.27 2002-08-24 05:00:07 sibaz Exp $
+ * $Id: afp_options.c,v 1.28 2002-12-07 02:39:57 rlewczuk Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -122,6 +122,8 @@ void afp_options_free(struct afp_options *opt,
         free(opt->nlspath);
     if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
         free(opt->passwdfile);
+    if (opt->signature && (opt->signature != save->signature))
+       free(opt->signature);
 }
 
 /* initialize options */
@@ -144,6 +146,7 @@ void afp_options_init(struct afp_options *options)
     options->timeout = 4;
     options->server_notif = 1;
     options->authprintdir = NULL;
+    options->signature = "host";
     options->umask = 0;
 #ifdef ADMIN_GRP
     options->admingid = 0;
@@ -393,6 +396,8 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         options->port = atoi(c);
     if ((c = getoption(buf, "-ddpaddr")))
         atalk_aton(c, &options->ddpaddr);
+    if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
+        options->signature = opt;
 
     /* do a little checking for the domain name. */
     if ((c = getoption(buf, "-fqdn"))) {
index 65ab4f77ab641a0a2cd24d1d84e803bf03b1ca82..8da46105a57d4db2e08f414cfee32dd214940e43 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: globals.h,v 1.14 2002-08-31 05:35:10 jmarcus Exp $
+ * $Id: globals.h,v 1.15 2002-12-07 02:39:57 rlewczuk Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -59,6 +59,7 @@ struct afp_options {
     char *guest, *loginmesg, *keyfile, *passwdfile;
     char *uamlist;
     char *authprintdir;
+    char *signature;
     mode_t umask;
     mode_t save_mask;
 #ifdef ADMIN_GRP
index f5acacaeb4c59245199c57b58048c4f05d278ca3..c9acbce7cfb5e01fd013f3166bd5ed1346e878f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: status.c,v 1.7 2002-02-06 21:58:50 jmarcus Exp $
+ * $Id: status.c,v 1.8 2002-12-07 02:39:57 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 <syslog.h>
 
 #ifdef BSD4_4
 #include <sys/param.h>
@@ -121,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 char *hostname, const struct afp_options *options)
 {
     char                 *status;
+    char                *usersign, *ifaddr;
     int                  i;
     u_int16_t            offset, sigoff;
     long                 hostid;
@@ -142,6 +144,25 @@ 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) {
+           syslog( LOG_ERR, "Signature %s id not valid. Switching back to hostid.", 
+                                   options->signature);
+           goto server_signature_hostid;
+    }
+    usersign = options->signature + 5;
+        if (strlen(usersign) < 3) 
+           syslog( LOG_WARNING, "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;
@@ -170,8 +191,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);
@@ -339,7 +361,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->hostname, options);
 
     /* returns length */
     c = status_netaddress(status, c, asp, dsi, options->fqdn);