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 ------------------------------------------------------*/
40 #include <mLib/alloc.h>
41 #include <mLib/mdwopt.h>
42 #include <mLib/quis.h>
43 #include <mLib/report.h>
45 #include "checkpath.h"
48 /*----- Main code ---------------------------------------------------------*/
50 /* --- @report@ --- */
52 static void report(unsigned what
, int verbose
,
53 const char *p
, const char *msg
,
59 static void usage(FILE *fp
)
60 { fprintf(fp
, "Usage: %s [-vqstp] [-g NAME] [PATH...]\n", QUIS
); }
62 /* --- @version@ --- */
64 static void version(FILE *fp
)
65 { fprintf(fp
, "%s version %s\n", QUIS
, VERSION
); }
69 static void help(FILE *fp
)
75 Checks a path string (by default the PATH variable) for security. It\n\
76 ensures that only `root' or the calling user can write to all the parent\n\
77 directories of the path elements, so nobody can maliciously replace the\n\
78 binaries unexpectedly.\n\
80 Options provided are:\n\
82 -h, --help Display this help message.\n\
83 -V, --version Display the program's version number.\n\
84 -u, --usage Show a terse usage summary.\n\
86 -v, --verbose Be verbose about the search progress (cumulative).\n\
87 -q, --quiet Be quiet about the search progress (cumulative).\n\
88 -s, --sticky Consider sticky directories secure against\n\
89 modification by world and group (not recommended).\n\
90 -t, --trust-group Consider other members of your group trustworthy.\n\
91 -g, --group NAME Consider members of group NAME trustworthy.\n\
92 -p, --print Write the secure path elements to standard output.\n\
97 int main(int argc
, char *argv
[])
108 /* --- Initialize the world --- */
112 /* --- Set up path scanning defaults --- */
115 cp
.cp_what
= (CP_PROBLEMS
| CP_REPORT
| CP_SYMLINK
) & ~CP_WRGRP
;
116 cp
.cp_report
= report
;
119 checkpath_setuid(&cp
);
121 /* --- Parse the options --- */
124 static struct option opts
[] = {
125 { "help", 0, 0, 'h' },
126 { "version", 0, 0, 'V' },
127 { "usage", 0, 0, 'u' },
128 { "verbose", 0, 0, 'v' },
129 { "quiet", 0, 0, 'q' },
130 { "sticky", 0, 0, 's' },
131 { "trust-group", 0, 0, 't' },
132 { "print", 0, 0, 'p' },
135 int i
= mdwopt(argc
, argv
, "hVu" "vqstpg:", opts
, 0, 0, 0);
157 cp
.cp_what
|= CP_STICKYOK
;
160 if (checkpath_setgid(&cp
) || checkpath_setgroups(&cp
))
161 die(1, "too many groups");
164 allowgroup(&cp
, optarg
);
180 /* --- Sort out what needs doing --- */
182 if (optind
== argc
) {
183 path
= getenv("PATH");
189 for (i
= optind
; i
< argc
; i
++) {
190 p
= xstrdup(argv
[i
]);
193 unsigned b
= checkpath(q
, &cp
);
194 if (!b
&& (f
& f_print
)) {
212 /*----- That's all, folks -------------------------------------------------*/