/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-client.c

Fixed fallback on error in mandos-client
fixed a bug in password-request

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
}
172
172
 
173
173
bool print_out_password(const char *buffer, size_t length){
174
 
  size_t ret;
175
 
  for(size_t written = 0; written < length; written += ret){
 
174
  ssize_t ret;
 
175
  if(length>0 and buffer[length-1] == '\n'){
 
176
    length--;
 
177
  }
 
178
  for(size_t written = 0; written < length; written += (size_t)ret){
176
179
    ret = TEMP_FAILURE_RETRY(write(STDOUT_FILENO, buffer + written,
177
180
                                   length - written));
178
181
    if(ret < 0){
199
202
                                      .sa_flags = SA_NOCLDSTOP };
200
203
  char *plus_options = NULL;
201
204
  char **plus_argv = NULL;
 
205
 
 
206
  errno = 0;
202
207
  
203
208
  /* Establish a signal handler */
204
209
  sigemptyset(&sigchld_action.sa_mask);
304
309
  
305
310
  ret = argp_parse (&argp, argc, argv, 0, 0, &plugin_list);
306
311
  if (ret == ARGP_ERR_UNKNOWN){
307
 
    fprintf(stderr, "Unkown error while parsing arguments\n");
 
312
    fprintf(stderr, "Unknown error while parsing arguments\n");
308
313
    exitstatus = EXIT_FAILURE;
309
314
    goto end;
310
315
  }
341
346
    }
342
347
    ret = argp_parse (&argp, new_argc, plus_argv, 0, 0, &plugin_list);
343
348
    if (ret == ARGP_ERR_UNKNOWN){
344
 
      fprintf(stderr, "Unkown error while parsing arguments\n");
 
349
      fprintf(stderr, "Unknown error while parsing arguments\n");
345
350
      exitstatus = EXIT_FAILURE;
346
351
      goto end;
347
352
    }
705
710
      }
706
711
    }
707
712
  }
 
713
 
 
714
 
 
715
 end:
708
716
  
709
 
  if(process_list == NULL){
 
717
  if(process_list == NULL or exitstatus != EXIT_SUCCESS){
 
718
    /* Fallback if all plugins failed or an error occured */
710
719
    bool bret;
711
720
    fprintf(stderr, "Going to fallback mode using getpass(3)\n");
712
721
    char *passwordbuffer = getpass("Password: ");
716
725
      exitstatus = EXIT_FAILURE;
717
726
      goto end;
718
727
    }
719
 
    bret = print_out_password("\n", 1);
720
 
    if(not bret){
721
 
      perror("print_out_password");
722
 
      exitstatus = EXIT_FAILURE;
723
 
    }
724
728
  }
725
 
 
726
 
 end:
727
729
  
728
730
  /* Restore old signal handler */
729
731
  sigaction(SIGCHLD, &old_sigchld_action, NULL);