/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-03-23 19:24:40 UTC
  • Revision ID: teddy@recompile.se-20140323192440-d71iiqxebsxf9u2v
Update GCC warning flags and function attributes to GCC 4.7.

* Makefile (WARN): Update to include almost all warning flags.
* plugin-runner.c (getplugin, add_to_char_array, add_argument,
                   add_environment, set_cloexec_flag,
                   print_out_password): Add attribute
                                        "warn_unused_result".
  (main/parse_opt): Bug fix: Add error checking to --global-env,
                    --env-for, --plugin-dir, and --config-file, and
                    make sure errno does not "leak" from unrelated
                    functions.
* plugins.d/mandos-client.c
  (fprintf_plus, debuggnutls, resolve_callback): Add "nonnull"
                                                 attribute.
  (incbuffer, add_server, init_gpgme): Add "nonnull" and
                                       "warn_unused_result"
                                       attributes.
  (pgp_packet_decrypt, init_gnutls_global): - '' -
  (init_gnutls_session start_mandos_communication, get_flags): - '' -
  (good_flags, good_interface, interface_is_up): - '' -
  (interface_is_running, runnable_hook): - '' -
  (avahi_loop_with_timeout, bring_up_interface): : - '' -
  (safer_gnutls_strerror): Add "warn_unused_result" attribute.
  (notdotentries): Set "nonnull", "pure", and "warn_unused_result"
                   attributes.
  (raise_privileges, raise_privileges_permanently, lower_privileges,
  lower_privileges_permanently): Set "warn_unused_result" attribute.
  (run_network_hooks): Exit child process if it fails to do anything
                       it needs to do.  Make explicit cast to double
                       when passing float value to asprintf().  Change
                       return type to void - all callers changed.
  (bring_up_interface): Move variables "sd", "ret_errno", and
                        "ret_setflags" to innermost scope.  Bug fix:
                        Fail if could not get interface flags also in
                        non-debug mode, and restore old errno
                        correctly.  Print message if could not raise
                        (or later lower) privileges.
  (take_down_interface): Bug fix: When failing because it could not
                         get interface flags, restore old errno
                         correctly.  Print message if it could not
                         raise (or later lower) privileges.
  (main): Complain if failed to raise or lower privileges.  Only run
          network hooks or lower privileges if raising privileges was
          successful.

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-2014 Teddy Hogeborn
13
 
 * Copyright © 2008-2014 Björn Påhlsson
 
12
 * Copyright © 2008-2013 Teddy Hogeborn
 
13
 * Copyright © 2008-2013 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 * const seckey,
262
 
                       const char * const pubkey,
263
 
                       const char * const tempdir,
264
 
                       mandos_context *mc){
 
261
static bool init_gpgme(const char *seckey, const char *pubkey,
 
262
                       const char *tempdir, mandos_context *mc){
265
263
  gpgme_error_t rc;
266
264
  gpgme_engine_info_t engine_info;
267
265
  
268
266
  /*
269
267
   * Helper function to insert pub and seckey to the engine keyring.
270
268
   */
271
 
  bool import_key(const char * const filename){
 
269
  bool import_key(const char *filename){
272
270
    int ret;
273
271
    int fd;
274
272
    gpgme_data_t pgp_data;
1715
1713
    
1716
1714
    /* Raise privileges */
1717
1715
    ret_errno = raise_privileges();
 
1716
    bool restore_loglevel = false;
1718
1717
    if(ret_errno != 0){
1719
1718
      perror_plus("Failed to raise privileges");
1720
1719
    }
1721
 
    
1722
1720
#ifdef __linux__
1723
1721
    int ret_linux;
1724
 
    bool restore_loglevel = false;
1725
1722
    if(ret_errno == 0){
1726
1723
      /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1727
1724
         messages about the network interface to mess up the prompt */
1827
1824
    if(ret_errno != 0){
1828
1825
      perror_plus("Failed to raise privileges");
1829
1826
    }
1830
 
    
1831
1827
    int ret_setflags = ioctl(sd, SIOCSIFFLAGS, &network);
1832
1828
    ioctl_errno = errno;
1833
1829
    
1875
1871
  int exitcode = EXIT_SUCCESS;
1876
1872
  char *interfaces_to_take_down = NULL;
1877
1873
  size_t interfaces_to_take_down_size = 0;
1878
 
  char run_tempdir[] = "/run/tmp/mandosXXXXXX";
1879
 
  char old_tempdir[] = "/tmp/mandosXXXXXX";
1880
 
  char *tempdir = NULL;
 
1874
  char tempdir[] = "/tmp/mandosXXXXXX";
 
1875
  bool tempdir_created = false;
1881
1876
  AvahiIfIndex if_index = AVAHI_IF_UNSPEC;
1882
1877
  const char *seckey = PATHDIR "/" SECKEY;
1883
1878
  const char *pubkey = PATHDIR "/" PUBKEY;
2332
2327
    goto end;
2333
2328
  }
2334
2329
  
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){
 
2330
  if(mkdtemp(tempdir) == NULL){
2345
2331
    perror_plus("mkdtemp");
2346
2332
    goto end;
2347
2333
  }
 
2334
  tempdir_created = true;
2348
2335
  
2349
2336
  if(quit_now){
2350
2337
    goto end;
2562
2549
        }
2563
2550
      }
2564
2551
    }
2565
 
    
2566
2552
    ret_errno = lower_privileges_permanently();
2567
2553
    if(ret_errno != 0){
2568
2554
      perror_plus("Failed to lower privileges permanently");
2573
2559
  free(interfaces_hooks);
2574
2560
  
2575
2561
  /* Removes the GPGME temp directory and all files inside */
2576
 
  if(tempdir != NULL){
 
2562
  if(tempdir_created){
2577
2563
    struct dirent **direntries = NULL;
2578
2564
    struct dirent *direntry = NULL;
2579
2565
    int numentries = scandir(tempdir, &direntries, notdotentries,