/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-16 23:01:02 UTC
  • Revision ID: teddy@recompile.se-20150716230102-62u5uwaguiufc6ac
mandos-client: Don't use memset().

* plugins.d/mandos-client.c (start_mandos_communication): Use compound
                                                          literal
                                                          struct
                                                          assignment
                                                          instead of
                                                          memset().

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
47
47
                                   strtof(), abort() */
48
48
#include <stdbool.h>            /* bool, false, true */
49
49
#include <string.h>             /* strcmp(), strlen(), strerror(),
50
 
                                   asprintf(), strncpy() */
 
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 = 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"
1223
1222
                    sizeof(struct sockaddr_in));
1224
1223
    }
1225
1224
    if(ret < 0){
1226
 
      if(((errno == ENETUNREACH) or (errno == EHOSTUNREACH))
 
1225
      if(errno == ENETUNREACH
1227
1226
         and if_index != AVAHI_IF_UNSPEC
1228
1227
         and connect_to == NULL
1229
1228
         and not route_added and
1467
1466
    free(decrypted_buffer);
1468
1467
    free(buffer);
1469
1468
    if(tcp_sd >= 0){
1470
 
      ret = close(tcp_sd);
 
1469
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
1471
1470
    }
1472
1471
    if(ret == -1){
1473
1472
      if(e == 0){
1637
1636
    errno = ret_errno;
1638
1637
    return false;
1639
1638
  }
1640
 
  strncpy(ifr->ifr_name, ifname, IF_NAMESIZE);
1641
 
  ifr->ifr_name[IF_NAMESIZE-1] = '\0'; /* NUL terminate */
 
1639
  strcpy(ifr->ifr_name, ifname);
1642
1640
  ret = ioctl(s, SIOCGIFFLAGS, ifr);
1643
1641
  if(ret == -1){
1644
1642
    if(debug){
2013
2011
        perror_plus("openat");
2014
2012
        _exit(EXIT_FAILURE);
2015
2013
      }
2016
 
      if(close(hookdir_fd) == -1){
 
2014
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2017
2015
        perror_plus("close");
2018
2016
        _exit(EXIT_FAILURE);
2019
2017
      }
2022
2020
        perror_plus("dup2(devnull, STDIN_FILENO)");
2023
2021
        _exit(EX_OSERR);
2024
2022
      }
2025
 
      ret = close(devnull);
 
2023
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
2026
2024
      if(ret == -1){
2027
2025
        perror_plus("close");
2028
2026
        _exit(EX_OSERR);
2077
2075
    free(direntry);
2078
2076
  }
2079
2077
  free(direntries);
2080
 
  if(close(hookdir_fd) == -1){
 
2078
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2081
2079
    perror_plus("close");
2082
2080
  } else {
2083
2081
    hookdir_fd = -1;
2123
2121
    }
2124
2122
    
2125
2123
    if(quit_now){
2126
 
      ret = close(sd);
 
2124
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
2127
2125
      if(ret == -1){
2128
2126
        perror_plus("close");
2129
2127
      }
2179
2177
    }
2180
2178
    
2181
2179
    /* Close the socket */
2182
 
    ret = close(sd);
 
2180
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
2183
2181
    if(ret == -1){
2184
2182
      perror_plus("close");
2185
2183
    }
2267
2265
    }
2268
2266
    
2269
2267
    /* Close the socket */
2270
 
    int ret = close(sd);
 
2268
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
2271
2269
    if(ret == -1){
2272
2270
      perror_plus("close");
2273
2271
    }
2289
2287
 
2290
2288
int main(int argc, char *argv[]){
2291
2289
  mandos_context mc = { .server = NULL, .dh_bits = 0,
2292
 
                        .priority = "SECURE256:!CTYPE-X.509"
2293
 
                        ":+CTYPE-OPENPGP:!RSA:+SIGN-DSA-SHA256",
2294
 
                        .current_server = NULL, .interfaces = NULL,
2295
 
                        .interfaces_size = 0 };
 
2290
                        .priority = "SECURE256:!CTYPE-X.509:"
 
2291
                        "+CTYPE-OPENPGP:!RSA", .current_server = NULL,
 
2292
                        .interfaces = NULL, .interfaces_size = 0 };
2296
2293
  AvahiSServiceBrowser *sb = NULL;
2297
2294
  error_t ret_errno;
2298
2295
  int ret;
2525
2522
              }
2526
2523
            }
2527
2524
          }
2528
 
          close(seckey_fd);
 
2525
          TEMP_FAILURE_RETRY(close(seckey_fd));
2529
2526
        }
2530
2527
      }
2531
2528
      
2546
2543
              }
2547
2544
            }
2548
2545
          }
2549
 
          close(pubkey_fd);
 
2546
          TEMP_FAILURE_RETRY(close(pubkey_fd));
2550
2547
        }
2551
2548
      }
2552
2549
      
2553
 
      if(dh_params_file != NULL
2554
 
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2550
      if(strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
2555
2551
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2556
2552
        if(dhparams_fd == -1){
2557
2553
          perror_plus("open");
2568
2564
              }
2569
2565
            }
2570
2566
          }
2571
 
          close(dhparams_fd);
 
2567
          TEMP_FAILURE_RETRY(close(dhparams_fd));
2572
2568
        }
2573
2569
      }
2574
2570
      
3087
3083
          perror_plus("rmdir");
3088
3084
        }
3089
3085
      }
3090
 
      close(tempdir_fd);
 
3086
      TEMP_FAILURE_RETRY(close(tempdir_fd));
3091
3087
    }
3092
3088
  }
3093
3089