-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradm_human.c
186 lines (168 loc) · 4 KB
/
gradm_human.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright (C) 2002-2014 Bradley Spengler, Open Source Security, Inc.
* http://www.grsecurity.net [email protected]
*
* This file is part of gradm.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "gradm.h"
static struct role_name_table {
u_int16_t modeint;
char modechar;
} role_mode_table[] = {
{
GR_ROLE_USER, 'u'}, {
GR_ROLE_GROUP, 'g'}, {
GR_ROLE_SPECIAL, 's'}, {
GR_ROLE_AUTH, 'G'}, {
GR_ROLE_NOPW, 'N'}, {
GR_ROLE_GOD, 'A'}, {
GR_ROLE_TPE, 'T'}, {
GR_ROLE_PERSIST, 'R'}, {
GR_ROLE_PAM, 'P'}
};
static struct mode_name_table {
u_int32_t modeint;
char modechar;
} mode_table[] = {
{
GR_READ, 'r'}, {
GR_EXEC, 'x'}, {
GR_WRITE, 'w'}, {
GR_APPEND, 'a'}, {
GR_INHERIT, 'i'}, {
GR_PTRACERD, 't'}, {
GR_SETID, 'm'}, {
GR_CREATE, 'c'}, {
GR_DELETE, 'd'}, {
GR_LINK, 'l'}, {
GR_AUDIT_FIND, 'F'}, {
GR_AUDIT_READ, 'R'}, {
GR_AUDIT_WRITE, 'W'}, {
GR_AUDIT_EXEC, 'X'}, {
GR_AUDIT_APPEND, 'A'}, {
GR_AUDIT_INHERIT, 'I'}, {
GR_AUDIT_SETID, 'M'}, {
GR_AUDIT_CREATE, 'C'}, {
GR_AUDIT_DELETE, 'D'}, {
GR_AUDIT_LINK, 'L'}, {
GR_SUPPRESS, 's'}, {
GR_NOPTRACE, 'p'}, {
GR_INIT_TRANSFER, 'f'}, {
GR_FIND, 'h'}
};
static struct subj_mode_name_table {
u_int32_t modeint;
char modechar;
} subj_mode_table[] = {
{
GR_OVERRIDE, 'o'}, {
GR_KILL, 'k'}, {
GR_PROTECTED, 'p'}, {
GR_VIEW, 'v'}, {
GR_IGNORE, 'O'}, {
GR_PROCFIND, 'h'}, {
GR_PROTSHM, 'A'}, {
GR_KILLPROC, 'K'}, {
GR_KILLIPPROC, 'C'}, {
GR_NOTROJAN, 'T'}, {
GR_PROTPROCFD, 'd'}, {
GR_PROCACCT, 'b'}, {
GR_RELAXPTRACE, 'r'}, {
GR_LEARN, 'l'}, {
GR_INHERITLEARN, 'i'}, {
GR_POVERRIDE, 't'}, {
GR_KERNELAUTH, 'a'}, {
GR_ATSECURE, 's'}, {
GR_SHMEXEC, 'x'}
};
void
conv_mode_to_str(u_int32_t mode, char *modestr, unsigned short len)
{
unsigned short i;
unsigned short x;
memset(modestr, 0, len);
for (x = 0, i = 0;
i < len
&& x < (sizeof (mode_table) / sizeof (struct mode_name_table));
x++) {
if (mode_table[x].modeint == GR_WRITE && (mode & GR_WRITE)) {
modestr[i] = 'w';
mode &= ~GR_APPEND;
i++;
continue;
}
if (mode_table[x].modeint == GR_AUDIT_WRITE
&& (mode & GR_AUDIT_WRITE)) {
modestr[i] = 'W';
mode &= ~GR_AUDIT_APPEND;
i++;
continue;
}
if (mode_table[x].modeint == GR_FIND && !(mode & GR_FIND)) {
modestr[i] = 'h';
i++;
continue;
} else if (mode_table[x].modeint == GR_FIND)
continue;
if (mode & mode_table[x].modeint) {
modestr[i] = mode_table[x].modechar;
i++;
}
}
return;
}
void
conv_subj_mode_to_str(u_int32_t mode, char *modestr, unsigned short len)
{
unsigned short i;
unsigned short x;
memset(modestr, 0, len);
for (x = 0, i = 0;
i < len
&& x <
(sizeof (subj_mode_table) / sizeof (struct subj_mode_name_table));
x++) {
if (subj_mode_table[x].modeint == GR_PROCFIND && !(mode & GR_PROCFIND)) {
modestr[i] = 'h';
i++;
continue;
} else if (subj_mode_table[x].modeint == GR_PROCFIND)
continue;
if (mode & subj_mode_table[x].modeint) {
modestr[i] = subj_mode_table[x].modechar;
i++;
}
}
return;
}
void
conv_role_mode_to_str(u_int16_t mode, char *modestr, unsigned short len)
{
unsigned short i;
unsigned short x;
memset(modestr, 0, len);
for (x = 0, i = 0;
i < len
&& x <
(sizeof (role_mode_table) / sizeof (struct role_name_table));
x++) {
if (mode & role_mode_table[x].modeint) {
modestr[i] = role_mode_table[x].modechar;
i++;
}
}
return;
}