/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-10 06:34:36 UTC
  • Revision ID: teddy@recompile.se-20140310063436-zksdghqvv6k1pbyg
Do not add a new server to server list if clock_gettime() fails

* plugins.d/mandos-client.c (add_server): Set server.last_seen before
                                          adding new server, in case
                                          clock_gettime() fails.

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;
178
179
  do {
179
 
    *array = realloc(*array, sizeof(char *)
180
 
                     * (size_t) ((*len) + 2));
181
 
  } while(*array == NULL and errno == EINTR);
 
180
    new_array = realloc(*array, sizeof(char *)
 
181
                        * (size_t) ((*len) + 2));
 
182
  } while(new_array == NULL and errno == EINTR);
182
183
  /* Malloc check */
183
 
  if(*array == NULL){
 
184
  if(new_array == NULL){
184
185
    return false;
185
186
  }
 
187
  *array = new_array;
186
188
  /* Make a copy of the new string */
187
189
  char *copy;
188
190
  do {
217
219
  /* namelen = length of name of environment variable */
218
220
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
219
221
  /* Search for this environment variable */
220
 
  for(char **e = p->environ; *e != NULL; e++){
221
 
    if(strncmp(*e, def, namelen + 1) == 0){
 
222
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
 
223
    if(strncmp(*envdef, def, namelen + 1) == 0){
222
224
      /* It already exists */
223
225
      if(replace){
224
 
        char *new;
 
226
        char *new_envdef;
225
227
        do {
226
 
          new = realloc(*e, strlen(def) + 1);
227
 
        } while(new == NULL and errno == EINTR);
228
 
        if(new == NULL){
 
228
          new_envdef = realloc(*envdef, strlen(def) + 1);
 
229
        } while(new_envdef == NULL and errno == EINTR);
 
230
        if(new_envdef == NULL){
229
231
          return false;
230
232
        }
231
 
        *e = new;
232
 
        strcpy(*e, def);
 
233
        *envdef = new_envdef;
 
234
        strcpy(*envdef, def);
233
235
      }
234
236
      return true;
235
237
    }
664
666
        }
665
667
        
666
668
        custom_argc += 1;
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;
 
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
          }
674
682
        }
675
683
        custom_argv[custom_argc-1] = new_arg;
676
684
        custom_argv[custom_argc] = NULL;
850
858
    {
851
859
      bool bad_name = false;
852
860
      
853
 
      const char const *bad_prefixes[] = { ".", "#", NULL };
 
861
      const char * const bad_prefixes[] = { ".", "#", NULL };
854
862
      
855
 
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
 
863
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
856
864
                                           ".dpkg-old",
857
865
                                           ".dpkg-bak",
858
866
                                           ".dpkg-divert", NULL };
859
 
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
 
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
860
876
        size_t pre_len = strlen(*pre);
861
877
        if((d_name_len >= pre_len)
862
878
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
871
887
      if(bad_name){
872
888
        continue;
873
889
      }
874
 
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
 
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
875
899
        size_t suf_len = strlen(*suf);
876
900
        if((d_name_len >= suf_len)
877
901
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
1226
1250
      }
1227
1251
      /* Before reading, make the process' data buffer large enough */
1228
1252
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1229
 
        proc->buffer = realloc(proc->buffer, proc->buffer_size
1230
 
                               + (size_t) BUFFER_SIZE);
1231
 
        if(proc->buffer == NULL){
 
1253
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
 
1254
                                   + (size_t) BUFFER_SIZE);
 
1255
        if(new_buffer == NULL){
1232
1256
          error(0, errno, "malloc");
1233
1257
          exitstatus = EX_OSERR;
1234
1258
          goto fallback;
1235
1259
        }
 
1260
        proc->buffer = new_buffer;
1236
1261
        proc->buffer_size += BUFFER_SIZE;
1237
1262
      }
1238
1263
      /* Read from the process */