summaryrefslogtreecommitdiff
path: root/usr.sbin/ppp/id.c
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>1997-11-23 20:27:41 +0000
committerbrian <brian@cvs.openbsd.org>1997-11-23 20:27:41 +0000
commit2cb79b0580b6b5629530c4d142a73a9a654f282f (patch)
tree8b062ff5e99e22ec2c95145149e22b58b7fc0e22 /usr.sbin/ppp/id.c
parent518c0071f44dfb9716d70e0d8781585db7a3bd7d (diff)
Import version 1.5 of ppp.
<sales> This is a user-level ppp implementation that uses the tun driver. It was originally created by a Japanese ISP. It's now piled with features. Check the man pages for details. </sales> The sources are identical to the ones in FreeBSD, except for the Makefile. IP aliasing (NAT) is disabled, and can be enabled by simply doing a ``make install'' of libalias, then rebuilding ppp. I'll create libalias as a port soon.
Diffstat (limited to 'usr.sbin/ppp/id.c')
-rw-r--r--usr.sbin/ppp/id.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/usr.sbin/ppp/id.c b/usr.sbin/ppp/id.c
new file mode 100644
index 00000000000..e9ce99a602f
--- /dev/null
+++ b/usr.sbin/ppp/id.c
@@ -0,0 +1,146 @@
+/*
+ * $Id: id.c,v 1.1 1997/11/23 20:27:34 brian Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include "command.h"
+#include "mbuf.h"
+#include "log.h"
+#include "main.h"
+#ifdef __OpenBSD__
+#include <util.h>
+#else
+#include <libutil.h>
+#endif
+#include "id.h"
+
+static int uid;
+static int gid;
+static int euid;
+static int egid;
+
+void
+ID0init()
+{
+ uid = getuid();
+ gid = getgid();
+ euid = geteuid();
+ egid = getegid();
+}
+
+static void
+ID0setuser(void)
+{
+ if (seteuid(uid) == -1) {
+ LogPrintf(LogERROR, "ID0setuser: Unable to seteuid!\n");
+ Cleanup(EX_NOPERM);
+ }
+}
+
+uid_t
+ID0realuid()
+{
+ return uid;
+}
+
+static void
+ID0set0(void)
+{
+ if (seteuid(euid) == -1) {
+ LogPrintf(LogERROR, "ID0set0: Unable to seteuid!\n");
+ Cleanup(EX_NOPERM);
+ }
+}
+
+int
+ID0ioctl(int fd, unsigned long req, void *arg)
+{
+ int ret;
+
+ ID0set0();
+ ret = ioctl(fd, req, arg);
+ LogPrintf(LogID0, "%d = ioctl(%d, %d, %p)\n", ret, fd, req, arg);
+ 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
+ID0open(const char *path, int flags)
+{
+ int ret;
+
+ ID0set0();
+ ret = open(path, flags);
+ LogPrintf(LogID0, "%d = open(\"%s\", %d)\n", ret, path, flags);
+ 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;
+}