...
|
...
|
@@ -2747,7 +2747,8 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2747
|
2747
|
} result;
|
2748
|
2748
|
#endif
|
2749
|
2749
|
char *dbfile;
|
2750
|
|
- int ret = CL_EOPEN, have_cld;
|
|
2750
|
+ int ret = CL_EOPEN, have_cld, ends_with_sep = 0;
|
|
2751
|
+ size_t dirname_len;
|
2751
|
2752
|
struct cl_cvd *daily_cld, *daily_cvd;
|
2752
|
2753
|
|
2753
|
2754
|
|
...
|
...
|
@@ -2758,6 +2759,14 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2758
|
2758
|
return CL_EOPEN;
|
2759
|
2759
|
}
|
2760
|
2760
|
|
|
2761
|
+ dirname_len = strlen(dirname);
|
|
2762
|
+ if(dirname_len >= strlen(PATHSEP)) {
|
|
2763
|
+ if(strcmp(dirname + dirname_len - strlen(PATHSEP), PATHSEP) == 0) {
|
|
2764
|
+ cli_dbgmsg("cli_loaddbdir(): dirname ends with separator\n");
|
|
2765
|
+ ends_with_sep = 1;
|
|
2766
|
+ }
|
|
2767
|
+ }
|
|
2768
|
+
|
2761
|
2769
|
/* first round - load .ign and .ign2 files */
|
2762
|
2770
|
#ifdef HAVE_READDIR_R_3
|
2763
|
2771
|
while(!readdir_r(dd, &result.d, &dent) && dent) {
|
...
|
...
|
@@ -2769,13 +2778,16 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2769
|
2769
|
if(dent->d_ino)
|
2770
|
2770
|
{
|
2771
|
2771
|
if(cli_strbcasestr(dent->d_name, ".ign") || cli_strbcasestr(dent->d_name, ".ign2")) {
|
2772
|
|
- dbfile = (char *) cli_malloc(strlen(dent->d_name) + strlen(dirname) + 2);
|
|
2772
|
+ dbfile = (char *) cli_malloc(strlen(dent->d_name) + dirname_len + 2);
|
2773
|
2773
|
if(!dbfile) {
|
2774
|
2774
|
cli_errmsg("cli_loaddbdir(): dbfile == NULL\n");
|
2775
|
2775
|
closedir(dd);
|
2776
|
2776
|
return CL_EMEM;
|
2777
|
2777
|
}
|
2778
|
|
- sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
|
|
2778
|
+ if(ends_with_sep)
|
|
2779
|
+ sprintf(dbfile, "%s%s", dirname, dent->d_name);
|
|
2780
|
+ else
|
|
2781
|
+ sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
|
2779
|
2782
|
ret = cli_load(dbfile, engine, signo, options, NULL);
|
2780
|
2783
|
if(ret) {
|
2781
|
2784
|
cli_errmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
|
...
|
...
|
@@ -2789,14 +2801,17 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2789
|
2789
|
}
|
2790
|
2790
|
|
2791
|
2791
|
/* the daily db must be loaded before main */
|
2792
|
|
- dbfile = (char *) cli_malloc(strlen(dirname) + 20);
|
|
2792
|
+ dbfile = (char *) cli_malloc(dirname_len + 20);
|
2793
|
2793
|
if(!dbfile) {
|
2794
|
2794
|
closedir(dd);
|
2795
|
2795
|
cli_errmsg("cli_loaddbdir: Can't allocate memory for dbfile\n");
|
2796
|
2796
|
return CL_EMEM;
|
2797
|
2797
|
}
|
2798
|
2798
|
|
2799
|
|
- sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
|
2799
|
+ if(ends_with_sep)
|
|
2800
|
+ sprintf(dbfile, "%sdaily.cld", dirname);
|
|
2801
|
+ else
|
|
2802
|
+ sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
2800
|
2803
|
have_cld = !access(dbfile, R_OK);
|
2801
|
2804
|
if(have_cld) {
|
2802
|
2805
|
daily_cld = cl_cvdhead(dbfile);
|
...
|
...
|
@@ -2807,7 +2822,10 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2807
|
2807
|
return CL_EMALFDB;
|
2808
|
2808
|
}
|
2809
|
2809
|
}
|
2810
|
|
- sprintf(dbfile, "%s"PATHSEP"daily.cvd", dirname);
|
|
2810
|
+ if(ends_with_sep)
|
|
2811
|
+ sprintf(dbfile, "%sdaily.cvd", dirname);
|
|
2812
|
+ else
|
|
2813
|
+ sprintf(dbfile, "%s"PATHSEP"daily.cvd", dirname);
|
2811
|
2814
|
if(!access(dbfile, R_OK)) {
|
2812
|
2815
|
if(have_cld) {
|
2813
|
2816
|
daily_cvd = cl_cvdhead(dbfile);
|
...
|
...
|
@@ -2818,12 +2836,19 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2818
|
2818
|
closedir(dd);
|
2819
|
2819
|
return CL_EMALFDB;
|
2820
|
2820
|
}
|
2821
|
|
- if(daily_cld->version > daily_cvd->version)
|
2822
|
|
- sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
|
2821
|
+ if(daily_cld->version > daily_cvd->version) {
|
|
2822
|
+ if(ends_with_sep)
|
|
2823
|
+ sprintf(dbfile, "%sdaily.cld", dirname);
|
|
2824
|
+ else
|
|
2825
|
+ sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
|
2826
|
+ }
|
2823
|
2827
|
cl_cvdfree(daily_cvd);
|
2824
|
2828
|
}
|
2825
|
2829
|
} else {
|
2826
|
|
- sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
|
2830
|
+ if(ends_with_sep)
|
|
2831
|
+ sprintf(dbfile, "%sdaily.cld", dirname);
|
|
2832
|
+ else
|
|
2833
|
+ sprintf(dbfile, "%s"PATHSEP"daily.cld", dirname);
|
2827
|
2834
|
}
|
2828
|
2835
|
if(have_cld)
|
2829
|
2836
|
cl_cvdfree(daily_cld);
|
...
|
...
|
@@ -2835,7 +2860,10 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2835
|
2835
|
}
|
2836
|
2836
|
|
2837
|
2837
|
/* try to load local.gdb next */
|
2838
|
|
- sprintf(dbfile, "%s"PATHSEP"local.gdb", dirname);
|
|
2838
|
+ if(ends_with_sep)
|
|
2839
|
+ sprintf(dbfile, "%slocal.gdb", dirname);
|
|
2840
|
+ else
|
|
2841
|
+ sprintf(dbfile, "%s"PATHSEP"local.gdb", dirname);
|
2839
|
2842
|
if(!access(dbfile, R_OK) && (ret = cli_load(dbfile, engine, signo, options, NULL))) {
|
2840
|
2843
|
free(dbfile);
|
2841
|
2844
|
closedir(dd);
|
...
|
...
|
@@ -2843,7 +2871,10 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2843
|
2843
|
}
|
2844
|
2844
|
|
2845
|
2845
|
/* check for and load daily.cfg */
|
2846
|
|
- sprintf(dbfile, "%s"PATHSEP"daily.cfg", dirname);
|
|
2846
|
+ if(ends_with_sep)
|
|
2847
|
+ sprintf(dbfile, "%sdaily.cfg", dirname);
|
|
2848
|
+ else
|
|
2849
|
+ sprintf(dbfile, "%s"PATHSEP"daily.cfg", dirname);
|
2847
|
2850
|
if(!access(dbfile, R_OK) && (ret = cli_load(dbfile, engine, signo, options, NULL))) {
|
2848
|
2851
|
free(dbfile);
|
2849
|
2852
|
closedir(dd);
|
...
|
...
|
@@ -2868,13 +2899,16 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
|
2868
|
2868
|
continue;
|
2869
|
2869
|
}
|
2870
|
2870
|
|
2871
|
|
- dbfile = (char *) cli_malloc(strlen(dent->d_name) + strlen(dirname) + 2);
|
|
2871
|
+ dbfile = (char *) cli_malloc(strlen(dent->d_name) + dirname_len + 2);
|
2872
|
2872
|
if(!dbfile) {
|
2873
|
2873
|
cli_errmsg("cli_loaddbdir(): dbfile == NULL\n");
|
2874
|
2874
|
closedir(dd);
|
2875
|
2875
|
return CL_EMEM;
|
2876
|
2876
|
}
|
2877
|
|
- sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
|
|
2877
|
+ if(ends_with_sep)
|
|
2878
|
+ sprintf(dbfile, "%s%s", dirname, dent->d_name);
|
|
2879
|
+ else
|
|
2880
|
+ sprintf(dbfile, "%s"PATHSEP"%s", dirname, dent->d_name);
|
2878
|
2881
|
ret = cli_load(dbfile, engine, signo, options, NULL);
|
2879
|
2882
|
if(ret) {
|
2880
|
2883
|
cli_errmsg("cli_loaddbdir(): error loading database %s\n", dbfile);
|