/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-07 20:27:17 UTC
  • Revision ID: teddy@recompile.se-20140607202717-j5hiiinwg6osy9ss
Minor bug fix in mandos-client: Allow periods in network hook names.

* plugins.d/mandos-client.c (runnable_hook): Add "." to strspn() call
                                             to match documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2008-2013 Teddy Hogeborn
13
 
 * Copyright © 2008-2013 Björn Påhlsson
 
12
 * Copyright © 2008-2014 Teddy Hogeborn
 
13
 * Copyright © 2008-2014 Björn Påhlsson
14
14
 * 
15
15
 * This program is free software: you can redistribute it and/or
16
16
 * modify it under the terms of the GNU General Public License as
258
258
 * Initialize GPGME.
259
259
 */
260
260
__attribute__((nonnull, warn_unused_result))
261
 
static bool init_gpgme(const char *seckey, const char *pubkey,
262
 
                       const char *tempdir, mandos_context *mc){
 
261
static bool init_gpgme(const char * const seckey,
 
262
                       const char * const pubkey,
 
263
                       const char * const tempdir,
 
264
                       mandos_context *mc){
263
265
  gpgme_error_t rc;
264
266
  gpgme_engine_info_t engine_info;
265
267
  
266
268
  /*
267
269
   * Helper function to insert pub and seckey to the engine keyring.
268
270
   */
269
 
  bool import_key(const char *filename){
 
271
  bool import_key(const char * const filename){
270
272
    int ret;
271
273
    int fd;
272
274
    gpgme_data_t pgp_data;
1333
1335
  sret = strspn(direntry->d_name, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1334
1336
                "abcdefghijklmnopqrstuvwxyz"
1335
1337
                "0123456789"
1336
 
                "_-");
 
1338
                "_.-");
1337
1339
  if((direntry->d_name)[sret] != '\0'){
1338
1340
    /* Contains non-allowed characters */
1339
1341
    if(debug){
1713
1715
    
1714
1716
    /* Raise privileges */
1715
1717
    ret_errno = raise_privileges();
 
1718
    if(ret_errno != 0){
 
1719
      perror_plus("Failed to raise privileges");
 
1720
    }
 
1721
    
 
1722
#ifdef __linux__
 
1723
    int ret_linux;
1716
1724
    bool restore_loglevel = false;
1717
 
    if(ret_errno != 0){
1718
 
      perror_plus("Failed to raise privileges");
1719
 
    }
1720
 
#ifdef __linux__
1721
 
    int ret_linux;
1722
1725
    if(ret_errno == 0){
1723
1726
      /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1724
1727
         messages about the network interface to mess up the prompt */
1824
1827
    if(ret_errno != 0){
1825
1828
      perror_plus("Failed to raise privileges");
1826
1829
    }
 
1830
    
1827
1831
    int ret_setflags = ioctl(sd, SIOCSIFFLAGS, &network);
1828
1832
    ioctl_errno = errno;
1829
1833
    
1871
1875
  int exitcode = EXIT_SUCCESS;
1872
1876
  char *interfaces_to_take_down = NULL;
1873
1877
  size_t interfaces_to_take_down_size = 0;
1874
 
  char tempdir[] = "/tmp/mandosXXXXXX";
1875
 
  bool tempdir_created = false;
 
1878
  char run_tempdir[] = "/run/tmp/mandosXXXXXX";
 
1879
  char old_tempdir[] = "/tmp/mandosXXXXXX";
 
1880
  char *tempdir = NULL;
1876
1881
  AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
1877
1882
  const char *seckey = PATHDIR "/" SECKEY;
1878
1883
  const char *pubkey = PATHDIR "/" PUBKEY;
2327
2332
    goto end;
2328
2333
  }
2329
2334
  
2330
 
  if(mkdtemp(tempdir) == NULL){
 
2335
  /* Try /run/tmp before /tmp */
 
2336
  tempdir = mkdtemp(run_tempdir);
 
2337
  if(tempdir == NULL and errno == ENOENT){
 
2338
      if(debug){
 
2339
        fprintf_plus(stderr, "Tempdir %s did not work, trying %s\n",
 
2340
                     run_tempdir, old_tempdir);
 
2341
      }
 
2342
      tempdir = mkdtemp(old_tempdir);
 
2343
  }
 
2344
  if(tempdir == NULL){
2331
2345
    perror_plus("mkdtemp");
2332
2346
    goto end;
2333
2347
  }
2334
 
  tempdir_created = true;
2335
2348
  
2336
2349
  if(quit_now){
2337
2350
    goto end;
2473
2486
  if(debug){
2474
2487
    fprintf_plus(stderr, "Starting Avahi loop search\n");
2475
2488
  }
2476
 
 
 
2489
  
2477
2490
  ret = avahi_loop_with_timeout(simple_poll,
2478
2491
                                (int)(retry_interval * 1000), &mc);
2479
2492
  if(debug){
2549
2562
        }
2550
2563
      }
2551
2564
    }
 
2565
    
2552
2566
    ret_errno = lower_privileges_permanently();
2553
2567
    if(ret_errno != 0){
2554
2568
      perror_plus("Failed to lower privileges permanently");
2559
2573
  free(interfaces_hooks);
2560
2574
  
2561
2575
  /* Removes the GPGME temp directory and all files inside */
2562
 
  if(tempdir_created){
 
2576
  if(tempdir != NULL){
2563
2577
    struct dirent **direntries = NULL;
2564
2578
    struct dirent *direntry = NULL;
2565
2579
    int numentries = scandir(tempdir, &direntries, notdotentries,
2582
2596
        free(fullname);
2583
2597
      }
2584
2598
    }
2585
 
 
 
2599
    
2586
2600
    /* need to clean even if 0 because man page doesn't specify */
2587
2601
    free(direntries);
2588
2602
    if(numentries == -1){