13 #include <sys/types.h>
18 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
19 int chkpwd_write_pipe[2];
20 int chkpwd_read_pipe[2];
23 * Validate a password on the host unix system by talking to the chkpwd daemon
25 static int validpw(uid_t uid, const char *pass)
29 write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
30 write(chkpwd_write_pipe[1], pass, 256);
31 read(chkpwd_read_pipe[0], buf, 4);
33 if (!strncmp(buf, "PASS", 4)) {
43 * Start up the chkpwd daemon so validpw() has something to talk to
45 void start_chkpwd_daemon(void) {
49 printf("Starting chkpwd daemon for host authentication mode\n");
51 if (pipe(chkpwd_write_pipe) != 0) {
52 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
55 if (pipe(chkpwd_read_pipe) != 0) {
56 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
62 printf("Unable to fork chkpwd daemon: %s\n", strerror(errno));
65 if (chkpwd_pid == 0) {
66 dup2(chkpwd_write_pipe[0], 0);
67 dup2(chkpwd_read_pipe[1], 1);
68 for (i=2; i<256; ++i) close(i);
69 execl("./chkpwd", "chkpwd", NULL);
70 printf("Unable to exec chkpwd daemon: %s\n", strerror(errno));
78 int main(int argc, char **argv) {
83 printf("\n\n ** host auth mode test utility **\n\n");
84 start_chkpwd_daemon();
87 printf("\n\nUsername: ");
91 printf("Not found\n");
95 printf(" uid: %d\n", uid);