2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/param.h>
32 #include <sys/socket.h>
35 #include <sys/ioctl.h>
45 #if defined(__FreeBSD__) && !defined(NOKLDLOAD)
46 #include <sys/linker.h>
73 if (seteuid(uid) == -1) {
74 log_Printf(LogERROR, "ID0setuser: Unable to seteuid!\n");
75 AbortProgram(EX_NOPERM);
88 if (seteuid(euid) == -1) {
89 log_Printf(LogERROR, "ID0set0: Unable to seteuid!\n");
90 AbortProgram(EX_NOPERM);
95 ID0ioctl(int fd, unsigned long req, void *arg)
100 ret = ioctl(fd, req, arg);
101 log_Printf(LogID0, "%d = ioctl(%d, %lu, %p)\n", ret, fd, req, arg);
107 ID0unlink(const char *name)
113 log_Printf(LogID0, "%d = unlink(\"%s\")\n", ret, name);
119 ID0socket(int domain, int type, int protocol)
124 ret = socket(domain, type, protocol);
125 log_Printf(LogID0, "%d = socket(%d, %d, %d)\n", ret, domain, type, protocol);
131 ID0fopen(const char *path, const char *mode)
136 ret = fopen(path, mode);
137 log_Printf(LogID0, "%p = fopen(\"%s\", \"%s\")\n", ret, path, mode);
143 ID0open(const char *path, int flags, ...)
150 ret = open(path, flags, va_arg(ap, int));
151 log_Printf(LogID0, "%d = open(\"%s\", %d)\n", ret, path, flags);
158 ID0write(int fd, const void *data, size_t len)
163 ret = write(fd, data, len);
164 log_Printf(LogID0, "%d = write(%d, data, %ld)\n", ret, fd, (long)len);
170 ID0uu_lock(const char *basettyname)
175 ret = uu_lock(basettyname);
176 log_Printf(LogID0, "%d = uu_lock(\"%s\")\n", ret, basettyname);
182 ID0uu_lock_txfr(const char *basettyname, pid_t newpid)
187 ret = uu_lock_txfr(basettyname, newpid);
188 log_Printf(LogID0, "%d = uu_lock_txfr(\"%s\", %ld)\n", ret, basettyname,
195 ID0uu_unlock(const char *basettyname)
200 ret = uu_unlock(basettyname);
201 log_Printf(LogID0, "%d = uu_unlock(\"%s\")\n", ret, basettyname);
207 ID0login(const struct utmpx *ut)
211 log_Printf(LogID0, "pututxline(\"%.*s\", \"%.*s\", \"%.*s\", \"%.*s\")\n",
212 (int)sizeof ut->ut_id, ut->ut_id,
213 (int)sizeof ut->ut_user, ut->ut_user,
214 (int)sizeof ut->ut_line, ut->ut_line,
215 (int)sizeof ut->ut_host, ut->ut_host);
220 ID0logout(const struct utmpx *ut)
224 log_Printf(LogID0, "pututxline(\"%.*s\")\n",
225 (int)sizeof ut->ut_id, ut->ut_id);
230 ID0bind_un(int s, const struct sockaddr_un *name)
235 result = bind(s, (const struct sockaddr *)name, sizeof *name);
236 log_Printf(LogID0, "%d = bind(%d, \"%s\", %d)\n",
237 result, s, name->sun_path, (int)sizeof(*name));
243 ID0connect_un(int s, const struct sockaddr_un *name)
248 result = connect(s, (const struct sockaddr *)name, sizeof *name);
249 log_Printf(LogID0, "%d = connect(%d, \"%s\", %d)\n",
250 result, s, name->sun_path, (int)sizeof(*name));
256 ID0kill(pid_t pid, int sig)
261 result = kill(pid, sig);
262 log_Printf(LogID0, "%d = kill(%ld, %d)\n", result, (long)pid, sig);
267 #if defined(__FreeBSD__) && !defined(NOKLDLOAD)
269 ID0kldload(const char *dev)
274 result = kldload(dev);
275 log_Printf(LogID0, "%d = kldload(\"%s\")\n", result, dev);
283 ID0NgMkSockNode(const char *name, int *cs, int *ds)
288 result = NgMkSockNode(name, cs, ds);
289 log_Printf(LogID0, "%d = NgMkSockNode(\"%s\", &cs, &ds)\n",
290 result, name ? name : "");