2 * Copyright (c) 1987-2021 by the citadel.org team
4 * This program is open source software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
21 #include <sys/types.h>
32 #include "citadel_dirs.h"
33 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
34 int chkpwd_write_pipe[2];
35 int chkpwd_read_pipe[2];
38 * Validate a password on the host unix system by talking to the chkpwd daemon
40 static int validpw(uid_t uid, const char *pass)
45 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
47 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
51 rv = write(chkpwd_write_pipe[1], pass, 256);
53 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
56 rv = read(chkpwd_read_pipe[0], buf, 4);
58 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
61 if (!strncmp(buf, "PASS", 4)) {
71 * Start up the chkpwd daemon so validpw() has something to talk to
73 void start_chkpwd_daemon(void) {
75 struct stat filestats;
78 printf("Starting chkpwd daemon for host authentication mode\n");
80 if ((stat(file_chkpwd, &filestats)==-1) ||
81 (filestats.st_size==0)){
82 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
85 if (pipe(chkpwd_write_pipe) != 0) {
86 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
89 if (pipe(chkpwd_read_pipe) != 0) {
90 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
96 printf("Unable to fork chkpwd daemon: %s\n", strerror(errno));
99 if (chkpwd_pid == 0) {
100 dup2(chkpwd_write_pipe[0], 0);
101 dup2(chkpwd_read_pipe[1], 1);
102 for (i=2; i<256; ++i) close(i);
103 execl(file_chkpwd, file_chkpwd, NULL);
104 printf("Unable to exec chkpwd daemon: %s\n", strerror(errno));
112 int main(int argc, char **argv) {
116 char ctdldir[PATH_MAX]=CTDLDIR;
118 printf("\n\n ** host auth mode test utility **\n\n");
119 start_chkpwd_daemon();
122 printf("\n\nERROR: you need to be root to run this!\n\n");
126 printf("\n\nUsername: ");
127 fgets(buf, sizeof buf, stdin);
128 buf[strlen(buf)-1] = 0;
131 printf("Not found\n");
135 printf(" uid: %d\n", uid);
136 printf("Password: ");
137 fgets(buf, sizeof buf, stdin);
138 buf[strlen(buf)-1] = 0;