/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 plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2013-06-23 15:13:06 UTC
  • Revision ID: teddy@recompile.se-20130623151306-3y4zwy76d95hcvpq
* mandos: Bug fix: Make boolean options work from the config file
          again.
          Bug fix: Make --no-ipv6 work again.
          Bug fix: Add extra magic to GnuTLS priority to make it work
          with current version of GnuTLS.
* mandos-options.xml (priority): Document new default value.
* mandos.conf (priority): - '' -
* plugins.d/mandos-client.xml (EXAMPLE): Minor grammar fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008-2013 Teddy Hogeborn
6
 
 * Copyright © 2008-2013 Björn Påhlsson
 
5
 * Copyright © 2008-2012 Teddy Hogeborn
 
6
 * Copyright © 2008-2012 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
175
175
static bool add_to_char_array(const char *new, char ***array,
176
176
                              int *len){
177
177
  /* Resize the pointed-to array to hold one more pointer */
178
 
  char **new_array = NULL;
179
178
  do {
180
 
    new_array = realloc(*array, sizeof(char *)
181
 
                        * (size_t) ((*len) + 2));
182
 
  } while(new_array == NULL and errno == EINTR);
 
179
    *array = realloc(*array, sizeof(char *)
 
180
                     * (size_t) ((*len) + 2));
 
181
  } while(*array == NULL and errno == EINTR);
183
182
  /* Malloc check */
184
 
  if(new_array == NULL){
 
183
  if(*array == NULL){
185
184
    return false;
186
185
  }
187
 
  *array = new_array;
188
186
  /* Make a copy of the new string */
189
187
  char *copy;
190
188
  do {
219
217
  /* namelen = length of name of environment variable */
220
218
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
221
219
  /* Search for this environment variable */
222
 
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
223
 
    if(strncmp(*envdef, def, namelen + 1) == 0){
 
220
  for(char **e = p->environ; *e != NULL; e++){
 
221
    if(strncmp(*e, def, namelen + 1) == 0){
224
222
      /* It already exists */
225
223
      if(replace){
226
 
        char *new_envdef;
 
224
        char *new;
227
225
        do {
228
 
          new_envdef = realloc(*envdef, strlen(def) + 1);
229
 
        } while(new_envdef == NULL and errno == EINTR);
230
 
        if(new_envdef == NULL){
 
226
          new = realloc(*e, strlen(def) + 1);
 
227
        } while(new == NULL and errno == EINTR);
 
228
        if(new == NULL){
231
229
          return false;
232
230
        }
233
 
        *envdef = new_envdef;
234
 
        strcpy(*envdef, def);
 
231
        *e = new;
 
232
        strcpy(*e, def);
235
233
      }
236
234
      return true;
237
235
    }
666
664
        }
667
665
        
668
666
        custom_argc += 1;
669
 
        {
670
 
          char **new_argv = realloc(custom_argv, sizeof(char *)
671
 
                                    * ((unsigned int)
672
 
                                       custom_argc + 1));
673
 
          if(new_argv == NULL){
674
 
            error(0, errno, "realloc");
675
 
            exitstatus = EX_OSERR;
676
 
            free(new_arg);
677
 
            free(org_line);
678
 
            goto fallback;
679
 
          } else {
680
 
            custom_argv = new_argv;
681
 
          }
 
667
        custom_argv = realloc(custom_argv, sizeof(char *)
 
668
                              * ((unsigned int) custom_argc + 1));
 
669
        if(custom_argv == NULL){
 
670
          error(0, errno, "realloc");
 
671
          exitstatus = EX_OSERR;
 
672
          free(org_line);
 
673
          goto fallback;
682
674
        }
683
675
        custom_argv[custom_argc-1] = new_arg;
684
676
        custom_argv[custom_argc] = NULL;
779
771
  }
780
772
  
781
773
  /* Lower permissions */
782
 
  ret = setgid(gid);
 
774
  setgid(gid);
783
775
  if(ret == -1){
784
776
    error(0, errno, "setgid");
785
777
  }
858
850
    {
859
851
      bool bad_name = false;
860
852
      
861
 
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
853
      const char const *bad_prefixes[] = { ".", "#", NULL };
862
854
      
863
 
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
855
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
864
856
                                           ".dpkg-old",
865
857
                                           ".dpkg-bak",
866
858
                                           ".dpkg-divert", NULL };
867
 
#ifdef __GNUC__
868
 
#pragma GCC diagnostic push
869
 
#pragma GCC diagnostic ignored "-Wcast-qual"
870
 
#endif
871
 
      for(const char **pre = (const char **)bad_prefixes;
872
 
          *pre != NULL; pre++){
873
 
#ifdef __GNUC__
874
 
#pragma GCC diagnostic pop
875
 
#endif
 
859
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
876
860
        size_t pre_len = strlen(*pre);
877
861
        if((d_name_len >= pre_len)
878
862
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
887
871
      if(bad_name){
888
872
        continue;
889
873
      }
890
 
#ifdef __GNUC__
891
 
#pragma GCC diagnostic push
892
 
#pragma GCC diagnostic ignored "-Wcast-qual"
893
 
#endif
894
 
      for(const char **suf = (const char **)bad_suffixes;
895
 
          *suf != NULL; suf++){
896
 
#ifdef __GNUC__
897
 
#pragma GCC diagnostic pop
898
 
#endif
 
874
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
899
875
        size_t suf_len = strlen(*suf);
900
876
        if((d_name_len >= suf_len)
901
877
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
1095
1071
      goto fallback;
1096
1072
    }
1097
1073
    
1098
 
#if defined (__GNUC__) and defined (__GLIBC__)
1099
 
#if not __GLIBC_PREREQ(2, 16)
1100
 
#pragma GCC diagnostic push
1101
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1102
 
#endif
1103
 
#endif
1104
1074
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1105
 
                                          -Wconversion in GNU libc
1106
 
                                          before 2.16 */
1107
 
#if defined (__GNUC__) and defined (__GLIBC__)
1108
 
#if not __GLIBC_PREREQ(2, 16)
1109
 
#pragma GCC diagnostic pop
1110
 
#endif
1111
 
#endif
 
1075
                                          -Wconversion */
1112
1076
    
1113
1077
    if(maxfd < new_plugin->fd){
1114
1078
      maxfd = new_plugin->fd;
1168
1132
          }
1169
1133
          
1170
1134
          /* Remove the plugin */
1171
 
#if defined (__GNUC__) and defined (__GLIBC__)
1172
 
#if not __GLIBC_PREREQ(2, 16)
1173
 
#pragma GCC diagnostic push
1174
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1175
 
#endif
1176
 
#endif
1177
1135
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1178
 
                                          -Wconversion in GNU libc
1179
 
                                          before 2.16 */
1180
 
#if defined (__GNUC__) and defined (__GLIBC__)
1181
 
#if not __GLIBC_PREREQ(2, 16)
1182
 
#pragma GCC diagnostic pop
1183
 
#endif
1184
 
#endif
 
1136
                                          -Wconversion */
1185
1137
          
1186
1138
          /* Block signal while modifying process_list */
1187
1139
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1227
1179
      }
1228
1180
      
1229
1181
      /* This process has not completed.  Does it have any output? */
1230
 
#if defined (__GNUC__) and defined (__GLIBC__)
1231
 
#if not __GLIBC_PREREQ(2, 16)
1232
 
#pragma GCC diagnostic push
1233
 
#pragma GCC diagnostic ignored "-Wsign-conversion"
1234
 
#endif
1235
 
#endif
1236
1182
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1237
1183
                                                         warning from
1238
 
                                                         -Wconversion
1239
 
                                                         in GNU libc
1240
 
                                                         before
1241
 
                                                         2.16 */
1242
 
#if defined (__GNUC__) and defined (__GLIBC__)
1243
 
#if not __GLIBC_PREREQ(2, 16)
1244
 
#pragma GCC diagnostic pop
1245
 
#endif
1246
 
#endif
 
1184
                                                         -Wconversion */
1247
1185
        /* This process had nothing to say at this time */
1248
1186
        proc = proc->next;
1249
1187
        continue;
1250
1188
      }
1251
1189
      /* Before reading, make the process' data buffer large enough */
1252
1190
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1253
 
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
1254
 
                                   + (size_t) BUFFER_SIZE);
1255
 
        if(new_buffer == NULL){
 
1191
        proc->buffer = realloc(proc->buffer, proc->buffer_size
 
1192
                               + (size_t) BUFFER_SIZE);
 
1193
        if(proc->buffer == NULL){
1256
1194
          error(0, errno, "malloc");
1257
1195
          exitstatus = EX_OSERR;
1258
1196
          goto fallback;
1259
1197
        }
1260
 
        proc->buffer = new_buffer;
1261
1198
        proc->buffer_size += BUFFER_SIZE;
1262
1199
      }
1263
1200
      /* Read from the process */