+ /* calculate/store Directory Services Names offset */
+ offset = htons(data - begin);
+ *servoffset += sizeof(offset);
+ memcpy(begin + *servoffset, &offset, sizeof(offset));
+
+ /* return length of buffer */
+ return (data - begin);
+}
+
+static int status_directorynames(char *data, int *diroffset,
+ const DSI *dsi,
+ const struct afp_options *options)
+{
+ char *begin = data;
+ u_int16_t offset;
+ memcpy(&offset, data + *diroffset, sizeof(offset));
+ offset = ntohs(offset);
+ data += offset;
+
+ /* I can not find documentation of any other purpose for the
+ * DirectoryNames field.
+ */
+ /*
+ * Try to synthesize a principal:
+ * service '/' fqdn '@' realm
+ */
+ if (options->k5service && options->k5realm && options->fqdn) {
+ /* should k5princ be utf8 encoded? */
+ u_int8_t len;
+ char *p = strchr( options->fqdn, ':' );
+ if (p)
+ *p = '\0';
+ len = strlen( options->k5service )
+ + strlen( options->fqdn )
+ + strlen( options->k5realm );
+ len+=2; /* '/' and '@' */
+ *data++ = 1; /* DirectoryNamesCount */
+ *data++ = len;
+ snprintf( data, len + 1, "%s/%s@%s", options->k5service,
+ options->fqdn, options->k5realm );
+ data += len;
+ if (p)
+ *p = ':';
+ } else {
+ memset(begin + *diroffset, 0, sizeof(offset));
+ }
+
+ /* Calculate and store offset for UTF8ServerName */
+ *diroffset += sizeof(u_int16_t);
+ offset = htons(data - begin);
+ memcpy(begin + *diroffset, &offset, sizeof(u_int16_t));
+
+ /* return length of buffer */
+ return (data - begin);
+}
+
+static int status_utf8servername(char *data, int *nameoffset,
+ const DSI *dsi,
+ const struct afp_options *options)
+{
+ u_int16_t namelen, len;
+ char *begin = data;
+ u_int16_t offset;
+ memcpy(&offset, data + *nameoffset, sizeof(offset));
+ offset = ntohs(offset);
+ data += offset;
+
+ /* FIXME: For now we set the UTF-8 ServerName offset to 0
+ * It's irrelevent anyway until we set the appropriate Flags value.
+ * Later this can be set to something meaningful.
+ *
+ * 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.
+ */
+ memset(begin + *nameoffset, 0, sizeof(offset));
+