/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 20:30:35 UTC
  • Revision ID: teddy@recompile.se-20150716203035-z7qjwm270o2vrjah
Assume the C11 language (ISO 9899:2011), when compiling C code.

* Makefile (LANGUAGE): Changed to "-std=gnu11".

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);
956
956
      perror_plus("openat");
957
957
      _exit(EX_UNAVAILABLE);
958
958
    }
959
 
    close(helperdir_fd);
 
959
    TEMP_FAILURE_RETRY(close(helperdir_fd));
960
960
#ifdef __GNUC__
961
961
#pragma GCC diagnostic push
962
962
#pragma GCC diagnostic ignored "-Wcast-qual"
1130
1130
    goto mandos_end;
1131
1131
  }
1132
1132
  
 
1133
  memset(&to, 0, sizeof(to));
1133
1134
  if(af == AF_INET6){
1134
 
    struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&to;
1135
 
    *to6 = (struct sockaddr_in6){ .sin6_family = (sa_family_t)af };
1136
 
    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);
1137
1137
  } else {                      /* IPv4 */
1138
 
    struct sockaddr_in *to4 = (struct sockaddr_in *)&to;
1139
 
    *to4 = (struct sockaddr_in){ .sin_family = (sa_family_t)af };
1140
 
    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);
1141
1140
  }
1142
1141
  if(ret < 0 ){
1143
1142
    int e = errno;
1466
1465
    free(decrypted_buffer);
1467
1466
    free(buffer);
1468
1467
    if(tcp_sd >= 0){
1469
 
      ret = close(tcp_sd);
 
1468
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
1470
1469
    }
1471
1470
    if(ret == -1){
1472
1471
      if(e == 0){
2011
2010
        perror_plus("openat");
2012
2011
        _exit(EXIT_FAILURE);
2013
2012
      }
2014
 
      if(close(hookdir_fd) == -1){
 
2013
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2015
2014
        perror_plus("close");
2016
2015
        _exit(EXIT_FAILURE);
2017
2016
      }
2020
2019
        perror_plus("dup2(devnull, STDIN_FILENO)");
2021
2020
        _exit(EX_OSERR);
2022
2021
      }
2023
 
      ret = close(devnull);
 
2022
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
2024
2023
      if(ret == -1){
2025
2024
        perror_plus("close");
2026
2025
        _exit(EX_OSERR);
2075
2074
    free(direntry);
2076
2075
  }
2077
2076
  free(direntries);
2078
 
  if(close(hookdir_fd) == -1){
 
2077
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
2079
2078
    perror_plus("close");
2080
2079
  } else {
2081
2080
    hookdir_fd = -1;
2121
2120
    }
2122
2121
    
2123
2122
    if(quit_now){
2124
 
      ret = close(sd);
 
2123
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
2125
2124
      if(ret == -1){
2126
2125
        perror_plus("close");
2127
2126
      }
2177
2176
    }
2178
2177
    
2179
2178
    /* Close the socket */
2180
 
    ret = close(sd);
 
2179
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
2181
2180
    if(ret == -1){
2182
2181
      perror_plus("close");
2183
2182
    }
2265
2264
    }
2266
2265
    
2267
2266
    /* Close the socket */
2268
 
    int ret = close(sd);
 
2267
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
2269
2268
    if(ret == -1){
2270
2269
      perror_plus("close");
2271
2270
    }
2522
2521
              }
2523
2522
            }
2524
2523
          }
2525
 
          close(seckey_fd);
 
2524
          TEMP_FAILURE_RETRY(close(seckey_fd));
2526
2525
        }
2527
2526
      }
2528
2527
      
2543
2542
              }
2544
2543
            }
2545
2544
          }
2546
 
          close(pubkey_fd);
 
2545
          TEMP_FAILURE_RETRY(close(pubkey_fd));
2547
2546
        }
2548
2547
      }
2549
2548
      
2564
2563
              }
2565
2564
            }
2566
2565
          }
2567
 
          close(dhparams_fd);
 
2566
          TEMP_FAILURE_RETRY(close(dhparams_fd));
2568
2567
        }
2569
2568
      }
2570
2569
      
3083
3082
          perror_plus("rmdir");
3084
3083
        }
3085
3084
      }
3086
 
      close(tempdir_fd);
 
3085
      TEMP_FAILURE_RETRY(close(tempdir_fd));
3087
3086
    }
3088
3087
  }
3089
3088