From 2fa726a750f1cc443be01125b60e6d92be2d623f Mon Sep 17 00:00:00 2001 From: bluhm Date: Wed, 20 Aug 2014 19:16:27 +0000 Subject: [PATCH] Rename priv_gethostserv() to priv_getaddrinfo() as this is what the function does. Change the return code semantics to match getaddrinfo(3). OK deraadt@ --- usr.sbin/syslogd/privsep.c | 22 ++++++++++++---------- usr.sbin/syslogd/syslogd.c | 11 +++++------ usr.sbin/syslogd/syslogd.h | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/usr.sbin/syslogd/privsep.c b/usr.sbin/syslogd/privsep.c index 75bbefeb2e6..8144e10ba1f 100644 --- a/usr.sbin/syslogd/privsep.c +++ b/usr.sbin/syslogd/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.36 2014/08/19 00:53:01 bluhm Exp $ */ +/* $OpenBSD: privsep.c,v 1.37 2014/08/20 19:16:27 bluhm Exp $ */ /* * Copyright (c) 2003 Anil Madhavapeddy @@ -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 lockfd, int nullfd, char *argv[]) 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, struct sockaddr *addr, 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, struct sockaddr *addr, /* 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, struct sockaddr *addr, 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 diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index fa6f10b25de..9452ff2a180 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.112 2014/08/19 00:24:00 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.113 2014/08/20 19:16:27 bluhm Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -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; diff --git a/usr.sbin/syslogd/syslogd.h b/usr.sbin/syslogd/syslogd.h index ee8b4f0a8f8..62495b54cdd 100644 --- a/usr.sbin/syslogd/syslogd.h +++ b/usr.sbin/syslogd/syslogd.h @@ -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 */ -- 2.20.1