2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Gerald (Jerry) Carter 2006.
7 * Copyright (C) Guenther Deschner 2007-2008.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 /* This is the implementation of the wks interface. */
26 #include "libnet/libnet.h"
29 #define DBGC_CLASS DBGC_RPC_SRV
31 /*******************************************************************
32 Fill in the values for the struct wkssvc_NetWkstaInfo100.
33 ********************************************************************/
35 static void create_wks_info_100(struct wkssvc_NetWkstaInfo100
*info100
)
37 info100
->platform_id
= PLATFORM_ID_NT
; /* unknown */
38 info100
->version_major
= lp_major_announce_version();
39 info100
->version_minor
= lp_minor_announce_version();
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());
49 /********************************************************************
50 only supports info level 100 at the moment.
51 ********************************************************************/
53 WERROR
_wkssvc_NetWkstaGetInfo(pipes_struct
*p
, struct wkssvc_NetWkstaGetInfo
*r
)
55 struct wkssvc_NetWkstaInfo100
*wks100
= NULL
;
57 /* We only support info level 100 currently */
59 if ( r
->in
.level
!= 100 ) {
60 return WERR_UNKNOWN_LEVEL
;
63 if ( (wks100
= TALLOC_ZERO_P(p
->mem_ctx
, struct wkssvc_NetWkstaInfo100
)) == NULL
) {
67 create_wks_info_100( wks100
);
69 r
->out
.info
->info100
= wks100
;
74 /********************************************************************
75 ********************************************************************/
77 WERROR
_wkssvc_NetWkstaSetInfo(pipes_struct
*p
, struct wkssvc_NetWkstaSetInfo
*r
)
79 /* FIXME: Add implementation code here */
80 p
->rng_fault_state
= True
;
81 return WERR_NOT_SUPPORTED
;
84 /********************************************************************
85 ********************************************************************/
87 WERROR
_wkssvc_NetWkstaEnumUsers(pipes_struct
*p
, struct wkssvc_NetWkstaEnumUsers
*r
)
89 /* FIXME: Add implementation code here */
90 p
->rng_fault_state
= True
;
91 return WERR_NOT_SUPPORTED
;
94 /********************************************************************
95 ********************************************************************/
97 WERROR
_wkssvc_NetrWkstaUserGetInfo(pipes_struct
*p
, struct wkssvc_NetrWkstaUserGetInfo
*r
)
99 /* FIXME: Add implementation code here */
100 p
->rng_fault_state
= True
;
101 return WERR_NOT_SUPPORTED
;
104 /********************************************************************
105 ********************************************************************/
107 WERROR
_wkssvc_NetrWkstaUserSetInfo(pipes_struct
*p
, struct wkssvc_NetrWkstaUserSetInfo
*r
)
109 /* FIXME: Add implementation code here */
110 p
->rng_fault_state
= True
;
111 return WERR_NOT_SUPPORTED
;
114 /********************************************************************
115 ********************************************************************/
117 WERROR
_wkssvc_NetWkstaTransportEnum(pipes_struct
*p
, struct wkssvc_NetWkstaTransportEnum
*r
)
119 /* FIXME: Add implementation code here */
120 p
->rng_fault_state
= True
;
121 return WERR_NOT_SUPPORTED
;
124 /********************************************************************
125 ********************************************************************/
127 WERROR
_wkssvc_NetrWkstaTransportAdd(pipes_struct
*p
, struct wkssvc_NetrWkstaTransportAdd
*r
)
129 /* FIXME: Add implementation code here */
130 p
->rng_fault_state
= True
;
131 return WERR_NOT_SUPPORTED
;
134 /********************************************************************
135 ********************************************************************/
137 WERROR
_wkssvc_NetrWkstaTransportDel(pipes_struct
*p
, struct wkssvc_NetrWkstaTransportDel
*r
)
139 /* FIXME: Add implementation code here */
140 p
->rng_fault_state
= True
;
141 return WERR_NOT_SUPPORTED
;
144 /********************************************************************
145 ********************************************************************/
147 WERROR
_wkssvc_NetrUseAdd(pipes_struct
*p
, struct wkssvc_NetrUseAdd
*r
)
149 /* FIXME: Add implementation code here */
150 p
->rng_fault_state
= True
;
151 return WERR_NOT_SUPPORTED
;
154 /********************************************************************
155 ********************************************************************/
157 WERROR
_wkssvc_NetrUseGetInfo(pipes_struct
*p
, struct wkssvc_NetrUseGetInfo
*r
)
159 /* FIXME: Add implementation code here */
160 p
->rng_fault_state
= True
;
161 return WERR_NOT_SUPPORTED
;
164 /********************************************************************
165 ********************************************************************/
167 WERROR
_wkssvc_NetrUseDel(pipes_struct
*p
, struct wkssvc_NetrUseDel
*r
)
169 /* FIXME: Add implementation code here */
170 p
->rng_fault_state
= True
;
171 return WERR_NOT_SUPPORTED
;
174 /********************************************************************
175 ********************************************************************/
177 WERROR
_wkssvc_NetrUseEnum(pipes_struct
*p
, struct wkssvc_NetrUseEnum
*r
)
179 /* FIXME: Add implementation code here */
180 p
->rng_fault_state
= True
;
181 return WERR_NOT_SUPPORTED
;
184 /********************************************************************
185 ********************************************************************/
187 WERROR
_wkssvc_NetrMessageBufferSend(pipes_struct
*p
, struct wkssvc_NetrMessageBufferSend
*r
)
189 /* FIXME: Add implementation code here */
190 p
->rng_fault_state
= True
;
191 return WERR_NOT_SUPPORTED
;
194 /********************************************************************
195 ********************************************************************/
197 WERROR
_wkssvc_NetrWorkstationStatisticsGet(pipes_struct
*p
, struct wkssvc_NetrWorkstationStatisticsGet
*r
)
199 /* FIXME: Add implementation code here */
200 p
->rng_fault_state
= True
;
201 return WERR_NOT_SUPPORTED
;
204 /********************************************************************
205 ********************************************************************/
207 WERROR
_wkssvc_NetrLogonDomainNameAdd(pipes_struct
*p
, struct wkssvc_NetrLogonDomainNameAdd
*r
)
209 /* FIXME: Add implementation code here */
210 p
->rng_fault_state
= True
;
211 return WERR_NOT_SUPPORTED
;
214 /********************************************************************
215 ********************************************************************/
217 WERROR
_wkssvc_NetrLogonDomainNameDel(pipes_struct
*p
, struct wkssvc_NetrLogonDomainNameDel
*r
)
219 /* FIXME: Add implementation code here */
220 p
->rng_fault_state
= True
;
221 return WERR_NOT_SUPPORTED
;
224 /********************************************************************
225 ********************************************************************/
227 WERROR
_wkssvc_NetrJoinDomain(pipes_struct
*p
, struct wkssvc_NetrJoinDomain
*r
)
229 /* FIXME: Add implementation code here */
230 p
->rng_fault_state
= True
;
231 return WERR_NOT_SUPPORTED
;
234 /********************************************************************
235 ********************************************************************/
237 WERROR
_wkssvc_NetrUnjoinDomain(pipes_struct
*p
, struct wkssvc_NetrUnjoinDomain
*r
)
239 /* FIXME: Add implementation code here */
240 p
->rng_fault_state
= True
;
241 return WERR_NOT_SUPPORTED
;
244 /********************************************************************
245 ********************************************************************/
247 WERROR
_wkssvc_NetrRenameMachineInDomain(pipes_struct
*p
, struct wkssvc_NetrRenameMachineInDomain
*r
)
249 /* FIXME: Add implementation code here */
250 p
->rng_fault_state
= True
;
251 return WERR_NOT_SUPPORTED
;
254 /********************************************************************
255 ********************************************************************/
257 WERROR
_wkssvc_NetrValidateName(pipes_struct
*p
, struct wkssvc_NetrValidateName
*r
)
259 /* FIXME: Add implementation code here */
260 p
->rng_fault_state
= True
;
261 return WERR_NOT_SUPPORTED
;
264 /********************************************************************
265 ********************************************************************/
267 WERROR
_wkssvc_NetrGetJoinInformation(pipes_struct
*p
, struct wkssvc_NetrGetJoinInformation
*r
)
269 /* FIXME: Add implementation code here */
270 p
->rng_fault_state
= True
;
271 return WERR_NOT_SUPPORTED
;
274 /********************************************************************
275 ********************************************************************/
277 WERROR
_wkssvc_NetrGetJoinableOus(pipes_struct
*p
, struct wkssvc_NetrGetJoinableOus
*r
)
279 /* FIXME: Add implementation code here */
280 p
->rng_fault_state
= True
;
281 return WERR_NOT_SUPPORTED
;
284 /********************************************************************
285 _wkssvc_NetrJoinDomain2
286 ********************************************************************/
288 WERROR
_wkssvc_NetrJoinDomain2(pipes_struct
*p
,
289 struct wkssvc_NetrJoinDomain2
*r
)
291 struct libnet_JoinCtx
*j
= NULL
;
292 char *cleartext_pwd
= NULL
;
293 char *admin_domain
= NULL
;
294 char *admin_account
= NULL
;
296 struct nt_user_token
*token
= p
->server_info
->ptok
;
298 if (!r
->in
.domain_name
) {
299 return WERR_INVALID_PARAM
;
302 if (!r
->in
.admin_account
|| !r
->in
.encrypted_password
) {
303 return WERR_INVALID_PARAM
;
306 if (!user_has_privileges(token
, &se_machine_account
) &&
307 !nt_token_check_domain_rid(token
, DOMAIN_GROUP_RID_ADMINS
) &&
308 !nt_token_check_domain_rid(token
, BUILTIN_ALIAS_RID_ADMINS
)) {
309 DEBUG(5,("_wkssvc_NetrJoinDomain2: account doesn't have "
310 "sufficient privileges\n"));
311 return WERR_ACCESS_DENIED
;
314 if ((r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED
) ||
315 (r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
)) {
316 return WERR_NOT_SUPPORTED
;
319 werr
= decode_wkssvc_join_password_buffer(
320 p
->mem_ctx
, r
->in
.encrypted_password
,
321 &p
->server_info
->user_session_key
, &cleartext_pwd
);
322 if (!W_ERROR_IS_OK(werr
)) {
326 split_domain_user(p
->mem_ctx
,
331 werr
= libnet_init_JoinCtx(p
->mem_ctx
, &j
);
332 if (!W_ERROR_IS_OK(werr
)) {
336 j
->in
.domain_name
= r
->in
.domain_name
;
337 j
->in
.account_ou
= r
->in
.account_ou
;
338 j
->in
.join_flags
= r
->in
.join_flags
;
339 j
->in
.admin_account
= admin_account
;
340 j
->in
.admin_password
= cleartext_pwd
;
342 j
->in
.modify_config
= lp_config_backend_is_registry();
343 j
->in
.msg_ctx
= smbd_messaging_context();
346 werr
= libnet_Join(p
->mem_ctx
, j
);
349 if (!W_ERROR_IS_OK(werr
)) {
350 DEBUG(5,("_wkssvc_NetrJoinDomain2: libnet_Join failed with: %s\n",
351 j
->out
.error_string
? j
->out
.error_string
:
359 /********************************************************************
360 _wkssvc_NetrUnjoinDomain2
361 ********************************************************************/
363 WERROR
_wkssvc_NetrUnjoinDomain2(pipes_struct
*p
,
364 struct wkssvc_NetrUnjoinDomain2
*r
)
366 struct libnet_UnjoinCtx
*u
= NULL
;
367 char *cleartext_pwd
= NULL
;
368 char *admin_domain
= NULL
;
369 char *admin_account
= NULL
;
371 struct nt_user_token
*token
= p
->server_info
->ptok
;
373 if (!r
->in
.account
|| !r
->in
.encrypted_password
) {
374 return WERR_INVALID_PARAM
;
377 if (!user_has_privileges(token
, &se_machine_account
) &&
378 !nt_token_check_domain_rid(token
, DOMAIN_GROUP_RID_ADMINS
) &&
379 !nt_token_check_domain_rid(token
, BUILTIN_ALIAS_RID_ADMINS
)) {
380 DEBUG(5,("_wkssvc_NetrUnjoinDomain2: account doesn't have "
381 "sufficient privileges\n"));
382 return WERR_ACCESS_DENIED
;
385 werr
= decode_wkssvc_join_password_buffer(
386 p
->mem_ctx
, r
->in
.encrypted_password
,
387 &p
->server_info
->user_session_key
, &cleartext_pwd
);
388 if (!W_ERROR_IS_OK(werr
)) {
392 split_domain_user(p
->mem_ctx
,
397 werr
= libnet_init_UnjoinCtx(p
->mem_ctx
, &u
);
398 if (!W_ERROR_IS_OK(werr
)) {
402 u
->in
.domain_name
= lp_realm();
403 u
->in
.unjoin_flags
= r
->in
.unjoin_flags
|
404 WKSSVC_JOIN_FLAGS_JOIN_TYPE
;
405 u
->in
.admin_account
= admin_account
;
406 u
->in
.admin_password
= cleartext_pwd
;
408 u
->in
.modify_config
= lp_config_backend_is_registry();
409 u
->in
.msg_ctx
= smbd_messaging_context();
412 werr
= libnet_Unjoin(p
->mem_ctx
, u
);
415 if (!W_ERROR_IS_OK(werr
)) {
416 DEBUG(5,("_wkssvc_NetrUnjoinDomain2: libnet_Unjoin failed with: %s\n",
417 u
->out
.error_string
? u
->out
.error_string
:
425 /********************************************************************
426 ********************************************************************/
428 WERROR
_wkssvc_NetrRenameMachineInDomain2(pipes_struct
*p
, struct wkssvc_NetrRenameMachineInDomain2
*r
)
430 /* FIXME: Add implementation code here */
431 p
->rng_fault_state
= True
;
432 return WERR_NOT_SUPPORTED
;
435 /********************************************************************
436 ********************************************************************/
438 WERROR
_wkssvc_NetrValidateName2(pipes_struct
*p
, struct wkssvc_NetrValidateName2
*r
)
440 /* FIXME: Add implementation code here */
441 p
->rng_fault_state
= True
;
442 return WERR_NOT_SUPPORTED
;
445 /********************************************************************
446 ********************************************************************/
448 WERROR
_wkssvc_NetrGetJoinableOus2(pipes_struct
*p
, struct wkssvc_NetrGetJoinableOus2
*r
)
450 /* FIXME: Add implementation code here */
451 p
->rng_fault_state
= True
;
452 return WERR_NOT_SUPPORTED
;
455 /********************************************************************
456 ********************************************************************/
458 WERROR
_wkssvc_NetrAddAlternateComputerName(pipes_struct
*p
, struct wkssvc_NetrAddAlternateComputerName
*r
)
460 /* FIXME: Add implementation code here */
461 p
->rng_fault_state
= True
;
462 return WERR_NOT_SUPPORTED
;
465 /********************************************************************
466 ********************************************************************/
468 WERROR
_wkssvc_NetrRemoveAlternateComputerName(pipes_struct
*p
, struct wkssvc_NetrRemoveAlternateComputerName
*r
)
470 /* FIXME: Add implementation code here */
471 p
->rng_fault_state
= True
;
472 return WERR_NOT_SUPPORTED
;
475 /********************************************************************
476 ********************************************************************/
478 WERROR
_wkssvc_NetrSetPrimaryComputername(pipes_struct
*p
, struct wkssvc_NetrSetPrimaryComputername
*r
)
480 /* FIXME: Add implementation code here */
481 p
->rng_fault_state
= True
;
482 return WERR_NOT_SUPPORTED
;
485 /********************************************************************
486 ********************************************************************/
488 WERROR
_wkssvc_NetrEnumerateComputerNames(pipes_struct
*p
, struct wkssvc_NetrEnumerateComputerNames
*r
)
490 /* FIXME: Add implementation code here */
491 p
->rng_fault_state
= True
;
492 return WERR_NOT_SUPPORTED
;