Fix Compiler warnings by including the proper header.
[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 *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 #endif
354         p->rng_fault_state = True;
355         return WERR_NOT_SUPPORTED;
356 }
357
358 /********************************************************************
359  ********************************************************************/
360
361 WERROR _wkssvc_NetrUnjoinDomain2(pipes_struct *p, struct wkssvc_NetrUnjoinDomain2 *r)
362 {
363         /* FIXME: Add implementation code here */
364         p->rng_fault_state = True;
365         return WERR_NOT_SUPPORTED;
366 }
367
368 /********************************************************************
369  ********************************************************************/
370
371 WERROR _wkssvc_NetrRenameMachineInDomain2(pipes_struct *p, struct wkssvc_NetrRenameMachineInDomain2 *r)
372 {
373         /* FIXME: Add implementation code here */
374         p->rng_fault_state = True;
375         return WERR_NOT_SUPPORTED;
376 }
377
378 /********************************************************************
379  ********************************************************************/
380
381 WERROR _wkssvc_NetrValidateName2(pipes_struct *p, struct wkssvc_NetrValidateName2 *r)
382 {
383         /* FIXME: Add implementation code here */
384         p->rng_fault_state = True;
385         return WERR_NOT_SUPPORTED;
386 }
387
388 /********************************************************************
389  ********************************************************************/
390
391 WERROR _wkssvc_NetrGetJoinableOus2(pipes_struct *p, struct wkssvc_NetrGetJoinableOus2 *r)
392 {
393         /* FIXME: Add implementation code here */
394         p->rng_fault_state = True;
395         return WERR_NOT_SUPPORTED;
396 }
397
398 /********************************************************************
399  ********************************************************************/
400
401 WERROR _wkssvc_NetrAddAlternateComputerName(pipes_struct *p, struct wkssvc_NetrAddAlternateComputerName *r)
402 {
403         /* FIXME: Add implementation code here */
404         p->rng_fault_state = True;
405         return WERR_NOT_SUPPORTED;
406 }
407
408 /********************************************************************
409  ********************************************************************/
410
411 WERROR _wkssvc_NetrRemoveAlternateComputerName(pipes_struct *p, struct wkssvc_NetrRemoveAlternateComputerName *r)
412 {
413         /* FIXME: Add implementation code here */
414         p->rng_fault_state = True;
415         return WERR_NOT_SUPPORTED;
416 }
417
418 /********************************************************************
419  ********************************************************************/
420
421 WERROR _wkssvc_NetrSetPrimaryComputername(pipes_struct *p, struct wkssvc_NetrSetPrimaryComputername *r)
422 {
423         /* FIXME: Add implementation code here */
424         p->rng_fault_state = True;
425         return WERR_NOT_SUPPORTED;
426 }
427
428 /********************************************************************
429  ********************************************************************/
430
431 WERROR _wkssvc_NetrEnumerateComputerNames(pipes_struct *p, struct wkssvc_NetrEnumerateComputerNames *r)
432 {
433         /* FIXME: Add implementation code here */
434         p->rng_fault_state = True;
435         return WERR_NOT_SUPPORTED;
436 }
437