summaryrefslogtreecommitdiff
path: root/source4/utils/getntacl.c
blob: 8d857d206ab27906f041197d05e5d0aa2ffc64de (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
128
129
/* 
   Unix SMB/CIFS implementation.

   Get NT ACLs from UNIX files.

   Copyright (C) Tim Potter <tpot@samba.org> 2005
   
   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"
#include "system/filesys.h"
#include "libcli/security/security.h"
#include "librpc/gen_ndr/ndr_xattr.h"

#if HAVE_XATTR_SUPPORT	

/* eww - crappy dependencies */

NTSTATUS samdb_privilege_setup(struct security_token *token)
{
	token->privilege_mask = 0;
	return NT_STATUS_OK;
}

static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
{
	va_list ap;
	char *s = NULL;
	int i;

	va_start(ap, format);
	vasprintf(&s, format, ap);
	va_end(ap);

	for (i=0;i<ndr->depth;i++) {
		printf("    ");
	}

	printf("%s\n", s);
	free(s);
}

static NTSTATUS get_ntacl(char *filename, struct xattr_NTACL **ntacl, 
			  ssize_t *ntacl_len)
{
	DATA_BLOB blob;
	ssize_t size;
	NTSTATUS result;
	struct ndr_pull *ndr;
	struct ndr_print *pr;

	*ntacl = talloc(NULL, struct xattr_NTACL);

	size = getxattr(filename, XATTR_NTACL_NAME, NULL, 0);

	if (size < 0) {
		fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
		return NT_STATUS_INTERNAL_ERROR;
	}

	blob.data = talloc_size(*ntacl, size);
	blob.length = getxattr(filename, XATTR_NTACL_NAME, blob.data, size);

	if (blob.length < 0) {
		fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
		return NT_STATUS_INTERNAL_ERROR;
	}

	ndr = ndr_pull_init_blob(&blob, NULL);

	result = ndr_pull_xattr_NTACL(ndr, NDR_SCALARS|NDR_BUFFERS, *ntacl);

	if (NT_STATUS_IS_OK(result)) {
		pr = talloc(*ntacl, struct ndr_print);
		pr->print = ntacl_print_debug_helper;
		pr->depth = 0;
		pr->flags = 0;
		
		ndr_print_xattr_NTACL(pr, filename, *ntacl);
	}

	return result;
}

static void print_ntacl(struct xattr_NTACL *ntacl)
{
}

int main(int argc, char *argv[])
{
	struct xattr_NTACL *ntacl;
	ssize_t ntacl_len;

	if (argc != 2) {
		fprintf(stderr, "Usage: getntacl FILENAME\n");
		return 1;
	}


	get_ntacl(argv[1], &ntacl, &ntacl_len);

	print_ntacl(ntacl);

	return 0;
}

#else

int main(int argc, char *argv[])
{
	printf("getntacl: not compiled with xattr support!\n");
	return 1;

}

#endif