/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-27 21:24:33 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: teddy@recompile.se-20140327212433-oxdvfg1vsaagc6v0
Use fnmatch()in plugin-runner.

* plugin-runner.c (main): Use fnmatch().

Show diffs side-by-side

added added

removed removed

Lines of Context:
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() */
75
76
 
76
77
#define BUFFER_SIZE 256
77
78
 
347
348
  char *plugindir = NULL;
348
349
  char *argfile = NULL;
349
350
  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
 
    
867
865
    /* Ignore dotfiles, backup files and other junk */
868
866
    {
869
867
      bool bad_name = false;
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
 
      
 
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
      }
922
891
      if(bad_name){
923
892
        continue;
924
893
      }