this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #470 from JL2210/update-src-tools-sudo

Update src/tools/sudo.c with more features

authored by

Luboš Doležel and committed by
GitHub
9216e47a b86fb4ad

+57 -15
+57 -15
src/tools/sudo.c
··· 1 1 #include <unistd.h> 2 2 #include <stdio.h> 3 + #include <string.h> 3 4 4 - int main(int argc, char** argv) 5 - { 6 - int firstarg = 1; 5 + unsigned int firstarg = 1, uid = 0, gid = 0; 7 6 8 - if (argc <= 1) 9 - { 10 - fprintf(stderr, "This is Darling fake sudo.\n" 11 - "Processes will think they run as UID/GID 0, but Linux kernel will still see your original UID.\n" 12 - "The purpose is to convince some tools that they can write into / or enable you to talk to certain system daemons\n."); 13 - return 1; 14 - } 7 + int argparse(int, char**); 8 + int usage(int, int); 15 9 16 - setuid(0); 17 - setgid(0); 10 + int main(int argc, char **argv) 11 + { 12 + if ( ( argparse(argc, argv) || usage(argc, 0) ) == 1 ) 13 + return 1; 18 14 19 - if (strcmp(argv[1], "-k") == 0) 20 - firstarg++; 15 + setuid(uid); 16 + setgid(gid); 21 17 22 18 execvp(argv[firstarg], &argv[firstarg]); 23 - perror("Cannot execute:"); 19 + perror("Error"); 24 20 return 1; 25 21 } 26 22 23 + int argparse(int argc, char **argv) 24 + { 25 + while( (argv[firstarg] != NULL) && (!strncmp(argv[firstarg], "-", 1)) ) 26 + { 27 + if(!strcmp(argv[firstarg], "-g")) 28 + { 29 + sscanf(argv[++firstarg], "%u", &gid); 30 + firstarg++; 31 + } 32 + else if(!strcmp(argv[firstarg], "-u")) 33 + { 34 + sscanf(argv[++firstarg], "%u", &uid); 35 + firstarg++; 36 + } 37 + else if(!strcmp(argv[firstarg], "--")) 38 + { 39 + firstarg++; 40 + break; 41 + } 42 + else if(!strcmp(argv[firstarg], "-k")) 43 + firstarg++; 44 + else if(!strcmp(argv[firstarg], "--help")) 45 + return usage(argc, 1); 46 + else 47 + { 48 + fprintf(stderr, "Unknown option: %s\n", argv[firstarg]); 49 + return usage(argc, 1); 50 + } 51 + } 52 + return 0; 53 + } 54 + 55 + int usage(int argc, int arg_help) 56 + { 57 + if (argc <= (int)firstarg || arg_help == 1) 58 + { 59 + fprintf(stderr, "This is a fake 'sudo' implementation, intended for use in Darling.\n" 60 + "Processes will think they are run as UID/GID 0, but they are still run as your original UID/GID.\n" 61 + "One purpose of this program is to convince some tools that they can write into '/'.\n" 62 + "Another is to enable you to talk to certain system daemons.\n" 63 + "\nUsage:\n" 64 + " sudo [-g GID] [-u UID] [-k] [--] COMMAND\n"); 65 + return 1; 66 + } 67 + return 0; 68 + }