summaryrefslogtreecommitdiff
path: root/source4/utils
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-11-02 08:49:23 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:44:00 +0100
commitf1374b02eab98fa63d484e39a14a934db4ee0dea (patch)
tree35e00747b6e75c51c5aea6486112c9cbea9130bc /source4/utils
parent8fc7df10fb1e3a5fdd6764bc4aea0a661eee7770 (diff)
downloadsamba-f1374b02eab98fa63d484e39a14a934db4ee0dea.tar.gz
samba-f1374b02eab98fa63d484e39a14a934db4ee0dea.tar.bz2
samba-f1374b02eab98fa63d484e39a14a934db4ee0dea.zip
r25790: - remove some nesting by using error and out logic
- print in the print_* function ... metze (This used to be commit dbd7e8bcceeecaa650b164990f9874cf3308974e)
Diffstat (limited to 'source4/utils')
-rw-r--r--source4/utils/getntacl.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/source4/utils/getntacl.c b/source4/utils/getntacl.c
index c3f9332537..18a889a030 100644
--- a/source4/utils/getntacl.c
+++ b/source4/utils/getntacl.c
@@ -44,16 +44,17 @@ static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format,
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;
struct ndr_pull *ndr;
- struct ndr_print *pr;
- *ntacl = talloc(NULL, struct xattr_NTACL);
+ *ntacl = talloc(mem_ctx, struct xattr_NTACL);
size = wrap_getxattr(filename, XATTR_NTACL_NAME, NULL, 0);
@@ -74,24 +75,30 @@ static NTSTATUS get_ntacl(char *filename, struct xattr_NTACL **ntacl,
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);
+ if (!NT_STATUS_IS_OK(result)) {
+ return result;
}
- 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;
@@ -100,10 +107,15 @@ int main(int argc, char *argv[])
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;
}