-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Claes Wikstrom
committed
Nov 27, 2002
1 parent
8a876cd
commit 0c9da97
Showing
15 changed files
with
2,388 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
Oops, something went wrong.