]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_options.c
add -advertise_ssh flag to afpd.conf, if set announce SSH tunneling capabilities.
[netatalk.git] / etc / afpd / afp_options.c
index 0bc77f3520ee290c3957e222fa5a52de13d28a1b..ae4265282c9867e8f06ecdcb40d64c91f363972a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_options.c,v 1.24 2002-05-03 22:51:34 jmarcus Exp $
+ * $Id: afp_options.c,v 1.30.2.2.2.8 2004-06-09 02:07:15 bfernhomberg Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -61,6 +61,10 @@ char *strchr (), *strrchr ();
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
 #endif /* MIN */
 
+/* FIXME CNID */
+char             Cnid_srv[MAXHOSTNAMELEN + 1] = "localhost";
+int              Cnid_port = 4700;
+
 #define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:Ivm:"
 #define LENGTH 512
 
@@ -100,10 +104,21 @@ static char *getoption(char *buf, const char *option)
 void afp_options_free(struct afp_options *opt,
                       const struct afp_options *save)
 {
-    if (opt->defaultvol && (opt->defaultvol != save->defaultvol))
-        free(opt->defaultvol);
-    if (opt->systemvol && (opt->systemvol != save->systemvol))
-        free(opt->systemvol);
+    if (opt->defaultvol.name && (opt->defaultvol.name != save->defaultvol.name))
+        free(opt->defaultvol.name);
+    if (opt->defaultvol.full_name && (opt->defaultvol.full_name != save->defaultvol.full_name))
+        free(opt->defaultvol.full_name);
+
+    if (opt->systemvol.name && (opt->systemvol.name != save->systemvol.name))
+        free(opt->systemvol.name);
+    if (opt->systemvol.full_name && (opt->systemvol.full_name != save->systemvol.full_name))
+        free(opt->systemvol.full_name);
+
+    if (opt->uservol.name && (opt->uservol.name != save->uservol.name))
+        free(opt->uservol.name);
+    if (opt->uservol.full_name && (opt->uservol.full_name != save->uservol.full_name))
+        free(opt->uservol.full_name);
+
     if (opt->loginmesg && (opt->loginmesg != save->loginmesg))
         free(opt->loginmesg);
     if (opt->guest && (opt->guest != save->guest))
@@ -118,10 +133,20 @@ void afp_options_free(struct afp_options *opt,
         free(opt->uampath);
     if (opt->uamlist && (opt->uamlist != save->uamlist))
         free(opt->uamlist);
-    if (opt->nlspath && (opt->nlspath != save->nlspath))
-        free(opt->nlspath);
     if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
         free(opt->passwdfile);
+    if (opt->signature && (opt->signature != save->signature))
+       free(opt->signature);
+    if (opt->k5service && (opt->k5service != save->k5service))
+       free(opt->k5service);
+    if (opt->k5realm && (opt->k5realm != save->k5realm))
+       free(opt->k5realm);
+    if (opt->k5keytab && (opt->k5keytab != save->k5keytab))
+       free(opt->k5keytab);
+    if (opt->unixcodepage && (opt->unixcodepage != save->unixcodepage))
+       free(opt->unixcodepage);
+    if (opt->maccodepage && (opt->maccodepage != save->maccodepage))
+       free(opt->maccodepage);
 }
 
 /* initialize options */
@@ -130,10 +155,9 @@ void afp_options_init(struct afp_options *options)
     memset(options, 0, sizeof(struct afp_options));
     options->connections = 20;
     options->pidfile = _PATH_AFPDLOCK;
-    options->defaultvol = _PATH_AFPDDEFVOL;
-    options->systemvol = _PATH_AFPDSYSVOL;
+    options->defaultvol.name = _PATH_AFPDDEFVOL;
+    options->systemvol.name = _PATH_AFPDSYSVOL;
     options->configfile = _PATH_AFPDCONF;
-    options->nlspath = _PATH_AFPDNLSPATH;
     options->uampath = _PATH_AFPDUAMPATH;
     options->uamlist = "uams_clrtxt.so,uams_dhx.so";
     options->guest = "nobody";
@@ -142,12 +166,21 @@ void afp_options_init(struct afp_options *options)
     options->passwdfile = _PATH_AFPDPWFILE;
     options->tickleval = 30;
     options->timeout = 4;
+    options->sleep = 10* 120; /* 10 h in 30 seconds tick */
     options->server_notif = 1;
     options->authprintdir = NULL;
+    options->signature = "host";
     options->umask = 0;
 #ifdef ADMIN_GRP
     options->admingid = 0;
 #endif /* ADMIN_GRP */
+    options->k5service = NULL;
+    options->k5realm = NULL;
+    options->k5keytab = NULL;
+    options->unixcharset = CH_UNIX;
+    options->unixcodepage = "LOCALE";
+    options->maccharset = CH_MAC;
+    options->maccodepage = "MAC_ROMAN";
 }
 
 /* parse an afpd.conf line. i'm doing it this way because it's
@@ -188,6 +221,8 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         options->flags &= ~OPTION_CUSTOMICON;
     if (strstr(buf, " -icon"))
         options->flags |= OPTION_CUSTOMICON;
+    if (strstr(buf, " -advertise_ssh"))
+        options->flags |= OPTION_ANNOUNCESSH;
 
     /* passwd bits */
     if (strstr(buf, " -nosavepassword"))
@@ -218,9 +253,9 @@ int afp_options_parseline(char *buf, struct afp_options *options)
     /* figure out options w/ values. currently, this will ignore the setting
      * if memory is lacking. */
     if ((c = getoption(buf, "-defaultvol")) && (opt = strdup(c)))
-        options->defaultvol = opt;
+        options->defaultvol.name = opt;
     if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
-        options->systemvol = opt;
+        options->systemvol.name = opt;
     if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
         options->loginmesg = opt;
     if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
@@ -244,15 +279,27 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         }
     }
 
+    if ((c = getoption(buf, "-sleep"))) {
+        options->sleep = atoi(c) *120;
+        if (options->sleep <= 4) {
+            options->sleep = 4;
+        }
+    }
+
     if ((c = getoption(buf, "-server_quantum")))
         options->server_quantum = strtoul(c, NULL, 0);
 
+#ifndef DISABLE_LOGGER
     /* -setuplogtype <syslog|filelog> <logtype> <loglevel> <filename>*/
-    if ((c = getoption(buf, "-setuplogtype")))
+    /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
+    if ((c = getoption(buf, "-setuplog")))
     {
       char *ptr, *logsource, *logtype, *loglevel, *filename;
 
-      LOG(log_extradebug, logtype_afpd, "setting up logtype, c is %s", c);
+      LOG(log_debug6, logtype_afpd, "setting up logtype, c is %s", c);
+      ptr = c;
+      
+      /* 
       logsource = ptr = c;
       if (ptr)
       {
@@ -264,8 +311,9 @@ int afp_options_parseline(char *buf, struct afp_options *options)
             ptr++;
         }
       }
+      */
 
-      logtype = ptr;
+      logtype = ptr; 
       if (ptr)
       {
         ptr = strpbrk(ptr, " \t");
@@ -301,12 +349,61 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         }
       }
 
-      LOG(log_extradebug, logtype_afpd, "Doing setuplog %s %s %s %s", 
-          logsource, logtype, loglevel, filename);
+      LOG(log_debug7, logtype_afpd, "calling setuplog %s %s %s", 
+          logtype, loglevel, filename);
 
-      setuplog(logsource, logtype, loglevel, filename);
+      setuplog(logtype, loglevel, filename);
     }
 
+    if ((c = getoption(buf, "-unsetuplog")))
+    {
+      char *ptr, *logtype, *loglevel, *filename;
+
+      LOG(log_debug6, logtype_afpd, "unsetting up logtype, c is %s", c);
+
+      ptr = c;
+      logtype = ptr;
+      if (ptr)
+      {
+        ptr = strpbrk(ptr, " \t");
+        if (ptr)
+        {
+          *ptr++ = 0;
+          while (*ptr && isspace(*ptr))
+            ptr++;
+        }
+      }
+
+      loglevel = ptr;
+      if (ptr)
+      {
+        ptr = strpbrk(ptr, " \t");
+        if (ptr)
+        {
+          *ptr++ = 0;
+           while (*ptr && isspace(*ptr))
+             ptr++;
+        }
+      }
+
+      filename = ptr;
+      if (ptr)
+      {
+        ptr = strpbrk(ptr, " \t");
+        if (ptr)
+        {
+          *ptr++ = 0;
+          while (*ptr && isspace(*ptr))
+            ptr++;
+        }
+      }
+      
+      LOG(log_debug7, logtype_afpd, "calling setuplog %s %s %s",
+              logtype, NULL, filename);
+
+      setuplog(logtype, NULL, filename);
+    }
+#endif /* DISABLE_LOGGER */
 #ifdef ADMIN_GRP
     if ((c = getoption(buf, "-admingroup"))) {
         struct group *gr = getgrnam(c);
@@ -316,28 +413,53 @@ int afp_options_parseline(char *buf, struct afp_options *options)
     }
 #endif /* ADMIN_GRP */
 
+    if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
+       options->k5service = opt;
+    if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
+       options->k5realm = opt;
+    if ((c = getoption(buf, "-k5keytab"))) {
+       if ( NULL == (options->k5keytab = (char *) malloc(sizeof(char)*(strlen(c)+14)) )) {
+               LOG(log_error, logtype_afpd, "malloc failed");
+               exit(-1);
+       }
+       snprintf(options->k5keytab, strlen(c)+14, "KRB5_KTNAME=%s", c);
+       putenv(options->k5keytab);
+       /* setenv( "KRB5_KTNAME", c, 1 ); */
+    }
     if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
         options->authprintdir = opt;
     if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
         options->uampath = opt;
     if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
         options->uamlist = opt;
-    if ((c = getoption(buf, "-nlspath")) && (opt = strdup(c)))
-        options->nlspath = opt;
 
     if ((c = getoption(buf, "-ipaddr"))) {
         struct in_addr inaddr;
         if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
             if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
-                LOG(log_info, logtype_afpd, "WARNING: can't find %s\n", opt);
+                LOG(log_info, logtype_afpd, "WARNING: can't find %s", opt);
             options->ipaddr = opt;
         }
     }
 
+    /* FIXME CNID Cnid_srv is a server attribute */
+    if ((c = getoption(buf, "-cnidserver"))) {
+        char *p;
+       int len;        
+        p = strchr(c, ':');
+       if (p != NULL && (len = p - c) <= MAXHOSTNAMELEN) {
+           memcpy(Cnid_srv, c, len);
+           Cnid_srv[len] = 0;
+           Cnid_port = atoi(p +1);
+       }
+    }
+
     if ((c = getoption(buf, "-port")))
         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"))) {
@@ -350,6 +472,31 @@ int afp_options_parseline(char *buf, struct afp_options *options)
             if ((opt = strdup(c)))
                 options->fqdn = opt;
         }
+       else {
+            LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
+       }
+    }
+
+    if ((c = getoption(buf, "-unixcodepage"))) {
+       if ((charset_t)-1  == ( options->unixcharset = add_charset(c)) ) {
+            options->unixcharset = CH_UNIX;
+            LOG(log_warning, logtype_afpd, "setting Unix codepage to '%s' failed", c);
+       }
+       else {
+            if ((opt = strdup(c)))
+                options->unixcodepage = opt;
+       }
+    }
+       
+    if ((c = getoption(buf, "-maccodepage"))) {
+       if ((charset_t)-1 == ( options->maccharset = add_charset(c)) ) {
+            options->maccharset = CH_MAC;
+            LOG(log_warning, logtype_afpd, "setting Mac codepage to '%s' failed", c);
+       }
+       else {
+            if ((opt = strdup(c)))
+                options->maccodepage = opt;
+       }
     }
 
     return 1;
@@ -368,17 +515,17 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
         perror( "gethostname" );
         return 0;
     }
-    if (( p = strchr(options->hostname, '.' )) != 0 ) {
+    if (NULL != ( p = strchr(options->hostname, '.' )) ) {
         *p = '\0';
     }
 
-    if (( p = strrchr( av[ 0 ], '/' )) == NULL ) {
+    if (NULL == ( p = strrchr( av[ 0 ], '/' )) ) {
         p = av[ 0 ];
     } else {
         p++;
     }
 
-    while (( c = getopt( ac, av, OPTIONS )) != EOF ) {
+    while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
         switch ( c ) {
         case 'd' :
             options->flags |= OPTION_DEBUG;
@@ -387,10 +534,10 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
             options->server = optarg;
             break;
         case 'f' :
-            options->defaultvol = optarg;
+            options->defaultvol.name = optarg;
             break;
         case 's' :
-            options->systemvol = optarg;
+            options->systemvol.name = optarg;
             break;
         case 'u' :
             options->flags |= OPTION_USERVOLFIRST;