5d7e01dc522077f9da8fc4eb2367704128b01c48
3 * $Id: chkpath.c,v 1.4 2004/04/08 01:36:22 mdw Exp $
5 * Check a user's file search path
7 * (c) 1999 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of chkpath.
14 * chkpath is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * chkpath is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with chkpath; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- 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 static void report(unsigned what
, int verbose
,
47 const char *p
, const char *msg
,
55 static void usage(FILE *fp
)
57 fprintf(fp
, "Usage: %s [-vqstp] [PATH...]\n", QUIS
);
60 /* --- @version@ --- */
62 static void version(FILE *fp
)
64 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 -p, --print Write the secure path elements to standard output.\n\
96 int main(int argc
, char *argv
[])
107 /* --- Initialize the world --- */
111 /* --- Set up path scanning defaults --- */
114 cp
.cp_what
= CP_PROBLEMS
| CP_REPORT
| CP_SYMLINK
;
115 cp
.cp_report
= report
;
117 checkpath_setids(&cp
);
119 /* --- Parse the options --- */
122 static struct option opts
[] = {
123 { "help", 0, 0, 'h' },
124 { "version", 0, 0, 'V' },
125 { "usage", 0, 0, 'u' },
126 { "verbose", 0, 0, 'v' },
127 { "quiet", 0, 0, 'q' },
128 { "sticky", 0, 0, 's' },
129 { "trust-group", 0, 0, 't' },
130 { "print", 0, 0, 'p' },
133 int i
= mdwopt(argc
, argv
, "hVu vqstp", opts
, 0, 0, 0);
155 cp
.cp_what
|= CP_STICKYOK
;
158 cp
.cp_what
= (cp
.cp_what
& ~CP_WRGRP
) | CP_WROTHGRP
;
174 /* --- Sort out what needs doing --- */
176 if (optind
== argc
) {
177 path
= getenv("PATH");
183 for (i
= optind
; i
< argc
; i
++) {
184 p
= xstrdup(argv
[i
]);
187 unsigned b
= checkpath(q
, &cp
);
188 if (!b
&& (f
& f_print
)) {
206 /*----- That's all, folks -------------------------------------------------*/