/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: 2014-03-01 09:39:25 UTC
  • Revision ID: teddy@recompile.se-20140301093925-0x6nwf21f0zljk6e
* debian/copyright: Change year to "2014".
* mandos-ctl: - '' -
* mandos-monitor: - '' -
* plugins.d/mandos-client.xml: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
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)
1250
1226
      }
1251
1227
      /* Before reading, make the process' data buffer large enough */
1252
1228
      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){
 
1229
        proc->buffer = realloc(proc->buffer, proc->buffer_size
 
1230
                               + (size_t) BUFFER_SIZE);
 
1231
        if(proc->buffer == NULL){
1256
1232
          error(0, errno, "malloc");
1257
1233
          exitstatus = EX_OSERR;
1258
1234
          goto fallback;
1259
1235
        }
1260
 
        proc->buffer = new_buffer;
1261
1236
        proc->buffer_size += BUFFER_SIZE;
1262
1237
      }
1263
1238
      /* Read from the process */