/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-22 02:19:30 UTC
  • Revision ID: teddy@recompile.se-20140622021930-icl7h4cm97blhjml
mandos-keygen: Generate "checker" option to use SSH fingerprints.

To turn this off, use a new "--no-ssh" option to mandos-keygen.

* INSTALL (Mandos Server, Mandos Client): Document new suggested
                                          installation of SSH.
* Makefile (confdir/clients.conf): Use new "--no-ssh" option to
                                   "mandos-keygen".
* debian/control (mandos/Depends): Changed to "fping | ssh-client".
  (mandos-client/Recommends): New; set to "ssh".
* intro.xml (FREQUENTLY ASKED QUESTIONS): Rename and rewrite section
                                          called "Faking ping
                                          replies?" to address new
                                          default behavior.
* mandos-clients.conf.xml (OPTIONS/checker): Briefly discuss new
                                             behavior of
                                             mandos-keygen.
* mandos-keygen: Bug fix: Suppress failure output of "shred" to remove
                 "sec*", since no such files may exist.
 (password mode): Scan for SSH key fingerprints and output as new
                  "checker" and "ssh_fingerprint" options, unless new
                  "--no-ssh" option is given.
* mandos-keygen.xml (SYNOPSIS/--force): Bug fix: Document short form.
  (OPTIONS/--no-ssh): New.
  (SEE ALSO): Add reference "ssh-keyscan(1)".
* plugins.d/mandos-client.xml (SECURITY): Briefly mention the
                                          possibility of using SSH key
                                          fingerprints for checking.

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");
1462
1461
  }
1463
1462
  errno = old_errno;
1464
1463
  return ret_errno;
1475
1474
  }
1476
1475
  if(setuid(0) == -1){
1477
1476
    ret_errno = errno;
1478
 
    perror_plus("seteuid");
1479
1477
  }
1480
1478
  errno = old_errno;
1481
1479
  return ret_errno;
1488
1486
  error_t ret_errno = 0;
1489
1487
  if(seteuid(uid) == -1){
1490
1488
    ret_errno = errno;
1491
 
    perror_plus("seteuid");
1492
1489
  }
1493
1490
  errno = old_errno;
1494
1491
  return ret_errno;
1501
1498
  error_t ret_errno = 0;
1502
1499
  if(setuid(uid) == -1){
1503
1500
    ret_errno = errno;
1504
 
    perror_plus("setuid");
1505
1501
  }
1506
1502
  errno = old_errno;
1507
1503
  return ret_errno;
1508
1504
}
1509
1505
 
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
 
 
1529
1506
__attribute__((nonnull))
1530
1507
void run_network_hooks(const char *mode, const char *interface,
1531
1508
                       const float delay){
1532
 
  struct dirent **direntries;
 
1509
  struct dirent **direntries = NULL;
1533
1510
  if(hookdir_fd == -1){
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
 
                      );
 
1511
    hookdir_fd = open(hookdir, O_RDONLY);
1541
1512
    if(hookdir_fd == -1){
1542
1513
      if(errno == ENOENT){
1543
1514
        if(debug){
1549
1520
      }
1550
1521
      return;
1551
1522
    }
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 */
1563
1523
  }
1564
1524
#ifdef __GLIBC__
1565
1525
#if __GLIBC_PREREQ(2, 15)
1590
1550
    if(hook_pid == 0){
1591
1551
      /* Child */
1592
1552
      /* Raise privileges */
1593
 
      if(raise_privileges_permanently() != 0){
 
1553
      errno = raise_privileges_permanently();
 
1554
      if(errno != 0){
1594
1555
        perror_plus("Failed to raise privileges");
1595
1556
        _exit(EX_NOPERM);
1596
1557
      }
1663
1624
          _exit(EX_OSERR);
1664
1625
        }
1665
1626
      }
1666
 
      if(fexecve(hookdir_fd, (char *const [])
1667
 
                 { direntry->d_name, NULL }, environ) == -1){
 
1627
      int hook_fd = openat(hookdir_fd, direntry->d_name, O_RDONLY);
 
1628
      if(hook_fd == -1){
 
1629
        perror_plus("openat");
 
1630
        _exit(EXIT_FAILURE);
 
1631
      }
 
1632
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
1633
        perror_plus("close");
 
1634
        _exit(EXIT_FAILURE);
 
1635
      }
 
1636
      if(fexecve(hook_fd, (char *const []){ direntry->d_name, NULL },
 
1637
                 environ) == -1){
1668
1638
        perror_plus("fexecve");
1669
1639
        _exit(EXIT_FAILURE);
1670
1640
      }
1697
1667
                   direntry->d_name);
1698
1668
    }
1699
1669
  }
 
1670
  free(direntries);
1700
1671
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1701
1672
    perror_plus("close");
1702
1673
  } else {
1759
1730
    /* Raise privileges */
1760
1731
    ret_errno = raise_privileges();
1761
1732
    if(ret_errno != 0){
 
1733
      errno = ret_errno;
1762
1734
      perror_plus("Failed to raise privileges");
1763
1735
    }
1764
1736
    
1868
1840
    /* Raise privileges */
1869
1841
    ret_errno = raise_privileges();
1870
1842
    if(ret_errno != 0){
 
1843
      errno = ret_errno;
1871
1844
      perror_plus("Failed to raise privileges");
1872
1845
    }
1873
1846
    
2280
2253
  
2281
2254
  /* If no interfaces were specified, make a list */
2282
2255
  if(mc.interfaces == NULL){
2283
 
    struct dirent **direntries;
 
2256
    struct dirent **direntries = NULL;
2284
2257
    /* Look for any good interfaces */
2285
2258
    ret = scandir(sys_class_net, &direntries, good_interface,
2286
2259
                  alphasort);
2301
2274
      }
2302
2275
      free(direntries);
2303
2276
    } else {
2304
 
      free(direntries);
 
2277
      if(ret == 0){
 
2278
        free(direntries);
 
2279
      }
2305
2280
      fprintf_plus(stderr, "Could not find a network interface\n");
2306
2281
      exitcode = EXIT_FAILURE;
2307
2282
      goto end;
2580
2555
  {
2581
2556
    ret_errno = raise_privileges();
2582
2557
    if(ret_errno != 0){
 
2558
      errno = ret_errno;
2583
2559
      perror_plus("Failed to raise privileges");
2584
2560
    } else {
2585
2561
      
2608
2584
    
2609
2585
    ret_errno = lower_privileges_permanently();
2610
2586
    if(ret_errno != 0){
 
2587
      errno = ret_errno;
2611
2588
      perror_plus("Failed to lower privileges permanently");
2612
2589
    }
2613
2590
  }
2618
2595
  /* Removes the GPGME temp directory and all files inside */
2619
2596
  if(tempdir != NULL){
2620
2597
    struct dirent **direntries = NULL;
2621
 
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY));
 
2598
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY |
 
2599
                                                  O_NOFOLLOW));
2622
2600
    if(tempdir_fd == -1){
2623
2601
      perror_plus("open");
2624
2602
    } else {
2625
 
      int numentries = scandir(tempdir, &direntries, notdotentries,
2626
 
                               alphasort);
2627
 
      if(numentries > 0){
 
2603
#ifdef __GLIBC__
 
2604
#if __GLIBC_PREREQ(2, 15)
 
2605
      int numentries = scandirat(tempdir_fd, ".", &direntries,
 
2606
                                 notdotentries, alphasort);
 
2607
#else  /* not __GLIBC_PREREQ(2, 15) */
 
2608
      int numentries = scandir(tempdir, &direntries, notdotentries,
 
2609
                               alphasort);
 
2610
#endif  /* not __GLIBC_PREREQ(2, 15) */
 
2611
#else   /* not __GLIBC__ */
 
2612
      int numentries = scandir(tempdir, &direntries, notdotentries,
 
2613
                               alphasort);
 
2614
#endif  /* not __GLIBC__ */
 
2615
      if(numentries >= 0){
2628
2616
        for(int i = 0; i < numentries; i++){
2629
2617
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2630
2618
          if(ret == -1){