Whamcloud - gitweb
DDN-1956 audit: scandir's filter returns non-zero to include
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 15 Mar 2021 13:48:29 +0000 (22:48 +0900)
committerJohn L. Hammond <jhammond@whamcloud.com>
Fri, 25 Mar 2022 19:59:07 +0000 (19:59 +0000)
When a filter function is used for scandir to select which entries
are to be included, the select routine should return a non-zero
value if the directory entry is to be included.

Fixes: dd3ba5e ("EX-274 lipe: add style check of C language code")
Change-Id: Ic02dc39e9a4e23286916bae92e9ee7a963406e3e
Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-on: https://review.whamcloud.com/46905
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
lipe/src/laudit-report.c
lipe/src/laudit.c

index f0e9035..637dbef 100644 (file)
@@ -511,9 +511,9 @@ int filter_out_files_for_time(const struct dirent *de)
        int n, ret;
 
        ret = sscanf(de->d_name, "%02d", &n);
-       if (ret != 1)
-               return -EINVAL;
-       return n;
+       if (ret < 0)
+               return 0;
+       return ret;
 }
 
 int browse_dir_depth_first(char *dir, char *uidgid)
@@ -753,10 +753,8 @@ int browse_files_fid(char *file_to_audit, bool use_as_basename)
 
                fp = fopen("paths", "r");
                if (fp == NULL) {
-                       printerr("cannot open %s/%s/paths: %s\n",
-                                main_dir, ep->d_name, strerror(errno));
-                       rc = errno;
-                       break;
+                       chdir(main_dir);
+                       continue;
                }
 
                while ((read = getline(&line, &len, fp)) != -1) {
@@ -909,6 +907,7 @@ int get_opts(int argc, char *const argv[])
 
        /*  The config file */
        strncpy(config_file, argv[argc - 1], sizeof(config_file) - 1);
+       config_file[sizeof(config_file) - 1] = '\0';
 
        if (user_to_audit && sscanf(user_to_audit, "%u:%u", &uid, &gid) != 2) {
                /* incorrect uid:gid provided */
index fecd69e..5c3bffe 100644 (file)
@@ -1447,6 +1447,7 @@ int get_opts(int argc, char *const argv[])
 
        /*  The config file */
        strncpy(config_file, argv[argc - 1], sizeof(config_file) - 1);
+       config_file[sizeof(config_file) - 1] = '\0';
 
        return 0;
 }