summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2012-11-07 11:40:57 -0800
committerJulian Blake Kongslie <jblake@omgwallhack.org>2012-11-07 11:40:57 -0800
commit6d8606941c7bbdb72c76c81fef8eb91232ffc918 (patch)
treee4c9046aa399c437b709090d977f52bcfcc8fa21 /main.c
parentefeb94cdab68ecb81cae8b0bba816a6ee55207c2 (diff)
downloadinsecuresuexec-6d8606941c7bbdb72c76c81fef8eb91232ffc918.tar.gz
insecuresuexec-6d8606941c7bbdb72c76c81fef8eb91232ffc918.zip
Joe wanted it configurable. Laaame.
Diffstat (limited to 'main.c')
-rw-r--r--main.c62
1 files changed, 0 insertions, 62 deletions
diff --git a/main.c b/main.c
deleted file mode 100644
index 8d07953..0000000
--- a/main.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#define _GNU_SOURCE
-
-#include <assert.h>
-#include <errno.h>
-#include <grp.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-int main( int argc, char *argv[] ) {
-
- if ( argc < 4 ) {
- fprintf( stderr, "Usage: %s user group cmd [args..]\n", argv[0] );
- return 1;
- };
-
- char *user = argv[1];
- char *group = argv[2];
- char *cmd = argv[3];
- char **args = argv + 3;
-
- char *end;
- unsigned long tmp;
-
- struct passwd *userpw;
- struct group *grouppw;
-
- tmp = strtoul( user, &end, 10 );
- if ( end != user && ! *end ) {
- userpw = getpwuid( tmp );
- } else {
- userpw = getpwnam( user );
- };
- assert( userpw != NULL );
-
- tmp = strtoul( group, &end, 10 );
- if ( end != user && ! *end ) {
- grouppw = getgrgid( tmp );
- } else {
- grouppw = getgrnam( group );
- };
- assert( grouppw != NULL );
-
- // literally the only security check
- assert( grouppw->gr_gid != 0 );
- assert( userpw->pw_uid != 0 );
-
- if ( setgroups( 0, NULL ) != 0 )
- assert_perror( errno );
-
- if ( setregid( grouppw->gr_gid, grouppw->gr_gid ) != 0 )
- assert_perror( errno );
-
- if ( setreuid( userpw->pw_uid, userpw->pw_uid ) != 0 )
- assert_perror( errno );
-
- execv( cmd, args );
- assert_perror( errno );
-
-}