X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fstatus.c;h=d95a7f3b8daf5fb24ecf8894bbb301da6da67154;hb=b1338b390059f9f7019edc1080833f5002e948d8;hp=ae51d26e28cc7fa973d133858f208fb761866d35;hpb=25ca059b795321076af8d8d422ba6a473ef04cf6;p=netatalk.git diff --git a/etc/afpd/status.c b/etc/afpd/status.c index ae51d26e..d95a7f3b 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -7,6 +7,7 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include #include #include #include @@ -28,24 +29,42 @@ #endif /* BSD4_4 */ #endif -#include -#include +#include + +#ifdef HAVE_KERBEROS +#ifdef HAVE_KRB5_KRB5_H +#include +#else +#include +#endif /* HAVE_KRB5_KRB5_H */ +#endif /* HAVE_KERBEROS */ + #include -#include -#include -#include #include #include +#include -#include "globals.h" /* includes */ #include "status.h" #include "afp_config.h" #include "icon.h" +#include "uam_auth.h" static size_t maxstatuslen = 0; -static void status_flags(char *data, const int notif, const int ipok, - const unsigned char passwdbits, const int dirsrvcs _U_, int flags) +static int uam_gss_enabled() +{ + /* XXX: must be a better way to find out if uam_gss is active */ + return auth_uamfind(UAM_SERVER_LOGIN_EXT, + "Client Krb v2", + sizeof("Client Krb v2")) != NULL; +} + +static void status_flags(char *data, + const int notif, + const int ipok, + const unsigned char passwdbits, + const int dirsrvcs, + int flags) { uint16_t status; @@ -53,7 +72,6 @@ static void status_flags(char *data, const int notif, const int ipok, | AFPSRVRINFO_SRVSIGNATURE | AFPSRVRINFO_SRVMSGS | AFPSRVRINFO_FASTBOZO - | AFPSRVRINFO_SRVRDIR | AFPSRVRINFO_SRVUTF8 | AFPSRVRINFO_EXTSLEEP; @@ -61,10 +79,12 @@ static void status_flags(char *data, const int notif, const int ipok, status |= AFPSRVRINFO_PASSWD; if (passwdbits & PASSWD_NOSAVE) status |= AFPSRVRINFO_NOSAVEPASSWD; - if (ipok) /* only advertise tcp/ip if we have a valid address */ + if (ipok) /* only advertise tcp/ip if we have a valid address */ status |= AFPSRVRINFO_TCPIP; - if (notif) /* Default is yes */ + if (notif) /* Default is yes */ status |= AFPSRVRINFO_SRVNOTIFY; + if (dirsrvcs) + status |= AFPSRVRINFO_SRVRDIR; if (flags & OPTION_UUID) status |= AFPSRVRINFO_UUID; @@ -75,9 +95,9 @@ static void status_flags(char *data, const int notif, const int ipok, 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]; - u_int16_t status; + uint16_t status; size_t len; /* make room for all offsets before server name */ @@ -85,14 +105,13 @@ static int status_server(char *data, const char *server, const struct afp_option /* extract the obj part of the server */ Obj = (char *) server; - nbp_name(server, &Obj, &Type, &Zone); if ((size_t)-1 == (len = convert_string( - options->unixcharset, options->maccharset, - Obj, -1, buf, sizeof(buf))) ) { - len = MIN(strlen(Obj), 31); + options->unixcharset, options->maccharset, + Obj, -1, buf, sizeof(buf))) ) { + len = MIN(strlen(Obj), 31); *data++ = len; memcpy( data, Obj, len ); - LOG ( log_error, logtype_afpd, "Could not set servername, using fallback"); + LOG ( log_error, logtype_afpd, "Could not set servername, using fallback"); } else { *data++ = len; memcpy( data, buf, len ); @@ -123,20 +142,32 @@ static int status_server(char *data, const char *server, const struct afp_option static void status_machine(char *data) { char *start = data; - u_int16_t status; + uint16_t status; int len; #ifdef AFS const char *machine = "afs"; #else /* !AFS */ - const char *machine = "Netatalk %s"; + const char *machine = "Netatalk%s"; #endif /* AFS */ char buf[AFPSTATUS_MACHLEN+1]; memcpy(&status, start + AFPSTATUS_MACHOFF, sizeof(status)); data += ntohs( status ); - // len = strlen( machine ); - len = snprintf(buf, AFPSTATUS_MACHLEN+1, machine, VERSION); + if ((strlen(machine) + strlen(VERSION)) <= AFPSTATUS_MACHLEN) { + len = snprintf(buf, AFPSTATUS_MACHLEN + 1, machine, VERSION); + } else { + if (strlen(VERSION) > AFPSTATUS_MACHLEN) { + len = snprintf(buf, AFPSTATUS_MACHLEN + 1, VERSION); + } else { + (void)snprintf(buf, AFPSTATUS_MACHLEN + 1, machine, ""); + (void)snprintf(buf + AFPSTATUS_MACHLEN - strlen(VERSION), + strlen(VERSION) + 1, + VERSION); + len = AFPSTATUS_MACHLEN; + } + } + *data++ = len; memcpy( data, buf, len ); data += len; @@ -146,11 +177,11 @@ static void status_machine(char *data) } /* server signature is a 16-byte quantity */ -static u_int16_t status_signature(char *data, int *servoffset, +static uint16_t status_signature(char *data, int *servoffset, const struct afp_options *options) { char *status; - u_int16_t offset, sigoff; + uint16_t offset, sigoff; status = data; @@ -173,11 +204,11 @@ static u_int16_t status_signature(char *data, int *servoffset, } static size_t status_netaddress(char *data, int *servoffset, - const ASP asp, const DSI *dsi, + const DSI *dsi, const struct afp_options *options) { char *begin; - u_int16_t offset; + uint16_t offset; size_t addresses_len = 0; begin = data; @@ -197,7 +228,7 @@ static size_t status_netaddress(char *data, int *servoffset, /* number of addresses. this currently screws up if we have a dsi connection, but we don't have the ip address. to get around this, we turn off the status flag for tcp/ip. */ - *data++ = ((options->fqdn && dsi)? 1 : 0) + (dsi ? 1 : 0) + (asp ? 1 : 0) + + *data++ = ((options->fqdn && dsi)? 1 : 0) + (dsi ? 1 : 0) + (((options->flags & OPTION_ANNOUNCESSH) && options->fqdn && dsi)? 1 : 0); /* ip address */ @@ -271,23 +302,6 @@ static size_t status_netaddress(char *data, int *servoffset, } } -#ifndef NO_DDP - if (asp) { - const struct sockaddr_at *ddpaddr = atp_sockaddr(asp->asp_atp); - - /* ddp address */ - *data++ = 6; - *data++ = 0x03; /* ddp address */ - memcpy(data, &ddpaddr->sat_addr.s_net, sizeof(ddpaddr->sat_addr.s_net)); - data += sizeof(ddpaddr->sat_addr.s_net); - memcpy(data, &ddpaddr->sat_addr.s_node, - sizeof(ddpaddr->sat_addr.s_node)); - data += sizeof(ddpaddr->sat_addr.s_node); - memcpy(data, &ddpaddr->sat_port, sizeof(ddpaddr->sat_port)); - data += sizeof(ddpaddr->sat_port); - } -#endif /* ! NO_DDP */ - /* calculate/store Directory Services Names offset */ offset = htons(data - begin); *servoffset += sizeof(offset); @@ -297,54 +311,37 @@ static size_t status_netaddress(char *data, int *servoffset, return (data - begin); } -static size_t status_directorynames(char *data, int *diroffset, - const DSI *dsi _U_, - const struct afp_options *options) + +/** + * DirectoryNamesCount offset: uint16_t + * ... + * DirectoryNamesCount: uint8_t + * DirectoryNames: list of UTF-8 Pascal strings (uint8_t + char[1,255]) + */ +static size_t status_directorynames(char *data, + int *diroffset, + const DSI *dsi _U_, + const struct afp_options *options) { char *begin = data; - u_int16_t offset; - memcpy(&offset, data + *diroffset, sizeof(offset)); + uint16_t offset; + + memcpy(&offset, begin + *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? */ - size_t len; - char *p = strchr( options->fqdn, ':' ); - if (p) - *p = '\0'; - len = strlen( options->k5service ) - + strlen( options->fqdn ) - + strlen( options->k5realm ); - len+=2; /* '/' and '@' */ - if ( len > 255 || len+2 > maxstatuslen - offset) { - *data++ = 0; - LOG ( log_error, logtype_afpd, "status: could not set directory service list, no more room"); - } - else { - *data++ = 1; /* DirectoryNamesCount */ - *data++ = len; - snprintf( data, len + 1, "%s/%s@%s", options->k5service, - options->fqdn, options->k5realm ); - data += len; - if (p) - *p = ':'; - } + if (!uam_gss_enabled() || !options->k5principal) { + *data = 0; + data++; } else { - *data++ = 0; + memcpy(data, options->k5principal, options->k5principal_buflen); + data += options->k5principal_buflen; } /* Calculate and store offset for UTF8ServerName */ - *diroffset += sizeof(u_int16_t); + *diroffset += sizeof(uint16_t); offset = htons(data - begin); - memcpy(begin + *diroffset, &offset, sizeof(u_int16_t)); + memcpy(begin + *diroffset, &offset, sizeof(uint16_t)); /* return length of buffer */ return (data - begin); @@ -354,44 +351,35 @@ static size_t status_utf8servername(char *data, int *nameoffset, const DSI *dsi _U_, const struct afp_options *options) { - char *Obj, *Type, *Zone; - u_int16_t namelen; + uint16_t namelen; size_t len; char *begin = data; - u_int16_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. - */ - - /* extract the obj part of the server */ - Obj = (char *) (options->server ? options->server : options->hostname); - nbp_name(options->server ? options->server : options->hostname, &Obj, &Type, &Zone); + LOG(log_info, logtype_afpd, "servername: %s", 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)); + /* set offset to 0 */ + memset(begin + *nameoffset, 0, sizeof(offset)); data = begin + offset; - } - else { + } else { namelen = htons(len); memcpy( data, &namelen, sizeof(namelen)); data += sizeof(namelen); data += len; offset = htons(offset); - memcpy(begin + *nameoffset, &offset, sizeof(u_int16_t)); + memcpy(begin + *nameoffset, &offset, sizeof(uint16_t)); } /* return length of buffer */ @@ -405,7 +393,7 @@ static void status_icon(char *data, const unsigned char *icondata, { char *start = data; char *sigdata = data + sigoffset; - u_int16_t ret, status; + uint16_t ret, status; memcpy(&status, start + AFPSTATUS_ICONOFF, sizeof(status)); if ( icondata == NULL ) { @@ -425,44 +413,27 @@ static void status_icon(char *data, const unsigned char *icondata, /* --------------------- */ -void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, - const struct afp_options *options) +void status_init(AFPObj *obj, DSI *dsi) { - ASP asp; - DSI *dsi; - char *status = NULL; + char *status = dsi->status; size_t statuslen; - int c, sigoff, ipok; - - if (!(aspconfig || dsiconfig) || !options) - return; - - if (aspconfig) { - status = aspconfig->status; - maxstatuslen=sizeof(aspconfig->status); - asp = aspconfig->obj.handle; - } else - asp = NULL; - - ipok = 0; - if (dsiconfig) { - status = dsiconfig->status; - maxstatuslen=sizeof(dsiconfig->status); - dsi = dsiconfig->obj.handle; - if (dsi->server.ss_family == AF_INET) { /* IPv4 */ - const struct sockaddr_in *sa4 = (struct sockaddr_in *)&dsi->server; - ipok = sa4->sin_addr.s_addr ? 1 : 0; - } else { /* IPv6 */ - const struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&dsi->server; - for (int i=0; i<16; i++) { - if (sa6->sin6_addr.s6_addr[i]) { - ipok = 1; - break; - } + int c, sigoff, ipok = 0; + const struct afp_options *options = &obj->options; + + maxstatuslen = sizeof(dsi->status); + + if (dsi->server.ss_family == AF_INET) { /* IPv4 */ + const struct sockaddr_in *sa4 = (struct sockaddr_in *)&dsi->server; + ipok = sa4->sin_addr.s_addr ? 1 : 0; + } else { /* IPv6 */ + const struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&dsi->server; + for (int i=0; i<16; i++) { + if (sa6->sin6_addr.s6_addr[i]) { + ipok = 1; + break; } } - } else - dsi = NULL; + } /* * These routines must be called in order -- earlier calls @@ -485,26 +456,22 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, */ status_flags(status, - options->server_notif, + options->flags & OPTION_SERVERNOTIF, (options->fqdn || ipok), options->passwdbits, - (options->k5service && options->k5realm && options->fqdn), + 1, options->flags); /* returns offset to signature offset */ - c = status_server(status, options->server ? options->server : - options->hostname, options); + c = status_server(status, options->hostname, options); status_machine(status); - status_versions(status, asp, dsi); + 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 */ - status_netaddress(status, &c, asp, dsi, options); + status_netaddress(status, &c, dsi, options); /* c now contains the offset where the Directory Names Count offset lives */ statuslen = status_directorynames(status, &c, dsi, options); @@ -513,24 +480,8 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, if ( statuslen < maxstatuslen) statuslen = status_utf8servername(status, &c, dsi, options); -#ifndef NO_DDP - if (aspconfig) { - if (dsiconfig) /* status is dsiconfig->status */ - memcpy(aspconfig->status, status, statuslen); - asp_setstatus(asp, status, statuslen); - aspconfig->signature = status + sigoff; - aspconfig->statuslen = statuslen; - } -#endif /* ! NO_DDP */ - - if (dsiconfig) { - if ((options->flags & OPTION_CUSTOMICON) == 0) { - status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0); - } - dsi_setstatus(dsi, status, statuslen); - dsiconfig->signature = status + sigoff; - dsiconfig->statuslen = statuslen; - } + dsi->signature = status + sigoff; + dsi->statuslen = statuslen; } /* set_signature() */ @@ -539,52 +490,39 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, /* 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->server ? options->server : options->hostname); - if (strcmp(options->signatureopt, "auto") == 0) { + server_tmp = options->hostname; + 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: @@ -679,7 +617,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 afpd.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) { @@ -695,8 +633,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], @@ -712,9 +649,8 @@ server_signature_done: /* this is the same as asp/dsi_getstatus */ int afp_getsrvrinfo(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { - AFPConfig *config = obj->config; + memcpy(rbuf, obj->dsi->status, obj->dsi->statuslen); + *rbuflen = obj->dsi->statuslen; - memcpy(rbuf, config->status, config->statuslen); - *rbuflen = config->statuslen; return AFP_OK; }