r3586: Fix some of the issues with the module init functions.
[jelmer/samba4-debian.git] / source / utils / setnttoken.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Set NT ACLs on UNIX files.
5
6    Copyright (C) Tim Potter <tpot@samba.org> 2004
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "system/filesys.h"
25
26 #if (defined(HAVE_NO_ACLS) || !defined(HAVE_XATTR_SUPPORT))
27
28 int main(int argc, char **argv)
29 {
30         printf("ACL support not compiled in.");
31         return 1;
32 }
33
34 #else
35
36 int main(int argc, char **argv)
37 {
38         char line[255];
39         struct ndr_push *ndr;
40         struct lsa_SidArray sidarray;
41         NTSTATUS status;
42         TALLOC_CTX *mem_ctx;
43
44         static_init_setnttoken;
45
46         setup_logging("setnttoken", DEBUG_STDOUT);
47
48         mem_ctx = talloc_init("setnttoken");
49
50         ndr = ndr_push_init();
51
52         sidarray.num_sids = 0;
53         sidarray.sids = NULL;
54
55         while(fgets(line, sizeof(line), stdin)) {
56                 struct dom_sid *sid = dom_sid_parse_talloc(ndr, line);
57
58                 if (!sid) {
59                         fprintf(stderr, "Invalid sid: %s", line);
60                         continue;
61                 }
62
63                 sidarray.sids = talloc_realloc(mem_ctx, sidarray.sids,
64                                 (sidarray.num_sids + 1) * sizeof(struct lsa_SidPtr));
65
66                 sidarray.sids[sidarray.num_sids].sid =
67                         dom_sid_dup(ndr, sid);
68
69                 sidarray.num_sids++;
70         }
71
72 /*      NDR_PRINT_DEBUG(lsa_SidArray, &sidarray); */
73
74         status = ndr_push_lsa_SidArray(
75                 ndr, NDR_SCALARS|NDR_BUFFERS, &sidarray);
76
77         fwrite(ndr->data, 1, ndr->offset, stdout);
78
79         return 0;
80 }
81
82 #endif /* HAVE_NO_ACLS */