/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:
1458
1458
  error_t ret_errno = 0;
1459
1459
  if(seteuid(0) == -1){
1460
1460
    ret_errno = errno;
 
1461
    perror_plus("seteuid");
1461
1462
  }
1462
1463
  errno = old_errno;
1463
1464
  return ret_errno;
1474
1475
  }
1475
1476
  if(setuid(0) == -1){
1476
1477
    ret_errno = errno;
 
1478
    perror_plus("seteuid");
1477
1479
  }
1478
1480
  errno = old_errno;
1479
1481
  return ret_errno;
1486
1488
  error_t ret_errno = 0;
1487
1489
  if(seteuid(uid) == -1){
1488
1490
    ret_errno = errno;
 
1491
    perror_plus("seteuid");
1489
1492
  }
1490
1493
  errno = old_errno;
1491
1494
  return ret_errno;
1498
1501
  error_t ret_errno = 0;
1499
1502
  if(setuid(uid) == -1){
1500
1503
    ret_errno = errno;
 
1504
    perror_plus("setuid");
1501
1505
  }
1502
1506
  errno = old_errno;
1503
1507
  return ret_errno;
1506
1510
__attribute__((nonnull))
1507
1511
void run_network_hooks(const char *mode, const char *interface,
1508
1512
                       const float delay){
1509
 
  struct dirent **direntries = NULL;
 
1513
  struct dirent **direntries;
1510
1514
  if(hookdir_fd == -1){
1511
1515
    hookdir_fd = open(hookdir, O_RDONLY);
1512
1516
    if(hookdir_fd == -1){
1550
1554
    if(hook_pid == 0){
1551
1555
      /* Child */
1552
1556
      /* Raise privileges */
1553
 
      errno = raise_privileges_permanently();
1554
 
      if(errno != 0){
 
1557
      if(raise_privileges_permanently() != 0){
1555
1558
        perror_plus("Failed to raise privileges");
1556
1559
        _exit(EX_NOPERM);
1557
1560
      }
1667
1670
                   direntry->d_name);
1668
1671
    }
1669
1672
  }
1670
 
  free(direntries);
1671
1673
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1672
1674
    perror_plus("close");
1673
1675
  } else {
1730
1732
    /* Raise privileges */
1731
1733
    ret_errno = raise_privileges();
1732
1734
    if(ret_errno != 0){
1733
 
      errno = ret_errno;
1734
1735
      perror_plus("Failed to raise privileges");
1735
1736
    }
1736
1737
    
1840
1841
    /* Raise privileges */
1841
1842
    ret_errno = raise_privileges();
1842
1843
    if(ret_errno != 0){
1843
 
      errno = ret_errno;
1844
1844
      perror_plus("Failed to raise privileges");
1845
1845
    }
1846
1846
    
2274
2274
      }
2275
2275
      free(direntries);
2276
2276
    } else {
2277
 
      if(ret == 0){
2278
 
        free(direntries);
2279
 
      }
 
2277
      free(direntries);
2280
2278
      fprintf_plus(stderr, "Could not find a network interface\n");
2281
2279
      exitcode = EXIT_FAILURE;
2282
2280
      goto end;
2555
2553
  {
2556
2554
    ret_errno = raise_privileges();
2557
2555
    if(ret_errno != 0){
2558
 
      errno = ret_errno;
2559
2556
      perror_plus("Failed to raise privileges");
2560
2557
    } else {
2561
2558
      
2584
2581
    
2585
2582
    ret_errno = lower_privileges_permanently();
2586
2583
    if(ret_errno != 0){
2587
 
      errno = ret_errno;
2588
2584
      perror_plus("Failed to lower privileges permanently");
2589
2585
    }
2590
2586
  }
2612
2608
      int numentries = scandir(tempdir, &direntries, notdotentries,
2613
2609
                               alphasort);
2614
2610
#endif  /* not __GLIBC__ */
2615
 
      if(numentries >= 0){
 
2611
      if(numentries > 0){
2616
2612
        for(int i = 0; i < numentries; i++){
2617
2613
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2618
2614
          if(ret == -1){