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 "librpc/gen_ndr/ndr_lsa.h"
26 #include "librpc/gen_ndr/ndr_samr.h"
27 #include "rpc_server/dcerpc_server.h"
28 #include "rpc_server/common/common.h"
29 #include "lib/ldb/include/ldb.h"
30 #include "auth/auth.h"
31 #include "system/time.h"
35 this type allows us to distinguish handle types
41 LSA_HANDLE_TRUSTED_DOMAIN
45 state associated with a lsa_OpenPolicy() operation
47 struct lsa_policy_state {
48 struct dcesrv_handle *handle;
49 struct ldb_context *sam_ldb;
50 struct sidmap_context *sidmap;
52 const struct ldb_dn *domain_dn;
53 const struct ldb_dn *builtin_dn;
54 const struct ldb_dn *system_dn;
55 const char *domain_name;
56 struct dom_sid *domain_sid;
57 struct dom_sid *builtin_sid;
62 state associated with a lsa_OpenAccount() operation
64 struct lsa_account_state {
65 struct lsa_policy_state *policy;
67 struct dom_sid *account_sid;
68 const struct ldb_dn *account_dn;
73 state associated with a lsa_OpenSecret() operation
75 struct lsa_secret_state {
76 struct lsa_policy_state *policy;
78 const struct ldb_dn *secret_dn;
79 struct ldb_context *sam_ldb;
84 state associated with a lsa_OpenTrustedDomain() operation
86 struct lsa_trusted_domain_state {
87 struct lsa_policy_state *policy;
89 const struct ldb_dn *trusted_domain_dn;
95 static NTSTATUS lsa_Close(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
98 struct dcesrv_handle *h;
100 *r->out.handle = *r->in.handle;
102 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
106 ZERO_STRUCTP(r->out.handle);
115 static NTSTATUS lsa_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
116 struct lsa_Delete *r)
118 struct dcesrv_handle *h;
121 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
122 if (h->wire_handle.handle_type == LSA_HANDLE_SECRET) {
123 struct lsa_secret_state *secret_state = h->data;
124 ret = samdb_delete(secret_state->sam_ldb, mem_ctx, secret_state->secret_dn);
127 return NT_STATUS_INVALID_HANDLE;
131 } else if (h->wire_handle.handle_type == LSA_HANDLE_TRUSTED_DOMAIN) {
132 struct lsa_trusted_domain_state *trusted_domain_state = h->data;
133 ret = samdb_delete(trusted_domain_state->policy->sam_ldb, mem_ctx,
134 trusted_domain_state->trusted_domain_dn);
137 return NT_STATUS_INVALID_HANDLE;
143 return NT_STATUS_INVALID_HANDLE;
150 static NTSTATUS lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
151 struct lsa_EnumPrivs *r)
153 struct dcesrv_handle *h;
154 struct lsa_policy_state *state;
156 const char *privname;
158 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
162 i = *r->in.resume_handle;
165 while ((privname = sec_privilege_name(i)) &&
166 r->out.privs->count < r->in.max_count) {
167 struct lsa_PrivEntry *e;
169 r->out.privs->privs = talloc_realloc(r->out.privs,
171 struct lsa_PrivEntry,
172 r->out.privs->count+1);
173 if (r->out.privs->privs == NULL) {
174 return NT_STATUS_NO_MEMORY;
176 e = &r->out.privs->privs[r->out.privs->count];
179 e->name.string = privname;
180 r->out.privs->count++;
184 *r->out.resume_handle = i;
193 static NTSTATUS lsa_QuerySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
194 struct lsa_QuerySecurity *r)
196 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
203 static NTSTATUS lsa_SetSecObj(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
204 struct lsa_SetSecObj *r)
206 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
213 static NTSTATUS lsa_ChangePassword(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
214 struct lsa_ChangePassword *r)
216 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
219 static NTSTATUS lsa_get_policy_state(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
220 struct lsa_policy_state **_state)
222 struct lsa_policy_state *state;
223 const char *domain_attrs[] = {"nETBIOSName", "nCName", NULL};
225 struct ldb_message **msgs_domain;
227 state = talloc(mem_ctx, struct lsa_policy_state);
229 return NT_STATUS_NO_MEMORY;
232 /* make sure the sam database is accessible */
233 state->sam_ldb = samdb_connect(state);
234 if (state->sam_ldb == NULL) {
235 return NT_STATUS_INVALID_SYSTEM_SERVICE;
238 state->sidmap = sidmap_open(state);
239 if (state->sidmap == NULL) {
240 return NT_STATUS_INVALID_SYSTEM_SERVICE;
243 /* work out the domain_dn - useful for so many calls its worth
245 state->domain_dn = samdb_base_dn(state);
246 if (!state->domain_dn) {
247 return NT_STATUS_NO_MEMORY;
250 ret_domain = gendb_search(state->sam_ldb, mem_ctx, NULL, &msgs_domain, domain_attrs,
251 "(&(objectclass=crossRef)(ncName=%s))", ldb_dn_linearize(mem_ctx, state->domain_dn));
253 if (ret_domain == -1) {
254 return NT_STATUS_INTERNAL_DB_CORRUPTION;
257 if (ret_domain != 1) {
258 return NT_STATUS_NO_SUCH_DOMAIN;
261 /* work out the builtin_dn - useful for so many calls its worth
263 state->builtin_dn = samdb_search_dn(state->sam_ldb, mem_ctx, state->domain_dn, "(objectClass=builtinDomain)");
264 if (!state->builtin_dn) {
265 return NT_STATUS_NO_SUCH_DOMAIN;
268 /* work out the system_dn - useful for so many calls its worth
270 state->system_dn = samdb_search_dn(state->sam_ldb, mem_ctx,
271 state->domain_dn, "(&(objectClass=container)(cn=System))");
272 if (!state->system_dn) {
273 return NT_STATUS_NO_SUCH_DOMAIN;
276 state->domain_sid = talloc_steal(state,
277 samdb_search_dom_sid(state->sam_ldb, state,
278 state->domain_dn, "objectSid", "dn=%s",
279 ldb_dn_linearize(mem_ctx, state->domain_dn)));
280 if (!state->domain_sid) {
281 return NT_STATUS_NO_SUCH_DOMAIN;
284 state->builtin_sid = dom_sid_parse_talloc(state, SID_BUILTIN);
285 if (!state->builtin_sid) {
286 return NT_STATUS_NO_SUCH_DOMAIN;
289 state->domain_name = talloc_strdup(state,
290 samdb_result_string(msgs_domain[0], "nETBIOSName",
301 static NTSTATUS lsa_OpenPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
302 struct lsa_OpenPolicy2 *r)
305 struct lsa_policy_state *state;
306 struct dcesrv_handle *handle;
308 ZERO_STRUCTP(r->out.handle);
310 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
311 if (!NT_STATUS_IS_OK(status)) {
315 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_POLICY);
317 return NT_STATUS_NO_MEMORY;
320 handle->data = talloc_steal(handle, state);
322 state->access_mask = r->in.access_mask;
323 state->handle = handle;
324 *r->out.handle = handle->wire_handle;
326 /* note that we have completely ignored the attr element of
327 the OpenPolicy. As far as I can tell, this is what w2k3
335 a wrapper around lsa_OpenPolicy2
337 static NTSTATUS lsa_OpenPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
338 struct lsa_OpenPolicy *r)
340 struct lsa_OpenPolicy2 r2;
342 r2.in.system_name = NULL;
343 r2.in.attr = r->in.attr;
344 r2.in.access_mask = r->in.access_mask;
345 r2.out.handle = r->out.handle;
347 return lsa_OpenPolicy2(dce_call, mem_ctx, &r2);
354 fill in the AccountDomain info
356 static NTSTATUS lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
357 struct lsa_DomainInfo *info)
359 info->name.string = state->domain_name;
360 info->sid = state->domain_sid;
366 fill in the DNS domain info
368 static NTSTATUS lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
369 struct lsa_DnsDomainInfo *info)
371 const char * const attrs[] = { "dnsDomain", "objectGUID", "objectSid", NULL };
373 struct ldb_message **res;
375 ret = gendb_search_dn(state->sam_ldb, mem_ctx, state->domain_dn, &res, attrs);
377 return NT_STATUS_INTERNAL_DB_CORRUPTION;
380 info->name.string = state->domain_name;
381 info->sid = state->domain_sid;
382 info->dns_domain.string = samdb_result_string(res[0], "dnsDomain", NULL);
383 info->dns_forest.string = samdb_result_string(res[0], "dnsDomain", NULL);
384 info->domain_guid = samdb_result_guid(res[0], "objectGUID");
392 static NTSTATUS lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
393 struct lsa_QueryInfoPolicy2 *r)
395 struct lsa_policy_state *state;
396 struct dcesrv_handle *h;
400 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
404 r->out.info = talloc(mem_ctx, union lsa_PolicyInformation);
406 return NT_STATUS_NO_MEMORY;
409 ZERO_STRUCTP(r->out.info);
411 switch (r->in.level) {
412 case LSA_POLICY_INFO_DOMAIN:
413 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
414 return lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
416 case LSA_POLICY_INFO_DNS:
417 return lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
420 return NT_STATUS_INVALID_INFO_CLASS;
426 static NTSTATUS lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
427 struct lsa_QueryInfoPolicy *r)
429 struct lsa_QueryInfoPolicy2 r2;
432 r2.in.handle = r->in.handle;
433 r2.in.level = r->in.level;
435 status = lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
437 r->out.info = r2.out.info;
445 static NTSTATUS lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
446 struct lsa_SetInfoPolicy *r)
448 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
455 static NTSTATUS lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
456 struct lsa_ClearAuditLog *r)
458 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
465 static NTSTATUS lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
466 struct lsa_CreateAccount *r)
468 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
475 static NTSTATUS lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
476 struct lsa_EnumAccounts *r)
478 struct dcesrv_handle *h;
479 struct lsa_policy_state *state;
481 struct ldb_message **res;
482 const char * const attrs[] = { "objectSid", NULL};
485 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
489 ret = gendb_search(state->sam_ldb, mem_ctx, state->builtin_dn, &res, attrs,
492 return NT_STATUS_NO_SUCH_USER;
495 if (*r->in.resume_handle >= ret) {
496 return NT_STATUS_NO_MORE_ENTRIES;
499 count = ret - *r->in.resume_handle;
500 if (count > r->in.num_entries) {
501 count = r->in.num_entries;
505 return NT_STATUS_NO_MORE_ENTRIES;
508 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, count);
509 if (r->out.sids->sids == NULL) {
510 return NT_STATUS_NO_MEMORY;
513 for (i=0;i<count;i++) {
514 r->out.sids->sids[i].sid =
515 samdb_result_dom_sid(r->out.sids->sids,
516 res[i + *r->in.resume_handle],
518 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
521 r->out.sids->num_sids = count;
522 *r->out.resume_handle = count + *r->in.resume_handle;
530 lsa_CreateTrustedDomainEx2
532 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
534 struct lsa_CreateTrustedDomainEx2 *r)
536 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
540 lsa_CreateTrustedDomainEx
542 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
544 struct lsa_CreateTrustedDomainEx *r)
546 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
550 lsa_CreateTrustedDomain
552 static NTSTATUS lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
553 struct lsa_CreateTrustedDomain *r)
555 struct dcesrv_handle *policy_handle;
556 struct lsa_policy_state *policy_state;
557 struct lsa_trusted_domain_state *trusted_domain_state;
558 struct dcesrv_handle *handle;
559 struct ldb_message **msgs, *msg;
560 const char *attrs[] = {
566 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
567 ZERO_STRUCTP(r->out.trustdom_handle);
569 policy_state = policy_handle->data;
571 if (!r->in.info->name.string) {
572 return NT_STATUS_INVALID_PARAMETER;
574 name = r->in.info->name.string;
576 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
577 if (!trusted_domain_state) {
578 return NT_STATUS_NO_MEMORY;
580 trusted_domain_state->policy = policy_state;
582 msg = ldb_msg_new(mem_ctx);
584 return NT_STATUS_NO_MEMORY;
587 /* search for the trusted_domain record */
588 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
589 mem_ctx, policy_state->system_dn, &msgs, attrs,
590 "(&(cn=%s)(objectclass=trustedDomain))",
591 r->in.info->name.string);
593 return NT_STATUS_OBJECT_NAME_COLLISION;
596 if (ret < 0 || ret > 1) {
597 DEBUG(0,("Found %d records matching DN %s\n", ret,
598 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
599 return NT_STATUS_INTERNAL_DB_CORRUPTION;
602 msg->dn = ldb_dn_build_child(mem_ctx, "cn",
603 r->in.info->name.string,
604 policy_state->system_dn);
606 return NT_STATUS_NO_MEMORY;
609 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "cn", name);
610 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "flatname", name);
612 if (r->in.info->sid) {
613 const char *sid_string = dom_sid_string(mem_ctx, r->in.info->sid);
615 return NT_STATUS_NO_MEMORY;
618 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "securityIdentifier", sid_string);
621 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "objectClass", "trustedDomain");
623 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msg->dn);
625 /* create the trusted_domain */
626 ret = samdb_add(trusted_domain_state->policy->sam_ldb, mem_ctx, msg);
628 DEBUG(0,("Failed to create trusted_domain record %s\n",
629 ldb_dn_linearize(mem_ctx, msg->dn)));
630 return NT_STATUS_INTERNAL_DB_CORRUPTION;
633 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
635 return NT_STATUS_NO_MEMORY;
638 handle->data = talloc_steal(handle, trusted_domain_state);
640 trusted_domain_state->access_mask = r->in.access_mask;
641 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
643 *r->out.trustdom_handle = handle->wire_handle;
649 lsa_OpenTrustedDomain
651 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
652 struct lsa_OpenTrustedDomain *r)
654 struct dcesrv_handle *policy_handle;
656 struct lsa_policy_state *policy_state;
657 struct lsa_trusted_domain_state *trusted_domain_state;
658 struct dcesrv_handle *handle;
659 struct ldb_message **msgs;
660 const char *attrs[] = {
664 const char *sid_string;
667 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
668 ZERO_STRUCTP(r->out.trustdom_handle);
669 policy_state = policy_handle->data;
671 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
672 if (!trusted_domain_state) {
673 return NT_STATUS_NO_MEMORY;
675 trusted_domain_state->policy = policy_state;
677 sid_string = dom_sid_string(mem_ctx, r->in.sid);
679 return NT_STATUS_NO_MEMORY;
682 /* search for the trusted_domain record */
683 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
684 mem_ctx, policy_state->system_dn, &msgs, attrs,
685 "(&(securityIdentifier=%s)(objectclass=trustedDomain))",
688 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
692 DEBUG(0,("Found %d records matching DN %s\n", ret,
693 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
694 return NT_STATUS_INTERNAL_DB_CORRUPTION;
697 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
699 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
701 return NT_STATUS_NO_MEMORY;
704 handle->data = talloc_steal(handle, trusted_domain_state);
706 trusted_domain_state->access_mask = r->in.access_mask;
707 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
709 *r->out.trustdom_handle = handle->wire_handle;
716 lsa_OpenTrustedDomainByName
718 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
720 struct lsa_OpenTrustedDomainByName *r)
722 struct dcesrv_handle *policy_handle;
724 struct lsa_policy_state *policy_state;
725 struct lsa_trusted_domain_state *trusted_domain_state;
726 struct dcesrv_handle *handle;
727 struct ldb_message **msgs;
728 const char *attrs[] = {
734 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
735 ZERO_STRUCTP(r->out.trustdom_handle);
736 policy_state = policy_handle->data;
738 if (!r->in.name.string) {
739 return NT_STATUS_INVALID_PARAMETER;
742 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
743 if (!trusted_domain_state) {
744 return NT_STATUS_NO_MEMORY;
746 trusted_domain_state->policy = policy_state;
748 /* search for the trusted_domain record */
749 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
750 mem_ctx, policy_state->system_dn, &msgs, attrs,
751 "(&(flatname=%s)(objectclass=trustedDomain))",
754 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
758 DEBUG(0,("Found %d records matching DN %s\n", ret,
759 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
760 return NT_STATUS_INTERNAL_DB_CORRUPTION;
763 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
765 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
767 return NT_STATUS_NO_MEMORY;
770 handle->data = talloc_steal(handle, trusted_domain_state);
772 trusted_domain_state->access_mask = r->in.access_mask;
773 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
775 *r->out.trustdom_handle = handle->wire_handle;
782 lsa_QueryTrustedDomainInfoBySid
784 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
785 struct lsa_QueryTrustedDomainInfoBySid *r)
787 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
792 lsa_SetTrustDomainInfo
794 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
795 struct lsa_SetTrustDomainInfo *r)
797 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
802 lsa_DeleteTrustDomain
804 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
805 struct lsa_DeleteTrustDomain *r)
807 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
812 lsa_QueryTrustedDomainInfo
814 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
815 struct lsa_QueryTrustedDomainInfo *r)
817 struct dcesrv_handle *h;
818 struct lsa_trusted_domain_state *trusted_domain_state;
819 struct ldb_message *msg;
821 struct ldb_message **res;
822 const char *attrs[] = {
826 "securityIdentifier",
830 DCESRV_PULL_HANDLE(h, r->in.trustdom_handle, LSA_HANDLE_TRUSTED_DOMAIN);
832 trusted_domain_state = h->data;
834 /* pull all the user attributes */
835 ret = gendb_search_dn(trusted_domain_state->policy->sam_ldb, mem_ctx,
836 trusted_domain_state->trusted_domain_dn, &res, attrs);
838 return NT_STATUS_INTERNAL_DB_CORRUPTION;
842 r->out.info = talloc(mem_ctx, union lsa_TrustedDomainInfo);
844 return NT_STATUS_NO_MEMORY;
846 switch (r->in.level) {
847 case LSA_TRUSTED_DOMAIN_INFO_NAME:
848 r->out.info->name.netbios_name.string
849 = samdb_result_string(msg, "flatname", NULL);
851 case LSA_TRUSTED_DOMAIN_INFO_POSIX_OFFSET:
852 r->out.info->posix_offset.posix_offset
853 = samdb_result_uint(msg, "posixOffset", 0);
856 /* oops, we don't want to return the info after all */
857 talloc_free(r->out.info);
859 return NT_STATUS_INVALID_INFO_CLASS;
867 lsa_SetInformationTrustedDomain
869 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
870 struct lsa_SetInformationTrustedDomain *r)
872 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
877 lsa_QueryTrustedDomainInfoByName
879 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
881 struct lsa_QueryTrustedDomainInfoByName *r)
883 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
887 lsa_SetTrustedDomainInfoByName
889 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
891 struct lsa_SetTrustedDomainInfoByName *r)
893 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
897 lsa_EnumTrustedDomainsEx
899 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
901 struct lsa_EnumTrustedDomainsEx *r)
903 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
907 lsa_CloseTrustedDomainEx
909 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
911 struct lsa_CloseTrustedDomainEx *r)
913 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
918 comparison function for sorting lsa_DomainInformation array
920 static int compare_DomainInformation(struct lsa_DomainInformation *e1, struct lsa_DomainInformation *e2)
922 return strcasecmp(e1->name.string, e2->name.string);
928 static NTSTATUS lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
929 struct lsa_EnumTrustDom *r)
931 struct dcesrv_handle *policy_handle;
932 struct lsa_DomainInformation *entries;
933 struct lsa_policy_state *policy_state;
934 struct ldb_message **domains;
935 const char *attrs[] = {
937 "securityIdentifier",
944 *r->out.resume_handle = 0;
946 r->out.domains->domains = NULL;
947 r->out.domains->count = 0;
949 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
951 policy_state = policy_handle->data;
953 /* search for all users in this domain. This could possibly be cached and
954 resumed based on resume_key */
955 count = gendb_search(policy_state->sam_ldb, mem_ctx, policy_state->system_dn, &domains, attrs,
956 "objectclass=trustedDomain");
958 return NT_STATUS_INTERNAL_DB_CORRUPTION;
960 if (count == 0 || r->in.max_size == 0) {
964 /* convert to lsa_DomainInformation format */
965 entries = talloc_array(mem_ctx, struct lsa_DomainInformation, count);
967 return NT_STATUS_NO_MEMORY;
969 for (i=0;i<count;i++) {
970 entries[i].sid = samdb_result_dom_sid(mem_ctx, domains[i], "securityIdentifier");
971 entries[i].name.string = samdb_result_string(domains[i], "flatname", NULL);
974 /* sort the results by name */
975 qsort(entries, count, sizeof(struct lsa_DomainInformation),
976 (comparison_fn_t)compare_DomainInformation);
978 if (*r->in.resume_handle >= count) {
979 *r->out.resume_handle = -1;
981 return NT_STATUS_NO_MORE_ENTRIES;
984 /* return the rest, limit by max_size. Note that we
985 use the w2k3 element size value of 60 */
986 r->out.domains->count = count - *r->in.resume_handle;
987 r->out.domains->count = MIN(r->out.domains->count,
988 1+(r->in.max_size/LSA_ENUM_TRUST_DOMAIN_MULTIPLIER));
990 r->out.domains->domains = entries + *r->in.resume_handle;
991 r->out.domains->count = r->out.domains->count;
993 if (r->out.domains->count < count - *r->in.resume_handle) {
994 *r->out.resume_handle = *r->in.resume_handle + r->out.domains->count;
995 return STATUS_MORE_ENTRIES;
1003 return the authority name and authority sid, given a sid
1005 static NTSTATUS lsa_authority_name(struct lsa_policy_state *state,
1006 TALLOC_CTX *mem_ctx, struct dom_sid *sid,
1007 const char **authority_name,
1008 struct dom_sid **authority_sid)
1010 if (dom_sid_in_domain(state->domain_sid, sid)) {
1011 *authority_name = state->domain_name;
1012 *authority_sid = state->domain_sid;
1013 return NT_STATUS_OK;
1016 if (dom_sid_in_domain(state->builtin_sid, sid)) {
1017 *authority_name = "BUILTIN";
1018 *authority_sid = state->builtin_sid;
1019 return NT_STATUS_OK;
1022 *authority_sid = dom_sid_dup(mem_ctx, sid);
1023 if (*authority_sid == NULL) {
1024 return NT_STATUS_NO_MEMORY;
1026 (*authority_sid)->num_auths = 0;
1027 *authority_name = dom_sid_string(mem_ctx, *authority_sid);
1028 if (*authority_name == NULL) {
1029 return NT_STATUS_NO_MEMORY;
1032 return NT_STATUS_OK;
1036 add to the lsa_RefDomainList for LookupSids and LookupNames
1038 static NTSTATUS lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1039 struct dom_sid *sid,
1040 struct lsa_RefDomainList *domains,
1041 uint32_t *sid_index)
1044 const char *authority_name;
1045 struct dom_sid *authority_sid;
1048 /* work out the authority name */
1049 status = lsa_authority_name(state, mem_ctx, sid,
1050 &authority_name, &authority_sid);
1051 if (!NT_STATUS_IS_OK(status)) {
1055 /* see if we've already done this authority name */
1056 for (i=0;i<domains->count;i++) {
1057 if (strcmp(authority_name, domains->domains[i].name.string) == 0) {
1059 return NT_STATUS_OK;
1063 domains->domains = talloc_realloc(domains,
1065 struct lsa_TrustInformation,
1067 if (domains->domains == NULL) {
1068 return NT_STATUS_NO_MEMORY;
1070 domains->domains[i].name.string = authority_name;
1071 domains->domains[i].sid = authority_sid;
1075 return NT_STATUS_OK;
1079 lookup a name for 1 SID
1081 static NTSTATUS lsa_lookup_sid(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1082 struct dom_sid *sid, const char *sid_str,
1083 const char **name, uint32_t *atype)
1086 struct ldb_message **res;
1087 const char * const attrs[] = { "sAMAccountName", "sAMAccountType", "name", NULL};
1090 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1091 "objectSid=%s", ldap_encode_ndr_dom_sid(mem_ctx, sid));
1093 *name = ldb_msg_find_string(res[0], "sAMAccountName", NULL);
1095 *name = ldb_msg_find_string(res[0], "name", NULL);
1097 *name = talloc_strdup(mem_ctx, sid_str);
1098 NTSTATUS_TALLOC_CHECK(*name);
1102 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1104 return NT_STATUS_OK;
1107 status = sidmap_allocated_sid_lookup(state->sidmap, mem_ctx, sid, name, atype);
1116 static NTSTATUS lsa_LookupSids3(struct dcesrv_call_state *dce_call,
1117 TALLOC_CTX *mem_ctx,
1118 struct lsa_LookupSids3 *r)
1120 struct lsa_policy_state *state;
1122 NTSTATUS status = NT_STATUS_OK;
1124 r->out.domains = NULL;
1126 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
1127 if (!NT_STATUS_IS_OK(status)) {
1131 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
1132 if (r->out.domains == NULL) {
1133 return NT_STATUS_NO_MEMORY;
1136 r->out.names = talloc_zero(mem_ctx, struct lsa_TransNameArray2);
1137 if (r->out.names == NULL) {
1138 return NT_STATUS_NO_MEMORY;
1143 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName2,
1144 r->in.sids->num_sids);
1145 if (r->out.names->names == NULL) {
1146 return NT_STATUS_NO_MEMORY;
1149 for (i=0;i<r->in.sids->num_sids;i++) {
1150 struct dom_sid *sid = r->in.sids->sids[i].sid;
1151 char *sid_str = dom_sid_string(mem_ctx, sid);
1153 uint32_t atype, rtype, sid_index;
1156 r->out.names->count++;
1159 r->out.names->names[i].sid_type = SID_NAME_UNKNOWN;
1160 r->out.names->names[i].name.string = sid_str;
1161 r->out.names->names[i].sid_index = 0xFFFFFFFF;
1162 r->out.names->names[i].unknown = 0;
1164 if (sid_str == NULL) {
1165 r->out.names->names[i].name.string = "(SIDERROR)";
1166 status = STATUS_SOME_UNMAPPED;
1170 /* work out the authority name */
1171 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1172 if (!NT_STATUS_IS_OK(status2)) {
1176 status2 = lsa_lookup_sid(state, mem_ctx, sid, sid_str,
1178 if (!NT_STATUS_IS_OK(status2)) {
1179 status = STATUS_SOME_UNMAPPED;
1183 rtype = samdb_atype_map(atype);
1184 if (rtype == SID_NAME_UNKNOWN) {
1185 status = STATUS_SOME_UNMAPPED;
1189 r->out.names->names[i].sid_type = rtype;
1190 r->out.names->names[i].name.string = name;
1191 r->out.names->names[i].sid_index = sid_index;
1192 r->out.names->names[i].unknown = 0;
1202 static NTSTATUS lsa_LookupSids2(struct dcesrv_call_state *dce_call,
1203 TALLOC_CTX *mem_ctx,
1204 struct lsa_LookupSids2 *r)
1206 struct lsa_LookupSids3 r3;
1209 r3.in.sids = r->in.sids;
1210 r3.in.names = r->in.names;
1211 r3.in.level = r->in.level;
1212 r3.in.count = r->in.count;
1213 r3.in.unknown1 = r->in.unknown1;
1214 r3.in.unknown2 = r->in.unknown2;
1215 r3.out.count = r->out.count;
1216 r3.out.names = r->out.names;
1218 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1219 if (dce_call->fault_code != 0) {
1223 r->out.domains = r3.out.domains;
1224 r->out.names = r3.out.names;
1225 r->out.count = r3.out.count;
1234 static NTSTATUS lsa_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1235 struct lsa_LookupSids *r)
1237 struct lsa_LookupSids3 r3;
1241 r3.in.sids = r->in.sids;
1243 r3.in.level = r->in.level;
1244 r3.in.count = r->in.count;
1247 r3.out.count = r->out.count;
1248 r3.out.names = NULL;
1250 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1251 if (dce_call->fault_code != 0) {
1255 r->out.domains = r3.out.domains;
1256 if (!r3.out.names) {
1257 r->out.names = NULL;
1261 r->out.names = talloc(mem_ctx, struct lsa_TransNameArray);
1262 if (r->out.names == NULL) {
1263 return NT_STATUS_NO_MEMORY;
1265 r->out.names->count = r3.out.names->count;
1266 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName,
1267 r->out.names->count);
1268 if (r->out.names->names == NULL) {
1269 return NT_STATUS_NO_MEMORY;
1271 for (i=0;i<r->out.names->count;i++) {
1272 r->out.names->names[i].sid_type = r3.out.names->names[i].sid_type;
1273 r->out.names->names[i].name.string = r3.out.names->names[i].name.string;
1274 r->out.names->names[i].sid_index = r3.out.names->names[i].sid_index;
1284 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1285 struct lsa_OpenAccount *r)
1287 struct dcesrv_handle *h, *ah;
1288 struct lsa_policy_state *state;
1289 struct lsa_account_state *astate;
1291 ZERO_STRUCTP(r->out.acct_handle);
1293 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1297 astate = talloc(dce_call->conn, struct lsa_account_state);
1298 if (astate == NULL) {
1299 return NT_STATUS_NO_MEMORY;
1302 astate->account_sid = dom_sid_dup(astate, r->in.sid);
1303 if (astate->account_sid == NULL) {
1304 talloc_free(astate);
1305 return NT_STATUS_NO_MEMORY;
1308 /* check it really exists */
1309 astate->account_dn = samdb_search_dn(state->sam_ldb, astate,
1310 NULL, "(&(objectSid=%s)(objectClass=group))",
1311 ldap_encode_ndr_dom_sid(mem_ctx, astate->account_sid));
1312 if (astate->account_dn == NULL) {
1313 talloc_free(astate);
1314 return NT_STATUS_NO_SUCH_USER;
1317 astate->policy = talloc_reference(astate, state);
1318 astate->access_mask = r->in.access_mask;
1320 ah = dcesrv_handle_new(dce_call->context, LSA_HANDLE_ACCOUNT);
1322 talloc_free(astate);
1323 return NT_STATUS_NO_MEMORY;
1326 ah->data = talloc_steal(ah, astate);
1328 *r->out.acct_handle = ah->wire_handle;
1330 return NT_STATUS_OK;
1335 lsa_EnumPrivsAccount
1337 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
1338 TALLOC_CTX *mem_ctx,
1339 struct lsa_EnumPrivsAccount *r)
1341 struct dcesrv_handle *h;
1342 struct lsa_account_state *astate;
1344 struct ldb_message **res;
1345 const char * const attrs[] = { "privilege", NULL};
1346 struct ldb_message_element *el;
1348 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1352 r->out.privs = talloc(mem_ctx, struct lsa_PrivilegeSet);
1353 r->out.privs->count = 0;
1354 r->out.privs->unknown = 0;
1355 r->out.privs->set = NULL;
1357 ret = gendb_search_dn(astate->policy->sam_ldb, mem_ctx,
1358 astate->account_dn, &res, attrs);
1360 return NT_STATUS_OK;
1363 el = ldb_msg_find_element(res[0], "privilege");
1364 if (el == NULL || el->num_values == 0) {
1365 return NT_STATUS_OK;
1368 r->out.privs->set = talloc_array(r->out.privs,
1369 struct lsa_LUIDAttribute, el->num_values);
1370 if (r->out.privs->set == NULL) {
1371 return NT_STATUS_NO_MEMORY;
1374 for (i=0;i<el->num_values;i++) {
1375 int id = sec_privilege_id((const char *)el->values[i].data);
1377 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1379 r->out.privs->set[i].attribute = 0;
1380 r->out.privs->set[i].luid.low = id;
1381 r->out.privs->set[i].luid.high = 0;
1384 r->out.privs->count = el->num_values;
1386 return NT_STATUS_OK;
1390 lsa_EnumAccountRights
1392 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
1393 TALLOC_CTX *mem_ctx,
1394 struct lsa_EnumAccountRights *r)
1396 struct dcesrv_handle *h;
1397 struct lsa_policy_state *state;
1399 struct ldb_message **res;
1400 const char * const attrs[] = { "privilege", NULL};
1402 struct ldb_message_element *el;
1404 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1408 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, r->in.sid);
1409 if (sidstr == NULL) {
1410 return NT_STATUS_NO_MEMORY;
1413 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1414 "objectSid=%s", sidstr);
1416 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1419 el = ldb_msg_find_element(res[0], "privilege");
1420 if (el == NULL || el->num_values == 0) {
1421 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1424 r->out.rights->count = el->num_values;
1425 r->out.rights->names = talloc_array(r->out.rights,
1426 struct lsa_String, r->out.rights->count);
1427 if (r->out.rights->names == NULL) {
1428 return NT_STATUS_NO_MEMORY;
1431 for (i=0;i<el->num_values;i++) {
1432 r->out.rights->names[i].string = (const char *)el->values[i].data;
1435 return NT_STATUS_OK;
1441 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
1443 static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
1444 TALLOC_CTX *mem_ctx,
1445 struct lsa_policy_state *state,
1447 struct dom_sid *sid,
1448 const struct lsa_RightSet *rights)
1451 struct ldb_message *msg;
1452 struct ldb_message_element el;
1454 struct lsa_EnumAccountRights r2;
1456 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
1457 if (sidstr == NULL) {
1458 return NT_STATUS_NO_MEMORY;
1461 msg = ldb_msg_new(mem_ctx);
1463 return NT_STATUS_NO_MEMORY;
1466 msg->dn = samdb_search_dn(state->sam_ldb, mem_ctx, NULL, "objectSid=%s", sidstr);
1467 if (msg->dn == NULL) {
1468 return NT_STATUS_NO_SUCH_USER;
1471 if (ldb_msg_add_empty(state->sam_ldb, msg, "privilege", ldb_flag)) {
1472 return NT_STATUS_NO_MEMORY;
1475 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1478 r2.in.handle = &state->handle->wire_handle;
1480 r2.out.rights = talloc(mem_ctx, struct lsa_RightSet);
1482 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1483 if (!NT_STATUS_IS_OK(status)) {
1484 ZERO_STRUCTP(r2.out.rights);
1489 el.values = talloc_array(mem_ctx, struct ldb_val, rights->count);
1490 if (el.values == NULL) {
1491 return NT_STATUS_NO_MEMORY;
1493 for (i=0;i<rights->count;i++) {
1494 if (sec_privilege_id(rights->names[i].string) == -1) {
1495 return NT_STATUS_NO_SUCH_PRIVILEGE;
1498 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1500 for (j=0;j<r2.out.rights->count;j++) {
1501 if (strcasecmp_m(r2.out.rights->names[j].string,
1502 rights->names[i].string) == 0) {
1506 if (j != r2.out.rights->count) continue;
1510 el.values[el.num_values].length = strlen(rights->names[i].string);
1511 el.values[el.num_values].data = (uint8_t *)talloc_strdup(mem_ctx, rights->names[i].string);
1512 if (el.values[el.num_values].data == NULL) {
1513 return NT_STATUS_NO_MEMORY;
1518 if (el.num_values == 0) {
1519 return NT_STATUS_OK;
1522 ret = samdb_modify(state->sam_ldb, mem_ctx, msg);
1524 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1525 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1527 return NT_STATUS_UNEXPECTED_IO_ERROR;
1530 return NT_STATUS_OK;
1534 lsa_AddPrivilegesToAccount
1536 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1537 struct lsa_AddPrivilegesToAccount *r)
1539 struct lsa_RightSet rights;
1540 struct dcesrv_handle *h;
1541 struct lsa_account_state *astate;
1544 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1548 rights.count = r->in.privs->count;
1549 rights.names = talloc_array(mem_ctx, struct lsa_String, rights.count);
1550 if (rights.names == NULL) {
1551 return NT_STATUS_NO_MEMORY;
1553 for (i=0;i<rights.count;i++) {
1554 int id = r->in.privs->set[i].luid.low;
1555 if (r->in.privs->set[i].luid.high) {
1556 return NT_STATUS_NO_SUCH_PRIVILEGE;
1558 rights.names[i].string = sec_privilege_name(id);
1559 if (rights.names[i].string == NULL) {
1560 return NT_STATUS_NO_SUCH_PRIVILEGE;
1564 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1565 LDB_FLAG_MOD_ADD, astate->account_sid,
1571 lsa_RemovePrivilegesFromAccount
1573 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1574 struct lsa_RemovePrivilegesFromAccount *r)
1576 struct lsa_RightSet *rights;
1577 struct dcesrv_handle *h;
1578 struct lsa_account_state *astate;
1581 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1585 rights = talloc(mem_ctx, struct lsa_RightSet);
1587 if (r->in.remove_all == 1 &&
1588 r->in.privs == NULL) {
1589 struct lsa_EnumAccountRights r2;
1592 r2.in.handle = &astate->policy->handle->wire_handle;
1593 r2.in.sid = astate->account_sid;
1594 r2.out.rights = rights;
1596 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1597 if (!NT_STATUS_IS_OK(status)) {
1601 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1602 LDB_FLAG_MOD_DELETE, astate->account_sid,
1606 if (r->in.remove_all != 0) {
1607 return NT_STATUS_INVALID_PARAMETER;
1610 rights->count = r->in.privs->count;
1611 rights->names = talloc_array(mem_ctx, struct lsa_String, rights->count);
1612 if (rights->names == NULL) {
1613 return NT_STATUS_NO_MEMORY;
1615 for (i=0;i<rights->count;i++) {
1616 int id = r->in.privs->set[i].luid.low;
1617 if (r->in.privs->set[i].luid.high) {
1618 return NT_STATUS_NO_SUCH_PRIVILEGE;
1620 rights->names[i].string = sec_privilege_name(id);
1621 if (rights->names[i].string == NULL) {
1622 return NT_STATUS_NO_SUCH_PRIVILEGE;
1626 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1627 LDB_FLAG_MOD_DELETE, astate->account_sid,
1633 lsa_GetQuotasForAccount
1635 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1636 struct lsa_GetQuotasForAccount *r)
1638 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1643 lsa_SetQuotasForAccount
1645 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1646 struct lsa_SetQuotasForAccount *r)
1648 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1653 lsa_GetSystemAccessAccount
1655 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1656 struct lsa_GetSystemAccessAccount *r)
1658 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1663 lsa_SetSystemAccessAccount
1665 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1666 struct lsa_SetSystemAccessAccount *r)
1668 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1675 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1676 struct lsa_CreateSecret *r)
1678 struct dcesrv_handle *policy_handle;
1679 struct lsa_policy_state *policy_state;
1680 struct lsa_secret_state *secret_state;
1681 struct dcesrv_handle *handle;
1682 struct ldb_message **msgs, *msg;
1683 const char *attrs[] = {
1691 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1692 ZERO_STRUCTP(r->out.sec_handle);
1694 policy_state = policy_handle->data;
1696 if (!r->in.name.string) {
1697 return NT_STATUS_INVALID_PARAMETER;
1700 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1701 if (!secret_state) {
1702 return NT_STATUS_NO_MEMORY;
1704 secret_state->policy = policy_state;
1706 msg = ldb_msg_new(mem_ctx);
1708 return NT_STATUS_NO_MEMORY;
1711 if (strncmp("G$", r->in.name.string, 2) == 0) {
1713 name = &r->in.name.string[2];
1714 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1715 secret_state->global = True;
1717 if (strlen(name) < 1) {
1718 return NT_STATUS_INVALID_PARAMETER;
1721 name2 = talloc_asprintf(mem_ctx, "%s Secret", name);
1722 /* search for the secret record */
1723 ret = gendb_search(secret_state->sam_ldb,
1724 mem_ctx, policy_state->system_dn, &msgs, attrs,
1725 "(&(cn=%s)(objectclass=secret))",
1728 return NT_STATUS_OBJECT_NAME_COLLISION;
1731 if (ret < 0 || ret > 1) {
1732 DEBUG(0,("Found %d records matching DN %s\n", ret,
1733 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1734 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1737 msg->dn = ldb_dn_build_child(mem_ctx, "cn", name2, policy_state->system_dn);
1738 if (!name2 || !msg->dn) {
1739 return NT_STATUS_NO_MEMORY;
1742 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name2);
1745 secret_state->global = False;
1747 name = r->in.name.string;
1748 if (strlen(name) < 1) {
1749 return NT_STATUS_INVALID_PARAMETER;
1752 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1753 /* search for the secret record */
1754 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1755 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1757 "(&(cn=%s)(objectclass=secret))", name);
1759 return NT_STATUS_OBJECT_NAME_COLLISION;
1762 if (ret < 0 || ret > 1) {
1763 DEBUG(0,("Found %d records matching DN %s\n", ret,
1764 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1765 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1768 msg->dn = ldb_dn_string_compose(mem_ctx, NULL, "cn=%s,cn=LSA Secrets", name);
1769 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name);
1772 /* pull in all the template attributes. Note this is always from the global samdb */
1773 ret = samdb_copy_template(secret_state->policy->sam_ldb, mem_ctx, msg,
1774 "(&(name=TemplateSecret)(objectclass=secretTemplate))");
1776 DEBUG(0,("Failed to load TemplateSecret from samdb\n"));
1777 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1780 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "objectClass", "secret");
1782 secret_state->secret_dn = talloc_reference(secret_state, msg->dn);
1784 /* create the secret */
1785 ret = samdb_add(secret_state->sam_ldb, mem_ctx, msg);
1787 DEBUG(0,("Failed to create secret record %s\n",
1788 ldb_dn_linearize(mem_ctx, msg->dn)));
1789 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1792 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1794 return NT_STATUS_NO_MEMORY;
1797 handle->data = talloc_steal(handle, secret_state);
1799 secret_state->access_mask = r->in.access_mask;
1800 secret_state->policy = talloc_reference(secret_state, policy_state);
1802 *r->out.sec_handle = handle->wire_handle;
1804 return NT_STATUS_OK;
1811 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1812 struct lsa_OpenSecret *r)
1814 struct dcesrv_handle *policy_handle;
1816 struct lsa_policy_state *policy_state;
1817 struct lsa_secret_state *secret_state;
1818 struct dcesrv_handle *handle;
1819 struct ldb_message **msgs;
1820 const char *attrs[] = {
1828 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1829 ZERO_STRUCTP(r->out.sec_handle);
1830 policy_state = policy_handle->data;
1832 if (!r->in.name.string) {
1833 return NT_STATUS_INVALID_PARAMETER;
1836 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1837 if (!secret_state) {
1838 return NT_STATUS_NO_MEMORY;
1840 secret_state->policy = policy_state;
1842 if (strncmp("G$", r->in.name.string, 2) == 0) {
1843 name = &r->in.name.string[2];
1844 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1845 secret_state->global = True;
1847 if (strlen(name) < 1) {
1848 return NT_STATUS_INVALID_PARAMETER;
1851 /* search for the secret record */
1852 ret = gendb_search(secret_state->sam_ldb,
1853 mem_ctx, policy_state->system_dn, &msgs, attrs,
1854 "(&(cn=%s Secret)(objectclass=secret))",
1857 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1861 DEBUG(0,("Found %d records matching DN %s\n", ret,
1862 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1863 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1867 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1869 secret_state->global = False;
1870 name = r->in.name.string;
1871 if (strlen(name) < 1) {
1872 return NT_STATUS_INVALID_PARAMETER;
1875 /* search for the secret record */
1876 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1877 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1879 "(&(cn=%s)(objectclass=secret))", name);
1881 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1885 DEBUG(0,("Found %d records matching DN %s\n", ret,
1886 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1887 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1891 secret_state->secret_dn = talloc_reference(secret_state, msgs[0]->dn);
1893 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1895 return NT_STATUS_NO_MEMORY;
1898 handle->data = talloc_steal(handle, secret_state);
1900 secret_state->access_mask = r->in.access_mask;
1901 secret_state->policy = talloc_reference(secret_state, policy_state);
1903 *r->out.sec_handle = handle->wire_handle;
1905 return NT_STATUS_OK;
1912 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1913 struct lsa_SetSecret *r)
1916 struct dcesrv_handle *h;
1917 struct lsa_secret_state *secret_state;
1918 struct ldb_message *msg;
1919 DATA_BLOB session_key;
1920 DATA_BLOB crypt_secret, secret;
1923 NTSTATUS status = NT_STATUS_OK;
1925 struct timeval now = timeval_current();
1926 NTTIME nt_now = timeval_to_nttime(&now);
1928 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
1930 secret_state = h->data;
1932 msg = ldb_msg_new(mem_ctx);
1934 return NT_STATUS_NO_MEMORY;
1937 msg->dn = talloc_reference(mem_ctx, secret_state->secret_dn);
1939 return NT_STATUS_NO_MEMORY;
1941 status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
1942 if (!NT_STATUS_IS_OK(status)) {
1946 if (r->in.old_val) {
1948 crypt_secret.data = r->in.old_val->data;
1949 crypt_secret.length = r->in.old_val->size;
1951 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
1952 if (!NT_STATUS_IS_OK(status)) {
1956 val.data = secret.data;
1957 val.length = secret.length;
1960 if (samdb_msg_add_value(secret_state->sam_ldb,
1961 mem_ctx, msg, "priorSecret", &val) != 0) {
1962 return NT_STATUS_NO_MEMORY;
1965 /* set old value mtime */
1966 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1967 mem_ctx, msg, "priorSetTime", nt_now) != 0) {
1968 return NT_STATUS_NO_MEMORY;
1971 if (!r->in.new_val) {
1972 /* This behaviour varies depending of if this is a local, or a global secret... */
1973 if (secret_state->global) {
1974 /* set old value mtime */
1975 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1976 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
1977 return NT_STATUS_NO_MEMORY;
1980 if (samdb_msg_add_delete(secret_state->sam_ldb,
1981 mem_ctx, msg, "secret")) {
1982 return NT_STATUS_NO_MEMORY;
1984 if (samdb_msg_add_delete(secret_state->sam_ldb,
1985 mem_ctx, msg, "lastSetTime")) {
1986 return NT_STATUS_NO_MEMORY;
1992 if (r->in.new_val) {
1994 crypt_secret.data = r->in.new_val->data;
1995 crypt_secret.length = r->in.new_val->size;
1997 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
1998 if (!NT_STATUS_IS_OK(status)) {
2002 val.data = secret.data;
2003 val.length = secret.length;
2006 if (samdb_msg_add_value(secret_state->sam_ldb,
2007 mem_ctx, msg, "secret", &val) != 0) {
2008 return NT_STATUS_NO_MEMORY;
2011 /* set new value mtime */
2012 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2013 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
2014 return NT_STATUS_NO_MEMORY;
2017 /* If the old value is not set, then migrate the
2018 * current value to the old value */
2019 if (!r->in.old_val) {
2020 const struct ldb_val *new_val;
2021 NTTIME last_set_time;
2022 struct ldb_message **res;
2023 const char *attrs[] = {
2029 /* search for the secret record */
2030 ret = gendb_search_dn(secret_state->sam_ldb,mem_ctx,
2031 secret_state->secret_dn, &res, attrs);
2033 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2037 DEBUG(0,("Found %d records matching dn=%s\n", ret,
2038 ldb_dn_linearize(mem_ctx, secret_state->secret_dn)));
2039 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2042 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2043 last_set_time = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2047 if (samdb_msg_add_value(secret_state->sam_ldb,
2048 mem_ctx, msg, "priorSecret",
2050 return NT_STATUS_NO_MEMORY;
2054 /* set new value mtime */
2055 if (ldb_msg_find_ldb_val(res[0], "lastSetTime")) {
2056 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2057 mem_ctx, msg, "priorSetTime", last_set_time) != 0) {
2058 return NT_STATUS_NO_MEMORY;
2064 /* modify the samdb record */
2065 ret = samdb_replace(secret_state->sam_ldb, mem_ctx, msg);
2067 /* we really need samdb.c to return NTSTATUS */
2068 return NT_STATUS_UNSUCCESSFUL;
2071 return NT_STATUS_OK;
2078 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2079 struct lsa_QuerySecret *r)
2081 struct dcesrv_handle *h;
2082 struct lsa_secret_state *secret_state;
2083 struct ldb_message *msg;
2084 DATA_BLOB session_key;
2085 DATA_BLOB crypt_secret, secret;
2087 struct ldb_message **res;
2088 const char *attrs[] = {
2098 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
2100 secret_state = h->data;
2102 /* pull all the user attributes */
2103 ret = gendb_search_dn(secret_state->sam_ldb, mem_ctx,
2104 secret_state->secret_dn, &res, attrs);
2106 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2110 nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
2111 if (!NT_STATUS_IS_OK(nt_status)) {
2115 if (r->in.old_val) {
2116 const struct ldb_val *prior_val;
2117 r->out.old_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2118 if (!r->out.old_val) {
2119 return NT_STATUS_NO_MEMORY;
2122 prior_val = ldb_msg_find_ldb_val(res[0], "priorSecret");
2124 if (prior_val && prior_val->length) {
2125 secret.data = prior_val->data;
2126 secret.length = prior_val->length;
2128 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2129 if (!crypt_secret.length) {
2130 return NT_STATUS_NO_MEMORY;
2132 r->out.old_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2133 if (!r->out.old_val->buf) {
2134 return NT_STATUS_NO_MEMORY;
2136 r->out.old_val->buf->size = crypt_secret.length;
2137 r->out.old_val->buf->length = crypt_secret.length;
2138 r->out.old_val->buf->data = crypt_secret.data;
2142 if (r->in.old_mtime) {
2143 r->out.old_mtime = talloc(mem_ctx, NTTIME);
2144 if (!r->out.old_mtime) {
2145 return NT_STATUS_NO_MEMORY;
2147 *r->out.old_mtime = ldb_msg_find_uint64(res[0], "priorSetTime", 0);
2150 if (r->in.new_val) {
2151 const struct ldb_val *new_val;
2152 r->out.new_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2153 if (!r->out.new_val) {
2154 return NT_STATUS_NO_MEMORY;
2158 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2160 if (new_val && new_val->length) {
2161 secret.data = new_val->data;
2162 secret.length = new_val->length;
2164 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2165 if (!crypt_secret.length) {
2166 return NT_STATUS_NO_MEMORY;
2168 r->out.new_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2169 if (!r->out.new_val->buf) {
2170 return NT_STATUS_NO_MEMORY;
2172 r->out.new_val->buf->length = crypt_secret.length;
2173 r->out.new_val->buf->size = crypt_secret.length;
2174 r->out.new_val->buf->data = crypt_secret.data;
2178 if (r->in.new_mtime) {
2179 r->out.new_mtime = talloc(mem_ctx, NTTIME);
2180 if (!r->out.new_mtime) {
2181 return NT_STATUS_NO_MEMORY;
2183 *r->out.new_mtime = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2186 return NT_STATUS_OK;
2193 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
2194 TALLOC_CTX *mem_ctx,
2195 struct lsa_LookupPrivValue *r)
2197 struct dcesrv_handle *h;
2198 struct lsa_policy_state *state;
2201 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2205 id = sec_privilege_id(r->in.name->string);
2207 return NT_STATUS_NO_SUCH_PRIVILEGE;
2210 r->out.luid->low = id;
2211 r->out.luid->high = 0;
2213 return NT_STATUS_OK;
2220 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
2221 TALLOC_CTX *mem_ctx,
2222 struct lsa_LookupPrivName *r)
2224 struct dcesrv_handle *h;
2225 struct lsa_policy_state *state;
2226 const char *privname;
2228 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2232 if (r->in.luid->high != 0) {
2233 return NT_STATUS_NO_SUCH_PRIVILEGE;
2236 privname = sec_privilege_name(r->in.luid->low);
2237 if (privname == NULL) {
2238 return NT_STATUS_NO_SUCH_PRIVILEGE;
2241 r->out.name = talloc(mem_ctx, struct lsa_String);
2242 if (r->out.name == NULL) {
2243 return NT_STATUS_NO_MEMORY;
2245 r->out.name->string = privname;
2247 return NT_STATUS_OK;
2252 lsa_LookupPrivDisplayName
2254 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
2255 TALLOC_CTX *mem_ctx,
2256 struct lsa_LookupPrivDisplayName *r)
2258 struct dcesrv_handle *h;
2259 struct lsa_policy_state *state;
2262 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2266 id = sec_privilege_id(r->in.name->string);
2268 return NT_STATUS_NO_SUCH_PRIVILEGE;
2271 r->out.disp_name = talloc(mem_ctx, struct lsa_String);
2272 if (r->out.disp_name == NULL) {
2273 return NT_STATUS_NO_MEMORY;
2276 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
2277 if (r->out.disp_name->string == NULL) {
2278 return NT_STATUS_INTERNAL_ERROR;
2281 return NT_STATUS_OK;
2288 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2289 struct lsa_DeleteObject *r)
2291 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2296 lsa_EnumAccountsWithUserRight
2298 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
2299 TALLOC_CTX *mem_ctx,
2300 struct lsa_EnumAccountsWithUserRight *r)
2302 struct dcesrv_handle *h;
2303 struct lsa_policy_state *state;
2305 struct ldb_message **res;
2306 const char * const attrs[] = { "objectSid", NULL};
2307 const char *privname;
2309 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2313 if (r->in.name == NULL) {
2314 return NT_STATUS_NO_SUCH_PRIVILEGE;
2317 privname = r->in.name->string;
2318 if (sec_privilege_id(privname) == -1) {
2319 return NT_STATUS_NO_SUCH_PRIVILEGE;
2322 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
2323 "privilege=%s", privname);
2325 return NT_STATUS_NO_SUCH_USER;
2328 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, ret);
2329 if (r->out.sids->sids == NULL) {
2330 return NT_STATUS_NO_MEMORY;
2332 for (i=0;i<ret;i++) {
2333 r->out.sids->sids[i].sid = samdb_result_dom_sid(r->out.sids->sids,
2334 res[i], "objectSid");
2335 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
2337 r->out.sids->num_sids = ret;
2339 return NT_STATUS_OK;
2344 lsa_AddAccountRights
2346 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
2347 TALLOC_CTX *mem_ctx,
2348 struct lsa_AddAccountRights *r)
2350 struct dcesrv_handle *h;
2351 struct lsa_policy_state *state;
2353 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2357 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2359 r->in.sid, r->in.rights);
2364 lsa_RemoveAccountRights
2366 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
2367 TALLOC_CTX *mem_ctx,
2368 struct lsa_RemoveAccountRights *r)
2370 struct dcesrv_handle *h;
2371 struct lsa_policy_state *state;
2373 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2377 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2378 LDB_FLAG_MOD_DELETE,
2379 r->in.sid, r->in.rights);
2384 lsa_StorePrivateData
2386 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2387 struct lsa_StorePrivateData *r)
2389 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2394 lsa_RetrievePrivateData
2396 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2397 struct lsa_RetrievePrivateData *r)
2399 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2406 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2407 struct lsa_GetUserName *r)
2409 NTSTATUS status = NT_STATUS_OK;
2410 const char *account_name;
2411 const char *authority_name;
2412 struct lsa_String *_account_name;
2413 struct lsa_StringPointer *_authority_name = NULL;
2415 /* this is what w2k3 does */
2416 r->out.account_name = r->in.account_name;
2417 r->out.authority_name = r->in.authority_name;
2419 if (r->in.account_name && r->in.account_name->string) {
2420 return NT_STATUS_INVALID_PARAMETER;
2423 if (r->in.authority_name &&
2424 r->in.authority_name->string &&
2425 r->in.authority_name->string->string) {
2426 return NT_STATUS_INVALID_PARAMETER;
2429 /* TODO: this check should go and we should rely on the calling code that this is valid */
2430 if (!dce_call->conn->auth_state.session_info ||
2431 !dce_call->conn->auth_state.session_info->server_info ||
2432 !dce_call->conn->auth_state.session_info->server_info->account_name ||
2433 !dce_call->conn->auth_state.session_info->server_info->domain_name) {
2434 return NT_STATUS_INTERNAL_ERROR;
2437 account_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->account_name);
2438 authority_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->domain_name);
2440 _account_name = talloc(mem_ctx, struct lsa_String);
2441 NTSTATUS_TALLOC_CHECK(_account_name);
2442 _account_name->string = account_name;
2444 if (r->in.authority_name) {
2445 _authority_name = talloc(mem_ctx, struct lsa_StringPointer);
2446 NTSTATUS_TALLOC_CHECK(_authority_name);
2447 _authority_name->string = talloc(mem_ctx, struct lsa_String);
2448 NTSTATUS_TALLOC_CHECK(_authority_name->string);
2449 _authority_name->string->string = authority_name;
2452 r->out.account_name = _account_name;
2453 r->out.authority_name = _authority_name;
2461 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
2462 TALLOC_CTX *mem_ctx,
2463 struct lsa_SetInfoPolicy2 *r)
2465 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2469 lsa_QueryDomainInformationPolicy
2471 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2472 TALLOC_CTX *mem_ctx,
2473 struct lsa_QueryDomainInformationPolicy *r)
2475 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2479 lsa_SetDomInfoPolicy
2481 static NTSTATUS lsa_SetDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2482 TALLOC_CTX *mem_ctx,
2483 struct lsa_SetDomainInformationPolicy *r)
2485 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2491 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
2492 TALLOC_CTX *mem_ctx,
2493 struct lsa_TestCall *r)
2495 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2499 lookup a SID for 1 name
2501 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
2502 const char *name, struct dom_sid **sid, uint32_t *atype)
2505 struct ldb_message **res;
2506 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
2509 p = strchr_m(name, '\\');
2511 /* TODO: properly parse the domain prefix here, and use it to
2516 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", name);
2518 *sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
2520 return NT_STATUS_INVALID_SID;
2523 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
2525 return NT_STATUS_OK;
2528 /* need to add a call into sidmap to check for a allocated sid */
2530 return NT_STATUS_INVALID_SID;
2537 static NTSTATUS lsa_LookupNames3(struct dcesrv_call_state *dce_call,
2538 TALLOC_CTX *mem_ctx,
2539 struct lsa_LookupNames3 *r)
2541 struct lsa_policy_state *state;
2542 struct dcesrv_handle *h;
2544 NTSTATUS status = NT_STATUS_OK;
2546 r->out.domains = NULL;
2548 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2552 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2553 if (r->out.domains == NULL) {
2554 return NT_STATUS_NO_MEMORY;
2557 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray3);
2558 if (r->out.sids == NULL) {
2559 return NT_STATUS_NO_MEMORY;
2564 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid3,
2566 if (r->out.sids->sids == NULL) {
2567 return NT_STATUS_NO_MEMORY;
2570 for (i=0;i<r->in.num_names;i++) {
2571 const char *name = r->in.names[i].string;
2572 struct dom_sid *sid;
2573 uint32_t atype, rtype, sid_index;
2576 r->out.sids->count++;
2579 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2580 r->out.sids->sids[i].sid = NULL;
2581 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2582 r->out.sids->sids[i].unknown = 0;
2584 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2585 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2586 status = STATUS_SOME_UNMAPPED;
2590 rtype = samdb_atype_map(atype);
2591 if (rtype == SID_NAME_UNKNOWN) {
2592 status = STATUS_SOME_UNMAPPED;
2596 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2597 if (!NT_STATUS_IS_OK(status2)) {
2601 r->out.sids->sids[i].sid_type = rtype;
2602 r->out.sids->sids[i].sid = sid;
2603 r->out.sids->sids[i].sid_index = sid_index;
2604 r->out.sids->sids[i].unknown = 0;
2613 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
2614 TALLOC_CTX *mem_ctx,
2615 struct lsa_LookupNames2 *r)
2617 struct lsa_policy_state *state;
2618 struct dcesrv_handle *h;
2620 NTSTATUS status = NT_STATUS_OK;
2622 r->out.domains = NULL;
2624 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2628 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2629 if (r->out.domains == NULL) {
2630 return NT_STATUS_NO_MEMORY;
2633 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray2);
2634 if (r->out.sids == NULL) {
2635 return NT_STATUS_NO_MEMORY;
2640 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid2,
2642 if (r->out.sids->sids == NULL) {
2643 return NT_STATUS_NO_MEMORY;
2646 for (i=0;i<r->in.num_names;i++) {
2647 const char *name = r->in.names[i].string;
2648 struct dom_sid *sid;
2649 uint32_t atype, rtype, sid_index;
2652 r->out.sids->count++;
2655 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2656 r->out.sids->sids[i].rid = 0xFFFFFFFF;
2657 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2658 r->out.sids->sids[i].unknown = 0;
2660 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2661 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2662 status = STATUS_SOME_UNMAPPED;
2666 rtype = samdb_atype_map(atype);
2667 if (rtype == SID_NAME_UNKNOWN) {
2668 status = STATUS_SOME_UNMAPPED;
2672 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2673 if (!NT_STATUS_IS_OK(status2)) {
2677 r->out.sids->sids[i].sid_type = rtype;
2678 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
2679 r->out.sids->sids[i].sid_index = sid_index;
2680 r->out.sids->sids[i].unknown = 0;
2689 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2690 struct lsa_LookupNames *r)
2692 struct lsa_LookupNames2 r2;
2696 r2.in.handle = r->in.handle;
2697 r2.in.num_names = r->in.num_names;
2698 r2.in.names = r->in.names;
2700 r2.in.level = r->in.level;
2701 r2.in.count = r->in.count;
2704 r2.out.count = r->out.count;
2706 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
2707 if (dce_call->fault_code != 0) {
2711 r->out.domains = r2.out.domains;
2712 r->out.sids = talloc(mem_ctx, struct lsa_TransSidArray);
2713 if (r->out.sids == NULL) {
2714 return NT_STATUS_NO_MEMORY;
2716 r->out.sids->count = r2.out.sids->count;
2717 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid,
2718 r->out.sids->count);
2719 if (r->out.sids->sids == NULL) {
2720 return NT_STATUS_NO_MEMORY;
2722 for (i=0;i<r->out.sids->count;i++) {
2723 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
2724 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
2725 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
2734 static NTSTATUS lsa_CREDRWRITE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2735 struct lsa_CREDRWRITE *r)
2737 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2744 static NTSTATUS lsa_CREDRREAD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2745 struct lsa_CREDRREAD *r)
2747 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2754 static NTSTATUS lsa_CREDRENUMERATE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2755 struct lsa_CREDRENUMERATE *r)
2757 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2762 lsa_CREDRWRITEDOMAINCREDENTIALS
2764 static NTSTATUS lsa_CREDRWRITEDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2765 struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
2767 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2772 lsa_CREDRREADDOMAINCREDENTIALS
2774 static NTSTATUS lsa_CREDRREADDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2775 struct lsa_CREDRREADDOMAINCREDENTIALS *r)
2777 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2784 static NTSTATUS lsa_CREDRDELETE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2785 struct lsa_CREDRDELETE *r)
2787 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2792 lsa_CREDRGETTARGETINFO
2794 static NTSTATUS lsa_CREDRGETTARGETINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2795 struct lsa_CREDRGETTARGETINFO *r)
2797 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2802 lsa_CREDRPROFILELOADED
2804 static NTSTATUS lsa_CREDRPROFILELOADED(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2805 struct lsa_CREDRPROFILELOADED *r)
2807 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2812 lsa_CREDRGETSESSIONTYPES
2814 static NTSTATUS lsa_CREDRGETSESSIONTYPES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2815 struct lsa_CREDRGETSESSIONTYPES *r)
2817 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2822 lsa_LSARREGISTERAUDITEVENT
2824 static NTSTATUS lsa_LSARREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2825 struct lsa_LSARREGISTERAUDITEVENT *r)
2827 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2832 lsa_LSARGENAUDITEVENT
2834 static NTSTATUS lsa_LSARGENAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2835 struct lsa_LSARGENAUDITEVENT *r)
2837 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2842 lsa_LSARUNREGISTERAUDITEVENT
2844 static NTSTATUS lsa_LSARUNREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2845 struct lsa_LSARUNREGISTERAUDITEVENT *r)
2847 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2852 lsa_LSARQUERYFORESTTRUSTINFORMATION
2854 static NTSTATUS lsa_LSARQUERYFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2855 struct lsa_LSARQUERYFORESTTRUSTINFORMATION *r)
2857 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2862 lsa_LSARSETFORESTTRUSTINFORMATION
2864 static NTSTATUS lsa_LSARSETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2865 struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2867 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2874 static NTSTATUS lsa_CREDRRENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2875 struct lsa_CREDRRENAME *r)
2877 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2882 lsa_LSARLOOKUPNAMES4
2884 static NTSTATUS lsa_LSARLOOKUPNAMES4(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2885 struct lsa_LSARLOOKUPNAMES4 *r)
2887 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2892 lsa_LSAROPENPOLICYSCE
2894 static NTSTATUS lsa_LSAROPENPOLICYSCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2895 struct lsa_LSAROPENPOLICYSCE *r)
2897 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2902 lsa_LSARADTREGISTERSECURITYEVENTSOURCE
2904 static NTSTATUS lsa_LSARADTREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2905 struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
2907 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2912 lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE
2914 static NTSTATUS lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2915 struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
2917 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2922 lsa_LSARADTREPORTSECURITYEVENT
2924 static NTSTATUS lsa_LSARADTREPORTSECURITYEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2925 struct lsa_LSARADTREPORTSECURITYEVENT *r)
2927 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2931 /* include the generated boilerplate */
2932 #include "librpc/gen_ndr/ndr_lsa_s.c"