1998-01-29 00:44:16 +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.
|
|
|
|
*
|
1998-04-19 23:09:03 +00:00
|
|
|
* $Id: id.c,v 1.6.4.5 1998/04/17 22:05:16 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
1998-04-17 22:05:37 +00:00
|
|
|
#include <stdarg.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <stdio.h>
|
1998-02-19 02:08:53 +00:00
|
|
|
#include <string.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <sysexits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#else
|
|
|
|
#include <libutil.h>
|
|
|
|
#endif
|
1998-02-19 02:08:53 +00:00
|
|
|
#include <utmp.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "main.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "id.h"
|
|
|
|
|
|
|
|
static int uid;
|
|
|
|
static int euid;
|
|
|
|
|
|
|
|
void
|
|
|
|
ID0init()
|
|
|
|
{
|
|
|
|
uid = getuid();
|
|
|
|
euid = geteuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ID0setuser(void)
|
|
|
|
{
|
|
|
|
if (seteuid(uid) == -1) {
|
|
|
|
LogPrintf(LogERROR, "ID0setuser: Unable to seteuid!\n");
|
1998-02-08 11:07:32 +00:00
|
|
|
AbortProgram(EX_NOPERM);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uid_t
|
|
|
|
ID0realuid()
|
|
|
|
{
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ID0set0(void)
|
|
|
|
{
|
|
|
|
if (seteuid(euid) == -1) {
|
|
|
|
LogPrintf(LogERROR, "ID0set0: Unable to seteuid!\n");
|
1998-02-08 11:07:32 +00:00
|
|
|
AbortProgram(EX_NOPERM);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0ioctl(int fd, unsigned long req, void *arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = ioctl(fd, req, arg);
|
1998-04-19 23:09:03 +00:00
|
|
|
LogPrintf(LogID0, "%d = ioctl(%d, %lu, %p)\n", ret, fd, req, arg);
|
1998-01-29 00:44:16 +00:00
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0unlink(const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = unlink(name);
|
|
|
|
LogPrintf(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);
|
|
|
|
LogPrintf(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);
|
|
|
|
LogPrintf(LogID0, "%p = fopen(\"%s\", \"%s\")\n", ret, path, mode);
|
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-04-17 22:05:37 +00:00
|
|
|
ID0open(const char *path, int flags, ...)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
int ret;
|
1998-04-17 22:05:37 +00:00
|
|
|
va_list ap;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
va_start(ap, flags);
|
1998-01-29 00:44:16 +00:00
|
|
|
ID0set0();
|
1998-04-17 22:05:37 +00:00
|
|
|
ret = open(path, flags, va_arg(ap, int));
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogID0, "%d = open(\"%s\", %d)\n", ret, path, flags);
|
|
|
|
ID0setuser();
|
1998-04-17 22:05:37 +00:00
|
|
|
va_end(ap);
|
1998-01-29 00:44:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0write(int fd, const void *data, size_t len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = write(fd, data, len);
|
|
|
|
LogPrintf(LogID0, "%d = write(%d, data, %d)\n", ret, fd, len);
|
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0uu_lock(const char *basettyname)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = uu_lock(basettyname);
|
|
|
|
LogPrintf(LogID0, "%d = uu_lock(\"%s\")\n", ret, basettyname);
|
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ID0uu_unlock(const char *basettyname)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
ret = uu_unlock(basettyname);
|
|
|
|
LogPrintf(LogID0, "%d = uu_unlock(\"%s\")\n", ret, basettyname);
|
|
|
|
ID0setuser();
|
|
|
|
return ret;
|
|
|
|
}
|
1998-02-19 02:08:53 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ID0login(struct utmp *ut)
|
|
|
|
{
|
|
|
|
ID0set0();
|
|
|
|
if (logout(ut->ut_line)) {
|
|
|
|
LogPrintf(LogID0, "logout(\"%s\")\n", ut->ut_line);
|
|
|
|
logwtmp(ut->ut_line, "", "");
|
|
|
|
LogPrintf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut->ut_line);
|
|
|
|
}
|
|
|
|
login(ut);
|
|
|
|
LogPrintf(LogID0, "login(\"%s\", \"%.*s\")\n",
|
1998-04-19 23:09:03 +00:00
|
|
|
ut->ut_line, (int)(sizeof ut->ut_name), ut->ut_name);
|
1998-02-19 02:08:53 +00:00
|
|
|
ID0setuser();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ID0logout(const char *device)
|
|
|
|
{
|
|
|
|
struct utmp ut;
|
|
|
|
|
|
|
|
strncpy(ut.ut_line, device, sizeof ut.ut_line - 1);
|
|
|
|
ut.ut_line[sizeof ut.ut_line - 1] = '\0';
|
|
|
|
|
|
|
|
ID0set0();
|
|
|
|
if (logout(ut.ut_line)) {
|
|
|
|
LogPrintf(LogID0, "logout(\"%s\")\n", ut.ut_line);
|
|
|
|
logwtmp(ut.ut_line, "", "");
|
|
|
|
LogPrintf(LogID0, "logwtmp(\"%s\", \"\", \"\")\n", ut.ut_line);
|
|
|
|
} else
|
|
|
|
LogPrintf(LogERROR, "ID0logout: No longer logged in on %s\n", ut.ut_line);
|
|
|
|
ID0setuser();
|
|
|
|
}
|