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-2005
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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "rpc_server/dcerpc_server.h"
26 #include "rpc_server/common/common.h"
27 #include "auth/auth.h"
28 #include "dsdb/samdb/samdb.h"
29 #include "libcli/ldap/ldap.h"
30 #include "ntvfs/ntvfs.h"
33 this type allows us to distinguish handle types
39 LSA_HANDLE_TRUSTED_DOMAIN
43 state associated with a lsa_OpenPolicy() operation
45 struct lsa_policy_state {
46 struct dcesrv_handle *handle;
47 struct ldb_context *sam_ldb;
48 struct sidmap_context *sidmap;
50 const struct ldb_dn *domain_dn;
51 const struct ldb_dn *builtin_dn;
52 const struct ldb_dn *system_dn;
53 const char *domain_name;
54 struct dom_sid *domain_sid;
55 struct dom_sid *builtin_sid;
60 state associated with a lsa_OpenAccount() operation
62 struct lsa_account_state {
63 struct lsa_policy_state *policy;
65 struct dom_sid *account_sid;
66 const struct ldb_dn *account_dn;
71 state associated with a lsa_OpenSecret() operation
73 struct lsa_secret_state {
74 struct lsa_policy_state *policy;
76 const struct ldb_dn *secret_dn;
77 struct ldb_context *sam_ldb;
82 state associated with a lsa_OpenTrustedDomain() operation
84 struct lsa_trusted_domain_state {
85 struct lsa_policy_state *policy;
87 const struct ldb_dn *trusted_domain_dn;
93 static NTSTATUS lsa_Close(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
96 struct dcesrv_handle *h;
98 *r->out.handle = *r->in.handle;
100 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
104 ZERO_STRUCTP(r->out.handle);
113 static NTSTATUS lsa_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
114 struct lsa_Delete *r)
116 struct dcesrv_handle *h;
119 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
120 if (h->wire_handle.handle_type == LSA_HANDLE_SECRET) {
121 struct lsa_secret_state *secret_state = h->data;
122 ret = samdb_delete(secret_state->sam_ldb, mem_ctx, secret_state->secret_dn);
125 return NT_STATUS_INVALID_HANDLE;
129 } else if (h->wire_handle.handle_type == LSA_HANDLE_TRUSTED_DOMAIN) {
130 struct lsa_trusted_domain_state *trusted_domain_state = h->data;
131 ret = samdb_delete(trusted_domain_state->policy->sam_ldb, mem_ctx,
132 trusted_domain_state->trusted_domain_dn);
135 return NT_STATUS_INVALID_HANDLE;
141 return NT_STATUS_INVALID_HANDLE;
148 static NTSTATUS lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
149 struct lsa_EnumPrivs *r)
151 struct dcesrv_handle *h;
152 struct lsa_policy_state *state;
154 const char *privname;
156 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
160 i = *r->in.resume_handle;
163 while ((privname = sec_privilege_name(i)) &&
164 r->out.privs->count < r->in.max_count) {
165 struct lsa_PrivEntry *e;
167 r->out.privs->privs = talloc_realloc(r->out.privs,
169 struct lsa_PrivEntry,
170 r->out.privs->count+1);
171 if (r->out.privs->privs == NULL) {
172 return NT_STATUS_NO_MEMORY;
174 e = &r->out.privs->privs[r->out.privs->count];
177 e->name.string = privname;
178 r->out.privs->count++;
182 *r->out.resume_handle = i;
191 static NTSTATUS lsa_QuerySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
192 struct lsa_QuerySecurity *r)
194 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
201 static NTSTATUS lsa_SetSecObj(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
202 struct lsa_SetSecObj *r)
204 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
211 static NTSTATUS lsa_ChangePassword(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
212 struct lsa_ChangePassword *r)
214 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
217 static NTSTATUS lsa_get_policy_state(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
218 struct lsa_policy_state **_state)
220 struct lsa_policy_state *state;
222 state = talloc(mem_ctx, struct lsa_policy_state);
224 return NT_STATUS_NO_MEMORY;
227 /* make sure the sam database is accessible */
228 state->sam_ldb = samdb_connect(state, dce_call->conn->auth_state.session_info);
229 if (state->sam_ldb == NULL) {
230 return NT_STATUS_INVALID_SYSTEM_SERVICE;
233 state->sidmap = sidmap_open(state);
234 if (state->sidmap == NULL) {
235 return NT_STATUS_INVALID_SYSTEM_SERVICE;
238 /* work out the domain_dn - useful for so many calls its worth
240 state->domain_dn = samdb_base_dn(state);
241 if (!state->domain_dn) {
242 return NT_STATUS_NO_MEMORY;
246 = samdb_search_string(state->sam_ldb, state, NULL, "nETBIOSName",
247 "(&(objectclass=crossRef)(ncName=%s))", ldb_dn_linearize(mem_ctx, state->domain_dn));
249 if (!state->domain_name) {
250 return NT_STATUS_NO_SUCH_DOMAIN;
252 talloc_steal(state, state->domain_name);
254 /* work out the builtin_dn - useful for so many calls its worth
256 state->builtin_dn = samdb_search_dn(state->sam_ldb, state, state->domain_dn, "(objectClass=builtinDomain)");
257 if (!state->builtin_dn) {
258 return NT_STATUS_NO_SUCH_DOMAIN;
261 /* work out the system_dn - useful for so many calls its worth
263 state->system_dn = samdb_search_dn(state->sam_ldb, state,
264 state->domain_dn, "(&(objectClass=container)(cn=System))");
265 if (!state->system_dn) {
266 return NT_STATUS_NO_SUCH_DOMAIN;
269 state->domain_sid = samdb_search_dom_sid(state->sam_ldb, state,
270 state->domain_dn, "objectSid", NULL);
271 if (!state->domain_sid) {
272 return NT_STATUS_NO_SUCH_DOMAIN;
275 talloc_steal(state, state->domain_sid);
277 state->builtin_sid = dom_sid_parse_talloc(state, SID_BUILTIN);
278 if (!state->builtin_sid) {
279 return NT_STATUS_NO_SUCH_DOMAIN;
290 static NTSTATUS lsa_OpenPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
291 struct lsa_OpenPolicy2 *r)
294 struct lsa_policy_state *state;
295 struct dcesrv_handle *handle;
297 ZERO_STRUCTP(r->out.handle);
299 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
300 if (!NT_STATUS_IS_OK(status)) {
304 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_POLICY);
306 return NT_STATUS_NO_MEMORY;
309 handle->data = talloc_steal(handle, state);
311 state->access_mask = r->in.access_mask;
312 state->handle = handle;
313 *r->out.handle = handle->wire_handle;
315 /* note that we have completely ignored the attr element of
316 the OpenPolicy. As far as I can tell, this is what w2k3
324 a wrapper around lsa_OpenPolicy2
326 static NTSTATUS lsa_OpenPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
327 struct lsa_OpenPolicy *r)
329 struct lsa_OpenPolicy2 r2;
331 r2.in.system_name = NULL;
332 r2.in.attr = r->in.attr;
333 r2.in.access_mask = r->in.access_mask;
334 r2.out.handle = r->out.handle;
336 return lsa_OpenPolicy2(dce_call, mem_ctx, &r2);
343 fill in the AccountDomain info
345 static NTSTATUS lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
346 struct lsa_DomainInfo *info)
348 info->name.string = state->domain_name;
349 info->sid = state->domain_sid;
355 fill in the DNS domain info
357 static NTSTATUS lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
358 struct lsa_DnsDomainInfo *info)
360 const char * const attrs[] = { "dnsDomain", "objectGUID", "objectSid", NULL };
362 struct ldb_message **res;
364 ret = gendb_search_dn(state->sam_ldb, mem_ctx, state->domain_dn, &res, attrs);
366 return NT_STATUS_INTERNAL_DB_CORRUPTION;
369 info->name.string = state->domain_name;
370 info->sid = state->domain_sid;
371 info->dns_domain.string = samdb_result_string(res[0], "dnsDomain", NULL);
372 info->dns_forest.string = samdb_result_string(res[0], "dnsDomain", NULL);
373 info->domain_guid = samdb_result_guid(res[0], "objectGUID");
381 static NTSTATUS lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
382 struct lsa_QueryInfoPolicy2 *r)
384 struct lsa_policy_state *state;
385 struct dcesrv_handle *h;
389 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
393 r->out.info = talloc(mem_ctx, union lsa_PolicyInformation);
395 return NT_STATUS_NO_MEMORY;
398 ZERO_STRUCTP(r->out.info);
400 switch (r->in.level) {
401 case LSA_POLICY_INFO_DOMAIN:
402 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
403 return lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
405 case LSA_POLICY_INFO_DNS:
406 return lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
409 return NT_STATUS_INVALID_INFO_CLASS;
415 static NTSTATUS lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
416 struct lsa_QueryInfoPolicy *r)
418 struct lsa_QueryInfoPolicy2 r2;
421 r2.in.handle = r->in.handle;
422 r2.in.level = r->in.level;
424 status = lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
426 r->out.info = r2.out.info;
434 static NTSTATUS lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
435 struct lsa_SetInfoPolicy *r)
437 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
444 static NTSTATUS lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
445 struct lsa_ClearAuditLog *r)
447 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
454 static NTSTATUS lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
455 struct lsa_CreateAccount *r)
457 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
464 static NTSTATUS lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
465 struct lsa_EnumAccounts *r)
467 struct dcesrv_handle *h;
468 struct lsa_policy_state *state;
470 struct ldb_message **res;
471 const char * const attrs[] = { "objectSid", NULL};
474 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
478 ret = gendb_search(state->sam_ldb, mem_ctx, state->builtin_dn, &res, attrs,
479 "(|(privilege=*)(objectSid=*))");
481 return NT_STATUS_NO_SUCH_USER;
484 if (*r->in.resume_handle >= ret) {
485 return NT_STATUS_NO_MORE_ENTRIES;
488 count = ret - *r->in.resume_handle;
489 if (count > r->in.num_entries) {
490 count = r->in.num_entries;
494 return NT_STATUS_NO_MORE_ENTRIES;
497 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, count);
498 if (r->out.sids->sids == NULL) {
499 return NT_STATUS_NO_MEMORY;
502 for (i=0;i<count;i++) {
503 r->out.sids->sids[i].sid =
504 samdb_result_dom_sid(r->out.sids->sids,
505 res[i + *r->in.resume_handle],
507 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
510 r->out.sids->num_sids = count;
511 *r->out.resume_handle = count + *r->in.resume_handle;
519 lsa_CreateTrustedDomainEx2
521 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
523 struct lsa_CreateTrustedDomainEx2 *r)
525 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
529 lsa_CreateTrustedDomainEx
531 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
533 struct lsa_CreateTrustedDomainEx *r)
535 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
539 lsa_CreateTrustedDomain
541 static NTSTATUS lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
542 struct lsa_CreateTrustedDomain *r)
544 struct dcesrv_handle *policy_handle;
545 struct lsa_policy_state *policy_state;
546 struct lsa_trusted_domain_state *trusted_domain_state;
547 struct dcesrv_handle *handle;
548 struct ldb_message **msgs, *msg;
549 const char *attrs[] = {
555 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
556 ZERO_STRUCTP(r->out.trustdom_handle);
558 policy_state = policy_handle->data;
560 if (!r->in.info->name.string) {
561 return NT_STATUS_INVALID_PARAMETER;
563 name = r->in.info->name.string;
565 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
566 if (!trusted_domain_state) {
567 return NT_STATUS_NO_MEMORY;
569 trusted_domain_state->policy = policy_state;
571 msg = ldb_msg_new(mem_ctx);
573 return NT_STATUS_NO_MEMORY;
576 /* search for the trusted_domain record */
577 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
578 mem_ctx, policy_state->system_dn, &msgs, attrs,
579 "(&(cn=%s)(objectclass=trustedDomain))",
580 ldb_binary_encode_string(mem_ctx, r->in.info->name.string));
582 return NT_STATUS_OBJECT_NAME_COLLISION;
585 if (ret < 0 || ret > 1) {
586 DEBUG(0,("Found %d records matching DN %s\n", ret,
587 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
588 return NT_STATUS_INTERNAL_DB_CORRUPTION;
591 msg->dn = ldb_dn_build_child(mem_ctx, "cn",
592 r->in.info->name.string,
593 policy_state->system_dn);
595 return NT_STATUS_NO_MEMORY;
598 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "cn", name);
599 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "flatname", name);
601 if (r->in.info->sid) {
602 const char *sid_string = dom_sid_string(mem_ctx, r->in.info->sid);
604 return NT_STATUS_NO_MEMORY;
607 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "securityIdentifier", sid_string);
610 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "objectClass", "trustedDomain");
612 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msg->dn);
614 /* create the trusted_domain */
615 ret = samdb_add(trusted_domain_state->policy->sam_ldb, mem_ctx, msg);
617 DEBUG(0,("Failed to create trusted_domain record %s\n",
618 ldb_dn_linearize(mem_ctx, msg->dn)));
619 return NT_STATUS_INTERNAL_DB_CORRUPTION;
622 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
624 return NT_STATUS_NO_MEMORY;
627 handle->data = talloc_steal(handle, trusted_domain_state);
629 trusted_domain_state->access_mask = r->in.access_mask;
630 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
632 *r->out.trustdom_handle = handle->wire_handle;
638 lsa_OpenTrustedDomain
640 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
641 struct lsa_OpenTrustedDomain *r)
643 struct dcesrv_handle *policy_handle;
645 struct lsa_policy_state *policy_state;
646 struct lsa_trusted_domain_state *trusted_domain_state;
647 struct dcesrv_handle *handle;
648 struct ldb_message **msgs;
649 const char *attrs[] = {
653 const char *sid_string;
656 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
657 ZERO_STRUCTP(r->out.trustdom_handle);
658 policy_state = policy_handle->data;
660 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
661 if (!trusted_domain_state) {
662 return NT_STATUS_NO_MEMORY;
664 trusted_domain_state->policy = policy_state;
666 sid_string = dom_sid_string(mem_ctx, r->in.sid);
668 return NT_STATUS_NO_MEMORY;
671 /* search for the trusted_domain record */
672 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
673 mem_ctx, policy_state->system_dn, &msgs, attrs,
674 "(&(securityIdentifier=%s)(objectclass=trustedDomain))",
677 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
681 DEBUG(0,("Found %d records matching DN %s\n", ret,
682 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
683 return NT_STATUS_INTERNAL_DB_CORRUPTION;
686 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
688 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
690 return NT_STATUS_NO_MEMORY;
693 handle->data = talloc_steal(handle, trusted_domain_state);
695 trusted_domain_state->access_mask = r->in.access_mask;
696 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
698 *r->out.trustdom_handle = handle->wire_handle;
705 lsa_OpenTrustedDomainByName
707 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
709 struct lsa_OpenTrustedDomainByName *r)
711 struct dcesrv_handle *policy_handle;
713 struct lsa_policy_state *policy_state;
714 struct lsa_trusted_domain_state *trusted_domain_state;
715 struct dcesrv_handle *handle;
716 struct ldb_message **msgs;
717 const char *attrs[] = {
723 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
724 ZERO_STRUCTP(r->out.trustdom_handle);
725 policy_state = policy_handle->data;
727 if (!r->in.name.string) {
728 return NT_STATUS_INVALID_PARAMETER;
731 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
732 if (!trusted_domain_state) {
733 return NT_STATUS_NO_MEMORY;
735 trusted_domain_state->policy = policy_state;
737 /* search for the trusted_domain record */
738 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
739 mem_ctx, policy_state->system_dn, &msgs, attrs,
740 "(&(flatname=%s)(objectclass=trustedDomain))",
741 ldb_binary_encode_string(mem_ctx, r->in.name.string));
743 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
747 DEBUG(0,("Found %d records matching DN %s\n", ret,
748 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
749 return NT_STATUS_INTERNAL_DB_CORRUPTION;
752 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
754 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
756 return NT_STATUS_NO_MEMORY;
759 handle->data = talloc_steal(handle, trusted_domain_state);
761 trusted_domain_state->access_mask = r->in.access_mask;
762 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
764 *r->out.trustdom_handle = handle->wire_handle;
771 lsa_QueryTrustedDomainInfoBySid
773 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
774 struct lsa_QueryTrustedDomainInfoBySid *r)
776 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
781 lsa_SetTrustDomainInfo
783 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
784 struct lsa_SetTrustDomainInfo *r)
786 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
791 lsa_DeleteTrustDomain
793 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
794 struct lsa_DeleteTrustDomain *r)
796 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
801 lsa_QueryTrustedDomainInfo
803 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
804 struct lsa_QueryTrustedDomainInfo *r)
806 struct dcesrv_handle *h;
807 struct lsa_trusted_domain_state *trusted_domain_state;
808 struct ldb_message *msg;
810 struct ldb_message **res;
811 const char *attrs[] = {
815 "securityIdentifier",
819 DCESRV_PULL_HANDLE(h, r->in.trustdom_handle, LSA_HANDLE_TRUSTED_DOMAIN);
821 trusted_domain_state = h->data;
823 /* pull all the user attributes */
824 ret = gendb_search_dn(trusted_domain_state->policy->sam_ldb, mem_ctx,
825 trusted_domain_state->trusted_domain_dn, &res, attrs);
827 return NT_STATUS_INTERNAL_DB_CORRUPTION;
831 r->out.info = talloc(mem_ctx, union lsa_TrustedDomainInfo);
833 return NT_STATUS_NO_MEMORY;
835 switch (r->in.level) {
836 case LSA_TRUSTED_DOMAIN_INFO_NAME:
837 r->out.info->name.netbios_name.string
838 = samdb_result_string(msg, "flatname", NULL);
840 case LSA_TRUSTED_DOMAIN_INFO_POSIX_OFFSET:
841 r->out.info->posix_offset.posix_offset
842 = samdb_result_uint(msg, "posixOffset", 0);
845 /* oops, we don't want to return the info after all */
846 talloc_free(r->out.info);
848 return NT_STATUS_INVALID_INFO_CLASS;
856 lsa_SetInformationTrustedDomain
858 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
859 struct lsa_SetInformationTrustedDomain *r)
861 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
866 lsa_QueryTrustedDomainInfoByName
868 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
870 struct lsa_QueryTrustedDomainInfoByName *r)
872 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
876 lsa_SetTrustedDomainInfoByName
878 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
880 struct lsa_SetTrustedDomainInfoByName *r)
882 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
886 lsa_EnumTrustedDomainsEx
888 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
890 struct lsa_EnumTrustedDomainsEx *r)
892 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
896 lsa_CloseTrustedDomainEx
898 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
900 struct lsa_CloseTrustedDomainEx *r)
902 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
907 comparison function for sorting lsa_DomainInformation array
909 static int compare_DomainInformation(struct lsa_DomainInformation *e1, struct lsa_DomainInformation *e2)
911 return strcasecmp(e1->name.string, e2->name.string);
917 static NTSTATUS lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
918 struct lsa_EnumTrustDom *r)
920 struct dcesrv_handle *policy_handle;
921 struct lsa_DomainInformation *entries;
922 struct lsa_policy_state *policy_state;
923 struct ldb_message **domains;
924 const char *attrs[] = {
926 "securityIdentifier",
933 *r->out.resume_handle = 0;
935 r->out.domains->domains = NULL;
936 r->out.domains->count = 0;
938 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
940 policy_state = policy_handle->data;
942 /* search for all users in this domain. This could possibly be cached and
943 resumed based on resume_key */
944 count = gendb_search(policy_state->sam_ldb, mem_ctx, policy_state->system_dn, &domains, attrs,
945 "objectclass=trustedDomain");
947 return NT_STATUS_INTERNAL_DB_CORRUPTION;
949 if (count == 0 || r->in.max_size == 0) {
953 /* convert to lsa_DomainInformation format */
954 entries = talloc_array(mem_ctx, struct lsa_DomainInformation, count);
956 return NT_STATUS_NO_MEMORY;
958 for (i=0;i<count;i++) {
959 entries[i].sid = samdb_result_dom_sid(mem_ctx, domains[i], "securityIdentifier");
960 entries[i].name.string = samdb_result_string(domains[i], "flatname", NULL);
963 /* sort the results by name */
964 qsort(entries, count, sizeof(struct lsa_DomainInformation),
965 (comparison_fn_t)compare_DomainInformation);
967 if (*r->in.resume_handle >= count) {
968 *r->out.resume_handle = -1;
970 return NT_STATUS_NO_MORE_ENTRIES;
973 /* return the rest, limit by max_size. Note that we
974 use the w2k3 element size value of 60 */
975 r->out.domains->count = count - *r->in.resume_handle;
976 r->out.domains->count = MIN(r->out.domains->count,
977 1+(r->in.max_size/LSA_ENUM_TRUST_DOMAIN_MULTIPLIER));
979 r->out.domains->domains = entries + *r->in.resume_handle;
980 r->out.domains->count = r->out.domains->count;
982 if (r->out.domains->count < count - *r->in.resume_handle) {
983 *r->out.resume_handle = *r->in.resume_handle + r->out.domains->count;
984 return STATUS_MORE_ENTRIES;
992 return the authority name and authority sid, given a sid
994 static NTSTATUS lsa_authority_name(struct lsa_policy_state *state,
995 TALLOC_CTX *mem_ctx, struct dom_sid *sid,
996 const char **authority_name,
997 struct dom_sid **authority_sid)
999 if (dom_sid_in_domain(state->domain_sid, sid)) {
1000 *authority_name = state->domain_name;
1001 *authority_sid = state->domain_sid;
1002 return NT_STATUS_OK;
1005 if (dom_sid_in_domain(state->builtin_sid, sid)) {
1006 *authority_name = "BUILTIN";
1007 *authority_sid = state->builtin_sid;
1008 return NT_STATUS_OK;
1011 *authority_sid = dom_sid_dup(mem_ctx, sid);
1012 if (*authority_sid == NULL) {
1013 return NT_STATUS_NO_MEMORY;
1015 (*authority_sid)->num_auths = 0;
1016 *authority_name = dom_sid_string(mem_ctx, *authority_sid);
1017 if (*authority_name == NULL) {
1018 return NT_STATUS_NO_MEMORY;
1021 return NT_STATUS_OK;
1025 add to the lsa_RefDomainList for LookupSids and LookupNames
1027 static NTSTATUS lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1028 struct dom_sid *sid,
1029 struct lsa_RefDomainList *domains,
1030 uint32_t *sid_index)
1033 const char *authority_name;
1034 struct dom_sid *authority_sid;
1037 /* work out the authority name */
1038 status = lsa_authority_name(state, mem_ctx, sid,
1039 &authority_name, &authority_sid);
1040 if (!NT_STATUS_IS_OK(status)) {
1044 /* see if we've already done this authority name */
1045 for (i=0;i<domains->count;i++) {
1046 if (strcmp(authority_name, domains->domains[i].name.string) == 0) {
1048 return NT_STATUS_OK;
1052 domains->domains = talloc_realloc(domains,
1054 struct lsa_TrustInformation,
1056 if (domains->domains == NULL) {
1057 return NT_STATUS_NO_MEMORY;
1059 domains->domains[i].name.string = authority_name;
1060 domains->domains[i].sid = authority_sid;
1064 return NT_STATUS_OK;
1068 lookup a name for 1 SID
1070 static NTSTATUS lsa_lookup_sid(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1071 struct dom_sid *sid, const char *sid_str,
1072 const char **name, uint32_t *atype)
1075 struct ldb_message **res;
1076 const char * const attrs[] = { "sAMAccountName", "sAMAccountType", "name", NULL};
1079 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1080 "objectSid=%s", ldap_encode_ndr_dom_sid(mem_ctx, sid));
1082 *name = ldb_msg_find_string(res[0], "sAMAccountName", NULL);
1084 *name = ldb_msg_find_string(res[0], "name", NULL);
1086 *name = talloc_strdup(mem_ctx, sid_str);
1087 NTSTATUS_TALLOC_CHECK(*name);
1091 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1093 return NT_STATUS_OK;
1096 status = sidmap_allocated_sid_lookup(state->sidmap, mem_ctx, sid, name, atype);
1105 static NTSTATUS lsa_LookupSids3(struct dcesrv_call_state *dce_call,
1106 TALLOC_CTX *mem_ctx,
1107 struct lsa_LookupSids3 *r)
1109 struct lsa_policy_state *state;
1111 NTSTATUS status = NT_STATUS_OK;
1113 r->out.domains = NULL;
1115 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
1116 if (!NT_STATUS_IS_OK(status)) {
1120 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
1121 if (r->out.domains == NULL) {
1122 return NT_STATUS_NO_MEMORY;
1125 r->out.names = talloc_zero(mem_ctx, struct lsa_TransNameArray2);
1126 if (r->out.names == NULL) {
1127 return NT_STATUS_NO_MEMORY;
1132 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName2,
1133 r->in.sids->num_sids);
1134 if (r->out.names->names == NULL) {
1135 return NT_STATUS_NO_MEMORY;
1138 for (i=0;i<r->in.sids->num_sids;i++) {
1139 struct dom_sid *sid = r->in.sids->sids[i].sid;
1140 char *sid_str = dom_sid_string(mem_ctx, sid);
1142 uint32_t atype, rtype, sid_index;
1145 r->out.names->count++;
1148 r->out.names->names[i].sid_type = SID_NAME_UNKNOWN;
1149 r->out.names->names[i].name.string = sid_str;
1150 r->out.names->names[i].sid_index = 0xFFFFFFFF;
1151 r->out.names->names[i].unknown = 0;
1153 if (sid_str == NULL) {
1154 r->out.names->names[i].name.string = "(SIDERROR)";
1155 status = STATUS_SOME_UNMAPPED;
1159 /* work out the authority name */
1160 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1161 if (!NT_STATUS_IS_OK(status2)) {
1165 status2 = lsa_lookup_sid(state, mem_ctx, sid, sid_str,
1167 if (!NT_STATUS_IS_OK(status2)) {
1168 status = STATUS_SOME_UNMAPPED;
1172 rtype = samdb_atype_map(atype);
1173 if (rtype == SID_NAME_UNKNOWN) {
1174 status = STATUS_SOME_UNMAPPED;
1178 r->out.names->names[i].sid_type = rtype;
1179 r->out.names->names[i].name.string = name;
1180 r->out.names->names[i].sid_index = sid_index;
1181 r->out.names->names[i].unknown = 0;
1191 static NTSTATUS lsa_LookupSids2(struct dcesrv_call_state *dce_call,
1192 TALLOC_CTX *mem_ctx,
1193 struct lsa_LookupSids2 *r)
1195 struct lsa_LookupSids3 r3;
1198 r3.in.sids = r->in.sids;
1199 r3.in.names = r->in.names;
1200 r3.in.level = r->in.level;
1201 r3.in.count = r->in.count;
1202 r3.in.unknown1 = r->in.unknown1;
1203 r3.in.unknown2 = r->in.unknown2;
1204 r3.out.count = r->out.count;
1205 r3.out.names = r->out.names;
1207 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1208 if (dce_call->fault_code != 0) {
1212 r->out.domains = r3.out.domains;
1213 r->out.names = r3.out.names;
1214 r->out.count = r3.out.count;
1223 static NTSTATUS lsa_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1224 struct lsa_LookupSids *r)
1226 struct lsa_LookupSids3 r3;
1230 r3.in.sids = r->in.sids;
1232 r3.in.level = r->in.level;
1233 r3.in.count = r->in.count;
1236 r3.out.count = r->out.count;
1237 r3.out.names = NULL;
1239 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1240 if (dce_call->fault_code != 0) {
1244 r->out.domains = r3.out.domains;
1245 if (!r3.out.names) {
1246 r->out.names = NULL;
1250 r->out.names = talloc(mem_ctx, struct lsa_TransNameArray);
1251 if (r->out.names == NULL) {
1252 return NT_STATUS_NO_MEMORY;
1254 r->out.names->count = r3.out.names->count;
1255 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName,
1256 r->out.names->count);
1257 if (r->out.names->names == NULL) {
1258 return NT_STATUS_NO_MEMORY;
1260 for (i=0;i<r->out.names->count;i++) {
1261 r->out.names->names[i].sid_type = r3.out.names->names[i].sid_type;
1262 r->out.names->names[i].name.string = r3.out.names->names[i].name.string;
1263 r->out.names->names[i].sid_index = r3.out.names->names[i].sid_index;
1273 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1274 struct lsa_OpenAccount *r)
1276 struct dcesrv_handle *h, *ah;
1277 struct lsa_policy_state *state;
1278 struct lsa_account_state *astate;
1280 ZERO_STRUCTP(r->out.acct_handle);
1282 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1286 astate = talloc(dce_call->conn, struct lsa_account_state);
1287 if (astate == NULL) {
1288 return NT_STATUS_NO_MEMORY;
1291 astate->account_sid = dom_sid_dup(astate, r->in.sid);
1292 if (astate->account_sid == NULL) {
1293 talloc_free(astate);
1294 return NT_STATUS_NO_MEMORY;
1297 /* check it really exists */
1298 astate->account_dn = samdb_search_dn(state->sam_ldb, astate,
1299 NULL, "(&(objectSid=%s)(objectClass=group))",
1300 ldap_encode_ndr_dom_sid(mem_ctx, astate->account_sid));
1301 if (astate->account_dn == NULL) {
1302 talloc_free(astate);
1303 return NT_STATUS_NO_SUCH_USER;
1306 astate->policy = talloc_reference(astate, state);
1307 astate->access_mask = r->in.access_mask;
1309 ah = dcesrv_handle_new(dce_call->context, LSA_HANDLE_ACCOUNT);
1311 talloc_free(astate);
1312 return NT_STATUS_NO_MEMORY;
1315 ah->data = talloc_steal(ah, astate);
1317 *r->out.acct_handle = ah->wire_handle;
1319 return NT_STATUS_OK;
1324 lsa_EnumPrivsAccount
1326 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
1327 TALLOC_CTX *mem_ctx,
1328 struct lsa_EnumPrivsAccount *r)
1330 struct dcesrv_handle *h;
1331 struct lsa_account_state *astate;
1333 struct ldb_message **res;
1334 const char * const attrs[] = { "privilege", NULL};
1335 struct ldb_message_element *el;
1337 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1341 r->out.privs = talloc(mem_ctx, struct lsa_PrivilegeSet);
1342 r->out.privs->count = 0;
1343 r->out.privs->unknown = 0;
1344 r->out.privs->set = NULL;
1346 ret = gendb_search_dn(astate->policy->sam_ldb, mem_ctx,
1347 astate->account_dn, &res, attrs);
1349 return NT_STATUS_OK;
1352 el = ldb_msg_find_element(res[0], "privilege");
1353 if (el == NULL || el->num_values == 0) {
1354 return NT_STATUS_OK;
1357 r->out.privs->set = talloc_array(r->out.privs,
1358 struct lsa_LUIDAttribute, el->num_values);
1359 if (r->out.privs->set == NULL) {
1360 return NT_STATUS_NO_MEMORY;
1363 for (i=0;i<el->num_values;i++) {
1364 int id = sec_privilege_id((const char *)el->values[i].data);
1366 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1368 r->out.privs->set[i].attribute = 0;
1369 r->out.privs->set[i].luid.low = id;
1370 r->out.privs->set[i].luid.high = 0;
1373 r->out.privs->count = el->num_values;
1375 return NT_STATUS_OK;
1379 lsa_EnumAccountRights
1381 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
1382 TALLOC_CTX *mem_ctx,
1383 struct lsa_EnumAccountRights *r)
1385 struct dcesrv_handle *h;
1386 struct lsa_policy_state *state;
1388 struct ldb_message **res;
1389 const char * const attrs[] = { "privilege", NULL};
1391 struct ldb_message_element *el;
1393 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1397 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, r->in.sid);
1398 if (sidstr == NULL) {
1399 return NT_STATUS_NO_MEMORY;
1402 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1403 "objectSid=%s", sidstr);
1405 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1408 el = ldb_msg_find_element(res[0], "privilege");
1409 if (el == NULL || el->num_values == 0) {
1410 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1413 r->out.rights->count = el->num_values;
1414 r->out.rights->names = talloc_array(r->out.rights,
1415 struct lsa_StringLarge, r->out.rights->count);
1416 if (r->out.rights->names == NULL) {
1417 return NT_STATUS_NO_MEMORY;
1420 for (i=0;i<el->num_values;i++) {
1421 r->out.rights->names[i].string = (const char *)el->values[i].data;
1424 return NT_STATUS_OK;
1430 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
1432 static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
1433 TALLOC_CTX *mem_ctx,
1434 struct lsa_policy_state *state,
1436 struct dom_sid *sid,
1437 const struct lsa_RightSet *rights)
1440 struct ldb_message *msg;
1441 struct ldb_message_element el;
1443 struct lsa_EnumAccountRights r2;
1445 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
1446 if (sidstr == NULL) {
1447 return NT_STATUS_NO_MEMORY;
1450 msg = ldb_msg_new(mem_ctx);
1452 return NT_STATUS_NO_MEMORY;
1455 msg->dn = samdb_search_dn(state->sam_ldb, mem_ctx, NULL, "objectSid=%s", sidstr);
1456 if (msg->dn == NULL) {
1457 return NT_STATUS_NO_SUCH_USER;
1460 if (ldb_msg_add_empty(msg, "privilege", ldb_flag)) {
1461 return NT_STATUS_NO_MEMORY;
1464 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1467 r2.in.handle = &state->handle->wire_handle;
1469 r2.out.rights = talloc(mem_ctx, struct lsa_RightSet);
1471 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1472 if (!NT_STATUS_IS_OK(status)) {
1473 ZERO_STRUCTP(r2.out.rights);
1478 el.values = talloc_array(mem_ctx, struct ldb_val, rights->count);
1479 if (el.values == NULL) {
1480 return NT_STATUS_NO_MEMORY;
1482 for (i=0;i<rights->count;i++) {
1483 if (sec_privilege_id(rights->names[i].string) == -1) {
1484 return NT_STATUS_NO_SUCH_PRIVILEGE;
1487 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1489 for (j=0;j<r2.out.rights->count;j++) {
1490 if (strcasecmp_m(r2.out.rights->names[j].string,
1491 rights->names[i].string) == 0) {
1495 if (j != r2.out.rights->count) continue;
1499 el.values[el.num_values].length = strlen(rights->names[i].string);
1500 el.values[el.num_values].data = (uint8_t *)talloc_strdup(mem_ctx, rights->names[i].string);
1501 if (el.values[el.num_values].data == NULL) {
1502 return NT_STATUS_NO_MEMORY;
1507 if (el.num_values == 0) {
1508 return NT_STATUS_OK;
1511 ret = samdb_modify(state->sam_ldb, mem_ctx, msg);
1513 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1514 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1516 return NT_STATUS_UNEXPECTED_IO_ERROR;
1519 return NT_STATUS_OK;
1523 lsa_AddPrivilegesToAccount
1525 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1526 struct lsa_AddPrivilegesToAccount *r)
1528 struct lsa_RightSet rights;
1529 struct dcesrv_handle *h;
1530 struct lsa_account_state *astate;
1533 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1537 rights.count = r->in.privs->count;
1538 rights.names = talloc_array(mem_ctx, struct lsa_StringLarge, rights.count);
1539 if (rights.names == NULL) {
1540 return NT_STATUS_NO_MEMORY;
1542 for (i=0;i<rights.count;i++) {
1543 int id = r->in.privs->set[i].luid.low;
1544 if (r->in.privs->set[i].luid.high) {
1545 return NT_STATUS_NO_SUCH_PRIVILEGE;
1547 rights.names[i].string = sec_privilege_name(id);
1548 if (rights.names[i].string == NULL) {
1549 return NT_STATUS_NO_SUCH_PRIVILEGE;
1553 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1554 LDB_FLAG_MOD_ADD, astate->account_sid,
1560 lsa_RemovePrivilegesFromAccount
1562 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1563 struct lsa_RemovePrivilegesFromAccount *r)
1565 struct lsa_RightSet *rights;
1566 struct dcesrv_handle *h;
1567 struct lsa_account_state *astate;
1570 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1574 rights = talloc(mem_ctx, struct lsa_RightSet);
1576 if (r->in.remove_all == 1 &&
1577 r->in.privs == NULL) {
1578 struct lsa_EnumAccountRights r2;
1581 r2.in.handle = &astate->policy->handle->wire_handle;
1582 r2.in.sid = astate->account_sid;
1583 r2.out.rights = rights;
1585 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1586 if (!NT_STATUS_IS_OK(status)) {
1590 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1591 LDB_FLAG_MOD_DELETE, astate->account_sid,
1595 if (r->in.remove_all != 0) {
1596 return NT_STATUS_INVALID_PARAMETER;
1599 rights->count = r->in.privs->count;
1600 rights->names = talloc_array(mem_ctx, struct lsa_StringLarge, rights->count);
1601 if (rights->names == NULL) {
1602 return NT_STATUS_NO_MEMORY;
1604 for (i=0;i<rights->count;i++) {
1605 int id = r->in.privs->set[i].luid.low;
1606 if (r->in.privs->set[i].luid.high) {
1607 return NT_STATUS_NO_SUCH_PRIVILEGE;
1609 rights->names[i].string = sec_privilege_name(id);
1610 if (rights->names[i].string == NULL) {
1611 return NT_STATUS_NO_SUCH_PRIVILEGE;
1615 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1616 LDB_FLAG_MOD_DELETE, astate->account_sid,
1622 lsa_GetQuotasForAccount
1624 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1625 struct lsa_GetQuotasForAccount *r)
1627 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1632 lsa_SetQuotasForAccount
1634 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1635 struct lsa_SetQuotasForAccount *r)
1637 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1642 lsa_GetSystemAccessAccount
1644 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1645 struct lsa_GetSystemAccessAccount *r)
1647 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1652 lsa_SetSystemAccessAccount
1654 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1655 struct lsa_SetSystemAccessAccount *r)
1657 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1664 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1665 struct lsa_CreateSecret *r)
1667 struct dcesrv_handle *policy_handle;
1668 struct lsa_policy_state *policy_state;
1669 struct lsa_secret_state *secret_state;
1670 struct dcesrv_handle *handle;
1671 struct ldb_message **msgs, *msg;
1672 const char *attrs[] = {
1680 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1681 ZERO_STRUCTP(r->out.sec_handle);
1683 policy_state = policy_handle->data;
1685 if (!r->in.name.string) {
1686 return NT_STATUS_INVALID_PARAMETER;
1689 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1690 if (!secret_state) {
1691 return NT_STATUS_NO_MEMORY;
1693 secret_state->policy = policy_state;
1695 msg = ldb_msg_new(mem_ctx);
1697 return NT_STATUS_NO_MEMORY;
1700 if (strncmp("G$", r->in.name.string, 2) == 0) {
1702 name = &r->in.name.string[2];
1703 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1704 secret_state->global = True;
1706 if (strlen(name) < 1) {
1707 return NT_STATUS_INVALID_PARAMETER;
1710 name2 = talloc_asprintf(mem_ctx, "%s Secret", ldb_binary_encode_string(mem_ctx, name));
1711 /* search for the secret record */
1712 ret = gendb_search(secret_state->sam_ldb,
1713 mem_ctx, policy_state->system_dn, &msgs, attrs,
1714 "(&(cn=%s)(objectclass=secret))",
1717 return NT_STATUS_OBJECT_NAME_COLLISION;
1720 if (ret < 0 || ret > 1) {
1721 DEBUG(0,("Found %d records matching DN %s\n", ret,
1722 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1723 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1726 msg->dn = ldb_dn_build_child(mem_ctx, "cn", name2, policy_state->system_dn);
1727 if (!name2 || !msg->dn) {
1728 return NT_STATUS_NO_MEMORY;
1731 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name2);
1734 secret_state->global = False;
1736 name = r->in.name.string;
1737 if (strlen(name) < 1) {
1738 return NT_STATUS_INVALID_PARAMETER;
1741 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1742 /* search for the secret record */
1743 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1744 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1746 "(&(cn=%s)(objectclass=secret))",
1747 ldb_binary_encode_string(mem_ctx, name));
1749 return NT_STATUS_OBJECT_NAME_COLLISION;
1752 if (ret < 0 || ret > 1) {
1753 DEBUG(0,("Found %d records matching DN %s\n", ret,
1754 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1755 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1758 msg->dn = ldb_dn_string_compose(mem_ctx, NULL, "cn=%s,cn=LSA Secrets", name);
1759 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name);
1762 /* pull in all the template attributes. Note this is always from the global samdb */
1763 ret = samdb_copy_template(secret_state->policy->sam_ldb, mem_ctx, msg,
1764 "(&(name=TemplateSecret)(objectclass=secretTemplate))");
1766 DEBUG(0,("Failed to load TemplateSecret from samdb\n"));
1767 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1770 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "objectClass", "secret");
1772 secret_state->secret_dn = talloc_reference(secret_state, msg->dn);
1774 /* create the secret */
1775 ret = samdb_add(secret_state->sam_ldb, mem_ctx, msg);
1777 DEBUG(0,("Failed to create secret record %s\n",
1778 ldb_dn_linearize(mem_ctx, msg->dn)));
1779 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1782 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1784 return NT_STATUS_NO_MEMORY;
1787 handle->data = talloc_steal(handle, secret_state);
1789 secret_state->access_mask = r->in.access_mask;
1790 secret_state->policy = talloc_reference(secret_state, policy_state);
1792 *r->out.sec_handle = handle->wire_handle;
1794 return NT_STATUS_OK;
1801 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1802 struct lsa_OpenSecret *r)
1804 struct dcesrv_handle *policy_handle;
1806 struct lsa_policy_state *policy_state;
1807 struct lsa_secret_state *secret_state;
1808 struct dcesrv_handle *handle;
1809 struct ldb_message **msgs;
1810 const char *attrs[] = {
1818 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1819 ZERO_STRUCTP(r->out.sec_handle);
1820 policy_state = policy_handle->data;
1822 if (!r->in.name.string) {
1823 return NT_STATUS_INVALID_PARAMETER;
1826 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1827 if (!secret_state) {
1828 return NT_STATUS_NO_MEMORY;
1830 secret_state->policy = policy_state;
1832 if (strncmp("G$", r->in.name.string, 2) == 0) {
1833 name = &r->in.name.string[2];
1834 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1835 secret_state->global = True;
1837 if (strlen(name) < 1) {
1838 return NT_STATUS_INVALID_PARAMETER;
1841 /* search for the secret record */
1842 ret = gendb_search(secret_state->sam_ldb,
1843 mem_ctx, policy_state->system_dn, &msgs, attrs,
1844 "(&(cn=%s Secret)(objectclass=secret))",
1845 ldb_binary_encode_string(mem_ctx, name));
1847 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1851 DEBUG(0,("Found %d records matching DN %s\n", ret,
1852 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1853 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1857 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1859 secret_state->global = False;
1860 name = r->in.name.string;
1861 if (strlen(name) < 1) {
1862 return NT_STATUS_INVALID_PARAMETER;
1865 /* search for the secret record */
1866 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1867 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1869 "(&(cn=%s)(objectclass=secret))",
1870 ldb_binary_encode_string(mem_ctx, name));
1872 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1876 DEBUG(0,("Found %d records matching DN %s\n", ret,
1877 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1878 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1882 secret_state->secret_dn = talloc_reference(secret_state, msgs[0]->dn);
1884 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1886 return NT_STATUS_NO_MEMORY;
1889 handle->data = talloc_steal(handle, secret_state);
1891 secret_state->access_mask = r->in.access_mask;
1892 secret_state->policy = talloc_reference(secret_state, policy_state);
1894 *r->out.sec_handle = handle->wire_handle;
1896 return NT_STATUS_OK;
1903 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1904 struct lsa_SetSecret *r)
1907 struct dcesrv_handle *h;
1908 struct lsa_secret_state *secret_state;
1909 struct ldb_message *msg;
1910 DATA_BLOB session_key;
1911 DATA_BLOB crypt_secret, secret;
1914 NTSTATUS status = NT_STATUS_OK;
1916 struct timeval now = timeval_current();
1917 NTTIME nt_now = timeval_to_nttime(&now);
1919 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
1921 secret_state = h->data;
1923 msg = ldb_msg_new(mem_ctx);
1925 return NT_STATUS_NO_MEMORY;
1928 msg->dn = talloc_reference(mem_ctx, secret_state->secret_dn);
1930 return NT_STATUS_NO_MEMORY;
1932 status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
1933 if (!NT_STATUS_IS_OK(status)) {
1937 if (r->in.old_val) {
1939 crypt_secret.data = r->in.old_val->data;
1940 crypt_secret.length = r->in.old_val->size;
1942 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
1943 if (!NT_STATUS_IS_OK(status)) {
1947 val.data = secret.data;
1948 val.length = secret.length;
1951 if (samdb_msg_add_value(secret_state->sam_ldb,
1952 mem_ctx, msg, "priorSecret", &val) != 0) {
1953 return NT_STATUS_NO_MEMORY;
1956 /* set old value mtime */
1957 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1958 mem_ctx, msg, "priorSetTime", nt_now) != 0) {
1959 return NT_STATUS_NO_MEMORY;
1962 if (!r->in.new_val) {
1963 /* This behaviour varies depending of if this is a local, or a global secret... */
1964 if (secret_state->global) {
1965 /* set old value mtime */
1966 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1967 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
1968 return NT_STATUS_NO_MEMORY;
1971 if (samdb_msg_add_delete(secret_state->sam_ldb,
1972 mem_ctx, msg, "secret")) {
1973 return NT_STATUS_NO_MEMORY;
1975 if (samdb_msg_add_delete(secret_state->sam_ldb,
1976 mem_ctx, msg, "lastSetTime")) {
1977 return NT_STATUS_NO_MEMORY;
1983 if (r->in.new_val) {
1985 crypt_secret.data = r->in.new_val->data;
1986 crypt_secret.length = r->in.new_val->size;
1988 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
1989 if (!NT_STATUS_IS_OK(status)) {
1993 val.data = secret.data;
1994 val.length = secret.length;
1997 if (samdb_msg_add_value(secret_state->sam_ldb,
1998 mem_ctx, msg, "secret", &val) != 0) {
1999 return NT_STATUS_NO_MEMORY;
2002 /* set new value mtime */
2003 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2004 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
2005 return NT_STATUS_NO_MEMORY;
2008 /* If the old value is not set, then migrate the
2009 * current value to the old value */
2010 if (!r->in.old_val) {
2011 const struct ldb_val *new_val;
2012 NTTIME last_set_time;
2013 struct ldb_message **res;
2014 const char *attrs[] = {
2020 /* search for the secret record */
2021 ret = gendb_search_dn(secret_state->sam_ldb,mem_ctx,
2022 secret_state->secret_dn, &res, attrs);
2024 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2028 DEBUG(0,("Found %d records matching dn=%s\n", ret,
2029 ldb_dn_linearize(mem_ctx, secret_state->secret_dn)));
2030 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2033 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2034 last_set_time = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2038 if (samdb_msg_add_value(secret_state->sam_ldb,
2039 mem_ctx, msg, "priorSecret",
2041 return NT_STATUS_NO_MEMORY;
2045 /* set new value mtime */
2046 if (ldb_msg_find_ldb_val(res[0], "lastSetTime")) {
2047 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2048 mem_ctx, msg, "priorSetTime", last_set_time) != 0) {
2049 return NT_STATUS_NO_MEMORY;
2055 /* modify the samdb record */
2056 ret = samdb_replace(secret_state->sam_ldb, mem_ctx, msg);
2058 /* we really need samdb.c to return NTSTATUS */
2059 return NT_STATUS_UNSUCCESSFUL;
2062 return NT_STATUS_OK;
2069 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2070 struct lsa_QuerySecret *r)
2072 struct dcesrv_handle *h;
2073 struct lsa_secret_state *secret_state;
2074 struct ldb_message *msg;
2075 DATA_BLOB session_key;
2076 DATA_BLOB crypt_secret, secret;
2078 struct ldb_message **res;
2079 const char *attrs[] = {
2089 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
2091 secret_state = h->data;
2093 /* pull all the user attributes */
2094 ret = gendb_search_dn(secret_state->sam_ldb, mem_ctx,
2095 secret_state->secret_dn, &res, attrs);
2097 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2101 nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
2102 if (!NT_STATUS_IS_OK(nt_status)) {
2106 if (r->in.old_val) {
2107 const struct ldb_val *prior_val;
2108 r->out.old_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2109 if (!r->out.old_val) {
2110 return NT_STATUS_NO_MEMORY;
2113 prior_val = ldb_msg_find_ldb_val(res[0], "priorSecret");
2115 if (prior_val && prior_val->length) {
2116 secret.data = prior_val->data;
2117 secret.length = prior_val->length;
2119 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2120 if (!crypt_secret.length) {
2121 return NT_STATUS_NO_MEMORY;
2123 r->out.old_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2124 if (!r->out.old_val->buf) {
2125 return NT_STATUS_NO_MEMORY;
2127 r->out.old_val->buf->size = crypt_secret.length;
2128 r->out.old_val->buf->length = crypt_secret.length;
2129 r->out.old_val->buf->data = crypt_secret.data;
2133 if (r->in.old_mtime) {
2134 r->out.old_mtime = talloc(mem_ctx, NTTIME);
2135 if (!r->out.old_mtime) {
2136 return NT_STATUS_NO_MEMORY;
2138 *r->out.old_mtime = ldb_msg_find_uint64(res[0], "priorSetTime", 0);
2141 if (r->in.new_val) {
2142 const struct ldb_val *new_val;
2143 r->out.new_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2144 if (!r->out.new_val) {
2145 return NT_STATUS_NO_MEMORY;
2149 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2151 if (new_val && new_val->length) {
2152 secret.data = new_val->data;
2153 secret.length = new_val->length;
2155 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2156 if (!crypt_secret.length) {
2157 return NT_STATUS_NO_MEMORY;
2159 r->out.new_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2160 if (!r->out.new_val->buf) {
2161 return NT_STATUS_NO_MEMORY;
2163 r->out.new_val->buf->length = crypt_secret.length;
2164 r->out.new_val->buf->size = crypt_secret.length;
2165 r->out.new_val->buf->data = crypt_secret.data;
2169 if (r->in.new_mtime) {
2170 r->out.new_mtime = talloc(mem_ctx, NTTIME);
2171 if (!r->out.new_mtime) {
2172 return NT_STATUS_NO_MEMORY;
2174 *r->out.new_mtime = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2177 return NT_STATUS_OK;
2184 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
2185 TALLOC_CTX *mem_ctx,
2186 struct lsa_LookupPrivValue *r)
2188 struct dcesrv_handle *h;
2189 struct lsa_policy_state *state;
2192 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2196 id = sec_privilege_id(r->in.name->string);
2198 return NT_STATUS_NO_SUCH_PRIVILEGE;
2201 r->out.luid->low = id;
2202 r->out.luid->high = 0;
2204 return NT_STATUS_OK;
2211 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
2212 TALLOC_CTX *mem_ctx,
2213 struct lsa_LookupPrivName *r)
2215 struct dcesrv_handle *h;
2216 struct lsa_policy_state *state;
2217 const char *privname;
2219 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2223 if (r->in.luid->high != 0) {
2224 return NT_STATUS_NO_SUCH_PRIVILEGE;
2227 privname = sec_privilege_name(r->in.luid->low);
2228 if (privname == NULL) {
2229 return NT_STATUS_NO_SUCH_PRIVILEGE;
2232 r->out.name = talloc(mem_ctx, struct lsa_StringLarge);
2233 if (r->out.name == NULL) {
2234 return NT_STATUS_NO_MEMORY;
2236 r->out.name->string = privname;
2238 return NT_STATUS_OK;
2243 lsa_LookupPrivDisplayName
2245 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
2246 TALLOC_CTX *mem_ctx,
2247 struct lsa_LookupPrivDisplayName *r)
2249 struct dcesrv_handle *h;
2250 struct lsa_policy_state *state;
2253 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2257 id = sec_privilege_id(r->in.name->string);
2259 return NT_STATUS_NO_SUCH_PRIVILEGE;
2262 r->out.disp_name = talloc(mem_ctx, struct lsa_StringLarge);
2263 if (r->out.disp_name == NULL) {
2264 return NT_STATUS_NO_MEMORY;
2267 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
2268 if (r->out.disp_name->string == NULL) {
2269 return NT_STATUS_INTERNAL_ERROR;
2272 return NT_STATUS_OK;
2279 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2280 struct lsa_DeleteObject *r)
2282 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2287 lsa_EnumAccountsWithUserRight
2289 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
2290 TALLOC_CTX *mem_ctx,
2291 struct lsa_EnumAccountsWithUserRight *r)
2293 struct dcesrv_handle *h;
2294 struct lsa_policy_state *state;
2296 struct ldb_message **res;
2297 const char * const attrs[] = { "objectSid", NULL};
2298 const char *privname;
2300 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2304 if (r->in.name == NULL) {
2305 return NT_STATUS_NO_SUCH_PRIVILEGE;
2308 privname = r->in.name->string;
2309 if (sec_privilege_id(privname) == -1) {
2310 return NT_STATUS_NO_SUCH_PRIVILEGE;
2313 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
2314 "privilege=%s", privname);
2316 return NT_STATUS_NO_SUCH_USER;
2319 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, ret);
2320 if (r->out.sids->sids == NULL) {
2321 return NT_STATUS_NO_MEMORY;
2323 for (i=0;i<ret;i++) {
2324 r->out.sids->sids[i].sid = samdb_result_dom_sid(r->out.sids->sids,
2325 res[i], "objectSid");
2326 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
2328 r->out.sids->num_sids = ret;
2330 return NT_STATUS_OK;
2335 lsa_AddAccountRights
2337 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
2338 TALLOC_CTX *mem_ctx,
2339 struct lsa_AddAccountRights *r)
2341 struct dcesrv_handle *h;
2342 struct lsa_policy_state *state;
2344 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2348 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2350 r->in.sid, r->in.rights);
2355 lsa_RemoveAccountRights
2357 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
2358 TALLOC_CTX *mem_ctx,
2359 struct lsa_RemoveAccountRights *r)
2361 struct dcesrv_handle *h;
2362 struct lsa_policy_state *state;
2364 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2368 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2369 LDB_FLAG_MOD_DELETE,
2370 r->in.sid, r->in.rights);
2375 lsa_StorePrivateData
2377 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2378 struct lsa_StorePrivateData *r)
2380 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2385 lsa_RetrievePrivateData
2387 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2388 struct lsa_RetrievePrivateData *r)
2390 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2397 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2398 struct lsa_GetUserName *r)
2400 NTSTATUS status = NT_STATUS_OK;
2401 const char *account_name;
2402 const char *authority_name;
2403 struct lsa_String *_account_name;
2404 struct lsa_StringPointer *_authority_name = NULL;
2406 /* this is what w2k3 does */
2407 r->out.account_name = r->in.account_name;
2408 r->out.authority_name = r->in.authority_name;
2410 if (r->in.account_name && r->in.account_name->string) {
2411 return NT_STATUS_INVALID_PARAMETER;
2414 if (r->in.authority_name &&
2415 r->in.authority_name->string &&
2416 r->in.authority_name->string->string) {
2417 return NT_STATUS_INVALID_PARAMETER;
2420 account_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->account_name);
2421 authority_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->domain_name);
2423 _account_name = talloc(mem_ctx, struct lsa_String);
2424 NTSTATUS_TALLOC_CHECK(_account_name);
2425 _account_name->string = account_name;
2427 if (r->in.authority_name) {
2428 _authority_name = talloc(mem_ctx, struct lsa_StringPointer);
2429 NTSTATUS_TALLOC_CHECK(_authority_name);
2430 _authority_name->string = talloc(mem_ctx, struct lsa_String);
2431 NTSTATUS_TALLOC_CHECK(_authority_name->string);
2432 _authority_name->string->string = authority_name;
2435 r->out.account_name = _account_name;
2436 r->out.authority_name = _authority_name;
2444 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
2445 TALLOC_CTX *mem_ctx,
2446 struct lsa_SetInfoPolicy2 *r)
2448 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2452 lsa_QueryDomainInformationPolicy
2454 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2455 TALLOC_CTX *mem_ctx,
2456 struct lsa_QueryDomainInformationPolicy *r)
2458 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2462 lsa_SetDomInfoPolicy
2464 static NTSTATUS lsa_SetDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2465 TALLOC_CTX *mem_ctx,
2466 struct lsa_SetDomainInformationPolicy *r)
2468 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2474 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
2475 TALLOC_CTX *mem_ctx,
2476 struct lsa_TestCall *r)
2478 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2482 lookup a SID for 1 name
2484 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
2485 const char *name, struct dom_sid **sid, uint32_t *atype)
2488 struct ldb_message **res;
2489 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
2492 p = strchr_m(name, '\\');
2494 /* TODO: properly parse the domain prefix here, and use it to
2499 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", ldb_binary_encode_string(mem_ctx, name));
2501 *sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
2503 return NT_STATUS_INVALID_SID;
2506 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
2508 return NT_STATUS_OK;
2511 /* need to add a call into sidmap to check for a allocated sid */
2513 return NT_STATUS_INVALID_SID;
2520 static NTSTATUS lsa_LookupNames4(struct dcesrv_call_state *dce_call,
2521 TALLOC_CTX *mem_ctx,
2522 struct lsa_LookupNames4 *r)
2524 struct lsa_policy_state *state;
2526 NTSTATUS status = NT_STATUS_OK;
2528 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
2529 if (!NT_STATUS_IS_OK(status)) {
2533 r->out.domains = NULL;
2535 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2536 if (r->out.domains == NULL) {
2537 return NT_STATUS_NO_MEMORY;
2540 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray3);
2541 if (r->out.sids == NULL) {
2542 return NT_STATUS_NO_MEMORY;
2547 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid3,
2549 if (r->out.sids->sids == NULL) {
2550 return NT_STATUS_NO_MEMORY;
2553 for (i=0;i<r->in.num_names;i++) {
2554 const char *name = r->in.names[i].string;
2555 struct dom_sid *sid;
2556 uint32_t atype, rtype, sid_index;
2559 r->out.sids->count++;
2562 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2563 r->out.sids->sids[i].sid = NULL;
2564 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2565 r->out.sids->sids[i].unknown = 0;
2567 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2568 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2569 status = STATUS_SOME_UNMAPPED;
2573 rtype = samdb_atype_map(atype);
2574 if (rtype == SID_NAME_UNKNOWN) {
2575 status = STATUS_SOME_UNMAPPED;
2579 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2580 if (!NT_STATUS_IS_OK(status2)) {
2584 r->out.sids->sids[i].sid_type = rtype;
2585 r->out.sids->sids[i].sid = sid;
2586 r->out.sids->sids[i].sid_index = sid_index;
2587 r->out.sids->sids[i].unknown = 0;
2596 static NTSTATUS lsa_LookupNames3(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2597 struct lsa_LookupNames3 *r)
2599 struct lsa_LookupNames4 r2;
2601 struct dcesrv_handle *h;
2602 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2604 r2.in.num_names = r->in.num_names;
2605 r2.in.names = r->in.names;
2606 r2.in.sids = r->in.sids;
2607 r2.in.count = r->in.count;
2608 r2.in.unknown1 = r->in.unknown1;
2609 r2.in.unknown2 = r->in.unknown2;
2610 r2.out.domains = r->out.domains;
2611 r2.out.sids = r->out.sids;
2612 r2.out.count = r->out.count;
2614 status = lsa_LookupNames4(dce_call, mem_ctx, &r2);
2615 if (dce_call->fault_code != 0) {
2619 r->out.domains = r2.out.domains;
2620 r->out.sids = r2.out.sids;
2621 r->out.count = r2.out.count;
2628 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
2629 TALLOC_CTX *mem_ctx,
2630 struct lsa_LookupNames2 *r)
2632 struct lsa_policy_state *state;
2633 struct dcesrv_handle *h;
2635 NTSTATUS status = NT_STATUS_OK;
2637 r->out.domains = NULL;
2639 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2643 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2644 if (r->out.domains == NULL) {
2645 return NT_STATUS_NO_MEMORY;
2648 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray2);
2649 if (r->out.sids == NULL) {
2650 return NT_STATUS_NO_MEMORY;
2655 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid2,
2657 if (r->out.sids->sids == NULL) {
2658 return NT_STATUS_NO_MEMORY;
2661 for (i=0;i<r->in.num_names;i++) {
2662 const char *name = r->in.names[i].string;
2663 struct dom_sid *sid;
2664 uint32_t atype, rtype, sid_index;
2667 r->out.sids->count++;
2670 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2671 r->out.sids->sids[i].rid = 0xFFFFFFFF;
2672 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2673 r->out.sids->sids[i].unknown = 0;
2675 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2676 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2677 status = STATUS_SOME_UNMAPPED;
2681 rtype = samdb_atype_map(atype);
2682 if (rtype == SID_NAME_UNKNOWN) {
2683 status = STATUS_SOME_UNMAPPED;
2687 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2688 if (!NT_STATUS_IS_OK(status2)) {
2692 r->out.sids->sids[i].sid_type = rtype;
2693 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
2694 r->out.sids->sids[i].sid_index = sid_index;
2695 r->out.sids->sids[i].unknown = 0;
2704 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2705 struct lsa_LookupNames *r)
2707 struct lsa_LookupNames2 r2;
2711 r2.in.handle = r->in.handle;
2712 r2.in.num_names = r->in.num_names;
2713 r2.in.names = r->in.names;
2715 r2.in.level = r->in.level;
2716 r2.in.count = r->in.count;
2719 r2.out.count = r->out.count;
2721 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
2722 if (dce_call->fault_code != 0) {
2726 r->out.domains = r2.out.domains;
2727 r->out.sids = talloc(mem_ctx, struct lsa_TransSidArray);
2728 if (r->out.sids == NULL) {
2729 return NT_STATUS_NO_MEMORY;
2731 r->out.sids->count = r2.out.sids->count;
2732 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid,
2733 r->out.sids->count);
2734 if (r->out.sids->sids == NULL) {
2735 return NT_STATUS_NO_MEMORY;
2737 for (i=0;i<r->out.sids->count;i++) {
2738 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
2739 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
2740 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
2749 static NTSTATUS lsa_CREDRWRITE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2750 struct lsa_CREDRWRITE *r)
2752 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2759 static NTSTATUS lsa_CREDRREAD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2760 struct lsa_CREDRREAD *r)
2762 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2769 static NTSTATUS lsa_CREDRENUMERATE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2770 struct lsa_CREDRENUMERATE *r)
2772 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2777 lsa_CREDRWRITEDOMAINCREDENTIALS
2779 static NTSTATUS lsa_CREDRWRITEDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2780 struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
2782 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2787 lsa_CREDRREADDOMAINCREDENTIALS
2789 static NTSTATUS lsa_CREDRREADDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2790 struct lsa_CREDRREADDOMAINCREDENTIALS *r)
2792 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2799 static NTSTATUS lsa_CREDRDELETE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2800 struct lsa_CREDRDELETE *r)
2802 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2807 lsa_CREDRGETTARGETINFO
2809 static NTSTATUS lsa_CREDRGETTARGETINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2810 struct lsa_CREDRGETTARGETINFO *r)
2812 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2817 lsa_CREDRPROFILELOADED
2819 static NTSTATUS lsa_CREDRPROFILELOADED(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2820 struct lsa_CREDRPROFILELOADED *r)
2822 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2827 lsa_CREDRGETSESSIONTYPES
2829 static NTSTATUS lsa_CREDRGETSESSIONTYPES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2830 struct lsa_CREDRGETSESSIONTYPES *r)
2832 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2837 lsa_LSARREGISTERAUDITEVENT
2839 static NTSTATUS lsa_LSARREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2840 struct lsa_LSARREGISTERAUDITEVENT *r)
2842 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2847 lsa_LSARGENAUDITEVENT
2849 static NTSTATUS lsa_LSARGENAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2850 struct lsa_LSARGENAUDITEVENT *r)
2852 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2857 lsa_LSARUNREGISTERAUDITEVENT
2859 static NTSTATUS lsa_LSARUNREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2860 struct lsa_LSARUNREGISTERAUDITEVENT *r)
2862 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2867 lsa_LSARQUERYFORESTTRUSTINFORMATION
2869 static NTSTATUS lsa_LSARQUERYFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2870 struct lsa_LSARQUERYFORESTTRUSTINFORMATION *r)
2872 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2877 lsa_LSARSETFORESTTRUSTINFORMATION
2879 static NTSTATUS lsa_LSARSETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2880 struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2882 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2889 static NTSTATUS lsa_CREDRRENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2890 struct lsa_CREDRRENAME *r)
2892 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2898 lsa_LSAROPENPOLICYSCE
2900 static NTSTATUS lsa_LSAROPENPOLICYSCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2901 struct lsa_LSAROPENPOLICYSCE *r)
2903 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2908 lsa_LSARADTREGISTERSECURITYEVENTSOURCE
2910 static NTSTATUS lsa_LSARADTREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2911 struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
2913 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2918 lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE
2920 static NTSTATUS lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2921 struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
2923 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2928 lsa_LSARADTREPORTSECURITYEVENT
2930 static NTSTATUS lsa_LSARADTREPORTSECURITYEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2931 struct lsa_LSARADTREPORTSECURITYEVENT *r)
2933 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2937 /* include the generated boilerplate */
2938 #include "librpc/gen_ndr/ndr_lsa_s.c"