* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* chkpath is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* chkpath is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with chkpath; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* You should have received a copy of the GNU General Public License
* along with chkpath; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*----- Static variables --------------------------------------------------*/
static struct elt rootnode = { 0, 0, 0 }; /* Root of the list */
static struct elt *sp; /* Stack pointer for list */
/*----- Static variables --------------------------------------------------*/
static struct elt rootnode = { 0, 0, 0 }; /* Root of the list */
static struct elt *sp; /* Stack pointer for list */
- * Arguments: @struct chkpath *cp@ = pointer to context
- * @int what@ = what sort of report is this?
+ * Arguments: @const struct checkpath *cp@ = pointer to context
+ * @unsigned what@ = what sort of report is this?
* @int verbose@ = how verbose is this?
* @const char *p@ = what path does it refer to?
* @const char *msg@ = the message to give to the user
* @int verbose@ = how verbose is this?
* @const char *p@ = what path does it refer to?
* @const char *msg@ = the message to give to the user
-static void report(struct chkpath *cp, int what, int verbose,
+static void report(const struct checkpath *cp, unsigned what, int verbose,
const char *p, const char *msg, ...)
{
/* --- Decide whether to bin this message --- */
const char *p, const char *msg, ...)
{
/* --- Decide whether to bin this message --- */
*
* Arguments: @const char *p@ = name of directory to check
* @struct stat *st@ = pointer to @stat@(2) block for it
*
* Arguments: @const char *p@ = name of directory to check
* @struct stat *st@ = pointer to @stat@(2) block for it
* @unsigned f@ = various flags
*
* Returns: Zero if everything's OK, else bitmask of problems.
* @unsigned f@ = various flags
*
* Returns: Zero if everything's OK, else bitmask of problems.
-static int sanity(const char *p, struct stat *st,
- struct chkpath *cp, unsigned f)
+static unsigned sanity(const char *p, struct stat *st,
+ const struct checkpath *cp, unsigned f)
bad |= CP_WRWORLD;
report(cp, CP_WRWORLD, 1, p, "** world writable **");
}
bad |= CP_WRWORLD;
report(cp, CP_WRWORLD, 1, p, "** world writable **");
}
- (st->st_mode & (0020 | sticky)) == 0020) {
- if (cp->cp_what & CP_WRGRP) {
- bad |= CP_WRGRP;
- report(cp, CP_WRGRP, 1, p, "writable by group %g", st->st_gid);
- } else {
- int i;
+ (st->st_mode & (0020 | stickyok)) == 0020) {
+ int i;
+ unsigned b = CP_WRGRP;
+
+ if (cp->cp_what & CP_WROTHGRP) {
+ b = CP_WROTHGRP;
- bad |= CP_WROTHGRP;
- report(cp, CP_WROTHGRP, 1, p, "writable by group %g", st->st_gid);
- good_gid:;
+ }
+ if (b) {
+ bad |= b;
+ report(cp, b, 1, p, "writable by %sgroup %g",
+ (b == CP_WROTHGRP) ? "other " : "", st->st_gid);
- if ((i = readlink(d.buf, buf, sizeof(buf))) < 0) {
+ dstr_ensure(&buf, st.st_size + 1);
+ if ((i = readlink(d.buf, buf.buf, buf.sz)) < 0) {
report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e");
bad |= CP_ERROR;
break;
}
report(cp, CP_ERROR, 0, d.buf, "can't readlink: %e");
bad |= CP_ERROR;
break;
}
- buf[i] = 0;
- report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf);
+ buf.buf[i] = 0;
+ report(cp, CP_SYMLINK, 2, d.buf, "symlink -> `%s'", buf.buf);