summaryrefslogtreecommitdiff
path: root/source4/utils/getntacl.c
blob: 0d6e86bf3b2328b0b25d2c906731812e2080ba2c (plain)
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
/* 
   Unix SMB/CIFS implementation.

   Get NT ACLs from UNIX files.

   Copyright (C) Tim Potter <tpot@samba.org> 2004
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 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 General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"

#ifdef HAVE_NO_ACLS

int main(int argc, char **argv)
{
	printf("ACL support not compiled in.");
	return 1;
}

#else

/* Display a security descriptor in "psec" format which is as follows.

   The first two lines describe the owner user and owner group of the
   object.  If either of these lines are blank then the respective
   owner property is not set.  The remaining lines list the individual
   permissions or ACE entries, one per line.  Each column describes a
   different property of the ACE:

       Column    Description
       -------------------------------------------------------------------
         1       ACE type (allow/deny etc)
         2       ACE flags
         3       ACE mask
         4       SID the ACE applies to

   Example:

       S-1-5-21-1067277791-1719175008-3000797951-500

       1 9 0x10000000 S-1-5-21-1067277791-1719175008-3000797951-501
       1 2 0x10000000 S-1-5-21-1067277791-1719175008-3000797951-501
       0 9 0x10000000 S-1-5-21-1067277791-1719175008-3000797951-500
       0 2 0x10000000 S-1-5-21-1067277791-1719175008-3000797951-500
       0 9 0x10000000 S-1-5-21-1067277791-1719175008-3000797951-513
       0 2 0x00020000 S-1-5-21-1067277791-1719175008-3000797951-513
       0 2 0xe0000000 S-1-1-0
*/

static void print_psec(TALLOC_CTX *mem_ctx, struct security_descriptor *sd)
{
	if (sd->owner_sid)
		printf("%s\n", dom_sid_string(mem_ctx, sd->owner_sid));
	else
		printf("\n");

	if (sd->group_sid)
		printf("%s\n", dom_sid_string(mem_ctx, sd->owner_sid));
	else
		printf("\n");

	/* Note: SACL not displayed */

	if (sd->dacl) {
		int i;

		for (i = 0; i < sd->dacl->num_aces; i++) {
			struct security_ace *ace = &sd->dacl->aces[i];
			
			printf("%d %d 0x%08x %s\n", ace->type, ace->flags,
			       ace->access_mask, 
			       dom_sid_string(mem_ctx, &ace->trustee));
		}
			
	}
}

int main(int argc, char **argv)
{
	TALLOC_CTX *mem_ctx;
	ssize_t size;
	char *data;
	struct security_descriptor sd;
	DATA_BLOB blob;
	struct ndr_pull *ndr;
	NTSTATUS result;

	mem_ctx = talloc_init("getntacl");

	/* Fetch ACL data */

	size = getxattr(argv[1], "security.ntacl", NULL, 0);

	if (size == -1) {
		fprintf(stderr, "%s: %s\n", argv[1], strerror(errno));
		exit(1);
	}

	data = talloc(mem_ctx, size);

	size = getxattr(argv[1], "security.ntacl", data, size);

	blob = data_blob_talloc(mem_ctx, data, size);

	ndr = ndr_pull_init_blob(&blob, mem_ctx);

	result = ndr_pull_security_descriptor(
		ndr, NDR_SCALARS|NDR_BUFFERS, &sd);

	print_psec(data, &sd);
	return 0;
}

#endif /* HAVE_NO_ACLS */