/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:
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);
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;
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){
2012
2010
        perror_plus("openat");
2013
2011
        _exit(EXIT_FAILURE);
2014
2012
      }
2015
 
      if(close(hookdir_fd) == -1){
 
2013
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2016
2014
        perror_plus("close");
2017
2015
        _exit(EXIT_FAILURE);
2018
2016
      }
2021
2019
        perror_plus("dup2(devnull, STDIN_FILENO)");
2022
2020
        _exit(EX_OSERR);
2023
2021
      }
2024
 
      ret = close(devnull);
 
2022
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
2025
2023
      if(ret == -1){
2026
2024
        perror_plus("close");
2027
2025
        _exit(EX_OSERR);
2076
2074
    free(direntry);
2077
2075
  }
2078
2076
  free(direntries);
2079
 
  if(close(hookdir_fd) == -1){
 
2077
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2080
2078
    perror_plus("close");
2081
2079
  } else {
2082
2080
    hookdir_fd = -1;
2122
2120
    }
2123
2121
    
2124
2122
    if(quit_now){
2125
 
      ret = close(sd);
 
2123
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
2126
2124
      if(ret == -1){
2127
2125
        perror_plus("close");
2128
2126
      }
2178
2176
    }
2179
2177
    
2180
2178
    /* Close the socket */
2181
 
    ret = close(sd);
 
2179
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
2182
2180
    if(ret == -1){
2183
2181
      perror_plus("close");
2184
2182
    }
2266
2264
    }
2267
2265
    
2268
2266
    /* Close the socket */
2269
 
    int ret = close(sd);
 
2267
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
2270
2268
    if(ret == -1){
2271
2269
      perror_plus("close");
2272
2270
    }
2288
2286
 
2289
2287
int main(int argc, char *argv[]){
2290
2288
  mandos_context mc = { .server = NULL, .dh_bits = 0,
2291
 
                        .priority = "SECURE256:!CTYPE-X.509"
2292
 
                        ":+CTYPE-OPENPGP:!RSA:+SIGN-DSA-SHA256",
2293
 
                        .current_server = NULL, .interfaces = NULL,
2294
 
                        .interfaces_size = 0 };
 
2289
                        .priority = "SECURE256:!CTYPE-X.509:"
 
2290
                        "+CTYPE-OPENPGP:!RSA", .current_server = NULL,
 
2291
                        .interfaces = NULL, .interfaces_size = 0 };
2295
2292
  AvahiSServiceBrowser *sb = NULL;
2296
2293
  error_t ret_errno;
2297
2294
  int ret;
2524
2521
              }
2525
2522
            }
2526
2523
          }
2527
 
          close(seckey_fd);
 
2524
          TEMP_FAILURE_RETRY(close(seckey_fd));
2528
2525
        }
2529
2526
      }
2530
2527
      
2545
2542
              }
2546
2543
            }
2547
2544
          }
2548
 
          close(pubkey_fd);
 
2545
          TEMP_FAILURE_RETRY(close(pubkey_fd));
2549
2546
        }
2550
2547
      }
2551
2548
      
2552
 
      if(dh_params_file != NULL
2553
 
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2549
      if(strcmp(dh_params_file, PATHDIR "/client-dhparams.pem" )
 
2550
         == 0){
2554
2551
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2555
2552
        if(dhparams_fd == -1){
2556
2553
          perror_plus("open");
2567
2564
              }
2568
2565
            }
2569
2566
          }
2570
 
          close(dhparams_fd);
 
2567
          TEMP_FAILURE_RETRY(close(dhparams_fd));
2571
2568
        }
2572
2569
      }
2573
2570
      
2750
2747
      errno = bring_up_interface(interface, delay);
2751
2748
      if(not interface_was_up){
2752
2749
        if(errno != 0){
2753
 
          fprintf_plus(stderr, "Failed to bring up interface \"%s\":"
2754
 
                       " %s\n", interface, strerror(errno));
 
2750
          perror_plus("Failed to bring up interface");
2755
2751
        } else {
2756
2752
          errno = argz_add(&interfaces_to_take_down,
2757
2753
                           &interfaces_to_take_down_size,
3086
3082
          perror_plus("rmdir");
3087
3083
        }
3088
3084
      }
3089
 
      close(tempdir_fd);
 
3085
      TEMP_FAILURE_RETRY(close(tempdir_fd));
3090
3086
    }
3091
3087
  }
3092
3088