Index: stable/3/usr.sbin/ppp/ether.c =================================================================== --- stable/3/usr.sbin/ppp/ether.c (revision 53535) +++ stable/3/usr.sbin/ppp/ether.c (revision 53536) @@ -1,640 +1,640 @@ /*- * Copyright (c) 1999 Brian Somers * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__FreeBSD__) && !defined(NOKLDLOAD) #include #include #endif #include #include #include #include #include "layer.h" #include "defs.h" #include "mbuf.h" #include "log.h" #include "timer.h" #include "lqr.h" #include "hdlc.h" #include "throughput.h" #include "fsm.h" #include "lcp.h" #include "ccp.h" #include "link.h" #include "async.h" #include "descriptor.h" #include "physical.h" #include "main.h" #include "mp.h" #include "chat.h" #include "auth.h" #include "chap.h" #include "cbcp.h" #include "datalink.h" #include "slcompress.h" #include "iplist.h" #include "ipcp.h" #include "filter.h" #ifndef NORADIUS #include "radius.h" #endif #include "bundle.h" #include "id.h" #include "ether.h" #define PPPOE_NODE_TYPE_LEN (sizeof NG_PPPOE_NODE_TYPE - 1) /* "PPPoE" */ struct etherdevice { struct device dev; /* What struct physical knows about */ int cs; /* Control socket */ int connected; /* Are we connected yet ? */ int timeout; /* Seconds attempting to connect */ char hook[sizeof TUN_NAME + 11]; /* Our socket node hook */ }; #define device2ether(d) \ ((d)->type == ETHER_DEVICE ? (struct etherdevice *)d : NULL) int ether_DeviceSize(void) { return sizeof(struct etherdevice); } static ssize_t ether_Write(struct physical *p, const void *v, size_t n) { struct etherdevice *dev = device2ether(p->handler); return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : n; } static ssize_t ether_Read(struct physical *p, void *v, size_t n) { char hook[sizeof TUN_NAME + 11]; return NgRecvData(p->fd, v, n, hook); } static int ether_RemoveFromSet(struct physical *p, fd_set *r, fd_set *w, fd_set *e) { struct etherdevice *dev = device2ether(p->handler); int result; if (r && dev->cs >= 0 && FD_ISSET(dev->cs, r)) { FD_CLR(dev->cs, r); log_Printf(LogTIMER, "%s: fdunset(ctrl) %d\n", p->link.name, dev->cs); result = 1; } else result = 0; /* Careful... physical_RemoveFromSet() called us ! */ p->handler->removefromset = NULL; result += physical_RemoveFromSet(p, r, w, e); p->handler->removefromset = ether_RemoveFromSet; return result; } static void ether_Free(struct physical *p) { struct etherdevice *dev = device2ether(p->handler); physical_SetDescriptor(p); if (dev->cs != -1) close(dev->cs); free(dev); } static const char * ether_OpenInfo(struct physical *p) { struct etherdevice *dev = device2ether(p->handler); switch (dev->connected) { case CARRIER_PENDING: return "negotiating"; case CARRIER_OK: return "established"; } return "disconnected"; } static void ether_device2iov(struct device *d, struct iovec *iov, int *niov, int maxiov, int *auxfd, int *nauxfd, pid_t newpid) { struct etherdevice *dev = device2ether(d); int sz = physical_MaxDeviceSize(); iov[*niov].iov_base = realloc(d, sz); if (iov[*niov].iov_base == NULL) { log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz); AbortProgram(EX_OSERR); } iov[*niov].iov_len = sz; (*niov)++; if (dev->cs >= 0) { *auxfd = dev->cs; (*nauxfd)++; } } static void ether_MessageIn(struct etherdevice *dev) { char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)]; struct ng_mesg *rep = (struct ng_mesg *)msgbuf; struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep); char unknown[14]; const char *msg; struct timeval t; fd_set r; if (dev->cs < 0) return; FD_ZERO(&r); FD_SET(dev->cs, &r); t.tv_sec = t.tv_usec = 0; if (select(dev->cs + 1, &r, NULL, NULL, &t) <= 0) return; if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) < 0) return; if (rep->header.version != NG_VERSION) { log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n", (long)rep->header.version, (long)NG_VERSION); return; } if (rep->header.typecookie != NGM_PPPOE_COOKIE) { log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n", (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE); return; } switch (rep->header.cmd) { case NGM_PPPOE_SET_FLAG: msg = "SET_FLAG"; break; case NGM_PPPOE_CONNECT: msg = "CONNECT"; break; case NGM_PPPOE_LISTEN: msg = "LISTEN"; break; case NGM_PPPOE_OFFER: msg = "OFFER"; break; case NGM_PPPOE_SUCCESS: msg = "SUCCESS"; break; case NGM_PPPOE_FAIL: msg = "FAIL"; break; case NGM_PPPOE_CLOSE: msg = "CLOSE"; break; case NGM_PPPOE_GET_STATUS: msg = "GET_STATUS"; break; default: snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); msg = unknown; break; } log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook); switch (rep->header.cmd) { case NGM_PPPOE_SUCCESS: dev->connected = CARRIER_OK; break; case NGM_PPPOE_FAIL: case NGM_PPPOE_CLOSE: dev->connected = CARRIER_LOST; break; } } static int ether_AwaitCarrier(struct physical *p) { struct etherdevice *dev = device2ether(p->handler); if (dev->connected != CARRIER_OK && !dev->timeout--) dev->connected = CARRIER_LOST; else if (dev->connected == CARRIER_PENDING) ether_MessageIn(dev); return dev->connected; } static const struct device baseetherdevice = { ETHER_DEVICE, "ether", ether_AwaitCarrier, ether_RemoveFromSet, NULL, NULL, NULL, NULL, ether_Free, ether_Read, ether_Write, ether_device2iov, NULL, ether_OpenInfo }; struct device * ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, int maxiov, int *auxfd, int *nauxfd) { if (type == ETHER_DEVICE) { struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base; dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */ if (dev == NULL) { log_Printf(LogALERT, "Failed to allocate memory: %d\n", (int)(sizeof *dev)); AbortProgram(EX_OSERR); } if (*nauxfd) { dev->cs = *auxfd; (*nauxfd)--; } else dev->cs = -1; /* Refresh function pointers etc */ memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); return &dev->dev; } return NULL; } static int ether_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) { struct physical *p = descriptor2physical(d); struct etherdevice *dev = device2ether(p->handler); int result; if (r && dev->cs >= 0) { FD_SET(dev->cs, r); log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs); result = 1; } else result = 0; result += physical_doUpdateSet(d, r, w, e, n, 0); return result; } static int ether_IsSet(struct descriptor *d, const fd_set *fdset) { struct physical *p = descriptor2physical(d); struct etherdevice *dev = device2ether(p->handler); int result; result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset); result += physical_IsSet(d, fdset); return result; } static void ether_DescriptorRead(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) { struct physical *p = descriptor2physical(d); struct etherdevice *dev = device2ether(p->handler); if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) { ether_MessageIn(dev); if (dev->connected == CARRIER_LOST) { log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name); datalink_Down(p->dl, CLOSE_NORMAL); return; } } if (physical_IsSet(d, fdset)) physical_DescriptorRead(d, bundle, fdset); } static struct device * ether_Abandon(struct etherdevice *dev, struct physical *p) { /* Abandon our node construction */ close(dev->cs); close(p->fd); p->fd = -2; /* Nobody else need try.. */ free(dev); return NULL; } struct device * ether_Create(struct physical *p) { u_char rbuf[2048]; struct etherdevice *dev; struct ng_mesg *resp; const struct hooklist *hlist; const struct nodeinfo *ninfo; int f; dev = NULL; if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE, PPPOE_NODE_TYPE_LEN) && p->name.full[PPPOE_NODE_TYPE_LEN] == ':') { const struct linkinfo *nlink; struct ngpppoe_init_data *data; struct ngm_mkpeer mkp; struct ngm_connect ngc; const char *iface, *provider; char *path, etherid[12]; int ifacelen, providerlen; char connectpath[sizeof dev->hook + 2]; /* .: */ p->fd--; /* We own the device - change fd */ #if defined(__FreeBSD__) && !defined(NOKLDLOAD) if (modfind("netgraph") == -1) { log_Printf(LogWARN, "Netgraph is not built into the kernel\n"); return NULL; } if (modfind("ng_socket") == -1 && ID0kldload("ng_socket") == -1) { log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno)); return NULL; } #endif if ((dev = malloc(sizeof *dev)) == NULL) return NULL; iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1; provider = strchr(iface, ':'); if (provider) { ifacelen = provider - iface; provider++; providerlen = strlen(provider); } else { ifacelen = strlen(iface); provider = ""; providerlen = 0; } /* * We're going to do this (where tunN is our tunnel device): * * .---------. * | ether | * | | dev->cs * `---------' | * (orphan) p->fd | * | | | * | | | * (ethernet) | | * .---------. .-----------. * | pppoe | | socket | * | |(tunN)<---->(tunN)| | * `--------- `-----------' * (tunX) * ^ * | * `--->(tunX) */ /* Create a socket node */ - if (NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) { + if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) { log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n", strerror(errno)); free(dev); return NULL; } /* * Ask for a list of hooks attached to the "ether" node. This node should * magically exist as a way of hooking stuff onto an ethernet device */ path = (char *)alloca(ifacelen + 2); sprintf(path, "%.*s:", ifacelen, iface); if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0) < 0) { log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n", path, strerror(errno)); return ether_Abandon(dev, p); } /* Get our list back */ resp = (struct ng_mesg *)rbuf; if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) { log_Printf(LogWARN, "Cannot get netgraph response: %s\n", strerror(errno)); return ether_Abandon(dev, p); } hlist = (const struct hooklist *)resp->data; ninfo = &hlist->nodeinfo; /* Make sure we've got the right type of node */ if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, sizeof NG_ETHER_NODE_TYPE - 1)) { log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``" NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type); return ether_Abandon(dev, p); } log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n", path, ninfo->id); /* look for a hook already attached. */ for (f = 0; f < ninfo->hooks; f++) { nlink = &hlist->link[f]; log_Printf(LogDEBUG, " Found %s -> %s\n", nlink->ourhook, nlink->peerhook); if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) || !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) { /* * Something is using the data coming out of this ``ether'' node. * If it's a PPPoE node, we use that node, otherwise we complain that * someone else is using the node. */ if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) /* Use this PPPoE node ! */ snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id); else { log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n", path, nlink->nodeinfo.type); return ether_Abandon(dev, p); } break; } } if (f == ninfo->hooks) { /* * Create a new ``PPPoE'' node connected to the ``ether'' node using * the magic ``orphan'' and ``ethernet'' hooks */ snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE); snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN); snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET); snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id); log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n", etherid, mkp.ourhook, mkp.peerhook); if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE, NGM_MKPEER, &mkp, sizeof mkp) < 0) { log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n", etherid, strerror(errno)); return ether_Abandon(dev, p); } snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN); } snprintf(dev->hook, sizeof dev->hook, "%s%d", TUN_NAME, p->dl->bundle->unit); /* * Connect the PPPoE node to our socket node. * ngc.path has already been set up */ snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook); memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook); log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n", ngc.ourhook, ngc.path, ngc.peerhook); if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, sizeof ngc) < 0) { log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph " "nodes: %s\n", strerror(errno)); return ether_Abandon(dev, p); } /* And finally, request a connection to the given provider */ data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen + 1); snprintf(data->hook, sizeof data->hook, "%s", dev->hook); strcpy(data->data, provider); data->data_len = providerlen; snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook); log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath); if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) { log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n", connectpath, strerror(errno)); return ether_Abandon(dev, p); } dev->timeout = p->cfg.cd.delay; dev->connected = CARRIER_PENDING; /* Hook things up so that we monitor dev->cs */ p->desc.UpdateSet = ether_UpdateSet; p->desc.IsSet = ether_IsSet; p->desc.Read = ether_DescriptorRead; } else { /* See if we're a netgraph socket */ struct sockaddr_ng ngsock; struct sockaddr *sock = (struct sockaddr *)&ngsock; int sz; sz = sizeof ngsock; if (getsockname(p->fd, sock, &sz) != -1 && sock->sa_family == AF_NETGRAPH) { /* * It's a netgraph node... We can't determine hook names etc, so we * stay pretty impartial.... */ log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name); if ((dev = malloc(sizeof *dev)) == NULL) { log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n", p->link.name, strerror(errno)); return NULL; } dev->cs = -1; dev->timeout = 0; dev->connected = CARRIER_OK; *dev->hook = '\0'; } } if (dev) { memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); /* Moan about (and fix) invalid LCP configurations */ if (p->link.lcp.cfg.mru > 1492) { log_Printf(LogWARN, "%s: Reducing MRU to 1492\n", p->link.name); p->link.lcp.cfg.mru = 1492; } if (p->dl->bundle->cfg.mtu > 1492) { log_Printf(LogWARN, "%s: Reducing MTU to 1492\n", p->link.name); p->dl->bundle->cfg.mtu = 1492; } return &dev->dev; } return NULL; } Index: stable/3/usr.sbin/ppp/id.c =================================================================== --- stable/3/usr.sbin/ppp/id.c (revision 53535) +++ stable/3/usr.sbin/ppp/id.c (revision 53536) @@ -1,298 +1,316 @@ /*- * Copyright (c) 1997 Brian Somers * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include +#ifndef NONETGRAPH +#include +#endif #include #include #include #include #include #if defined(__FreeBSD__) && !defined(NOKLDLOAD) #include #endif #include #ifdef __OpenBSD__ #include #else #include #endif #include #include "log.h" #include "main.h" #include "id.h" static int uid; static int euid; void ID0init() { uid = getuid(); euid = geteuid(); } static void ID0setuser(void) { if (seteuid(uid) == -1) { log_Printf(LogERROR, "ID0setuser: Unable to seteuid!\n"); AbortProgram(EX_NOPERM); } } uid_t ID0realuid() { return uid; } static void ID0set0(void) { if (seteuid(euid) == -1) { log_Printf(LogERROR, "ID0set0: Unable to seteuid!\n"); AbortProgram(EX_NOPERM); } } int ID0ioctl(int fd, unsigned long req, void *arg) { int ret; ID0set0(); ret = ioctl(fd, req, arg); log_Printf(LogID0, "%d = ioctl(%d, %lu, %p)\n", ret, fd, req, arg); ID0setuser(); return ret; } int ID0unlink(const char *name) { int ret; ID0set0(); ret = unlink(name); log_Printf(LogID0, "%d = unlink(\"%s\")\n", ret, name); ID0setuser(); return ret; } int ID0socket(int domain, int type, int protocol) { int ret; ID0set0(); ret = socket(domain, type, protocol); log_Printf(LogID0, "%d = socket(%d, %d, %d)\n", ret, domain, type, protocol); ID0setuser(); return ret; } FILE * ID0fopen(const char *path, const char *mode) { FILE *ret; ID0set0(); ret = fopen(path, mode); log_Printf(LogID0, "%p = fopen(\"%s\", \"%s\")\n", ret, path, mode); ID0setuser(); return ret; } int ID0open(const char *path, int flags, ...) { int ret; va_list ap; va_start(ap, flags); ID0set0(); ret = open(path, flags, va_arg(ap, int)); log_Printf(LogID0, "%d = open(\"%s\", %d)\n", ret, path, flags); ID0setuser(); va_end(ap); return ret; } int ID0write(int fd, const void *data, size_t len) { int ret; ID0set0(); ret = write(fd, data, len); log_Printf(LogID0, "%d = write(%d, data, %ld)\n", ret, fd, (long)len); ID0setuser(); return ret; } int ID0uu_lock(const char *basettyname) { int ret; ID0set0(); ret = uu_lock(basettyname); log_Printf(LogID0, "%d = uu_lock(\"%s\")\n", ret, basettyname); ID0setuser(); return ret; } int ID0uu_lock_txfr(const char *basettyname, pid_t newpid) { int ret; ID0set0(); ret = uu_lock_txfr(basettyname, newpid); log_Printf(LogID0, "%d = uu_lock_txfr(\"%s\", %d)\n", ret, basettyname, (int)newpid); ID0setuser(); return ret; } int ID0uu_unlock(const char *basettyname) { int ret; ID0set0(); ret = uu_unlock(basettyname); log_Printf(LogID0, "%d = uu_unlock(\"%s\")\n", ret, basettyname); ID0setuser(); return ret; } void ID0login(struct utmp *ut) { ID0set0(); if (logout(ut->ut_line)) { log_Printf(LogID0, "logout(\"%s\")\n", ut->ut_line); logwtmp(ut->ut_line, "", ""); log_Printf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut->ut_line); } login(ut); log_Printf(LogID0, "login(\"%s\", \"%.*s\")\n", ut->ut_line, (int)(sizeof ut->ut_name), ut->ut_name); ID0setuser(); } void ID0logout(const char *device, int nologout) { struct utmp ut; strncpy(ut.ut_line, device, sizeof ut.ut_line - 1); ut.ut_line[sizeof ut.ut_line - 1] = '\0'; ID0set0(); if (nologout || logout(ut.ut_line)) { log_Printf(LogID0, "logout(\"%s\")\n", ut.ut_line); logwtmp(ut.ut_line, "", ""); log_Printf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut.ut_line); } else log_Printf(LogERROR, "ID0logout: No longer logged in on %s\n", ut.ut_line); ID0setuser(); } int ID0bind_un(int s, const struct sockaddr_un *name) { int result; ID0set0(); result = bind(s, (const struct sockaddr *)name, sizeof *name); log_Printf(LogID0, "%d = bind(%d, \"%s\", %d)\n", result, s, name->sun_path, (int)sizeof(*name)); ID0setuser(); return result; } int ID0connect_un(int s, const struct sockaddr_un *name) { int result; ID0set0(); result = connect(s, (const struct sockaddr *)name, sizeof *name); log_Printf(LogID0, "%d = connect(%d, \"%s\", %d)\n", result, s, name->sun_path, (int)sizeof(*name)); ID0setuser(); return result; } int ID0kill(pid_t pid, int sig) { int result; ID0set0(); result = kill(pid, sig); log_Printf(LogID0, "%d = kill(%d, %d)\n", result, (int)pid, sig); ID0setuser(); return result; } void ID0setproctitle(const char *title) { ID0set0(); if (title == NULL) { setproctitle(NULL); log_Printf(LogID0, "setproctitle(NULL)\n"); } else { setproctitle("%s", title); log_Printf(LogID0, "setproctitle(\"%%s\", \"%s\")\n", title); } ID0setuser(); } #if defined(__FreeBSD__) && !defined(NOKLDLOAD) int ID0kldload(const char *dev) { int result; ID0set0(); result = kldload(dev); log_Printf(LogID0, "%d = kldload(\"%s\")\n", result, dev); + ID0setuser(); + return result; +} +#endif + +#ifndef NONETGRAPH +int +ID0NgMkSockNode(const char *name, int *cs, int *ds) +{ + int result; + + ID0set0(); + result = NgMkSockNode(name, cs, ds); + log_Printf(LogID0, "%d = NgMkSockNode(\"%s\", &cs, &ds)\n", + result, name ? name : ""); ID0setuser(); return result; } #endif Index: stable/3/usr.sbin/ppp/id.h =================================================================== --- stable/3/usr.sbin/ppp/id.h (revision 53535) +++ stable/3/usr.sbin/ppp/id.h (revision 53536) @@ -1,51 +1,54 @@ /*- * Copyright (c) 1997 Brian Somers * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ struct utmp; struct sockaddr_un; extern void ID0init(void); extern uid_t ID0realuid(void); extern int ID0ioctl(int, unsigned long, void *); extern int ID0unlink(const char *); extern int ID0socket(int, int, int); extern FILE *ID0fopen(const char *, const char *); extern int ID0open(const char *, int, ...); extern int ID0write(int, const void *, size_t); extern int ID0uu_lock(const char *); extern int ID0uu_lock_txfr(const char *, pid_t); extern int ID0uu_unlock(const char *); extern void ID0login(struct utmp *); extern void ID0logout(const char *, int); extern int ID0bind_un(int, const struct sockaddr_un *); extern int ID0connect_un(int, const struct sockaddr_un *); extern int ID0kill(pid_t, int); extern void ID0setproctitle(const char *); #if defined(__FreeBSD__) && !defined(NOKLDLOAD) extern int ID0kldload(const char *); #endif +#ifndef NONETGRAPH +extern int ID0NgMkSockNode(const char *, int *, int *); +#endif