Skip to content

Commit

Permalink
added ability to run as different user than root
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@315 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Nov 27, 2002
1 parent 8a876cd commit 0c9da97
Show file tree
Hide file tree
Showing 15 changed files with 2,388 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
31 changes: 31 additions & 0 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -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





85 changes: 85 additions & 0 deletions c_src/setuid_drv.c
Original file line number Diff line number Diff line change
@@ -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;
}


Loading

0 comments on commit 0c9da97

Please sign in to comment.