/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 02:52:31 UTC
  • Revision ID: teddy@recompile.se-20140614025231-xpairrn1olkfgsek
plugin-runner: Do not leak file descriptors on certain errors.

* plugin-runner.c (main): If set_cloexec_flag fails, close pipe FD's.

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
                          .af = af };
235
235
  if(new_server->ip == NULL){
236
236
    perror_plus("strdup");
237
 
    free(new_server);
238
237
    return false;
239
238
  }
240
239
  ret = clock_gettime(CLOCK_MONOTONIC, &(new_server->last_seen));
241
240
  if(ret == -1){
242
241
    perror_plus("clock_gettime");
243
 
    free(new_server->ip);
244
 
    free(new_server);
245
242
    return false;
246
243
  }
247
244
  /* Special case of first server */
1461
1458
  error_t ret_errno = 0;
1462
1459
  if(seteuid(0) == -1){
1463
1460
    ret_errno = errno;
 
1461
    perror_plus("seteuid");
1464
1462
  }
1465
1463
  errno = old_errno;
1466
1464
  return ret_errno;
1477
1475
  }
1478
1476
  if(setuid(0) == -1){
1479
1477
    ret_errno = errno;
 
1478
    perror_plus("seteuid");
1480
1479
  }
1481
1480
  errno = old_errno;
1482
1481
  return ret_errno;
1489
1488
  error_t ret_errno = 0;
1490
1489
  if(seteuid(uid) == -1){
1491
1490
    ret_errno = errno;
 
1491
    perror_plus("seteuid");
1492
1492
  }
1493
1493
  errno = old_errno;
1494
1494
  return ret_errno;
1501
1501
  error_t ret_errno = 0;
1502
1502
  if(setuid(uid) == -1){
1503
1503
    ret_errno = errno;
 
1504
    perror_plus("setuid");
1504
1505
  }
1505
1506
  errno = old_errno;
1506
1507
  return ret_errno;
1509
1510
__attribute__((nonnull))
1510
1511
void run_network_hooks(const char *mode, const char *interface,
1511
1512
                       const float delay){
1512
 
  struct dirent **direntries = NULL;
 
1513
  struct dirent **direntries;
1513
1514
  if(hookdir_fd == -1){
1514
1515
    hookdir_fd = open(hookdir, O_RDONLY);
1515
1516
    if(hookdir_fd == -1){
1553
1554
    if(hook_pid == 0){
1554
1555
      /* Child */
1555
1556
      /* Raise privileges */
1556
 
      errno = raise_privileges_permanently();
1557
 
      if(errno != 0){
 
1557
      if(raise_privileges_permanently() != 0){
1558
1558
        perror_plus("Failed to raise privileges");
1559
1559
        _exit(EX_NOPERM);
1560
1560
      }
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 {
1733
1732
    /* Raise privileges */
1734
1733
    ret_errno = raise_privileges();
1735
1734
    if(ret_errno != 0){
1736
 
      errno = ret_errno;
1737
1735
      perror_plus("Failed to raise privileges");
1738
1736
    }
1739
1737
    
1843
1841
    /* Raise privileges */
1844
1842
    ret_errno = raise_privileges();
1845
1843
    if(ret_errno != 0){
1846
 
      errno = ret_errno;
1847
1844
      perror_plus("Failed to raise privileges");
1848
1845
    }
1849
1846
    
2277
2274
      }
2278
2275
      free(direntries);
2279
2276
    } else {
2280
 
      if(ret == 0){
2281
 
        free(direntries);
2282
 
      }
 
2277
      free(direntries);
2283
2278
      fprintf_plus(stderr, "Could not find a network interface\n");
2284
2279
      exitcode = EXIT_FAILURE;
2285
2280
      goto end;
2558
2553
  {
2559
2554
    ret_errno = raise_privileges();
2560
2555
    if(ret_errno != 0){
2561
 
      errno = ret_errno;
2562
2556
      perror_plus("Failed to raise privileges");
2563
2557
    } else {
2564
2558
      
2587
2581
    
2588
2582
    ret_errno = lower_privileges_permanently();
2589
2583
    if(ret_errno != 0){
2590
 
      errno = ret_errno;
2591
2584
      perror_plus("Failed to lower privileges permanently");
2592
2585
    }
2593
2586
  }
2615
2608
      int numentries = scandir(tempdir, &direntries, notdotentries,
2616
2609
                               alphasort);
2617
2610
#endif  /* not __GLIBC__ */
2618
 
      if(numentries >= 0){
 
2611
      if(numentries > 0){
2619
2612
        for(int i = 0; i < numentries; i++){
2620
2613
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2621
2614
          if(ret == -1){