Also, no need to change umask now that we use mkstemp(3).
-/* $OpenBSD: activate.c,v 1.2 1996/06/23 14:31:30 deraadt Exp $ */
+/* $OpenBSD: activate.c,v 1.3 1997/03/23 03:52:13 millert Exp $ */
/* $NetBSD: activate.c,v 1.5 1995/04/23 10:33:18 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
* SUCH DAMAGE.
*
* from: Id: activate.c,v 1.2 1992/05/27 07:09:27 jsp Exp
- * @(#)activate.c 8.2 (Berkeley) 3/27/94
+ * @(#)activate.c 8.3 (Berkeley) 4/28/95
*/
#include <stdio.h>
* Scan the providers list and call the
* appropriate function.
*/
-static int activate_argv(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
+static int
+activate_argv(pcr, key, v, so, fdp)
+ struct portal_cred *pcr;
+ char *key;
+ char **v;
+ int so;
+ int *fdp;
{
provider *pr;
return (ENOENT);
}
-static int get_request(so, pcr, key, klen)
-int so;
-struct portal_cred *pcr;
-char *key;
-int klen;
+static int
+get_request(so, pcr, key, klen)
+ int so;
+ struct portal_cred *pcr;
+ char *key;
+ int klen;
{
struct iovec iov[2];
struct msghdr msg;
int n;
- iov[0].iov_base = (caddr_t) pcr;
+ iov[0].iov_base = (caddr_t)pcr;
iov[0].iov_len = sizeof(*pcr);
iov[1].iov_base = key;
iov[1].iov_len = klen;
- memset(&msg, 0, sizeof(msg));
+ (void)memset(&msg, 0, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = 2;
return (0);
}
-static void send_reply(so, fd, error)
-int so;
-int fd;
-int error;
+static void
+send_reply(so, fd, error)
+ int so;
+ int fd;
+ int error;
{
int n;
struct iovec iov;
* Line up error code. Don't worry about byte ordering
* because we must be sending to the local machine.
*/
- iov.iov_base = (caddr_t) &error;
+ iov.iov_base = (caddr_t)&error;
iov.iov_len = sizeof(error);
/*
* Build a msghdr
*/
- memset(&msg, 0, sizeof(msg));
+ (void)memset(&msg, 0, sizeof(msg));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
ctl.cmsg.cmsg_len = sizeof(ctl);
ctl.cmsg.cmsg_level = SOL_SOCKET;
ctl.cmsg.cmsg_type = SCM_RIGHTS;
- msg.msg_control = (caddr_t) &ctl;
+ msg.msg_control = (caddr_t)&ctl;
msg.msg_controllen = ctl.cmsg.cmsg_len;
}
* Send to kernel...
*/
if ((n = sendmsg(so, &msg, MSG_EOR)) < 0)
- syslog(LOG_ERR, "send: %s", strerror(errno));
+ syslog(LOG_ERR, "send: %m");
#ifdef DEBUG
- fprintf(stderr, "sent %d bytes\n", n);
+ (void)fprintf(stderr, "sent %d bytes\n", n);
#endif
- sleep(1); /*XXX*/
+ sleep(1); /* XXX */
#ifdef notdef
if (shutdown(so, 2) < 0)
- syslog(LOG_ERR, "shutdown: %s", strerror(errno));
+ syslog(LOG_ERR, "shutdown: %m");
#endif
/*
* Throw away the open file descriptor
*/
- (void) close(fd);
+ (void)close(fd);
}
-void activate(q, so)
-qelem *q;
-int so;
+void
+activate(q, so)
+ qelem *q;
+ int so;
{
struct portal_cred pcred;
char key[MAXPATHLEN+1];
*/
error = get_request(so, &pcred, key, sizeof(key));
if (error) {
- syslog(LOG_ERR, "activate: recvmsg: %s", strerror(error));
+ syslog(LOG_ERR, "activate: recvmsg: %m");
goto drop;
}
#ifdef DEBUG
- fprintf(stderr, "lookup key %s\n", key);
+ (void)fprintf(stderr, "lookup key %s\n", key);
#endif
/*
-/* $OpenBSD: conf.c,v 1.3 1997/03/23 03:04:28 millert Exp $ */
+/* $OpenBSD: conf.c,v 1.4 1997/03/23 03:52:13 millert Exp $ */
/* $NetBSD: conf.c,v 1.4 1995/04/23 10:33:19 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
* Add an element to a 2-way list,
* just after (pred)
*/
-static void ins_que(elem, pred)
-qelem *elem, *pred;
+static void
+ins_que(elem, pred)
+ qelem *elem, *pred;
{
qelem *p = pred->q_forw;
elem->q_back = pred;
/*
* Remove an element from a 2-way list
*/
-static void rem_que(elem)
-qelem *elem;
+static void
+rem_que(elem)
+ qelem *elem;
{
qelem *p = elem->q_forw;
qelem *p2 = elem->q_back;
/*
* Error checking malloc
*/
-static void *xmalloc(siz)
-unsigned siz;
+static void *
+xmalloc(siz)
+ size_t siz;
{
void *p = malloc(siz);
if (p)
* not found then the path is added to the end of the list
* and 1 is returned.
*/
-static int pinsert(p0, q0)
-path *p0;
-qelem *q0;
+static int
+pinsert(p0, q0)
+ path *p0;
+ qelem *q0;
{
qelem *q;
return (0);
for (q = q0->q_forw; q != q0; q = q->q_forw) {
- path *p = (path *) q;
+ path *p = (path *)q;
if (strcmp(p->p_key, p0->p_key) == 0)
return (0);
}
}
-void regerror(s)
-const char *s;
+void
+regerror(s)
+ const char *s;
{
syslog(LOG_ERR, "%s:%d: regcomp %s: %s",
conf_file, curp->p_lno, curp->p_key, s);
}
-static path *palloc(cline, lno)
-char *cline;
-int lno;
+static path *
+palloc(cline, lno)
+ char *cline;
+ int lno;
{
int c;
char *s;
*/
c = 0;
key = strdup(cline);
+ if (key == NULL) {
+ syslog(LOG_ALERT, "malloc: failed to get %d bytes",
+ strlen(cline));
+ exit(1);
+ }
for (s = key; s != NULL; ) {
char *val;
while ((val = strsep(&s, " \t\n")) != NULL && *val == '\0')
p->p_argc = 0;
p->p_argv = xmalloc(c * sizeof(char *));
p->p_args = strdup(cline);
+ if (p->p_args == NULL) {
+ syslog(LOG_ALERT, "malloc: failed to get %d bytes",
+ strlen(cline));
+ exit(1);
+ }
ap = p->p_argv;
for (s = p->p_args; s != NULL; ) {
char *val;
#ifdef DEBUG
for (c = 0; c < p->p_argc; c++)
- printf("%sv[%d] = %s\n", c?"\t":"", c, p->p_argv[c]);
+ (void)printf("%sv[%d] = %s\n", c?"\t":"", c, p->p_argv[c]);
#endif
p->p_key = p->p_argv[0];
/*
* Free a path structure
*/
-static void pfree(p)
-path *p;
+static void
+pfree(p)
+ path *p;
{
free(p->p_args);
if (p->p_re)
- free((char *) p->p_re);
- free((char *) p->p_argv);
- free((char *) p);
+ free((void *)p->p_re);
+ free((void *)p->p_argv);
+ free((void *)p);
}
/*
* Discard all currently held path structures on q0.
* and add all the ones on xq.
*/
-static void preplace(q0, xq)
-qelem *q0;
-qelem *xq;
+static void
+preplace(q0, xq)
+ qelem *q0;
+ qelem *xq;
{
/*
* While the list is not empty,
while (q0->q_forw != q0) {
qelem *q = q0->q_forw;
rem_que(q);
- pfree((path *) q);
+ pfree((path *)q);
}
while (xq->q_forw != xq) {
qelem *q = xq->q_forw;
* Read the lines from the configuration file and
* add them to the list of paths.
*/
-static void readfp(q0, fp)
-qelem *q0;
-FILE *fp;
+static void
+readfp(q0, fp)
+ qelem *q0;
+ FILE *fp;
{
char cline[LINE_MAX];
int nread = 0;
* the existing path list with the new version.
* If the file is not readable, then no changes take place
*/
-void conf_read(q, conf)
-qelem *q;
-char *conf;
+void
+conf_read(q, conf)
+ qelem *q;
+ char *conf;
{
FILE *fp = fopen(conf, "r");
if (fp) {
conf_file = conf; /* XXX */
readfp(q, fp);
conf_file = 0; /* XXX */
- (void) fclose(fp);
+ (void)fclose(fp);
} else {
- syslog(LOG_ERR, "open config file \"%s\": %s", conf, strerror(errno));
+ syslog(LOG_ERR, "open config file \"%s\": %m", conf);
}
}
qelem *q;
for (q = q0->q_forw; q != q0; q = q->q_forw) {
- path *p = (path *) q;
+ path *p = (path *)q;
if (p->p_re) {
if (regexec(p->p_re, key))
return (p->p_argv+1);
-.\" $OpenBSD: mount_portal.8,v 1.2 1996/06/23 14:31:32 deraadt Exp $
+.\" $OpenBSD: mount_portal.8,v 1.3 1997/03/23 03:52:14 millert Exp $
.\" $NetBSD: mount_portal.8,v 1.6 1995/08/18 15:01:19 pk Exp $
.\"
.\" Copyright (c) 1993, 1994
.\" The Regents of the University of California. All rights reserved.
+.\" All rights reserved.
.\"
.\" This code is derived from software donated to Berkeley by
.\" Jan-Simon Pendry.
-/* $OpenBSD: mount_portal.c,v 1.6 1997/03/23 03:04:29 millert Exp $ */
+/* $OpenBSD: mount_portal.c,v 1.7 1997/03/23 03:52:14 millert Exp $ */
/* $NetBSD: mount_portal.c,v 1.8 1996/04/13 01:31:54 jtc Exp $ */
/*
#ifndef lint
#if 0
-static char sccsid[] = "@(#)mount_portal.c 8.4 (Berkeley) 3/27/94";
+static char sccsid[] = "@(#)mount_portal.c 8.6 (Berkeley) 4/26/95";
#else
-static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.6 1997/03/23 03:04:29 millert Exp $";
+static char rcsid[] = "$OpenBSD: mount_portal.c,v 1.7 1997/03/23 03:52:14 millert Exp $";
#endif
#endif /* not lint */
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/syslog.h>
-#include <sys/stat.h>
#include <sys/mount.h>
#include <err.h>
while ((pid = waitpid((pid_t) -1, (int *) 0, WNOHANG)) > 0)
;
if (pid < 0 && errno != ECHILD)
- syslog(LOG_WARNING, "waitpid: %s", strerror(errno));
+ syslog(LOG_WARNING, "waitpid: %m");
}
static void
{
if (unmount(mountpt, MNT_FORCE) < 0)
- syslog(LOG_WARNING, "sigterm: unmounting %s failed: %s",
- mountpt, strerror(errno));
+ syslog(LOG_WARNING, "sigterm: unmounting %s failed: %m",
+ mountpt);
}
int
char *conf;
int mntflags = 0;
char tag[32];
- mode_t um;
qelem q;
int rc;
un.sun_family = AF_UNIX;
if (sizeof(_PATH_TMPPORTAL) >= sizeof(un.sun_path))
errx(1, "portal socket name too long");
- strcpy(un.sun_path, _PATH_TMPPORTAL);
+ (void)strcpy(un.sun_path, _PATH_TMPPORTAL);
so = mkstemp(un.sun_path);
if (so < 0)
err(1, "can't create portal socket name: %s", un.sun_path);
if (so < 0)
err(1, "socket(2)");
- um = umask(077);
(void)unlink(un.sun_path);
if (bind(so, (struct sockaddr *) &un, sizeof(un)) < 0)
err(1, "bind(2)");
(void)unlink(un.sun_path);
- (void)umask(um);
(void)listen(so, 5);
args.pa_socket = so;
- (void)sprintf(tag, "portal:%d", getpid() + 1);
+ (void)snprintf(tag, sizeof(tag), "portal:%d", getpid() + 1);
args.pa_config = tag;
rc = mount(MOUNT_PORTAL, mountpt, mntflags, &args);
if (rc < 0) {
if (errno == EINTR)
continue;
- syslog(LOG_ERR, "select: %s", strerror(errno));
+ syslog(LOG_ERR, "select: %m");
exit(1);
}
if (rc == 0)
if (errno == ECONNABORTED)
break;
if (errno != EINTR) {
- syslog(LOG_ERR, "accept: %s", strerror(errno));
+ syslog(LOG_ERR, "accept: %m");
exit(1);
}
continue;
sleep(1);
goto eagain;
}
- syslog(LOG_ERR, "fork: %s", strerror(errno));
+ syslog(LOG_ERR, "fork: %m");
break;
case 0:
(void)close(so);
-/* $OpenBSD: pathnames.h,v 1.3 1997/03/23 03:04:29 millert Exp $ */
+/* $OpenBSD: pathnames.h,v 1.4 1997/03/23 03:52:15 millert Exp $ */
/* $NetBSD: pathnames.h,v 1.4 1995/04/23 10:33:21 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
-/* $OpenBSD: portald.h,v 1.2 1996/06/23 14:31:34 deraadt Exp $ */
+/* $OpenBSD: portald.h,v 1.3 1997/03/23 03:52:15 millert Exp $ */
/* $NetBSD: portald.h,v 1.4 1995/04/23 10:33:23 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
-/* $OpenBSD: pt_conf.c,v 1.2 1996/06/23 14:31:35 deraadt Exp $ */
+/* $OpenBSD: pt_conf.c,v 1.3 1997/03/23 03:52:16 millert Exp $ */
/* $NetBSD: pt_conf.c,v 1.4 1995/04/23 10:33:24 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
-/* $OpenBSD: pt_exec.c,v 1.2 1996/06/23 14:31:35 deraadt Exp $ */
+/* $OpenBSD: pt_exec.c,v 1.3 1997/03/23 03:52:16 millert Exp $ */
/* $NetBSD: pt_exec.c,v 1.4 1995/04/23 10:33:25 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
#include "portald.h"
-int portal_exec(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
+int
+portal_exec(pcr, key, v, so, fdp)
+ struct portal_cred *pcr;
+ char *key;
+ char **v;
+ int so;
+ int *fdp;
{
return (ENOEXEC);
}
-
-/* $OpenBSD: pt_file.c,v 1.3 1997/03/23 03:04:30 millert Exp $ */
+/* $OpenBSD: pt_file.c,v 1.4 1997/03/23 03:52:16 millert Exp $ */
/* $NetBSD: pt_file.c,v 1.7 1995/06/06 19:54:30 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
* SUCH DAMAGE.
*
* from: Id: pt_file.c,v 1.1 1992/05/25 21:43:09 jsp Exp
- * @(#)pt_file.c 8.2 (Berkeley) 3/27/94
+ * @(#)pt_file.c 8.3 (Berkeley) 7/3/94
*/
#include <stdio.h>
#include "portald.h"
-int portal_file(pcr, key, v, so, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int so;
-int *fdp;
+int
+portal_file(pcr, key, v, so, fdp)
+ struct portal_cred *pcr;
+ char *key;
+ char **v;
+ int so;
+ int *fdp;
{
int fd;
char pbuf[MAXPATHLEN];
int error;
pbuf[0] = '/';
- strcpy(pbuf+1, key + (v[1] ? strlen(v[1]) : 0));
+ (void)strcpy(pbuf+1, key + (v[1] ? strlen(v[1]) : 0));
#ifdef DEBUG
- printf("path = %s, uid = %d, gid = %d\n", pbuf, pcr->pcr_uid, pcr->pcr_gid);
+ (void)printf("path = %s, uid = %d, gid = %d\n", pbuf, pcr->pcr_uid,
+ pcr->pcr_gid);
#endif
if (setegid(pcr->pcr_gid) < 0 ||
if (seteuid((uid_t) 0) < 0) { /* XXX - should reset gidset too */
error = errno;
- syslog(LOG_ERR, "setcred: %s", strerror(error));
+ syslog(LOG_ERR, "setcred: %m");
if (fd >= 0) {
- (void) close(fd);
+ (void)close(fd);
fd = -1;
}
}
*fdp = fd;
#ifdef DEBUG
- fprintf(stderr, "pt_file returns *fdp = %d, error = %d\n", *fdp, error);
+ (void)fprintf(stderr, "pt_file returns *fdp = %d, error = %d\n",
+ *fdp, error);
#endif
return (error);
-/* $OpenBSD: pt_tcp.c,v 1.2 1996/06/23 14:31:36 deraadt Exp $ */
+/* $OpenBSD: pt_tcp.c,v 1.3 1997/03/23 03:52:17 millert Exp $ */
/* $NetBSD: pt_tcp.c,v 1.9 1995/05/21 15:33:22 mycroft Exp $ */
/*
- * Copyright (c) 1992, 1993
+ * Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
+ * All rights reserved.
*
* This code is derived from software donated to Berkeley by
* Jan-Simon Pendry.
* SUCH DAMAGE.
*
* from: Id: pt_tcp.c,v 1.1 1992/05/25 21:43:09 jsp Exp
- * @(#)pt_tcp.c 8.3 (Berkeley) 3/27/94
+ * @(#)pt_tcp.c 8.5 (Berkeley) 4/28/95
*/
#include <stdio.h>
* Some trailing suffix values have special meanings.
* An unrecognised suffix is an error.
*/
-int portal_tcp(pcr, key, v, kso, fdp)
-struct portal_cred *pcr;
-char *key;
-char **v;
-int kso;
-int *fdp;
+int
+portal_tcp(pcr, key, v, kso, fdp)
+ struct portal_cred *pcr;
+ char *key;
+ char **v;
+ int kso;
+ int *fdp;
{
char host[MAXHOSTNAMELEN];
char port[MAXHOSTNAMELEN];
if (q == 0 || q - p >= sizeof(host))
return (EINVAL);
*q = '\0';
- strcpy(host, p);
+ (void)strcpy(host, p);
p = q + 1;
q = strchr(p, '/');
*q = '\0';
if (strlen(p) >= sizeof(port))
return (EINVAL);
- strcpy(port, p);
+ (void)strcpy(port, p);
if (q) {
p = q + 1;
if (strcmp(p, "priv") == 0) {
hp = gethostbyname(host);
if (hp == 0)
return (EINVAL);
- ipp = (struct in_addr **) hp->h_addr_list;
+ ipp = (struct in_addr **)hp->h_addr_list;
} else {
ip[0] = &ina;
ip[1] = 0;
if (sp != 0)
s_port = sp->s_port;
else {
- s_port = htons(atoi(port));
- if (s_port == 0)
+ s_port = strtoul(port, &p, 0);
+ if (s_port == 0 || *p != '\0')
return (EINVAL);
+ s_port = htons(s_port);
}
- memset(&sain, 0, sizeof(sain));
+ (void)memset(&sain, 0, sizeof(sain));
sain.sin_len = sizeof(sain);
sain.sin_family = AF_INET;
sain.sin_port = s_port;
*fdp = so;
return (0);
}
- (void) close(so);
+ (void)close(so);
ipp++;
}