1997-12-21 12:11:13 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
1997-12-21 12:11:13 +00:00
|
|
|
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1997-11-09 06:22:49 +00:00
|
|
|
*/
|
|
|
|
|
1999-09-22 00:40:47 +00:00
|
|
|
#include <sys/param.h>
|
1997-11-09 06:22:49 +00:00
|
|
|
#include <sys/socket.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <sys/un.h>
|
1997-11-09 06:22:49 +00:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
1999-11-21 23:27:23 +00:00
|
|
|
#ifndef NONETGRAPH
|
|
|
|
#include <netgraph.h>
|
|
|
|
#endif
|
1998-05-29 18:33:10 +00:00
|
|
|
#include <signal.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <stdarg.h>
|
1997-11-09 06:22:49 +00:00
|
|
|
#include <stdio.h>
|
1998-02-19 02:10:13 +00:00
|
|
|
#include <string.h>
|
1997-11-09 06:22:49 +00:00
|
|
|
#include <sysexits.h>
|
1999-09-22 00:40:47 +00:00
|
|
|
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
|
|
|
#include <sys/linker.h>
|
|
|
|
#endif
|
1997-11-09 06:22:49 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include <util.h>
|
|
|
|
#else
|
|
|
|
#include <libutil.h>
|
|
|
|
#endif
|
2010-01-13 17:54:32 +00:00
|
|
|
#include <utmpx.h>
|
1998-02-19 02:10:13 +00:00
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "main.h"
|
1997-11-09 06:22:49 +00:00
|
|
|
#include "id.h"
|
|
|
|
|
|
|
|
static int uid;
|
|
|
|
static int euid;
|
|
|
|
|
|
|
|
void
|
|
|
|
ID0init()
|
|
|
|
{
|
|
|
|
uid = getuid();
|
|
|
|
euid = geteuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
ID0setuser(void)
|
1997-11-09 06:22:49 +00:00
|
|
|
{
|
1997-11-13 17:31:52 +00:00
|
|
|
if (seteuid(uid) == -1) {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogERROR, "ID0setuser: Unable to seteuid!\n");
|
|
|
|
AbortProgram(EX_NOPERM);
|
1997-11-09 06:22:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uid_t
|
|
|
|
ID0realuid()
|
|
|
|
{
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
ID0set0(void)
|
1997-11-09 06:22:49 +00:00
|
|
|
{
|
1997-11-13 17:31:52 +00:00
|
|
|
if (seteuid(euid) == -1) {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogERROR, "ID0set0: Unable to seteuid!\n");
|
|
|
|
AbortProgram(EX_NOPERM);
|
1997-11-09 06:22:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0ioctl(int fd, unsigned long req, void *arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = ioctl(fd, req, arg);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%d = ioctl(%d, %lu, %p)\n", ret, fd, req, arg);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0unlink(const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = unlink(name);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%d = unlink(\"%s\")\n", ret, name);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0socket(int domain, int type, int protocol)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = socket(domain, type, protocol);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%d = socket(%d, %d, %d)\n", ret, domain, type, protocol);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
|
|
|
ID0fopen(const char *path, const char *mode)
|
|
|
|
{
|
|
|
|
FILE *ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = fopen(path, mode);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%p = fopen(\"%s\", \"%s\")\n", ret, path, mode);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-05-21 21:49:08 +00:00
|
|
|
ID0open(const char *path, int flags, ...)
|
1997-11-09 06:22:49 +00:00
|
|
|
{
|
|
|
|
int ret;
|
1998-05-21 21:49:08 +00:00
|
|
|
va_list ap;
|
1997-11-09 06:22:49 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
va_start(ap, flags);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0set0();
|
1998-05-21 21:49:08 +00:00
|
|
|
ret = open(path, flags, va_arg(ap, int));
|
|
|
|
log_Printf(LogID0, "%d = open(\"%s\", %d)\n", ret, path, flags);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
1998-05-21 21:49:08 +00:00
|
|
|
va_end(ap);
|
1997-11-09 06:22:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1997-12-27 19:23:13 +00:00
|
|
|
int
|
|
|
|
ID0write(int fd, const void *data, size_t len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = write(fd, data, len);
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogID0, "%d = write(%d, data, %ld)\n", ret, fd, (long)len);
|
1997-12-27 19:23:13 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1997-11-09 06:22:49 +00:00
|
|
|
int
|
1997-11-22 03:37:54 +00:00
|
|
|
ID0uu_lock(const char *basettyname)
|
1997-11-09 06:22:49 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
1997-11-22 03:37:54 +00:00
|
|
|
ret = uu_lock(basettyname);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%d = uu_lock(\"%s\")\n", ret, basettyname);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1998-05-28 23:15:40 +00:00
|
|
|
int
|
|
|
|
ID0uu_lock_txfr(const char *basettyname, pid_t newpid)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = uu_lock_txfr(basettyname, newpid);
|
2002-05-27 23:19:53 +00:00
|
|
|
log_Printf(LogID0, "%d = uu_lock_txfr(\"%s\", %ld)\n", ret, basettyname,
|
|
|
|
(long)newpid);
|
1998-05-28 23:15:40 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1997-11-09 06:22:49 +00:00
|
|
|
int
|
1997-11-22 03:37:54 +00:00
|
|
|
ID0uu_unlock(const char *basettyname)
|
1997-11-09 06:22:49 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
1997-11-22 03:37:54 +00:00
|
|
|
ret = uu_unlock(basettyname);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogID0, "%d = uu_unlock(\"%s\")\n", ret, basettyname);
|
1997-11-09 06:22:49 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
1998-02-19 02:10:13 +00:00
|
|
|
|
|
|
|
void
|
2010-01-13 17:54:32 +00:00
|
|
|
ID0login(const struct utmpx *ut)
|
1998-02-19 02:10:13 +00:00
|
|
|
{
|
|
|
|
ID0set0();
|
2010-01-13 17:54:32 +00:00
|
|
|
pututxline(ut);
|
|
|
|
log_Printf(LogID0, "pututxline(\"%.*s\", \"%.*s\", \"%.*s\", \"%.*s\")\n",
|
|
|
|
(int)sizeof ut->ut_id, ut->ut_id,
|
|
|
|
(int)sizeof ut->ut_user, ut->ut_user,
|
|
|
|
(int)sizeof ut->ut_line, ut->ut_line,
|
|
|
|
(int)sizeof ut->ut_host, ut->ut_host);
|
1998-02-19 02:10:13 +00:00
|
|
|
ID0setuser();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-13 17:54:32 +00:00
|
|
|
ID0logout(const struct utmpx *ut)
|
1998-02-19 02:10:13 +00:00
|
|
|
{
|
|
|
|
ID0set0();
|
2010-01-13 17:54:32 +00:00
|
|
|
pututxline(ut);
|
|
|
|
log_Printf(LogID0, "pututxline(\"%.*s\")\n",
|
|
|
|
(int)sizeof ut->ut_id, ut->ut_id);
|
1998-02-19 02:10:13 +00:00
|
|
|
ID0setuser();
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
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",
|
1998-06-27 23:48:54 +00:00
|
|
|
result, s, name->sun_path, (int)sizeof(*name));
|
1998-05-21 21:49:08 +00:00
|
|
|
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",
|
1998-06-27 23:48:54 +00:00
|
|
|
result, s, name->sun_path, (int)sizeof(*name));
|
1998-05-21 21:49:08 +00:00
|
|
|
ID0setuser();
|
|
|
|
return result;
|
|
|
|
}
|
1998-05-29 18:33:10 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
ID0kill(pid_t pid, int sig)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
result = kill(pid, sig);
|
2002-05-27 23:19:53 +00:00
|
|
|
log_Printf(LogID0, "%d = kill(%ld, %d)\n", result, (long)pid, sig);
|
1998-05-29 18:33:10 +00:00
|
|
|
ID0setuser();
|
|
|
|
return result;
|
|
|
|
}
|
1999-09-22 00:40:47 +00:00
|
|
|
|
1999-11-16 21:57:34 +00:00
|
|
|
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
1999-09-22 00:40:47 +00:00
|
|
|
int
|
|
|
|
ID0kldload(const char *dev)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
result = kldload(dev);
|
|
|
|
log_Printf(LogID0, "%d = kldload(\"%s\")\n", result, dev);
|
|
|
|
ID0setuser();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
1999-11-21 23:27:23 +00:00
|
|
|
|
|
|
|
#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
|