Permalink
Browse files

added ability to run as different user than root

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@315 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
klacke committed Nov 27, 2002
1 parent 8a876cd commit 0c9da974461568c3ab731169f9b7e6f549c8105e
Showing with 2,388 additions and 43 deletions.
  1. +1 −1 Makefile
  2. +31 −0 c_src/Makefile
  3. +85 −0 c_src/setuid_drv.c
  4. +890 −0 config.guess
  5. +952 −0 config.sub
  6. +43 −5 include.mk → include.mk.in
  7. +2 −1 include/yaws.hrl
  8. +250 −0 install-sh
  9. +12 −0 man/yaws.conf.5
  10. +1 −1 src/yaws.erl
  11. +3 −0 src/yaws_config.erl
  12. +10 −6 src/yaws_ctl.erl
  13. +10 −2 src/yaws_log.erl
  14. +97 −26 src/yaws_server.erl
  15. +1 −1 src/yaws_sup.erl
View
@@ -1,4 +1,4 @@
-SUBDIRS = src scripts man www/shopingcart doc
+SUBDIRS = c_src src scripts man www/shopingcart doc
APPS = webmail
include ./include.mk
View
@@ -0,0 +1,31 @@
+include ../include.mk
+
+
+PRIV_FILES= ../priv/setuid_drv.$(DLL)
+
+CFLAGS += -I${ERLDIR}/usr/include
+
+#
+# Targets
+#
+
+all: $(PRIV_FILES)
+
+clean:
+ -rm -f $(PRIV_FILES) setuid_drv.$(OBJ)
+
+install:
+ install -d $(INSTALLPREFIX)/lib/yaws/priv
+ install ../priv/setuid_drv.$(DLL) $(INSTALLPREFIX)/lib/yaws/priv
+
+
+../priv/setuid_drv.$(DLL): setuid_drv.$(OBJ)
+ $(LD_SHARED) $(OUT)$@ setuid_drv.$(OBJ) $(DLL_LIBS)
+
+setuid_drv.$(OBJ): setuid_drv.c
+ $(CC) -c $(FPIC) $(CFLAGS) -DDYNAMIC_DRIVER setuid_drv.c
+
+
+
+
+
View
@@ -0,0 +1,85 @@
+/* author: klacke@hyber.org */
+/* purpose, make us run under a different username */
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#include "erl_driver.h"
+#ifndef ERL_DRV_NIL
+#include "erl_driver_compat.h"
+#endif
+
+
+
+static ErlDrvData setuid_start(ErlDrvPort port, char *buf);
+static void setuid_stop(ErlDrvData drv_data);
+
+static ErlDrvEntry setuid_driver_entry;
+
+
+/* buf is the name of the intented user */
+static ErlDrvData setuid_start(ErlDrvPort port, char *buf)
+{
+ char *t;
+ char xbuf[BUFSIZ];
+ struct passwd *pe;
+
+ if ((t = strchr(buf, ' ')) == NULL)
+ return (ErlDrvData) -1;
+ t++;
+
+ while ((pe = getpwent())) {
+ if (strcmp(pe->pw_name , t) == 0) {
+ if ((setuid(pe->pw_uid) != 0) ||
+ (setreuid(pe->pw_uid, pe->pw_uid) != 0)) {
+ return (ErlDrvData) -1;
+ }
+ sprintf(xbuf, "ok %d", pe->pw_uid);
+ endpwent();
+ driver_output(port,xbuf, strlen(xbuf));
+ return (ErlDrvData) port;
+ }
+ }
+ endpwent();
+ return (ErlDrvData) -1;
+}
+
+
+static void setuid_stop(ErlDrvData drv_data)
+{
+}
+
+
+
+
+/*
+ * Initialize and return a driver entry struct
+ */
+
+
+
+
+DRIVER_INIT(setuid_drv)
+{
+ setuid_driver_entry.init = NULL; /* Not used */
+ setuid_driver_entry.start = setuid_start;
+ setuid_driver_entry.stop = setuid_stop;
+ setuid_driver_entry.output = NULL;
+ setuid_driver_entry.ready_input = NULL;
+ setuid_driver_entry.ready_output = NULL;
+ setuid_driver_entry.driver_name = "setuid_drv";
+ setuid_driver_entry.finish = NULL;
+ setuid_driver_entry.control = NULL;
+ setuid_driver_entry.outputv = NULL;
+ return (ErlDrvEntry*) &setuid_driver_entry;
+}
+
+
Oops, something went wrong.

0 comments on commit 0c9da97

Please sign in to comment.