]> arthur.barton.de Git - netatalk.git/commitdiff
MFH and MFM: 1.12, 1.13
authorjmarcus <jmarcus>
Sun, 16 Dec 2001 23:26:17 +0000 (23:26 +0000)
committerjmarcus <jmarcus>
Sun, 16 Dec 2001 23:26:17 +0000 (23:26 +0000)
Certain platforms do not support snprintf() (e.g. Tru64).  Remove that
function call, and replace it with sprintf() after verifying we aren't
going to overflow srvloc_url.

Remove the snprintf() argument from the sprintf() calls.  Thanks to
Burkhard Schmidt for catching this.

etc/afpd/afp_config.c

index 240f5e4250b244eeacb44330cb04cc4a24cf29e9..ff584cfe8205823e2e7c317273edd219b3ef903f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_config.c,v 1.7.2.1 2001-12-03 05:01:03 jmarcus Exp $
+ * $Id: afp_config.c,v 1.7.2.2 2001-12-16 23:26:17 jmarcus Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved.  See COPYRIGHT.
@@ -11,6 +11,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 /* STDC check */
 #if STDC_HEADERS
@@ -107,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");
+        syslog(LOG_ERR, "dsi_cleanup: Error opening SRVLOC handle");
         goto srvloc_dereg_err;
     }
 
@@ -116,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);
+        syslog(LOG_ERR, "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);
+        syslog(LOG_ERR, "dsi_cleanup: Error in callback while trying to unregister %s from SRVLOC (%d)", srvloc_url, callbackerr);
         goto srvloc_dereg_err;
     }
 
@@ -146,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: %m" );
+        syslog( LOG_ERR, "main: asp_getsession: %s", strerror(errno) );
         exit( 1 );
     }
 
@@ -167,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: %m" );
+        syslog( LOG_ERR, "main: dsi_getsession: %s", strerror(errno) );
         exit( 1 );
     }
 
@@ -194,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: %m");
+        syslog( LOG_ERR, "main: atp_open: %s", strerror(errno) );
         free(config);
         return NULL;
     }
 
     if ((asp = asp_init( atp )) == NULL) {
-        syslog( LOG_ERR, "main: asp_init: %m" );
+        syslog( LOG_ERR, "main: asp_init: %s", strerror(errno) );
         atp_close(atp);
         free(config);
         return NULL;
@@ -281,7 +283,7 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
 #endif /* USE_SRVLOC */
 
     if ((config = (AFPConfig *) calloc(1, sizeof(AFPConfig))) == NULL) {
-        syslog( LOG_ERR, "DSIConfigInit: malloc(config): %m" );
+        syslog( LOG_ERR, "DSIConfigInit: malloc(config): %s", strerror(errno) );
         return NULL;
     }
 
@@ -289,7 +291,7 @@ 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: %m" );
+        syslog( LOG_ERR, "main: dsi_init: %s", strerror(errno) );
         free(config);
         return NULL;
     }
@@ -307,7 +309,7 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
 #ifdef USE_SRVLOC
     err = SLPOpen("en", SLP_FALSE, &hslp);
     if (err != SLP_OK) {
-        syslog(LOG_ERR, "Error opening SRVLOC handle");
+        syslog(LOG_ERR, "DSIConfigInit: Error opening SRVLOC handle");
         goto srvloc_reg_err;
     }
 
@@ -316,11 +318,15 @@ 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 (strlen(options->hostname) > (sizeof(srvloc_url) - strlen(inet_ntoa(dsi->server.sin_addr)) - 21)) {
+        syslog(LOG_ERR, "DSIConfigInit: Hostname is too long for SRVLOC");
+        goto srvloc_reg_err;
+    }
     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);
+        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,
@@ -332,12 +338,12 @@ 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);
+        syslog(LOG_ERR, "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);
+        syslog(LOG_ERR, "DSIConfigInit: Error in callback trying to register %s with SRVLOC", srvloc_url);
         goto srvloc_reg_err;
     }
 
@@ -381,7 +387,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): %m" );
+        syslog( LOG_ERR, "AFPConfigInit: calloc(refcount): %s", strerror(errno) );
         return NULL;
     }