/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-08 00:44:52 UTC
  • Revision ID: teddy@recompile.se-20140608004452-6p928psyr1gbcawn
Make mandos-client use more scandirat().

* plugins.d/mandos-client.d (main): Use scandirat() when removing
                                    GPGME temp directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1507
1507
  return ret_errno;
1508
1508
}
1509
1509
 
 
1510
#ifndef O_CLOEXEC
 
1511
/*
 
1512
 * Based on the example in the GNU LibC manual chapter 13.13 "File
 
1513
 * Descriptor Flags".
 
1514
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
 
1515
 */
 
1516
__attribute__((warn_unused_result))
 
1517
static int set_cloexec_flag(int fd){
 
1518
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
 
1519
  /* If reading the flags failed, return error indication now. */
 
1520
  if(ret < 0){
 
1521
    return ret;
 
1522
  }
 
1523
  /* Store modified flag word in the descriptor. */
 
1524
  return (int)TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD,
 
1525
                                       ret | FD_CLOEXEC));
 
1526
}
 
1527
#endif  /* not O_CLOEXEC */
 
1528
 
1510
1529
__attribute__((nonnull))
1511
1530
void run_network_hooks(const char *mode, const char *interface,
1512
1531
                       const float delay){
1513
1532
  struct dirent **direntries;
1514
1533
  if(hookdir_fd == -1){
1515
 
    hookdir_fd = open(hookdir, O_RDONLY);
 
1534
    hookdir_fd = open(hookdir, O_RDONLY |
 
1535
#ifdef O_CLOEXEC
 
1536
                      O_CLOEXEC
 
1537
#else  /* not O_CLOEXEC */
 
1538
                      0
 
1539
#endif  /* not O_CLOEXEC */
 
1540
                      );
1516
1541
    if(hookdir_fd == -1){
1517
1542
      if(errno == ENOENT){
1518
1543
        if(debug){
1524
1549
      }
1525
1550
      return;
1526
1551
    }
 
1552
#ifndef O_CLOEXEC
 
1553
    if(set_cloexec_flag(hookdir_fd) < 0){
 
1554
      perror_plus("set_cloexec_flag");
 
1555
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
1556
        perror_plus("close");
 
1557
      } else {
 
1558
        hookdir_fd = -1;
 
1559
      }
 
1560
      return;
 
1561
    }
 
1562
#endif  /* not O_CLOEXEC */
1527
1563
  }
1528
1564
#ifdef __GLIBC__
1529
1565
#if __GLIBC_PREREQ(2, 15)
1627
1663
          _exit(EX_OSERR);
1628
1664
        }
1629
1665
      }
1630
 
      int hook_fd = openat(hookdir_fd, direntry->d_name, O_RDONLY);
1631
 
      if(hook_fd == -1){
1632
 
        perror_plus("openat");
1633
 
        _exit(EXIT_FAILURE);
1634
 
      }
1635
 
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1636
 
        perror_plus("close");
1637
 
        _exit(EXIT_FAILURE);
1638
 
      }
1639
 
      if(fexecve(hook_fd, (char *const []){ direntry->d_name, NULL },
1640
 
                 environ) == -1){
 
1666
      if(fexecve(hookdir_fd, (char *const [])
 
1667
                 { direntry->d_name, NULL }, environ) == -1){
1641
1668
        perror_plus("fexecve");
1642
1669
        _exit(EXIT_FAILURE);
1643
1670
      }
2253
2280
  
2254
2281
  /* If no interfaces were specified, make a list */
2255
2282
  if(mc.interfaces == NULL){
2256
 
    struct dirent **direntries = NULL;
 
2283
    struct dirent **direntries;
2257
2284
    /* Look for any good interfaces */
2258
2285
    ret = scandir(sys_class_net, &direntries, good_interface,
2259
2286
                  alphasort);
2591
2618
  /* Removes the GPGME temp directory and all files inside */
2592
2619
  if(tempdir != NULL){
2593
2620
    struct dirent **direntries = NULL;
2594
 
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY |
2595
 
                                                  O_NOFOLLOW));
 
2621
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY));
2596
2622
    if(tempdir_fd == -1){
2597
2623
      perror_plus("open");
2598
2624
    } else {