r19463: Make it clear what argument is incorrect
[Samba/gbeck.git] / source / utils / getntacl.c
blob441f233a8473edc59e660b96362caadcbd53968c
1 /*
2 Unix SMB/CIFS implementation.
4 Get NT ACLs from UNIX files.
6 Copyright (C) Tim Potter <tpot@samba.org> 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "system/filesys.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
26 #include "lib/util/wrap_xattr.h"
28 static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
30 static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
32 va_list ap;
33 char *s = NULL;
34 int i;
36 va_start(ap, format);
37 vasprintf(&s, format, ap);
38 va_end(ap);
40 for (i=0;i<ndr->depth;i++) {
41 printf(" ");
44 printf("%s\n", s);
45 free(s);
48 static NTSTATUS get_ntacl(char *filename, struct xattr_NTACL **ntacl,
49 ssize_t *ntacl_len)
51 DATA_BLOB blob;
52 ssize_t size;
53 NTSTATUS result;
54 struct ndr_pull *ndr;
55 struct ndr_print *pr;
57 *ntacl = talloc(NULL, struct xattr_NTACL);
59 size = wrap_getxattr(filename, XATTR_NTACL_NAME, NULL, 0);
61 if (size < 0) {
62 fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
63 return NT_STATUS_INTERNAL_ERROR;
66 blob.data = talloc_size(*ntacl, size);
67 size = wrap_getxattr(filename, XATTR_NTACL_NAME, blob.data, size);
68 if (size < 0) {
69 fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
70 return NT_STATUS_INTERNAL_ERROR;
72 blob.length = size;
74 ndr = ndr_pull_init_blob(&blob, NULL);
76 result = ndr_pull_xattr_NTACL(ndr, NDR_SCALARS|NDR_BUFFERS, *ntacl);
78 if (NT_STATUS_IS_OK(result)) {
79 pr = talloc(*ntacl, struct ndr_print);
80 pr->print = ntacl_print_debug_helper;
81 pr->depth = 0;
82 pr->flags = 0;
84 ndr_print_xattr_NTACL(pr, filename, *ntacl);
87 return result;
90 static void print_ntacl(struct xattr_NTACL *ntacl)
94 int main(int argc, char *argv[])
96 struct xattr_NTACL *ntacl;
97 ssize_t ntacl_len;
99 if (argc != 2) {
100 fprintf(stderr, "Usage: getntacl FILENAME\n");
101 return 1;
105 get_ntacl(argv[1], &ntacl, &ntacl_len);
107 print_ntacl(ntacl);
109 return 0;