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 ,
10 .BI " const struct checkpath *" cp ");"
11 .BI "int checkpath_addgid(struct checkpath *" cp ", gid_t " g ");"
12 .BI "void checkpath_setuid(struct checkpath *" cp ");"
13 .BI "int checkpath_setgid(struct checkpath *" cp ");"
14 .BI "int checkpath_setgroups(struct checkpath *" cp ");"
15 .BI "void checkpath_setids(struct checkpath *" cp ");"
20 function checks a path for security. It ensures that only acceptble
21 users and groups can change the files or file contents accessible
24 The function is given a
26 to be checked, and a pointer
28 to a parameter block of type
29 .BR "struct checkpath" .
30 It scans the path and returns a bitmask of problems that it found. It
31 may also have invoked a caller-provided reporting function with details
33 .SS "The parameter structure"
34 This structure contains the following members:
37 The user running the check. Files and directories owned by
43 .B "gid_t cp_gid[NGROUPS_MAX + 1]"
44 The groups of which the user is a member. Files whose groups are in
45 this set may be considered safe, depending on the
47 configuration. See below.
50 The number of gids in the
55 The verbosity level. Messages are only given to the reporting function
56 if their verbosity level is less than or equal to this setting. As a
57 guide, unexpected errors (e.g., nonexistent files) have level 0,
58 security concerns about the path have level 1, and other details have
59 levels 2 and above. The recommended value is 1.
62 A bitmask of flags determining what conditions are considered problems,
63 and other behaviour. See below.
65 .B "void (*cp_report)(...)"
66 The reporting function. See below.
69 An argument to be passed to the reporting function
77 can be set up to reflect the current user and group memberships by
80 passing the address of the structure to fill in; this overwrites the
81 previous contents of the
86 members. Alternatively, the functions
87 .BR checkpath_setuid ,
88 .BR checkpath_setgid ,
90 .B checkpath_setgroups
91 can be called to do the job in stages. The
93 function simply stores the process's real uid in
98 .B checkpath_setgroups
99 functions store respectively the process's real gid and supplementary
102 array; they avoid inserting duplicate entries; they return 0 on success
103 or \-1 if the table would overflow; they assume that the table is
104 properly set up (minimally, just set
106 They use a utility function
108 to do their work; it takes a pointer to a
110 and a gid, and again returns 0 on success or \-1 if overflow would
112 .SS "The cp_what flags"
115 flags are as follows.
118 Some kind of operating system error occurred while checking the path.
121 A path element is world writable.
124 A path element is group-writable.
127 A path element is group-writable, and its group is not listed in
131 A path element is owned by another user.
134 Report traversal of a symbolic link while checking the path.
137 Format a user-readable message string when reporting problems.
140 Don't complain if the object designated by the path is a sticky
141 directory, as long as the owner is trustworthy (i.e., either
145 This is useful when testing candidate temporary directories for
159 has only these bits set. A problem is reported (and returned) only if
160 its bit is set in the
162 structure member. Note that it's possible that a problem might fit into
163 multiple categories, e.g., a group-writable directory might be reported
168 in this case, the most specific problem is used (in this case
170 .SS "The reporting function"
171 The reporting function is passed the following arguments:
174 A flag inidicating the kind of notification this is. It will be a
179 The verbosity level of this message.
181 .BI "const char *" path
182 The full pathname of the object which caused this report to be issued.
183 The pathname will not contain symbolic links (except as the last
184 element, and then only if this is a
188 .BI "const char *" msg
189 A human-readable message describing this notification in detail. This
199 member of the parameter structure, provided as a context pointer for the
207 Mark Wooding (mdw@distorted.org.uk).