3 * Check a user's file search path
5 * (c) 1999 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of chkpath.
12 * chkpath is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * chkpath is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with chkpath; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/alloc.h>
38 #include <mLib/mdwopt.h>
39 #include <mLib/quis.h>
40 #include <mLib/report.h>
42 #include "checkpath.h"
44 /*----- Main code ---------------------------------------------------------*/
46 /* --- @report@ --- */
48 static void report(unsigned what, int verbose,
49 const char *p, const char *msg,
55 static void usage(FILE *fp)
56 { fprintf(fp, "Usage: %s [-vqstp] [PATH...]\n", QUIS); }
58 /* --- @version@ --- */
60 static void version(FILE *fp)
61 { fprintf(fp, "%s version %s\n", QUIS, VERSION); }
65 static void help(FILE *fp)
71 Checks a path string (by default the PATH variable) for security. It\n\
72 ensures that only `root' or the calling user can write to all the parent\n\
73 directories of the path elements, so nobody can maliciously replace the\n\
74 binaries unexpectedly.\n\
76 Options provided are:\n\
78 -h, --help Display this help message.\n\
79 -V, --version Display the program's version number.\n\
80 -u, --usage Show a terse usage summary.\n\
82 -v, --verbose Be verbose about the search progress (cumulative).\n\
83 -q, --quiet Be quiet about the search progress (cumulative).\n\
84 -s, --sticky Consider sticky directories secure against\n\
85 modification by world and group (not recommended).\n\
86 -t, --trust-group Consider other members of your group trustworthy.\n\
87 -p, --print Write the secure path elements to standard output.\n\
92 int main(int argc, char *argv[])
103 /* --- Initialize the world --- */
107 /* --- Set up path scanning defaults --- */
110 cp.cp_what = CP_PROBLEMS | CP_REPORT | CP_SYMLINK;
111 cp.cp_report = report;
113 checkpath_setids(&cp);
115 /* --- Parse the options --- */
118 static struct option opts[] = {
119 { "help", 0, 0, 'h' },
120 { "version", 0, 0, 'V' },
121 { "usage", 0, 0, 'u' },
122 { "verbose", 0, 0, 'v' },
123 { "quiet", 0, 0, 'q' },
124 { "sticky", 0, 0, 's' },
125 { "trust-group", 0, 0, 't' },
126 { "print", 0, 0, 'p' },
129 int i = mdwopt(argc, argv, "hVu" "vqstp", opts, 0, 0, 0);
151 cp.cp_what |= CP_STICKYOK;
154 cp.cp_what = (cp.cp_what & ~CP_WRGRP) | CP_WROTHGRP;
170 /* --- Sort out what needs doing --- */
172 if (optind == argc) {
173 path = getenv("PATH");
179 for (i = optind; i < argc; i++) {
180 p = xstrdup(argv[i]);
183 unsigned b = checkpath(q, &cp);
184 if (!b && (f & f_print)) {
202 /*----- That's all, folks -------------------------------------------------*/