2 Unix SMB/CIFS implementation.
4 endpoint server for the netlogon pipe
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004
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 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rpc_server/common/common.h"
26 struct server_pipe_state {
28 struct netr_Credential client_challenge;
29 struct netr_Credential server_challenge;
32 char *computer_name; /* for logging only */
34 uint16_t sec_chan_type;
35 struct creds_CredentialState *creds;
40 a client has connected to the netlogon server using schannel, so we need
41 to re-establish the credentials state
43 static NTSTATUS netlogon_schannel_setup(struct dcesrv_call_state *dce_call)
45 struct server_pipe_state *state;
49 mem_ctx = talloc_init("netlogon_bind");
51 return NT_STATUS_NO_MEMORY;
53 state = talloc_p(mem_ctx, struct server_pipe_state);
55 talloc_destroy(mem_ctx);
56 return NT_STATUS_NO_MEMORY;
59 state->mem_ctx = mem_ctx;
60 state->authenticated = True;
62 if (dce_call->conn->auth_state.session_info == NULL) {
63 talloc_destroy(mem_ctx);
64 smb_panic("No session info provided by schannel level setup!");
65 return NT_STATUS_NO_USER_SESSION_KEY;
68 status = dcerpc_schannel_creds(dce_call->conn->auth_state.gensec_security,
72 if (!NT_STATUS_IS_OK(status)) {
73 DEBUG(3, ("getting schannel credentials failed with %s\n", nt_errstr(status)));
74 talloc_destroy(mem_ctx);
78 dce_call->conn->private = state;
84 a hook for bind on the netlogon pipe
86 static NTSTATUS netlogon_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *di)
88 dce_call->conn->private = NULL;
90 /* if this is a schannel bind then we need to reconstruct the pipe state */
91 if (dce_call->conn->auth_state.auth_info &&
92 dce_call->conn->auth_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
95 DEBUG(5, ("schannel bind on netlogon\n"));
97 status = netlogon_schannel_setup(dce_call);
98 if (!NT_STATUS_IS_OK(status)) {
99 DEBUG(3, ("schannel bind on netlogon failed with %s\n", nt_errstr(status)));
107 /* this function is called when the client disconnects the endpoint */
108 static void netlogon_unbind(struct dcesrv_connection *conn, const struct dcesrv_interface *di)
110 struct server_pipe_state *pipe_state = conn->private;
113 talloc_destroy(pipe_state->mem_ctx);
116 conn->private = NULL;
119 #define DCESRV_INTERFACE_NETLOGON_BIND netlogon_bind
120 #define DCESRV_INTERFACE_NETLOGON_UNBIND netlogon_unbind
122 static NTSTATUS netr_ServerReqChallenge(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
123 struct netr_ServerReqChallenge *r)
125 struct server_pipe_state *pipe_state = dce_call->conn->private;
126 TALLOC_CTX *pipe_mem_ctx;
128 ZERO_STRUCTP(r->out.credentials);
130 /* destroyed on pipe shutdown */
133 talloc_destroy(pipe_state->mem_ctx);
134 dce_call->conn->private = NULL;
137 pipe_mem_ctx = talloc_init("internal netlogon pipe state for %s",
138 r->in.computer_name);
141 return NT_STATUS_NO_MEMORY;
144 pipe_state = talloc_p(pipe_mem_ctx, struct server_pipe_state);
146 talloc_destroy(pipe_mem_ctx);
147 return NT_STATUS_NO_MEMORY;
150 pipe_state->mem_ctx = pipe_mem_ctx;
151 pipe_state->authenticated = False;
152 pipe_state->creds = NULL;
153 pipe_state->account_name = NULL;
154 pipe_state->computer_name = NULL;
156 pipe_state->client_challenge = *r->in.credentials;
158 generate_random_buffer(pipe_state->server_challenge.data,
159 sizeof(pipe_state->server_challenge.data));
161 *r->out.credentials = pipe_state->server_challenge;
163 dce_call->conn->private = pipe_state;
168 static NTSTATUS netr_ServerAuthenticate3(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
169 struct netr_ServerAuthenticate3 *r)
171 struct server_pipe_state *pipe_state = dce_call->conn->private;
173 struct samr_Password *mach_pwd;
176 struct ldb_message **msgs;
178 const char *attrs[] = {"unicodePwd", "lmPwdHash", "ntPwdHash", "userAccountControl",
181 ZERO_STRUCTP(r->out.credentials);
183 *r->out.negotiate_flags = *r->in.negotiate_flags;
186 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
187 return NT_STATUS_ACCESS_DENIED;
190 sam_ctx = samdb_connect(mem_ctx);
191 if (sam_ctx == NULL) {
192 return NT_STATUS_INVALID_SYSTEM_SERVICE;
194 /* pull the user attributes */
195 num_records = samdb_search(sam_ctx, mem_ctx, NULL, &msgs, attrs,
196 "(&(sAMAccountName=%s)(objectclass=user))",
199 if (num_records == 0) {
200 DEBUG(3,("Couldn't find user [%s] in samdb.\n",
201 r->in.account_name));
202 return NT_STATUS_NO_SUCH_USER;
205 if (num_records > 1) {
206 DEBUG(0,("Found %d records matching user [%s]\n", num_records, r->in.account_name));
207 return NT_STATUS_INTERNAL_DB_CORRUPTION;
210 acct_flags = samdb_result_acct_flags(msgs[0],
211 "userAccountControl");
213 if (acct_flags & ACB_DISABLED) {
214 DEBUG(1, ("Account [%s] is disabled\n", r->in.account_name));
215 return NT_STATUS_ACCESS_DENIED;
218 if (r->in.secure_channel_type == SEC_CHAN_WKSTA) {
219 if (!(acct_flags & ACB_WSTRUST)) {
220 DEBUG(1, ("Client asked for a workstation secure channel, but is not a workstation (member server) acb flags: 0x%x\n", acct_flags));
221 return NT_STATUS_ACCESS_DENIED;
223 } else if (r->in.secure_channel_type == SEC_CHAN_DOMAIN) {
224 if (!(acct_flags & ACB_DOMTRUST)) {
225 DEBUG(1, ("Client asked for a trusted domain secure channel, but is not a trusted domain: acb flags: 0x%x\n", acct_flags));
226 return NT_STATUS_ACCESS_DENIED;
228 } else if (r->in.secure_channel_type == SEC_CHAN_BDC) {
229 if (!(acct_flags & ACB_SVRTRUST)) {
230 DEBUG(1, ("Client asked for a server secure channel, but is not a server (domain controller): acb flags: 0x%x\n", acct_flags));
231 return NT_STATUS_ACCESS_DENIED;
234 DEBUG(1, ("Client asked for an invalid secure channel type: %d\n",
235 r->in.secure_channel_type));
236 return NT_STATUS_ACCESS_DENIED;
239 pipe_state->acct_flags = acct_flags;
240 pipe_state->sec_chan_type = r->in.secure_channel_type;
242 *r->out.rid = samdb_result_rid_from_sid(mem_ctx, msgs[0], "objectSid", 0);
244 nt_status = samdb_result_passwords(mem_ctx, msgs[0], NULL, &mach_pwd);
245 if (!NT_STATUS_IS_OK(nt_status) || mach_pwd == NULL) {
246 return NT_STATUS_ACCESS_DENIED;
249 if (!pipe_state->creds) {
250 pipe_state->creds = talloc_p(pipe_state->mem_ctx, struct creds_CredentialState);
251 if (!pipe_state->creds) {
252 return NT_STATUS_NO_MEMORY;
256 creds_server_init(pipe_state->creds, &pipe_state->client_challenge,
257 &pipe_state->server_challenge, mach_pwd,
259 *r->in.negotiate_flags);
261 if (!creds_server_check(pipe_state->creds, r->in.credentials)) {
262 return NT_STATUS_ACCESS_DENIED;
265 pipe_state->authenticated = True;
267 if (pipe_state->account_name) {
268 /* We don't want a memory leak on this long-lived talloc context */
269 talloc_free(pipe_state->account_name);
272 pipe_state->account_name = talloc_strdup(pipe_state->mem_ctx, r->in.account_name);
274 if (pipe_state->computer_name) {
275 /* We don't want a memory leak on this long-lived talloc context */
276 talloc_free(pipe_state->account_name);
279 pipe_state->computer_name = talloc_strdup(pipe_state->mem_ctx, r->in.computer_name);
281 /* remember this session key state */
282 nt_status = schannel_store_session_key(mem_ctx, pipe_state->computer_name, pipe_state->creds);
287 static NTSTATUS netr_ServerAuthenticate(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
288 struct netr_ServerAuthenticate *r)
290 struct netr_ServerAuthenticate3 r3;
293 * negotiate_flags is used as an [in] parameter
294 * so it need to be initialised.
296 * (I think ... = 0; seems wrong here --metze)
298 uint32 negotiate_flags = 0;
300 r3.in.server_name = r->in.server_name;
301 r3.in.account_name = r->in.account_name;
302 r3.in.secure_channel_type = r->in.secure_channel_type;
303 r3.in.computer_name = r->in.computer_name;
304 r3.in.credentials = r->in.credentials;
305 r3.out.credentials = r->out.credentials;
306 r3.in.negotiate_flags = &negotiate_flags;
307 r3.out.negotiate_flags = &negotiate_flags;
310 return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
313 static NTSTATUS netr_ServerAuthenticate2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
314 struct netr_ServerAuthenticate2 *r)
316 struct netr_ServerAuthenticate3 r3;
319 r3.in.server_name = r->in.server_name;
320 r3.in.account_name = r->in.account_name;
321 r3.in.secure_channel_type = r->in.secure_channel_type;
322 r3.in.computer_name = r->in.computer_name;
323 r3.in.credentials = r->in.credentials;
324 r3.out.credentials = r->out.credentials;
325 r3.in.negotiate_flags = r->in.negotiate_flags;
326 r3.out.negotiate_flags = r->out.negotiate_flags;
329 return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
333 static BOOL netr_creds_server_step_check(struct server_pipe_state *pipe_state,
334 struct netr_Authenticator *received_authenticator,
335 struct netr_Authenticator *return_authenticator)
337 if (!pipe_state->authenticated) {
340 return creds_server_step_check(pipe_state->creds,
341 received_authenticator,
342 return_authenticator);
346 static NTSTATUS netr_ServerPasswordSet(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
347 struct netr_ServerPasswordSet *r)
349 struct server_pipe_state *pipe_state = dce_call->conn->private;
353 int num_records_domain;
355 struct ldb_message **msgs;
356 struct ldb_message **msgs_domain;
358 struct ldb_message mod, *msg_set_pw = &mod;
359 const char *domain_dn;
360 const char *domain_sid;
362 const char *attrs[] = {"objectSid", NULL };
364 const char **domain_attrs = attrs;
368 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
369 return NT_STATUS_ACCESS_DENIED;
372 if (!netr_creds_server_step_check(pipe_state, &r->in.credential, &r->out.return_authenticator)) {
373 return NT_STATUS_ACCESS_DENIED;
376 sam_ctx = samdb_connect(mem_ctx);
377 if (sam_ctx == NULL) {
378 return NT_STATUS_INVALID_SYSTEM_SERVICE;
380 /* pull the user attributes */
381 num_records = samdb_search(sam_ctx, mem_ctx, NULL, &msgs, attrs,
382 "(&(sAMAccountName=%s)(objectclass=user))",
383 pipe_state->account_name);
385 if (num_records == 0) {
386 DEBUG(3,("Couldn't find user [%s] in samdb.\n",
387 pipe_state->account_name));
388 return NT_STATUS_NO_SUCH_USER;
391 if (num_records > 1) {
392 DEBUG(0,("Found %d records matching user [%s]\n", num_records,
393 pipe_state->account_name));
394 return NT_STATUS_INTERNAL_DB_CORRUPTION;
397 domain_sid = samdb_result_sid_prefix(mem_ctx, msgs[0], "objectSid");
399 DEBUG(0,("no objectSid in user record\n"));
400 return NT_STATUS_INTERNAL_DB_CORRUPTION;
403 /* find the domain's DN */
404 num_records_domain = samdb_search(sam_ctx, mem_ctx, NULL,
405 &msgs_domain, domain_attrs,
406 "(&(objectSid=%s)(objectclass=domain))",
409 if (num_records_domain == 0) {
410 DEBUG(3,("check_sam_security: Couldn't find domain [%s] in passdb file.\n",
412 return NT_STATUS_NO_SUCH_USER;
415 if (num_records_domain > 1) {
416 DEBUG(0,("Found %d records matching domain [%s]\n",
417 num_records_domain, domain_sid));
418 return NT_STATUS_INTERNAL_DB_CORRUPTION;
421 domain_dn = msgs_domain[0]->dn;
423 mod.dn = talloc_strdup(mem_ctx, msgs[0]->dn);
425 return NT_STATUS_NO_MEMORY;
428 creds_des_decrypt(pipe_state->creds, &r->in.new_password);
430 /* set the password - samdb needs to know both the domain and user DNs,
431 so the domain password policy can be used */
432 nt_status = samdb_set_password(sam_ctx, mem_ctx,
433 msgs[0]->dn, domain_dn,
435 NULL, /* Don't have plaintext */
436 NULL, &r->in.new_password,
437 False /* This is not considered a password change */,
440 if (!NT_STATUS_IS_OK(nt_status)) {
444 ret = samdb_replace(sam_ctx, mem_ctx, msg_set_pw);
446 /* we really need samdb.c to return NTSTATUS */
447 return NT_STATUS_UNSUCCESSFUL;
457 static WERROR netr_LogonUasLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
458 struct netr_LogonUasLogon *r)
460 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
467 static WERROR netr_LogonUasLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
468 struct netr_LogonUasLogoff *r)
470 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
475 netr_LogonSamLogonWithFlags
478 static NTSTATUS netr_LogonSamLogonWithFlags(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
479 struct netr_LogonSamLogonWithFlags *r)
481 struct server_pipe_state *pipe_state = dce_call->conn->private;
483 struct auth_context *auth_context;
484 struct auth_usersupplied_info *user_info;
485 struct auth_serversupplied_info *server_info;
488 static const char zeros[16];
489 struct netr_SamBaseInfo *sam;
490 struct netr_SamInfo2 *sam2;
491 struct netr_SamInfo3 *sam3;
492 struct netr_SamInfo6 *sam6;
495 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
496 return NT_STATUS_ACCESS_DENIED;
499 r->out.return_authenticator = talloc_p(mem_ctx, struct netr_Authenticator);
500 if (!r->out.return_authenticator) {
501 return NT_STATUS_NO_MEMORY;
504 if (!netr_creds_server_step_check(pipe_state, r->in.credential, r->out.return_authenticator)) {
505 return NT_STATUS_ACCESS_DENIED;
508 switch (r->in.logon_level) {
512 creds_arcfour_crypt(pipe_state->creds,
513 r->in.logon.password->lmpassword.hash,
514 sizeof(r->in.logon.password->lmpassword.hash));
515 creds_arcfour_crypt(pipe_state->creds,
516 r->in.logon.password->ntpassword.hash,
517 sizeof(r->in.logon.password->ntpassword.hash));
519 nt_status = make_auth_context_subsystem(&auth_context);
520 if (!NT_STATUS_IS_OK(nt_status)) {
524 chal = auth_context->get_ntlm_challenge(auth_context);
525 nt_status = make_user_info_netlogon_interactive(&user_info,
526 r->in.logon.password->identity_info.account_name.string,
527 r->in.logon.password->identity_info.domain_name.string,
528 r->in.logon.password->identity_info.workstation.string,
530 &r->in.logon.password->lmpassword,
531 &r->in.logon.password->ntpassword);
536 nt_status = make_auth_context_fixed(&auth_context, r->in.logon.network->challenge);
537 if (!NT_STATUS_IS_OK(nt_status)) {
541 nt_status = make_user_info_netlogon_network(&user_info,
542 r->in.logon.network->identity_info.account_name.string,
543 r->in.logon.network->identity_info.domain_name.string,
544 r->in.logon.network->identity_info.workstation.string,
545 r->in.logon.network->lm.data, r->in.logon.network->lm.length,
546 r->in.logon.network->nt.data, r->in.logon.network->nt.length);
549 free_auth_context(&auth_context);
550 return NT_STATUS_INVALID_PARAMETER;
553 if (!NT_STATUS_IS_OK(nt_status)) {
557 nt_status = auth_context->check_ntlm_password(auth_context,
561 if (!NT_STATUS_IS_OK(nt_status)) {
562 free_auth_context(&auth_context);
565 free_auth_context(&auth_context);
567 sam = talloc_p(mem_ctx, struct netr_SamBaseInfo);
571 sam->last_logon = server_info->last_logon;
572 sam->last_logoff = server_info->last_logoff;
573 sam->acct_expiry = server_info->acct_expiry;
574 sam->last_password_change = server_info->last_password_change;
575 sam->allow_password_change = server_info->allow_password_change;
576 sam->force_password_change = server_info->force_password_change;
578 sam->account_name.string = talloc_strdup(mem_ctx, server_info->account_name);
579 sam->full_name.string = talloc_strdup(mem_ctx, server_info->full_name);
580 sam->logon_script.string = talloc_strdup(mem_ctx, server_info->logon_script);
581 sam->profile_path.string = talloc_strdup(mem_ctx, server_info->profile_path);
582 sam->home_directory.string = talloc_strdup(mem_ctx, server_info->home_directory);
583 sam->home_drive.string = talloc_strdup(mem_ctx, server_info->home_drive);
585 sam->logon_count = server_info->logon_count;
586 sam->bad_password_count = sam->bad_password_count;
587 sam->rid = server_info->user_sid->sub_auths[server_info->user_sid->num_auths-1];
588 sam->primary_gid = server_info->primary_group_sid->sub_auths[server_info->primary_group_sid->num_auths-1];
589 sam->group_count = 0;
590 sam->groupids = NULL;
591 sam->user_flags = 0; /* TODO: w2k3 uses 0x120 - what is this? */
592 sam->acct_flags = server_info->acct_flags;
593 sam->logon_server.string = lp_netbios_name();
595 sam->domain.string = talloc_strdup(mem_ctx, server_info->domain);
597 sam->domain_sid = dom_sid_dup(mem_ctx, server_info->user_sid);
598 sam->domain_sid->num_auths--;
600 if (server_info->user_session_key.length == sizeof(sam->key.key)) {
601 memcpy(sam->key.key, server_info->user_session_key.data, sizeof(sam->key.key));
603 ZERO_STRUCT(sam->key.key);
606 /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
607 if (memcmp(sam->key.key, zeros,
608 sizeof(sam->key.key)) != 0) {
609 creds_arcfour_crypt(pipe_state->creds,
611 sizeof(sam->key.key));
614 if (server_info->lm_session_key.length == sizeof(sam->LMSessKey.key)) {
615 memcpy(sam->LMSessKey.key, server_info->lm_session_key.data,
616 sizeof(sam->LMSessKey.key));
618 ZERO_STRUCT(sam->LMSessKey.key);
621 /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
622 if (memcmp(sam->LMSessKey.key, zeros,
623 sizeof(sam->LMSessKey.key)) != 0) {
624 creds_arcfour_crypt(pipe_state->creds,
626 sizeof(sam->LMSessKey.key));
629 switch (r->in.validation_level) {
631 sam2 = talloc_p(mem_ctx, struct netr_SamInfo2);
634 r->out.validation.sam2 = sam2;
638 sam3 = talloc_p(mem_ctx, struct netr_SamInfo3);
641 r->out.validation.sam3 = sam3;
645 sam6 = talloc_p(mem_ctx, struct netr_SamInfo6);
648 sam6->forest.string = lp_realm();
649 sam6->principle.string = talloc_asprintf(mem_ctx, "%s@%s",
650 sam->account_name.string, sam6->forest.string);
651 r->out.validation.sam6 = sam6;
658 r->out.authoritative = 1;
666 static NTSTATUS netr_LogonSamLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
667 struct netr_LogonSamLogon *r)
669 struct netr_LogonSamLogonWithFlags r2;
674 r2.in.server_name = r->in.server_name;
675 r2.in.workstation = r->in.workstation;
676 r2.in.credential = r->in.credential;
677 r2.in.return_authenticator = r->in.return_authenticator;
678 r2.in.logon_level = r->in.logon_level;
679 r2.in.logon = r->in.logon;
680 r2.in.validation_level = r->in.validation_level;
683 status = netr_LogonSamLogonWithFlags(dce_call, mem_ctx, &r2);
685 r->out.return_authenticator = r2.out.return_authenticator;
686 r->out.validation = r2.out.validation;
687 r->out.authoritative = r2.out.authoritative;
696 static NTSTATUS netr_LogonSamLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
697 struct netr_LogonSamLogoff *r)
699 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
707 static NTSTATUS netr_DatabaseDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
708 struct netr_DatabaseDeltas *r)
710 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
717 static NTSTATUS netr_DatabaseSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
718 struct netr_DatabaseSync *r)
720 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
727 static NTSTATUS netr_AccountDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
728 struct netr_AccountDeltas *r)
730 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
737 static NTSTATUS netr_AccountSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
738 struct netr_AccountSync *r)
740 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
747 static NTSTATUS netr_GetDcName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
748 struct netr_GetDcName *r)
750 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
757 static WERROR netr_LogonControl(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
758 struct netr_LogonControl *r)
760 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
767 static WERROR netr_GetAnyDCName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
768 struct netr_GetAnyDCName *r)
770 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
777 static WERROR netr_LogonControl2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
778 struct netr_LogonControl2 *r)
780 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
787 static NTSTATUS netr_DatabaseSync2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
788 struct netr_DatabaseSync2 *r)
790 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
797 static NTSTATUS netr_DatabaseRedo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
798 struct netr_DatabaseRedo *r)
800 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
807 static WERROR netr_LogonControl2Ex(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
808 struct netr_LogonControl2Ex *r)
810 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
815 netr_NETRENUMERATETRUSTEDDOMAINS
817 static WERROR netr_NETRENUMERATETRUSTEDDOMAINS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
818 struct netr_NETRENUMERATETRUSTEDDOMAINS *r)
820 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
827 static WERROR netr_DSRGETDCNAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
828 struct netr_DSRGETDCNAME *r)
830 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
835 netr_NETRLOGONDUMMYROUTINE1
837 static WERROR netr_NETRLOGONDUMMYROUTINE1(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
838 struct netr_NETRLOGONDUMMYROUTINE1 *r)
840 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
845 netr_NETRLOGONSETSERVICEBITS
847 static WERROR netr_NETRLOGONSETSERVICEBITS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
848 struct netr_NETRLOGONSETSERVICEBITS *r)
850 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
855 netr_NETRLOGONGETTRUSTRID
857 static WERROR netr_NETRLOGONGETTRUSTRID(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
858 struct netr_NETRLOGONGETTRUSTRID *r)
860 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
865 netr_NETRLOGONCOMPUTESERVERDIGEST
867 static WERROR netr_NETRLOGONCOMPUTESERVERDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
868 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
870 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
875 netr_NETRLOGONCOMPUTECLIENTDIGEST
877 static WERROR netr_NETRLOGONCOMPUTECLIENTDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
878 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
880 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
887 static WERROR netr_DSRGETDCNAMEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
888 struct netr_DSRGETDCNAMEX *r)
890 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
897 static WERROR netr_DSRGETSITENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
898 struct netr_DSRGETSITENAME *r)
900 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
905 fill in a netr_DomainTrustInfo from a ldb search result
907 static NTSTATUS fill_domain_trust_info(TALLOC_CTX *mem_ctx, struct ldb_message *res,
908 struct netr_DomainTrustInfo *info)
912 info->domainname.string = samdb_result_string(res, "flatName", NULL);
913 if (info->domainname.string == NULL) {
914 info->domainname.string = samdb_result_string(res, "name", NULL);
915 info->fulldomainname.string = samdb_result_string(res, "dnsDomain", NULL);
917 info->fulldomainname.string = samdb_result_string(res, "name", NULL);
920 /* TODO: we need proper forest support */
921 info->forest.string = info->fulldomainname.string;
923 info->guid = samdb_result_guid(res, "objectGUID");
924 info->sid = samdb_result_dom_sid(mem_ctx, res, "objectSid");
930 netr_LogonGetDomainInfo
931 this is called as part of the ADS domain logon procedure.
933 static NTSTATUS netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
934 struct netr_LogonGetDomainInfo *r)
936 struct server_pipe_state *pipe_state = dce_call->conn->private;
937 const char * const attrs[] = { "name", "dnsDomain", "objectSid",
938 "objectGUID", "flatName", NULL };
940 struct ldb_message **res1, **res2;
941 struct netr_DomainInfo1 *info1;
946 return NT_STATUS_ACCESS_DENIED;
949 if (!netr_creds_server_step_check(pipe_state,
950 r->in.credential, r->out.credential)) {
951 return NT_STATUS_ACCESS_DENIED;
954 sam_ctx = samdb_connect(mem_ctx);
955 if (sam_ctx == NULL) {
956 return NT_STATUS_INVALID_SYSTEM_SERVICE;
959 /* we need to do two searches. The first will pull our primary
960 domain and the second will pull any trusted domains. Our
961 primary domain is also a "trusted" domain, so we need to
962 put the primary domain into the lists of returned trusts as
964 ret1 = samdb_search(sam_ctx, mem_ctx, NULL, &res1, attrs, "(objectClass=domainDNS)");
966 return NT_STATUS_INTERNAL_DB_CORRUPTION;
969 ret2 = samdb_search(sam_ctx, mem_ctx, NULL, &res2, attrs, "(objectClass=trustedDomain)");
971 return NT_STATUS_INTERNAL_DB_CORRUPTION;
974 info1 = talloc_p(mem_ctx, struct netr_DomainInfo1);
976 return NT_STATUS_NO_MEMORY;
981 info1->num_trusts = ret2 + 1;
982 info1->trusts = talloc_array_p(mem_ctx, struct netr_DomainTrustInfo,
984 if (info1->trusts == NULL) {
985 return NT_STATUS_NO_MEMORY;
988 status = fill_domain_trust_info(mem_ctx, res1[0], &info1->domaininfo);
989 if (!NT_STATUS_IS_OK(status)) {
993 status = fill_domain_trust_info(mem_ctx, res1[0], &info1->trusts[0]);
994 if (!NT_STATUS_IS_OK(status)) {
998 for (i=0;i<ret2;i++) {
999 status = fill_domain_trust_info(mem_ctx, res2[i], &info1->trusts[i+1]);
1000 if (!NT_STATUS_IS_OK(status)) {
1005 r->out.info.info1 = info1;
1007 return NT_STATUS_OK;
1012 netr_NETRSERVERPASSWORDSET2
1014 static WERROR netr_NETRSERVERPASSWORDSET2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1015 struct netr_NETRSERVERPASSWORDSET2 *r)
1017 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1022 netr_NETRSERVERPASSWORDGET
1024 static WERROR netr_NETRSERVERPASSWORDGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1025 struct netr_NETRSERVERPASSWORDGET *r)
1027 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1032 netr_NETRLOGONSENDTOSAM
1034 static WERROR netr_NETRLOGONSENDTOSAM(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1035 struct netr_NETRLOGONSENDTOSAM *r)
1037 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1042 netr_DSRADDRESSTOSITENAMESW
1044 static WERROR netr_DSRADDRESSTOSITENAMESW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1045 struct netr_DSRADDRESSTOSITENAMESW *r)
1047 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1052 netr_DSRGETDCNAMEEX2
1054 static WERROR netr_DSRGETDCNAMEEX2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1055 struct netr_DSRGETDCNAMEEX2 *r)
1057 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1062 netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
1064 static WERROR netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1065 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
1067 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1072 netr_NETRENUMERATETRUSTEDDOMAINSEX
1074 static WERROR netr_NETRENUMERATETRUSTEDDOMAINSEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1075 struct netr_NETRENUMERATETRUSTEDDOMAINSEX *r)
1077 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1082 netr_DSRADDRESSTOSITENAMESEXW
1084 static WERROR netr_DSRADDRESSTOSITENAMESEXW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1085 struct netr_DSRADDRESSTOSITENAMESEXW *r)
1087 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1092 netr_DSRGETDCSITECOVERAGEW
1094 static WERROR netr_DSRGETDCSITECOVERAGEW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1095 struct netr_DSRGETDCSITECOVERAGEW *r)
1097 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1102 netr_NETRLOGONSAMLOGONEX
1104 static WERROR netr_NETRLOGONSAMLOGONEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1105 struct netr_NETRLOGONSAMLOGONEX *r)
1107 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1112 netr_DsrEnumerateDomainTrusts
1114 static WERROR netr_DsrEnumerateDomainTrusts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1115 struct netr_DsrEnumerateDomainTrusts *r)
1117 struct netr_DomainTrust *trusts;
1120 struct ldb_message **res;
1121 const char * const attrs[] = { "name", "dnsDomain", "objectSid", "objectGUID", NULL };
1123 ZERO_STRUCT(r->out);
1125 sam_ctx = samdb_connect(mem_ctx);
1126 if (sam_ctx == NULL) {
1127 return WERR_GENERAL_FAILURE;
1130 ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs, "(objectClass=domainDNS)");
1132 return WERR_GENERAL_FAILURE;
1139 trusts = talloc_array_p(mem_ctx, struct netr_DomainTrust, ret);
1140 if (trusts == NULL) {
1145 r->out.trusts = trusts;
1147 /* TODO: add filtering by trust_flags, and correct trust_type
1149 for (i=0;i<ret;i++) {
1150 trusts[i].netbios_name = samdb_result_string(res[i], "name", NULL);
1151 trusts[i].dns_name = samdb_result_string(res[i], "dnsDomain", NULL);
1152 trusts[i].trust_flags =
1153 NETR_TRUST_FLAG_TREEROOT |
1154 NETR_TRUST_FLAG_IN_FOREST |
1155 NETR_TRUST_FLAG_PRIMARY;
1156 trusts[i].parent_index = 0;
1157 trusts[i].trust_type = 2;
1158 trusts[i].trust_attributes = 0;
1159 trusts[i].sid = samdb_result_dom_sid(mem_ctx, res[i], "objectSid");
1160 trusts[i].guid = samdb_result_guid(res[i], "objectGUID");
1169 netr_DSRDEREGISTERDNSHOSTRECORDS
1171 static WERROR netr_DSRDEREGISTERDNSHOSTRECORDS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1172 struct netr_DSRDEREGISTERDNSHOSTRECORDS *r)
1174 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1179 netr_NETRSERVERTRUSTPASSWORDSGET
1181 static WERROR netr_NETRSERVERTRUSTPASSWORDSGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1182 struct netr_NETRSERVERTRUSTPASSWORDSGET *r)
1184 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1189 netr_DSRGETFORESTTRUSTINFORMATION
1191 static WERROR netr_DSRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1192 struct netr_DSRGETFORESTTRUSTINFORMATION *r)
1194 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1199 netr_NETRGETFORESTTRUSTINFORMATION
1201 static WERROR netr_NETRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1202 struct netr_NETRGETFORESTTRUSTINFORMATION *r)
1204 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1209 netr_NETRSERVERGETTRUSTINFO
1211 static WERROR netr_NETRSERVERGETTRUSTINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1212 struct netr_NETRSERVERGETTRUSTINFO *r)
1214 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1218 /* include the generated boilerplate */
1219 #include "librpc/gen_ndr/ndr_netlogon_s.c"