0cb3a2160cf2abbb20c980fc7489e0d437db0ba9
[sfrench/samba-autobuild/.git] / source4 / scripting / ejs / smbcalls_samba3.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    provide hooks into smbd C calls from ejs scripts
5
6    Copyright (C) Jelmer Vernooij 2005
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 "scripting/ejs/smbcalls.h"
25 #include "lib/appweb/ejs/ejs.h"
26 #include "lib/samba3/samba3.h"
27
28 #if 0
29 struct samba3_samaccount {
30         uint32_t logon_time,
31                 logoff_time,
32                 kickoff_time,
33                 bad_password_time,
34                 pass_last_set_time,
35                 pass_can_change_time,
36                 pass_must_change_time;
37         char *username;
38         char *domain;
39         char *nt_username;
40         char *dir_drive;
41         char *unknown_str;
42         char *munged_dial;
43         char *fullname;
44         char *homedir;
45         char *logon_script;
46         char *profile_path;
47         char *acct_desc;
48         char *workstations;
49         uint32_t user_rid, group_rid, hours_len, unknown_6;
50         uint16_t acct_ctrl, logon_divs;
51         uint16_t bad_password_count, logon_count;
52         uint8_t *lm_pw_ptr, *nt_pw_ptr;
53         uint8_t *nt_pw_hist_ptr;
54         uint8_t *hours;
55 };
56
57 struct samba3_groupmapping {
58         gid_t gid;
59         struct dom_sid *sid;
60         int sid_name_use;
61         const char *nt_name;
62         const char *comment;
63 };
64
65 struct samba3_alias {
66         struct dom_sid *sid;
67         uint32_t member_count;
68         struct dom_sid **members;
69 };
70
71 struct samba3_groupdb {
72         uint32_t groupmap_count;
73         struct samba3_groupmapping *groupmappings;
74
75         uint32_t alias_count;
76         struct samba3_alias *aliases;
77 };
78
79 struct samba3_idmap_mapping
80 {
81         enum { IDMAP_GROUP, IDMAP_USER } type;
82         uint32_t unix_id;
83         struct dom_sid *sid;
84 };
85
86 struct samba3_idmapdb
87 {
88         /* High water marks */
89         uint32_t user_hwm;
90         uint32_t group_hwm;
91
92         uint32_t mapping_count;
93         struct samba3_idmap_mapping *mappings;
94 };
95
96 struct samba3_winsdb_entry 
97 {
98         char *name;
99         int nb_flags;
100         int type;
101         time_t ttl;
102         uint32_t ip_count;
103         struct ipv4_addr *ips;
104 };
105
106 struct samba3_policy
107 {
108         uint32_t min_password_length;
109         uint32_t password_history;
110         uint32_t user_must_logon_to_change_password;
111         uint32_t maximum_password_age;
112         uint32_t minimum_password_age;
113         uint32_t lockout_duration;
114         uint32_t reset_count_minutes;
115         uint32_t bad_lockout_minutes;
116         uint32_t disconnect_time;
117         uint32_t refuse_machine_password_change;
118 };
119
120 struct samba3_regval {
121         char *name;
122         uint16_t                type;
123         DATA_BLOB               data;
124 };
125
126 struct samba3_regkey {
127         char *name;
128         
129         uint32_t value_count;
130         struct samba3_regval *values;
131
132         uint32_t subkey_count;
133         char **subkeys;
134 };
135
136 struct samba3_regdb
137 {
138         uint32_t key_count;
139         struct samba3_regkey *keys;
140 };
141
142 struct samba3_secrets
143 {
144         struct cli_credentials *ipc_cred;
145         
146         uint32_t ldappw_count;
147         struct samba3_ldappw 
148         {
149                 char *dn;
150                 char *password;
151         } *ldappws;
152
153         uint32_t domain_count;
154         struct samba3_domainsecrets 
155         {
156                 char *name;
157                 struct dom_sid sid;
158                 struct GUID guid;
159                 char *plaintext_pw;
160                 time_t last_change_time;
161                 struct {
162                         uint8_t hash[16];
163                         time_t mod_time;
164                 } hash_pw;;
165                 int sec_channel_type;
166         } *domains;
167
168         uint32_t trusted_domain_count;
169         struct samba3_trusted_dom_pass {
170                 uint32_t uni_name_len;
171                 const char *uni_name[32]; /* unicode domain name */
172                 const char *pass;               /* trust relationship's password */
173                 time_t mod_time;
174                 struct dom_sid domain_sid;      /* remote domain's sid */
175         } *trusted_domains;
176
177         uint32_t afs_keyfile_count;
178
179         struct samba3_afs_keyfile {
180                 uint32_t nkeys;
181                 struct {
182                         uint32_t kvno;
183                         char key[8];
184                 } entry[8];
185                 char *cell;
186         } *afs_keyfiles;
187 };
188
189 struct samba3_parameter {
190         char *name;
191         char *value;
192 };
193
194 struct samba3_share_info {
195         char *name;
196         struct security_descriptor secdesc;
197
198         uint32_t parameter_count;
199         struct samba3_parameter *parameters;
200 };
201
202 struct samba3 
203 {
204         uint32_t winsdb_count;
205         struct samba3_winsdb_entry *winsdb_entries;
206         
207         uint32_t samaccount_count;
208         struct samba3_samaccount *samaccounts;
209
210         uint32_t share_count;
211         struct samba3_share_info *shares;
212
213         struct samba3_secrets secrets;
214         struct samba3_groupdb group;
215         struct samba3_idmapdb idmap;
216         struct samba3_policy policy;
217         struct samba3_regdb registry;
218 };
219
220 #endif 
221
222 /*
223   initialise samba3 ejs subsystem
224 */
225 static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv)
226 {
227         struct MprVar *mpv = mprInitObject(eid, "samba3", argc, argv);
228         struct samba3 *samba3;
229         NTSTATUS status;
230
231         if (argc < 2) {
232                 ejsSetErrorMsg(eid, "samba3_read invalid arguments");
233                 return -1;
234         }
235
236         status = samba3_read(mprToString(argv[0]), mprToString(argv[0]), mprMemCtx(), &samba3);
237
238         if (NT_STATUS_IS_ERR(status)) {
239                 ejsSetErrorMsg(eid, "samba3_read: error");
240                 return -1;
241         }
242
243         mprSetThisPtr(eid, "db", samba3);
244         
245         return 0;
246 }
247
248
249 /*
250   setup C functions that be called from ejs
251 */
252 void smb_setup_ejs_samba3(void)
253 {
254         ejsDefineCFunction(-1, "samba3_read", ejs_samba3_read, NULL, MPR_VAR_SCRIPT_HANDLE);
255 }