]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_options.c
IPv6 support for afpd and cnid_metad
[netatalk.git] / etc / afpd / afp_options.c
index 9813fe3a87ba0a42ce8f1a25d13c396cf45e8b2e..0a1c9e4d6a8516c49ea65ee8d299fe0da2ad50b9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_options.c,v 1.32 2003-06-09 15:09:19 srittau Exp $
+ * $Id: afp_options.c,v 1.48 2009-11-05 14:38:07 franklahm Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -61,7 +61,11 @@ char *strchr (), *strrchr ();
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
 #endif /* MIN */
 
-#define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:Ivm:"
+/* FIXME CNID */
+const char *Cnid_srv = "localhost";
+const char *Cnid_port = "4700";
+
+#define OPTIONS "dn:f:s:uc:g:P:ptDS:TL:F:U:hIvVm:"
 #define LENGTH 512
 
 /* return an option. this uses an internal array, so it's necessary
@@ -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))
@@ -112,22 +127,33 @@ void afp_options_free(struct afp_options *opt,
         free(opt->server);
     if (opt->ipaddr && (opt->ipaddr != save->ipaddr))
         free(opt->ipaddr);
+    if (opt->port && (opt->port != save->port))
+        free(opt->port);
     if (opt->fqdn && (opt->fqdn != save->fqdn))
         free(opt->fqdn);
     if (opt->uampath && (opt->uampath != save->uampath))
         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);
+       free(opt->signature);
     if (opt->k5service && (opt->k5service != save->k5service))
-        free(opt->k5service);
+       free(opt->k5service);
     if (opt->k5realm && (opt->k5realm != save->k5realm))
-        free(opt->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);
+
+    if (opt->ntdomain && (opt->ntdomain != save->ntdomain))
+       free(opt->ntdomain);
+    if (opt->ntseparator && (opt->ntseparator != save->ntseparator))
+       free(opt->ntseparator);
 }
 
 /* initialize options */
@@ -136,15 +162,14 @@ 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->uamlist = "uams_dhx.so,uams_dhx2.so";
     options->guest = "nobody";
     options->loginmesg = "";
-    options->transports = AFPTRANS_ALL;
+    options->transports = AFPTRANS_TCP; /*  TCP only */
     options->passwdfile = _PATH_AFPDPWFILE;
     options->tickleval = 30;
     options->timeout = 4;
@@ -158,6 +183,14 @@ void afp_options_init(struct afp_options *options)
 #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";
+    options->volnamelen = 80; /* spec: 255, 10.1: 73, 10.4/10.5: 80 */
+    options->ntdomain = NULL;
+    options->ntseparator = NULL;
 }
 
 /* parse an afpd.conf line. i'm doing it this way because it's
@@ -198,6 +231,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"))
@@ -227,10 +262,21 @@ 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, "-hostname"))) {
+        int len = strlen (c);
+        if (len <= MAXHOSTNAMELEN) {
+            memcpy(options->hostname, c, len);
+            options->hostname[len] = 0;
+        }
+        else
+            LOG(log_info, logtype_afpd, "WARNING: hostname %s is too long (%d)",c,len);
+    }
+
     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)))
@@ -264,124 +310,31 @@ int afp_options_parseline(char *buf, struct afp_options *options)
     if ((c = getoption(buf, "-server_quantum")))
         options->server_quantum = strtoul(c, NULL, 0);
 
-#ifndef DISABLE_LOGGER
-    /* -setuplogtype <syslog|filelog> <logtype> <loglevel> <filename>*/
-    /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
-    if ((c = getoption(buf, "-setuplog")))
-    {
-      char *ptr, *logtype, *loglevel, *filename;
-#if 0
-      char *logsource;
-#endif
-
-      LOG(log_debug6, logtype_afpd, "setting up logtype, c is %s", c);
-      ptr = c;
-
-#if 0
-      logsource = ptr = c;
-      if (ptr)
-      {
-        ptr = strpbrk(ptr, " \t");
-        if (ptr) 
-        {
-          *ptr++ = 0;
-          while (*ptr && isspace(*ptr))
-            ptr++;
+    if ((c = getoption(buf, "-volnamelen"))) {
+        options->volnamelen = atoi(c);
+        if (options->volnamelen < 8) {
+            options->volnamelen = 8; /* max mangled volname "???#FFFF" */
         }
-      }
-#endif
-
-      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++;
+        if (options->volnamelen > 255) {
+           options->volnamelen = 255; /* AFP3 spec */
         }
-      }
-
-      LOG(log_debug7, logtype_afpd, "calling setuplog %s %s %s", 
-          logtype, loglevel, filename);
+    }
 
-      setuplog(logtype, loglevel, filename);
+    /* -[no]setuplog <logtype> <loglevel> [<filename>]*/
+    c = buf;
+    /* Now THIS is hokey! Multiple occurrences are not supported by our current code, */
+    /* so I have to loop myself. */
+    while (NULL != (c = strstr(c, "-setuplog"))) {
+        char *optstr;
+        if ((optstr = getoption(c, "-setuplog"))) {
+            setuplog(optstr);
+            c += sizeof("-setuplog");
+        }
     }
 
     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);
+      unsetuplog(c);
 
-      setuplog(logtype, NULL, filename);
-    }
-#endif /* DISABLE_LOGGER */
 #ifdef ADMIN_GRP
     if ((c = getoption(buf, "-admingroup"))) {
         struct group *gr = getgrnam(c);
@@ -392,31 +345,50 @@ int afp_options_parseline(char *buf, struct afp_options *options)
 #endif /* ADMIN_GRP */
 
     if ((c = getoption(buf, "-k5service")) && (opt = strdup(c)))
-        options->k5service = opt;
+       options->k5service = opt;
     if ((c = getoption(buf, "-k5realm")) && (opt = strdup(c)))
-        options->k5realm = opt;
-    if ((c = getoption(buf, "-k5keytab")))
-        setenv( "KRB5_KTNAME", c, 1 );
+       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;
         }
+        else {
+            LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
+        }
+    }
+
+    /* FIXME CNID Cnid_srv is a server attribute */
+    if ((c = getoption(buf, "-cnidserver"))) {
+        char *p = strrchr(c, ':');
+        if (p)
+            *p = 0;
+        Cnid_srv = strdup(c);
+        if (p)
+            Cnid_port = strdup(p + 1);
+        LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", Cnid_srv, Cnid_port);
     }
 
     if ((c = getoption(buf, "-port")))
-        options->port = atoi(c);
+        options->port = strdup(c);
     if ((c = getoption(buf, "-ddpaddr")))
         atalk_aton(c, &options->ddpaddr);
     if ((c = getoption(buf, "-signature")) && (opt = strdup(c)))
@@ -433,11 +405,191 @@ 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;
+       }
+    }
+    
+    if ((c = strstr(buf, "-closevol"))) {
+        options->closevol= 1;
     }
 
+    if ((c = getoption(buf, "-ntdomain")) && (opt = strdup(c)))
+       options->ntdomain = opt;
+
+    if ((c = getoption(buf, "-ntseparator")) && (opt = strdup(c)))
+       options->ntseparator = opt;
+     
     return 1;
 }
 
+/*
+ * Show version information about afpd.
+ * Used by "afp -v".
+ */
+static void show_version( void )
+{
+       printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
+
+       puts( "This program is free software; you can redistribute it and/or modify it under" );
+       puts( "the terms of the GNU General Public License as published by the Free Software" );
+       puts( "Foundation; either version 2 of the License, or (at your option) any later" );
+       puts( "version. Please see the file COPYING for further information and details.\n" );
+
+       puts( "afpd has been compiled with support for these features:\n" );
+
+       printf( "        AFP3.1 support:\t" );
+#ifdef AFP3x
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "      Transport layers:\t" );
+#ifdef NO_DDP
+       puts( "TCP/IP" );
+#else
+       puts( "TCP/IP DDP" );
+#endif
+
+       printf( "         CNID backends:\t" );
+#ifdef CNID_BACKEND_CDB
+       printf( "cdb ");
+#endif
+#ifdef CNID_BACKEND_DB3
+       printf( "db3 " );
+#endif
+#ifdef CNID_BACKEND_DBD
+#ifdef CNID_BACKEND_DBD_TXN
+       printf( "dbd-txn " );
+#else
+       printf( "dbd " );
+#endif
+#endif
+#ifdef CNID_BACKEND_HASH
+       printf( "hash " );
+#endif
+#ifdef CNID_BACKEND_LAST
+       printf( "last " );
+#endif
+#ifdef CNID_BACKEND_MTAB
+       printf( "mtab " );
+#endif
+#ifdef CNID_BACKEND_TDB
+       printf( "tdb " );
+#endif
+       puts( "" );
+}
+
+/*
+ * Show extended version information about afpd and Netatalk.
+ * Used by "afp -V".
+ */
+static void show_version_extended(void )
+{
+       show_version( );
+
+       printf( "           SLP support:\t" );
+#ifdef USE_SRVLOC
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "  TCP wrappers support:\t" );
+#ifdef TCPWRAP
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "         Quota support:\t" );
+#ifndef NO_QUOTA_SUPPORT
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "   Admin group support:\t" );
+#ifdef ADMIN_GRP
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "    Valid shell checks:\t" );
+#ifndef DISABLE_SHELLCHECK
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "      cracklib support:\t" );
+#ifdef USE_CRACKLIB
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "        Dropbox kludge:\t" );
+#ifdef DROPKLUDGE
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "  Force volume uid/gid:\t" );
+#ifdef FORCE_UIDGID
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+}
+
+/*
+ * Display compiled-in default paths
+ */
+static void show_paths( void )
+{
+       printf( "             afpd.conf:\t%s\n", _PATH_AFPDCONF );
+       printf( "   AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
+       printf( "  AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
+       printf( "       UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
+}
+
+/*
+ * Display usage information about adpd.
+ */
+static void show_usage( char *name )
+{
+       fprintf( stderr, "Usage:\t%s [-dDIptTu] [-c maxconnections] [-f defaultvolumes] [-F config]\n", name );
+       fprintf( stderr, "\t     [-g guest] [-L message] [-m umask][-n nbpname] [-P pidfile]\n" );
+       fprintf( stderr, "\t     [-s systemvolumes] [-S port] [-U uams]\n" );
+       fprintf( stderr, "\t%s -h|-v|-V\n", name );
+}
+
 int afp_options_parse(int ac, char **av, struct afp_options *options)
 {
     extern char *optarg;
@@ -470,10 +622,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;
@@ -500,7 +652,7 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
             options->transports &= ~AFPTRANS_DDP;
             break;
         case 'S':
-            options->port = atoi(optarg);
+            options->port = optarg;
             break;
         case 'T':
             options->transports &= ~AFPTRANS_TCP;
@@ -515,8 +667,18 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
             options->uamlist = optarg;
             break;
         case 'v':      /* version */
-            printf( "afpd (version %s)\n", VERSION );
-            exit ( 1 );
+            show_version( ); puts( "" );
+           show_paths( ); puts( "" );
+            exit( 0 );
+            break;
+        case 'V':      /* extended version */
+            show_version_extended( ); puts( "" );
+           show_paths( ); puts( "" );
+            exit( 0 );
+            break;
+        case 'h':      /* usage */
+            show_usage( p );
+            exit( 0 );
             break;
         case 'I':
             options->flags |= OPTION_CUSTOMICON;
@@ -537,20 +699,14 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
         }
     }
     if ( err || optind != ac ) {
-        fprintf( stderr,
-                 "Usage:\t%s [ -dpDTIt ] [ -n nbpname ] [ -f defvols ] \
-                 [ -P pidfile ] [ -s sysvols ] \n", p );
-        fprintf( stderr,
-                 "\t[ -u ] [ -c maxconn ] [ -g guest ] \
-                 [ -S port ] [ -L loginmesg ] [ -F configfile ] [ -U uamlist ]\n" );
-        return 0;
+        show_usage( p );
+        exit( 2 );
     }
 
 #ifdef ultrix
     openlog( p, LOG_PID ); /* ultrix only */
-#else /* ultrix */
+#else
     set_processname(p);
-    syslog_setup(log_debug, logtype_default, logoption_ndelay|logoption_pid, logfacility_daemon);
 #endif /* ultrix */
 
     return 1;