/*
- * $Id: status.c,v 1.10 2003-03-11 09:35:40 didg Exp $
+ * $Id: status.c,v 1.11 2003-04-16 22:45:10 samnoble Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include "icon.h"
static void status_flags(char *data, const int notif, const int ipok,
- const unsigned char passwdbits)
+ const unsigned char passwdbits, const int dirsrvcs)
{
u_int16_t status;
status |= AFPSRVRINFO_SRVNOTIFY;
}
status |= AFPSRVRINFO_FASTBOZO;
+ if (dirsrvcs)
+ status |= AFPSRVRINFO_SRVRDIR;
status = htons(status);
memcpy(data + AFPSTATUS_FLAGOFF, &status, sizeof(status));
}
data += len;
/* make room for signature and net address offset. save location of
- * signature offset.
+ * signature offset. we're also making room for directory names offset
+ * and the utf-8 server name offset.
*
* NOTE: technically, we don't need to reserve space for the
* signature and net address offsets if they're not going to be
* used. as there are no offsets after them, it doesn't hurt to
* have them specified though. so, we just do that to simplify
* things.
+ *
+ * NOTE2: AFP3.1 Documentation states that the directory names offset
+ * is a required feature, even though it can be set to zero.
*/
len = data - start;
status = htons(len + AFPSTATUS_POSTLEN);
return sigoff;
}
-static int status_netaddress(char *data, const int servoffset,
+static int status_netaddress(char *data, int *servoffset,
const ASP asp, const DSI *dsi,
const char *fqdn)
{
begin = data;
/* get net address offset */
- memcpy(&offset, data + servoffset, sizeof(offset));
+ memcpy(&offset, data + *servoffset, sizeof(offset));
data += ntohs(offset);
/* format:
}
#endif /* ! NO_DDP */
+ /* 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 = 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;
+ } 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));
+
/* return length of buffer */
return (data - begin);
+
}
/* returns actual offset to signature */
ASP asp;
DSI *dsi;
char *status;
- int c, sigoff;
+ int statuslen, c, sigoff;
if (!(aspconfig || dsiconfig) || !options)
return;
status_flags(status, options->server_notif, options->fqdn ||
(dsiconfig && dsi->server.sin_addr.s_addr),
- options->passwdbits);
+ options->passwdbits,
+ (options->k5service && options->k5realm && options->fqdn));
/* returns offset to signature offset */
c = status_server(status, options->server ? options->server :
options->hostname);
status_icon(status, apple_atalk_icon, sizeof(apple_atalk_icon), c);
sigoff = status_signature(status, &c, dsi, options);
+ /* c now contains the offset where the netaddress offset lives */
+
+ status_netaddress(status, &c, asp, dsi, options->fqdn);
+ /* c now contains the offset where the Directory Names Count offset lives */
+
+ status_directorynames(status, &c, dsi, options);
+ /* c now contains the offset where the UTF-8 ServerName offset lives */
- /* returns length */
- c = status_netaddress(status, c, asp, dsi, options->fqdn);
+ statuslen = status_utf8servername(status, &c, dsi, options);
#ifndef NO_DDP
if (aspconfig) {
- asp_setstatus(asp, status, c);
+ asp_setstatus(asp, status, statuslen);
aspconfig->signature = status + sigoff;
- aspconfig->statuslen = c;
+ aspconfig->statuslen = statuslen;
}
#endif /* ! NO_DDP */
if ((options->flags & OPTION_CUSTOMICON) == 0) {
status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0);
}
- dsi_setstatus(dsi, status, c);
+ dsi_setstatus(dsi, status, statuslen);
dsiconfig->signature = status + sigoff;
- dsiconfig->statuslen = c;
+ dsiconfig->statuslen = statuslen;
}
}