2 Unix SMB/CIFS implementation.
4 endpoint server for the lsarpc pipe
6 Copyright (C) Andrew Tridgell 2004
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-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 #include "rpc_server/lsa/lsa.h"
24 #include "util/util_ldb.h"
25 #include "libcli/ldap/ldap_ndr.h"
26 #include "system/kerberos.h"
27 #include "auth/kerberos/kerberos.h"
28 #include "librpc/gen_ndr/ndr_drsblobs.h"
29 #include "librpc/gen_ndr/ndr_lsa.h"
30 #include "lib/crypto/crypto.h"
33 this type allows us to distinguish handle types
37 state associated with a lsa_OpenAccount() operation
39 struct lsa_account_state {
40 struct lsa_policy_state *policy;
42 struct dom_sid *account_sid;
47 state associated with a lsa_OpenSecret() operation
49 struct lsa_secret_state {
50 struct lsa_policy_state *policy;
52 struct ldb_dn *secret_dn;
53 struct ldb_context *sam_ldb;
58 state associated with a lsa_OpenTrustedDomain() operation
60 struct lsa_trusted_domain_state {
61 struct lsa_policy_state *policy;
63 struct ldb_dn *trusted_domain_dn;
64 struct ldb_dn *trusted_domain_user_dn;
67 static NTSTATUS dcesrv_lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
69 struct lsa_EnumAccountRights *r);
71 static NTSTATUS dcesrv_lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
73 struct lsa_policy_state *state,
76 const struct lsa_RightSet *rights);
81 static NTSTATUS dcesrv_lsa_Close(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
84 struct dcesrv_handle *h;
86 *r->out.handle = *r->in.handle;
88 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
92 ZERO_STRUCTP(r->out.handle);
101 static NTSTATUS dcesrv_lsa_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
102 struct lsa_Delete *r)
104 return NT_STATUS_NOT_SUPPORTED;
111 static NTSTATUS dcesrv_lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
112 struct lsa_DeleteObject *r)
114 struct dcesrv_handle *h;
117 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
119 if (h->wire_handle.handle_type == LSA_HANDLE_SECRET) {
120 struct lsa_secret_state *secret_state = h->data;
122 /* Ensure user is permitted to delete this... */
123 switch (security_session_user_level(dce_call->conn->auth_state.session_info))
125 case SECURITY_SYSTEM:
126 case SECURITY_ADMINISTRATOR:
129 /* Users and annonymous are not allowed delete things */
130 return NT_STATUS_ACCESS_DENIED;
133 ret = ldb_delete(secret_state->sam_ldb,
134 secret_state->secret_dn);
137 return NT_STATUS_INVALID_HANDLE;
140 ZERO_STRUCTP(r->out.handle);
143 } else if (h->wire_handle.handle_type == LSA_HANDLE_TRUSTED_DOMAIN) {
144 struct lsa_trusted_domain_state *trusted_domain_state = h->data;
145 ret = ldb_transaction_start(trusted_domain_state->policy->sam_ldb);
147 return NT_STATUS_INTERNAL_DB_CORRUPTION;
150 ret = ldb_delete(trusted_domain_state->policy->sam_ldb,
151 trusted_domain_state->trusted_domain_dn);
153 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
154 return NT_STATUS_INVALID_HANDLE;
157 if (trusted_domain_state->trusted_domain_user_dn) {
158 ret = ldb_delete(trusted_domain_state->policy->sam_ldb,
159 trusted_domain_state->trusted_domain_user_dn);
161 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
162 return NT_STATUS_INVALID_HANDLE;
166 ret = ldb_transaction_commit(trusted_domain_state->policy->sam_ldb);
168 return NT_STATUS_INTERNAL_DB_CORRUPTION;
171 ZERO_STRUCTP(r->out.handle);
174 } else if (h->wire_handle.handle_type == LSA_HANDLE_ACCOUNT) {
175 struct lsa_RightSet *rights;
176 struct lsa_account_state *astate;
177 struct lsa_EnumAccountRights r2;
180 rights = talloc(mem_ctx, struct lsa_RightSet);
182 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
186 r2.in.handle = &astate->policy->handle->wire_handle;
187 r2.in.sid = astate->account_sid;
188 r2.out.rights = rights;
190 status = dcesrv_lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
191 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
195 if (!NT_STATUS_IS_OK(status)) {
199 status = dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
200 LDB_FLAG_MOD_DELETE, astate->account_sid,
202 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
206 if (!NT_STATUS_IS_OK(status)) {
210 ZERO_STRUCTP(r->out.handle);
213 return NT_STATUS_INVALID_HANDLE;
220 static NTSTATUS dcesrv_lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
221 struct lsa_EnumPrivs *r)
223 struct dcesrv_handle *h;
224 struct lsa_policy_state *state;
226 const char *privname;
228 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
232 i = *r->in.resume_handle;
235 while ((privname = sec_privilege_name(i)) &&
236 r->out.privs->count < r->in.max_count) {
237 struct lsa_PrivEntry *e;
239 r->out.privs->privs = talloc_realloc(r->out.privs,
241 struct lsa_PrivEntry,
242 r->out.privs->count+1);
243 if (r->out.privs->privs == NULL) {
244 return NT_STATUS_NO_MEMORY;
246 e = &r->out.privs->privs[r->out.privs->count];
249 e->name.string = privname;
250 r->out.privs->count++;
254 *r->out.resume_handle = i;
263 static NTSTATUS dcesrv_lsa_QuerySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
264 struct lsa_QuerySecurity *r)
266 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
273 static NTSTATUS dcesrv_lsa_SetSecObj(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
274 struct lsa_SetSecObj *r)
276 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
283 static NTSTATUS dcesrv_lsa_ChangePassword(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
284 struct lsa_ChangePassword *r)
286 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
290 dssetup_DsRoleGetPrimaryDomainInformation
292 This is not an LSA call, but is the only call left on the DSSETUP
293 pipe (after the pipe was truncated), and needs lsa_get_policy_state
295 static WERROR dcesrv_dssetup_DsRoleGetPrimaryDomainInformation(struct dcesrv_call_state *dce_call,
297 struct dssetup_DsRoleGetPrimaryDomainInformation *r)
299 union dssetup_DsRoleInfo *info;
301 info = talloc(mem_ctx, union dssetup_DsRoleInfo);
302 W_ERROR_HAVE_NO_MEMORY(info);
304 switch (r->in.level) {
305 case DS_ROLE_BASIC_INFORMATION:
307 enum dssetup_DsRole role = DS_ROLE_STANDALONE_SERVER;
309 const char *domain = NULL;
310 const char *dns_domain = NULL;
311 const char *forest = NULL;
312 struct GUID domain_guid;
313 struct lsa_policy_state *state;
315 NTSTATUS status = dcesrv_lsa_get_policy_state(dce_call, mem_ctx, &state);
316 if (!NT_STATUS_IS_OK(status)) {
317 return ntstatus_to_werror(status);
320 ZERO_STRUCT(domain_guid);
322 switch (lp_server_role(dce_call->conn->dce_ctx->lp_ctx)) {
323 case ROLE_STANDALONE:
324 role = DS_ROLE_STANDALONE_SERVER;
326 case ROLE_DOMAIN_MEMBER:
327 role = DS_ROLE_MEMBER_SERVER;
329 case ROLE_DOMAIN_CONTROLLER:
330 if (samdb_is_pdc(state->sam_ldb)) {
331 role = DS_ROLE_PRIMARY_DC;
333 role = DS_ROLE_BACKUP_DC;
338 switch (lp_server_role(dce_call->conn->dce_ctx->lp_ctx)) {
339 case ROLE_STANDALONE:
340 domain = talloc_strdup(mem_ctx, lp_workgroup(dce_call->conn->dce_ctx->lp_ctx));
341 W_ERROR_HAVE_NO_MEMORY(domain);
343 case ROLE_DOMAIN_MEMBER:
344 domain = talloc_strdup(mem_ctx, lp_workgroup(dce_call->conn->dce_ctx->lp_ctx));
345 W_ERROR_HAVE_NO_MEMORY(domain);
346 /* TODO: what is with dns_domain and forest and guid? */
348 case ROLE_DOMAIN_CONTROLLER:
349 flags = DS_ROLE_PRIMARY_DS_RUNNING;
351 if (state->mixed_domain == 1) {
352 flags |= DS_ROLE_PRIMARY_DS_MIXED_MODE;
355 domain = state->domain_name;
356 dns_domain = state->domain_dns;
357 forest = state->forest_dns;
359 domain_guid = state->domain_guid;
360 flags |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
364 info->basic.role = role;
365 info->basic.flags = flags;
366 info->basic.domain = domain;
367 info->basic.dns_domain = dns_domain;
368 info->basic.forest = forest;
369 info->basic.domain_guid = domain_guid;
374 case DS_ROLE_UPGRADE_STATUS:
376 info->upgrade.upgrading = DS_ROLE_NOT_UPGRADING;
377 info->upgrade.previous_role = DS_ROLE_PREVIOUS_UNKNOWN;
382 case DS_ROLE_OP_STATUS:
384 info->opstatus.status = DS_ROLE_OP_IDLE;
390 return WERR_INVALID_PARAM;
393 return WERR_INVALID_PARAM;
398 fill in the AccountDomain info
400 static NTSTATUS dcesrv_lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
401 struct lsa_DomainInfo *info)
403 info->name.string = state->domain_name;
404 info->sid = state->domain_sid;
410 fill in the DNS domain info
412 static NTSTATUS dcesrv_lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
413 struct lsa_DnsDomainInfo *info)
415 info->name.string = state->domain_name;
416 info->sid = state->domain_sid;
417 info->dns_domain.string = state->domain_dns;
418 info->dns_forest.string = state->forest_dns;
419 info->domain_guid = state->domain_guid;
427 static NTSTATUS dcesrv_lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
428 struct lsa_QueryInfoPolicy2 *r)
430 struct lsa_policy_state *state;
431 struct dcesrv_handle *h;
435 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
439 r->out.info = talloc(mem_ctx, union lsa_PolicyInformation);
441 return NT_STATUS_NO_MEMORY;
444 ZERO_STRUCTP(r->out.info);
446 switch (r->in.level) {
447 case LSA_POLICY_INFO_DOMAIN:
448 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
449 return dcesrv_lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
451 case LSA_POLICY_INFO_DNS:
452 return dcesrv_lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
453 case LSA_POLICY_INFO_DB:
454 case LSA_POLICY_INFO_AUDIT_FULL_SET:
455 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
456 return NT_STATUS_INVALID_PARAMETER;
459 return NT_STATUS_INVALID_INFO_CLASS;
465 static NTSTATUS dcesrv_lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
466 struct lsa_QueryInfoPolicy *r)
468 struct lsa_QueryInfoPolicy2 r2;
471 r2.in.handle = r->in.handle;
472 r2.in.level = r->in.level;
474 status = dcesrv_lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
476 r->out.info = r2.out.info;
484 static NTSTATUS dcesrv_lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
485 struct lsa_SetInfoPolicy *r)
487 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
494 static NTSTATUS dcesrv_lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
495 struct lsa_ClearAuditLog *r)
497 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
504 This call does not seem to have any long-term effects, hence no database operations
506 static NTSTATUS dcesrv_lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
507 struct lsa_CreateAccount *r)
509 struct lsa_account_state *astate;
511 struct lsa_policy_state *state;
512 struct dcesrv_handle *h, *ah;
514 ZERO_STRUCTP(r->out.acct_handle);
516 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
520 astate = talloc(dce_call->conn, struct lsa_account_state);
521 if (astate == NULL) {
522 return NT_STATUS_NO_MEMORY;
525 astate->account_sid = dom_sid_dup(astate, r->in.sid);
526 if (astate->account_sid == NULL) {
528 return NT_STATUS_NO_MEMORY;
531 astate->policy = talloc_reference(astate, state);
532 astate->access_mask = r->in.access_mask;
534 ah = dcesrv_handle_new(dce_call->context, LSA_HANDLE_ACCOUNT);
537 return NT_STATUS_NO_MEMORY;
540 ah->data = talloc_steal(ah, astate);
542 *r->out.acct_handle = ah->wire_handle;
551 static NTSTATUS dcesrv_lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
552 struct lsa_EnumAccounts *r)
554 struct dcesrv_handle *h;
555 struct lsa_policy_state *state;
557 struct ldb_message **res;
558 const char * const attrs[] = { "objectSid", NULL};
561 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
565 /* NOTE: This call must only return accounts that have at least
568 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
569 "(&(objectSid=*)(privilege=*))");
571 return NT_STATUS_NO_SUCH_USER;
574 if (*r->in.resume_handle >= ret) {
575 return NT_STATUS_NO_MORE_ENTRIES;
578 count = ret - *r->in.resume_handle;
579 if (count > r->in.num_entries) {
580 count = r->in.num_entries;
584 return NT_STATUS_NO_MORE_ENTRIES;
587 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, count);
588 if (r->out.sids->sids == NULL) {
589 return NT_STATUS_NO_MEMORY;
592 for (i=0;i<count;i++) {
593 r->out.sids->sids[i].sid =
594 samdb_result_dom_sid(r->out.sids->sids,
595 res[i + *r->in.resume_handle],
597 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
600 r->out.sids->num_sids = count;
601 *r->out.resume_handle = count + *r->in.resume_handle;
609 lsa_CreateTrustedDomainEx2
611 static NTSTATUS dcesrv_lsa_CreateTrustedDomain_base(struct dcesrv_call_state *dce_call,
613 struct lsa_CreateTrustedDomainEx2 *r,
616 struct dcesrv_handle *policy_handle;
617 struct lsa_policy_state *policy_state;
618 struct lsa_trusted_domain_state *trusted_domain_state;
619 struct dcesrv_handle *handle;
620 struct ldb_message **msgs, *msg, *msg_user;
621 const char *attrs[] = {
624 const char *netbios_name;
625 const char *dns_name;
627 DATA_BLOB session_key = data_blob(NULL, 0);
628 DATA_BLOB trustAuthIncoming, trustAuthOutgoing, auth_blob;
629 struct trustAuthInAndOutBlob auth_struct;
632 enum ndr_err_code ndr_err;
634 DCESRV_PULL_HANDLE(policy_handle, r->in.policy_handle, LSA_HANDLE_POLICY);
635 ZERO_STRUCTP(r->out.trustdom_handle);
637 policy_state = policy_handle->data;
639 nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
640 if (!NT_STATUS_IS_OK(nt_status)) {
644 netbios_name = r->in.info->netbios_name.string;
646 return NT_STATUS_INVALID_PARAMETER;
649 dns_name = r->in.info->domain_name.string;
651 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
652 if (!trusted_domain_state) {
653 return NT_STATUS_NO_MEMORY;
655 trusted_domain_state->policy = policy_state;
657 if (strcasecmp(netbios_name, "BUILTIN") == 0
658 || (dns_name && strcasecmp(dns_name, "BUILTIN") == 0)
659 || (dom_sid_in_domain(policy_state->builtin_sid, r->in.info->sid))) {
660 return NT_STATUS_INVALID_PARAMETER;;
663 if (strcasecmp(netbios_name, policy_state->domain_name) == 0
664 || strcasecmp(netbios_name, policy_state->domain_dns) == 0
665 || (dns_name && strcasecmp(dns_name, policy_state->domain_dns) == 0)
666 || (dns_name && strcasecmp(dns_name, policy_state->domain_name) == 0)
667 || (dom_sid_equal(policy_state->domain_sid, r->in.info->sid))) {
668 return NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED;
671 /* While this is a REF pointer, some of the functions that wrap this don't provide this */
672 if (op == NDR_LSA_CREATETRUSTEDDOMAIN) {
673 /* No secrets are created at this time, for this function */
674 auth_struct.outgoing.count = 0;
675 auth_struct.incoming.count = 0;
677 auth_blob = data_blob_const(r->in.auth_info->auth_blob.data, r->in.auth_info->auth_blob.size);
678 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
679 ndr_err = ndr_pull_struct_blob(&auth_blob, mem_ctx,
680 lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx),
682 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInAndOutBlob);
683 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
684 return NT_STATUS_INVALID_PARAMETER;
688 if (auth_struct.incoming.count) {
689 ndr_err = ndr_push_struct_blob(&trustAuthIncoming, mem_ctx,
690 lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx),
691 &auth_struct.incoming,
692 (ndr_push_flags_fn_t)ndr_push_trustAuthInOutBlob);
693 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
694 return NT_STATUS_INVALID_PARAMETER;
697 trustAuthIncoming = data_blob(NULL, 0);
700 if (auth_struct.outgoing.count) {
701 ndr_err = ndr_push_struct_blob(&trustAuthOutgoing, mem_ctx,
702 lp_iconv_convenience(dce_call->conn->dce_ctx->lp_ctx),
703 &auth_struct.outgoing,
704 (ndr_push_flags_fn_t)ndr_push_trustAuthInOutBlob);
705 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
706 return NT_STATUS_INVALID_PARAMETER;
709 trustAuthOutgoing = data_blob(NULL, 0);
712 ret = ldb_transaction_start(policy_state->sam_ldb);
713 if (ret != LDB_SUCCESS) {
714 return NT_STATUS_INTERNAL_DB_CORRUPTION;
718 char *dns_encoded = ldb_binary_encode_string(mem_ctx, netbios_name);
719 char *netbios_encoded = ldb_binary_encode_string(mem_ctx, netbios_name);
720 /* search for the trusted_domain record */
721 ret = gendb_search(policy_state->sam_ldb,
722 mem_ctx, policy_state->system_dn, &msgs, attrs,
723 "(&(|(flatname=%s)(cn=%s)(trustPartner=%s)(flatname=%s)(cn=%s)(trustPartner=%s))(objectclass=trustedDomain))",
724 dns_encoded, dns_encoded, dns_encoded, netbios_encoded, netbios_encoded, netbios_encoded);
726 ldb_transaction_cancel(policy_state->sam_ldb);
727 return NT_STATUS_OBJECT_NAME_COLLISION;
730 char *netbios_encoded = ldb_binary_encode_string(mem_ctx, netbios_name);
731 /* search for the trusted_domain record */
732 ret = gendb_search(policy_state->sam_ldb,
733 mem_ctx, policy_state->system_dn, &msgs, attrs,
734 "(&(|(flatname=%s)(cn=%s)(trustPartner=%s))(objectclass=trustedDomain))",
735 netbios_encoded, netbios_encoded, netbios_encoded);
737 ldb_transaction_cancel(policy_state->sam_ldb);
738 return NT_STATUS_OBJECT_NAME_COLLISION;
743 ldb_transaction_cancel(policy_state->sam_ldb);
744 return NT_STATUS_INTERNAL_DB_CORRUPTION;
747 name = dns_name ? dns_name : netbios_name;
749 msg = ldb_msg_new(mem_ctx);
751 return NT_STATUS_NO_MEMORY;
754 msg->dn = ldb_dn_copy(mem_ctx, policy_state->system_dn);
755 if ( ! ldb_dn_add_child_fmt(msg->dn, "cn=%s", name)) {
756 ldb_transaction_cancel(policy_state->sam_ldb);
757 return NT_STATUS_NO_MEMORY;
760 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "flatname", netbios_name);
762 if (r->in.info->sid) {
763 const char *sid_string = dom_sid_string(mem_ctx, r->in.info->sid);
765 ldb_transaction_cancel(policy_state->sam_ldb);
766 return NT_STATUS_NO_MEMORY;
769 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "securityIdentifier", sid_string);
772 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "objectClass", "trustedDomain");
774 samdb_msg_add_int(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "trustType", r->in.info->trust_type);
776 samdb_msg_add_int(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "trustAttributes", r->in.info->trust_attributes);
778 samdb_msg_add_int(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "trustDirection", r->in.info->trust_direction);
781 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "trustPartner", dns_name);
784 if (trustAuthIncoming.data) {
785 ret = ldb_msg_add_value(msg, "trustAuthIncoming", &trustAuthIncoming, NULL);
786 if (ret != LDB_SUCCESS) {
787 ldb_transaction_cancel(policy_state->sam_ldb);
788 return NT_STATUS_NO_MEMORY;
791 if (trustAuthOutgoing.data) {
792 ret = ldb_msg_add_value(msg, "trustAuthOutgoing", &trustAuthOutgoing, NULL);
793 if (ret != LDB_SUCCESS) {
794 ldb_transaction_cancel(policy_state->sam_ldb);
795 return NT_STATUS_NO_MEMORY;
799 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msg->dn);
801 /* create the trusted_domain */
802 ret = ldb_add(trusted_domain_state->policy->sam_ldb, msg);
806 case LDB_ERR_ENTRY_ALREADY_EXISTS:
807 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
808 DEBUG(0,("Failed to create trusted domain record %s: %s\n",
809 ldb_dn_get_linearized(msg->dn),
810 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
811 return NT_STATUS_DOMAIN_EXISTS;
812 case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
813 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
814 DEBUG(0,("Failed to create trusted domain record %s: %s\n",
815 ldb_dn_get_linearized(msg->dn),
816 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
817 return NT_STATUS_ACCESS_DENIED;
819 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
820 DEBUG(0,("Failed to create user record %s: %s\n",
821 ldb_dn_get_linearized(msg->dn),
822 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
823 return NT_STATUS_INTERNAL_DB_CORRUPTION;
826 if (r->in.info->trust_direction & LSA_TRUST_DIRECTION_INBOUND) {
827 msg_user = ldb_msg_new(mem_ctx);
829 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
830 return NT_STATUS_NO_MEMORY;
833 /* Inbound trusts must also create a cn=users object to match */
835 trusted_domain_state->trusted_domain_user_dn = msg_user->dn
836 = ldb_dn_copy(trusted_domain_state, policy_state->domain_dn);
837 if ( ! ldb_dn_add_child_fmt(msg_user->dn, "cn=users")) {
838 ldb_transaction_cancel(policy_state->sam_ldb);
839 return NT_STATUS_NO_MEMORY;
842 if ( ! ldb_dn_add_child_fmt(msg_user->dn, "cn=%s", netbios_name)) {
843 ldb_transaction_cancel(policy_state->sam_ldb);
844 return NT_STATUS_NO_MEMORY;
847 ldb_msg_add_string(msg_user, "objectClass", "user");
849 ldb_msg_add_steal_string(msg_user, "samAccountName",
850 talloc_asprintf(mem_ctx, "%s$", netbios_name));
852 if (samdb_msg_add_uint(trusted_domain_state->policy->sam_ldb, mem_ctx, msg_user,
853 "userAccountControl",
854 UF_INTERDOMAIN_TRUST_ACCOUNT) != 0) {
855 ldb_transaction_cancel(policy_state->sam_ldb);
856 return NT_STATUS_NO_MEMORY;
859 if (auth_struct.incoming.count) {
861 for (i=0; i < auth_struct.incoming.count; i++ ) {
862 if (auth_struct.incoming.current->array[i].AuthType == TRUST_AUTH_TYPE_NT4OWF) {
863 samdb_msg_add_hash(trusted_domain_state->policy->sam_ldb,
864 mem_ctx, msg_user, "unicodePwd",
865 &auth_struct.incoming.current->array[i].AuthInfo.nt4owf.password);
866 } else if (auth_struct.incoming.current->array[i].AuthType == TRUST_AUTH_TYPE_CLEAR) {
867 struct samr_Password hash;
869 . We cannot do this, as windows chooses to send in random passwords here, that won't convert to UTF8
870 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb,
871 mem_ctx, msg_user, "userPassword",
872 auth_struct.incoming.current->array[i].AuthInfo.clear.password);
874 mdfour(hash.hash, auth_struct.incoming.current->array[i].AuthInfo.clear.password,
875 auth_struct.incoming.current->array[i].AuthInfo.clear.size);
876 samdb_msg_add_hash(trusted_domain_state->policy->sam_ldb,
877 mem_ctx, msg_user, "unicodePwd",
883 /* create the cn=users trusted_domain account */
884 ret = ldb_add(trusted_domain_state->policy->sam_ldb, msg_user);
888 case LDB_ERR_ENTRY_ALREADY_EXISTS:
889 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
890 DEBUG(0,("Failed to create trusted domain record %s: %s\n",
891 ldb_dn_get_linearized(msg_user->dn),
892 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
893 return NT_STATUS_DOMAIN_EXISTS;
894 case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS:
895 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
896 DEBUG(0,("Failed to create trusted domain record %s: %s\n",
897 ldb_dn_get_linearized(msg_user->dn),
898 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
899 return NT_STATUS_ACCESS_DENIED;
901 ldb_transaction_cancel(trusted_domain_state->policy->sam_ldb);
902 DEBUG(0,("Failed to create user record %s: %s\n",
903 ldb_dn_get_linearized(msg_user->dn),
904 ldb_errstring(trusted_domain_state->policy->sam_ldb)));
905 return NT_STATUS_INTERNAL_DB_CORRUPTION;
909 ret = ldb_transaction_commit(policy_state->sam_ldb);
910 if (ret != LDB_SUCCESS) {
911 return NT_STATUS_INTERNAL_DB_CORRUPTION;
914 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
916 return NT_STATUS_NO_MEMORY;
919 handle->data = talloc_steal(handle, trusted_domain_state);
921 trusted_domain_state->access_mask = r->in.access_mask;
922 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
924 *r->out.trustdom_handle = handle->wire_handle;
930 lsa_CreateTrustedDomainEx2
932 static NTSTATUS dcesrv_lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
934 struct lsa_CreateTrustedDomainEx2 *r)
936 return dcesrv_lsa_CreateTrustedDomain_base(dce_call, mem_ctx, r, NDR_LSA_CREATETRUSTEDDOMAINEX2);
939 lsa_CreateTrustedDomainEx
941 static NTSTATUS dcesrv_lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
943 struct lsa_CreateTrustedDomainEx *r)
945 struct lsa_CreateTrustedDomainEx2 r2;
947 r2.in.policy_handle = r->in.policy_handle;
948 r2.in.info = r->in.info;
949 r2.in.auth_info = r->in.auth_info;
950 r2.out.trustdom_handle = r->out.trustdom_handle;
951 return dcesrv_lsa_CreateTrustedDomain_base(dce_call, mem_ctx, &r2, NDR_LSA_CREATETRUSTEDDOMAINEX);
955 lsa_CreateTrustedDomain
957 static NTSTATUS dcesrv_lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
958 struct lsa_CreateTrustedDomain *r)
960 struct lsa_CreateTrustedDomainEx2 r2;
962 r2.in.policy_handle = r->in.policy_handle;
963 r2.in.info = talloc(mem_ctx, struct lsa_TrustDomainInfoInfoEx);
965 return NT_STATUS_NO_MEMORY;
968 r2.in.info->domain_name.string = NULL;
969 r2.in.info->netbios_name = r->in.info->name;
970 r2.in.info->sid = r->in.info->sid;
971 r2.in.info->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND;
972 r2.in.info->trust_type = LSA_TRUST_TYPE_DOWNLEVEL;
973 r2.in.info->trust_attributes = 0;
975 r2.in.access_mask = r->in.access_mask;
976 r2.out.trustdom_handle = r->out.trustdom_handle;
978 return dcesrv_lsa_CreateTrustedDomain_base(dce_call, mem_ctx, &r2, NDR_LSA_CREATETRUSTEDDOMAIN);
983 lsa_OpenTrustedDomain
985 static NTSTATUS dcesrv_lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
986 struct lsa_OpenTrustedDomain *r)
988 struct dcesrv_handle *policy_handle;
990 struct lsa_policy_state *policy_state;
991 struct lsa_trusted_domain_state *trusted_domain_state;
992 struct dcesrv_handle *handle;
993 struct ldb_message **msgs;
994 const char *attrs[] = {
1000 const char *sid_string;
1003 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1004 ZERO_STRUCTP(r->out.trustdom_handle);
1005 policy_state = policy_handle->data;
1007 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
1008 if (!trusted_domain_state) {
1009 return NT_STATUS_NO_MEMORY;
1011 trusted_domain_state->policy = policy_state;
1013 sid_string = dom_sid_string(mem_ctx, r->in.sid);
1015 return NT_STATUS_NO_MEMORY;
1018 /* search for the trusted_domain record */
1019 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
1020 mem_ctx, policy_state->system_dn, &msgs, attrs,
1021 "(&(securityIdentifier=%s)(objectclass=trustedDomain))",
1024 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1028 DEBUG(0,("Found %d records matching DN %s\n", ret,
1029 ldb_dn_get_linearized(policy_state->system_dn)));
1030 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1033 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
1035 trusted_domain_state->trusted_domain_user_dn = NULL;
1037 if (ldb_msg_find_attr_as_int(msgs[0], "trustDirection", 0) & LSA_TRUST_DIRECTION_INBOUND) {
1038 const char *flatname = ldb_binary_encode_string(mem_ctx, ldb_msg_find_attr_as_string(msgs[0], "flatname", NULL));
1039 /* search for the trusted_domain record */
1040 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
1041 mem_ctx, policy_state->domain_dn, &msgs, attrs,
1042 "(&(samaccountname=%s$)(objectclass=user)(userAccountControl:1.2.840.113556.1.4.803:=%d))",
1043 flatname, UF_INTERDOMAIN_TRUST_ACCOUNT);
1045 trusted_domain_state->trusted_domain_user_dn = talloc_steal(trusted_domain_state, msgs[0]->dn);
1048 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
1050 return NT_STATUS_NO_MEMORY;
1053 handle->data = talloc_steal(handle, trusted_domain_state);
1055 trusted_domain_state->access_mask = r->in.access_mask;
1056 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
1058 *r->out.trustdom_handle = handle->wire_handle;
1060 return NT_STATUS_OK;
1065 lsa_OpenTrustedDomainByName
1067 static NTSTATUS dcesrv_lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
1068 TALLOC_CTX *mem_ctx,
1069 struct lsa_OpenTrustedDomainByName *r)
1071 struct dcesrv_handle *policy_handle;
1073 struct lsa_policy_state *policy_state;
1074 struct lsa_trusted_domain_state *trusted_domain_state;
1075 struct dcesrv_handle *handle;
1076 struct ldb_message **msgs;
1077 const char *attrs[] = {
1083 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1084 ZERO_STRUCTP(r->out.trustdom_handle);
1085 policy_state = policy_handle->data;
1087 if (!r->in.name.string) {
1088 return NT_STATUS_INVALID_PARAMETER;
1091 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
1092 if (!trusted_domain_state) {
1093 return NT_STATUS_NO_MEMORY;
1095 trusted_domain_state->policy = policy_state;
1097 /* search for the trusted_domain record */
1098 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
1099 mem_ctx, policy_state->system_dn, &msgs, attrs,
1100 "(&(flatname=%s)(objectclass=trustedDomain))",
1101 ldb_binary_encode_string(mem_ctx, r->in.name.string));
1103 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1107 DEBUG(0,("Found %d records matching DN %s\n", ret,
1108 ldb_dn_get_linearized(policy_state->system_dn)));
1109 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1112 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
1114 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
1116 return NT_STATUS_NO_MEMORY;
1119 handle->data = talloc_steal(handle, trusted_domain_state);
1121 trusted_domain_state->access_mask = r->in.access_mask;
1122 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
1124 *r->out.trustdom_handle = handle->wire_handle;
1126 return NT_STATUS_OK;
1132 lsa_SetTrustedDomainInfo
1134 static NTSTATUS dcesrv_lsa_SetTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1135 struct lsa_SetTrustedDomainInfo *r)
1137 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1143 lsa_SetInfomrationTrustedDomain
1145 static NTSTATUS dcesrv_lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call,
1146 TALLOC_CTX *mem_ctx,
1147 struct lsa_SetInformationTrustedDomain *r)
1149 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1154 lsa_DeleteTrustedDomain
1156 static NTSTATUS dcesrv_lsa_DeleteTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1157 struct lsa_DeleteTrustedDomain *r)
1160 struct lsa_OpenTrustedDomain open;
1161 struct lsa_DeleteObject delete;
1162 struct dcesrv_handle *h;
1164 open.in.handle = r->in.handle;
1165 open.in.sid = r->in.dom_sid;
1166 open.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1167 open.out.trustdom_handle = talloc(mem_ctx, struct policy_handle);
1168 if (!open.out.trustdom_handle) {
1169 return NT_STATUS_NO_MEMORY;
1171 status = dcesrv_lsa_OpenTrustedDomain(dce_call, mem_ctx, &open);
1172 if (!NT_STATUS_IS_OK(status)) {
1176 DCESRV_PULL_HANDLE(h, open.out.trustdom_handle, DCESRV_HANDLE_ANY);
1177 talloc_steal(mem_ctx, h);
1179 delete.in.handle = open.out.trustdom_handle;
1180 delete.out.handle = open.out.trustdom_handle;
1181 status = dcesrv_lsa_DeleteObject(dce_call, mem_ctx, &delete);
1182 if (!NT_STATUS_IS_OK(status)) {
1185 return NT_STATUS_OK;
1188 static NTSTATUS fill_trust_domain_ex(TALLOC_CTX *mem_ctx,
1189 struct ldb_message *msg,
1190 struct lsa_TrustDomainInfoInfoEx *info_ex)
1192 info_ex->domain_name.string
1193 = ldb_msg_find_attr_as_string(msg, "trustPartner", NULL);
1194 info_ex->netbios_name.string
1195 = ldb_msg_find_attr_as_string(msg, "flatname", NULL);
1197 = samdb_result_dom_sid(mem_ctx, msg, "securityIdentifier");
1198 info_ex->trust_direction
1199 = ldb_msg_find_attr_as_int(msg, "trustDirection", 0);
1201 = ldb_msg_find_attr_as_int(msg, "trustType", 0);
1202 info_ex->trust_attributes
1203 = ldb_msg_find_attr_as_int(msg, "trustAttributes", 0);
1204 return NT_STATUS_OK;
1208 lsa_QueryTrustedDomainInfo
1210 static NTSTATUS dcesrv_lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1211 struct lsa_QueryTrustedDomainInfo *r)
1213 struct dcesrv_handle *h;
1214 struct lsa_trusted_domain_state *trusted_domain_state;
1215 struct ldb_message *msg;
1217 struct ldb_message **res;
1218 const char *attrs[] = {
1221 "securityIdentifier",
1225 "msDs-supportedEncryptionTypes",
1229 DCESRV_PULL_HANDLE(h, r->in.trustdom_handle, LSA_HANDLE_TRUSTED_DOMAIN);
1231 trusted_domain_state = h->data;
1233 /* pull all the user attributes */
1234 ret = gendb_search_dn(trusted_domain_state->policy->sam_ldb, mem_ctx,
1235 trusted_domain_state->trusted_domain_dn, &res, attrs);
1237 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1241 r->out.info = talloc(mem_ctx, union lsa_TrustedDomainInfo);
1243 return NT_STATUS_NO_MEMORY;
1245 switch (r->in.level) {
1246 case LSA_TRUSTED_DOMAIN_INFO_NAME:
1247 r->out.info->name.netbios_name.string
1248 = samdb_result_string(msg, "flatname", NULL);
1250 case LSA_TRUSTED_DOMAIN_INFO_POSIX_OFFSET:
1251 r->out.info->posix_offset.posix_offset
1252 = samdb_result_uint(msg, "posixOffset", 0);
1254 #if 0 /* Win2k3 doesn't implement this */
1255 case LSA_TRUSTED_DOMAIN_INFO_BASIC:
1256 r->out.info->info_basic.netbios_name.string
1257 = ldb_msg_find_attr_as_string(msg, "flatname", NULL);
1258 r->out.info->info_basic.sid
1259 = samdb_result_dom_sid(mem_ctx, msg, "securityIdentifier");
1262 case LSA_TRUSTED_DOMAIN_INFO_INFO_EX:
1263 return fill_trust_domain_ex(mem_ctx, msg, &r->out.info->info_ex);
1265 case LSA_TRUSTED_DOMAIN_INFO_FULL_INFO:
1266 ZERO_STRUCT(r->out.info->full_info);
1267 return fill_trust_domain_ex(mem_ctx, msg, &r->out.info->full_info.info_ex);
1269 case LSA_TRUSTED_DOMAIN_INFO_FULL_INFO_2_INTERNAL:
1270 ZERO_STRUCT(r->out.info->full_info2_internal);
1271 r->out.info->full_info2_internal.posix_offset.posix_offset
1272 = samdb_result_uint(msg, "posixOffset", 0);
1273 return fill_trust_domain_ex(mem_ctx, msg, &r->out.info->full_info2_internal.info.info_ex);
1275 case LSA_TRUSTED_DOMAIN_SUPPORTED_ENCRTYPION_TYPES:
1276 r->out.info->enc_types.enc_types
1277 = samdb_result_uint(msg, "msDs-supportedEncryptionTypes", KERB_ENCTYPE_RC4_HMAC_MD5);
1280 case LSA_TRUSTED_DOMAIN_INFO_CONTROLLERS:
1281 case LSA_TRUSTED_DOMAIN_INFO_INFO_EX2_INTERNAL:
1282 /* oops, we don't want to return the info after all */
1283 talloc_free(r->out.info);
1285 return NT_STATUS_INVALID_PARAMETER;
1287 /* oops, we don't want to return the info after all */
1288 talloc_free(r->out.info);
1290 return NT_STATUS_INVALID_INFO_CLASS;
1293 return NT_STATUS_OK;
1298 lsa_QueryTrustedDomainInfoBySid
1300 static NTSTATUS dcesrv_lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1301 struct lsa_QueryTrustedDomainInfoBySid *r)
1304 struct lsa_OpenTrustedDomain open;
1305 struct lsa_QueryTrustedDomainInfo query;
1306 struct dcesrv_handle *h;
1307 open.in.handle = r->in.handle;
1308 open.in.sid = r->in.dom_sid;
1309 open.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1310 open.out.trustdom_handle = talloc(mem_ctx, struct policy_handle);
1311 if (!open.out.trustdom_handle) {
1312 return NT_STATUS_NO_MEMORY;
1314 status = dcesrv_lsa_OpenTrustedDomain(dce_call, mem_ctx, &open);
1315 if (!NT_STATUS_IS_OK(status)) {
1319 /* Ensure this handle goes away at the end of this call */
1320 DCESRV_PULL_HANDLE(h, open.out.trustdom_handle, DCESRV_HANDLE_ANY);
1321 talloc_steal(mem_ctx, h);
1323 query.in.trustdom_handle = open.out.trustdom_handle;
1324 query.in.level = r->in.level;
1325 status = dcesrv_lsa_QueryTrustedDomainInfo(dce_call, mem_ctx, &query);
1326 if (!NT_STATUS_IS_OK(status)) {
1330 r->out.info = query.out.info;
1331 return NT_STATUS_OK;
1335 lsa_SetTrustedDomainInfoByName
1337 static NTSTATUS dcesrv_lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1338 TALLOC_CTX *mem_ctx,
1339 struct lsa_SetTrustedDomainInfoByName *r)
1341 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1345 lsa_QueryTrustedDomainInfoByName
1347 static NTSTATUS dcesrv_lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1348 TALLOC_CTX *mem_ctx,
1349 struct lsa_QueryTrustedDomainInfoByName *r)
1352 struct lsa_OpenTrustedDomainByName open;
1353 struct lsa_QueryTrustedDomainInfo query;
1354 struct dcesrv_handle *h;
1355 open.in.handle = r->in.handle;
1356 open.in.name = r->in.trusted_domain;
1357 open.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1358 open.out.trustdom_handle = talloc(mem_ctx, struct policy_handle);
1359 if (!open.out.trustdom_handle) {
1360 return NT_STATUS_NO_MEMORY;
1362 status = dcesrv_lsa_OpenTrustedDomainByName(dce_call, mem_ctx, &open);
1363 if (!NT_STATUS_IS_OK(status)) {
1367 /* Ensure this handle goes away at the end of this call */
1368 DCESRV_PULL_HANDLE(h, open.out.trustdom_handle, DCESRV_HANDLE_ANY);
1369 talloc_steal(mem_ctx, h);
1371 query.in.trustdom_handle = open.out.trustdom_handle;
1372 query.in.level = r->in.level;
1373 status = dcesrv_lsa_QueryTrustedDomainInfo(dce_call, mem_ctx, &query);
1374 if (!NT_STATUS_IS_OK(status)) {
1378 r->out.info = query.out.info;
1379 return NT_STATUS_OK;
1383 lsa_CloseTrustedDomainEx
1385 static NTSTATUS dcesrv_lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
1386 TALLOC_CTX *mem_ctx,
1387 struct lsa_CloseTrustedDomainEx *r)
1389 /* The result of a bad hair day from an IDL programmer? Not
1390 * implmented in Win2k3. You should always just lsa_Close
1392 return NT_STATUS_NOT_IMPLEMENTED;
1397 comparison function for sorting lsa_DomainInformation array
1399 static int compare_DomainInfo(struct lsa_DomainInfo *e1, struct lsa_DomainInfo *e2)
1401 return strcasecmp_m(e1->name.string, e2->name.string);
1407 static NTSTATUS dcesrv_lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1408 struct lsa_EnumTrustDom *r)
1410 struct dcesrv_handle *policy_handle;
1411 struct lsa_DomainInfo *entries;
1412 struct lsa_policy_state *policy_state;
1413 struct ldb_message **domains;
1414 const char *attrs[] = {
1416 "securityIdentifier",
1423 *r->out.resume_handle = 0;
1425 r->out.domains->domains = NULL;
1426 r->out.domains->count = 0;
1428 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1430 policy_state = policy_handle->data;
1432 /* search for all users in this domain. This could possibly be cached and
1433 resumed based on resume_key */
1434 count = gendb_search(policy_state->sam_ldb, mem_ctx, policy_state->system_dn, &domains, attrs,
1435 "objectclass=trustedDomain");
1437 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1440 /* convert to lsa_TrustInformation format */
1441 entries = talloc_array(mem_ctx, struct lsa_DomainInfo, count);
1443 return NT_STATUS_NO_MEMORY;
1445 for (i=0;i<count;i++) {
1446 entries[i].sid = samdb_result_dom_sid(mem_ctx, domains[i], "securityIdentifier");
1447 entries[i].name.string = samdb_result_string(domains[i], "flatname", NULL);
1450 /* sort the results by name */
1451 qsort(entries, count, sizeof(*entries),
1452 (comparison_fn_t)compare_DomainInfo);
1454 if (*r->in.resume_handle >= count) {
1455 *r->out.resume_handle = -1;
1457 return NT_STATUS_NO_MORE_ENTRIES;
1460 /* return the rest, limit by max_size. Note that we
1461 use the w2k3 element size value of 60 */
1462 r->out.domains->count = count - *r->in.resume_handle;
1463 r->out.domains->count = MIN(r->out.domains->count,
1464 1+(r->in.max_size/LSA_ENUM_TRUST_DOMAIN_MULTIPLIER));
1466 r->out.domains->domains = entries + *r->in.resume_handle;
1467 r->out.domains->count = r->out.domains->count;
1469 if (r->out.domains->count < count - *r->in.resume_handle) {
1470 *r->out.resume_handle = *r->in.resume_handle + r->out.domains->count;
1471 return STATUS_MORE_ENTRIES;
1474 return NT_STATUS_OK;
1478 comparison function for sorting lsa_DomainInformation array
1480 static int compare_TrustDomainInfoInfoEx(struct lsa_TrustDomainInfoInfoEx *e1, struct lsa_TrustDomainInfoInfoEx *e2)
1482 return strcasecmp_m(e1->netbios_name.string, e2->netbios_name.string);
1486 lsa_EnumTrustedDomainsEx
1488 static NTSTATUS dcesrv_lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1489 struct lsa_EnumTrustedDomainsEx *r)
1491 struct dcesrv_handle *policy_handle;
1492 struct lsa_TrustDomainInfoInfoEx *entries;
1493 struct lsa_policy_state *policy_state;
1494 struct ldb_message **domains;
1495 const char *attrs[] = {
1498 "securityIdentifier",
1508 *r->out.resume_handle = 0;
1510 r->out.domains->domains = NULL;
1511 r->out.domains->count = 0;
1513 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1515 policy_state = policy_handle->data;
1517 /* search for all users in this domain. This could possibly be cached and
1518 resumed based on resume_key */
1519 count = gendb_search(policy_state->sam_ldb, mem_ctx, policy_state->system_dn, &domains, attrs,
1520 "objectclass=trustedDomain");
1522 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1525 /* convert to lsa_DomainInformation format */
1526 entries = talloc_array(mem_ctx, struct lsa_TrustDomainInfoInfoEx, count);
1528 return NT_STATUS_NO_MEMORY;
1530 for (i=0;i<count;i++) {
1531 nt_status = fill_trust_domain_ex(mem_ctx, domains[i], &entries[i]);
1532 if (!NT_STATUS_IS_OK(nt_status)) {
1537 /* sort the results by name */
1538 qsort(entries, count, sizeof(*entries),
1539 (comparison_fn_t)compare_TrustDomainInfoInfoEx);
1541 if (*r->in.resume_handle >= count) {
1542 *r->out.resume_handle = -1;
1544 return NT_STATUS_NO_MORE_ENTRIES;
1547 /* return the rest, limit by max_size. Note that we
1548 use the w2k3 element size value of 60 */
1549 r->out.domains->count = count - *r->in.resume_handle;
1550 r->out.domains->count = MIN(r->out.domains->count,
1551 1+(r->in.max_size/LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER));
1553 r->out.domains->domains = entries + *r->in.resume_handle;
1554 r->out.domains->count = r->out.domains->count;
1556 if (r->out.domains->count < count - *r->in.resume_handle) {
1557 *r->out.resume_handle = *r->in.resume_handle + r->out.domains->count;
1558 return STATUS_MORE_ENTRIES;
1561 return NT_STATUS_OK;
1568 static NTSTATUS dcesrv_lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1569 struct lsa_OpenAccount *r)
1571 struct dcesrv_handle *h, *ah;
1572 struct lsa_policy_state *state;
1573 struct lsa_account_state *astate;
1575 ZERO_STRUCTP(r->out.acct_handle);
1577 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1581 astate = talloc(dce_call->conn, struct lsa_account_state);
1582 if (astate == NULL) {
1583 return NT_STATUS_NO_MEMORY;
1586 astate->account_sid = dom_sid_dup(astate, r->in.sid);
1587 if (astate->account_sid == NULL) {
1588 talloc_free(astate);
1589 return NT_STATUS_NO_MEMORY;
1592 astate->policy = talloc_reference(astate, state);
1593 astate->access_mask = r->in.access_mask;
1595 ah = dcesrv_handle_new(dce_call->context, LSA_HANDLE_ACCOUNT);
1597 talloc_free(astate);
1598 return NT_STATUS_NO_MEMORY;
1601 ah->data = talloc_steal(ah, astate);
1603 *r->out.acct_handle = ah->wire_handle;
1605 return NT_STATUS_OK;
1610 lsa_EnumPrivsAccount
1612 static NTSTATUS dcesrv_lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
1613 TALLOC_CTX *mem_ctx,
1614 struct lsa_EnumPrivsAccount *r)
1616 struct dcesrv_handle *h;
1617 struct lsa_account_state *astate;
1619 struct ldb_message **res;
1620 const char * const attrs[] = { "privilege", NULL};
1621 struct ldb_message_element *el;
1624 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1628 r->out.privs = talloc(mem_ctx, struct lsa_PrivilegeSet);
1629 r->out.privs->count = 0;
1630 r->out.privs->unknown = 0;
1631 r->out.privs->set = NULL;
1633 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, astate->account_sid);
1634 if (sidstr == NULL) {
1635 return NT_STATUS_NO_MEMORY;
1638 ret = gendb_search(astate->policy->sam_ldb, mem_ctx, NULL, &res, attrs,
1639 "objectSid=%s", sidstr);
1641 return NT_STATUS_OK;
1644 el = ldb_msg_find_element(res[0], "privilege");
1645 if (el == NULL || el->num_values == 0) {
1646 return NT_STATUS_OK;
1649 r->out.privs->set = talloc_array(r->out.privs,
1650 struct lsa_LUIDAttribute, el->num_values);
1651 if (r->out.privs->set == NULL) {
1652 return NT_STATUS_NO_MEMORY;
1655 for (i=0;i<el->num_values;i++) {
1656 int id = sec_privilege_id((const char *)el->values[i].data);
1658 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1660 r->out.privs->set[i].attribute = 0;
1661 r->out.privs->set[i].luid.low = id;
1662 r->out.privs->set[i].luid.high = 0;
1665 r->out.privs->count = el->num_values;
1667 return NT_STATUS_OK;
1671 lsa_EnumAccountRights
1673 static NTSTATUS dcesrv_lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
1674 TALLOC_CTX *mem_ctx,
1675 struct lsa_EnumAccountRights *r)
1677 struct dcesrv_handle *h;
1678 struct lsa_policy_state *state;
1680 struct ldb_message **res;
1681 const char * const attrs[] = { "privilege", NULL};
1683 struct ldb_message_element *el;
1685 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1689 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, r->in.sid);
1690 if (sidstr == NULL) {
1691 return NT_STATUS_NO_MEMORY;
1694 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1695 "(&(objectSid=%s)(privilege=*))", sidstr);
1697 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1700 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1703 DEBUG(3, ("searching for account rights for SID: %s failed: %s",
1704 dom_sid_string(mem_ctx, r->in.sid),
1705 ldb_errstring(state->sam_ldb)));
1706 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1709 el = ldb_msg_find_element(res[0], "privilege");
1710 if (el == NULL || el->num_values == 0) {
1711 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1714 r->out.rights->count = el->num_values;
1715 r->out.rights->names = talloc_array(r->out.rights,
1716 struct lsa_StringLarge, r->out.rights->count);
1717 if (r->out.rights->names == NULL) {
1718 return NT_STATUS_NO_MEMORY;
1721 for (i=0;i<el->num_values;i++) {
1722 r->out.rights->names[i].string = (const char *)el->values[i].data;
1725 return NT_STATUS_OK;
1731 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
1733 static NTSTATUS dcesrv_lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
1734 TALLOC_CTX *mem_ctx,
1735 struct lsa_policy_state *state,
1737 struct dom_sid *sid,
1738 const struct lsa_RightSet *rights)
1741 struct ldb_message *msg;
1742 struct ldb_message_element *el;
1744 struct lsa_EnumAccountRights r2;
1746 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
1747 if (sidstr == NULL) {
1748 return NT_STATUS_NO_MEMORY;
1751 msg = ldb_msg_new(mem_ctx);
1753 return NT_STATUS_NO_MEMORY;
1756 msg->dn = samdb_search_dn(state->sam_ldb, mem_ctx,
1757 NULL, "objectSid=%s", sidstr);
1758 if (msg->dn == NULL) {
1760 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1761 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1763 status = samdb_create_foreign_security_principal(state->sam_ldb, mem_ctx,
1765 if (!NT_STATUS_IS_OK(status)) {
1768 return NT_STATUS_NO_SUCH_USER;
1771 if (ldb_msg_add_empty(msg, "privilege", ldb_flag, NULL)) {
1772 return NT_STATUS_NO_MEMORY;
1775 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1778 r2.in.handle = &state->handle->wire_handle;
1780 r2.out.rights = talloc(mem_ctx, struct lsa_RightSet);
1782 status = dcesrv_lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1783 if (!NT_STATUS_IS_OK(status)) {
1784 ZERO_STRUCTP(r2.out.rights);
1788 for (i=0;i<rights->count;i++) {
1789 if (sec_privilege_id(rights->names[i].string) == -1) {
1790 return NT_STATUS_NO_SUCH_PRIVILEGE;
1793 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1795 for (j=0;j<r2.out.rights->count;j++) {
1796 if (strcasecmp_m(r2.out.rights->names[j].string,
1797 rights->names[i].string) == 0) {
1801 if (j != r2.out.rights->count) continue;
1804 ret = ldb_msg_add_string(msg, "privilege", rights->names[i].string);
1805 if (ret != LDB_SUCCESS) {
1806 return NT_STATUS_NO_MEMORY;
1810 el = ldb_msg_find_element(msg, "privilege");
1812 return NT_STATUS_OK;
1815 ret = ldb_modify(state->sam_ldb, msg);
1817 if (ldb_flag == LDB_FLAG_MOD_DELETE && ret == LDB_ERR_NO_SUCH_ATTRIBUTE) {
1818 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1820 DEBUG(3, ("Could not %s attributes from %s: %s",
1821 ldb_flag == LDB_FLAG_MOD_DELETE ? "delete" : "add",
1822 ldb_dn_get_linearized(msg->dn), ldb_errstring(state->sam_ldb)));
1823 return NT_STATUS_UNEXPECTED_IO_ERROR;
1826 return NT_STATUS_OK;
1830 lsa_AddPrivilegesToAccount
1832 static NTSTATUS dcesrv_lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1833 struct lsa_AddPrivilegesToAccount *r)
1835 struct lsa_RightSet rights;
1836 struct dcesrv_handle *h;
1837 struct lsa_account_state *astate;
1840 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1844 rights.count = r->in.privs->count;
1845 rights.names = talloc_array(mem_ctx, struct lsa_StringLarge, rights.count);
1846 if (rights.names == NULL) {
1847 return NT_STATUS_NO_MEMORY;
1849 for (i=0;i<rights.count;i++) {
1850 int id = r->in.privs->set[i].luid.low;
1851 if (r->in.privs->set[i].luid.high) {
1852 return NT_STATUS_NO_SUCH_PRIVILEGE;
1854 rights.names[i].string = sec_privilege_name(id);
1855 if (rights.names[i].string == NULL) {
1856 return NT_STATUS_NO_SUCH_PRIVILEGE;
1860 return dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1861 LDB_FLAG_MOD_ADD, astate->account_sid,
1867 lsa_RemovePrivilegesFromAccount
1869 static NTSTATUS dcesrv_lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1870 struct lsa_RemovePrivilegesFromAccount *r)
1872 struct lsa_RightSet *rights;
1873 struct dcesrv_handle *h;
1874 struct lsa_account_state *astate;
1877 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1881 rights = talloc(mem_ctx, struct lsa_RightSet);
1883 if (r->in.remove_all == 1 &&
1884 r->in.privs == NULL) {
1885 struct lsa_EnumAccountRights r2;
1888 r2.in.handle = &astate->policy->handle->wire_handle;
1889 r2.in.sid = astate->account_sid;
1890 r2.out.rights = rights;
1892 status = dcesrv_lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1893 if (!NT_STATUS_IS_OK(status)) {
1897 return dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1898 LDB_FLAG_MOD_DELETE, astate->account_sid,
1902 if (r->in.remove_all != 0) {
1903 return NT_STATUS_INVALID_PARAMETER;
1906 rights->count = r->in.privs->count;
1907 rights->names = talloc_array(mem_ctx, struct lsa_StringLarge, rights->count);
1908 if (rights->names == NULL) {
1909 return NT_STATUS_NO_MEMORY;
1911 for (i=0;i<rights->count;i++) {
1912 int id = r->in.privs->set[i].luid.low;
1913 if (r->in.privs->set[i].luid.high) {
1914 return NT_STATUS_NO_SUCH_PRIVILEGE;
1916 rights->names[i].string = sec_privilege_name(id);
1917 if (rights->names[i].string == NULL) {
1918 return NT_STATUS_NO_SUCH_PRIVILEGE;
1922 return dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1923 LDB_FLAG_MOD_DELETE, astate->account_sid,
1929 lsa_GetQuotasForAccount
1931 static NTSTATUS dcesrv_lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1932 struct lsa_GetQuotasForAccount *r)
1934 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1939 lsa_SetQuotasForAccount
1941 static NTSTATUS dcesrv_lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1942 struct lsa_SetQuotasForAccount *r)
1944 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1949 lsa_GetSystemAccessAccount
1951 static NTSTATUS dcesrv_lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1952 struct lsa_GetSystemAccessAccount *r)
1954 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1959 lsa_SetSystemAccessAccount
1961 static NTSTATUS dcesrv_lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1962 struct lsa_SetSystemAccessAccount *r)
1964 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1971 static NTSTATUS dcesrv_lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1972 struct lsa_CreateSecret *r)
1974 struct dcesrv_handle *policy_handle;
1975 struct lsa_policy_state *policy_state;
1976 struct lsa_secret_state *secret_state;
1977 struct dcesrv_handle *handle;
1978 struct ldb_message **msgs, *msg;
1980 const char *attrs[] = {
1988 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1989 ZERO_STRUCTP(r->out.sec_handle);
1991 switch (security_session_user_level(dce_call->conn->auth_state.session_info))
1993 case SECURITY_SYSTEM:
1994 case SECURITY_ADMINISTRATOR:
1997 /* Users and annonymous are not allowed create secrets */
1998 return NT_STATUS_ACCESS_DENIED;
2001 policy_state = policy_handle->data;
2003 if (!r->in.name.string) {
2004 return NT_STATUS_INVALID_PARAMETER;
2007 secret_state = talloc(mem_ctx, struct lsa_secret_state);
2008 if (!secret_state) {
2009 return NT_STATUS_NO_MEMORY;
2011 secret_state->policy = policy_state;
2013 msg = ldb_msg_new(mem_ctx);
2015 return NT_STATUS_NO_MEMORY;
2018 if (strncmp("G$", r->in.name.string, 2) == 0) {
2020 name = &r->in.name.string[2];
2021 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
2022 secret_state->global = true;
2024 if (strlen(name) < 1) {
2025 return NT_STATUS_INVALID_PARAMETER;
2028 name2 = talloc_asprintf(mem_ctx, "%s Secret", ldb_binary_encode_string(mem_ctx, name));
2029 /* search for the secret record */
2030 ret = gendb_search(secret_state->sam_ldb,
2031 mem_ctx, policy_state->system_dn, &msgs, attrs,
2032 "(&(cn=%s)(objectclass=secret))",
2035 return NT_STATUS_OBJECT_NAME_COLLISION;
2039 DEBUG(0,("Failure searching for CN=%s: %s\n",
2040 name2, ldb_errstring(secret_state->sam_ldb)));
2041 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2044 msg->dn = ldb_dn_copy(mem_ctx, policy_state->system_dn);
2045 if (!name2 || ! ldb_dn_add_child_fmt(msg->dn, "cn=%s", name2)) {
2046 return NT_STATUS_NO_MEMORY;
2049 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name2);
2052 secret_state->global = false;
2054 name = r->in.name.string;
2055 if (strlen(name) < 1) {
2056 return NT_STATUS_INVALID_PARAMETER;
2059 secret_state->sam_ldb = talloc_reference(secret_state,
2060 secrets_db_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx));
2061 /* search for the secret record */
2062 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
2063 ldb_dn_new(mem_ctx, secret_state->sam_ldb, "cn=LSA Secrets"),
2065 "(&(cn=%s)(objectclass=secret))",
2066 ldb_binary_encode_string(mem_ctx, name));
2068 return NT_STATUS_OBJECT_NAME_COLLISION;
2072 DEBUG(0,("Failure searching for CN=%s: %s\n",
2073 name, ldb_errstring(secret_state->sam_ldb)));
2074 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2077 msg->dn = ldb_dn_new_fmt(mem_ctx, secret_state->sam_ldb, "cn=%s,cn=LSA Secrets", name);
2078 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name);
2081 /* pull in all the template attributes. Note this is always from the global samdb */
2082 ret = samdb_copy_template(secret_state->policy->sam_ldb, msg,
2085 DEBUG(0,("Failed to load TemplateSecret from samdb: %s\n",
2087 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2090 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "objectClass", "secret");
2092 secret_state->secret_dn = talloc_reference(secret_state, msg->dn);
2094 /* create the secret */
2095 ret = ldb_add(secret_state->sam_ldb, msg);
2097 DEBUG(0,("Failed to create secret record %s: %s\n",
2098 ldb_dn_get_linearized(msg->dn),
2099 ldb_errstring(secret_state->sam_ldb)));
2100 return NT_STATUS_ACCESS_DENIED;
2103 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
2105 return NT_STATUS_NO_MEMORY;
2108 handle->data = talloc_steal(handle, secret_state);
2110 secret_state->access_mask = r->in.access_mask;
2111 secret_state->policy = talloc_reference(secret_state, policy_state);
2113 *r->out.sec_handle = handle->wire_handle;
2115 return NT_STATUS_OK;
2122 static NTSTATUS dcesrv_lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2123 struct lsa_OpenSecret *r)
2125 struct dcesrv_handle *policy_handle;
2127 struct lsa_policy_state *policy_state;
2128 struct lsa_secret_state *secret_state;
2129 struct dcesrv_handle *handle;
2130 struct ldb_message **msgs;
2131 const char *attrs[] = {
2139 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
2140 ZERO_STRUCTP(r->out.sec_handle);
2141 policy_state = policy_handle->data;
2143 if (!r->in.name.string) {
2144 return NT_STATUS_INVALID_PARAMETER;
2147 switch (security_session_user_level(dce_call->conn->auth_state.session_info))
2149 case SECURITY_SYSTEM:
2150 case SECURITY_ADMINISTRATOR:
2153 /* Users and annonymous are not allowed to access secrets */
2154 return NT_STATUS_ACCESS_DENIED;
2157 secret_state = talloc(mem_ctx, struct lsa_secret_state);
2158 if (!secret_state) {
2159 return NT_STATUS_NO_MEMORY;
2161 secret_state->policy = policy_state;
2163 if (strncmp("G$", r->in.name.string, 2) == 0) {
2164 name = &r->in.name.string[2];
2165 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
2166 secret_state->global = true;
2168 if (strlen(name) < 1) {
2169 return NT_STATUS_INVALID_PARAMETER;
2172 /* search for the secret record */
2173 ret = gendb_search(secret_state->sam_ldb,
2174 mem_ctx, policy_state->system_dn, &msgs, attrs,
2175 "(&(cn=%s Secret)(objectclass=secret))",
2176 ldb_binary_encode_string(mem_ctx, name));
2178 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2182 DEBUG(0,("Found %d records matching DN %s\n", ret,
2183 ldb_dn_get_linearized(policy_state->system_dn)));
2184 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2188 secret_state->global = false;
2189 secret_state->sam_ldb = talloc_reference(secret_state,
2190 secrets_db_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx));
2192 name = r->in.name.string;
2193 if (strlen(name) < 1) {
2194 return NT_STATUS_INVALID_PARAMETER;
2197 /* search for the secret record */
2198 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
2199 ldb_dn_new(mem_ctx, secret_state->sam_ldb, "cn=LSA Secrets"),
2201 "(&(cn=%s)(objectclass=secret))",
2202 ldb_binary_encode_string(mem_ctx, name));
2204 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2208 DEBUG(0,("Found %d records matching CN=%s\n",
2209 ret, ldb_binary_encode_string(mem_ctx, name)));
2210 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2214 secret_state->secret_dn = talloc_reference(secret_state, msgs[0]->dn);
2216 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
2218 return NT_STATUS_NO_MEMORY;
2221 handle->data = talloc_steal(handle, secret_state);
2223 secret_state->access_mask = r->in.access_mask;
2224 secret_state->policy = talloc_reference(secret_state, policy_state);
2226 *r->out.sec_handle = handle->wire_handle;
2228 return NT_STATUS_OK;
2235 static NTSTATUS dcesrv_lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2236 struct lsa_SetSecret *r)
2239 struct dcesrv_handle *h;
2240 struct lsa_secret_state *secret_state;
2241 struct ldb_message *msg;
2242 DATA_BLOB session_key;
2243 DATA_BLOB crypt_secret, secret;
2246 NTSTATUS status = NT_STATUS_OK;
2248 struct timeval now = timeval_current();
2249 NTTIME nt_now = timeval_to_nttime(&now);
2251 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
2253 secret_state = h->data;
2255 msg = ldb_msg_new(mem_ctx);
2257 return NT_STATUS_NO_MEMORY;
2260 msg->dn = talloc_reference(mem_ctx, secret_state->secret_dn);
2262 return NT_STATUS_NO_MEMORY;
2264 status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
2265 if (!NT_STATUS_IS_OK(status)) {
2269 if (r->in.old_val) {
2271 crypt_secret.data = r->in.old_val->data;
2272 crypt_secret.length = r->in.old_val->size;
2274 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
2275 if (!NT_STATUS_IS_OK(status)) {
2279 val.data = secret.data;
2280 val.length = secret.length;
2283 if (samdb_msg_add_value(secret_state->sam_ldb,
2284 mem_ctx, msg, "priorValue", &val) != 0) {
2285 return NT_STATUS_NO_MEMORY;
2288 /* set old value mtime */
2289 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2290 mem_ctx, msg, "priorSetTime", nt_now) != 0) {
2291 return NT_STATUS_NO_MEMORY;
2294 if (!r->in.new_val) {
2295 /* set old value mtime */
2296 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2297 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
2298 return NT_STATUS_NO_MEMORY;
2300 if (samdb_msg_add_delete(secret_state->sam_ldb,
2301 mem_ctx, msg, "currentValue")) {
2302 return NT_STATUS_NO_MEMORY;
2307 if (r->in.new_val) {
2309 crypt_secret.data = r->in.new_val->data;
2310 crypt_secret.length = r->in.new_val->size;
2312 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
2313 if (!NT_STATUS_IS_OK(status)) {
2317 val.data = secret.data;
2318 val.length = secret.length;
2321 if (samdb_msg_add_value(secret_state->sam_ldb,
2322 mem_ctx, msg, "currentValue", &val) != 0) {
2323 return NT_STATUS_NO_MEMORY;
2326 /* set new value mtime */
2327 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2328 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
2329 return NT_STATUS_NO_MEMORY;
2332 /* If the old value is not set, then migrate the
2333 * current value to the old value */
2334 if (!r->in.old_val) {
2335 const struct ldb_val *new_val;
2336 NTTIME last_set_time;
2337 struct ldb_message **res;
2338 const char *attrs[] = {
2344 /* search for the secret record */
2345 ret = gendb_search_dn(secret_state->sam_ldb,mem_ctx,
2346 secret_state->secret_dn, &res, attrs);
2348 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2352 DEBUG(0,("Found %d records matching dn=%s\n", ret,
2353 ldb_dn_get_linearized(secret_state->secret_dn)));
2354 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2357 new_val = ldb_msg_find_ldb_val(res[0], "currentValue");
2358 last_set_time = ldb_msg_find_attr_as_uint64(res[0], "lastSetTime", 0);
2362 if (samdb_msg_add_value(secret_state->sam_ldb,
2363 mem_ctx, msg, "priorValue",
2365 return NT_STATUS_NO_MEMORY;
2369 /* set new value mtime */
2370 if (ldb_msg_find_ldb_val(res[0], "lastSetTime")) {
2371 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2372 mem_ctx, msg, "priorSetTime", last_set_time) != 0) {
2373 return NT_STATUS_NO_MEMORY;
2379 /* modify the samdb record */
2380 ret = samdb_replace(secret_state->sam_ldb, mem_ctx, msg);
2382 /* we really need samdb.c to return NTSTATUS */
2383 return NT_STATUS_UNSUCCESSFUL;
2386 return NT_STATUS_OK;
2393 static NTSTATUS dcesrv_lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2394 struct lsa_QuerySecret *r)
2396 struct dcesrv_handle *h;
2397 struct lsa_secret_state *secret_state;
2398 struct ldb_message *msg;
2399 DATA_BLOB session_key;
2400 DATA_BLOB crypt_secret, secret;
2402 struct ldb_message **res;
2403 const char *attrs[] = {
2413 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
2415 /* Ensure user is permitted to read this... */
2416 switch (security_session_user_level(dce_call->conn->auth_state.session_info))
2418 case SECURITY_SYSTEM:
2419 case SECURITY_ADMINISTRATOR:
2422 /* Users and annonymous are not allowed to read secrets */
2423 return NT_STATUS_ACCESS_DENIED;
2426 secret_state = h->data;
2428 /* pull all the user attributes */
2429 ret = gendb_search_dn(secret_state->sam_ldb, mem_ctx,
2430 secret_state->secret_dn, &res, attrs);
2432 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2436 nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
2437 if (!NT_STATUS_IS_OK(nt_status)) {
2441 if (r->in.old_val) {
2442 const struct ldb_val *prior_val;
2443 r->out.old_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2444 if (!r->out.old_val) {
2445 return NT_STATUS_NO_MEMORY;
2447 prior_val = ldb_msg_find_ldb_val(res[0], "priorValue");
2449 if (prior_val && prior_val->length) {
2450 secret.data = prior_val->data;
2451 secret.length = prior_val->length;
2454 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2455 if (!crypt_secret.length) {
2456 return NT_STATUS_NO_MEMORY;
2458 r->out.old_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2459 if (!r->out.old_val->buf) {
2460 return NT_STATUS_NO_MEMORY;
2462 r->out.old_val->buf->size = crypt_secret.length;
2463 r->out.old_val->buf->length = crypt_secret.length;
2464 r->out.old_val->buf->data = crypt_secret.data;
2468 if (r->in.old_mtime) {
2469 r->out.old_mtime = talloc(mem_ctx, NTTIME);
2470 if (!r->out.old_mtime) {
2471 return NT_STATUS_NO_MEMORY;
2473 *r->out.old_mtime = ldb_msg_find_attr_as_uint64(res[0], "priorSetTime", 0);
2476 if (r->in.new_val) {
2477 const struct ldb_val *new_val;
2478 r->out.new_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2479 if (!r->out.new_val) {
2480 return NT_STATUS_NO_MEMORY;
2483 new_val = ldb_msg_find_ldb_val(res[0], "currentValue");
2485 if (new_val && new_val->length) {
2486 secret.data = new_val->data;
2487 secret.length = new_val->length;
2490 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2491 if (!crypt_secret.length) {
2492 return NT_STATUS_NO_MEMORY;
2494 r->out.new_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2495 if (!r->out.new_val->buf) {
2496 return NT_STATUS_NO_MEMORY;
2498 r->out.new_val->buf->length = crypt_secret.length;
2499 r->out.new_val->buf->size = crypt_secret.length;
2500 r->out.new_val->buf->data = crypt_secret.data;
2504 if (r->in.new_mtime) {
2505 r->out.new_mtime = talloc(mem_ctx, NTTIME);
2506 if (!r->out.new_mtime) {
2507 return NT_STATUS_NO_MEMORY;
2509 *r->out.new_mtime = ldb_msg_find_attr_as_uint64(res[0], "lastSetTime", 0);
2512 return NT_STATUS_OK;
2519 static NTSTATUS dcesrv_lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
2520 TALLOC_CTX *mem_ctx,
2521 struct lsa_LookupPrivValue *r)
2523 struct dcesrv_handle *h;
2524 struct lsa_policy_state *state;
2527 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2531 id = sec_privilege_id(r->in.name->string);
2533 return NT_STATUS_NO_SUCH_PRIVILEGE;
2536 r->out.luid->low = id;
2537 r->out.luid->high = 0;
2539 return NT_STATUS_OK;
2546 static NTSTATUS dcesrv_lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
2547 TALLOC_CTX *mem_ctx,
2548 struct lsa_LookupPrivName *r)
2550 struct dcesrv_handle *h;
2551 struct lsa_policy_state *state;
2552 const char *privname;
2554 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2558 if (r->in.luid->high != 0) {
2559 return NT_STATUS_NO_SUCH_PRIVILEGE;
2562 privname = sec_privilege_name(r->in.luid->low);
2563 if (privname == NULL) {
2564 return NT_STATUS_NO_SUCH_PRIVILEGE;
2567 r->out.name = talloc(mem_ctx, struct lsa_StringLarge);
2568 if (r->out.name == NULL) {
2569 return NT_STATUS_NO_MEMORY;
2571 r->out.name->string = privname;
2573 return NT_STATUS_OK;
2578 lsa_LookupPrivDisplayName
2580 static NTSTATUS dcesrv_lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
2581 TALLOC_CTX *mem_ctx,
2582 struct lsa_LookupPrivDisplayName *r)
2584 struct dcesrv_handle *h;
2585 struct lsa_policy_state *state;
2588 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2592 id = sec_privilege_id(r->in.name->string);
2594 return NT_STATUS_NO_SUCH_PRIVILEGE;
2597 r->out.disp_name = talloc(mem_ctx, struct lsa_StringLarge);
2598 if (r->out.disp_name == NULL) {
2599 return NT_STATUS_NO_MEMORY;
2602 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
2603 if (r->out.disp_name->string == NULL) {
2604 return NT_STATUS_INTERNAL_ERROR;
2607 return NT_STATUS_OK;
2612 lsa_EnumAccountsWithUserRight
2614 static NTSTATUS dcesrv_lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
2615 TALLOC_CTX *mem_ctx,
2616 struct lsa_EnumAccountsWithUserRight *r)
2618 struct dcesrv_handle *h;
2619 struct lsa_policy_state *state;
2621 struct ldb_message **res;
2622 const char * const attrs[] = { "objectSid", NULL};
2623 const char *privname;
2625 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2629 if (r->in.name == NULL) {
2630 return NT_STATUS_NO_SUCH_PRIVILEGE;
2633 privname = r->in.name->string;
2634 if (sec_privilege_id(privname) == -1) {
2635 return NT_STATUS_NO_SUCH_PRIVILEGE;
2638 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
2639 "privilege=%s", privname);
2641 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2644 return NT_STATUS_NO_MORE_ENTRIES;
2647 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, ret);
2648 if (r->out.sids->sids == NULL) {
2649 return NT_STATUS_NO_MEMORY;
2651 for (i=0;i<ret;i++) {
2652 r->out.sids->sids[i].sid = samdb_result_dom_sid(r->out.sids->sids,
2653 res[i], "objectSid");
2654 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
2656 r->out.sids->num_sids = ret;
2658 return NT_STATUS_OK;
2663 lsa_AddAccountRights
2665 static NTSTATUS dcesrv_lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
2666 TALLOC_CTX *mem_ctx,
2667 struct lsa_AddAccountRights *r)
2669 struct dcesrv_handle *h;
2670 struct lsa_policy_state *state;
2672 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2676 return dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2678 r->in.sid, r->in.rights);
2683 lsa_RemoveAccountRights
2685 static NTSTATUS dcesrv_lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
2686 TALLOC_CTX *mem_ctx,
2687 struct lsa_RemoveAccountRights *r)
2689 struct dcesrv_handle *h;
2690 struct lsa_policy_state *state;
2692 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2696 return dcesrv_lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2697 LDB_FLAG_MOD_DELETE,
2698 r->in.sid, r->in.rights);
2703 lsa_StorePrivateData
2705 static NTSTATUS dcesrv_lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2706 struct lsa_StorePrivateData *r)
2708 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2713 lsa_RetrievePrivateData
2715 static NTSTATUS dcesrv_lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2716 struct lsa_RetrievePrivateData *r)
2718 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2725 static NTSTATUS dcesrv_lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2726 struct lsa_GetUserName *r)
2728 NTSTATUS status = NT_STATUS_OK;
2729 const char *account_name;
2730 const char *authority_name;
2731 struct lsa_String *_account_name;
2732 struct lsa_StringPointer *_authority_name = NULL;
2734 /* this is what w2k3 does */
2735 r->out.account_name = r->in.account_name;
2736 r->out.authority_name = r->in.authority_name;
2738 if (r->in.account_name && r->in.account_name->string) {
2739 return NT_STATUS_INVALID_PARAMETER;
2742 if (r->in.authority_name &&
2743 r->in.authority_name->string &&
2744 r->in.authority_name->string->string) {
2745 return NT_STATUS_INVALID_PARAMETER;
2748 account_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->account_name);
2749 authority_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->domain_name);
2751 _account_name = talloc(mem_ctx, struct lsa_String);
2752 NT_STATUS_HAVE_NO_MEMORY(_account_name);
2753 _account_name->string = account_name;
2755 if (r->in.authority_name) {
2756 _authority_name = talloc(mem_ctx, struct lsa_StringPointer);
2757 NT_STATUS_HAVE_NO_MEMORY(_authority_name);
2758 _authority_name->string = talloc(mem_ctx, struct lsa_String);
2759 NT_STATUS_HAVE_NO_MEMORY(_authority_name->string);
2760 _authority_name->string->string = authority_name;
2763 r->out.account_name = _account_name;
2764 r->out.authority_name = _authority_name;
2772 static NTSTATUS dcesrv_lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
2773 TALLOC_CTX *mem_ctx,
2774 struct lsa_SetInfoPolicy2 *r)
2776 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2780 lsa_QueryDomainInformationPolicy
2782 static NTSTATUS dcesrv_lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2783 TALLOC_CTX *mem_ctx,
2784 struct lsa_QueryDomainInformationPolicy *r)
2786 r->out.info = talloc(mem_ctx, union lsa_DomainInformationPolicy);
2788 return NT_STATUS_NO_MEMORY;
2791 switch (r->in.level) {
2792 case LSA_DOMAIN_INFO_POLICY_EFS:
2793 talloc_free(r->out.info);
2795 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2796 case LSA_DOMAIN_INFO_POLICY_KERBEROS:
2798 struct lsa_DomainInfoKerberos *k = &r->out.info->kerberos_info;
2799 struct smb_krb5_context *smb_krb5_context;
2800 int ret = smb_krb5_init_context(mem_ctx,
2801 dce_call->event_ctx,
2802 dce_call->conn->dce_ctx->lp_ctx,
2805 talloc_free(r->out.info);
2807 return NT_STATUS_INTERNAL_ERROR;
2809 k->enforce_restrictions = 0; /* FIXME, details missing from MS-LSAD 2.2.53 */
2810 k->service_tkt_lifetime = 0; /* Need to find somewhere to store this, and query in KDC too */
2811 k->user_tkt_lifetime = 0; /* Need to find somewhere to store this, and query in KDC too */
2812 k->user_tkt_renewaltime = 0; /* Need to find somewhere to store this, and query in KDC too */
2813 k->clock_skew = krb5_get_max_time_skew(smb_krb5_context->krb5_context);
2814 talloc_free(smb_krb5_context);
2815 return NT_STATUS_OK;
2818 talloc_free(r->out.info);
2820 return NT_STATUS_INVALID_INFO_CLASS;
2825 lsa_SetDomInfoPolicy
2827 static NTSTATUS dcesrv_lsa_SetDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2828 TALLOC_CTX *mem_ctx,
2829 struct lsa_SetDomainInformationPolicy *r)
2831 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2837 static NTSTATUS dcesrv_lsa_TestCall(struct dcesrv_call_state *dce_call,
2838 TALLOC_CTX *mem_ctx,
2839 struct lsa_TestCall *r)
2841 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2847 static NTSTATUS dcesrv_lsa_CREDRWRITE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2848 struct lsa_CREDRWRITE *r)
2850 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2857 static NTSTATUS dcesrv_lsa_CREDRREAD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2858 struct lsa_CREDRREAD *r)
2860 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2867 static NTSTATUS dcesrv_lsa_CREDRENUMERATE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2868 struct lsa_CREDRENUMERATE *r)
2870 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2875 lsa_CREDRWRITEDOMAINCREDENTIALS
2877 static NTSTATUS dcesrv_lsa_CREDRWRITEDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2878 struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
2880 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2885 lsa_CREDRREADDOMAINCREDENTIALS
2887 static NTSTATUS dcesrv_lsa_CREDRREADDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2888 struct lsa_CREDRREADDOMAINCREDENTIALS *r)
2890 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2897 static NTSTATUS dcesrv_lsa_CREDRDELETE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2898 struct lsa_CREDRDELETE *r)
2900 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2905 lsa_CREDRGETTARGETINFO
2907 static NTSTATUS dcesrv_lsa_CREDRGETTARGETINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2908 struct lsa_CREDRGETTARGETINFO *r)
2910 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2915 lsa_CREDRPROFILELOADED
2917 static NTSTATUS dcesrv_lsa_CREDRPROFILELOADED(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2918 struct lsa_CREDRPROFILELOADED *r)
2920 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2925 lsa_CREDRGETSESSIONTYPES
2927 static NTSTATUS dcesrv_lsa_CREDRGETSESSIONTYPES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2928 struct lsa_CREDRGETSESSIONTYPES *r)
2930 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2935 lsa_LSARREGISTERAUDITEVENT
2937 static NTSTATUS dcesrv_lsa_LSARREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2938 struct lsa_LSARREGISTERAUDITEVENT *r)
2940 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2945 lsa_LSARGENAUDITEVENT
2947 static NTSTATUS dcesrv_lsa_LSARGENAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2948 struct lsa_LSARGENAUDITEVENT *r)
2950 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2955 lsa_LSARUNREGISTERAUDITEVENT
2957 static NTSTATUS dcesrv_lsa_LSARUNREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2958 struct lsa_LSARUNREGISTERAUDITEVENT *r)
2960 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2965 lsa_lsaRQueryForestTrustInformation
2967 static NTSTATUS dcesrv_lsa_lsaRQueryForestTrustInformation(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2968 struct lsa_lsaRQueryForestTrustInformation *r)
2970 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2975 lsa_LSARSETFORESTTRUSTINFORMATION
2977 static NTSTATUS dcesrv_lsa_LSARSETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2978 struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2980 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2987 static NTSTATUS dcesrv_lsa_CREDRRENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2988 struct lsa_CREDRRENAME *r)
2990 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2996 lsa_LSAROPENPOLICYSCE
2998 static NTSTATUS dcesrv_lsa_LSAROPENPOLICYSCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2999 struct lsa_LSAROPENPOLICYSCE *r)
3001 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3006 lsa_LSARADTREGISTERSECURITYEVENTSOURCE
3008 static NTSTATUS dcesrv_lsa_LSARADTREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3009 struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
3011 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3016 lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE
3018 static NTSTATUS dcesrv_lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3019 struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
3021 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3026 lsa_LSARADTREPORTSECURITYEVENT
3028 static NTSTATUS dcesrv_lsa_LSARADTREPORTSECURITYEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3029 struct lsa_LSARADTREPORTSECURITYEVENT *r)
3031 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3035 /* include the generated boilerplate */
3036 #include "librpc/gen_ndr/ndr_lsa_s.c"
3040 /*****************************************
3041 NOTE! The remaining calls below were
3042 removed in w2k3, so the DCESRV_FAULT()
3043 replies are the correct implementation. Do
3044 not try and fill these in with anything else
3045 ******************************************/
3048 dssetup_DsRoleDnsNameToFlatName
3050 static WERROR dcesrv_dssetup_DsRoleDnsNameToFlatName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3051 struct dssetup_DsRoleDnsNameToFlatName *r)
3053 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3058 dssetup_DsRoleDcAsDc
3060 static WERROR dcesrv_dssetup_DsRoleDcAsDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3061 struct dssetup_DsRoleDcAsDc *r)
3063 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3068 dssetup_DsRoleDcAsReplica
3070 static WERROR dcesrv_dssetup_DsRoleDcAsReplica(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3071 struct dssetup_DsRoleDcAsReplica *r)
3073 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3078 dssetup_DsRoleDemoteDc
3080 static WERROR dcesrv_dssetup_DsRoleDemoteDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3081 struct dssetup_DsRoleDemoteDc *r)
3083 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3088 dssetup_DsRoleGetDcOperationProgress
3090 static WERROR dcesrv_dssetup_DsRoleGetDcOperationProgress(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3091 struct dssetup_DsRoleGetDcOperationProgress *r)
3093 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3098 dssetup_DsRoleGetDcOperationResults
3100 static WERROR dcesrv_dssetup_DsRoleGetDcOperationResults(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3101 struct dssetup_DsRoleGetDcOperationResults *r)
3103 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3108 dssetup_DsRoleCancel
3110 static WERROR dcesrv_dssetup_DsRoleCancel(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3111 struct dssetup_DsRoleCancel *r)
3113 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3118 dssetup_DsRoleServerSaveStateForUpgrade
3120 static WERROR dcesrv_dssetup_DsRoleServerSaveStateForUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3121 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
3123 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3128 dssetup_DsRoleUpgradeDownlevelServer
3130 static WERROR dcesrv_dssetup_DsRoleUpgradeDownlevelServer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3131 struct dssetup_DsRoleUpgradeDownlevelServer *r)
3133 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3138 dssetup_DsRoleAbortDownlevelServerUpgrade
3140 static WERROR dcesrv_dssetup_DsRoleAbortDownlevelServerUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
3141 struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
3143 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
3147 /* include the generated boilerplate */
3148 #include "librpc/gen_ndr/ndr_dssetup_s.c"
3150 NTSTATUS dcerpc_server_lsa_init(void)
3154 ret = dcerpc_server_dssetup_init();
3155 if (!NT_STATUS_IS_OK(ret)) {
3158 ret = dcerpc_server_lsarpc_init();
3159 if (!NT_STATUS_IS_OK(ret)) {