/mandos/release

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

« back to all changes in this revision

Viewing changes to plugin-runner.c

* initramfs-tools-hook: Bug fix: Really install user-supplied plugins.
                        Bug fix: Warn about empty plugin directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
231
231
 */
232
232
static int set_cloexec_flag(int fd){
233
 
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
 
233
  int ret = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
234
234
  /* If reading the flags failed, return error indication now. */
235
235
  if(ret < 0){
236
236
    return ret;
237
237
  }
238
238
  /* Store modified flag word in the descriptor. */
239
 
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
240
 
                                       ret | FD_CLOEXEC));
 
239
  return TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, ret | FD_CLOEXEC));
241
240
}
242
241
 
243
242
 
789
788
    
790
789
    char *filename;
791
790
    if(plugindir == NULL){
792
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
793
 
                                             dirst->d_name));
 
791
      ret = TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
 
792
                                        dirst->d_name));
794
793
    } else {
795
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
796
 
                                             plugindir,
797
 
                                             dirst->d_name));
 
794
      ret = TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s", plugindir,
 
795
                                        dirst->d_name));
798
796
    }
799
797
    if(ret < 0){
800
798
      perror("asprintf");
801
799
      continue;
802
800
    }
803
801
    
804
 
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
 
802
    ret = TEMP_FAILURE_RETRY(stat(filename, &st));
805
803
    if(ret == -1){
806
804
      perror("stat");
807
805
      free(filename);
862
860
    }
863
861
    
864
862
    int pipefd[2];
865
 
    ret = (int)TEMP_FAILURE_RETRY(pipe(pipefd));
 
863
    ret = TEMP_FAILURE_RETRY(pipe(pipefd));
866
864
    if(ret == -1){
867
865
      perror("pipe");
868
866
      exitstatus = EXIT_FAILURE;
882
880
      goto fallback;
883
881
    }
884
882
    /* Block SIGCHLD until process is safely in process list */
885
 
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
886
 
                                              &sigchld_action.sa_mask,
887
 
                                              NULL));
 
883
    ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
 
884
                                         &sigchld_action.sa_mask,
 
885
                                         NULL));
888
886
    if(ret < 0){
889
887
      perror("sigprocmask");
890
888
      exitstatus = EXIT_FAILURE;
944
942
    plugin *new_plugin = getplugin(dirst->d_name);
945
943
    if(new_plugin == NULL){
946
944
      perror("getplugin");
947
 
      ret = (int)(TEMP_FAILURE_RETRY
948
 
                  (sigprocmask(SIG_UNBLOCK, &sigchld_action.sa_mask,
949
 
                               NULL)));
 
945
      ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
946
                                           &sigchld_action.sa_mask,
 
947
                                           NULL));
950
948
      if(ret < 0){
951
949
        perror("sigprocmask");
952
950
      }
959
957
    
960
958
    /* Unblock SIGCHLD so signal handler can be run if this process
961
959
       has already completed */
962
 
    ret = (int)TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
963
 
                                              &sigchld_action.sa_mask,
964
 
                                              NULL));
 
960
    ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
961
                                         &sigchld_action.sa_mask,
 
962
                                         NULL));
965
963
    if(ret < 0){
966
964
      perror("sigprocmask");
967
965
      exitstatus = EXIT_FAILURE;
968
966
      goto fallback;
969
967
    }
970
968
    
971
 
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
972
 
                                          -Wconversion */
 
969
    FD_SET(new_plugin->fd, &rfds_all);
973
970
    
974
971
    if(maxfd < new_plugin->fd){
975
972
      maxfd = new_plugin->fd;
1029
1026
          }
1030
1027
          
1031
1028
          /* Remove the plugin */
1032
 
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1033
 
                                          -Wconversion */
 
1029
          FD_CLR(proc->fd, &rfds_all);
1034
1030
          
1035
1031
          /* Block signal while modifying process_list */
1036
 
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1037
 
                                        (SIG_BLOCK,
1038
 
                                         &sigchld_action.sa_mask,
1039
 
                                         NULL));
 
1032
          ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_BLOCK,
 
1033
                                               &sigchld_action.sa_mask,
 
1034
                                               NULL));
1040
1035
          if(ret < 0){
1041
1036
            perror("sigprocmask");
1042
1037
            exitstatus = EXIT_FAILURE;
1048
1043
          proc = next_plugin;
1049
1044
          
1050
1045
          /* We are done modifying process list, so unblock signal */
1051
 
          ret = (int)(TEMP_FAILURE_RETRY
1052
 
                      (sigprocmask(SIG_UNBLOCK,
1053
 
                                   &sigchld_action.sa_mask, NULL)));
 
1046
          ret = TEMP_FAILURE_RETRY(sigprocmask(SIG_UNBLOCK,
 
1047
                                               &sigchld_action.sa_mask,
 
1048
                                               NULL));
1054
1049
          if(ret < 0){
1055
1050
            perror("sigprocmask");
1056
1051
            exitstatus = EXIT_FAILURE;
1076
1071
      }
1077
1072
      
1078
1073
      /* This process has not completed.  Does it have any output? */
1079
 
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1080
 
                                                         warning from
1081
 
                                                         -Wconversion */
 
1074
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1082
1075
        /* This process had nothing to say at this time */
1083
1076
        proc = proc->next;
1084
1077
        continue;