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 "librpc/gen_ndr/ndr_netlogon.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "rpc_server/common/common.h"
27 #include "librpc/gen_ndr/ndr_dcom.h"
28 #include "auth/auth.h"
29 #include "lib/ldb/include/ldb.h"
31 struct server_pipe_state {
32 struct netr_Credential client_challenge;
33 struct netr_Credential server_challenge;
36 char *computer_name; /* for logging only */
38 uint16_t sec_chan_type;
39 struct creds_CredentialState *creds;
44 a client has connected to the netlogon server using schannel, so we need
45 to re-establish the credentials state
47 static NTSTATUS netlogon_schannel_setup(struct dcesrv_call_state *dce_call)
49 struct server_pipe_state *state;
52 state = talloc_p(dce_call->conn, struct server_pipe_state);
54 return NT_STATUS_NO_MEMORY;
57 state->authenticated = True;
59 if (dce_call->conn->auth_state.session_info == NULL) {
61 smb_panic("No session info provided by schannel level setup!");
62 return NT_STATUS_NO_USER_SESSION_KEY;
65 status = dcerpc_schannel_creds(dce_call->conn->auth_state.gensec_security,
69 if (!NT_STATUS_IS_OK(status)) {
70 DEBUG(3, ("getting schannel credentials failed with %s\n", nt_errstr(status)));
75 dce_call->conn->private = state;
81 a hook for bind on the netlogon pipe
83 static NTSTATUS netlogon_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *di)
85 dce_call->conn->private = NULL;
87 /* if this is a schannel bind then we need to reconstruct the pipe state */
88 if (dce_call->conn->auth_state.auth_info &&
89 dce_call->conn->auth_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
92 DEBUG(5, ("schannel bind on netlogon\n"));
94 status = netlogon_schannel_setup(dce_call);
95 if (!NT_STATUS_IS_OK(status)) {
96 DEBUG(3, ("schannel bind on netlogon failed with %s\n", nt_errstr(status)));
104 /* this function is called when the client disconnects the endpoint */
105 static void netlogon_unbind(struct dcesrv_connection *conn, const struct dcesrv_interface *di)
107 struct server_pipe_state *pipe_state = conn->private;
110 talloc_free(pipe_state);
113 conn->private = NULL;
116 #define DCESRV_INTERFACE_NETLOGON_BIND netlogon_bind
117 #define DCESRV_INTERFACE_NETLOGON_UNBIND netlogon_unbind
119 static NTSTATUS netr_ServerReqChallenge(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
120 struct netr_ServerReqChallenge *r)
122 struct server_pipe_state *pipe_state = dce_call->conn->private;
124 ZERO_STRUCTP(r->out.credentials);
126 /* destroyed on pipe shutdown */
129 talloc_free(pipe_state);
130 dce_call->conn->private = NULL;
133 pipe_state = talloc_p(dce_call->conn, struct server_pipe_state);
135 return NT_STATUS_NO_MEMORY;
138 pipe_state->authenticated = False;
139 pipe_state->creds = NULL;
140 pipe_state->account_name = NULL;
141 pipe_state->computer_name = NULL;
143 pipe_state->client_challenge = *r->in.credentials;
145 generate_random_buffer(pipe_state->server_challenge.data,
146 sizeof(pipe_state->server_challenge.data));
148 *r->out.credentials = pipe_state->server_challenge;
150 dce_call->conn->private = pipe_state;
155 static NTSTATUS netr_ServerAuthenticate3(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
156 struct netr_ServerAuthenticate3 *r)
158 struct server_pipe_state *pipe_state = dce_call->conn->private;
160 struct samr_Password *mach_pwd;
163 struct ldb_message **msgs;
165 const char *attrs[] = {"unicodePwd", "lmPwdHash", "ntPwdHash", "userAccountControl",
168 ZERO_STRUCTP(r->out.credentials);
170 *r->out.negotiate_flags = *r->in.negotiate_flags;
173 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
174 return NT_STATUS_ACCESS_DENIED;
177 sam_ctx = samdb_connect(mem_ctx);
178 if (sam_ctx == NULL) {
179 return NT_STATUS_INVALID_SYSTEM_SERVICE;
181 /* pull the user attributes */
182 num_records = samdb_search(sam_ctx, mem_ctx, NULL, &msgs, attrs,
183 "(&(sAMAccountName=%s)(objectclass=user))",
186 if (num_records == 0) {
187 DEBUG(3,("Couldn't find user [%s] in samdb.\n",
188 r->in.account_name));
189 return NT_STATUS_NO_SUCH_USER;
192 if (num_records > 1) {
193 DEBUG(0,("Found %d records matching user [%s]\n", num_records, r->in.account_name));
194 return NT_STATUS_INTERNAL_DB_CORRUPTION;
197 acct_flags = samdb_result_acct_flags(msgs[0],
198 "userAccountControl");
200 if (acct_flags & ACB_DISABLED) {
201 DEBUG(1, ("Account [%s] is disabled\n", r->in.account_name));
202 return NT_STATUS_ACCESS_DENIED;
205 if (r->in.secure_channel_type == SEC_CHAN_WKSTA) {
206 if (!(acct_flags & ACB_WSTRUST)) {
207 DEBUG(1, ("Client asked for a workstation secure channel, but is not a workstation (member server) acb flags: 0x%x\n", acct_flags));
208 return NT_STATUS_ACCESS_DENIED;
210 } else if (r->in.secure_channel_type == SEC_CHAN_DOMAIN) {
211 if (!(acct_flags & ACB_DOMTRUST)) {
212 DEBUG(1, ("Client asked for a trusted domain secure channel, but is not a trusted domain: acb flags: 0x%x\n", acct_flags));
213 return NT_STATUS_ACCESS_DENIED;
215 } else if (r->in.secure_channel_type == SEC_CHAN_BDC) {
216 if (!(acct_flags & ACB_SVRTRUST)) {
217 DEBUG(1, ("Client asked for a server secure channel, but is not a server (domain controller): acb flags: 0x%x\n", acct_flags));
218 return NT_STATUS_ACCESS_DENIED;
221 DEBUG(1, ("Client asked for an invalid secure channel type: %d\n",
222 r->in.secure_channel_type));
223 return NT_STATUS_ACCESS_DENIED;
226 pipe_state->acct_flags = acct_flags;
227 pipe_state->sec_chan_type = r->in.secure_channel_type;
229 *r->out.rid = samdb_result_rid_from_sid(mem_ctx, msgs[0], "objectSid", 0);
231 nt_status = samdb_result_passwords(mem_ctx, msgs[0], NULL, &mach_pwd);
232 if (!NT_STATUS_IS_OK(nt_status) || mach_pwd == NULL) {
233 return NT_STATUS_ACCESS_DENIED;
236 if (!pipe_state->creds) {
237 pipe_state->creds = talloc_p(pipe_state, struct creds_CredentialState);
238 if (!pipe_state->creds) {
239 return NT_STATUS_NO_MEMORY;
243 creds_server_init(pipe_state->creds, &pipe_state->client_challenge,
244 &pipe_state->server_challenge, mach_pwd,
246 *r->in.negotiate_flags);
248 if (!creds_server_check(pipe_state->creds, r->in.credentials)) {
249 return NT_STATUS_ACCESS_DENIED;
252 pipe_state->authenticated = True;
254 if (pipe_state->account_name) {
255 /* We don't want a memory leak on this long-lived talloc context */
256 talloc_free(pipe_state->account_name);
259 pipe_state->account_name = talloc_strdup(pipe_state, r->in.account_name);
261 if (pipe_state->computer_name) {
262 /* We don't want a memory leak on this long-lived talloc context */
263 talloc_free(pipe_state->computer_name);
266 pipe_state->computer_name = talloc_strdup(pipe_state, r->in.computer_name);
268 /* remember this session key state */
269 nt_status = schannel_store_session_key(mem_ctx, pipe_state->computer_name, pipe_state->creds);
274 static NTSTATUS netr_ServerAuthenticate(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
275 struct netr_ServerAuthenticate *r)
277 struct netr_ServerAuthenticate3 r3;
280 * negotiate_flags is used as an [in] parameter
281 * so it need to be initialised.
283 * (I think ... = 0; seems wrong here --metze)
285 uint32 negotiate_flags = 0;
287 r3.in.server_name = r->in.server_name;
288 r3.in.account_name = r->in.account_name;
289 r3.in.secure_channel_type = r->in.secure_channel_type;
290 r3.in.computer_name = r->in.computer_name;
291 r3.in.credentials = r->in.credentials;
292 r3.out.credentials = r->out.credentials;
293 r3.in.negotiate_flags = &negotiate_flags;
294 r3.out.negotiate_flags = &negotiate_flags;
297 return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
300 static NTSTATUS netr_ServerAuthenticate2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
301 struct netr_ServerAuthenticate2 *r)
303 struct netr_ServerAuthenticate3 r3;
306 r3.in.server_name = r->in.server_name;
307 r3.in.account_name = r->in.account_name;
308 r3.in.secure_channel_type = r->in.secure_channel_type;
309 r3.in.computer_name = r->in.computer_name;
310 r3.in.credentials = r->in.credentials;
311 r3.out.credentials = r->out.credentials;
312 r3.in.negotiate_flags = r->in.negotiate_flags;
313 r3.out.negotiate_flags = r->out.negotiate_flags;
316 return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
320 static BOOL netr_creds_server_step_check(struct server_pipe_state *pipe_state,
321 struct netr_Authenticator *received_authenticator,
322 struct netr_Authenticator *return_authenticator)
324 if (!pipe_state->authenticated) {
327 return creds_server_step_check(pipe_state->creds,
328 received_authenticator,
329 return_authenticator);
333 static NTSTATUS netr_ServerPasswordSet(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
334 struct netr_ServerPasswordSet *r)
336 struct server_pipe_state *pipe_state = dce_call->conn->private;
340 int num_records_domain;
342 struct ldb_message **msgs;
343 struct ldb_message **msgs_domain;
345 struct ldb_message mod, *msg_set_pw = &mod;
346 const char *domain_dn;
347 const char *domain_sid;
349 const char *attrs[] = {"objectSid", NULL };
351 const char **domain_attrs = attrs;
355 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
356 return NT_STATUS_ACCESS_DENIED;
359 if (!netr_creds_server_step_check(pipe_state, &r->in.credential, &r->out.return_authenticator)) {
360 return NT_STATUS_ACCESS_DENIED;
363 sam_ctx = samdb_connect(mem_ctx);
364 if (sam_ctx == NULL) {
365 return NT_STATUS_INVALID_SYSTEM_SERVICE;
367 /* pull the user attributes */
368 num_records = samdb_search(sam_ctx, mem_ctx, NULL, &msgs, attrs,
369 "(&(sAMAccountName=%s)(objectclass=user))",
370 pipe_state->account_name);
372 if (num_records == 0) {
373 DEBUG(3,("Couldn't find user [%s] in samdb.\n",
374 pipe_state->account_name));
375 return NT_STATUS_NO_SUCH_USER;
378 if (num_records > 1) {
379 DEBUG(0,("Found %d records matching user [%s]\n", num_records,
380 pipe_state->account_name));
381 return NT_STATUS_INTERNAL_DB_CORRUPTION;
384 domain_sid = samdb_result_sid_prefix(mem_ctx, msgs[0], "objectSid");
386 DEBUG(0,("no objectSid in user record\n"));
387 return NT_STATUS_INTERNAL_DB_CORRUPTION;
390 /* find the domain's DN */
391 num_records_domain = samdb_search(sam_ctx, mem_ctx, NULL,
392 &msgs_domain, domain_attrs,
393 "(&(objectSid=%s)(objectclass=domain))",
396 if (num_records_domain == 0) {
397 DEBUG(3,("check_sam_security: Couldn't find domain [%s] in passdb file.\n",
399 return NT_STATUS_NO_SUCH_USER;
402 if (num_records_domain > 1) {
403 DEBUG(0,("Found %d records matching domain [%s]\n",
404 num_records_domain, domain_sid));
405 return NT_STATUS_INTERNAL_DB_CORRUPTION;
408 domain_dn = msgs_domain[0]->dn;
410 mod.dn = talloc_strdup(mem_ctx, msgs[0]->dn);
412 return NT_STATUS_NO_MEMORY;
415 creds_des_decrypt(pipe_state->creds, &r->in.new_password);
417 /* set the password - samdb needs to know both the domain and user DNs,
418 so the domain password policy can be used */
419 nt_status = samdb_set_password(sam_ctx, mem_ctx,
420 msgs[0]->dn, domain_dn,
422 NULL, /* Don't have plaintext */
423 NULL, &r->in.new_password,
424 False /* This is not considered a password change */,
427 if (!NT_STATUS_IS_OK(nt_status)) {
431 ret = samdb_replace(sam_ctx, mem_ctx, msg_set_pw);
433 /* we really need samdb.c to return NTSTATUS */
434 return NT_STATUS_UNSUCCESSFUL;
444 static WERROR netr_LogonUasLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
445 struct netr_LogonUasLogon *r)
447 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
454 static WERROR netr_LogonUasLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
455 struct netr_LogonUasLogoff *r)
457 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
462 netr_LogonSamLogonWithFlags
465 static NTSTATUS netr_LogonSamLogonWithFlags(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
466 struct netr_LogonSamLogonWithFlags *r)
468 struct server_pipe_state *pipe_state = dce_call->conn->private;
470 struct auth_context *auth_context;
471 struct auth_usersupplied_info *user_info;
472 struct auth_serversupplied_info *server_info;
475 static const char zeros[16];
476 struct netr_SamBaseInfo *sam;
477 struct netr_SamInfo2 *sam2;
478 struct netr_SamInfo3 *sam3;
479 struct netr_SamInfo6 *sam6;
482 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
483 return NT_STATUS_ACCESS_DENIED;
486 r->out.return_authenticator = talloc_p(mem_ctx, struct netr_Authenticator);
487 if (!r->out.return_authenticator) {
488 return NT_STATUS_NO_MEMORY;
491 if (!netr_creds_server_step_check(pipe_state, r->in.credential, r->out.return_authenticator)) {
492 return NT_STATUS_ACCESS_DENIED;
495 switch (r->in.logon_level) {
499 creds_arcfour_crypt(pipe_state->creds,
500 r->in.logon.password->lmpassword.hash,
501 sizeof(r->in.logon.password->lmpassword.hash));
502 creds_arcfour_crypt(pipe_state->creds,
503 r->in.logon.password->ntpassword.hash,
504 sizeof(r->in.logon.password->ntpassword.hash));
506 nt_status = make_auth_context_subsystem(pipe_state, &auth_context);
507 if (!NT_STATUS_IS_OK(nt_status)) {
511 chal = auth_context->get_ntlm_challenge(auth_context);
512 nt_status = make_user_info_netlogon_interactive(auth_context,
514 r->in.logon.password->identity_info.account_name.string,
515 r->in.logon.password->identity_info.domain_name.string,
516 r->in.logon.password->identity_info.workstation.string,
518 &r->in.logon.password->lmpassword,
519 &r->in.logon.password->ntpassword);
524 nt_status = make_auth_context_fixed(pipe_state,
525 &auth_context, r->in.logon.network->challenge);
526 if (!NT_STATUS_IS_OK(nt_status)) {
530 nt_status = make_user_info_netlogon_network(auth_context,
532 r->in.logon.network->identity_info.account_name.string,
533 r->in.logon.network->identity_info.domain_name.string,
534 r->in.logon.network->identity_info.workstation.string,
535 r->in.logon.network->lm.data, r->in.logon.network->lm.length,
536 r->in.logon.network->nt.data, r->in.logon.network->nt.length);
539 free_auth_context(&auth_context);
540 return NT_STATUS_INVALID_PARAMETER;
543 if (!NT_STATUS_IS_OK(nt_status)) {
547 nt_status = auth_context->check_ntlm_password(auth_context,
552 /* keep the auth_context for the life of this call */
553 talloc_steal(dce_call, auth_context);
555 if (!NT_STATUS_IS_OK(nt_status)) {
559 sam = talloc_p(mem_ctx, struct netr_SamBaseInfo);
563 sam->last_logon = server_info->last_logon;
564 sam->last_logoff = server_info->last_logoff;
565 sam->acct_expiry = server_info->acct_expiry;
566 sam->last_password_change = server_info->last_password_change;
567 sam->allow_password_change = server_info->allow_password_change;
568 sam->force_password_change = server_info->force_password_change;
570 sam->account_name.string = talloc_strdup(mem_ctx, server_info->account_name);
571 sam->full_name.string = talloc_strdup(mem_ctx, server_info->full_name);
572 sam->logon_script.string = talloc_strdup(mem_ctx, server_info->logon_script);
573 sam->profile_path.string = talloc_strdup(mem_ctx, server_info->profile_path);
574 sam->home_directory.string = talloc_strdup(mem_ctx, server_info->home_directory);
575 sam->home_drive.string = talloc_strdup(mem_ctx, server_info->home_drive);
577 sam->logon_count = server_info->logon_count;
578 sam->bad_password_count = sam->bad_password_count;
579 sam->rid = server_info->user_sid->sub_auths[server_info->user_sid->num_auths-1];
580 sam->primary_gid = server_info->primary_group_sid->sub_auths[server_info->primary_group_sid->num_auths-1];
581 sam->group_count = 0;
582 sam->groupids = NULL;
583 sam->user_flags = 0; /* TODO: w2k3 uses 0x120 - what is this? */
584 sam->acct_flags = server_info->acct_flags;
585 sam->logon_server.string = lp_netbios_name();
587 sam->domain.string = talloc_strdup(mem_ctx, server_info->domain);
589 sam->domain_sid = dom_sid_dup(mem_ctx, server_info->user_sid);
590 sam->domain_sid->num_auths--;
592 if (server_info->user_session_key.length == sizeof(sam->key.key)) {
593 memcpy(sam->key.key, server_info->user_session_key.data, sizeof(sam->key.key));
595 ZERO_STRUCT(sam->key.key);
598 /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
599 /* It appears that level 6 is not individually encrypted */
600 if ((r->in.validation_level != 6)
601 && memcmp(sam->key.key, zeros,
602 sizeof(sam->key.key)) != 0) {
603 creds_arcfour_crypt(pipe_state->creds,
605 sizeof(sam->key.key));
608 if (server_info->lm_session_key.length == sizeof(sam->LMSessKey.key)) {
609 memcpy(sam->LMSessKey.key, server_info->lm_session_key.data,
610 sizeof(sam->LMSessKey.key));
612 ZERO_STRUCT(sam->LMSessKey.key);
615 /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
616 /* It appears that level 6 is not individually encrypted */
617 if ((r->in.validation_level != 6)
618 && memcmp(sam->LMSessKey.key, zeros,
619 sizeof(sam->LMSessKey.key)) != 0) {
620 creds_arcfour_crypt(pipe_state->creds,
622 sizeof(sam->LMSessKey.key));
625 switch (r->in.validation_level) {
627 sam2 = talloc_p(mem_ctx, struct netr_SamInfo2);
630 r->out.validation.sam2 = sam2;
634 sam3 = talloc_p(mem_ctx, struct netr_SamInfo3);
637 r->out.validation.sam3 = sam3;
641 sam6 = talloc_p(mem_ctx, struct netr_SamInfo6);
644 sam6->forest.string = lp_realm();
645 sam6->principle.string = talloc_asprintf(mem_ctx, "%s@%s",
646 sam->account_name.string, sam6->forest.string);
647 r->out.validation.sam6 = sam6;
654 r->out.authoritative = 1;
662 static NTSTATUS netr_LogonSamLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
663 struct netr_LogonSamLogon *r)
665 struct netr_LogonSamLogonWithFlags r2;
670 r2.in.server_name = r->in.server_name;
671 r2.in.workstation = r->in.workstation;
672 r2.in.credential = r->in.credential;
673 r2.in.return_authenticator = r->in.return_authenticator;
674 r2.in.logon_level = r->in.logon_level;
675 r2.in.logon = r->in.logon;
676 r2.in.validation_level = r->in.validation_level;
679 status = netr_LogonSamLogonWithFlags(dce_call, mem_ctx, &r2);
681 r->out.return_authenticator = r2.out.return_authenticator;
682 r->out.validation = r2.out.validation;
683 r->out.authoritative = r2.out.authoritative;
692 static NTSTATUS netr_LogonSamLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
693 struct netr_LogonSamLogoff *r)
695 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
703 static NTSTATUS netr_DatabaseDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
704 struct netr_DatabaseDeltas *r)
706 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
713 static NTSTATUS netr_DatabaseSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
714 struct netr_DatabaseSync *r)
716 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
723 static NTSTATUS netr_AccountDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
724 struct netr_AccountDeltas *r)
726 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
733 static NTSTATUS netr_AccountSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
734 struct netr_AccountSync *r)
736 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
743 static NTSTATUS netr_GetDcName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
744 struct netr_GetDcName *r)
746 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
753 static WERROR netr_LogonControl(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
754 struct netr_LogonControl *r)
756 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
763 static WERROR netr_GetAnyDCName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
764 struct netr_GetAnyDCName *r)
766 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
773 static WERROR netr_LogonControl2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
774 struct netr_LogonControl2 *r)
776 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
783 static NTSTATUS netr_DatabaseSync2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
784 struct netr_DatabaseSync2 *r)
786 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
793 static NTSTATUS netr_DatabaseRedo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
794 struct netr_DatabaseRedo *r)
796 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
803 static WERROR netr_LogonControl2Ex(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
804 struct netr_LogonControl2Ex *r)
806 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
811 netr_NETRENUMERATETRUSTEDDOMAINS
813 static WERROR netr_NETRENUMERATETRUSTEDDOMAINS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
814 struct netr_NETRENUMERATETRUSTEDDOMAINS *r)
816 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
823 static WERROR netr_DSRGETDCNAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
824 struct netr_DSRGETDCNAME *r)
826 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
831 netr_NETRLOGONDUMMYROUTINE1
833 static WERROR netr_NETRLOGONDUMMYROUTINE1(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
834 struct netr_NETRLOGONDUMMYROUTINE1 *r)
836 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
841 netr_NETRLOGONSETSERVICEBITS
843 static WERROR netr_NETRLOGONSETSERVICEBITS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
844 struct netr_NETRLOGONSETSERVICEBITS *r)
846 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
851 netr_NETRLOGONGETTRUSTRID
853 static WERROR netr_NETRLOGONGETTRUSTRID(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
854 struct netr_NETRLOGONGETTRUSTRID *r)
856 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
861 netr_NETRLOGONCOMPUTESERVERDIGEST
863 static WERROR netr_NETRLOGONCOMPUTESERVERDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
864 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
866 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
871 netr_NETRLOGONCOMPUTECLIENTDIGEST
873 static WERROR netr_NETRLOGONCOMPUTECLIENTDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
874 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
876 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
883 static WERROR netr_DSRGETDCNAMEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
884 struct netr_DSRGETDCNAMEX *r)
886 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
893 static WERROR netr_DSRGETSITENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
894 struct netr_DSRGETSITENAME *r)
896 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
901 fill in a netr_DomainTrustInfo from a ldb search result
903 static NTSTATUS fill_domain_trust_info(TALLOC_CTX *mem_ctx, struct ldb_message *res,
904 struct netr_DomainTrustInfo *info)
908 info->domainname.string = samdb_result_string(res, "flatName", NULL);
909 if (info->domainname.string == NULL) {
910 info->domainname.string = samdb_result_string(res, "name", NULL);
911 info->fulldomainname.string = samdb_result_string(res, "dnsDomain", NULL);
913 info->fulldomainname.string = samdb_result_string(res, "name", NULL);
916 /* TODO: we need proper forest support */
917 info->forest.string = info->fulldomainname.string;
919 info->guid = samdb_result_guid(res, "objectGUID");
920 info->sid = samdb_result_dom_sid(mem_ctx, res, "objectSid");
926 netr_LogonGetDomainInfo
927 this is called as part of the ADS domain logon procedure.
929 static NTSTATUS netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
930 struct netr_LogonGetDomainInfo *r)
932 struct server_pipe_state *pipe_state = dce_call->conn->private;
933 const char * const attrs[] = { "name", "dnsDomain", "objectSid",
934 "objectGUID", "flatName", NULL };
936 struct ldb_message **res1, **res2;
937 struct netr_DomainInfo1 *info1;
942 return NT_STATUS_ACCESS_DENIED;
945 if (!netr_creds_server_step_check(pipe_state,
946 r->in.credential, r->out.credential)) {
947 return NT_STATUS_ACCESS_DENIED;
950 sam_ctx = samdb_connect(mem_ctx);
951 if (sam_ctx == NULL) {
952 return NT_STATUS_INVALID_SYSTEM_SERVICE;
955 /* we need to do two searches. The first will pull our primary
956 domain and the second will pull any trusted domains. Our
957 primary domain is also a "trusted" domain, so we need to
958 put the primary domain into the lists of returned trusts as
960 ret1 = samdb_search(sam_ctx, mem_ctx, NULL, &res1, attrs, "(objectClass=domainDNS)");
962 return NT_STATUS_INTERNAL_DB_CORRUPTION;
965 ret2 = samdb_search(sam_ctx, mem_ctx, NULL, &res2, attrs, "(objectClass=trustedDomain)");
967 return NT_STATUS_INTERNAL_DB_CORRUPTION;
970 info1 = talloc_p(mem_ctx, struct netr_DomainInfo1);
972 return NT_STATUS_NO_MEMORY;
977 info1->num_trusts = ret2 + 1;
978 info1->trusts = talloc_array_p(mem_ctx, struct netr_DomainTrustInfo,
980 if (info1->trusts == NULL) {
981 return NT_STATUS_NO_MEMORY;
984 status = fill_domain_trust_info(mem_ctx, res1[0], &info1->domaininfo);
985 if (!NT_STATUS_IS_OK(status)) {
989 status = fill_domain_trust_info(mem_ctx, res1[0], &info1->trusts[0]);
990 if (!NT_STATUS_IS_OK(status)) {
994 for (i=0;i<ret2;i++) {
995 status = fill_domain_trust_info(mem_ctx, res2[i], &info1->trusts[i+1]);
996 if (!NT_STATUS_IS_OK(status)) {
1001 r->out.info.info1 = info1;
1003 return NT_STATUS_OK;
1008 netr_NETRSERVERPASSWORDSET2
1010 static WERROR netr_NETRSERVERPASSWORDSET2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1011 struct netr_NETRSERVERPASSWORDSET2 *r)
1013 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1018 netr_NETRSERVERPASSWORDGET
1020 static WERROR netr_NETRSERVERPASSWORDGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1021 struct netr_NETRSERVERPASSWORDGET *r)
1023 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1028 netr_NETRLOGONSENDTOSAM
1030 static WERROR netr_NETRLOGONSENDTOSAM(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1031 struct netr_NETRLOGONSENDTOSAM *r)
1033 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1038 netr_DSRADDRESSTOSITENAMESW
1040 static WERROR netr_DSRADDRESSTOSITENAMESW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1041 struct netr_DSRADDRESSTOSITENAMESW *r)
1043 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1048 netr_DrsGetDCNameEx2
1050 static WERROR netr_DrsGetDCNameEx2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1051 struct netr_DrsGetDCNameEx2 *r)
1053 const char * const attrs[] = { "dnsDomain", "objectGUID", NULL };
1055 struct ldb_message **res;
1058 ZERO_STRUCT(r->out);
1060 sam_ctx = samdb_connect(mem_ctx);
1061 if (sam_ctx == NULL) {
1062 return WERR_DS_SERVICE_UNAVAILABLE;
1065 ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs,
1066 "(&(objectClass=domainDNS)(dnsDomain=%s))",
1069 return WERR_NO_SUCH_DOMAIN;
1072 r->out.info = talloc_p(mem_ctx, struct netr_DrsGetDCNameEx2Info);
1077 /* TODO: - return real IP address
1078 * - check all r->in.* parameters (server_unc is ignored by w2k3!)
1080 r->out.info->dc_unc = talloc_asprintf(mem_ctx, "\\\\%s.%s", lp_netbios_name(),lp_realm());
1081 r->out.info->dc_address = talloc_strdup(mem_ctx, "\\\\0.0.0.0");
1082 r->out.info->dc_address_type = 1;
1083 r->out.info->domain_guid = samdb_result_guid(res[0], "objectGUID");
1084 r->out.info->domain_name = samdb_result_string(res[0], "dnsDomain", NULL);
1085 r->out.info->forest_name = samdb_result_string(res[0], "dnsDomain", NULL);
1086 r->out.info->dc_flags = 0xE00001FD;
1087 r->out.info->dc_site_name = talloc_strdup(mem_ctx, "Default-First-Site-Name");
1088 r->out.info->client_site_name = talloc_strdup(mem_ctx, "Default-First-Site-Name");
1095 netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
1097 static WERROR netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1098 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
1100 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1105 netr_NETRENUMERATETRUSTEDDOMAINSEX
1107 static WERROR netr_NETRENUMERATETRUSTEDDOMAINSEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1108 struct netr_NETRENUMERATETRUSTEDDOMAINSEX *r)
1110 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1115 netr_DSRADDRESSTOSITENAMESEXW
1117 static WERROR netr_DSRADDRESSTOSITENAMESEXW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1118 struct netr_DSRADDRESSTOSITENAMESEXW *r)
1120 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1125 netr_DSRGETDCSITECOVERAGEW
1127 static WERROR netr_DSRGETDCSITECOVERAGEW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1128 struct netr_DSRGETDCSITECOVERAGEW *r)
1130 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1135 netr_LogonSamLogonEx
1137 static NTSTATUS netr_LogonSamLogonEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1138 struct netr_LogonSamLogonEx *r)
1140 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1145 netr_DsrEnumerateDomainTrusts
1147 static WERROR netr_DsrEnumerateDomainTrusts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1148 struct netr_DsrEnumerateDomainTrusts *r)
1150 struct netr_DomainTrust *trusts;
1153 struct ldb_message **res;
1154 const char * const attrs[] = { "name", "dnsDomain", "objectSid", "objectGUID", NULL };
1156 ZERO_STRUCT(r->out);
1158 sam_ctx = samdb_connect(mem_ctx);
1159 if (sam_ctx == NULL) {
1160 return WERR_GENERAL_FAILURE;
1163 ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs, "(objectClass=domainDNS)");
1165 return WERR_GENERAL_FAILURE;
1172 trusts = talloc_array_p(mem_ctx, struct netr_DomainTrust, ret);
1173 if (trusts == NULL) {
1178 r->out.trusts = trusts;
1180 /* TODO: add filtering by trust_flags, and correct trust_type
1182 for (i=0;i<ret;i++) {
1183 trusts[i].netbios_name = samdb_result_string(res[i], "name", NULL);
1184 trusts[i].dns_name = samdb_result_string(res[i], "dnsDomain", NULL);
1185 trusts[i].trust_flags =
1186 NETR_TRUST_FLAG_TREEROOT |
1187 NETR_TRUST_FLAG_IN_FOREST |
1188 NETR_TRUST_FLAG_PRIMARY;
1189 trusts[i].parent_index = 0;
1190 trusts[i].trust_type = 2;
1191 trusts[i].trust_attributes = 0;
1192 trusts[i].sid = samdb_result_dom_sid(mem_ctx, res[i], "objectSid");
1193 trusts[i].guid = samdb_result_guid(res[i], "objectGUID");
1202 netr_DSRDEREGISTERDNSHOSTRECORDS
1204 static WERROR netr_DSRDEREGISTERDNSHOSTRECORDS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1205 struct netr_DSRDEREGISTERDNSHOSTRECORDS *r)
1207 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1212 netr_NETRSERVERTRUSTPASSWORDSGET
1214 static WERROR netr_NETRSERVERTRUSTPASSWORDSGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1215 struct netr_NETRSERVERTRUSTPASSWORDSGET *r)
1217 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1222 netr_DSRGETFORESTTRUSTINFORMATION
1224 static WERROR netr_DSRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1225 struct netr_DSRGETFORESTTRUSTINFORMATION *r)
1227 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1232 netr_NETRGETFORESTTRUSTINFORMATION
1234 static WERROR netr_NETRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1235 struct netr_NETRGETFORESTTRUSTINFORMATION *r)
1237 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1242 netr_NETRSERVERGETTRUSTINFO
1244 static WERROR netr_NETRSERVERGETTRUSTINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1245 struct netr_NETRSERVERGETTRUSTINFO *r)
1247 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1251 /* include the generated boilerplate */
1252 #include "librpc/gen_ndr/ndr_netlogon_s.c"