2 Unix SMB/CIFS implementation.
4 Set NT ACLs on UNIX files.
6 Copyright (C) Tim Potter <tpot@samba.org> 2004
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.
24 #include "system/filesys.h"
26 #if (!defined(HAVE_NO_ACLS) || !defined(HAVE_XATTR_SUPPORT))
28 int main(int argc, char **argv)
30 printf("ACL support not compiled in.");
36 static void setntacl(char *filename, struct security_descriptor *sd)
42 ndr = ndr_push_init();
44 status = ndr_push_security_descriptor(
45 ndr, NDR_SCALARS|NDR_BUFFERS, sd);
48 filename, "security.ntacl", ndr->data, ndr->offset, 0);
51 fprintf(stderr, "%s: %s\n", filename, strerror(errno));
57 int main(int argc, char **argv)
60 struct security_descriptor *sd;
62 struct security_acl *acl;
64 setup_logging("setntacl", DEBUG_STDOUT);
66 mem_ctx = talloc_init("setntacl");
68 sd = sd_initialise(mem_ctx);
70 fgets(line, sizeof(line), stdin);
71 sd->owner_sid = dom_sid_parse_talloc(mem_ctx, line);
73 fgets(line, sizeof(line), stdin);
74 sd->group_sid = dom_sid_parse_talloc(mem_ctx, line);
76 acl = talloc(mem_ctx, sizeof(struct security_acl));
83 while(fgets(line, sizeof(line), stdin)) {
84 int ace_type, ace_flags;
89 if (sscanf(line, "%d %d 0x%x %s", &ace_type, &ace_flags,
90 &ace_mask, sidstr) != 4) {
91 fprintf(stderr, "invalid ACL line\ndr");
95 acl->aces = talloc_realloc(mem_ctx, acl->aces,
96 (acl->num_aces + 1) * sizeof(struct security_ace));
98 acl->aces[acl->num_aces].type = ace_type;
99 acl->aces[acl->num_aces].flags = ace_flags;
100 acl->aces[acl->num_aces].access_mask = ace_mask;
102 sid = dom_sid_parse_talloc(mem_ctx, sidstr);
104 acl->aces[acl->num_aces].trustee = *sid;
111 setntacl(argv[1], sd);
116 #endif /* HAVE_NO_ACLS */