Advertisement
AlexMatveev

Untitled

Mar 15th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.   FILE *fp;
  8.   uid_t uid;
  9.  
  10.   if(argc<2){
  11.     fprintf(srderr, "Usage: %s file_name\n", argv[0]);
  12.     exit(1);
  13.   }
  14.   printf("uid=%ld,  euid=%ld", getuid(), geteuid());
  15.   if((fp = fopen(argv[1], "r"))==NULL){
  16.     perror(argv[0]);
  17.     exit(2);
  18.   }
  19.   else{
  20.     printf("first open successful\n");
  21.     fclose(fp);
  22.   }
  23.   setuid(uid = getuid());
  24.   printf("after setuid(%ld):\n uid=%ld and euid=%ld\n", uid, getuid(), geteuid());
  25.   if((fp = fopen(argv[1], "r"))==NULL){
  26.     perror(argv[0]);
  27.     exit(2);
  28.   }
  29.   else{
  30.     printf("second open successful\n");
  31.     fclose(fp);
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement