8258ea525692dc0fa5887185cc1f7e76c006e94d
[sfrench/samba-autobuild/.git] / source4 / scripting / ejs / ejsnet / mpr_host.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    provides interfaces to libnet calls from ejs scripts
5
6    Copyright (C) Rafal Szczesniak  2005-2007
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22
23 #include "includes.h"
24 #include "lib/appweb/ejs/ejs.h"
25 #include "libnet/libnet.h"
26 #include "scripting/ejs/smbcalls.h"
27 #include "events/events.h"
28 #include "auth/credentials/credentials.h"
29
30
31 /*
32   Properties:
33   DomainsList.Domains[0]
34   DomainsList.Status
35 */
36 struct MprVar mprDomainsList(TALLOC_CTX *mem_ctx, struct libnet_DomainList *list, NTSTATUS result)
37 {
38         const char *name = "DomainsList";
39         NTSTATUS status;
40         struct MprVar mprDomainList, mprDomains;
41         struct MprVar mprSid, mprDomainName;
42         struct MprVar mprDomain;
43         int i;
44
45         if (list == NULL || mem_ctx == NULL) {
46                 mprDomainList = mprCreateNullVar();
47                 goto done;
48         }
49
50         mprDomains = mprArray("Domains");
51         for (i = 0; i < list->out.count; i++) {
52                 struct domainlist d = list->out.domains[i];
53
54                 /* get domainlist fields */
55                 mprSid        = mprString(d.sid);
56                 mprDomainName = mprString(d.name);
57
58                 mprDomain = mprObject("Domain");
59                 mprSetVar(&mprDomain, "Name", mprDomainName);
60                 mprSetVar(&mprDomain, "SID", mprSid);
61
62                 mprAddArray(&mprDomains, i, mprDomain);
63         }
64
65         mprDomainList = mprObject(name);
66         status = mprSetVar(&mprDomainList, "Domains", mprDomains);
67         if (!NT_STATUS_IS_OK(status)) goto done;
68         status = mprSetVar(&mprDomainList, "Count", mprCreateIntegerVar(list->out.count));
69         if (!NT_STATUS_IS_OK(status)) goto done;
70         status = mprSetVar(&mprDomainList, "Status", mprNTSTATUS(result));
71
72 done:
73         return mprDomainList;
74 }