/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: 2015-07-08 21:18:49 UTC
  • Revision ID: teddy@recompile.se-20150708211849-scisutuofnxumqc7
mandos-client: Add --dh-params FILE option.

* plugins.d/mandos-client.c: Added --dh-params FILE option.
  (init_gnutls_global): New "dhparamsfilename" argument.  All callers
                        changed.  Read and use Diffie-Hellman
                        parameters from it.  Bug fix:  check for error
                        when opening seckeyfile for the second time.
  (init_gnutls_session): Remove unnecessary call to
                         gnutls_dh_set_prime_bits();
  (main): New variable "dh_params_file".
  (main/argp_options): Added "--dh-params" option.
  (main/parse_opt): - '' -
* plugins.d/mandos-client.xml (SYNOPSIS): Add --dh-params option.
  (OPTIONS): Document --dh-params option and document that the
             --dh-bits options is potentially overridden by the
             --dh-params option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, srand(),
47
47
                                   strtof(), abort() */
48
48
#include <stdbool.h>            /* bool, false, true */
49
 
#include <string.h>             /* strcmp(), strlen(), strerror(),
50
 
                                   asprintf(), strcpy() */
 
49
#include <string.h>             /* memset(), strcmp(), strlen(),
 
50
                                   strerror(), asprintf(), strcpy() */
51
51
#include <sys/ioctl.h>          /* ioctl */
52
52
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
53
53
                                   sockaddr_in6, PF_INET6,
305
305
      return false;
306
306
    }
307
307
    
308
 
    ret = close(fd);
 
308
    ret = (int)TEMP_FAILURE_RETRY(close(fd));
309
309
    if(ret == -1){
310
310
      perror_plus("close");
311
311
    }
931
931
      perror_plus("dup2(devnull, STDIN_FILENO)");
932
932
      _exit(EX_OSERR);
933
933
    }
934
 
    ret = close(devnull);
 
934
    ret = (int)TEMP_FAILURE_RETRY(close(devnull));
935
935
    if(ret == -1){
936
936
      perror_plus("close");
937
937
      _exit(EX_OSERR);
956
956
      perror_plus("openat");
957
957
      _exit(EX_UNAVAILABLE);
958
958
    }
959
 
    close(helperdir_fd);
 
959
    TEMP_FAILURE_RETRY(close(helperdir_fd));
960
960
#ifdef __GNUC__
961
961
#pragma GCC diagnostic push
962
962
#pragma GCC diagnostic ignored "-Wcast-qual"
1130
1130
    goto mandos_end;
1131
1131
  }
1132
1132
  
 
1133
  memset(&to, 0, sizeof(to));
1133
1134
  if(af == AF_INET6){
1134
 
    struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&to;
1135
 
    *to6 = (struct sockaddr_in6){ .sin6_family = (sa_family_t)af };
1136
 
    ret = inet_pton(af, ip, &to6->sin6_addr);
 
1135
    ((struct sockaddr_in6 *)&to)->sin6_family = (sa_family_t)af;
 
1136
    ret = inet_pton(af, ip, &((struct sockaddr_in6 *)&to)->sin6_addr);
1137
1137
  } else {                      /* IPv4 */
1138
 
    struct sockaddr_in *to4 = (struct sockaddr_in *)&to;
1139
 
    *to4 = (struct sockaddr_in){ .sin_family = (sa_family_t)af };
1140
 
    ret = inet_pton(af, ip, &to4->sin_addr);
 
1138
    ((struct sockaddr_in *)&to)->sin_family = (sa_family_t)af;
 
1139
    ret = inet_pton(af, ip, &((struct sockaddr_in *)&to)->sin_addr);
1141
1140
  }
1142
1141
  if(ret < 0 ){
1143
1142
    int e = errno;
1466
1465
    free(decrypted_buffer);
1467
1466
    free(buffer);
1468
1467
    if(tcp_sd >= 0){
1469
 
      ret = close(tcp_sd);
 
1468
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
1470
1469
    }
1471
1470
    if(ret == -1){
1472
1471
      if(e == 0){
2011
2010
        perror_plus("openat");
2012
2011
        _exit(EXIT_FAILURE);
2013
2012
      }
2014
 
      if(close(hookdir_fd) == -1){
 
2013
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2015
2014
        perror_plus("close");
2016
2015
        _exit(EXIT_FAILURE);
2017
2016
      }
2020
2019
        perror_plus("dup2(devnull, STDIN_FILENO)");
2021
2020
        _exit(EX_OSERR);
2022
2021
      }
2023
 
      ret = close(devnull);
 
2022
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
2024
2023
      if(ret == -1){
2025
2024
        perror_plus("close");
2026
2025
        _exit(EX_OSERR);
2075
2074
    free(direntry);
2076
2075
  }
2077
2076
  free(direntries);
2078
 
  if(close(hookdir_fd) == -1){
 
2077
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2079
2078
    perror_plus("close");
2080
2079
  } else {
2081
2080
    hookdir_fd = -1;
2121
2120
    }
2122
2121
    
2123
2122
    if(quit_now){
2124
 
      ret = close(sd);
 
2123
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
2125
2124
      if(ret == -1){
2126
2125
        perror_plus("close");
2127
2126
      }
2177
2176
    }
2178
2177
    
2179
2178
    /* Close the socket */
2180
 
    ret = close(sd);
 
2179
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
2181
2180
    if(ret == -1){
2182
2181
      perror_plus("close");
2183
2182
    }
2265
2264
    }
2266
2265
    
2267
2266
    /* Close the socket */
2268
 
    int ret = close(sd);
 
2267
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
2269
2268
    if(ret == -1){
2270
2269
      perror_plus("close");
2271
2270
    }
2522
2521
              }
2523
2522
            }
2524
2523
          }
2525
 
          close(seckey_fd);
 
2524
          TEMP_FAILURE_RETRY(close(seckey_fd));
2526
2525
        }
2527
2526
      }
2528
2527
      
2543
2542
              }
2544
2543
            }
2545
2544
          }
2546
 
          close(pubkey_fd);
2547
 
        }
2548
 
      }
2549
 
      
2550
 
      if(strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
2551
 
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2552
 
        if(dhparams_fd == -1){
2553
 
          perror_plus("open");
2554
 
        } else {
2555
 
          ret = (int)TEMP_FAILURE_RETRY(fstat(dhparams_fd, &st));
2556
 
          if(ret == -1){
2557
 
            perror_plus("fstat");
2558
 
          } else {
2559
 
            if(S_ISREG(st.st_mode)
2560
 
               and st.st_uid == 0 and st.st_gid == 0){
2561
 
              ret = fchown(dhparams_fd, uid, gid);
2562
 
              if(ret == -1){
2563
 
                perror_plus("fchown");
2564
 
              }
2565
 
            }
2566
 
          }
2567
 
          close(dhparams_fd);
 
2545
          TEMP_FAILURE_RETRY(close(pubkey_fd));
2568
2546
        }
2569
2547
      }
2570
2548
      
2747
2725
      errno = bring_up_interface(interface, delay);
2748
2726
      if(not interface_was_up){
2749
2727
        if(errno != 0){
2750
 
          fprintf_plus(stderr, "Failed to bring up interface \"%s\":"
2751
 
                       " %s\n", interface, strerror(errno));
 
2728
          perror_plus("Failed to bring up interface");
2752
2729
        } else {
2753
2730
          errno = argz_add(&interfaces_to_take_down,
2754
2731
                           &interfaces_to_take_down_size,
3083
3060
          perror_plus("rmdir");
3084
3061
        }
3085
3062
      }
3086
 
      close(tempdir_fd);
 
3063
      TEMP_FAILURE_RETRY(close(tempdir_fd));
3087
3064
    }
3088
3065
  }
3089
3066