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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "system/filesys.h"
#include "librpc/gen_ndr/ndr_xattr.h"
-
-#if HAVE_XATTR_SUPPORT
+#include "lib/util/wrap_xattr.h"
static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
free(s);
}
-static NTSTATUS get_ntacl(char *filename, struct xattr_NTACL **ntacl,
+static NTSTATUS get_ntacl(TALLOC_CTX *mem_ctx,
+ char *filename,
+ struct xattr_NTACL **ntacl,
ssize_t *ntacl_len)
{
DATA_BLOB blob;
ssize_t size;
- NTSTATUS result;
+ enum ndr_err_code ndr_err;
struct ndr_pull *ndr;
- struct ndr_print *pr;
- *ntacl = talloc(NULL, struct xattr_NTACL);
+ *ntacl = talloc(mem_ctx, struct xattr_NTACL);
- size = getxattr(filename, XATTR_NTACL_NAME, NULL, 0);
+ size = wrap_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);
- size = getxattr(filename, XATTR_NTACL_NAME, blob.data, size);
+ blob.data = talloc_array(*ntacl, uint8_t, size);
+ size = wrap_getxattr(filename, XATTR_NTACL_NAME, blob.data, size);
if (size < 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);
+ ndr_err = ndr_pull_xattr_NTACL(ndr, NDR_SCALARS|NDR_BUFFERS, *ntacl);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return ndr_map_error2ntstatus(ndr_err);
}
- return result;
+ return NT_STATUS_OK;
}
-static void print_ntacl(struct xattr_NTACL *ntacl)
+static void print_ntacl(TALLOC_CTX *mem_ctx,
+ const char *fname,
+ struct xattr_NTACL *ntacl)
{
+ struct ndr_print *pr;
+
+ pr = talloc_zero(mem_ctx, struct ndr_print);
+ if (!pr) return;
+ pr->print = ntacl_print_debug_helper;
+
+ ndr_print_xattr_NTACL(pr, fname, ntacl);
+ talloc_free(pr);
}
int main(int argc, char *argv[])
{
+ NTSTATUS status;
struct xattr_NTACL *ntacl;
ssize_t ntacl_len;
return 1;
}
+ status = get_ntacl(NULL, argv[1], &ntacl, &ntacl_len);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "get_ntacl failed: %s\n", nt_errstr(status));
+ return 1;
+ }
- get_ntacl(argv[1], &ntacl, &ntacl_len);
+ print_ntacl(ntacl, argv[1], ntacl);
- print_ntacl(ntacl);
+ talloc_free(ntacl);
return 0;
}
-
-#else
-
-int main(int argc, char *argv[])
-{
- printf("getntacl: not compiled with xattr support!\n");
- return 1;
-
-}
-
-#endif