=== modified file 'TODO' --- TODO 2008-08-10 19:14:12 +0000 +++ TODO 2008-08-10 20:22:27 +0000 @@ -28,9 +28,6 @@ ** use strsep instead of strtok? ** use config file in addition to arguments ** pass things in environment, like device name, etc -** Fallback - As a fallback, if no plugins can be found or if all of them failed, - run getpass(3) itself. * Password-request ** [#A] Man page: man8/password-request.8mandos === modified file 'mandos-client.c' --- mandos-client.c 2008-08-10 03:32:42 +0000 +++ mandos-client.c 2008-08-10 20:22:27 +0000 @@ -170,6 +170,18 @@ proc->completed = true; } +bool print_out_password(const char *buffer, size_t length){ + size_t ret; + for(size_t written = 0; written < length; written += ret){ + ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written, + length - written)); + if(ret < 0){ + return false; + } + } + return true; +} + int main(int argc, char *argv[]){ const char *plugindir = "/conf/conf.d/mandos/plugins.d"; size_t d_name_len; @@ -583,9 +595,9 @@ dir = NULL; if (process_list == NULL){ - fprintf(stderr, "No plugin processes started, exiting\n"); - exitstatus = EXIT_FAILURE; - goto end; + fprintf(stderr, "No plugin processes started. Incorrect plugin" + " directory?\n"); + process_list = NULL; } while(process_list){ fd_set rfds = rfds_all; @@ -654,17 +666,11 @@ break; } /* This process exited nicely, so print its buffer */ - for(size_t written = 0; written < proc->buffer_length; - written += (size_t)ret){ - ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, - proc->buffer + written, - proc->buffer_length - - written)); - if(ret < 0){ - perror("write"); - exitstatus = EXIT_FAILURE; - goto end; - } + + bool bret = print_out_password(proc->buffer, proc->buffer_length); + if(not bret){ + perror("print_out_password"); + exitstatus = EXIT_FAILURE; } goto end; } @@ -699,12 +705,26 @@ } } } + if(process_list == NULL){ - fprintf(stderr, "All plugin processes failed, exiting\n"); - exitstatus = EXIT_FAILURE; + bool bret; + fprintf(stderr, "Going to fallback mode using getpass(3)\n"); + char *passwordbuffer = getpass("Password: "); + bret = print_out_password(passwordbuffer, strlen(passwordbuffer)); + if(not bret){ + perror("print_out_password"); + exitstatus = EXIT_FAILURE; + goto end; + } + bret = print_out_password("\n", 1); + if(not bret){ + perror("print_out_password"); + exitstatus = EXIT_FAILURE; + } } - + end: + /* Restore old signal handler */ sigaction(SIGCHLD, &old_sigchld_action, NULL);