32 extern int pedigree_login(
int uid,
char *password);
34 int main(
int argc,
char *argv[])
36 int iRunShell = 0, error = 0, help = 0, nStart = 0, i = 0;
37 for (i = 1; i < argc; i++)
39 if (!strcmp(argv[i],
"-s"))
41 else if (!strcmp(argv[i],
"-h"))
48 if (error || help || (!nStart && !iRunShell))
50 fprintf(stderr,
"Usage: sudo [-h] [-s|<command>]\n");
51 fprintf(stderr,
"\n");
52 fprintf(stderr,
" -s: Access root shell\n");
53 fprintf(stderr,
" -h: Show this help text\n");
58 struct passwd *pw = getpwnam(
"root");
61 fprintf(stderr,
"sudo: user 'root' doesn't exist!\n");
66 char password[256], c;
71 curt.c_lflag &= ~(ECHO | ICANON);
72 tcsetattr(0, TCSANOW, &curt);
74 printf(
"[sudo] Enter password: ");
77 while (i < 256 && (c = getchar()) !=
'\n')
94 curt.c_lflag |= (ECHO | ICANON);
95 tcsetattr(0, TCSANOW, &curt);
101 if (pedigree_login(pw->pw_uid, password) != 0)
103 fprintf(stderr,
"sudo: password is incorrect\n");
117 fprintf(stderr,
"sudo: couldn't fork: %s\n", strerror(errno));
123 execlp(pw->pw_shell, pw->pw_shell, 0);
126 fprintf(stderr,
"sudo: couldn't run shell: %s\n", strerror(errno));
133 waitpid(pid, &status, 0);
149 fprintf(stderr,
"sudo: couldn't fork: %s\n", strerror(errno));
155 execvp(argv[nStart], &argv[nStart]);
159 stderr,
"sudo: couldn't run command '%s': %s\n", argv[nStart],
167 waitpid(pid, &status, 0);