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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "system/filesys.h"
24 #include "librpc/gen_ndr/ndr_xattr.h"
25 #include "../lib/util/wrap_xattr.h"
26 #include "param/param.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
, ...)
37 vasprintf(&s
, format
, ap
);
40 for (i
=0;i
<ndr
->depth
;i
++) {
48 static NTSTATUS
get_ntacl(TALLOC_CTX
*mem_ctx
,
50 struct xattr_NTACL
**ntacl
,
55 enum ndr_err_code ndr_err
;
58 *ntacl
= talloc(mem_ctx
, struct xattr_NTACL
);
60 size
= wrap_getxattr(filename
, XATTR_NTACL_NAME
, NULL
, 0);
63 fprintf(stderr
, "get_ntacl: %s\n", strerror(errno
));
64 return NT_STATUS_INTERNAL_ERROR
;
67 blob
.data
= talloc_array(*ntacl
, uint8_t, size
);
68 size
= wrap_getxattr(filename
, XATTR_NTACL_NAME
, blob
.data
, size
);
70 fprintf(stderr
, "get_ntacl: %s\n", strerror(errno
));
71 return NT_STATUS_INTERNAL_ERROR
;
75 ndr
= ndr_pull_init_blob(&blob
, NULL
, NULL
);
77 ndr_err
= ndr_pull_xattr_NTACL(ndr
, NDR_SCALARS
|NDR_BUFFERS
, *ntacl
);
78 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
79 return ndr_map_error2ntstatus(ndr_err
);
85 static void print_ntacl(TALLOC_CTX
*mem_ctx
,
87 struct xattr_NTACL
*ntacl
)
91 pr
= talloc_zero(mem_ctx
, struct ndr_print
);
93 pr
->print
= ntacl_print_debug_helper
;
95 ndr_print_xattr_NTACL(pr
, fname
, ntacl
);
99 int main(int argc
, char *argv
[])
102 struct xattr_NTACL
*ntacl
;
106 fprintf(stderr
, "Usage: getntacl FILENAME\n");
110 status
= get_ntacl(NULL
, argv
[1], &ntacl
, &ntacl_len
);
111 if (!NT_STATUS_IS_OK(status
)) {
112 fprintf(stderr
, "get_ntacl failed: %s\n", nt_errstr(status
));
116 print_ntacl(ntacl
, argv
[1], ntacl
);