summaryrefslogtreecommitdiff
path: root/src/bin/supersu.c
blob: d3f7fece31fc686a6575abf9c2157bfdd015f92f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}