Skip to content

Commit

Permalink
Import setuid.c
Browse files Browse the repository at this point in the history
Import setuid.c from mariux64/mxtools repository.
  • Loading branch information
donald committed Nov 16, 2020
0 parents commit a99b491
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions setuid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc,char **argv) {
uid_t uid;
char *end;
int status;

if (argc<3) {
fprintf(stderr,"usage: %s uid cmd...\n",argv[0]);
exit(1);
}
uid=strtoul(argv[1],&end,10);
if (end==argv[1] || *end != '\0') {
fprintf(stderr,"%s: %s: invalid uid\n",argv[0],argv[1]);
exit(1);
}
status=setuid(uid);
if (status==-1) {
perror(argv[0]);
exit(1);
}

status=execvp(argv[2],&argv[2]);
if (status==-1) {
perror(argv[0]);
exit(1);
}
exit(0);
}

0 comments on commit a99b491

Please sign in to comment.