24
24
#define _GNU_SOURCE /* TEMP_FAILURE_RETRY() */
26
#include <stddef.h> /* size_t, NULL */
27
#include <stdlib.h> /* malloc(), exit(), EXIT_FAILURE,
28
EXIT_SUCCESS, realloc() */
29
#include <stdbool.h> /* bool, true, false */
30
#include <stdio.h> /* perror, popen(), fileno(),
31
fprintf(), stderr, STDOUT_FILENO */
32
#include <sys/types.h> /* DIR, opendir(), stat(), struct
33
stat, waitpid(), WIFEXITED(),
34
WEXITSTATUS(), wait(), pid_t,
35
uid_t, gid_t, getuid(), getgid(),
37
#include <sys/select.h> /* fd_set, select(), FD_ZERO(),
38
FD_SET(), FD_ISSET(), FD_CLR */
39
#include <sys/wait.h> /* wait(), waitpid(), WIFEXITED(),
41
#include <sys/stat.h> /* struct stat, stat(), S_ISREG() */
26
#include <stdio.h> /* popen(), fileno(), fprintf(),
27
stderr, STDOUT_FILENO */
42
28
#include <iso646.h> /* and, or, not */
29
#include <sys/types.h> /* DIR, opendir(), stat(),
30
struct stat, waitpid(),
31
WIFEXITED(), WEXITSTATUS(),
33
#include <sys/wait.h> /* wait() */
43
34
#include <dirent.h> /* DIR, struct dirent, opendir(),
44
readdir(), closedir(), dirfd() */
35
readdir(), closedir() */
36
#include <sys/stat.h> /* struct stat, stat(), S_ISREG() */
45
37
#include <unistd.h> /* struct stat, stat(), S_ISREG(),
46
fcntl(), setuid(), setgid(),
47
F_GETFD, F_SETFD, FD_CLOEXEC,
48
access(), pipe(), fork(), close()
49
dup2, STDOUT_FILENO, _exit(),
50
execv(), write(), read(),
52
#include <fcntl.h> /* fcntl(), F_GETFD, F_SETFD,
54
#include <string.h> /* strtok, strlen(), strcpy(),
39
#include <fcntl.h> /* fcntl() */
40
#include <stddef.h> /* NULL */
41
#include <stdlib.h> /* EXIT_FAILURE */
42
#include <sys/select.h> /* fd_set, select(), FD_ZERO(),
43
FD_SET(), FD_ISSET() */
44
#include <string.h> /* strlen(), strcpy(), strcat() */
45
#include <stdbool.h> /* true */
46
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
56
48
#include <errno.h> /* errno */
57
#include <argp.h> /* struct argp_option, struct
58
argp_state, struct argp,
59
argp_parse(), ARGP_ERR_UNKNOWN,
60
ARGP_KEY_END, ARGP_KEY_ARG, error_t */
61
#include <signal.h> /* struct sigaction, sigemptyset(),
62
sigaddset(), sigaction(),
63
sigprocmask(), SIG_BLOCK, SIGCHLD,
64
SIG_UNBLOCK, kill() */
65
#include <errno.h> /* errno, EBADF */
49
#include <argp.h> /* struct argp_option,
50
struct argp_state, struct argp,
67
53
#define BUFFER_SIZE 256
69
const char *argp_program_version = "mandos-client 1.0";
70
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
74
57
typedef struct process{
625
563
/* Bad exit by plugin */
627
565
if(WIFEXITED(proc->status)){
628
fprintf(stderr, "Plugin %u exited with status %d\n",
629
(unsigned int) (proc->pid),
630
WEXITSTATUS(proc->status));
566
fprintf(stderr, "Plugin %d exited with status %d\n",
567
proc->pid, WEXITSTATUS(proc->status));
631
568
} else if(WIFSIGNALED(proc->status)) {
632
fprintf(stderr, "Plugin %u killed by signal %d\n",
633
(unsigned int) (proc->pid),
634
WTERMSIG(proc->status));
569
fprintf(stderr, "Plugin %d killed by signal %d\n",
570
proc->pid, WTERMSIG(proc->status));
635
571
} else if(WCOREDUMP(proc->status)){
636
fprintf(stderr, "Plugin %d dumped core\n",
637
(unsigned int) (proc->pid));
572
fprintf(stderr, "Plugin %d dumped core\n", proc->pid);
640
575
/* Remove the plugin */
656
if(process_list == NULL){
657
fprintf(stderr, "All plugin processes failed, exiting\n");
658
exitstatus = EXIT_FAILURE;
719
if(process_list == NULL or exitstatus != EXIT_SUCCESS){
720
/* Fallback if all plugins failed, none are found or an error occured */
722
fprintf(stderr, "Going to fallback mode using getpass(3)\n");
723
char *passwordbuffer = getpass("Password: ");
724
bret = print_out_password(passwordbuffer, strlen(passwordbuffer));
726
perror("print_out_password");
727
exitstatus = EXIT_FAILURE;
732
662
/* Restore old signal handler */
733
663
sigaction(SIGCHLD, &old_sigchld_action, NULL);