X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fstatus.c;h=4aa134e9f78c15c55cb87a68f1a346bb5f18ef62;hb=df7560dfdb12b06090dc4b2c6e88d0858930b591;hp=24b6b8077a9223203a4fe4e78e817ee29113aa61;hpb=313b5f94348618d65523c1d8bde1fba9988f040a;p=netatalk.git diff --git a/etc/afpd/status.c b/etc/afpd/status.c index 24b6b807..4aa134e9 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -33,8 +33,8 @@ #include #include #include +#include -#include "globals.h" /* includes */ #include "status.h" #include "afp_config.h" #include "icon.h" @@ -74,7 +74,7 @@ static int status_server(char *data, const char *server, const struct afp_option char *start = data; char *Obj, *Type, *Zone; char buf[32]; - u_int16_t status; + uint16_t status; size_t len; /* make room for all offsets before server name */ @@ -119,20 +119,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[64]; + char buf[AFPSTATUS_MACHLEN+1]; memcpy(&status, start + AFPSTATUS_MACHOFF, sizeof(status)); data += ntohs( status ); - // len = strlen( machine ); - len = snprintf(buf, 64, 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; @@ -142,11 +154,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,7 +185,7 @@ static size_t status_netaddress(char *data, int *servoffset, const struct afp_options *options) { char *begin; - u_int16_t offset; + uint16_t offset; size_t addresses_len = 0; begin = data; @@ -281,7 +293,7 @@ static size_t status_directorynames(char *data, int *diroffset, const struct afp_options *options) { char *begin = data; - u_int16_t offset; + uint16_t offset; memcpy(&offset, data + *diroffset, sizeof(offset)); offset = ntohs(offset); data += offset; @@ -321,9 +333,9 @@ static size_t status_directorynames(char *data, int *diroffset, } /* 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); @@ -334,10 +346,10 @@ static size_t status_utf8servername(char *data, int *nameoffset, 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, status; memcpy(&offset, data + *nameoffset, sizeof(offset)); offset = ntohs(offset); @@ -367,7 +379,7 @@ static size_t status_utf8servername(char *data, int *nameoffset, 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 */ @@ -381,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 ) { @@ -416,7 +428,7 @@ void status_init(AFPConfig *dsiconfig, if (dsiconfig) { status = dsiconfig->status; maxstatuslen=sizeof(dsiconfig->status); - dsi = dsiconfig->obj.handle; + dsi = dsiconfig->obj.dsi; 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;