From: Mark Wooding Date: Tue, 16 Jul 2024 13:04:24 +0000 (+0100) Subject: checkpath.c: Rename global flags and put their definitions in constact. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/checkpath/commitdiff_plain/879843463bdf570d8b1b4adf031b60e4ddf85f68?ds=sidebyside checkpath.c: Rename global flags and put their definitions in constact. The `f_...' naming has been reserved for flags local to a function for a long time in my private naming conventions. To make matters worse, the two flags applied in entirely different context -- and even had the same numerical value. This is now made clear by giving them distinct prefices and defining them in different places. --- diff --git a/checkpath.c b/checkpath.c index 5d77b18..9c15086 100644 --- a/checkpath.c +++ b/checkpath.c @@ -59,12 +59,10 @@ struct elt { struct elt *e_link; /* Pointer to the next one along */ size_t e_offset; /* Offset of name in path string */ unsigned e_flags; /* Various useful flags */ +#define EF_STICKY 1u /* Directory has sticky bit set */ char e_name[1]; /* Name of the directory */ }; -#define f_sticky 1u /* Directory has sticky bit set */ - -#define f_last 1u /* This is the final item to check */ /*----- Static variables --------------------------------------------------*/ @@ -272,13 +270,17 @@ static void report(const struct checkpath *cp, unsigned what, int verbose, * Arguments: @const char *p@ = name of directory to check * @struct stat *st@ = pointer to @stat@(2) block for it * @const struct checkpath *cp@ = pointer to caller parameters - * @unsigned f@ = various flags + * @unsigned f@ = various flags (@SF_...@) * * Returns: Zero if everything's OK, else bitmask of problems. * * Use: Performs the main load of sanity-checking on a directory. + * If @SF_LAST@ is not set then sticky directories are always + * acceptable. */ +#define SF_LAST 1u /* This is the final item to check */ + static unsigned sanity(const char *p, struct stat *st, const struct checkpath *cp, unsigned f) { @@ -288,7 +290,7 @@ static unsigned sanity(const char *p, struct stat *st, unsigned b; if (S_ISDIR(st->st_mode) && - (!(f & f_last) || (cp->cp_what & CP_STICKYOK))) + (!(f & SF_LAST) || (cp->cp_what & CP_STICKYOK))) stickyok = 01000; /* --- Check for world-writability --- */ @@ -439,7 +441,7 @@ unsigned checkpath(const char *p, const struct checkpath *cp) */ if ((cp->cp_what & CP_WROTHUSR) && - (sp->e_link->e_flags & f_sticky) && + (sp->e_link->e_flags & EF_STICKY) && st.st_uid != cp->cp_uid && st.st_uid != 0) { bad |= CP_WROTHUSR; report(cp, CP_WROTHUSR, 1, d.buf, @@ -459,11 +461,11 @@ unsigned checkpath(const char *p, const struct checkpath *cp) /* --- Run the sanity check on this path element --- */ - bad |= sanity(d.buf, &st, cp, ee ? 0 : f_last); + bad |= sanity(d.buf, &st, cp, ee ? 0 : SF_LAST); if (S_ISDIR(st.st_mode)) { if (st.st_mode & 01000) - sp->e_flags |= f_sticky; + sp->e_flags |= EF_STICKY; report(cp, CP_REPORT, 4, d.buf, "directory"); continue; }