/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-08-10 21:23:46 UTC
  • mfrom: (237.4.57 release)
  • Revision ID: teddy@recompile.se-20150810212346-wvobzmqnnit9q8px
Merge from release branch.

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>             /* memset(), strcmp(), strlen(),
50
 
                                   strerror(), asprintf(), strcpy() */
 
49
#include <string.h>             /* strcmp(), strlen(), strerror(),
 
50
                                   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 = (int)TEMP_FAILURE_RETRY(close(fd));
 
308
    ret = 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 = (int)TEMP_FAILURE_RETRY(close(devnull));
 
934
    ret = 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);
957
958
      _exit(EX_UNAVAILABLE);
958
959
    }
959
 
    TEMP_FAILURE_RETRY(close(helperdir_fd));
 
960
    close(helperdir_fd);
960
961
#ifdef __GNUC__
961
962
#pragma GCC diagnostic push
962
963
#pragma GCC diagnostic ignored "-Wcast-qual"
1130
1131
    goto mandos_end;
1131
1132
  }
1132
1133
  
1133
 
  memset(&to, 0, sizeof(to));
1134
1134
  if(af == AF_INET6){
1135
 
    ((struct sockaddr_in6 *)&to)->sin6_family = (sa_family_t)af;
1136
 
    ret = inet_pton(af, ip, &((struct sockaddr_in6 *)&to)->sin6_addr);
 
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);
1137
1138
  } else {                      /* IPv4 */
1138
 
    ((struct sockaddr_in *)&to)->sin_family = (sa_family_t)af;
1139
 
    ret = inet_pton(af, ip, &((struct sockaddr_in *)&to)->sin_addr);
 
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);
1140
1142
  }
1141
1143
  if(ret < 0 ){
1142
1144
    int e = errno;
1465
1467
    free(decrypted_buffer);
1466
1468
    free(buffer);
1467
1469
    if(tcp_sd >= 0){
1468
 
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
 
1470
      ret = close(tcp_sd);
1469
1471
    }
1470
1472
    if(ret == -1){
1471
1473
      if(e == 0){
2010
2012
        perror_plus("openat");
2011
2013
        _exit(EXIT_FAILURE);
2012
2014
      }
2013
 
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2015
      if(close(hookdir_fd) == -1){
2014
2016
        perror_plus("close");
2015
2017
        _exit(EXIT_FAILURE);
2016
2018
      }
2019
2021
        perror_plus("dup2(devnull, STDIN_FILENO)");
2020
2022
        _exit(EX_OSERR);
2021
2023
      }
2022
 
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
 
2024
      ret = close(devnull);
2023
2025
      if(ret == -1){
2024
2026
        perror_plus("close");
2025
2027
        _exit(EX_OSERR);
2074
2076
    free(direntry);
2075
2077
  }
2076
2078
  free(direntries);
2077
 
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2079
  if(close(hookdir_fd) == -1){
2078
2080
    perror_plus("close");
2079
2081
  } else {
2080
2082
    hookdir_fd = -1;
2120
2122
    }
2121
2123
    
2122
2124
    if(quit_now){
2123
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2125
      ret = close(sd);
2124
2126
      if(ret == -1){
2125
2127
        perror_plus("close");
2126
2128
      }
2176
2178
    }
2177
2179
    
2178
2180
    /* Close the socket */
2179
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2181
    ret = close(sd);
2180
2182
    if(ret == -1){
2181
2183
      perror_plus("close");
2182
2184
    }
2264
2266
    }
2265
2267
    
2266
2268
    /* Close the socket */
2267
 
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2269
    int ret = close(sd);
2268
2270
    if(ret == -1){
2269
2271
      perror_plus("close");
2270
2272
    }
2286
2288
 
2287
2289
int main(int argc, char *argv[]){
2288
2290
  mandos_context mc = { .server = NULL, .dh_bits = 0,
2289
 
                        .priority = "SECURE256:!CTYPE-X.509:"
2290
 
                        "+CTYPE-OPENPGP:!RSA", .current_server = NULL,
2291
 
                        .interfaces = NULL, .interfaces_size = 0 };
 
2291
                        .priority = "SECURE256:!CTYPE-X.509"
 
2292
                        ":+CTYPE-OPENPGP:!RSA:+SIGN-DSA-SHA256",
 
2293
                        .current_server = NULL, .interfaces = NULL,
 
2294
                        .interfaces_size = 0 };
2292
2295
  AvahiSServiceBrowser *sb = NULL;
2293
2296
  error_t ret_errno;
2294
2297
  int ret;
2521
2524
              }
2522
2525
            }
2523
2526
          }
2524
 
          TEMP_FAILURE_RETRY(close(seckey_fd));
 
2527
          close(seckey_fd);
2525
2528
        }
2526
2529
      }
2527
2530
      
2542
2545
              }
2543
2546
            }
2544
2547
          }
2545
 
          TEMP_FAILURE_RETRY(close(pubkey_fd));
 
2548
          close(pubkey_fd);
 
2549
        }
 
2550
      }
 
2551
      
 
2552
      if(dh_params_file != NULL
 
2553
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2554
        int dhparams_fd = open(dh_params_file, O_RDONLY);
 
2555
        if(dhparams_fd == -1){
 
2556
          perror_plus("open");
 
2557
        } else {
 
2558
          ret = (int)TEMP_FAILURE_RETRY(fstat(dhparams_fd, &st));
 
2559
          if(ret == -1){
 
2560
            perror_plus("fstat");
 
2561
          } else {
 
2562
            if(S_ISREG(st.st_mode)
 
2563
               and st.st_uid == 0 and st.st_gid == 0){
 
2564
              ret = fchown(dhparams_fd, uid, gid);
 
2565
              if(ret == -1){
 
2566
                perror_plus("fchown");
 
2567
              }
 
2568
            }
 
2569
          }
 
2570
          close(dhparams_fd);
2546
2571
        }
2547
2572
      }
2548
2573
      
2725
2750
      errno = bring_up_interface(interface, delay);
2726
2751
      if(not interface_was_up){
2727
2752
        if(errno != 0){
2728
 
          perror_plus("Failed to bring up interface");
 
2753
          fprintf_plus(stderr, "Failed to bring up interface \"%s\":"
 
2754
                       " %s\n", interface, strerror(errno));
2729
2755
        } else {
2730
2756
          errno = argz_add(&interfaces_to_take_down,
2731
2757
                           &interfaces_to_take_down_size,
3060
3086
          perror_plus("rmdir");
3061
3087
        }
3062
3088
      }
3063
 
      TEMP_FAILURE_RETRY(close(tempdir_fd));
 
3089
      close(tempdir_fd);
3064
3090
    }
3065
3091
  }
3066
3092