On Tue, Aug 19, 2014 at 01:59:42AM +0200, Alexander Bluhm wrote: > I will split this diff into smaller parts to make review and > discussion easier.
Rename priv_gethostserv() to priv_getaddrinfo() as this is what the function does. Change the return code semantics to match getaddrinfo(3). ok? bluhm Index: usr.sbin/syslogd/privsep.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v retrieving revision 1.36 diff -u -p -u -p -r1.36 privsep.c --- usr.sbin/syslogd/privsep.c 19 Aug 2014 00:53:01 -0000 1.36 +++ usr.sbin/syslogd/privsep.c 19 Aug 2014 21:06:35 -0000 @@ -67,7 +67,7 @@ enum cmd_types { PRIV_OPEN_UTMP, /* open utmp for reading only */ PRIV_OPEN_CONFIG, /* open config file for reading only */ PRIV_CONFIG_MODIFIED, /* check if config file has been modified */ - PRIV_GETHOSTSERV, /* resolve host/service names */ + PRIV_GETADDRINFO, /* resolve host/service names */ PRIV_GETHOSTBYADDR, /* resolve numeric address into hostname */ PRIV_DONE_CONFIG_PARSE /* signal that the initial config parse is done */ }; @@ -289,17 +289,19 @@ priv_init(char *conf, int numeric, int l increase_state(STATE_RUNNING); break; - case PRIV_GETHOSTSERV: - dprintf("[priv]: msg PRIV_GETHOSTSERV received\n"); + case PRIV_GETADDRINFO: + dprintf("[priv]: msg PRIV_GETADDRINFO received\n"); /* Expecting: len, hostname, len, servname */ must_read(socks[0], &hostname_len, sizeof(size_t)); - if (hostname_len == 0 || hostname_len > sizeof(hostname)) + if (hostname_len == 0 || + hostname_len > sizeof(hostname)) _exit(1); must_read(socks[0], &hostname, hostname_len); hostname[hostname_len - 1] = '\0'; must_read(socks[0], &servname_len, sizeof(size_t)); - if (servname_len == 0 || servname_len > sizeof(servname)) + if (servname_len == 0 || + servname_len > sizeof(servname)) _exit(1); must_read(socks[0], &servname, servname_len); servname[servname_len - 1] = '\0'; @@ -657,7 +659,7 @@ priv_config_parse_done(void) /* Name/service to address translation. Response is placed into addr, and * the length is returned (zero on error) */ int -priv_gethostserv(char *host, char *serv, struct sockaddr *addr, +priv_getaddrinfo(char *host, char *serv, struct sockaddr *addr, size_t addr_len) { char hostcpy[MAXHOSTNAMELEN], servcpy[MAXHOSTNAMELEN]; @@ -674,7 +676,7 @@ priv_gethostserv(char *host, char *serv, errx(1, "%s: overflow attempt in servname", __func__); servname_len = strlen(servcpy) + 1; - cmd = PRIV_GETHOSTSERV; + cmd = PRIV_GETADDRINFO; must_write(priv_fd, &cmd, sizeof(int)); must_write(priv_fd, &hostname_len, sizeof(size_t)); must_write(priv_fd, hostcpy, hostname_len); @@ -686,7 +688,7 @@ priv_gethostserv(char *host, char *serv, /* Check there was no error (indicated by a return of 0) */ if (!ret_len) - return 0; + return (-1); /* Make sure we aren't overflowing the passed in buffer */ if (addr_len < ret_len) @@ -696,7 +698,7 @@ priv_gethostserv(char *host, char *serv, memset(addr, '\0', addr_len); must_read(priv_fd, addr, ret_len); - return ret_len; + return (0); } /* Reverse address resolution; response is placed into res, and length of Index: usr.sbin/syslogd/syslogd.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v retrieving revision 1.112 diff -u -p -u -p -r1.112 syslogd.c --- usr.sbin/syslogd/syslogd.c 19 Aug 2014 00:24:00 -0000 1.112 +++ usr.sbin/syslogd/syslogd.c 19 Aug 2014 21:09:15 -0000 @@ -1427,7 +1427,7 @@ find_dup(struct filed *f) struct filed * cfline(char *line, char *prog) { - int i, pri, addr_len; + int i, pri; size_t rb_len; char *bp, *p, *q, *cp; char buf[MAXLINE], ebuf[100]; @@ -1538,11 +1538,10 @@ cfline(char *line, char *prog) logerror(ebuf); break; } - addr_len = priv_gethostserv(f->f_un.f_forw.f_hname, + if (priv_getaddrinfo(f->f_un.f_forw.f_hname, cp == NULL ? "syslog" : cp, - (struct sockaddr*)&f->f_un.f_forw.f_addr, - sizeof(f->f_un.f_forw.f_addr)); - if (addr_len < 1) { + (struct sockaddr *)&f->f_un.f_forw.f_addr, + sizeof(f->f_un.f_forw.f_addr)) != 0) { snprintf(ebuf, sizeof(ebuf), "bad hostname \"%s\"", p); logerror(ebuf); break; Index: usr.sbin/syslogd/syslogd.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.h,v retrieving revision 1.8 diff -u -p -u -p -r1.8 syslogd.h --- usr.sbin/syslogd/syslogd.h 19 Aug 2013 06:09:23 -0000 1.8 +++ usr.sbin/syslogd/syslogd.h 19 Aug 2014 20:59:10 -0000 @@ -26,7 +26,7 @@ FILE *priv_open_utmp(void); FILE *priv_open_config(void); void priv_config_parse_done(void); int priv_config_modified(void); -int priv_gethostserv(char *, char *, struct sockaddr *, size_t); +int priv_getaddrinfo(char *, char *, struct sockaddr *, size_t); int priv_gethostbyaddr(char *, int, int, char *, size_t); /* Terminal message */