1755b230851607a61e8f83309978e1aa007224e3
[metze/samba/wip.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 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
24 #include "includes.h"
25 #include "lib/appweb/ejs/ejs.h"
26 #include "libnet/libnet.h"
27 #include "scripting/ejs/smbcalls.h"
28 #include "events/events.h"
29 #include "auth/credentials/credentials.h"
30
31
32 /*
33   Properties:
34   DomainsList.Domains[0]
35   DomainsList.Status
36 */
37 struct MprVar mprDomainsList(TALLOC_CTX *mem_ctx, struct libnet_DomainList *list, NTSTATUS result)
38 {
39         const char *name = "DomainsList";
40         NTSTATUS status;
41         struct MprVar mprDomainList, mprDomains;
42         struct MprVar mprSid, mprDomainName;
43         struct MprVar mprDomain;
44         int i;
45
46         if (list == NULL || mem_ctx == NULL) {
47                 mprDomainList = mprCreateNullVar();
48                 goto done;
49         }
50
51         mprDomains = mprArray("Domains");
52         for (i = 0; i < list->out.count; i++) {
53                 struct domainlist d = list->out.domains[i];
54
55                 /* get domainlist fields */
56                 mprSid        = mprString(d.sid);
57                 mprDomainName = mprString(d.name);
58
59                 mprDomain = mprObject("Domain");
60                 mprSetVar(&mprDomain, "Name", mprDomainName);
61                 mprSetVar(&mprDomain, "SID", mprSid);
62
63                 mprAddArray(&mprDomains, i, mprDomain);
64         }
65
66         mprDomainList = mprObject(name);
67         status = mprSetVar(&mprDomainList, "Domains", mprDomains);
68         if (!NT_STATUS_IS_OK(status)) goto done;
69         status = mprSetVar(&mprDomainList, "Count", mprCreateIntegerVar(list->out.count));
70         if (!NT_STATUS_IS_OK(status)) goto done;
71         status = mprSetVar(&mprDomainList, "Status", mprNTSTATUS(result));
72
73 done:
74         return mprDomainList;
75 }