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