Deactive remote join code server side until some last issues are resolved.
[amitay/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 #if 0
290         struct libnet_JoinCtx *j = NULL;
291         char *pwd = NULL;
292         char *admin_domain = NULL;
293         char *admin_account = NULL;
294         WERROR werr;
295         NTSTATUS status;
296         struct nt_user_token *token = p->pipe_user.nt_user_token;
297         struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
298
299         if (!r->in.domain_name) {
300                 return WERR_INVALID_PARAM;
301         }
302
303         if (!user_has_privileges(token, &se_machine_account) &&
304             !nt_token_check_domain_rid(token, DOMAIN_GROUP_RID_ADMINS) &&
305             !nt_token_check_domain_rid(token, BUILTIN_ALIAS_RID_ADMINS)) {
306                 return WERR_ACCESS_DENIED;
307         }
308
309         werr = decode_wkssvc_join_password_buffer(p->mem_ctx,
310                                                   r->in.encrypted_password,
311                                                   &p->session_key,
312                                                   &pwd);
313         if (!W_ERROR_IS_OK(werr)) {
314                 return werr;
315         }
316
317         werr = libnet_init_JoinCtx(p->mem_ctx, &j);
318         if (!W_ERROR_IS_OK(werr)) {
319                 return werr;
320         }
321
322         split_domain_user(p->mem_ctx,
323                           r->in.admin_account,
324                           &admin_domain,
325                           &admin_account);
326
327         status = DsGetDcName(p->mem_ctx,
328                              NULL,
329                              r->in.domain_name,
330                              NULL,
331                              NULL,
332                              DS_DIRECTORY_SERVICE_REQUIRED |
333                              DS_WRITABLE_REQUIRED |
334                              DS_RETURN_DNS_NAME,
335                              &info);
336         if (!NT_STATUS_IS_OK(status)) {
337                 return ntstatus_to_werror(status);
338         }
339
340         j->in.server_name       = info->domain_controller_name;
341         j->in.domain_name       = r->in.domain_name;
342         j->in.account_ou        = r->in.account_ou;
343         j->in.join_flags        = r->in.join_flags;
344
345         j->in.admin_account = admin_account;
346         j->in.password = pwd;
347         j->in.modify_config = true;
348
349         become_root();
350         werr = libnet_Join(p->mem_ctx, j);
351         unbecome_root();
352
353         return werr;
354 #endif
355         p->rng_fault_state = True;
356         return WERR_NOT_SUPPORTED;
357 }
358
359 /********************************************************************
360  ********************************************************************/
361
362 WERROR _wkssvc_NetrUnjoinDomain2(pipes_struct *p, struct wkssvc_NetrUnjoinDomain2 *r)
363 {
364         /* FIXME: Add implementation code here */
365         p->rng_fault_state = True;
366         return WERR_NOT_SUPPORTED;
367 }
368
369 /********************************************************************
370  ********************************************************************/
371
372 WERROR _wkssvc_NetrRenameMachineInDomain2(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain2 *r)
373 {
374         /* FIXME: Add implementation code here */
375         p->rng_fault_state = True;
376         return WERR_NOT_SUPPORTED;
377 }
378
379 /********************************************************************
380  ********************************************************************/
381
382 WERROR _wkssvc_NetrValidateName2(pipes_struct *p, struct wkssvc_NetrValidateName2 *r)
383 {
384         /* FIXME: Add implementation code here */
385         p->rng_fault_state = True;
386         return WERR_NOT_SUPPORTED;
387 }
388
389 /********************************************************************
390  ********************************************************************/
391
392 WERROR _wkssvc_NetrGetJoinableOus2(pipes_struct *p, struct wkssvc_NetrGetJoinableOus2 *r)
393 {
394         /* FIXME: Add implementation code here */
395         p->rng_fault_state = True;
396         return WERR_NOT_SUPPORTED;
397 }
398
399 /********************************************************************
400  ********************************************************************/
401
402 WERROR _wkssvc_NetrAddAlternateComputerName(pipes_struct *p, struct wkssvc_NetrAddAlternateComputerName *r)
403 {
404         /* FIXME: Add implementation code here */
405         p->rng_fault_state = True;
406         return WERR_NOT_SUPPORTED;
407 }
408
409 /********************************************************************
410  ********************************************************************/
411
412 WERROR _wkssvc_NetrRemoveAlternateComputerName(pipes_struct *p, struct wkssvc_NetrRemoveAlternateComputerName *r)
413 {
414         /* FIXME: Add implementation code here */
415         p->rng_fault_state = True;
416         return WERR_NOT_SUPPORTED;
417 }
418
419 /********************************************************************
420  ********************************************************************/
421
422 WERROR _wkssvc_NetrSetPrimaryComputername(pipes_struct *p, struct wkssvc_NetrSetPrimaryComputername *r)
423 {
424         /* FIXME: Add implementation code here */
425         p->rng_fault_state = True;
426         return WERR_NOT_SUPPORTED;
427 }
428
429 /********************************************************************
430  ********************************************************************/
431
432 WERROR _wkssvc_NetrEnumerateComputerNames(pipes_struct *p, struct wkssvc_NetrEnumerateComputerNames *r)
433 {
434         /* FIXME: Add implementation code here */
435         p->rng_fault_state = True;
436         return WERR_NOT_SUPPORTED;
437 }
438