Imported Upstream version 1.6.9p17
[debian/sudo] / parse.h
1 /*
2  * Copyright (c) 1996, 1998-2000, 2004, 2007
3  *      Todd C. Miller <Todd.Miller@courtesan.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $Sudo: parse.h,v 1.14.2.2 2008/02/09 14:44:48 millert Exp $
18  */
19
20 #ifndef _SUDO_PARSE_H
21 #define _SUDO_PARSE_H
22
23 /*
24  * Data structure used in parsing sudoers;
25  * top of stack values are the ones that
26  * apply when parsing is done & can be
27  * accessed by *_matches macros
28  */
29 #define STACKINCREMENT (32)
30 struct matchstack {
31         int user;
32         int cmnd;
33         int host;
34         int runas;
35         int nopass;
36         int noexec;
37         int setenv;
38         char *role;
39         char *type;
40 };
41
42 /*
43  * Data structure describing a command in the
44  * sudoers file.
45  */
46 struct sudo_command {
47     char *cmnd;
48     char *args;
49 };
50
51 /*
52  * SELinux-specific container struct.
53  * Currently just contains a role and type.
54  */
55 struct selinux_info {
56     char *role;
57     char *type;
58 };
59
60 #define user_matches    (match[top-1].user)
61 #define cmnd_matches    (match[top-1].cmnd)
62 #define host_matches    (match[top-1].host)
63 #define runas_matches   (match[top-1].runas)
64 #define no_passwd       (match[top-1].nopass)
65 #define no_execve       (match[top-1].noexec)
66 #define setenv_ok       (match[top-1].setenv)
67
68 /*
69  * Structure containing command matches if "sudo -l" is used.
70  */
71 struct command_match {
72     char *runas;
73     size_t runas_len;
74     size_t runas_size;
75     char *cmnd;
76     size_t cmnd_len;
77     size_t cmnd_size;
78     char *role;
79     size_t role_len;
80     size_t role_size;
81     char *type;
82     size_t type_len;
83     size_t type_size;
84     int nopasswd;
85     int noexecve;
86     int setenv;
87 };
88
89 /*
90  * Structure describing an alias match in parser.
91  */
92 typedef struct {
93     int type;
94     char *name;
95     int val;
96 } aliasinfo;
97
98 /*
99  * Structure containing Cmnd_Alias's if "sudo -l" is used.
100  */
101 struct generic_alias {
102     int type;
103     char *alias;
104     char *entries;
105     size_t entries_size;
106     size_t entries_len;
107 };
108
109 /* The matching stack and number of entries on it. */
110 extern struct matchstack *match;
111 extern int top;
112
113 /*
114  * Prototypes
115  */
116 int addr_matches        __P((char *));
117 int command_matches     __P((char *, char *));
118 int hostname_matches    __P((char *, char *, char *));
119 int netgr_matches       __P((char *, char *, char *, char *));
120 int userpw_matches      __P((char *, char *, struct passwd *));
121 int usergr_matches      __P((char *, char *, struct passwd *));
122
123 #endif /* _SUDO_PARSE_H */