/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: 2016-02-28 20:26:27 UTC
  • Revision ID: teddy@recompile.se-20160228202627-vls5dia6repq6ks2
Depend on the GNU C Library 2.16 or later 

* INSTALL: Document dependency.
* plugin-runner.c: Remove #ifdefs for scandirat() and adding of
                   -Wsign-conversion for FD_SET, FD_CLR, and FD_ISSET.
* plugins.d/mandos-client.c: - '' -

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-2015 Teddy Hogeborn
13
 
 * Copyright © 2008-2015 Björn Påhlsson
 
12
 * Copyright © 2008-2016 Teddy Hogeborn
 
13
 * Copyright © 2008-2016 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>             /* memset(), strcmp(), strlen(),
50
 
                                   strerror(), asprintf(), strcpy() */
 
49
#include <string.h>             /* strcmp(), strlen(), strerror(),
 
50
                                   asprintf(), strncpy() */
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;
1221
1223
                    sizeof(struct sockaddr_in));
1222
1224
    }
1223
1225
    if(ret < 0){
1224
 
      if(errno == ENETUNREACH
 
1226
      if(((errno == ENETUNREACH) or (errno == EHOSTUNREACH))
1225
1227
         and if_index != AVAHI_IF_UNSPEC
1226
1228
         and connect_to == NULL
1227
1229
         and not route_added and
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){
1635
1637
    errno = ret_errno;
1636
1638
    return false;
1637
1639
  }
1638
 
  strcpy(ifr->ifr_name, ifname);
 
1640
  strncpy(ifr->ifr_name, ifname, IF_NAMESIZE);
 
1641
  ifr->ifr_name[IF_NAMESIZE-1] = '\0'; /* NUL terminate */
1639
1642
  ret = ioctl(s, SIOCGIFFLAGS, ifr);
1640
1643
  if(ret == -1){
1641
1644
    if(debug){
1911
1914
      return;
1912
1915
    }
1913
1916
  }
1914
 
#ifdef __GLIBC__
1915
 
#if __GLIBC_PREREQ(2, 15)
1916
1917
  int numhooks = scandirat(hookdir_fd, ".", &direntries,
1917
1918
                           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__ */
1926
1919
  if(numhooks == -1){
1927
1920
    perror_plus("scandir");
1928
1921
    return;
2010
2003
        perror_plus("openat");
2011
2004
        _exit(EXIT_FAILURE);
2012
2005
      }
2013
 
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2006
      if(close(hookdir_fd) == -1){
2014
2007
        perror_plus("close");
2015
2008
        _exit(EXIT_FAILURE);
2016
2009
      }
2019
2012
        perror_plus("dup2(devnull, STDIN_FILENO)");
2020
2013
        _exit(EX_OSERR);
2021
2014
      }
2022
 
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
 
2015
      ret = close(devnull);
2023
2016
      if(ret == -1){
2024
2017
        perror_plus("close");
2025
2018
        _exit(EX_OSERR);
2074
2067
    free(direntry);
2075
2068
  }
2076
2069
  free(direntries);
2077
 
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2070
  if(close(hookdir_fd) == -1){
2078
2071
    perror_plus("close");
2079
2072
  } else {
2080
2073
    hookdir_fd = -1;
2120
2113
    }
2121
2114
    
2122
2115
    if(quit_now){
2123
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2116
      ret = close(sd);
2124
2117
      if(ret == -1){
2125
2118
        perror_plus("close");
2126
2119
      }
2176
2169
    }
2177
2170
    
2178
2171
    /* Close the socket */
2179
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2172
    ret = close(sd);
2180
2173
    if(ret == -1){
2181
2174
      perror_plus("close");
2182
2175
    }
2264
2257
    }
2265
2258
    
2266
2259
    /* Close the socket */
2267
 
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2260
    int ret = close(sd);
2268
2261
    if(ret == -1){
2269
2262
      perror_plus("close");
2270
2263
    }
2286
2279
 
2287
2280
int main(int argc, char *argv[]){
2288
2281
  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 };
 
2282
                        .priority = "SECURE256:!CTYPE-X.509"
 
2283
                        ":+CTYPE-OPENPGP:!RSA:+SIGN-DSA-SHA256",
 
2284
                        .current_server = NULL, .interfaces = NULL,
 
2285
                        .interfaces_size = 0 };
2292
2286
  AvahiSServiceBrowser *sb = NULL;
2293
2287
  error_t ret_errno;
2294
2288
  int ret;
2521
2515
              }
2522
2516
            }
2523
2517
          }
2524
 
          TEMP_FAILURE_RETRY(close(seckey_fd));
 
2518
          close(seckey_fd);
2525
2519
        }
2526
2520
      }
2527
2521
      
2542
2536
              }
2543
2537
            }
2544
2538
          }
2545
 
          TEMP_FAILURE_RETRY(close(pubkey_fd));
 
2539
          close(pubkey_fd);
2546
2540
        }
2547
2541
      }
2548
2542
      
2549
 
      if(strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2543
      if(dh_params_file != NULL
 
2544
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
2550
2545
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2551
2546
        if(dhparams_fd == -1){
2552
2547
          perror_plus("open");
2563
2558
              }
2564
2559
            }
2565
2560
          }
2566
 
          TEMP_FAILURE_RETRY(close(dhparams_fd));
 
2561
          close(dhparams_fd);
2567
2562
        }
2568
2563
      }
2569
2564
      
3049
3044
    if(tempdir_fd == -1){
3050
3045
      perror_plus("open");
3051
3046
    } else {
3052
 
#ifdef __GLIBC__
3053
 
#if __GLIBC_PREREQ(2, 15)
3054
3047
      int numentries = scandirat(tempdir_fd, ".", &direntries,
3055
3048
                                 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__ */
3064
3049
      if(numentries >= 0){
3065
3050
        for(int i = 0; i < numentries; i++){
3066
3051
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
3082
3067
          perror_plus("rmdir");
3083
3068
        }
3084
3069
      }
3085
 
      TEMP_FAILURE_RETRY(close(tempdir_fd));
 
3070
      close(tempdir_fd);
3086
3071
    }
3087
3072
  }
3088
3073