1. Toby Davies
  2. backup-plan

Commits

None  committed 0d86365

[svn r20] Setuid now working & tested

  • Participants
  • Parent commits 82667a8
  • Branches trunk

Comments (0)

Files changed (1)

File backup-controller.c

View file
  • Ignore whitespace
 #include <unistd.h>
 #include <string.h>
-#define SCRIPT_NAME "backup-controller.sh"
+#include <stdlib.h>
+#include <stdio.h>
+#include <error.h>
+#include <pwd.h>
+
+#define SCRIPT_NAME "./backup-controller.sh"
+#define USER "tdavies"
+
+//extern int errno;
+
 int main(int argc, char** argv){
-  char* args[argc+1];
+  char** args=calloc(sizeof(char*),argc);;
+  struct passwd *pw=getpwnam(USER);
+  int i;
+
+  setuid(pw->pw_uid);
+
   args[0]=SCRIPT_NAME;
-  args[argc]=NULL;
-  memcpy(args+1,argv+1,argc-1);
-  return execvp(SCRIPT_NAME,args);
+  for(i=1;i<argc;i++){
+    args[i]=argv[i];
+  }
+
+  execvp(SCRIPT_NAME,args);
+  perror("Failed to exec " SCRIPT_NAME ": ");
+  return -1;
 }