/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:28:32 UTC
  • Revision ID: teddy@recompile.se-20140607202832-02pucp4xd5nm646q
Minor bug fix in mandos-client: Remove memory leak for network hooks.

* plugins.d/mandos-client.c (runnable_hook): Call free() on full file
                                             name of network hook.

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){
1357
1359
    }
1358
1360
    return 0;
1359
1361
  }
 
1362
  free(fullname);
1360
1363
  if(not (S_ISREG(st.st_mode))){
1361
1364
    /* Not a regular file */
1362
1365
    if(debug){
1713
1716
    
1714
1717
    /* Raise privileges */
1715
1718
    ret_errno = raise_privileges();
 
1719
    if(ret_errno != 0){
 
1720
      perror_plus("Failed to raise privileges");
 
1721
    }
 
1722
    
 
1723
#ifdef __linux__
 
1724
    int ret_linux;
1716
1725
    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
1726
    if(ret_errno == 0){
1723
1727
      /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1724
1728
         messages about the network interface to mess up the prompt */
1824
1828
    if(ret_errno != 0){
1825
1829
      perror_plus("Failed to raise privileges");
1826
1830
    }
 
1831
    
1827
1832
    int ret_setflags = ioctl(sd, SIOCSIFFLAGS, &network);
1828
1833
    ioctl_errno = errno;
1829
1834
    
1871
1876
  int exitcode = EXIT_SUCCESS;
1872
1877
  char *interfaces_to_take_down = NULL;
1873
1878
  size_t interfaces_to_take_down_size = 0;
1874
 
  char tempdir[] = "/tmp/mandosXXXXXX";
1875
 
  bool tempdir_created = false;
 
1879
  char run_tempdir[] = "/run/tmp/mandosXXXXXX";
 
1880
  char old_tempdir[] = "/tmp/mandosXXXXXX";
 
1881
  char *tempdir = NULL;
1876
1882
  AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
1877
1883
  const char *seckey = PATHDIR "/" SECKEY;
1878
1884
  const char *pubkey = PATHDIR "/" PUBKEY;
2327
2333
    goto end;
2328
2334
  }
2329
2335
  
2330
 
  if(mkdtemp(tempdir) == NULL){
 
2336
  /* Try /run/tmp before /tmp */
 
2337
  tempdir = mkdtemp(run_tempdir);
 
2338
  if(tempdir == NULL and errno == ENOENT){
 
2339
      if(debug){
 
2340
        fprintf_plus(stderr, "Tempdir %s did not work, trying %s\n",
 
2341
                     run_tempdir, old_tempdir);
 
2342
      }
 
2343
      tempdir = mkdtemp(old_tempdir);
 
2344
  }
 
2345
  if(tempdir == NULL){
2331
2346
    perror_plus("mkdtemp");
2332
2347
    goto end;
2333
2348
  }
2334
 
  tempdir_created = true;
2335
2349
  
2336
2350
  if(quit_now){
2337
2351
    goto end;
2473
2487
  if(debug){
2474
2488
    fprintf_plus(stderr, "Starting Avahi loop search\n");
2475
2489
  }
2476
 
 
 
2490
  
2477
2491
  ret = avahi_loop_with_timeout(simple_poll,
2478
2492
                                (int)(retry_interval * 1000), &mc);
2479
2493
  if(debug){
2549
2563
        }
2550
2564
      }
2551
2565
    }
 
2566
    
2552
2567
    ret_errno = lower_privileges_permanently();
2553
2568
    if(ret_errno != 0){
2554
2569
      perror_plus("Failed to lower privileges permanently");
2559
2574
  free(interfaces_hooks);
2560
2575
  
2561
2576
  /* Removes the GPGME temp directory and all files inside */
2562
 
  if(tempdir_created){
 
2577
  if(tempdir != NULL){
2563
2578
    struct dirent **direntries = NULL;
2564
2579
    struct dirent *direntry = NULL;
2565
2580
    int numentries = scandir(tempdir, &direntries, notdotentries,
2582
2597
        free(fullname);
2583
2598
      }
2584
2599
    }
2585
 
 
 
2600
    
2586
2601
    /* need to clean even if 0 because man page doesn't specify */
2587
2602
    free(direntries);
2588
2603
    if(numentries == -1){