]> www.infradead.org Git - users/dwmw2/crm114-spamd.git/commitdiff
setuid() for the given user
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 9 May 2006 21:08:00 +0000 (23:08 +0200)
committerJohannes Berg <johannes@johannes.berg>
Tue, 9 May 2006 21:08:00 +0000 (23:08 +0200)
dspam-spamd.c

index c1895ec7f812410e78dad2da385888fb3231a321..27b6a5487aa407e681a1e3adf465ccc3d34ee500 100644 (file)
@@ -1,10 +1,11 @@
+#include <sys/types.h>
+#include <pwd.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
 #include <sysexits.h>
-#include <sys/types.h>
 #include <sys/wait.h>
 
 #define ERROR(code,descr) do {                                         \
@@ -61,6 +62,13 @@ int main() {
        if (sscanf(buf, "User: %s", user) != 1)
                ERROR(EX_PROTOCOL, "invalid input line");
 
+       struct passwd *ps;
+       ps = getpwnam(user);
+       if (!ps)
+               ERROR(EX_TEMPFAIL, "user not found");
+       if (!setuid(ps->pw_uid))
+               ERROR(EX_TEMPFAIL, "cannot setuid");
+
        /* now an empty line */
        fgets(buf, sizeof(buf), stdin);
        buf[sizeof(buf)-1] = '\0';