13 #include <sys/types.h>
24 #include "citadel_dirs.h"
25 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
26 int chkpwd_write_pipe
[2];
27 int chkpwd_read_pipe
[2];
30 * Validate a password on the host unix system by talking to the chkpwd daemon
32 static int validpw(uid_t uid
, const char *pass
)
36 write(chkpwd_write_pipe
[1], &uid
, sizeof(uid_t
));
37 write(chkpwd_write_pipe
[1], pass
, 256);
38 read(chkpwd_read_pipe
[0], buf
, 4);
40 if (!strncmp(buf
, "PASS", 4)) {
50 * Start up the chkpwd daemon so validpw() has something to talk to
52 void start_chkpwd_daemon(void) {
54 struct stat filestats
;
57 printf("Starting chkpwd daemon for host authentication mode\n");
59 if ((stat(file_chkpwd
, &filestats
)==-1) ||
60 (filestats
.st_size
==0)){
61 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd
, strerror(errno
));
64 if (pipe(chkpwd_write_pipe
) != 0) {
65 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno
));
68 if (pipe(chkpwd_read_pipe
) != 0) {
69 printf("Unable to create pipe for chkpwd daemon: %s\n", strerror(errno
));
75 printf("Unable to fork chkpwd daemon: %s\n", strerror(errno
));
78 if (chkpwd_pid
== 0) {
79 dup2(chkpwd_write_pipe
[0], 0);
80 dup2(chkpwd_read_pipe
[1], 1);
81 for (i
=2; i
<256; ++i
) close(i
);
82 execl(file_chkpwd
, file_chkpwd
, NULL
);
83 printf("Unable to exec chkpwd daemon: %s\n", strerror(errno
));
91 int main(int argc
, char **argv
) {
95 char ctdldir
[PATH_MAX
]=CTDLDIR
;
97 calc_dirs_n_files(0,0,"", ctdldir
, 0);
99 printf("\n\n ** host auth mode test utility **\n\n");
100 start_chkpwd_daemon();
103 printf("\n\nERROR: you need to be root to run this!\n\n");
107 printf("\n\nUsername: ");
108 fgets(buf
, sizeof buf
, stdin
);
109 buf
[strlen(buf
)-1] = 0;
112 printf("Not found\n");
116 printf(" uid: %d\n", uid
);
117 printf("Password: ");
118 fgets(buf
, sizeof buf
, stdin
);
119 buf
[strlen(buf
)-1] = 0;