Ticket #89: 02-clean-statok-uses

File 02-clean-statok-uses, 3.7 kB (added by matthijs, 16 months ago)

Do some cleanups enabled by the updated vuurmuur_fopen and stat_ok functions

Line 
1Index: vuurmuur/libvuurmuur/src/blocklist.c
2===================================================================
3--- vuurmuur.orig/libvuurmuur/src/blocklist.c   2009-04-21 23:47:10.000000000 +0200
4+++ vuurmuur/libvuurmuur/src/blocklist.c        2009-04-21 23:49:20.000000000 +0200
5@@ -392,25 +392,15 @@
6     if(debuglvl >= MEDIUM)
7         (void)vrprint.debug(__FUNC__, "load_ips: %c, no_refcnt: %c.", load_ips, no_refcnt);
8 
9-    /* check the file: it reports error's by itself */
10-    if(stat_ok(debuglvl, conf.blocklist_location, STATOK_WANT_FILE, STATOK_VERBOSE, STATOK_MUST_EXIST))
11-    {
12-        /* open the blocklist-file */
13-        if(!(fp = fopen(conf.blocklist_location, "r")))
14-        {
15-            (void)vrprint.error(-1, "Error", "opening blockfile '%s' failed: %s (in: %s:%d).",
16-                                conf.blocklist_location,
17-                                strerror(errno),
18-                                __FUNC__, __LINE__);
19-            return(-1);
20-        }
21-    }
22-    else
23-    {
24-        /* no error msg, stat_ok takes care of that */
25-        return(-1);
26-    }
27-
28+       /* open the blocklist-file */
29+       if(!(fp = vuurmuur_fopen(debuglvl, conf.blocklist_location, "r")))
30+       {
31+               (void)vrprint.error(-1, "Error", "opening blockfile '%s' failed: %s (in: %s:%d).",
32+                                                       conf.blocklist_location,
33+                                                       strerror(errno),
34+                                                       __FUNC__, __LINE__);
35+               return(-1);
36+       }
37 
38     /* read the file */
39     while(fgets(line, (int)sizeof(line), fp) != NULL)
40Index: vuurmuur/vuurmuur/vuurmuur/ruleset.c
41===================================================================
42--- vuurmuur.orig/vuurmuur/vuurmuur/ruleset.c   2009-04-21 23:47:10.000000000 +0200
43+++ vuurmuur/vuurmuur/vuurmuur/ruleset.c        2009-04-21 23:48:52.000000000 +0200
44@@ -1155,13 +1155,6 @@
45         final checks on the file
46     */
47 
48-    /* exist */
49-    if(!(ruleset_exists(debuglvl, path_to_ruleset)))
50-    {
51-        (void)vrprint.error(-1, "Error", "missing rulesetfile (in: %s:%d).", __FUNC__, __LINE__);
52-        return(-1);
53-    }
54-
55     /* stat_ok */
56     if(!(stat_ok(debuglvl, path_to_ruleset, STATOK_WANT_FILE, STATOK_VERBOSE, STATOK_MUST_EXIST)))
57     {
58@@ -1214,13 +1207,6 @@
59         final checks on the file
60     */
61 
62-    /* exist */
63-    if(!(ruleset_exists(debuglvl, path_to_ruleset)))
64-    {
65-        (void)vrprint.error(-1, "Error", "missing rulesetfile (in: %s:%d).", __FUNC__, __LINE__);
66-        return(-1);
67-    }
68-
69     /* stat_ok */
70     if(!(stat_ok(debuglvl, path_to_ruleset, STATOK_WANT_FILE, STATOK_VERBOSE, STATOK_MUST_EXIST)))
71     {
72Index: vuurmuur/vuurmuur/vuurmuur_log/logfile.c
73===================================================================
74--- vuurmuur.orig/vuurmuur/vuurmuur_log/logfile.c       2009-04-21 23:47:10.000000000 +0200
75+++ vuurmuur/vuurmuur/vuurmuur_log/logfile.c    2009-04-21 23:50:31.000000000 +0200
76@@ -130,26 +130,8 @@
77         return(NULL);
78     }
79 
80-    /* see if we think if the file is ok */
81-    if(!(fp = fopen(path, "r")) && errno == ENOENT)
82-    {
83-        /* don't check because file does not exist */
84-    }
85-    else
86-    {
87-        /* if we opened it, close it again */
88-        if(fp != NULL)
89-            (void)fclose(fp);
90-
91-        if(!stat_ok(debuglvl, path, STATOK_WANT_FILE, STATOK_VERBOSE, STATOK_MUST_EXIST))
92-        {
93-            (void)vrprint.error(-1, "Error", "won't open logfile '%s' because of permission problems (in: %s:%d).", path, __FUNC__, __LINE__);
94-            return(NULL);
95-        }
96-    }
97-
98     /* open the logfile */
99-    if(!(fp = fopen(path, mode)))
100+    if(!(fp = vuurmuur_fopen(debuglvl, path, mode)))
101     {
102         (void)vrprint.error(-1, "Error", "the logfile '%s' could not be opened: %s (in: %s:%d).", path, strerror(errno), __FUNC__, __LINE__);
103         return(NULL);