1 // Copyright (c) 1987-2022 by the citadel.org team
3 // This program is open source software. Use, duplication, or disclosure
4 // is subject to the terms of the GNU General Public License, version 3.
14 #include <sys/types.h>
21 #include "../server/citadel_defs.h"
22 #include "../server/server.h"
23 #include "../server/sysdep.h"
24 #include "../server/citadel_dirs.h"
26 // These pipes are used to talk to the chkpwd daemon, which is forked during startup
27 int chkpwd_write_pipe[2];
28 int chkpwd_read_pipe[2];
30 // Validate a password on the host unix system by talking to the chkpwd daemon
31 static int validpw(uid_t uid, const char *pass) {
35 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
37 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
41 rv = write(chkpwd_write_pipe[1], pass, 256);
43 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
46 rv = read(chkpwd_read_pipe[0], buf, 4);
48 printf( "Communicatino with chkpwd broken: %s\n", strerror(errno));
51 if (!strncmp(buf, "PASS", 4)) {
61 // Start up the chkpwd daemon so validpw() has something to talk to
62 void start_chkpwd_daemon(void) {
64 struct stat filestats;
67 printf("Starting chkpwd daemon for host authentication mode\n");
69 if ((stat(file_chkpwd, &filestats)==-1) || (filestats.st_size==0)){
70 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
73 if (pipe(chkpwd_write_pipe) != 0) {
74 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
77 if (pipe(chkpwd_read_pipe) != 0) {
78 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
84 printf("Unable to fork chkpwd daemon: %s\n", strerror(errno));
87 if (chkpwd_pid == 0) {
88 dup2(chkpwd_write_pipe[0], 0);
89 dup2(chkpwd_read_pipe[1], 1);
90 for (i=2; i<256; ++i) close(i);
91 execl(file_chkpwd, file_chkpwd, NULL);
92 printf("Unable to exec chkpwd daemon: %s\n", strerror(errno));
99 int main(int argc, char **argv) {
104 printf("\n\n ** host auth mode test utility **\n\n");
105 start_chkpwd_daemon();
108 printf("\n\nERROR: you need to be root to run this!\n\n");
112 printf("\n\nUsername: ");
113 fgets(buf, sizeof buf, stdin);
114 buf[strlen(buf)-1] = 0;
117 printf("Not found\n");
121 printf(" uid: %d\n", uid);
122 printf("Password: ");
123 fgets(buf, sizeof buf, stdin);
124 buf[strlen(buf)-1] = 0;