]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_config.c
added new type logtype_afpd
[netatalk.git] / etc / afpd / afp_config.c
index bbed20a88a0573e49269c46398bcf301b6742174..7cfeb80c6ab9e10275d7504452aedcc8846edaff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_config.c,v 1.11 2001-12-15 18:34:39 jmarcus Exp $
+ * $Id: afp_config.c,v 1.17 2002-03-24 01:23:40 sibaz Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved.  See COPYRIGHT.
@@ -33,7 +33,7 @@ char *strchr (), *strrchr ();
 #include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 #include <ctype.h>
-#include <syslog.h>
+#include <atalk/logger.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -109,7 +109,7 @@ static void dsi_cleanup(const AFPConfig *config)
     SLPHandle hslp;
     err = SLPOpen("en", SLP_FALSE, &hslp);
     if (err != SLP_OK) {
-        syslog(LOG_ERR, "Error opening SRVLOC handle");
+        LOG(log_error, logtype_afpd, "dsi_cleanup: Error opening SRVLOC handle");
         goto srvloc_dereg_err;
     }
 
@@ -118,12 +118,12 @@ static void dsi_cleanup(const AFPConfig *config)
                    SRVLOC_callback,
                    &callbackerr);
     if (err != SLP_OK) {
-        syslog(LOG_ERR, "Error unregistering %s from SRVLOC", srvloc_url);
+        LOG(log_error, logtype_afpd, "dsi_cleanup: Error unregistering %s from SRVLOC", srvloc_url);
         goto srvloc_dereg_err;
     }
 
     if (callbackerr != SLP_OK) {
-        syslog(LOG_ERR, "Error in callback while trying to unregister %s from SRVLOC (%i)", srvloc_url, callbackerr);
+        LOG(log_error, logtype_afpd, "dsi_cleanup: Error in callback while trying to unregister %s from SRVLOC (%d)", srvloc_url, callbackerr);
         goto srvloc_dereg_err;
     }
 
@@ -148,7 +148,7 @@ static int asp_start(AFPConfig *config, AFPConfig *configs,
 
     if (!(asp = asp_getsession(config->obj.handle, server_children,
                                config->obj.options.tickleval))) {
-        syslog( LOG_ERR, "main: asp_getsession: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "main: asp_getsession: %s", strerror(errno) );
         exit( 1 );
     }
 
@@ -169,7 +169,7 @@ static int dsi_start(AFPConfig *config, AFPConfig *configs,
 
     if (!(dsi = dsi_getsession(config->obj.handle, server_children,
                                config->obj.options.tickleval))) {
-        syslog( LOG_ERR, "main: dsi_getsession: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "main: dsi_getsession: %s", strerror(errno) );
         exit( 1 );
     }
 
@@ -196,13 +196,13 @@ static AFPConfig *ASPConfigInit(const struct afp_options *options,
         return NULL;
 
     if ((atp = atp_open(ATADDR_ANYPORT, &options->ddpaddr)) == NULL)  {
-        syslog( LOG_ERR, "main: atp_open: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "main: atp_open: %s", strerror(errno) );
         free(config);
         return NULL;
     }
 
     if ((asp = asp_init( atp )) == NULL) {
-        syslog( LOG_ERR, "main: asp_init: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "main: asp_init: %s", strerror(errno) );
         atp_close(atp);
         free(config);
         return NULL;
@@ -211,7 +211,7 @@ static AFPConfig *ASPConfigInit(const struct afp_options *options,
     /* register asp server */
     Obj = (char *) options->hostname;
     if (nbp_name(options->server, &Obj, &Type, &Zone )) {
-        syslog( LOG_ERR, "main: can't parse %s", options->server );
+        LOG(log_error, logtype_afpd, "main: can't parse %s", options->server );
         goto serv_free_return;
     }
 
@@ -234,17 +234,17 @@ static AFPConfig *ASPConfigInit(const struct afp_options *options,
     /* make sure we're not registered */
     nbp_unrgstr(Obj, Type, Zone, &options->ddpaddr);
     if (nbp_rgstr( atp_sockaddr( atp ), Obj, Type, Zone ) < 0 ) {
-        syslog( LOG_ERR, "Can't register %s:%s@%s", Obj, Type, Zone );
+        LOG(log_error, logtype_afpd, "Can't register %s:%s@%s", Obj, Type, Zone );
         free(config->obj.Obj);
         free(config->obj.Type);
         free(config->obj.Zone);
         goto serv_free_return;
     }
 
-    syslog( LOG_INFO, "%s:%s@%s started on %u.%u:%u (%s)", Obj, Type, Zone,
-            ntohs( atp_sockaddr( atp )->sat_addr.s_net ),
-            atp_sockaddr( atp )->sat_addr.s_node,
-            atp_sockaddr( atp )->sat_port, VERSION );
+    LOG(log_info, logtype_afpd, "%s:%s@%s started on %u.%u:%u (%s)", Obj, Type, Zone,
+        ntohs( atp_sockaddr( atp )->sat_addr.s_net ),
+        atp_sockaddr( atp )->sat_addr.s_node,
+        atp_sockaddr( atp )->sat_port, VERSION );
 
     config->fd = atp_fileno(atp);
     config->obj.handle = asp;
@@ -280,10 +280,11 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
     SLPError callbackerr;
     SLPHandle hslp;
     struct servent *afpovertcp;
+    int afp_port = 548;
 #endif /* USE_SRVLOC */
 
     if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) {
-        syslog( LOG_ERR, "DSIConfigInit: malloc(config): %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "DSIConfigInit: malloc(config): %s", strerror(errno) );
         return NULL;
     }
 
@@ -291,25 +292,25 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
                         options->ipaddr, options->port,
                         options->flags & OPTION_PROXY,
                         options->server_quantum)) == NULL) {
-        syslog( LOG_ERR, "main: dsi_init: %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "main: dsi_init: %s", strerror(errno) );
         free(config);
         return NULL;
     }
 
     if (options->flags & OPTION_PROXY) {
-        syslog(LOG_INFO, "ASIP proxy initialized for %s:%d (%s)",
-               inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port),
-               VERSION);
+        LOG(log_info, logtype_afpd, "ASIP proxy initialized for %s:%d (%s)",
+            inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port),
+            VERSION);
     } else {
-        syslog(LOG_INFO, "ASIP started on %s:%d(%d) (%s)",
-               inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port),
-               dsi->serversock, VERSION);
+        LOG(log_info, logtype_afpd, "ASIP started on %s:%d(%d) (%s)",
+            inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port),
+            dsi->serversock, VERSION);
     }
 
 #ifdef USE_SRVLOC
     err = SLPOpen("en", SLP_FALSE, &hslp);
     if (err != SLP_OK) {
-        syslog(LOG_ERR, "Error opening SRVLOC handle");
+        LOG(log_error, logtype_afpd, "DSIConfigInit: Error opening SRVLOC handle");
         goto srvloc_reg_err;
     }
 
@@ -318,11 +319,18 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
      * use a non-default port, they can, but be aware, this server might not
      * show up int the Network Browser. */
     afpovertcp = getservbyname("afpovertcp", "tcp");
-    if (dsi->server.sin_port == afpovertcp->s_port) {
-        snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), options->hostname);
+    if (afpovertcp != NULL) {
+        afp_port = afpovertcp->s_port;
+    }
+    if (strlen(options->hostname) > (sizeof(srvloc_url) - strlen(inet_ntoa(dsi->server.sin_addr)) - 21)) {
+        LOG(log_error, logtype_afpd, "DSIConfigInit: Hostname is too long for SRVLOC");
+        goto srvloc_reg_err;
+    }
+    if (dsi->server.sin_port == afp_port) {
+        sprintf(srvloc_url, "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), options->hostname);
     }
     else {
-        snprintf(srvloc_url, sizeof(srvloc_url), "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), options->hostname);
+        sprintf(srvloc_url, "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), options->hostname);
     }
 
     err = SLPReg(hslp,
@@ -334,16 +342,16 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
                  SRVLOC_callback,
                  &callbackerr);
     if (err != SLP_OK) {
-        syslog(LOG_ERR, "Error registering %s with SRVLOC", srvloc_url);
+        LOG(log_error, logtype_afpd, "DSIConfigInit: Error registering %s with SRVLOC", srvloc_url);
         goto srvloc_reg_err;
     }
 
     if (callbackerr != SLP_OK) {
-        syslog(LOG_ERR, "Error in callback trying to register %s with SRVLOC", srvloc_url);
+        LOG(log_error, logtype_afpd, "DSIConfigInit: Error in callback trying to register %s with SRVLOC", srvloc_url);
         goto srvloc_reg_err;
     }
 
-    syslog(LOG_INFO, "Sucessfully registered %s with SRVLOC", srvloc_url);
+    LOG(log_info, logtype_afpd, "Sucessfully registered %s with SRVLOC", srvloc_url);
 
 srvloc_reg_err:
     SLPClose(hslp);
@@ -383,7 +391,7 @@ static AFPConfig *AFPConfigInit(const struct afp_options *options,
 
     if ((refcount = (unsigned char *)
                     calloc(1, sizeof(unsigned char))) == NULL) {
-        syslog( LOG_ERR, "AFPConfigInit: calloc(refcount): %s", strerror(errno) );
+        LOG(log_error, logtype_afpd, "AFPConfigInit: calloc(refcount): %s", strerror(errno) );
         return NULL;
     }