Add _wkssvc_NetrJoinDomain2() server.
[samba.git] / source3 / rpc_server / srv_wkssvc_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *
5  *  Copyright (C) Andrew Tridgell               1992-1997,
6  *  Copyright (C) Gerald (Jerry) Carter         2006.
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 /* This is the implementation of the wks interface. */
23
24 #include "includes.h"
25 #include "libnet/libnet_join.h"
26 #include "libnet/libnet_proto.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_SRV
30
31 /*******************************************************************
32  Fill in the values for the struct wkssvc_NetWkstaInfo100.
33  ********************************************************************/
34
35 static void create_wks_info_100(struct wkssvc_NetWkstaInfo100 *info100)
36 {
37         info100->platform_id     = PLATFORM_ID_NT;      /* unknown */
38         info100->version_major   = lp_major_announce_version();
39         info100->version_minor   = lp_minor_announce_version();
40
41         info100->server_name = talloc_asprintf_strupper_m(
42                 info100, "%s", global_myname());
43         info100->domain_name = talloc_asprintf_strupper_m(
44                 info100, "%s", lp_workgroup());
45
46         return;
47 }
48
49 /********************************************************************
50  only supports info level 100 at the moment.
51  ********************************************************************/
52
53 WERROR _wkssvc_NetWkstaGetInfo(pipes_struct *p, struct wkssvc_NetWkstaGetInfo *r)
54 {
55         struct wkssvc_NetWkstaInfo100 *wks100 = NULL;
56         
57         /* We only support info level 100 currently */
58         
59         if ( r->in.level != 100 ) {
60                 return WERR_UNKNOWN_LEVEL;
61         }
62
63         if ( (wks100 = TALLOC_ZERO_P(p->mem_ctx, struct wkssvc_NetWkstaInfo100)) == NULL ) {
64                 return WERR_NOMEM;
65         }
66
67         create_wks_info_100( wks100 );
68         
69         r->out.info->info100 = wks100;
70
71         return WERR_OK;
72 }
73
74 /********************************************************************
75  ********************************************************************/
76
77 WERROR _wkssvc_NetWkstaSetInfo(pipes_struct *p, struct wkssvc_NetWkstaSetInfo *r)
78 {
79         /* FIXME: Add implementation code here */
80         p->rng_fault_state = True;
81         return WERR_NOT_SUPPORTED;
82 }
83
84 /********************************************************************
85  ********************************************************************/
86
87 WERROR _wkssvc_NetWkstaEnumUsers(pipes_struct *p, struct wkssvc_NetWkstaEnumUsers *r)
88 {
89         /* FIXME: Add implementation code here */
90         p->rng_fault_state = True;
91         return WERR_NOT_SUPPORTED;
92 }
93
94 /********************************************************************
95  ********************************************************************/
96
97 WERROR _wkssvc_NetrWkstaUserGetInfo(pipes_struct *p, struct wkssvc_NetrWkstaUserGetInfo *r)
98 {
99         /* FIXME: Add implementation code here */
100         p->rng_fault_state = True;
101         return WERR_NOT_SUPPORTED;
102 }
103
104 /********************************************************************
105  ********************************************************************/
106
107 WERROR _wkssvc_NetrWkstaUserSetInfo(pipes_struct *p, struct wkssvc_NetrWkstaUserSetInfo *r)
108 {
109         /* FIXME: Add implementation code here */
110         p->rng_fault_state = True;
111         return WERR_NOT_SUPPORTED;
112 }
113
114 /********************************************************************
115  ********************************************************************/
116
117 WERROR _wkssvc_NetWkstaTransportEnum(pipes_struct *p, struct wkssvc_NetWkstaTransportEnum *r)
118 {
119         /* FIXME: Add implementation code here */
120         p->rng_fault_state = True;
121         return WERR_NOT_SUPPORTED;
122 }
123
124 /********************************************************************
125  ********************************************************************/
126
127 WERROR _wkssvc_NetrWkstaTransportAdd(pipes_struct *p, struct wkssvc_NetrWkstaTransportAdd *r)
128 {
129         /* FIXME: Add implementation code here */
130         p->rng_fault_state = True;
131         return WERR_NOT_SUPPORTED;
132 }
133
134 /********************************************************************
135  ********************************************************************/
136
137 WERROR _wkssvc_NetrWkstaTransportDel(pipes_struct *p, struct wkssvc_NetrWkstaTransportDel *r)
138 {
139         /* FIXME: Add implementation code here */
140         p->rng_fault_state = True;
141         return WERR_NOT_SUPPORTED;
142 }
143
144 /********************************************************************
145  ********************************************************************/
146
147 WERROR _wkssvc_NetrUseAdd(pipes_struct *p, struct wkssvc_NetrUseAdd *r)
148 {
149         /* FIXME: Add implementation code here */
150         p->rng_fault_state = True;
151         return WERR_NOT_SUPPORTED;
152 }
153
154 /********************************************************************
155  ********************************************************************/
156
157 WERROR _wkssvc_NetrUseGetInfo(pipes_struct *p, struct wkssvc_NetrUseGetInfo *r)
158 {
159         /* FIXME: Add implementation code here */
160         p->rng_fault_state = True;
161         return WERR_NOT_SUPPORTED;
162 }
163
164 /********************************************************************
165  ********************************************************************/
166
167 WERROR _wkssvc_NetrUseDel(pipes_struct *p, struct wkssvc_NetrUseDel *r)
168 {
169         /* FIXME: Add implementation code here */
170         p->rng_fault_state = True;
171         return WERR_NOT_SUPPORTED;
172 }
173
174 /********************************************************************
175  ********************************************************************/
176
177 WERROR _wkssvc_NetrUseEnum(pipes_struct *p, struct wkssvc_NetrUseEnum *r)
178 {
179         /* FIXME: Add implementation code here */
180         p->rng_fault_state = True;
181         return WERR_NOT_SUPPORTED;
182 }
183
184 /********************************************************************
185  ********************************************************************/
186
187 WERROR _wkssvc_NetrMessageBufferSend(pipes_struct *p, struct wkssvc_NetrMessageBufferSend *r)
188 {
189         /* FIXME: Add implementation code here */
190         p->rng_fault_state = True;
191         return WERR_NOT_SUPPORTED;
192 }
193
194 /********************************************************************
195  ********************************************************************/
196
197 WERROR _wkssvc_NetrWorkstationStatisticsGet(pipes_struct *p, struct wkssvc_NetrWorkstationStatisticsGet *r) 
198 {
199         /* FIXME: Add implementation code here */
200         p->rng_fault_state = True;
201         return WERR_NOT_SUPPORTED;
202 }
203
204 /********************************************************************
205  ********************************************************************/
206
207 WERROR _wkssvc_NetrLogonDomainNameAdd(pipes_struct *p, struct wkssvc_NetrLogonDomainNameAdd *r)
208 {
209         /* FIXME: Add implementation code here */
210         p->rng_fault_state = True;
211         return WERR_NOT_SUPPORTED;
212 }
213
214 /********************************************************************
215  ********************************************************************/
216
217 WERROR _wkssvc_NetrLogonDomainNameDel(pipes_struct *p, struct wkssvc_NetrLogonDomainNameDel *r)
218 {
219         /* FIXME: Add implementation code here */
220         p->rng_fault_state = True;
221         return WERR_NOT_SUPPORTED;
222 }
223
224 /********************************************************************
225  ********************************************************************/
226
227 WERROR _wkssvc_NetrJoinDomain(pipes_struct *p, struct wkssvc_NetrJoinDomain *r)
228 {
229         /* FIXME: Add implementation code here */
230         p->rng_fault_state = True;
231         return WERR_NOT_SUPPORTED;
232 }
233
234 /********************************************************************
235  ********************************************************************/
236
237 WERROR _wkssvc_NetrUnjoinDomain(pipes_struct *p, struct wkssvc_NetrUnjoinDomain *r)
238 {
239         /* FIXME: Add implementation code here */
240         p->rng_fault_state = True;
241         return WERR_NOT_SUPPORTED;
242 }
243
244 /********************************************************************
245  ********************************************************************/
246
247 WERROR _wkssvc_NetrRenameMachineInDomain(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain *r)
248 {
249         /* FIXME: Add implementation code here */
250         p->rng_fault_state = True;
251         return WERR_NOT_SUPPORTED;
252 }
253
254 /********************************************************************
255  ********************************************************************/
256
257 WERROR _wkssvc_NetrValidateName(pipes_struct *p, struct wkssvc_NetrValidateName *r)
258 {
259         /* FIXME: Add implementation code here */
260         p->rng_fault_state = True;
261         return WERR_NOT_SUPPORTED;
262 }
263
264 /********************************************************************
265  ********************************************************************/
266
267 WERROR _wkssvc_NetrGetJoinInformation(pipes_struct *p, struct wkssvc_NetrGetJoinInformation *r)
268 {
269         /* FIXME: Add implementation code here */
270         p->rng_fault_state = True;
271         return WERR_NOT_SUPPORTED;
272 }
273
274 /********************************************************************
275  ********************************************************************/
276
277 WERROR _wkssvc_NetrGetJoinableOus(pipes_struct *p, struct wkssvc_NetrGetJoinableOus *r)
278 {
279         /* FIXME: Add implementation code here */
280         p->rng_fault_state = True;
281         return WERR_NOT_SUPPORTED;
282 }
283
284 /********************************************************************
285  ********************************************************************/
286
287 WERROR _wkssvc_NetrJoinDomain2(pipes_struct *p, struct wkssvc_NetrJoinDomain2 *r)
288 {
289         struct libnet_JoinCtx *j = NULL;
290         char *pwd = NULL;
291         char *admin_domain = NULL;
292         char *admin_account = NULL;
293         WERROR werr;
294         NTSTATUS status;
295         struct nt_user_token *token = p->pipe_user.nt_user_token;
296         struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
297
298         if (!r->in.domain_name) {
299                 return WERR_INVALID_PARAM;
300         }
301
302         if (!user_has_privileges(token, &se_machine_account) &&
303             !nt_token_check_domain_rid(token, DOMAIN_GROUP_RID_ADMINS) &&
304             !nt_token_check_domain_rid(token, BUILTIN_ALIAS_RID_ADMINS)) {
305                 return WERR_ACCESS_DENIED;
306         }
307
308         werr = decode_wkssvc_join_password_buffer(p->mem_ctx,
309                                                   r->in.encrypted_password,
310                                                   &p->session_key,
311                                                   &pwd);
312         if (!W_ERROR_IS_OK(werr)) {
313                 return werr;
314         }
315
316         werr = libnet_init_JoinCtx(p->mem_ctx, &j);
317         if (!W_ERROR_IS_OK(werr)) {
318                 return werr;
319         }
320
321         split_domain_user(p->mem_ctx,
322                           r->in.admin_account,
323                           &admin_domain,
324                           &admin_account);
325
326         status = DsGetDcName(p->mem_ctx,
327                              NULL,
328                              r->in.domain_name,
329                              NULL,
330                              NULL,
331                              DS_DIRECTORY_SERVICE_REQUIRED |
332                              DS_WRITABLE_REQUIRED |
333                              DS_RETURN_DNS_NAME,
334                              &info);
335         if (!NT_STATUS_IS_OK(status)) {
336                 return ntstatus_to_werror(status);
337         }
338
339         j->in.server_name       = info->domain_controller_name;
340         j->in.domain_name       = r->in.domain_name;
341         j->in.account_ou        = r->in.account_ou;
342         j->in.join_flags        = r->in.join_flags;
343
344         j->in.admin_account = admin_account;
345         j->in.password = pwd;
346         j->in.modify_config = true;
347
348         become_root();
349         werr = libnet_Join(p->mem_ctx, j);
350         unbecome_root();
351
352         return werr;
353 }
354
355 /********************************************************************
356  ********************************************************************/
357
358 WERROR _wkssvc_NetrUnjoinDomain2(pipes_struct *p, struct wkssvc_NetrUnjoinDomain2 *r)
359 {
360         /* FIXME: Add implementation code here */
361         p->rng_fault_state = True;
362         return WERR_NOT_SUPPORTED;
363 }
364
365 /********************************************************************
366  ********************************************************************/
367
368 WERROR _wkssvc_NetrRenameMachineInDomain2(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain2 *r)
369 {
370         /* FIXME: Add implementation code here */
371         p->rng_fault_state = True;
372         return WERR_NOT_SUPPORTED;
373 }
374
375 /********************************************************************
376  ********************************************************************/
377
378 WERROR _wkssvc_NetrValidateName2(pipes_struct *p, struct wkssvc_NetrValidateName2 *r)
379 {
380         /* FIXME: Add implementation code here */
381         p->rng_fault_state = True;
382         return WERR_NOT_SUPPORTED;
383 }
384
385 /********************************************************************
386  ********************************************************************/
387
388 WERROR _wkssvc_NetrGetJoinableOus2(pipes_struct *p, struct wkssvc_NetrGetJoinableOus2 *r)
389 {
390         /* FIXME: Add implementation code here */
391         p->rng_fault_state = True;
392         return WERR_NOT_SUPPORTED;
393 }
394
395 /********************************************************************
396  ********************************************************************/
397
398 WERROR _wkssvc_NetrAddAlternateComputerName(pipes_struct *p, struct wkssvc_NetrAddAlternateComputerName *r)
399 {
400         /* FIXME: Add implementation code here */
401         p->rng_fault_state = True;
402         return WERR_NOT_SUPPORTED;
403 }
404
405 /********************************************************************
406  ********************************************************************/
407
408 WERROR _wkssvc_NetrRemoveAlternateComputerName(pipes_struct *p, struct wkssvc_NetrRemoveAlternateComputerName *r)
409 {
410         /* FIXME: Add implementation code here */
411         p->rng_fault_state = True;
412         return WERR_NOT_SUPPORTED;
413 }
414
415 /********************************************************************
416  ********************************************************************/
417
418 WERROR _wkssvc_NetrSetPrimaryComputername(pipes_struct *p, struct wkssvc_NetrSetPrimaryComputername *r)
419 {
420         /* FIXME: Add implementation code here */
421         p->rng_fault_state = True;
422         return WERR_NOT_SUPPORTED;
423 }
424
425 /********************************************************************
426  ********************************************************************/
427
428 WERROR _wkssvc_NetrEnumerateComputerNames(pipes_struct *p, struct wkssvc_NetrEnumerateComputerNames *r)
429 {
430         /* FIXME: Add implementation code here */
431         p->rng_fault_state = True;
432         return WERR_NOT_SUPPORTED;
433 }
434