home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #define SECURE "/etc/secure"
-
- main(n, a)
- char **a;
- {
- int uid;
- FILE *fp;
- char program[100];
-
- if (strcmp(a[0], "SEC-URE"))/* I'm damned if I know why this is */
- { /* necessary, but it is */
- (void) strcpy(program, a[0]);
- a[0] = "SEC-URE";
- execv(program, a); /* re exec ourselves so setuid bits work */
- exit(1); /* this should never happen */
- }
- if ((fp = fopen(a[1], "r")) == (FILE *) NULL)
- exit(1); /* file not found */
- (void) fclose(fp);
- if (a[1][0] != '/')
- exit(1); /* only pass an absolute pathname to /bin/sh */
- if ((fp = fopen(SECURE, "r")) == (FILE *) NULL)
- exit(1); /* can't find the file of secure programs */
- while (fscanf(fp, "%s %d", program, &uid) == 2)
- {
- if (strcmp(program, a[1]) == 0)
- { /* aha ..... we found our program */
- (void) fclose(fp);
- (void) unsetenv("IFS");
- /* tweak the environment for added safety */
- (void) setenv("PATH", "/bin:/usr/bin", 1);
- (void) setuid(uid); /* set the uid */
- a[0] = "-sh";
- execv("/bin/sh", a);
- exit(1); /* this should never happen */
- }
- }
- exit(1); /* come here if we didn't find the program */
- }
-