File: libfwnt_debug.c

package info (click to toggle)
libevt 20200926-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 17,176 kB
  • sloc: ansic: 278,910; sh: 6,138; makefile: 1,727; python: 390; cpp: 88; sed: 16
file content (355 lines) | stat: -rw-r--r-- 8,377 bytes parent folder | download | duplicates (6)
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
 * Debug functions
 *
 * Copyright (C) 2009-2020, Joachim Metz <joachim.metz@gmail.com>
 *
 * Refer to AUTHORS for acknowledgements.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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 Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <common.h>
#include <memory.h>
#include <types.h>

#include "libfwnt_debug.h"
#include "libfwnt_definitions.h"
#include "libfwnt_libcnotify.h"

#if defined( HAVE_DEBUG_OUTPUT )

/* Prints the security descriptor control flags
 */
void libfwnt_debug_print_security_descriptor_control_flags(
      uint16_t control_flags )
{
	if( ( control_flags & 0x0001 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_OWNER_DEFAULTED)\n" );
	}
	if( ( control_flags & 0x0002 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_GROUP_DEFAULTED)\n" );
	}
	if( ( control_flags & 0x0004 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_DACL_PRESENT)\n" );
	}
	if( ( control_flags & 0x0008 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_DACL_DEFAULTED)\n" );
	}
	if( ( control_flags & 0x0010 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_SACL_PRESENT)\n" );
	}
	if( ( control_flags & 0x0020 ) != 0 )
	{
		libcnotify_printf(
		 "\t(Unknown 0x0020)\n" );
	}
	if( ( control_flags & 0x0040 ) != 0 )
	{
		libcnotify_printf(
		 "\t(Unknown 0x0040)\n" );
	}
	if( ( control_flags & 0x0080 ) != 0 )
	{
		libcnotify_printf(
		 "\t(Unknown 0x0080)\n" );
	}
	if( ( control_flags & 0x0100 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_DACL_AUTO_INHERIT_REQ)\n" );
	}
	if( ( control_flags & 0x0200 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_SACL_AUTO_INHERIT_REQ)\n" );
	}
	if( ( control_flags & 0x0400 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_DACL_AUTO_INHERITED)\n" );
	}
	if( ( control_flags & 0x0800 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_SACL_AUTO_INHERITED)\n" );
	}
	if( ( control_flags & 0x1000 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_DACL_PROTECTED)\n" );
	}
	if( ( control_flags & 0x2000 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_SACL_PROTECTED)\n" );
	}
	if( ( control_flags & 0x4000 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_RM_CONTROL_VALID)\n" );
	}
	if( ( control_flags & 0x8000 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SE_SELF_RELATIVE)\n" );
	}
}

/* Retrieves a string containing the access control entry type
 */
const char *libfwnt_debug_print_access_control_entry_type(
             uint8_t entry_type )
{
	switch( entry_type )
	{
		case LIBFWNT_ACCESS_ALLOWED:
			return( "Access allowed (ACCESS_ALLOWED_ACE_TYPE)" );

		case LIBFWNT_ACCESS_DENIED:
			return( "Access denied (ACCESS_DENIED_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_AUDIT:
			return( "System-audit (SYSTEM_AUDIT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_ALARM:
			return( "System-alarm (SYSTEM_ALARM_ACE_TYPE)" );

		case LIBFWNT_ACCESS_ALLOWED_COMPOUND:
			return( "Access allowed (ACCESS_ALLOWED_COMPOUND_ACE_TYPE)" );

		case LIBFWNT_ACCESS_ALLOWED_OBJECT:
			return( "Access allowed (ACCESS_ALLOWED_OBJECT_ACE_TYPE)" );

		case LIBFWNT_ACCESS_DENIED_OBJECT:
			return( "Access denied (ACCESS_DENIED_OBJECT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_AUDIT_OBJECT:
			return( "System-audit (SYSTEM_AUDIT_OBJECT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_ALARM_OBJECT:
			return( "System-alarm (SYSTEM_ALARM_OBJECT_ACE_TYPE)" );

		case LIBFWNT_ACCESS_ALLOWED_CALLBACK:
			return( "Access allowed (ACCESS_ALLOWED_CALLBACK_ACE_TYPE)" );

		case LIBFWNT_ACCESS_DENIED_CALLBACK:
			return( "Access denied (ACCESS_DENIED_CALLBACK_ACE_TYPE)" );

		case LIBFWNT_ACCESS_ALLOWED_CALLBACK_OBJECT:
			return( "Access allowed (ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE)" );

		case LIBFWNT_ACCESS_DENIED_CALLBACK_OBJECT:
			return( "Access denied (ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_AUDIT_CALLBACK:
			return( "System-audit (SYSTEM_AUDIT_CALLBACK_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_ALARM_CALLBACK:
			return( "System-alarm (SYSTEM_ALARM_CALLBACK_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_AUDIT_CALLBACK_OBJECT:
			return( "System-audit (SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_ALARM_CALLBACK_OBJECT:
			return( "System-alarm (SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE)" );

		case LIBFWNT_SYSTEM_MANDATORY_LABEL:
			return( "Mandatory label (SYSTEM_MANDATORY_LABEL_ACE_TYPE)" );
	}
	return( "UNKNOWN" );
}

/* Prints the access control entry flags
 */
void libfwnt_debug_print_access_control_entry_flags(
      uint8_t flags )
{
	if( ( flags & 0x01 ) != 0 )
	{
		libcnotify_printf(
		 "\t(OBJECT_INHERIT_ACE)\n" );
	}
	if( ( flags & 0x02 ) != 0 )
	{
		libcnotify_printf(
		 "\t(CONTAINER_INHERIT_ACE)\n" );
	}
	if( ( flags & 0x04 ) != 0 )
	{
		libcnotify_printf(
		 "\t(NO_PROPAGATE_INHERIT_ACE)\n" );
	}
	if( ( flags & 0x08 ) != 0 )
	{
		libcnotify_printf(
		 "\t(INHERIT_ONLY_ACE)\n" );
	}

	if( ( flags & 0x40 ) != 0 )
	{
		libcnotify_printf(
		 "\t(SUCCESSFUL_ACCESS_ACE_FLAG)\n" );
	}
	if( ( flags & 0x80 ) != 0 )
	{
		libcnotify_printf(
		 "\t(FAILED_ACCESS_ACE_FLAG)\n" );
	}
}

/* Prints the access control entry access mask
 */
void libfwnt_debug_print_access_control_entry_access_mask(
      uint32_t access_mask )
{
	if( ( access_mask & 0x00000001UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightReadBody or fsdrightListContents)\n" );
	}
	if( ( access_mask & 0x00000002UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteBody or fsdrightCreateItem)\n" );
	}
	if( ( access_mask & 0x00000004UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightAppendMsg or fsdrightCreateContainer)\n" );
	}
	if( ( access_mask & 0x00000008UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightReadProperty or fsdrightReadProperty)\n" );
	}
	if( ( access_mask & 0x00000010UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteProperty or fsdrightWriteProperty)\n" );
	}
	if( ( access_mask & 0x00000020UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightExecute)\n" );
	}

	if( ( access_mask & 0x00000080UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightReadAttributes or fsdrightReadAttributes)\n" );
	}
	if( ( access_mask & 0x00000100UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteAttributes or fsdrightWriteAttributes)\n" );
	}
	if( ( access_mask & 0x00000200UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteOwnProperty or fsdrightWriteOwnProperty)\n" );
	}
	if( ( access_mask & 0x00000400UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightDeleteOwnItem or fsdrightDeleteOwnItem)\n" );
	}
	if( ( access_mask & 0x00000800UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightViewItem or fsdrightViewItem)\n" );
	}

	if( ( access_mask & 0x00004000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightOwner)\n" );
	}
	if( ( access_mask & 0x00008000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightContact)\n" );
	}

	/* Standard access rights flags */
	if( ( access_mask & 0x00010000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightDelete)\n" );
	}
	if( ( access_mask & 0x00020000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightReadControl)\n" );
	}
	if( ( access_mask & 0x00040000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteSD)\n" );
	}
	if( ( access_mask & 0x00080000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightWriteOwner)\n" );
	}
	if( ( access_mask & 0x00100000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(fsdrightSynchronize)\n" );
	}

	if( ( access_mask & 0x01000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(ACCESS_SYSTEM_SECURITY)\n" );
	}
	if( ( access_mask & 0x02000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(MAXIMUM_ALLOWED)\n" );
	}

	if( ( access_mask & 0x10000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(GENERIC_ALL)\n" );
	}
	if( ( access_mask & 0x20000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(GENERIC_EXECUTE)\n" );
	}
	if( ( access_mask & 0x40000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(GENERIC_WRITE)\n" );
	}
	if( ( access_mask & 0x80000000UL ) != 0 )
	{
		libcnotify_printf(
		 "\t(GENERIC_READ)\n" );
	}
}

#endif /* defined( HAVE_DEBUG_OUTPUT ) */