#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#if 0
static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: tftpd.c,v 1.28 2004/05/05 20:15:45 kleink Exp $");
#endif
#endif
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "tftp.h"
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <netdb.h>
#include <pwd.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "tftpsubs.h"
#define DEFAULTUSER "nobody"
#define TIMEOUT 5
int peer;
int rexmtval = TIMEOUT;
int maxtimeout = 5*TIMEOUT;
char buf[MAXPKTSIZE];
char ackbuf[PKTSIZE];
char oackbuf[PKTSIZE];
struct sockaddr_storage from;
int fromlen;
int debug;
int tftp_opt_tsize = 0;
int tftp_blksize = SEGSIZE;
int tftp_tsize = 0;
#define MAXDIRS 20
static struct dirlist {
char *name;
int len;
} dirs[MAXDIRS+1];
static int suppress_naks;
static int logging;
static int insecure=0;
static int secure;
static char *securedir;
struct formats;
static const char *errtomsg(int);
static void nak(int);
static void tftp(struct tftphdr *, int);
static void usage(void);
static char *verifyhost(struct sockaddr *);
void justquit(int);
int main(int, char **);
void recvfile(struct formats *, int, int);
void sendfile(struct formats *, int, int);
void timer(int);
static const char *opcode(int);
int validate_access(char **, int);
struct formats {
const char *f_mode;
int (*f_validate)(char **, int);
void (*f_send)(struct formats *, int, int);
void (*f_recv)(struct formats *, int, int);
int f_convert;
} formats[] = {
{ "netascii", validate_access, sendfile, recvfile, 1 },
{ "octet", validate_access, sendfile, recvfile, 0 },
{ 0 }
};
static void
usage(void)
{
syslog(LOG_ERR,
"Usage: %s [-diln] [-u user] [-g group] [-s directory] [directory ...]",
getprogname());
exit(1);
}
int
main(int argc, char *argv[])
{
struct sockaddr_storage me;
struct passwd *pwent;
struct group *grent;
struct tftphdr *tp;
char *tgtuser, *tgtgroup, *ep;
int n, ch, on, fd;
int len, soopt;
uid_t curuid, tgtuid;
gid_t curgid, tgtgid;
long nid;
n = 0;
fd = 0;
tzset();
openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_DAEMON);
tgtuser = DEFAULTUSER;
tgtgroup = NULL;
curuid = getuid();
curgid = getgid();
while ((ch = getopt(argc, argv, "dg:ilns:u:")) != -1)
switch (ch) {
case 'd':
debug++;
break;
case 'g':
tgtgroup = optarg;
break;
case 'i':
insecure = 1;
break;
case 'l':
logging = 1;
break;
case 'n':
suppress_naks = 1;
break;
case 's':
secure = 1;
securedir = optarg;
break;
case 'u':
tgtuser = optarg;
break;
default:
usage();
break;
}
if (optind < argc) {
struct dirlist *dirp;
for (dirp = dirs; optind < argc && dirp < &dirs[MAXDIRS];
optind++) {
if (argv[optind][0] == '/') {
dirp->name = argv[optind];
dirp->len = strlen(dirp->name);
dirp++;
}
}
}
if (*tgtuser == '\0' || (tgtgroup != NULL && *tgtgroup == '\0'))
usage();
nid = (strtol(tgtuser, &ep, 10));
if (*ep == '\0') {
if (nid > UID_MAX) {
syslog(LOG_ERR, "uid %ld is too large", nid);
exit(1);
}
pwent = getpwuid((uid_t)nid);
} else
pwent = getpwnam(tgtuser);
if (pwent == NULL) {
syslog(LOG_ERR, "unknown user `%s'", tgtuser);
exit(1);
}
tgtuid = pwent->pw_uid;
tgtgid = pwent->pw_gid;
if (tgtgroup != NULL) {
nid = (strtol(tgtgroup, &ep, 10));
if (*ep == '\0') {
if (nid > GID_MAX) {
syslog(LOG_ERR, "gid %ld is too large", nid);
exit(1);
}
grent = getgrgid((gid_t)nid);
} else
grent = getgrnam(tgtgroup);
if (grent != NULL)
tgtgid = grent->gr_gid;
else {
syslog(LOG_ERR, "unknown group `%s'", tgtgroup);
exit(1);
}
}
if (secure) {
if (chdir(securedir) < 0) {
syslog(LOG_ERR, "chdir %s: %m", securedir);
exit(1);
}
if (chroot(".")) {
syslog(LOG_ERR, "chroot: %m");
exit(1);
}
}
if (logging)
syslog(LOG_DEBUG, "running as user `%s' (%d), group `%s' (%d)",
tgtuser, tgtuid, tgtgroup ? tgtgroup : "(unspecified)",
tgtgid);
if (curgid != tgtgid) {
if (setgid(tgtgid)) {
syslog(LOG_ERR, "setgid to %d: %m", (int)tgtgid);
exit(1);
}
if (setgroups(0, NULL)) {
syslog(LOG_ERR, "setgroups: %m");
exit(1);
}
}
if (curuid != tgtuid) {
if (setuid(tgtuid)) {
syslog(LOG_ERR, "setuid to %d: %m", (int)tgtuid);
exit(1);
}
}
on = 1;
if (ioctl(fd, FIONBIO, &on) < 0) {
syslog(LOG_ERR, "ioctl(FIONBIO): %m");
exit(1);
}
fromlen = sizeof (from);
n = recvfrom(fd, buf, sizeof (buf), 0,
(struct sockaddr *)&from, &fromlen);
if (n < 0) {
syslog(LOG_ERR, "recvfrom: %m");
exit(1);
}
{
int pid;
int i, j;
for (i = 1; i < 20; i++) {
pid = fork();
if (pid < 0) {
sleep(i);
j = sizeof from;
i = recvfrom(fd, buf, sizeof (buf), 0,
(struct sockaddr *)&from, &j);
if (i > 0) {
n = i;
fromlen = j;
}
} else {
break;
}
}
if (pid < 0) {
syslog(LOG_ERR, "fork: %m");
exit(1);
} else if (pid != 0) {
exit(0);
}
}
len = sizeof(me);
if (getsockname(fd, (struct sockaddr *)&me, &len) == 0) {
switch (me.ss_family) {
case AF_INET:
((struct sockaddr_in *)&me)->sin_port = 0;
break;
case AF_INET6:
((struct sockaddr_in6 *)&me)->sin6_port = 0;
break;
default:
break;
}
} else {
memset(&me, 0, sizeof(me));
me.ss_family = from.ss_family;
me.ss_len = from.ss_len;
}
alarm(0);
close(fd);
close(1);
peer = socket(from.ss_family, SOCK_DGRAM, 0);
if (peer < 0) {
syslog(LOG_ERR, "socket: %m");
exit(1);
}
if (bind(peer, (struct sockaddr *)&me, me.ss_len) < 0) {
syslog(LOG_ERR, "bind: %m");
exit(1);
}
if (connect(peer, (struct sockaddr *)&from, from.ss_len) < 0) {
syslog(LOG_ERR, "connect: %m");
exit(1);
}
soopt = 65536;
if (setsockopt(peer, SOL_SOCKET, SO_SNDBUF, (void *) &soopt, sizeof(soopt)) < 0) {
syslog(LOG_ERR, "set SNDBUF: %m");
exit(1);
}
if (setsockopt(peer, SOL_SOCKET, SO_RCVBUF, (void *) &soopt, sizeof(soopt)) < 0) {
syslog(LOG_ERR, "set RCVBUF: %m");
exit(1);
}
tp = (struct tftphdr *)buf;
tp->th_opcode = ntohs(tp->th_opcode);
if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
tftp(tp, n);
exit(1);
}
static int
blk_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
int *ackl, int *ec)
{
unsigned long bsize;
char *endp;
int l;
errno = 0;
bsize = strtoul(val, &endp, 10);
if ((bsize == ULONG_MAX && errno == ERANGE) || *endp) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"illegal value %s for blksize option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
if (bsize < 8 || bsize > 65464) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"out of range value %s for blksize option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
tftp_blksize = bsize;
strcpy(ack + *ackl, "blksize");
*ackl += 8;
l = sprintf(ack + *ackl, "%lu", bsize);
*ackl += l + 1;
return 0;
}
static int
timeout_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
int *ackl, int *ec)
{
unsigned long tout;
char *endp;
int l;
errno = 0;
tout = strtoul(val, &endp, 10);
if ((tout == ULONG_MAX && errno == ERANGE) || *endp) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"illegal value %s for timeout option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
if (tout < 1 || tout > 255) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"out of range value %s for timeout option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
rexmtval = tout;
strcpy(ack + *ackl, "timeout");
*ackl += 8;
l = sprintf(ack + *ackl, "%lu", tout);
*ackl += l + 1;
if (rexmtval > 60) {
maxtimeout = rexmtval * 3;
} else {
maxtimeout = rexmtval * 5;
}
return 0;
}
static int
tsize_handler(struct tftphdr *tp, char *opt, char *val, char *ack,
int *ackl, int *ec)
{
unsigned long fsize;
char *endp;
errno = 0;
fsize = strtoul(val, &endp, 10);
if ((fsize == ULONG_MAX && errno == ERANGE) || *endp) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"illegal value %s for tsize option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
if (fsize > (unsigned long) 65535 * 65464) {
syslog(LOG_NOTICE, "%s: %s request for %s: "
"out of range value %s for tsize option",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
tp->th_stuff, val);
return 0;
}
tftp_opt_tsize = 1;
tftp_tsize = fsize;
return 0;
}
struct tftp_options {
char *o_name;
int (*o_handler)(struct tftphdr *, char *, char *, char *,
int *, int *);
} options[] = {
{ "blksize", blk_handler },
{ "timeout", timeout_handler },
{ "tsize", tsize_handler },
{ NULL, NULL }
};
static int
get_options(struct tftphdr *tp, char *cp, int size, char *ackb,
int *alen, int *err)
{
struct tftp_options *op;
char *option, *value, *endp;
int r, rv=0, ec=0;
endp = cp + size;
while (cp < endp) {
option = cp;
while (*cp && cp < endp) {
*cp = tolower(*cp);
cp++;
}
if (*cp) {
break;
}
cp++;
value = cp;
while (*cp && cp < endp) {
cp++;
}
if (*cp) {
break;
}
cp++;
for (op = options; op->o_name; op++) {
if (strcmp(op->o_name, option) == 0)
break;
}
if (op->o_name) {
r = op->o_handler(tp, option, value, ackb, alen, &ec);
if (r < 0) {
rv = -1;
break;
}
rv++;
}
}
if (rv < 0)
*err = ec;
return rv;
}
static void
tftp(struct tftphdr *tp, int size)
{
struct formats *pf;
char *cp;
char *filename, *mode;
int first, ecode, alen, etftp=0, r;
first = 1;
mode = NULL;
filename = cp = tp->th_stuff;
again:
while (cp < buf + size) {
if (*cp == '\0')
break;
cp++;
}
if (*cp != '\0') {
nak(EBADOP);
exit(1);
}
if (first) {
mode = ++cp;
first = 0;
goto again;
}
for (cp = mode; *cp; cp++)
if (isupper(*cp))
*cp = tolower(*cp);
for (pf = formats; pf->f_mode; pf++)
if (strcmp(pf->f_mode, mode) == 0)
break;
if (pf->f_mode == 0) {
nak(EBADOP);
exit(1);
}
size -= (++cp - (char *) tp);
if (size > 0 && *cp) {
alen = 2;
r = get_options(tp, cp, size, oackbuf, &alen, &ecode);
if (r > 0) {
etftp = 1;
} else if (r < 0) {
nak(ecode);
exit(1);
}
}
ecode = (*pf->f_validate)(&filename, tp->th_opcode);
if (logging) {
syslog(LOG_INFO, "%s: %s request for %s: %s",
verifyhost((struct sockaddr *)&from),
tp->th_opcode == WRQ ? "write" : "read",
filename, errtomsg(ecode));
}
if (ecode) {
if (suppress_naks && *filename != '/' && ecode == ENOTFOUND)
exit(0);
nak(ecode);
exit(1);
}
if (etftp) {
struct tftphdr *oack_h;
if (tftp_opt_tsize) {
int l;
strcpy(oackbuf + alen, "tsize");
alen += 6;
l = sprintf(oackbuf + alen, "%u", tftp_tsize);
alen += l + 1;
}
oack_h = (struct tftphdr *) oackbuf;
oack_h->th_opcode = htons(OACK);
}
if (tp->th_opcode == WRQ)
(*pf->f_recv)(pf, etftp, alen);
else
(*pf->f_send)(pf, etftp, alen);
exit(0);
}
FILE *file;
int
validate_access(char **filep, int mode)
{
struct stat stbuf;
struct dirlist *dirp;
static char pathname[MAXPATHLEN];
int fd;
char *filename;
#ifdef __APPLE__
static char resolved_path[PATH_MAX+1];
bzero(resolved_path,PATH_MAX+1);
if(insecure) {
filename = *filep;
} else {
if (realpath(*filep, resolved_path)==NULL) {
return (EACCESS);
}
filename = resolved_path;
}
#else
filename = *filep;
#endif
if (strstr(filename, "/../"))
return (EACCESS);
if (*filename == '/') {
for (dirp = dirs; dirp->name != NULL; dirp++) {
if (dirp->len == 1 ||
(!strncmp(filename, dirp->name, dirp->len) &&
filename[dirp->len] == '/'))
break;
}
if (dirp->name == NULL && dirp != dirs)
return (EACCESS);
if (stat(filename, &stbuf) < 0)
return (errno == ENOENT ? ENOTFOUND : EACCESS);
if (!S_ISREG(stbuf.st_mode))
return (ENOTFOUND);
if (mode == RRQ) {
if ((stbuf.st_mode & S_IROTH) == 0)
return (EACCESS);
} else {
if ((stbuf.st_mode & S_IWOTH) == 0)
return (EACCESS);
}
} else {
if (!strncmp(filename, "../", 3))
return (EACCESS);
if (dirs[0].name != NULL) {
for (dirp = dirs; dirp->name != NULL; dirp++) {
snprintf(pathname, sizeof pathname, "%s/%s",
dirp->name, filename);
if (stat(pathname, &stbuf) == 0 &&
(stbuf.st_mode & S_IFMT) == S_IFREG) {
break;
}
}
if (dirp->name == NULL)
return (ENOTFOUND);
if (mode == RRQ && !(stbuf.st_mode & S_IROTH))
return (EACCESS);
if (mode == WRQ && !(stbuf.st_mode & S_IWOTH))
return (EACCESS);
filename = pathname;
*filep = filename;
} else {
if (stat(filename, &stbuf) < 0)
return (errno == ENOENT ? ENOTFOUND : EACCESS);
if (!S_ISREG(stbuf.st_mode))
return (ENOTFOUND);
if (mode == RRQ) {
if ((stbuf.st_mode & S_IROTH) == 0)
return (EACCESS);
} else {
if ((stbuf.st_mode & S_IWOTH) == 0)
return (EACCESS);
}
*filep = filename;
}
}
if (tftp_opt_tsize && mode == RRQ)
tftp_tsize = (unsigned long) stbuf.st_size;
fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY | O_TRUNC);
if (fd < 0)
return (errno + 100);
file = fdopen(fd, (mode == RRQ)? "r":"w");
if (file == NULL) {
close(fd);
return (errno + 100);
}
return (0);
}
int timeout;
jmp_buf timeoutbuf;
void
timer(int dummy)
{
timeout += rexmtval;
if (timeout >= maxtimeout)
exit(1);
longjmp(timeoutbuf, 1);
}
static const char *
opcode(int code)
{
static char buf[64];
switch (code) {
case RRQ:
return "RRQ";
case WRQ:
return "WRQ";
case DATA:
return "DATA";
case ACK:
return "ACK";
case ERROR:
return "ERROR";
case OACK:
return "OACK";
default:
(void)snprintf(buf, sizeof(buf), "*code %d*", code);
return buf;
}
}
void
sendfile(struct formats *pf, int etftp, int acklength)
{
volatile unsigned int block;
struct tftphdr *dp;
struct tftphdr *ap;
int size, n;
signal(SIGALRM, timer);
ap = (struct tftphdr *)ackbuf;
if (etftp) {
dp = (struct tftphdr *)oackbuf;
size = acklength - 4;
block = 0;
} else {
dp = r_init();
size = 0;
block = 1;
}
do {
if (block > 0) {
size = readit(file, &dp, tftp_blksize, pf->f_convert);
if (size < 0) {
nak(errno + 100);
goto abort;
}
dp->th_opcode = htons((u_short)DATA);
dp->th_block = htons((u_short)block);
}
timeout = 0;
(void)setjmp(timeoutbuf);
send_data:
if (!etftp && debug)
syslog(LOG_DEBUG, "Send DATA %u", block);
if ((n = send(peer, dp, size + 4, 0)) != size + 4) {
syslog(LOG_ERR, "tftpd: write: %m");
goto abort;
}
if (block)
read_ahead(file, tftp_blksize, pf->f_convert);
for ( ; ; ) {
alarm(rexmtval);
n = recv(peer, ackbuf, tftp_blksize, 0);
alarm(0);
if (n < 0) {
syslog(LOG_ERR, "tftpd: read: %m");
goto abort;
}
ap->th_opcode = ntohs((u_short)ap->th_opcode);
ap->th_block = ntohs((u_short)ap->th_block);
switch (ap->th_opcode) {
case ERROR:
goto abort;
case ACK:
if (ap->th_block == 0) {
etftp = 0;
acklength = 0;
dp = r_init();
goto done;
}
if (ap->th_block == block)
goto done;
if (debug)
syslog(LOG_DEBUG, "Resync ACK %u != %u",
(unsigned int)ap->th_block, block);
(void) synchnet(peer, tftp_blksize);
if (ap->th_block == (block -1))
goto send_data;
default:
syslog(LOG_INFO, "Received %s in sendfile\n",
opcode(dp->th_opcode));
}
}
done:
if (debug)
syslog(LOG_DEBUG, "Received ACK for block %u", block);
block++;
} while (size == tftp_blksize || block == 1);
abort:
(void) fclose(file);
}
void
justquit(int dummy)
{
exit(0);
}
void
recvfile(struct formats *pf, int etftp, int acklength)
{
volatile unsigned int block;
struct tftphdr *dp;
struct tftphdr *ap;
int n, size;
signal(SIGALRM, timer);
dp = w_init();
ap = (struct tftphdr *)oackbuf;
block = 0;
do {
timeout = 0;
if (etftp == 0) {
ap = (struct tftphdr *)ackbuf;
ap->th_opcode = htons((u_short)ACK);
ap->th_block = htons((u_short)block);
acklength = 4;
}
if (debug)
syslog(LOG_DEBUG, "Sending ACK for block %u\n", block);
block++;
(void) setjmp(timeoutbuf);
send_ack:
if (send(peer, ap, acklength, 0) != acklength) {
syslog(LOG_ERR, "tftpd: write: %m");
goto abort;
}
write_behind(file, pf->f_convert);
for ( ; ; ) {
alarm(rexmtval);
n = recv(peer, dp, tftp_blksize + 4, 0);
alarm(0);
if (n < 0) {
syslog(LOG_ERR, "tftpd: read: %m");
goto abort;
}
etftp = 0;
dp->th_opcode = ntohs((u_short)dp->th_opcode);
dp->th_block = ntohs((u_short)dp->th_block);
if (debug)
syslog(LOG_DEBUG, "Received %s for block %u",
opcode(dp->th_opcode),
(unsigned int)dp->th_block);
switch (dp->th_opcode) {
case ERROR:
goto abort;
case DATA:
if (dp->th_block == block)
goto done;
if (debug)
syslog(LOG_DEBUG, "Resync %u != %u",
(unsigned int)dp->th_block, block);
(void) synchnet(peer, tftp_blksize);
if (dp->th_block == (block-1))
goto send_ack;
break;
default:
syslog(LOG_INFO, "Received %s in recvfile\n",
opcode(dp->th_opcode));
break;
}
}
done:
if (debug)
syslog(LOG_DEBUG, "Got block %u", block);
size = writeit(file, &dp, n - 4, pf->f_convert);
if (size != (n-4)) {
if (size < 0) nak(errno + 100);
else nak(ENOSPACE);
goto abort;
}
} while (size == tftp_blksize);
write_behind(file, pf->f_convert);
(void) fclose(file);
ap->th_opcode = htons((u_short)ACK);
ap->th_block = htons((u_short)(block));
if (debug)
syslog(LOG_DEBUG, "Send final ACK %u", block);
(void) send(peer, ackbuf, 4, 0);
signal(SIGALRM, justquit);
alarm(rexmtval);
n = recv(peer, buf, sizeof (buf), 0);
alarm(0);
if (n >= 4 &&
dp->th_opcode == DATA &&
block == dp->th_block) {
(void) send(peer, ackbuf, 4, 0);
}
abort:
return;
}
const struct errmsg {
int e_code;
const char *e_msg;
} errmsgs[] = {
{ EUNDEF, "Undefined error code" },
{ ENOTFOUND, "File not found" },
{ EACCESS, "Access violation" },
{ ENOSPACE, "Disk full or allocation exceeded" },
{ EBADOP, "Illegal TFTP operation" },
{ EBADID, "Unknown transfer ID" },
{ EEXISTS, "File already exists" },
{ ENOUSER, "No such user" },
{ EOPTNEG, "Option negotiation failed" },
{ -1, 0 }
};
static const char *
errtomsg(int error)
{
static char ebuf[20];
const struct errmsg *pe;
if (error == 0)
return ("success");
for (pe = errmsgs; pe->e_code >= 0; pe++)
if (pe->e_code == error)
return (pe->e_msg);
snprintf(ebuf, sizeof(ebuf), "error %d", error);
return (ebuf);
}
static void
nak(int error)
{
const struct errmsg *pe;
struct tftphdr *tp;
int length;
size_t msglen;
tp = (struct tftphdr *)buf;
tp->th_opcode = htons((u_short)ERROR);
msglen = sizeof(buf) - (&tp->th_msg[0] - buf);
for (pe = errmsgs; pe->e_code >= 0; pe++)
if (pe->e_code == error)
break;
if (pe->e_code < 0) {
tp->th_code = EUNDEF;
strlcpy(tp->th_msg, strerror(error - 100), msglen);
} else {
tp->th_code = htons((u_short)error);
strlcpy(tp->th_msg, pe->e_msg, msglen);
}
if (debug)
syslog(LOG_DEBUG, "Send NACK %s", tp->th_msg);
length = strlen(tp->th_msg);
msglen = &tp->th_msg[length + 1] - buf;
if (send(peer, buf, msglen, 0) != msglen)
syslog(LOG_ERR, "nak: %m");
}
static char *
verifyhost(struct sockaddr *fromp)
{
static char hbuf[MAXHOSTNAMELEN];
if (getnameinfo(fromp, fromp->sa_len, hbuf, sizeof(hbuf), NULL, 0, 0))
strlcpy(hbuf, "?", sizeof(hbuf));
return (hbuf);
}