blob: 7589efd76880cdd74369194463c305e92ba76da9 [file] [log] [blame]
Steve Kondik2111ad72013-07-07 12:07:44 -07001/*
2 * General declarations for secaudit
3 *
4 * These declarations are organized to enable code sharing with ntfs-3g
5 * library, but should only be used to build tools runnable both
6 * on Linux (dynamic linking) and Windows (static linking)
7 *
8 * Copyright (c) 2007-2009 Jean-Pierre Andre
9 *
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program (in the main directory of the NTFS-3G
25 * distribution in the file COPYING); if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29/*
30 * General parameters which may have to be adapted to needs
31 */
32
33#define SELFTESTS 1 /* include code for self-testing */
34#define POSIXACLS 0 /* include code for processing Posix ACLs */
35#define NOREVBOM 0 /* temporary */
36
37#define OWNERFROMACL 1 /* must match option in security.c */
38
39#define MAXATTRSZ 65536 /* Max sec attr size (16448 met for WinXP) */
40#define MAXSECURID 262144
41#define SECBLKSZ 8
42#define MAXFILENAME 4096
43#define FORCEMASK 0 /* Special (dangerous) option -m to force a mask */
44#define MAXLINE 80 /* maximum processed size of a line */
45#define BUFSZ 1024 /* buffer size to read mapping file */
46#define LINESZ 120 /* maximum useful size of a mapping line */
47
48/*
49 * Definitions for Linux
50 * Use explicit or implicit dynamic linking
51 */
52
53#ifdef HAVE_CONFIG_H
54#undef POSIXACLS /* override default by configure option */
55#define USESTUBS 1 /* API stubs generated at link time */
56#else
57#define USESTUBS 0 /* direct calls to API, based on following definitions */
58#define ENVNTFS3G "NTFS3G"
Steve Kondike68cb602016-08-28 00:45:36 -070059#if defined(__SVR4)
60#define LIBFILE64 "/usr/lib/amd64/libntfs-3g.so"
61#define LIBFILE "/usr/lib/libntfs-3g.so"
62#else
63#define LIBFILE64 "/lib64/libntfs-3g.so"
64#define LIBFILE "/lib/libntfs-3g.so"
65#endif
Steve Kondik2111ad72013-07-07 12:07:44 -070066#endif
67
68#define MAPDIR ".NTFS-3G"
69#define MAPFILE "UserMapping"
70#define MAGIC_API 0x09042009
71
72#ifndef _NTFS_ENDIANS_H
73
74typedef char s8;
75typedef short s16;
76typedef long long s64;
77typedef unsigned char u8;
78typedef unsigned short le16, be16, u16;
79typedef unsigned long long u64;
80#ifdef STSC
81typedef long s32;
82typedef unsigned long le32, be32, u32;
83#else
84typedef int s32;
85typedef unsigned int le32, be32, u32;
86#endif
87
88#ifdef STSC
89#define endian_rev16(x) ((((x) & 255L) << 8) + (((x) >> 8) & 255L))
90#define endian_rev32(x) ((((x) & 255L) << 24) + (((x) & 0xff00L) << 8) \
91 + (((x) >> 8) & 0xff00L) + (((x) >> 24) & 255L))
92#else
93#define endian_rev16(x) ((((x) & 255) << 8) + (((x) >> 8) & 255))
94#define endian_rev32(x) ((((x) & 255) << 24) + (((x) & 0xff00) << 8) \
95 + (((x) >> 8) & 0xff00) + (((x) >> 24) & 255))
96#endif
97#define endian_rev64(x) ((((x) & 255LL) << 56) + (((x) & 0xff00LL) << 40) \
98 + (((x) & 0xff0000LL) << 24) + (((x) & 0xff000000LL) << 8) \
99 + (((x) >> 8) & 0xff000000LL) + (((x) >> 24) & 0xff0000LL) \
100 + (((x) >> 40) & 0xff00LL) + (((x) >> 56) & 255LL))
101
102#if __BYTE_ORDER == __LITTLE_ENDIAN
103
104#define cpu_to_be16(x) endian_rev16(x)
105#define cpu_to_be32(x) endian_rev32(x)
106#define cpu_to_le16(x) (x)
107#define cpu_to_le32(x) (x)
108#define cpu_to_le64(x) (x)
109#define le16_to_cpu(x) (x)
110#define le32_to_cpu(x) (x)
111#define le64_to_cpu(x) (x)
112
113#else
114
115#define cpu_to_be16(x) (x)
116#define cpu_to_be32(x) (x)
117#define cpu_to_le16(x) endian_rev16(x)
118#define cpu_to_le32(x) endian_rev32(x)
119#define cpu_to_le64(x) endian_rev64(x)
120#define le16_to_cpu(x) endian_rev16(x)
121#define le32_to_cpu(x) endian_rev32(x)
122#define le64_to_cpu(x) endian_rev64(x)
123
124#endif
125
126#define const_le16_to_cpu(x) le16_to_cpu(x)
127#define const_cpu_to_le16(x) cpu_to_le16(x)
128#define const_cpu_to_le32(x) cpu_to_le32(x)
129#define const_cpu_to_be16(x) cpu_to_be16(x)
130#define const_cpu_to_be32(x) cpu_to_be32(x)
131
132#endif /* _NTFS_ENDIANS_H */
133
134#ifndef FALSE
135enum { FALSE, TRUE } ;
136#endif /* FALSE */
137
138#ifdef WIN32
139
140typedef unsigned short uid_t;
141typedef unsigned short gid_t;
142
143#define UNICODE(c) ((unsigned short)(c))
144
145#define __attribute__(x)
146
147#else
148
149#ifndef BOOL
150typedef int BOOL; /* Already defined in windows.h */
151#endif /* BOOL */
152
153#ifdef STSC
154
155#define ENOTSUP 95
156
157#endif /* STSC */
158
159typedef u32 DWORD; /* must be 32 bits whatever the platform */
160typedef DWORD *LPDWORD;
161
162#define NTFS_MNT_NONE 0 /* no flag for mounting the device */
163#define NTFS_MNT_RDONLY 1 /* flag for mounting the device read-only */
164
165#endif /* WIN32 */
166
167#if defined(WIN32) | defined(STSC)
168
169/*
170 * On non-Linux computers, there is no mount and the user mapping
171 * if fetched from a real file (or a dummy one for self tests)
172 */
173
174#define NTFS_FIND_USID(map,uid,buf) ntfs_find_usid(map,uid,buf)
175#define NTFS_FIND_GSID(map,gid,buf) ntfs_find_gsid(map,gid,buf)
176#define NTFS_FIND_USER(map,usid) ntfs_find_user(map,usid)
177#define NTFS_FIND_GROUP(map,gsid) ntfs_find_group(map,gsid)
178
179#else
180
181/*
182 * On Linux computers, there is a mount and the user mapping
183 * if either obtained through the mount process or fetched
184 * from a dummy file for self-tests
185 */
186
187#define NTFS_FIND_USID(map,uid,buf) (mappingtype != MAPEXTERN ? \
188 ntfs_find_usid(map,uid,buf) : relay_find_usid(map,uid,buf))
189#define NTFS_FIND_GSID(map,gid,buf) (mappingtype != MAPEXTERN ? \
190 ntfs_find_gsid(map,gid,buf) : relay_find_gsid(map,gid,buf))
191#define NTFS_FIND_USER(map,usid) (mappingtype != MAPEXTERN ? \
192 ntfs_find_user(map,usid) : relay_find_user(map,usid))
193#define NTFS_FIND_GROUP(map,gsid) (mappingtype != MAPEXTERN ? \
194 ntfs_find_group(map,gsid) : relay_find_group(map,gsid))
195
196#endif
197
198/*
199 * A few name hijackings or definitions
200 * needed for using code from ntfs-3g
201 */
202
203#ifdef WIN32
204#define ACL MY_ACL
205#define SID MY_SID
206#define ACCESS_ALLOWED_ACE MY_ACCESS_ALLOWED_ACE
207#define ACCESS_DENIED_ACE MY_ACCESS_DENIED_ACE
208#define FILE_ATTRIBUTE_REPARSE_POINT 0x400
209#define IO_REPARSE_TAG_MOUNT_POINT 0xa0000003
210#define IO_REPARSE_TAG_SYMLINK 0xa000000c
211#else
212#define SE_OWNER_DEFAULTED const_cpu_to_le16(1)
213#define SE_GROUP_DEFAULTED const_cpu_to_le16(2)
214#define SE_DACL_PRESENT const_cpu_to_le16(4)
215#define SE_SACL_PRESENT const_cpu_to_le16(0x10)
216#define SE_DACL_DEFAULTED const_cpu_to_le16(8)
217#define SE_SELF_RELATIVE const_cpu_to_le16(0x8000)
218#define SID_REVISION 1
219#endif /* WIN32 */
220#define SE_DACL_PROTECTED const_cpu_to_le16(0x1000)
221#define SE_SACL_PROTECTED const_cpu_to_le16(0x2000)
222#define SE_DACL_AUTO_INHERITED const_cpu_to_le16(0x400)
223#define SE_SACL_AUTO_INHERITED const_cpu_to_le16(0x800)
Steve Kondike68cb602016-08-28 00:45:36 -0700224#define SE_DACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x100)
225#define SE_SACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x200)
Steve Kondik2111ad72013-07-07 12:07:44 -0700226
227typedef le16 ntfschar;
228
229#define ntfs_log_error(args...) do { printf("** " args); if (!isatty(1)) fprintf(stderr,args); } while(0)
230
231/*
232 * Struct to hold the input mapping file
233 * (private to this module)
234 */
235
236struct MAPLIST {
237 struct MAPLIST *next;
238 char *uidstr; /* uid text from the same record */
239 char *gidstr; /* gid text from the same record */
240 char *sidstr; /* sid text from the same record */
241 char maptext[LINESZ + 1];
242};
243
244/*
245 * A few dummy declarations needed for using code from security.c
246 */
247
248#define MFT_RECORD_IS_DIRECTORY const_cpu_to_le16(1)
249
250struct SECURITY_DATA {
251 u64 offset;
252 char *attr;
253 u32 hash;
254 u32 length;
255 unsigned int filecount:16;
256 unsigned int mode:12;
257 unsigned int flags:4;
258} ;
259
260 /* default security sub-authorities */
261enum {
262 DEFSECAUTH1 = -1153374643, /* 3141592653 */
263 DEFSECAUTH2 = 589793238,
264 DEFSECAUTH3 = 462843383,
265 DEFSECBASE = 10000
266};
267
268#define OWNERID 1016
269#define GROUPID 513
270
271
272#define INSDS1 1
273#define INSDS2 2
274#define INSII 4
275#define INSDH 8
276
277#ifdef WIN32
278
279typedef enum { RECSHOW, RECSET, RECSETPOSIX } RECURSE;
280
281#endif
282
283/*
284 * A type large enough to hold any SID
285 */
286
287typedef char BIGSID[40];
288
289/*
290 * Declarations for memory allocation checks
291 */
292
293struct CHKALLOC
294 {
295 struct CHKALLOC *next;
296 void *alloc;
297 const char *file;
298 int line;
299 size_t size;
300 } ;
301
302#if defined(WIN32) | defined(STSC)
303
304#define S_ISVTX 01000
305#define S_ISGID 02000
306#define S_ISUID 04000
307#define S_IXUSR 0100
308#define S_IWUSR 0200
309#define S_IRUSR 0400
310#define S_IXGRP 010
311#define S_IWGRP 020
312#define S_IRGRP 040
313#define S_IXOTH 001
314#define S_IWOTH 002
315#define S_IROTH 004
316
317#endif
318
319#ifdef WIN32
320#else
321/*
322 *
323 * See http://msdn2.microsoft.com/en-us/library/aa379649.aspx
324 */
325
326typedef enum {
327 DACL_SECURITY_INFORMATION = 4, // The DACL of the object is being referenced.
328 SACL_SECURITY_INFORMATION = 8, // The SACL of the object is being referenced.
329 LABEL_SECURITY_INFORMATION = 8, // The mandatory integrity label is being referenced.
330 GROUP_SECURITY_INFORMATION = 2, // The primary group identifier of the object is being referenced.
331 OWNER_SECURITY_INFORMATION = 1, // The owner identifier of the object is being referenced.
332} SECURITY_INFORMATION;
333
Steve Kondike68cb602016-08-28 00:45:36 -0700334#define STANDARD_RIGHTS_READ const_cpu_to_le32(0x20000)
335#define STANDARD_RIGHTS_WRITE const_cpu_to_le32(0x20000)
336#define STANDARD_RIGHTS_EXECUTE const_cpu_to_le32(0x20000)
337#define STANDARD_RIGHTS_REQUIRED const_cpu_to_le32(0xf0000)
Steve Kondik2111ad72013-07-07 12:07:44 -0700338
339#endif
340
341typedef struct SECHEAD {
342 s8 revision;
343 s8 alignment;
344 le16 control;
345 le32 owner;
346 le32 group;
347 le32 sacl;
348 le32 dacl;
349} SECURITY_DESCRIPTOR_RELATIVE;
350
351typedef struct ACL {
352 s8 revision;
353 s8 alignment1;
354 le16 size;
355 le16 ace_count;
356 le16 alignment2;
357} ACL;
358
359typedef struct {
360 union {
361 struct {
362 unsigned char revision;
363 unsigned char sub_authority_count;
364 } ;
365 struct {
366 /* evade an alignment problem when a 4 byte field */
367 /* in a struct implies alignment of the struct */
368 le16 dummy;
369 be16 high_part;
370 be32 low_part;
371 } identifier_authority;
372 } ;
373 le32 sub_authority[1];
374} SID;
375
376typedef u8 ACE_FLAGS;
377
378typedef struct ACE {
379 u8 type;
380 u8 flags;
381 le16 size;
382 le32 mask;
383 SID sid;
384} ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE;
385
386
387/*
388 * item in the mapping list
389 */
390
391struct MAPPING {
392 struct MAPPING *next;
393 int xid; /* linux id : uid or gid */
394 SID *sid; /* Windows id : usid or gsid */
395 int grcnt; /* group count (for users only) */
396 gid_t *groups; /* groups which the user is member of */
397};
398
399/*
400 * Posix ACL structures
401 */
402
403struct POSIX_ACE {
404 u16 tag;
405 u16 perms;
406 s32 id;
407} ;
408
409struct POSIX_ACL {
410 u8 version;
411 u8 flags;
412 u16 filler;
413 struct POSIX_ACE ace[0];
414} ;
415
416struct POSIX_SECURITY {
417 mode_t mode;
418 int acccnt;
419 int defcnt;
420 int firstdef;
421 u16 tagsset;
422 struct POSIX_ACL acl;
423} ;
424
425/*
426 * Posix tags, cpu-endian 16 bits
427 */
428
429enum {
430 POSIX_ACL_USER_OBJ = 1,
431 POSIX_ACL_USER = 2,
432 POSIX_ACL_GROUP_OBJ = 4,
433 POSIX_ACL_GROUP = 8,
434 POSIX_ACL_MASK = 16,
435 POSIX_ACL_OTHER = 32,
436 POSIX_ACL_SPECIAL = 64 /* internal use only */
437} ;
438
439/*
440 * Posix permissions, cpu-endian 16 bits
441 */
442
443enum {
444 POSIX_PERM_X = 1,
445 POSIX_PERM_W = 2,
446 POSIX_PERM_R = 4,
447 POSIX_PERM_DENIAL = 64 /* internal use only */
448} ;
449
450#define POSIX_VERSION 2
451
452/*
453 * A few definitions adapted from winnt.h
454 * (Windows version uses actual definitions from winnt.h, which are
455 * not compatible with code from security.c on a big-endian computer)
456 */
457
458#ifndef WIN32
459
Steve Kondike68cb602016-08-28 00:45:36 -0700460#define DELETE const_cpu_to_le32(0x00010000L)
461#define READ_CONTROL const_cpu_to_le32(0x00020000L)
462#define WRITE_DAC const_cpu_to_le32(0x00040000L)
463#define WRITE_OWNER const_cpu_to_le32(0x00080000L)
464#define SYNCHRONIZE const_cpu_to_le32(0x00100000L)
Steve Kondik2111ad72013-07-07 12:07:44 -0700465
466
Steve Kondike68cb602016-08-28 00:45:36 -0700467#define FILE_READ_DATA const_cpu_to_le32(0x0001) // file & pipe
468#define FILE_LIST_DIRECTORY const_cpu_to_le32(0x0001) // directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700469
Steve Kondike68cb602016-08-28 00:45:36 -0700470#define FILE_WRITE_DATA const_cpu_to_le32(0x0002) // file & pipe
471#define FILE_ADD_FILE const_cpu_to_le32(0x0002) // directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700472
Steve Kondike68cb602016-08-28 00:45:36 -0700473#define FILE_APPEND_DATA const_cpu_to_le32(0x0004) // file
474#define FILE_ADD_SUBDIRECTORY const_cpu_to_le32(0x0004) // directory
475#define FILE_CREATE_PIPE_INSTANCE const_cpu_to_le32(0x0004) // named pipe
Steve Kondik2111ad72013-07-07 12:07:44 -0700476
477
Steve Kondike68cb602016-08-28 00:45:36 -0700478#define FILE_READ_EA const_cpu_to_le32(0x0008) // file & directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700479
Steve Kondike68cb602016-08-28 00:45:36 -0700480#define FILE_WRITE_EA const_cpu_to_le32(0x0010) // file & directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700481
Steve Kondike68cb602016-08-28 00:45:36 -0700482#define FILE_EXECUTE const_cpu_to_le32(0x0020) // file
483#define FILE_TRAVERSE const_cpu_to_le32(0x0020) // directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700484
Steve Kondike68cb602016-08-28 00:45:36 -0700485#define FILE_DELETE_CHILD const_cpu_to_le32(0x0040) // directory
Steve Kondik2111ad72013-07-07 12:07:44 -0700486
Steve Kondike68cb602016-08-28 00:45:36 -0700487#define FILE_READ_ATTRIBUTES const_cpu_to_le32(0x0080) // all
Steve Kondik2111ad72013-07-07 12:07:44 -0700488
Steve Kondike68cb602016-08-28 00:45:36 -0700489#define FILE_WRITE_ATTRIBUTES const_cpu_to_le32(0x0100) // all
Steve Kondik2111ad72013-07-07 12:07:44 -0700490
491#define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
Steve Kondike68cb602016-08-28 00:45:36 -0700492 const_cpu_to_le32(0x1FF))
Steve Kondik2111ad72013-07-07 12:07:44 -0700493
494#define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
495 FILE_READ_DATA |\
496 FILE_READ_ATTRIBUTES |\
497 FILE_READ_EA |\
498 SYNCHRONIZE)
499
500
501#define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
502 FILE_WRITE_DATA |\
503 FILE_WRITE_ATTRIBUTES |\
504 FILE_WRITE_EA |\
505 FILE_APPEND_DATA |\
506 SYNCHRONIZE)
507
508
509#define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
510 FILE_READ_ATTRIBUTES |\
511 FILE_EXECUTE |\
512 SYNCHRONIZE)
513
Steve Kondike68cb602016-08-28 00:45:36 -0700514#define GENERIC_READ const_cpu_to_le32(0x80000000L)
515#define GENERIC_WRITE const_cpu_to_le32(0x40000000L)
516#define GENERIC_EXECUTE const_cpu_to_le32(0x20000000L)
517#define GENERIC_ALL const_cpu_to_le32(0x10000000L)
Steve Kondik2111ad72013-07-07 12:07:44 -0700518
519
520#define OBJECT_INHERIT_ACE (0x1)
521#define CONTAINER_INHERIT_ACE (0x2)
522#define NO_PROPAGATE_INHERIT_ACE (0x4)
523#define INHERIT_ONLY_ACE (0x8)
524#define INHERITED_ACE (0x10)
525#define VALID_INHERIT_FLAGS (0x1F)
526
527/*
528 * Other useful definitions
529 */
530
531#define ACL_REVISION 2
532#define ACCESS_ALLOWED_ACE_TYPE 0
533#define ACCESS_DENIED_ACE_TYPE 1
534#define SECURITY_DESCRIPTOR_REVISION 1
535
536#endif /* !WIN32 */
537
538#ifndef ACL_REVISION_DS /* not always defined in <windows.h> */
539#define ACL_REVISION_DS 4
540#endif
541
542#ifndef INHERITED_ACE /* not always defined in <windows.h> */
543#define INHERITED_ACE (0x10)
544#undef VALID_INHERIT_FLAGS
545#define VALID_INHERIT_FLAGS (0x1F)
546#endif
547
548/*
549 * Matching of ntfs permissions to Linux permissions
550 * these constants are adapted to endianness
551 * when setting, set them all
552 * when checking, check one is present
553 */
554
555 /* flags which are set to mean exec, write or read */
556
557#define FILE_READ (FILE_READ_DATA)
558#define FILE_WRITE (FILE_WRITE_DATA | FILE_APPEND_DATA \
559 | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA)
560#define FILE_EXEC (FILE_EXECUTE)
561#define DIR_READ FILE_LIST_DIRECTORY
562#define DIR_WRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD \
563 | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA)
564#define DIR_EXEC (FILE_TRAVERSE)
565
566 /* flags tested for meaning exec, write or read */
567 /* tests for write allow for interpretation of a sticky bit */
568
Steve Kondik79165c32015-11-09 19:43:00 -0800569#define FILE_GREAD (FILE_READ_DATA | GENERIC_READ | GENERIC_ALL)
570#define FILE_GWRITE (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE \
571 | GENERIC_ALL)
572#define FILE_GEXEC (FILE_EXECUTE | GENERIC_EXECUTE | GENERIC_ALL)
573#define DIR_GREAD (FILE_LIST_DIRECTORY | GENERIC_READ | GENERIC_ALL)
574#define DIR_GWRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | GENERIC_WRITE \
575 | GENERIC_ALL)
576#define DIR_GEXEC (FILE_TRAVERSE | GENERIC_EXECUTE | GENERIC_ALL)
Steve Kondik2111ad72013-07-07 12:07:44 -0700577
578 /* standard owner (and administrator) rights */
579
580#define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \
581 | SYNCHRONIZE \
582 | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \
583 | FILE_READ_EA | FILE_WRITE_EA)
584
585 /* standard world rights */
586
587#define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \
588 | SYNCHRONIZE)
589
590 /* inheritance flags for files and directories */
591
592#define FILE_INHERITANCE NO_PROPAGATE_INHERIT_ACE
593#define DIR_INHERITANCE (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE)
594
595/*
596 * To identify NTFS ACL meaning Posix ACL granted to root
597 * we use rights always granted to anybody, so they have no impact
598 * either on Windows or on Linux.
599 */
600
601#define ROOT_OWNER_UNMARK SYNCHRONIZE /* ACL granted to root as owner */
602#define ROOT_GROUP_UNMARK FILE_READ_EA /* ACL granted to root as group */
603
604
605struct SII { /* this is an image of an $SII index entry */
606 le16 offs;
607 le16 size;
608 le32 fill1;
609 le16 indexsz;
610 le16 indexksz;
611 le16 flags;
612 le16 fill2;
613 le32 keysecurid;
614
615 /* did not find official description for the following */
616 le32 hash;
617 le32 securid;
618 le32 dataoffsl; /* documented as badly aligned */
619 le32 dataoffsh;
620 le32 datasize;
621} ;
622
623struct SDH { /* this is an image of an $SDH index entry */
624 le16 offs;
625 le16 size;
626 le32 fill1;
627 le16 indexsz;
628 le16 indexksz;
629 le16 flags;
630 le16 fill2;
631 le32 keyhash;
632 le32 keysecurid;
633
634 /* did not find official description for the following */
635 le32 hash;
636 le32 securid;
637 le32 dataoffsl;
638 le32 dataoffsh;
639 le32 datasize;
640 le32 fill3;
641 } ;
642
643#ifndef INVALID_FILE_ATTRIBUTES /* not defined in old windows.h */
644#define INVALID_FILE_ATTRIBUTES (-1)
645#endif
646
647enum { MAPUSERS, MAPGROUPS, MAPCOUNT } ;
648
649struct SECURITY_CONTEXT {
650 struct MAPPING *mapping[MAPCOUNT];
651} ;
652
653typedef enum { MAPNONE, MAPEXTERN, MAPLOCAL, MAPDUMMY } MAPTYPE;
654
655
656
657struct passwd {
658 uid_t pw_uid;
659} ;
660
661struct group {
662 gid_t gr_gid;
663} ;
664
665typedef int (*FILEREADER)(void *fileid, char *buf, size_t size, off_t pos);
666
667/*
668 * Data defined in secaudit.c
669 */
670
671extern MAPTYPE mappingtype;
672
673/*
674 * Functions defined in acls.c
675 */
676
677BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz);
678BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc);
679BOOL ntfs_valid_pattern(const SID *sid);
680BOOL ntfs_same_sid(const SID *first, const SID *second);
681
682
683int ntfs_sid_size(const SID * sid);
684unsigned int ntfs_attr_size(const char *attr);
685
686const SID *ntfs_find_usid(const struct MAPPING *usermapping,
687 uid_t uid, SID *pdefsid);
688const SID *ntfs_find_gsid(const struct MAPPING *groupmapping,
689 gid_t gid, SID *pdefsid);
690uid_t ntfs_find_user(const struct MAPPING *usermapping, const SID *usid);
691gid_t ntfs_find_group(const struct MAPPING *groupmapping, const SID * gsid);
692const SID *ntfs_acl_owner(const char *secattr);
693
694void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc);
695int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode);
696
697
698struct POSIX_SECURITY *ntfs_build_permissions_posix(
699 struct MAPPING* const mapping[],
700 const char *securattr,
701 const SID *usid, const SID *gsid, BOOL isdir);
702int ntfs_build_permissions(const char *securattr,
703 const SID *usid, const SID *gsid, BOOL isdir);
704struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid);
705struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem);
706struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem);
707void ntfs_free_mapping(struct MAPPING *mapping[]);
708
709struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first,
710 const struct POSIX_SECURITY *second);
711char *ntfs_build_descr_posix(struct MAPPING* const mapping[],
712 struct POSIX_SECURITY *pxdesc,
713 int isdir, const SID *usid, const SID *gsid);
714char *ntfs_build_descr(mode_t mode,
715 int isdir, const SID * usid, const SID * gsid);
716
717/*
718 * Functions defined in secaudit.c
719 */
720
721void *chkmalloc(size_t, const char*, int);
722void *chkcalloc(size_t, size_t, const char *, int);
723void chkfree(void*, const char*, int);
724BOOL chkisalloc(void*, const char*, int);
725void dumpalloc(const char*);
726
727#define malloc(sz) chkmalloc(sz, __FILE__, __LINE__)
728#define calloc(cnt,sz) chkcalloc(cnt, sz, __FILE__, __LINE__)
729#define free(ptr) chkfree(ptr, __FILE__, __LINE__)
730#define isalloc(ptr) chkisalloc(ptr, __FILE__, __LINE__)
731#define ntfs_malloc(sz) chkmalloc(sz, __FILE__, __LINE__)
732
733struct passwd *getpwnam(const char *user);
734struct group *getgrnam(const char *group);
735
736const SID *relay_find_usid(const struct MAPPING *usermapping,
737 uid_t uid, SID *pdefsid);
738const SID *relay_find_gsid(const struct MAPPING *groupmapping,
739 gid_t gid, SID *pdefsid);
740uid_t relay_find_user(const struct MAPPING *usermapping, const SID *usid);
741gid_t relay_find_group(const struct MAPPING *groupmapping, const SID * gsid);
742