+/*
+ * Start up the chkpwd daemon so validpw() has something to talk to
+ */
+void start_chkpwd_daemon(void) {
+ pid_t chkpwd_pid;
+ int i;
+
+ lprintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
+
+ if (pipe(chkpwd_write_pipe) != 0) {
+ lprintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
+ abort();
+ }
+ if (pipe(chkpwd_read_pipe) != 0) {
+ lprintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
+ abort();
+ }
+
+ chkpwd_pid = fork();
+ if (chkpwd_pid < 0) {
+ lprintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
+ abort();
+ }
+ if (chkpwd_pid == 0) {
+ lprintf(CTDL_DEBUG, "Now calling dup2() write\n");
+ dup2(chkpwd_write_pipe[0], 0);
+ lprintf(CTDL_DEBUG, "Now calling dup2() write\n");
+ dup2(chkpwd_read_pipe[1], 1);
+ lprintf(CTDL_DEBUG, "Now closing stuff\n");
+ for (i=2; i<256; ++i) close(i);
+ lprintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
+ execl(file_chkpwd, file_chkpwd, NULL);
+ lprintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
+ abort();
+ exit(errno);
+ }
+}
+
+