]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/status.c
Merge branch 'v3-cleanup' into tmp/v3.0.4-alex
[netatalk.git] / etc / afpd / status.c
index f39e1ed48e3f49ad837ed3064b706b8c4d717947..ec1025dda3922106a2325290fd9ff59fb7d13ce2 100644 (file)
@@ -95,7 +95,7 @@ static void status_flags(char *data,
 static int status_server(char *data, const char *server, const struct afp_options *options)
 {
     char                *start = data;
-    char                *Obj, *Type, *Zone;
+    char                *Obj;
     char               buf[32];
     uint16_t           status;
     size_t             len;
@@ -363,9 +363,9 @@ static size_t status_directorynames(char *data,
     offset = ntohs(offset);
     data += offset;
 
-    char *DirectoryNamesCount = data++, *DirectoryNames = data;
-    *DirectoryNamesCount = 0;
+    char *DirectoryNamesCount = data++;
     size_t size = sizeof(uint8_t);
+    *DirectoryNamesCount = 0;
 
     if (!uam_gss_enabled())
         goto offset_calc;
@@ -415,7 +415,11 @@ static size_t status_directorynames(char *data,
                 "status:DirectoryNames: specified service principal '%s' not found in keytab",
                 principal);
             // XXX: should this be krb5_xfree?
+#ifdef HAVE_KRB5_FREE_UNPARSED_NAME
             krb5_free_unparsed_name(context, principal);
+#else
+           krb5_xfree(principal);
+#endif
             goto krb5_cleanup;
         }
         krb5_free_principal(context, service_principal);
@@ -436,8 +440,11 @@ static size_t status_directorynames(char *data,
     }
 
     krb5_unparse_name(context, entry.principal, &principal);
+#ifdef HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS
+    krb5_free_keytab_entry_contents(context, &entry);
+#elif defined(HAVE_KRB5_KT_FREE_ENTRY)
     krb5_kt_free_entry(context, &entry);
-
+#endif
     append_directoryname(&data,
                          offset,
                          &size,
@@ -445,17 +452,19 @@ static size_t status_directorynames(char *data,
                          strlen(principal),
                          principal);
 
-    // XXX: should this be krb5_xfree?
-    krb5_free_unparsed_name(context, principal);
+    free(principal);
     goto krb5_cleanup;
 
 krb5_error:
     if (ret) {
         error_msg = krb5_get_error_message(context, ret);
-        LOG(log_error, logtype_afpd,
-            "status:DirectoryNames: Kerberos error: %s",
-            (char *) error_msg);
+        LOG(log_note, logtype_afpd, "Can't get principal from default keytab: %s",
+            (char *)error_msg);
+#ifdef HAVE_KRB5_FREE_ERROR_MESSAGE
         krb5_free_error_message(context, error_msg);
+#else
+       krb5_xfree(error_msg);
+#endif
     }
 
 krb5_cleanup:
@@ -491,30 +500,24 @@ static size_t status_utf8servername(char *data, int *nameoffset,
                                 const DSI *dsi _U_,
                                 const struct afp_options *options)
 {
-    char *Obj, *Type, *Zone;
     uint16_t namelen;
     size_t len;
     char *begin = data;
-    uint16_t offset, status;
+    uint16_t offset;
 
     memcpy(&offset, data + *nameoffset, sizeof(offset));
     offset = ntohs(offset);
     data += offset;
 
-    /* FIXME:
-     * What is the valid character range for an nbpname?
-     *
-     * Apple's server likes to use the non-qualified hostname
-     * This obviously won't work very well if multiple servers are running
-     * on the box.
-     */
+    LOG(log_info, logtype_afpd, "servername: %s", options->hostname);
 
-    /* extract the obj part of the server */
-    Obj = options->hostname;
-    if ((size_t) -1 == (len = convert_string (
-                            options->unixcharset, CH_UTF8_MAC, 
-                            Obj, -1, data+sizeof(namelen), maxstatuslen-offset )) ) {
-        LOG ( log_error, logtype_afpd, "Could not set utf8 servername");
+    if ((len = convert_string(options->unixcharset,
+                              CH_UTF8_MAC, 
+                              options->hostname,
+                              -1,
+                              data + sizeof(namelen),
+                              maxstatuslen-offset)) == (size_t)-1) {
+        LOG(log_error, logtype_afpd, "Could not set utf8 servername");
 
         /* set offset to 0 */
         memset(begin + *nameoffset, 0, sizeof(offset));
@@ -605,17 +608,14 @@ void status_init(AFPObj *obj, DSI *dsi)
                  options->flags & OPTION_SERVERNOTIF,
                  (options->fqdn || ipok),
                  options->passwdbits, 
-                 uam_gss_enabled(),
+                 1,
                  options->flags);
     /* returns offset to signature offset */
     c = status_server(status, options->hostname, options);
     status_machine(status);
     status_versions(status, dsi);
     status_uams(status, options->uamlist);
-    if (options->flags & OPTION_CUSTOMICON)
-        status_icon(status, icon, sizeof(icon), c);
-    else
-        status_icon(status, apple_atalk_icon, sizeof(apple_atalk_icon), c);
+    status_icon(status, icon, sizeof(icon), c);
 
     sigoff = status_signature(status, &c, options);
     /* c now contains the offset where the netaddress offset lives */
@@ -629,10 +629,6 @@ void status_init(AFPObj *obj, DSI *dsi)
     if ( statuslen < maxstatuslen) 
         statuslen = status_utf8servername(status, &c, dsi, options);
 
-    if ((options->flags & OPTION_CUSTOMICON) == 0) {
-        status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0);
-    }
-
     dsi->signature = status + sigoff;
     dsi->statuslen = statuslen;
 }
@@ -643,52 +639,39 @@ void status_init(AFPObj *obj, DSI *dsi)
 /* If not found in conf file, genarate and append in conf file.       */
 /* If conf file don't exist, create and genarate.                     */
 /* If cannot open conf file, use one-time signature.                  */
-/* If signature = user:xxxxx, use it.                                  */
+/* If signature = xxxxx, use it.                                      */
 
 void set_signature(struct afp_options *options) {
-    char *usersign;
     int fd, i;
     struct stat tmpstat;
     char *servername_conf;
     int header = 0;
     char buf[1024], *p;
-    FILE *fp = NULL, *randomp;
+    FILE *fp = NULL;
     size_t len;
     char *server_tmp;
     
     server_tmp = options->hostname;
-    if (strcmp(options->signatureopt, "auto") == 0) {
+    len = strlen(options->signatureopt);
+    if (len == 0) {
         goto server_signature_auto;   /* default */
-    } else if (strcmp(options->signatureopt, "host") == 0) {
-        LOG(log_warning, logtype_afpd, "WARNING: option \"-signature host\" is obsoleted. Switching back to auto.", options->signatureopt);
-        goto server_signature_auto;   /* same as auto */
-    } else if (strncmp(options->signatureopt, "user", 4) == 0) {
-        goto server_signature_user;   /*  user string */
+    } else if (len < 3) {
+        LOG(log_warning, logtype_afpd, "WARNING: signature string %s is very short!", options->signatureopt);
+        goto server_signature_user;
+    } else if (len > 16) {
+        LOG(log_warning, logtype_afpd, "WARNING: signature string %s is very long!", options->signatureopt);
+        len = 16;
+        goto server_signature_user;
     } else {
-        LOG(log_error, logtype_afpd, "ERROR: option \"-signature %s\" is not valid. Switching back to auto.", options->signatureopt);
-        goto server_signature_auto;   /* switch back to auto*/
+        LOG(log_info, logtype_afpd, "signature string is %s.", options->signatureopt);
+        goto server_signature_user;
     }
     
 server_signature_user:
     
-    /* Signature type is user string */
-    len = strlen(options->signatureopt);
-    if (len <= 5) {
-        LOG(log_warning, logtype_afpd, "WARNING: option \"-signature %s\" is not valid. Switching back to auto.", options->signatureopt);
-        goto server_signature_auto;
-    }
-    usersign = options->signatureopt + 5;
-    len = len - 5;
-    if (len > 16) {
-        LOG(log_warning, logtype_afpd, "WARNING: signature user string %s is very long !",  usersign);
-        len = 16;
-    } else if (len >= 3) {
-        LOG(log_info, logtype_afpd, "signature user string is %s.", usersign);
-    } else {
-        LOG(log_warning, logtype_afpd, "WARNING: signature user string %s is very short !",  usersign);
-    }
+    /* Signature is defined in afp.conf */
     memset(options->signature, 0, 16);
-    memcpy(options->signature, usersign, len);
+    memcpy(options->signature, options->signatureopt, len);
     goto server_signature_done;
     
 server_signature_auto:
@@ -783,7 +766,7 @@ server_signature_random:
         fprintf(fp, "# ServerSignature is unique identifier used to prevent logging on to\n");
         fprintf(fp, "# the same server twice.\n");
         fprintf(fp, "# \n");
-        fprintf(fp, "# If setting \"signature = user:xxxxx\" in afp.conf, this file is not used.\n\n");
+        fprintf(fp, "# If setting \"signature = xxxxx\" in afp.conf, this file is not used.\n\n");
     }
     
     if (fp) {
@@ -799,8 +782,7 @@ server_signature_done:
     
     /* retrun */
     LOG(log_info, logtype_afpd,
-        " \"%s\"'s signature is  %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-        server_tmp,
+        "signature is %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
         (options->signature)[ 0], (options->signature)[ 1],
         (options->signature)[ 2], (options->signature)[ 3],
         (options->signature)[ 4], (options->signature)[ 5],