]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_options.c
Fix fce merge conflict
[netatalk.git] / etc / afpd / afp_options.c
index d6566dfdd0096f5943d63231db3fbb6046bd0f7d..9bb48042fa1e98ffdb5033edf70173995c310740 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: afp_options.c,v 1.35 2005-04-28 20:49:39 bfernhomberg Exp $
- *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
 
 #include <stdio.h>
 #include <stdlib.h>
-
-/* STDC check */
-#if STDC_HEADERS
 #include <string.h>
-#else /* STDC_HEADERS */
-#ifndef HAVE_STRCHR
-#define strchr index
-#define strrchr index
-#endif /* HAVE_STRCHR */
-char *strchr (), *strrchr ();
-#ifndef HAVE_MEMCPY
-#define memcpy(d,s,n) bcopy ((s), (d), (n))
-#define memmove(d,s,n) bcopy ((s), (d), (n))
-#endif /* ! HAVE_MEMCPY */
-#endif /* STDC_HEADERS */
-
 #include <ctype.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <atalk/logger.h>
 
 #include <netinet/in.h>
 #include <arpa/inet.h>
+
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif /* HAVE_NETDB_H */
 
+#ifdef ADMIN_GRP
+#include <grp.h>
+#include <sys/types.h>
+#endif /* ADMIN_GRP */
+
 #include <atalk/paths.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
+
 #include "globals.h"
 #include "status.h"
 #include "auth.h"
-
-#include <atalk/compat.h>
-
-#ifdef ADMIN_GRP
-#include <grp.h>
-#include <sys/types.h>
-#endif /* ADMIN_GRP */
+#include "dircache.h"
+#include "fce_api.h"
 
 #ifndef MIN
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
 #endif /* MIN */
 
 /* FIXME CNID */
-char             Cnid_srv[MAXHOSTNAMELEN + 1] = "localhost";
-int              Cnid_port = 4700;
+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
@@ -127,6 +111,8 @@ 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))
@@ -135,8 +121,8 @@ void afp_options_free(struct afp_options *opt,
         free(opt->uamlist);
     if (opt->passwdfile && (opt->passwdfile != save->passwdfile))
         free(opt->passwdfile);
-    if (opt->signature && (opt->signature != save->signature))
-       free(opt->signature);
+    if (opt->signatureopt && (opt->signatureopt != save->signatureopt))
+       free(opt->signatureopt);
     if (opt->k5service && (opt->k5service != save->k5service))
        free(opt->k5service);
     if (opt->k5realm && (opt->k5realm != save->k5realm))
@@ -147,6 +133,13 @@ void afp_options_free(struct afp_options *opt,
        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);
+    if (opt->logconfig && (opt->logconfig != save->logconfig))
+       free(opt->logconfig);
 }
 
 /* initialize options */
@@ -158,18 +151,21 @@ void afp_options_init(struct afp_options *options)
     options->defaultvol.name = _PATH_AFPDDEFVOL;
     options->systemvol.name = _PATH_AFPDSYSVOL;
     options->configfile = _PATH_AFPDCONF;
+    options->sigconffile = _PATH_AFPDSIGCONF;
+    options->uuidconf = _PATH_AFPDUUIDCONF;
     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;
-    options->sleep = 10* 120; /* 10 h in 30 seconds tick */
+    options->timeout = 4;       /* 4 tickles = 2 minutes */
+    options->sleep = 10 * 60 * 2; /* 10 h in 30 seconds tick */
+    options->disconnected = 10 * 60 * 2; /* 10 h in 30 seconds tick */
     options->server_notif = 1;
     options->authprintdir = NULL;
-    options->signature = "host";
+    options->signatureopt = "auto";
     options->umask = 0;
 #ifdef ADMIN_GRP
     options->admingid = 0;
@@ -181,6 +177,19 @@ void afp_options_init(struct afp_options *options)
     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;
+#ifdef USE_SRVLOC
+    /* don't advertize slp by default */
+    options->flags |= OPTION_NOSLP;
+#endif
+    options->dircachesize = DEFAULT_MAX_DIRCACHE_SIZE;
+    options->flags |= OPTION_ACL2MACCESS;
+    options->flags |= OPTION_UUID;
+    options->tcp_sndbuf = 0;    /* 0 means don't change OS default */
+    options->tcp_rcvbuf = 0;    /* 0 means don't change OS default */
+    options->dsireadbuf = 12;
 }
 
 /* parse an afpd.conf line. i'm doing it this way because it's
@@ -203,10 +212,13 @@ int afp_options_parseline(char *buf, struct afp_options *options)
     if (strstr(buf, " -nodebug"))
         options->flags &= ~OPTION_DEBUG;
 #ifdef USE_SRVLOC
-    if (strstr(buf, " -noslp"))
-        options->flags |= OPTION_NOSLP;
-#endif /* USE_SRVLOC */
-
+    if (strstr(buf, " -slp"))
+        options->flags &= ~OPTION_NOSLP;
+#endif
+#ifdef USE_ZEROCONF
+    if (strstr(buf, " -nozeroconf"))
+        options->flags |= OPTION_NOZEROCONF;
+#endif
     if (strstr(buf, " -nouservolfirst"))
         options->flags &= ~OPTION_USERVOLFIRST;
     if (strstr(buf, " -uservolfirst"))
@@ -223,6 +235,8 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         options->flags |= OPTION_CUSTOMICON;
     if (strstr(buf, " -advertise_ssh"))
         options->flags |= OPTION_ANNOUNCESSH;
+    if (strstr(buf, " -noacl2maccess"))
+        options->flags &= ~OPTION_ACL2MACCESS;
 
     /* passwd bits */
     if (strstr(buf, " -nosavepassword"))
@@ -267,8 +281,22 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         options->defaultvol.name = opt;
     if ((c = getoption(buf, "-systemvol")) && (opt = strdup(c)))
         options->systemvol.name = opt;
-    if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c)))
+    if ((c = getoption(buf, "-loginmesg")) && (opt = strdup(c))) {
+        int i = 0, j = 0;
+        while (c[i]) {
+            if (c[i] != '\\') {
+                opt[j++] = c[i];
+            } else {
+                i++;
+                if (c[i] == 'n')
+                    opt[j++] = '\n';
+            }
+            i++;
+        }
+        opt[j] = 0;
         options->loginmesg = opt;
+        
+    }
     if ((c = getoption(buf, "-guestname")) && (opt = strdup(c)))
         options->guest = opt;
     if ((c = getoption(buf, "-passwdfile")) && (opt = strdup(c)))
@@ -297,124 +325,41 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         }
     }
 
+    if ((c = getoption(buf, "-dsireadbuf"))) {
+        options->dsireadbuf = atoi(c);
+        if (options->dsireadbuf < 6)
+            options->dsireadbuf = 6;
+    }
+
     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, *logsource, *logtype, *loglevel, *filename;
-
-      LOG(log_debug6, logtype_afpd, "setting up logtype, c is %s", c);
-      ptr = c;
-      
-      /* 
-      logsource = ptr = c;
-      if (ptr)
-      {
-        ptr = strpbrk(ptr, " \t");
-        if (ptr) 
-        {
-          *ptr++ = 0;
-          while (*ptr && isspace(*ptr))
-            ptr++;
-        }
-      }
-      */
-
-      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++;
+    if ((c = getoption(buf, "-volnamelen"))) {
+        options->volnamelen = atoi(c);
+        if (options->volnamelen < 8) {
+            options->volnamelen = 8; /* max mangled volname "???#FFFF" */
         }
-      }
-
-      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);
+            options->logconfig = optstr; /* at least store the last (possibly only) one */
+            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);
@@ -445,6 +390,7 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         options->uamlist = opt;
 
     if ((c = getoption(buf, "-ipaddr"))) {
+#if 0
         struct in_addr inaddr;
         if (inet_aton(c, &inaddr) && (opt = strdup(c))) {
             if (!gethostbyaddr((const char *) &inaddr, sizeof(inaddr), AF_INET))
@@ -454,26 +400,27 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         else {
             LOG(log_error, logtype_afpd, "Error parsing -ipaddr, is %s in numbers-and-dots notation?", c);
         }
+#endif
+        options->ipaddr = strdup(c);
     }
 
     /* 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);
-       }
+        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)))
-        options->signature = opt;
+        options->signatureopt = opt;
 
     /* do a little checking for the domain name. */
     if ((c = getoption(buf, "-fqdn"))) {
@@ -517,6 +464,30 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         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;
+
+    if ((c = getoption(buf, "-dircachesize")))
+        options->dircachesize = atoi(c);
+     
+    if ((c = getoption(buf, "-tcpsndbuf")))
+        options->tcp_sndbuf = atoi(c);
+
+    if ((c = getoption(buf, "-tcprcvbuf")))
+        options->tcp_rcvbuf = atoi(c);
+
+       if ((c = getoption(buf, "-fcelistener"))) {
+               LOG(log_note, logtype_afpd, "Adding fce listener \"%s\"", c);
+               fce_add_udp_socket(c);
+       }
+       if ((c = getoption(buf, "-fcecoalesce"))) {
+               LOG(log_ote, logtype_afpd, "Fce coalesce: %s", c);
+               fce_set_coalesce(c);
+       }
+
     return 1;
 }
 
@@ -524,7 +495,7 @@ int afp_options_parseline(char *buf, struct afp_options *options)
  * Show version information about afpd.
  * Used by "afp -v".
  */
-void show_version( )
+static void show_version( void )
 {
        printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
 
@@ -535,18 +506,15 @@ void show_version( )
 
        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( "        AFP3.x support:\tYes\n" );
+        printf( "        TCP/IP Support:\t" );
+        puts( "Yes" );
 
-       printf( "      Transport layers:\t" );
+       printf( "DDP(AppleTalk) Support:\t" );
 #ifdef NO_DDP
-       puts( "TCP/IP" );
+       puts( "No" );
 #else
-       puts( "TCP/IP DDP" );
+       puts( "Yes" );
 #endif
 
        printf( "         CNID backends:\t" );
@@ -582,7 +550,7 @@ void show_version( )
  * Show extended version information about afpd and Netatalk.
  * Used by "afp -V".
  */
-void show_version_extended( )
+static void show_version_extended(void )
 {
        show_version( );
 
@@ -593,6 +561,13 @@ void show_version_extended( )
        puts( "No" );
 #endif
 
+       printf( "      Zeroconf support:\t" );
+#ifdef USE_ZEROCONF
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
        printf( "  TCP wrappers support:\t" );
 #ifdef TCPWRAP
        puts( "Yes" );
@@ -641,27 +616,53 @@ void show_version_extended( )
 #else
        puts( "No" );
 #endif
+
+       printf( "           ACL support:\t" );
+#ifdef HAVE_ACLS
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
+
+       printf( "            EA support:\t" );
+       puts( EA_MODULES );
+
+       printf( "          LDAP support:\t" );
+#ifdef HAVE_LDAP
+       puts( "Yes" );
+#else
+       puts( "No" );
+#endif
 }
 
 /*
  * Display compiled-in default paths
  */
-void show_paths( void )
+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( "    afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
+       printf( "      afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
+#ifdef HAVE_LDAP
+       printf( "         afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
+#else
+       printf( "         afp_ldap.conf:\tnot supported\n");
+#endif
        printf( "       UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
+       printf( "  Server messages path:\t%s\n", SERVERTEXT);
+       printf( "              lockfile:\t%s\n", _PATH_AFPDLOCK);
 }
 
 /*
- * Display usage information about adpd.
+ * Display usage information about afpd.
  */
-void show_usage( char *name )
+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, "Usage:\t%s [-duptDTI] [-f defaultvolumes] [-s systemvolumes] [-n nbpname]\n", name );
+       fprintf( stderr, "\t     [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
+       fprintf( stderr, "\t     [-F configfile] [-U uams] [-m umask]\n" );
        fprintf( stderr, "\t%s -h|-v|-V\n", name );
 }
 
@@ -727,7 +728,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;
@@ -780,9 +781,8 @@ int afp_options_parse(int ac, char **av, struct afp_options *options)
 
 #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;