2 .TH checkpath 3 "25 January 2003" "Local tools"
4 checkpath \- library for examining path security
7 .B "#include <checkpath.h>"
9 .BI "int checkpath(const char *" path ", const struct checkpath *" cp ");"
10 .BI "int checkpath_addgid(struct checkpath *" cp ", gid_t " g ");"
11 .BI "void checkpath_setuid(struct checkpath *" cp ");"
12 .BI "int checkpath_setgid(struct checkpath *" cp ");"
13 .BI "int checkpath_setgroups(struct checkpath *" cp ");"
14 .BI "void checkpath_setids(struct checkpath *" cp ");"
19 function checks a path for security. It ensures that only acceptble
20 users and groups can change the files or file contents accessible
23 The function is given a
25 to be checked, and a pointer
27 to a parameter block of type
28 .BR "struct checkpath" .
29 It scans the path and returns a bitmask of problems that it found. It
30 may also have invoked a caller-provided reporting function with details
32 .SS "The parameter structure"
33 This structure contains the following members:
36 The user running the check. Files and directories owned by
42 .B "gid_t cp_gid[NGROUPS_MAX + 1]"
43 The groups of which the user is a member. Files whose groups are in
44 this set may be considered safe, depending on the
46 configuration. See below.
49 The number of gids in the
54 The verbosity level. Messages are only given to the reporting function
55 if their verbosity level is less than or equal to this setting. As a
56 guide, unexpected errors (e.g., nonexistent files) have level 0,
57 security concerns about the path have level 1, and other details have
58 levels 2 and above. The recommended value is 1.
61 A bitmask of flags determining what conditions are considered problems,
62 and other behaviour. See below.
64 .B "void (*cp_report)(...)"
65 The reporting function. See below.
68 An argument to be passed to the reporting function
76 can be set up to reflect the current user and group memberships by
79 passing the address of the structure to fill in; this overwrites the
80 previous contents of the
85 members. Alternatively, the functions
86 .BR checkpath_setuid ,
87 .BR checkpath_setgid ,
89 .B checkpath_setgroups
90 can be called to do the job in stages. The
92 function simply stores the process's real uid in
97 .B checkpath_setgroups
98 functions store respectively the process's real gid and supplementary
101 array; they avoid inserting duplicate entries; they return 0 on success
102 or \-1 if the table would overflow; they assume that the table is
103 properly set up (minimally, just set
105 They use a utility function
107 to do their work; it takes a pointer to a
109 and a gid, and again returns 0 on success or \-1 if overflow would
111 .SS "The cp_what flags"
114 flags are as follows.
117 Some kind of operating system error occurred while checking the path.
120 A path element is world writable.
123 A path element is group-writable.
126 A path element is group-writable, and its group is not listed in
130 A path element is owned by another user.
133 Report traversal of a symbolic link while checking the path.
136 Format a user-readable message string when reporting problems.
139 Don't complain if the object designated by the path is a sticky
140 directory, as long as the owner is trustworthy (i.e., either
144 This is useful when testing candidate temporary directories for
158 has only these bits set. A problem is reported (and returned) only if
159 its bit is set in the
161 structure member. Note that it's possible that a problem might fit into
162 multiple categories, e.g., a group-writable directory might be reported
167 in this case, the most specific problem is used (in this case
169 .SS "The reporting function"
170 The reporting function is passed the following arguments:
173 A flag inidicating the kind of notification this is. It will be a
178 The verbosity level of this message.
180 .BI "const char *" path
181 The full pathname of the object which caused this report to be issued.
182 The pathname will not contain symbolic links (except as the last
183 element, and then only if this is a
187 .BI "const char *" msg
188 A human-readable message describing this notification in detail. This
198 member of the parameter structure, provided as a context pointer for the
206 Mark Wooding (mdw@distorted.org.uk).