aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/supersu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/supersu.c')
-rw-r--r--src/bin/supersu.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bin/supersu.c b/src/bin/supersu.c
new file mode 100644
index 0000000..d3f7fec
--- /dev/null
+++ b/src/bin/supersu.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+
+int main(int argc,char *argv[]) {
+ int i;
+ if(argc < 4) {
+ fprintf(stderr,"usage: %s uid gid [secondary_gids] absolute-path-of-executable\n",argv[0]);
+ return 0;
+ }
+ if(getuid() && geteuid()) {
+ fprintf(stderr,"supersu: uid: %d, euid: %d... I have no idea how this is supposed to work. oh well.\n",getuid(),geteuid());
+ }
+ int groups[argc-2];
+ int ngroups=0;
+ char **name;
+ int here=0;
+ for(i=2;i<argc;i++) {
+ if(argv[i][0]=='/') {
+ here=i;
+ break;
+ }
+ }
+ if(here == 0) {
+ fprintf(stderr,"%s: I didn't find an absolute-path in the argument list.\n",argv[0]);
+ return 0;
+ }
+ ngroups=argc-(argc-here)-2;
+ for(i=2;i<here;i++) {
+ groups[i-2]=atoi(argv[i]);
+ }
+ name=argv+i;
+ setgroups(ngroups,groups);
+ setgid(atoi(argv[2]));
+ setuid(atoi(argv[1]));
+ execv(*name,name);
+}