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 snprintf(buf, sizeof buf, "%016d", uid);
30 write(chkpwd_write_pipe[1], buf, 16);
31 write(chkpwd_write_pipe[1], pass, 256);
32 read(chkpwd_read_pipe[0], buf, 4);
34 if (!strncmp(buf, "PASS", 4)) {
44 * Start up the chkpwd daemon so validpw() has something to talk to
46 void start_chkpwd_daemon(void) {
50 printf("Starting chkpwd daemon for host authentication mode\n");
52 if (pipe(chkpwd_write_pipe) != 0) {
53 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
56 if (pipe(chkpwd_read_pipe) != 0) {
57 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
63 printf("Unable to fork chkpwd daemon: %s\n", strerror(errno));
66 if (chkpwd_pid == 0) {
67 dup2(chkpwd_write_pipe[0], 0);
68 dup2(chkpwd_read_pipe[1], 1);
69 for (i=2; i<256; ++i) close(i);
70 execl("./chkpwd", "chkpwd", NULL);
71 printf("Unable to exec chkpwd daemon: %s\n", strerror(errno));
79 int main(int argc, char **argv) {
84 printf("\n\n ** host auth mode test utility **\n\n");
85 start_chkpwd_daemon();
88 printf("\n\nUsername: ");
92 printf("Not found\n");
96 printf(" uid: %d\n", uid);