/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-09 20:32:52 UTC
  • Revision ID: teddy@recompile.se-20150709203252-u10p7trfsxc1a9yp
Install client Diffie-Hellman parameters into initramfs.

* debian/control (Package: mandos-client/Recommends): Added
  "gnutls-bin | openssl" (to generate DH parameters).
* debian/mandos-client.postinst (create_dh_params): New function
                                                    called on package
                                                    configure.
* plugins.d/mandos-client.c (main): Bug fix: Work around Debian bug
                                    #633582 also for the
                                    "client-dhparams.pem" file.

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-2016 Teddy Hogeborn
13
 
 * Copyright © 2008-2016 Björn Påhlsson
 
12
 * Copyright © 2008-2015 Teddy Hogeborn
 
13
 * Copyright © 2008-2015 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
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(), strncpy() */
 
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);
954
954
                                                   helper, O_RDONLY));
955
955
    if(helper_fd == -1){
956
956
      perror_plus("openat");
957
 
      close(helperdir_fd);
958
957
      _exit(EX_UNAVAILABLE);
959
958
    }
960
 
    close(helperdir_fd);
 
959
    TEMP_FAILURE_RETRY(close(helperdir_fd));
961
960
#ifdef __GNUC__
962
961
#pragma GCC diagnostic push
963
962
#pragma GCC diagnostic ignored "-Wcast-qual"
1131
1130
    goto mandos_end;
1132
1131
  }
1133
1132
  
 
1133
  memset(&to, 0, sizeof(to));
1134
1134
  if(af == AF_INET6){
1135
 
    struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&to;
1136
 
    *to6 = (struct sockaddr_in6){ .sin6_family = (sa_family_t)af };
1137
 
    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);
1138
1137
  } else {                      /* IPv4 */
1139
 
    struct sockaddr_in *to4 = (struct sockaddr_in *)&to;
1140
 
    *to4 = (struct sockaddr_in){ .sin_family = (sa_family_t)af };
1141
 
    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);
1142
1140
  }
1143
1141
  if(ret < 0 ){
1144
1142
    int e = errno;
1223
1221
                    sizeof(struct sockaddr_in));
1224
1222
    }
1225
1223
    if(ret < 0){
1226
 
      if(((errno == ENETUNREACH) or (errno == EHOSTUNREACH))
 
1224
      if(errno == ENETUNREACH
1227
1225
         and if_index != AVAHI_IF_UNSPEC
1228
1226
         and connect_to == NULL
1229
1227
         and not route_added and
1467
1465
    free(decrypted_buffer);
1468
1466
    free(buffer);
1469
1467
    if(tcp_sd >= 0){
1470
 
      ret = close(tcp_sd);
 
1468
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
1471
1469
    }
1472
1470
    if(ret == -1){
1473
1471
      if(e == 0){
1637
1635
    errno = ret_errno;
1638
1636
    return false;
1639
1637
  }
1640
 
  strncpy(ifr->ifr_name, ifname, IF_NAMESIZE);
1641
 
  ifr->ifr_name[IF_NAMESIZE-1] = '\0'; /* NUL terminate */
 
1638
  strcpy(ifr->ifr_name, ifname);
1642
1639
  ret = ioctl(s, SIOCGIFFLAGS, ifr);
1643
1640
  if(ret == -1){
1644
1641
    if(debug){
1914
1911
      return;
1915
1912
    }
1916
1913
  }
 
1914
#ifdef __GLIBC__
 
1915
#if __GLIBC_PREREQ(2, 15)
1917
1916
  int numhooks = scandirat(hookdir_fd, ".", &direntries,
1918
1917
                           runnable_hook, alphasort);
 
1918
#else  /* not __GLIBC_PREREQ(2, 15) */
 
1919
  int numhooks = scandir(hookdir, &direntries, runnable_hook,
 
1920
                         alphasort);
 
1921
#endif  /* not __GLIBC_PREREQ(2, 15) */
 
1922
#else   /* not __GLIBC__ */
 
1923
  int numhooks = scandir(hookdir, &direntries, runnable_hook,
 
1924
                         alphasort);
 
1925
#endif  /* not __GLIBC__ */
1919
1926
  if(numhooks == -1){
1920
1927
    perror_plus("scandir");
1921
1928
    return;
2003
2010
        perror_plus("openat");
2004
2011
        _exit(EXIT_FAILURE);
2005
2012
      }
2006
 
      if(close(hookdir_fd) == -1){
 
2013
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2007
2014
        perror_plus("close");
2008
2015
        _exit(EXIT_FAILURE);
2009
2016
      }
2012
2019
        perror_plus("dup2(devnull, STDIN_FILENO)");
2013
2020
        _exit(EX_OSERR);
2014
2021
      }
2015
 
      ret = close(devnull);
 
2022
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
2016
2023
      if(ret == -1){
2017
2024
        perror_plus("close");
2018
2025
        _exit(EX_OSERR);
2067
2074
    free(direntry);
2068
2075
  }
2069
2076
  free(direntries);
2070
 
  if(close(hookdir_fd) == -1){
 
2077
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2071
2078
    perror_plus("close");
2072
2079
  } else {
2073
2080
    hookdir_fd = -1;
2113
2120
    }
2114
2121
    
2115
2122
    if(quit_now){
2116
 
      ret = close(sd);
 
2123
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
2117
2124
      if(ret == -1){
2118
2125
        perror_plus("close");
2119
2126
      }
2169
2176
    }
2170
2177
    
2171
2178
    /* Close the socket */
2172
 
    ret = close(sd);
 
2179
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
2173
2180
    if(ret == -1){
2174
2181
      perror_plus("close");
2175
2182
    }
2257
2264
    }
2258
2265
    
2259
2266
    /* Close the socket */
2260
 
    int ret = close(sd);
 
2267
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
2261
2268
    if(ret == -1){
2262
2269
      perror_plus("close");
2263
2270
    }
2279
2286
 
2280
2287
int main(int argc, char *argv[]){
2281
2288
  mandos_context mc = { .server = NULL, .dh_bits = 0,
2282
 
                        .priority = "SECURE256:!CTYPE-X.509"
2283
 
                        ":+CTYPE-OPENPGP:!RSA:+SIGN-DSA-SHA256",
2284
 
                        .current_server = NULL, .interfaces = NULL,
2285
 
                        .interfaces_size = 0 };
 
2289
                        .priority = "SECURE256:!CTYPE-X.509:"
 
2290
                        "+CTYPE-OPENPGP:!RSA", .current_server = NULL,
 
2291
                        .interfaces = NULL, .interfaces_size = 0 };
2286
2292
  AvahiSServiceBrowser *sb = NULL;
2287
2293
  error_t ret_errno;
2288
2294
  int ret;
2515
2521
              }
2516
2522
            }
2517
2523
          }
2518
 
          close(seckey_fd);
 
2524
          TEMP_FAILURE_RETRY(close(seckey_fd));
2519
2525
        }
2520
2526
      }
2521
2527
      
2536
2542
              }
2537
2543
            }
2538
2544
          }
2539
 
          close(pubkey_fd);
 
2545
          TEMP_FAILURE_RETRY(close(pubkey_fd));
2540
2546
        }
2541
2547
      }
2542
2548
      
2543
 
      if(dh_params_file != NULL
2544
 
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2549
      if(strcmp(dh_params_file, PATHDIR "/client-dhparams.pem" )
 
2550
         == 0){
2545
2551
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2546
2552
        if(dhparams_fd == -1){
2547
2553
          perror_plus("open");
2558
2564
              }
2559
2565
            }
2560
2566
          }
2561
 
          close(dhparams_fd);
 
2567
          TEMP_FAILURE_RETRY(close(dhparams_fd));
2562
2568
        }
2563
2569
      }
2564
2570
      
2741
2747
      errno = bring_up_interface(interface, delay);
2742
2748
      if(not interface_was_up){
2743
2749
        if(errno != 0){
2744
 
          fprintf_plus(stderr, "Failed to bring up interface \"%s\":"
2745
 
                       " %s\n", interface, strerror(errno));
 
2750
          perror_plus("Failed to bring up interface");
2746
2751
        } else {
2747
2752
          errno = argz_add(&interfaces_to_take_down,
2748
2753
                           &interfaces_to_take_down_size,
3044
3049
    if(tempdir_fd == -1){
3045
3050
      perror_plus("open");
3046
3051
    } else {
 
3052
#ifdef __GLIBC__
 
3053
#if __GLIBC_PREREQ(2, 15)
3047
3054
      int numentries = scandirat(tempdir_fd, ".", &direntries,
3048
3055
                                 notdotentries, alphasort);
 
3056
#else  /* not __GLIBC_PREREQ(2, 15) */
 
3057
      int numentries = scandir(tempdir, &direntries, notdotentries,
 
3058
                               alphasort);
 
3059
#endif  /* not __GLIBC_PREREQ(2, 15) */
 
3060
#else   /* not __GLIBC__ */
 
3061
      int numentries = scandir(tempdir, &direntries, notdotentries,
 
3062
                               alphasort);
 
3063
#endif  /* not __GLIBC__ */
3049
3064
      if(numentries >= 0){
3050
3065
        for(int i = 0; i < numentries; i++){
3051
3066
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
3067
3082
          perror_plus("rmdir");
3068
3083
        }
3069
3084
      }
3070
 
      close(tempdir_fd);
 
3085
      TEMP_FAILURE_RETRY(close(tempdir_fd));
3071
3086
    }
3072
3087
  }
3073
3088