close
Attachments you submit will be routed for moderation. If you have an account, please log in first.

Ticket #89: 03-clean-statok

File 03-clean-statok, 2.3 KB (added by Matthijs Kooijman, 11 years ago)

Remove some duplicate code from the statok function and improve the info messages

Line 
1Index: vuurmuur/libvuurmuur/src/io.c
2===================================================================
3--- vuurmuur.orig/libvuurmuur/src/io.c  2009-04-21 23:56:57.000000000 +0200
4+++ vuurmuur/libvuurmuur/src/io.c       2009-04-22 00:05:35.000000000 +0200
5@@ -178,29 +178,31 @@
6         return(0);
7     }
8 
9+    int fixperm = 0;
10     /* some warnings about the permissions being too relax */
11-    if(stat_buf.st_mode & S_IRGRP || stat_buf.st_mode & S_IROTH)
12+    if(stat_buf.st_mode & S_IRGRP)
13     {
14-        (void)vrprint.info("Info", "'%s' is readable by 'group' and 'other'. This is not recommended. Fixing.", file_loc);
15-
16-        /* for dirs */
17-        if(S_ISDIR(stat_buf.st_mode))
18-            mode = 0700;
19-        /* for files */
20-        else if(S_ISREG(stat_buf.st_mode))
21-            mode = 0600;
22-
23-        if(chmod(file_loc, mode) == -1)
24-        {
25-            (void)vrprint.error(-1, "Error", "failed to repair permissions for '%s': %s.", file_loc, strerror(errno));
26-            return(0);
27-        }
28+        (void)vrprint.info("Info", "'%s' is readable by 'group'. This is not recommended. ", file_loc);
29+        fixperm = 1;
30+    }
31+    if(stat_buf.st_mode & S_IROTH)
32+    {
33+        (void)vrprint.info("Info", "'%s' is readable by and 'other'. This is not recommended.", file_loc);
34+        fixperm = 1;
35+    }
36 
37+    if(stat_buf.st_mode & S_IXGRP)
38+    {
39+        (void)vrprint.info("Info", "'%s' is executable by 'group'. This is not recommended.", file_loc);
40+        fixperm = 1;
41     }
42-    if(stat_buf.st_mode & S_IXGRP || stat_buf.st_mode & S_IXOTH)
43+    if(stat_buf.st_mode & S_IXOTH)
44     {
45-        (void)vrprint.info("Info", "'%s' is executable by 'group' and 'other'. This is not recommended. Fixing.", file_loc);
46+        (void)vrprint.info("Info", "'%s' is executable by 'other'. This is not recommended.", file_loc);
47+        fixperm = 1;
48+    }
49 
50+    if (fixperm) {
51         /* for dirs */
52         if(S_ISDIR(stat_buf.st_mode))
53             mode = 0700;
54@@ -208,6 +210,7 @@
55         else if(S_ISREG(stat_buf.st_mode))
56             mode = 0600;
57 
58+        (void)vrprint.info("Info", "Resetting permissions of '%s' to %o.", file_loc, mode);
59         if(chmod(file_loc, mode) == -1)
60         {
61             (void)vrprint.error(-1, "Error", "failed to repair permissions for '%s': %s.", file_loc, strerror(errno));