/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 plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2014-06-14 22:55:11 UTC
  • Revision ID: teddy@recompile.se-20140614225511-0ge6tce2esulf65t
In plugin-runner, do scandirat() or scandir() instead of readdir().

* plugin-runner.c (set_cloexec_flag): Only define if O_CLOEXEC is not
                                      defined, it is not called
                                      otherwise.
  (main): Remove variables "dir" and "dirst"; new variable "dir_fd".
          Use scandirat() if available, scandir() otherwise, both
          using new filter function "good_name".  Removed checking of
          plugin file name patterns; this is now done by "good_name".
          Do not set FD_CLOEXEC flag on plugin_fd, since fexecve()
          will not work with it.  Use pipe2() to set O_CLOEXEC on pipe
          FD's (if possible).
  (main/good_name): New filter function for scandirat() or scandir().

Show diffs side-by-side

added added

removed removed

Lines of Context:
1510
1510
__attribute__((nonnull))
1511
1511
void run_network_hooks(const char *mode, const char *interface,
1512
1512
                       const float delay){
1513
 
  struct dirent **direntries = NULL;
 
1513
  struct dirent **direntries;
1514
1514
  if(hookdir_fd == -1){
1515
1515
    hookdir_fd = open(hookdir, O_RDONLY);
1516
1516
    if(hookdir_fd == -1){
1670
1670
                   direntry->d_name);
1671
1671
    }
1672
1672
  }
1673
 
  free(direntries);
1674
1673
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1675
1674
    perror_plus("close");
1676
1675
  } else {
2275
2274
      }
2276
2275
      free(direntries);
2277
2276
    } else {
2278
 
      if(ret == 0){
2279
 
        free(direntries);
2280
 
      }
 
2277
      free(direntries);
2281
2278
      fprintf_plus(stderr, "Could not find a network interface\n");
2282
2279
      exitcode = EXIT_FAILURE;
2283
2280
      goto end;
2611
2608
      int numentries = scandir(tempdir, &direntries, notdotentries,
2612
2609
                               alphasort);
2613
2610
#endif  /* not __GLIBC__ */
2614
 
      if(numentries >= 0){
 
2611
      if(numentries > 0){
2615
2612
        for(int i = 0; i < numentries; i++){
2616
2613
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2617
2614
          if(ret == -1){