From ebb0ec6f92b58ca58e3e7b0a53aad33f11309370 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 30 Nov 2023 15:06:37 -0700 Subject: [PATCH] define mode, uid, and gid format specifiers cleaned up some spacing moved printits to gufi_treesummary --- contrib/verifytraceintree.cpp | 7 +++-- include/config.h | 9 ++++++ include/utils.h | 2 -- src/bf.c | 4 +-- src/dfw.c | 54 +++++++++++++++++------------------ src/gufi_rollup.c | 4 +-- src/gufi_treesummary.c | 42 +++++++++++++++++++++++++++ src/trace.c | 52 ++++++++++++++++----------------- src/utils.c | 42 --------------------------- 9 files changed, 111 insertions(+), 105 deletions(-) diff --git a/contrib/verifytraceintree.cpp b/contrib/verifytraceintree.cpp index df527d9b8..dd94f6404 100644 --- a/contrib/verifytraceintree.cpp +++ b/contrib/verifytraceintree.cpp @@ -76,6 +76,7 @@ OF SUCH DAMAGE. #include #include "QueuePerThreadPool.h" +#include "config.h" #include "trace.h" // Data stored during first pass of input file @@ -111,9 +112,9 @@ static int callback(void *arg, int, char **data, char **) { ca->count++; // assume no errors - sscanf(data[mode_col], "%d", &ca->st.st_mode); - sscanf(data[uid_col], "%d", &ca->st.st_uid); - sscanf(data[gid_col], "%d", &ca->st.st_gid); + sscanf(data[mode_col], "%" STAT_mode, &ca->st.st_mode); + sscanf(data[uid_col], "%" STAT_uid, &ca->st.st_uid); + sscanf(data[gid_col], "%" STAT_gid, &ca->st.st_gid); return 0; } diff --git a/include/config.h b/include/config.h index cb2436da0..c087e6841 100644 --- a/include/config.h +++ b/include/config.h @@ -20,7 +20,10 @@ See LICENSE.txt in top-level directory for license terms. // members of struct stat have sizes that vary between OSX/Linux #if defined(__APPLE__) # define STAT_ino "llu" +# define STAT_mode "hd" # define STAT_nlink "hu" +# define STAT_uid "u" +# define STAT_gid "u" # define STAT_size "lld" # define STAT_bsize "d" # define STAT_blocks "lld" @@ -30,7 +33,10 @@ See LICENSE.txt in top-level directory for license terms. #elif defined(__linux__) # define STAT_ino "lu" +# define STAT_mode "u" # define STAT_nlink "lu" +# define STAT_uid "u" +# define STAT_gid "u" # define STAT_size "ld" # define STAT_bsize "ld" # define STAT_blocks "ld" @@ -41,7 +47,10 @@ See LICENSE.txt in top-level directory for license terms. #elif defined(__CYGWIN__) # define STAT_ino "lu" +# define STAT_mode "u" # define STAT_nlink "hu" +# define STAT_uid "u" +# define STAT_gid "u" # define STAT_size "ld" # define STAT_bsize "d" # define STAT_blocks "ld" diff --git a/include/utils.h b/include/utils.h index d63d4a839..6ea1eea99 100644 --- a/include/utils.h +++ b/include/utils.h @@ -88,8 +88,6 @@ int SNPRINTF(char *str, size_t size, const char *format, ...); to size_t or weird bugs may occur */ size_t SNFORMAT_S(char *dst, const size_t dst_len, size_t count, ...); -int printits(struct input *in, struct work *pwork, struct entry_data *data, FILE *out); - int zeroit(struct sum *summary); int sumit(struct sum *summary, struct entry_data *data); diff --git a/src/bf.c b/src/bf.c index 1f77a56dd..a58d2a1f2 100644 --- a/src/bf.c +++ b/src/bf.c @@ -158,8 +158,8 @@ void show_input(struct input* in, int retval) { printf("in.nameto = '%s'\n", in->nameto.data); printf("in.andor = %d\n", (int) in->andor); printf("in.external_enabled = %d\n", in->external_enabled); - printf("in.nobody.uid = %d\n", (int) in->nobody.uid); - printf("in.nobody.gid = %d\n", (int) in->nobody.gid); + printf("in.nobody.uid = %" STAT_uid "\n", in->nobody.uid); + printf("in.nobody.gid = %" STAT_gid "\n", in->nobody.gid); printf("in.sql.init = '%s'\n", in->sql.init.data); printf("in.sql.tsum = '%s'\n", in->sql.tsum.data); printf("in.sql.sum = '%s'\n", in->sql.sum.data); diff --git a/src/dfw.c b/src/dfw.c index b88f121e0..5dba915a2 100644 --- a/src/dfw.c +++ b/src/dfw.c @@ -85,18 +85,18 @@ static int printit(const char *name, const struct stat *status, char *type, char printf("%s ", name); if (!strncmp(type,"l",1)) printf("-> %s ",linkname); - printf("%"STAT_ino" ", status->st_ino); - printf("%lld ", pinode); - printf("%d ", status->st_mode); - printf("%"STAT_nlink" ", status->st_nlink); - printf("%d ", status->st_uid); - printf("%d ", status->st_gid); - printf("%"STAT_size" ", status->st_size); - printf("%"STAT_bsize" ", status->st_blksize); - printf("%"STAT_blocks" ", status->st_blocks); - printf("%ld ", status->st_atime); - printf("%ld ", status->st_mtime); - printf("%ld ", status->st_ctime); + printf("%" STAT_ino" ", status->st_ino); + printf("%lld ", pinode); + printf("%" STAT_mode " ", status->st_mode); + printf("%" STAT_nlink " ", status->st_nlink); + printf("%" STAT_uid " ", status->st_uid); + printf("%" STAT_gid " ", status->st_gid); + printf("%" STAT_size " ", status->st_size); + printf("%" STAT_bsize " ", status->st_blksize); + printf("%" STAT_blocks" ", status->st_blocks); + printf("%ld ", status->st_atime); + printf("%ld ", status->st_mtime); + printf("%ld ", status->st_ctime); if (xattrs->count) { printf("xattr:"); @@ -112,21 +112,21 @@ static int printload(struct input *in, const char *name, const struct stat *stat char *type, char *linkname, struct xattrs *xattrs, long long pinode, char *sortf, FILE *of) { (void) pinode; - fprintf(of,"%s%c", name,in->delim); - fprintf(of,"%c%c", type[0],in->delim); - fprintf(of,"%"STAT_ino"%c", status->st_ino,in->delim); + fprintf(of,"%s%c", name,in->delim); + fprintf(of,"%c%c", type[0],in->delim); + fprintf(of,"%" STAT_ino "%c", status->st_ino,in->delim); //fprintf(of,"%lld%c", pinode,in->delim); - fprintf(of,"%d%c", status->st_mode,in->delim); - fprintf(of,"%"STAT_nlink"%c", status->st_nlink,in->delim); - fprintf(of,"%d%c", status->st_uid,in->delim); - fprintf(of,"%d%c", status->st_gid,in->delim); - fprintf(of,"%"STAT_size"%c", status->st_size,in->delim); - fprintf(of,"%"STAT_bsize"%c", status->st_blksize,in->delim); - fprintf(of,"%"STAT_blocks"%c", status->st_blocks,in->delim); - fprintf(of,"%ld%c", status->st_atime,in->delim); - fprintf(of,"%ld%c", status->st_mtime,in->delim); - fprintf(of,"%ld%c", status->st_ctime,in->delim); - fprintf(of,"%s%c", linkname,in->delim); + fprintf(of,"%" STAT_mode "%c", status->st_mode,in->delim); + fprintf(of,"%" STAT_nlink "%c", status->st_nlink,in->delim); + fprintf(of,"%" STAT_uid "%c", status->st_uid,in->delim); + fprintf(of,"%" STAT_gid "%c", status->st_gid,in->delim); + fprintf(of,"%" STAT_size "%c", status->st_size,in->delim); + fprintf(of,"%" STAT_bsize "%c", status->st_blksize,in->delim); + fprintf(of,"%" STAT_blocks"%c", status->st_blocks,in->delim); + fprintf(of,"%ld%c", status->st_atime,in->delim); + fprintf(of,"%ld%c", status->st_mtime,in->delim); + fprintf(of,"%ld%c", status->st_ctime,in->delim); + fprintf(of,"%s%c", linkname,in->delim); for(size_t i = 0; i < xattrs->count; i++) { fprintf(of, "%s\\0", xattrs->pairs[i].name); } @@ -261,7 +261,7 @@ void listdir(struct input *in, const char *name, long long int level, printit(path,&st,type,lpath,&xattrs,1,pin); } } else { - printf("%s %s %"STAT_ino" %lld\n",type, path, entry->d_ino,pin); + printf("%s %s %" STAT_ino " %lld\n",type, path, entry->d_ino,pin); } } } diff --git a/src/gufi_rollup.c b/src/gufi_rollup.c index 66eab9c0f..e36387dab 100644 --- a/src/gufi_rollup.c +++ b/src/gufi_rollup.c @@ -612,8 +612,8 @@ static int rollup_xattr_dbs_callback(void *args, int count, char **data, char ** uid_t uid; gid_t gid; - sscanf(uid_str, "%d", &uid); /* skip checking for failure */ - sscanf(gid_str, "%d", &gid); /* skip checking for failure */ + sscanf(uid_str, "%" STAT_uid, &uid); /* skip checking for failure */ + sscanf(gid_str, "%" STAT_gid, &gid); /* skip checking for failure */ /* parent xattr db filename */ char xattr_db_name[MAXPATH]; diff --git a/src/gufi_treesummary.c b/src/gufi_treesummary.c index e4f152141..d0ca235d2 100644 --- a/src/gufi_treesummary.c +++ b/src/gufi_treesummary.c @@ -77,6 +77,48 @@ OF SUCH DAMAGE. #include "dbutils.h" #include "QueuePerThreadPool.h" +static int printits(struct input *in, struct work *pwork, struct entry_data *ed, FILE *out) { + fprintf(out, "%s%c", pwork->name, in->delim); + fprintf(out, "%c%c", ed->type, in->delim); + fprintf(out, "%" STAT_ino "%c", ed->statuso.st_ino, in->delim); + fprintf(out, "%" STAT_mode "%c", ed->statuso.st_mode, in->delim); + fprintf(out, "%" STAT_nlink "%c", ed->statuso.st_nlink, in->delim); + fprintf(out, "%" STAT_uid "%c", ed->statuso.st_uid, in->delim); + fprintf(out, "%" STAT_gid "%c", ed->statuso.st_gid, in->delim); + fprintf(out, "%" STAT_size "%c", ed->statuso.st_size, in->delim); + fprintf(out, "%" STAT_bsize "%c", ed->statuso.st_blksize, in->delim); + fprintf(out, "%" STAT_blocks"%c", ed->statuso.st_blocks, in->delim); + fprintf(out, "%ld%c", ed->statuso.st_atime, in->delim); + fprintf(out, "%ld%c", ed->statuso.st_mtime, in->delim); + fprintf(out, "%ld%c", ed->statuso.st_ctime, in->delim); + +/* we need this field even if its not populated for gufi_trace2index */ +/* + if (!strncmp(pwork->type,"l",1)) { + fprintf(out, "%s%c", ed->linkname,in->delim); + } +*/ + fprintf(out, "%s%c", ed->linkname,in->delim); + +/* we need this field even if its not populated for gufi_trace2index */ +/* + if (ed->xattrs > 0) { + //printf("xattr: "); + fprintf(out,"%s%c",ed->xattr,in->delim); + } +*/ + /* fwrite(ed->xattrs, sizeof(char), ed->xattrs_len, out); */ + fprintf(out,"%c",in->delim); + + /* this one is for create time which posix doesnt have */ + fprintf(out,"%c", in->delim); + /* moved this to end because we would like to use this for input to gufi_trace2index load from file */ + fprintf(out, "%lld%c", pwork->pinode, in->delim); + fprintf(out, "%d%c", ed->suspect, in->delim); + fprintf(out,"\n"); + return 0; +} + struct PoolArgs { struct input in; trie_t *skip; /* paths to skip during descent (only . and ..) */ diff --git a/src/trace.c b/src/trace.c index ecb5c9e4b..4a37fd221 100644 --- a/src/trace.c +++ b/src/trace.c @@ -80,29 +80,29 @@ int worktofile(FILE *file, const char delim, const size_t prefix_len, struct wor count += fwrite(work->name + prefix_len, 1, work->name_len - prefix_len, file); count += fwrite(&delim, 1, 1, file); - count += fprintf(file, "%c%c", ed->type, delim); - count += fprintf(file, "%" STAT_ino "%c", ed->statuso.st_ino, delim); - count += fprintf(file, "%d%c", ed->statuso.st_mode, delim); - count += fprintf(file, "%" STAT_nlink "%c", ed->statuso.st_nlink, delim); - count += fprintf(file, "%" PRId64 "%c", (int64_t) ed->statuso.st_uid, delim); - count += fprintf(file, "%" PRId64 "%c", (int64_t) ed->statuso.st_gid, delim); - count += fprintf(file, "%" STAT_size "%c", ed->statuso.st_size, delim); - count += fprintf(file, "%" STAT_bsize "%c", ed->statuso.st_blksize, delim); - count += fprintf(file, "%" STAT_blocks "%c", ed->statuso.st_blocks, delim); - count += fprintf(file, "%ld%c", ed->statuso.st_atime, delim); - count += fprintf(file, "%ld%c", ed->statuso.st_mtime, delim); - count += fprintf(file, "%ld%c", ed->statuso.st_ctime, delim); - count += fprintf(file, "%s%c", ed->linkname, delim); + count += fprintf(file, "%c%c", ed->type, delim); + count += fprintf(file, "%" STAT_ino "%c", ed->statuso.st_ino, delim); + count += fprintf(file, "%" STAT_mode "%c", ed->statuso.st_mode, delim); + count += fprintf(file, "%" STAT_nlink "%c", ed->statuso.st_nlink, delim); + count += fprintf(file, "%" STAT_uid "%c", ed->statuso.st_uid, delim); + count += fprintf(file, "%" STAT_gid "%c", ed->statuso.st_gid, delim); + count += fprintf(file, "%" STAT_size "%c", ed->statuso.st_size, delim); + count += fprintf(file, "%" STAT_bsize "%c", ed->statuso.st_blksize, delim); + count += fprintf(file, "%" STAT_blocks "%c", ed->statuso.st_blocks, delim); + count += fprintf(file, "%ld%c", ed->statuso.st_atime, delim); + count += fprintf(file, "%ld%c", ed->statuso.st_mtime, delim); + count += fprintf(file, "%ld%c", ed->statuso.st_ctime, delim); + count += fprintf(file, "%s%c", ed->linkname, delim); count += xattrs_to_file(file, &ed->xattrs, XATTRDELIM); - count += fprintf(file, "%c", delim); - count += fprintf(file, "%d%c", ed->crtime, delim); - count += fprintf(file, "%d%c", ed->ossint1, delim); - count += fprintf(file, "%d%c", ed->ossint2, delim); - count += fprintf(file, "%d%c", ed->ossint3, delim); - count += fprintf(file, "%d%c", ed->ossint4, delim); - count += fprintf(file, "%s%c", ed->osstext1, delim); - count += fprintf(file, "%s%c", ed->osstext2, delim); - count += fprintf(file, "%lld%c", work->pinode, delim); + count += fprintf(file, "%c", delim); + count += fprintf(file, "%d%c", ed->crtime, delim); + count += fprintf(file, "%d%c", ed->ossint1, delim); + count += fprintf(file, "%d%c", ed->ossint2, delim); + count += fprintf(file, "%d%c", ed->ossint3, delim); + count += fprintf(file, "%d%c", ed->ossint4, delim); + count += fprintf(file, "%s%c", ed->osstext1, delim); + count += fprintf(file, "%s%c", ed->osstext2, delim); + count += fprintf(file, "%lld%c", work->pinode, delim); count += fprintf(file, "\n"); return count; @@ -117,16 +117,14 @@ int linetowork(char *line, const size_t len, const char delim, struct work *work char *p; char *q; - int64_t uid = -1; - int64_t gid = -1; p=line; q = split(p, &delim, 1, end); work->name_len = SNPRINTF(work->name, MAXPATH, "%s", p); p = q; q = split(p, &delim, 1, end); ed->type = *p; p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_ino, &ed->statuso.st_ino); - p = q; q = split(p, &delim, 1, end); ed->statuso.st_mode = atol(p); + p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_mode, &ed->statuso.st_mode); p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_nlink, &ed->statuso.st_nlink); - p = q; q = split(p, &delim, 1, end); sscanf(p, "%" PRId64, &uid); ed->statuso.st_uid = uid; - p = q; q = split(p, &delim, 1, end); sscanf(p, "%" PRId64, &gid); ed->statuso.st_gid = gid; + p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_uid, &ed->statuso.st_uid); + p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_gid, &ed->statuso.st_gid); p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_size, &ed->statuso.st_size); p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_bsize, &ed->statuso.st_blksize); p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_blocks, &ed->statuso.st_blocks); diff --git a/src/utils.c b/src/utils.c index 51dd5417d..a3764be7a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -74,48 +74,6 @@ OF SUCH DAMAGE. #include "utils.h" -int printits(struct input *in, struct work *pwork, struct entry_data *ed, FILE *out) { - fprintf(out, "%s%c", pwork->name, in->delim); - fprintf(out, "%c%c", ed->type, in->delim); - fprintf(out, "%"STAT_ino"%c", ed->statuso.st_ino, in->delim); - fprintf(out, "%d%c", ed->statuso.st_mode, in->delim); - fprintf(out, "%"STAT_nlink"%c", ed->statuso.st_nlink, in->delim); - fprintf(out, "%d%c", ed->statuso.st_uid, in->delim); - fprintf(out, "%d%c", ed->statuso.st_gid, in->delim); - fprintf(out, "%"STAT_size"%c", ed->statuso.st_size, in->delim); - fprintf(out, "%"STAT_bsize"%c", ed->statuso.st_blksize, in->delim); - fprintf(out, "%"STAT_blocks"%c", ed->statuso.st_blocks, in->delim); - fprintf(out, "%ld%c", ed->statuso.st_atime, in->delim); - fprintf(out, "%ld%c", ed->statuso.st_mtime, in->delim); - fprintf(out, "%ld%c", ed->statuso.st_ctime, in->delim); - -/* we need this field even if its not populated for gufi_trace2index */ -/* - if (!strncmp(pwork->type,"l",1)) { - fprintf(out, "%s%c", ed->linkname,in->delim); - } -*/ - fprintf(out, "%s%c", ed->linkname,in->delim); - -/* we need this field even if its not populated for gufi_trace2index */ -/* - if (ed->xattrs > 0) { - //printf("xattr: "); - fprintf(out,"%s%c",ed->xattr,in->delim); - } -*/ - /* fwrite(ed->xattrs, sizeof(char), ed->xattrs_len, out); */ - fprintf(out,"%c",in->delim); - - /* this one is for create time which posix doesnt have */ - fprintf(out,"%c", in->delim); - /* moved this to end because we would like to use this for input to gufi_trace2index load from file */ - fprintf(out, "%lld%c", pwork->pinode, in->delim); - fprintf(out, "%d%c", ed->suspect, in->delim); - fprintf(out,"\n"); - return 0; -} - int zeroit(struct sum *summary) { summary->totfiles=0;