chiark / gitweb /
Make guts into official library.
[checkpath] / checkpath.h
1 /* -*-c-*-
2  *
3  * $Id: checkpath.h,v 1.3 2003/01/25 23:58:44 mdw Exp $
4  *
5  * Check a path for safety
6  *
7  * (c) 1999 Mark Wooding
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of chkpath.
13  *
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.
18  * 
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.
23  * 
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.
27  */
28
29 /*----- Revision history --------------------------------------------------* 
30  *
31  * $Log: checkpath.h,v $
32  * Revision 1.3  2003/01/25 23:58:44  mdw
33  * Make guts into official library.
34  *
35  * Revision 1.2  2001/01/25 22:16:02  mdw
36  * Make flags be unsigned.
37  *
38  * Revision 1.1.1.1  1999/04/06 20:12:07  mdw
39  * Import new project.
40  *
41  */
42
43 #ifndef CHECKPATH_H
44 #define CHECKPATH_H
45
46 #ifdef __cplusplus
47   extern "C" {
48 #endif
49
50 /*----- Header files ------------------------------------------------------*/
51
52 #include <limits.h>
53 #include <sys/types.h>
54
55 /*----- Data structures ---------------------------------------------------*/
56
57 /* --- Search request --- *
58  *
59  * This contains parameters from the caller to control what problems are
60  * looked for, and what to do when they're found.
61  */
62
63 struct checkpath {
64   uid_t cp_uid;                         /* Uid that's considered OK */
65   gid_t cp_gid[NGROUPS_MAX + 1];        /* Array of groups that are OK */
66   int cp_gids;                          /* Number of groups in the array */
67   int cp_verbose;                       /* Verbosity level to spit up */
68   unsigned cp_what;                     /* What things to check for */
69   void (*cp_report)(unsigned /*what*/, int /*verb*/,
70                     const char */*dir*/, const char */*msg*/,
71                     void */*p*/);
72   void *cp_arg;                         /* Argument for cp_report */
73 };
74
75 /* --- Flags for `@what@' fields in the above --- */
76
77 /* Problem types */
78 #define CP_PROBLEMS 0x1fu               /* Mask of problem bits */
79 #define CP_ERROR 0x01u                  /* Error report */
80 #define CP_WRWORLD 0x02u                /* Check write by world */
81 #define CP_WRGRP 0x04u                  /* Check write by any group */
82 #define CP_WROTHGRP 0x08u               /* Check write by other group */
83 #define CP_WROTHUSR 0x10u               /* Check write by other user */
84
85 /* Other flags */
86 #define CP_SYMLINK 0x100u               /* Report symbolic links */
87 #define CP_REPORT 0x200u                /* Make user-readable reports */
88 #define CP_STICKYOK 0x400u              /* Don't care if sticky is set */
89
90 /*----- Functions provided ------------------------------------------------*/
91
92 /* --- @checkpath@ --- *
93  *
94  * Arguments:   @const char *p@ = directory name which needs checking
95  *              @const struct checkpath *cp@ = parameters for the check
96  *
97  * Returns:     Zero if all is well, otherwise bitmask of problems.
98  *
99  * Use:         Scrutinises a directory path to see what evil things other
100  *              users could do to it.
101  */
102
103 extern unsigned checkpath(const char */*p*/, const struct checkpath */*cp*/);
104
105 /* --- @checkpath_setids@ --- *
106  *
107  * Arguments:   @struct checkpath *cp@ = pointer to block to fill in
108  *
109  * Returns:     ---
110  *
111  * Use:         Fills in the user ids and things in the structure.
112  */
113
114 extern void checkpath_setids(struct checkpath */*cp*/);
115
116 /*----- That's all, folks -------------------------------------------------*/
117
118 #ifdef __cplusplus
119   }
120 #endif
121
122 #endif