/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2014-03-23 22:12:57 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: teddy@recompile.se-20140323221257-9lkufevfdn4kwoq6
Use openat() etc. in plugin-runner.  Also one less useless warning.

* plugin-runner.c (main): Only print warning about failure to work
                          around Debian bug #633582 if the plugin
                          directory actually exists.  Use openat(),
                          fstat(), faccessat(), and eliminate
                          asprintf().

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-2014 Teddy Hogeborn
6
 
 * Copyright © 2008-2014 Björn Påhlsson
 
5
 * Copyright © 2008-2013 Teddy Hogeborn
 
6
 * Copyright © 2008-2013 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
72
72
                                   EX_CONFIG, EX_UNAVAILABLE, EX_OK */
73
73
#include <errno.h>              /* errno */
74
74
#include <error.h>              /* error() */
75
 
#include <fnmatch.h>            /* fnmatch() */
76
75
 
77
76
#define BUFFER_SIZE 256
78
77
 
348
347
  char *plugindir = NULL;
349
348
  char *argfile = NULL;
350
349
  FILE *conffp;
 
350
  size_t d_name_len;
351
351
  DIR *dir = NULL;
352
352
  struct dirent *dirst;
353
353
  struct stat st;
862
862
      break;
863
863
    }
864
864
    
 
865
    d_name_len = strlen(dirst->d_name);
 
866
    
865
867
    /* Ignore dotfiles, backup files and other junk */
866
868
    {
867
869
      bool bad_name = false;
868
 
      const char * const patterns[] = { ".*", "#*#", "*~",
869
 
                                        "*.dpkg-new", "*.dpkg-old",
870
 
                                        "*.dpkg-bak", "*.dpkg-divert",
871
 
                                        NULL };
872
 
#ifdef __GNUC__
873
 
#pragma GCC diagnostic push
874
 
#pragma GCC diagnostic ignored "-Wcast-qual"
875
 
#endif
876
 
      for(const char **pat = (const char **)patterns;
877
 
          *pat != NULL; pat++){
878
 
#ifdef __GNUC__
879
 
#pragma GCC diagnostic pop
880
 
#endif
881
 
        if(fnmatch(*pat, dirst->d_name,
882
 
                   FNM_FILE_NAME | FNM_PERIOD) != FNM_NOMATCH){
883
 
          if(debug){
884
 
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
885
 
                    " matching pattern %s\n", dirst->d_name, *pat);
886
 
          }
887
 
          bad_name = true;
888
 
          break;
889
 
        }
890
 
      }
 
870
      
 
871
      const char * const bad_prefixes[] = { ".", "#", NULL };
 
872
      
 
873
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
 
874
                                           ".dpkg-old",
 
875
                                           ".dpkg-bak",
 
876
                                           ".dpkg-divert", NULL };
 
877
#ifdef __GNUC__
 
878
#pragma GCC diagnostic push
 
879
#pragma GCC diagnostic ignored "-Wcast-qual"
 
880
#endif
 
881
      for(const char **pre = (const char **)bad_prefixes;
 
882
          *pre != NULL; pre++){
 
883
#ifdef __GNUC__
 
884
#pragma GCC diagnostic pop
 
885
#endif
 
886
        size_t pre_len = strlen(*pre);
 
887
        if((d_name_len >= pre_len)
 
888
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
 
889
          if(debug){
 
890
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
891
                    " with bad prefix %s\n", dirst->d_name, *pre);
 
892
          }
 
893
          bad_name = true;
 
894
          break;
 
895
        }
 
896
      }
 
897
      if(bad_name){
 
898
        continue;
 
899
      }
 
900
#ifdef __GNUC__
 
901
#pragma GCC diagnostic push
 
902
#pragma GCC diagnostic ignored "-Wcast-qual"
 
903
#endif
 
904
      for(const char **suf = (const char **)bad_suffixes;
 
905
          *suf != NULL; suf++){
 
906
#ifdef __GNUC__
 
907
#pragma GCC diagnostic pop
 
908
#endif
 
909
        size_t suf_len = strlen(*suf);
 
910
        if((d_name_len >= suf_len)
 
911
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
 
912
                == 0)){
 
913
          if(debug){
 
914
            fprintf(stderr, "Ignoring plugin dir entry \"%s\""
 
915
                    " with bad suffix %s\n", dirst->d_name, *suf);
 
916
          }
 
917
          bad_name = true;
 
918
          break;
 
919
        }
 
920
      }
 
921
      
891
922
      if(bad_name){
892
923
        continue;
893
924
      }