Imported Debian patch 1.6.9p11-2
[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.1 2007/06/23 21:36: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 };
39
40 /*
41  * Data structure describing a command in the
42  * sudoers file.
43  */
44 struct sudo_command {
45     char *cmnd;
46     char *args;
47 };
48
49 #define user_matches    (match[top-1].user)
50 #define cmnd_matches    (match[top-1].cmnd)
51 #define host_matches    (match[top-1].host)
52 #define runas_matches   (match[top-1].runas)
53 #define no_passwd       (match[top-1].nopass)
54 #define no_execve       (match[top-1].noexec)
55 #define setenv_ok       (match[top-1].setenv)
56
57 /*
58  * Structure containing command matches if "sudo -l" is used.
59  */
60 struct command_match {
61     char *runas;
62     size_t runas_len;
63     size_t runas_size;
64     char *cmnd;
65     size_t cmnd_len;
66     size_t cmnd_size;
67     int nopasswd;
68     int noexecve;
69     int setenv;
70 };
71
72 /*
73  * Structure describing an alias match in parser.
74  */
75 typedef struct {
76     int type;
77     char *name;
78     int val;
79 } aliasinfo;
80
81 /*
82  * Structure containing Cmnd_Alias's if "sudo -l" is used.
83  */
84 struct generic_alias {
85     int type;
86     char *alias;
87     char *entries;
88     size_t entries_size;
89     size_t entries_len;
90 };
91
92 /* The matching stack and number of entries on it. */
93 extern struct matchstack *match;
94 extern int top;
95
96 /*
97  * Prototypes
98  */
99 int addr_matches        __P((char *));
100 int command_matches     __P((char *, char *));
101 int hostname_matches    __P((char *, char *, char *));
102 int netgr_matches       __P((char *, char *, char *, char *));
103 int userpw_matches      __P((char *, char *, struct passwd *));
104 int usergr_matches      __P((char *, char *, struct passwd *));
105
106 #endif /* _SUDO_PARSE_H */