X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fstatus.c;h=0782228ad952c3b99c31274cea6abacbf44489b0;hb=b0bcb8f6b0571592a50ce039882c9319e012a270;hp=bcdca483f38c5d5e3b6ca54fe3e4a533d7c62907;hpb=89f20b55b2278c29553472559bbfb060ef711ca2;p=netatalk.git diff --git a/etc/afpd/status.c b/etc/afpd/status.c index bcdca483..0782228a 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -28,15 +28,13 @@ #endif /* BSD4_4 */ #endif -#include -#include +#include + #include -#include -#include -#include #include +#include +#include -#include "globals.h" /* includes */ #include "status.h" #include "afp_config.h" #include "icon.h" @@ -46,32 +44,26 @@ 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) { - u_int16_t status; + uint16_t status; + + status = AFPSRVRINFO_COPY + | AFPSRVRINFO_SRVSIGNATURE + | AFPSRVRINFO_SRVMSGS + | AFPSRVRINFO_FASTBOZO + | AFPSRVRINFO_SRVRDIR + | AFPSRVRINFO_SRVUTF8 + | AFPSRVRINFO_EXTSLEEP; - status = AFPSRVRINFO_COPY; if (passwdbits & PASSWD_SET) /* some uams may not allow this. */ status |= AFPSRVRINFO_PASSWD; if (passwdbits & PASSWD_NOSAVE) status |= AFPSRVRINFO_NOSAVEPASSWD; - status |= AFPSRVRINFO_SRVSIGNATURE; - /* only advertise tcp/ip if we have a valid address */ - if (ipok) + if (ipok) /* only advertise tcp/ip if we have a valid address */ status |= AFPSRVRINFO_TCPIP; - status |= AFPSRVRINFO_SRVMSGS; - /* Allow the user to decide if we should support server notifications. - * With this turned off, the clients will poll for directory changes every - * 10 seconds. This might be too costly to network resources, so make - * this an optional thing. Default will be to _not_ support server - * notifications. */ - if (notif) { + if (notif) /* Default is yes */ status |= AFPSRVRINFO_SRVNOTIFY; - } - status |= AFPSRVRINFO_FASTBOZO; - status |= AFPSRVRINFO_SRVRDIR; /* AFP 3.1 specs says we need to specify this, but may set the count to 0 */ - /* We don't set the UTF8 name flag here, we don't know whether we have enough space ... */ - - if (flags & OPTION_UUID) /* 05122008 FIXME: can we set AFPSRVRINFO_UUID here ? see AFPSRVRINFO_SRVRDIR*/ - status |= AFPSRVRINFO_UUID; + if (flags & OPTION_UUID) + status |= AFPSRVRINFO_UUID; status = htons(status); memcpy(data + AFPSTATUS_FLAGOFF, &status, sizeof(status)); @@ -90,14 +82,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 ); @@ -133,15 +124,19 @@ static void status_machine(char *data) #ifdef AFS const char *machine = "afs"; #else /* !AFS */ - const char *machine = "Netatalk"; + const char *machine = "Netatalk %s"; #endif /* AFS */ + char buf[64]; memcpy(&status, start + AFPSTATUS_MACHOFF, sizeof(status)); data += ntohs( status ); - len = strlen( machine ); + + // len = strlen( machine ); + len = snprintf(buf, 64, machine, VERSION); *data++ = len; - memcpy( data, machine, len ); + memcpy( data, buf, len ); data += len; + status = htons(data - start); memcpy(start + AFPSTATUS_VERSOFF, &status, sizeof(status)); } @@ -174,7 +169,7 @@ 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; @@ -198,7 +193,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 */ @@ -272,23 +267,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); @@ -375,31 +353,21 @@ static size_t status_utf8servername(char *data, int *nameoffset, /* 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); - 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"); + options->unixcharset, CH_UTF8_MAC, + Obj, -1, data+sizeof(namelen), maxstatuslen-offset )) ) { + 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)); - - /* Now set the flag ... */ - memcpy(&status, begin + AFPSTATUS_FLAGOFF, sizeof(status)); - status = ntohs(status); - status |= AFPSRVRINFO_SRVUTF8; - status = htons(status); - memcpy(begin + AFPSTATUS_FLAGOFF, &status, sizeof(status)); } /* return length of buffer */ @@ -433,24 +401,16 @@ static void status_icon(char *data, const unsigned char *icondata, /* --------------------- */ -void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, +void status_init(AFPConfig *dsiconfig, const struct afp_options *options) { - ASP asp; DSI *dsi; char *status = NULL; size_t statuslen; int c, sigoff, ipok; - if (!(aspconfig || dsiconfig) || !options) + if (!dsiconfig || !options) return; - - if (aspconfig) { - status = aspconfig->status; - maxstatuslen=sizeof(aspconfig->status); - asp = aspconfig->obj.handle; - } else - asp = NULL; ipok = 0; if (dsiconfig) { @@ -502,7 +462,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, c = status_server(status, options->server ? options->server : 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); @@ -512,7 +472,7 @@ void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig, 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); @@ -521,16 +481,6 @@ 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); @@ -556,7 +506,7 @@ void set_signature(struct afp_options *options) { char *servername_conf; int header = 0; char buf[1024], *p; - FILE *fp, *randomp; + FILE *fp = NULL, *randomp; size_t len; char *server_tmp; @@ -661,12 +611,12 @@ server_signature_auto: } } else { /* conf file don't exist */ if (( fd = creat(options->sigconffile, 0644 )) < 0 ) { - LOG(log_error, logtype_atalkd, "ERROR: Cannot create %s (%s). Using one-time signature.", + LOG(log_error, logtype_afpd, "ERROR: Cannot create %s (%s). Using one-time signature.", options->sigconffile, strerror(errno)); goto server_signature_random; } if (( fp = fdopen( fd, "w" )) == NULL ) { - LOG(log_error, logtype_atalkd, "ERROR: Cannot fdopen %s (%s). Using one-time signature.", + LOG(log_error, logtype_afpd, "ERROR: Cannot fdopen %s (%s). Using one-time signature.", options->sigconffile, strerror(errno)); close(fd); goto server_signature_random; @@ -678,41 +628,9 @@ server_signature_auto: server_signature_random: /* generate signature from random number */ - if ((randomp = fopen("/dev/urandom", "r")) != NULL) { /* generate from /dev/urandom */ - for (i=0 ; i<16 ; i++) { - (options->signature)[i] = fgetc(randomp); - } - LOG(log_note, logtype_afpd, - "generate %s's signature %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X from /dev/urandom", - server_tmp, - (options->signature)[ 0], (options->signature)[ 1], - (options->signature)[ 2], (options->signature)[ 3], - (options->signature)[ 4], (options->signature)[ 5], - (options->signature)[ 6], (options->signature)[ 7], - (options->signature)[ 8], (options->signature)[ 9], - (options->signature)[10], (options->signature)[11], - (options->signature)[12], (options->signature)[13], - (options->signature)[14], (options->signature)[15]); - - } else { /* genarate from random() because cannot open /dev/urandom */ - srandom((unsigned int)time(NULL) + (unsigned int)options + (unsigned int)server_tmp); - for (i=0 ; i<16 ; i++) { - (options->signature)[i] = random() & 0xFF; - } - LOG(log_note, logtype_afpd, - "generate %s's signature %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X from random()", - server_tmp, - (options->signature)[ 0], (options->signature)[ 1], - (options->signature)[ 2], (options->signature)[ 3], - (options->signature)[ 4], (options->signature)[ 5], - (options->signature)[ 6], (options->signature)[ 7], - (options->signature)[ 8], (options->signature)[ 9], - (options->signature)[10], (options->signature)[11], - (options->signature)[12], (options->signature)[13], - (options->signature)[14], (options->signature)[15]); - } + randombytes(options->signature, 16); - if (fp && header) { /* conf file is created or size=0 */ + if (fp && header) { /* conf file is created or size=0 */ fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n"); fprintf(fp, "# This file is auto-generated by afpd.\n"); fprintf(fp, "# \n");