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 ret_domain = gendb_search(state->sam_ldb, mem_ctx, NULL, &msgs_domain, domain_attrs,
244 "(&(&(nETBIOSName=%s)(objectclass=crossRef))(ncName=*))",
247 if (ret_domain == -1) {
248 return NT_STATUS_INTERNAL_DB_CORRUPTION;
251 if (ret_domain != 1) {
252 return NT_STATUS_NO_SUCH_DOMAIN;
255 /* work out the domain_dn - useful for so many calls its worth
257 state->domain_dn = samdb_result_dn(state, msgs_domain[0], "nCName", NULL);
258 if (!state->domain_dn) {
259 return NT_STATUS_NO_SUCH_DOMAIN;
262 /* work out the builtin_dn - useful for so many calls its worth
264 state->builtin_dn = ldb_dn_explode(state,
265 samdb_search_string(state->sam_ldb, mem_ctx, NULL,
266 "dn", "objectClass=builtinDomain"));
267 if (!state->builtin_dn) {
268 return NT_STATUS_NO_SUCH_DOMAIN;
271 /* work out the system_dn - useful for so many calls its worth
273 state->system_dn = ldb_dn_explode(state,
274 samdb_search_string(state->sam_ldb, mem_ctx, state->domain_dn,
275 "dn", "(&(objectClass=container)(cn=System))"));
276 if (!state->system_dn) {
277 return NT_STATUS_NO_SUCH_DOMAIN;
280 state->domain_sid = talloc_steal(state,
281 samdb_search_dom_sid(state->sam_ldb, state,
282 state->domain_dn, "objectSid", "dn=%s",
283 ldb_dn_linearize(mem_ctx, state->domain_dn)));
284 if (!state->domain_sid) {
285 return NT_STATUS_NO_SUCH_DOMAIN;
288 state->builtin_sid = dom_sid_parse_talloc(state, SID_BUILTIN);
289 if (!state->builtin_sid) {
290 return NT_STATUS_NO_SUCH_DOMAIN;
293 state->domain_name = talloc_strdup(state,
294 samdb_result_string(msgs_domain[0], "nETBIOSName",
305 static NTSTATUS lsa_OpenPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
306 struct lsa_OpenPolicy2 *r)
309 struct lsa_policy_state *state;
310 struct dcesrv_handle *handle;
312 ZERO_STRUCTP(r->out.handle);
314 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
315 if (!NT_STATUS_IS_OK(status)) {
319 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_POLICY);
321 return NT_STATUS_NO_MEMORY;
324 handle->data = talloc_steal(handle, state);
326 state->access_mask = r->in.access_mask;
327 state->handle = handle;
328 *r->out.handle = handle->wire_handle;
330 /* note that we have completely ignored the attr element of
331 the OpenPolicy. As far as I can tell, this is what w2k3
339 a wrapper around lsa_OpenPolicy2
341 static NTSTATUS lsa_OpenPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
342 struct lsa_OpenPolicy *r)
344 struct lsa_OpenPolicy2 r2;
346 r2.in.system_name = NULL;
347 r2.in.attr = r->in.attr;
348 r2.in.access_mask = r->in.access_mask;
349 r2.out.handle = r->out.handle;
351 return lsa_OpenPolicy2(dce_call, mem_ctx, &r2);
358 fill in the AccountDomain info
360 static NTSTATUS lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
361 struct lsa_DomainInfo *info)
363 info->name.string = state->domain_name;
364 info->sid = state->domain_sid;
370 fill in the DNS domain info
372 static NTSTATUS lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
373 struct lsa_DnsDomainInfo *info)
375 const char * const attrs[] = { "dnsDomain", "objectGUID", "objectSid", NULL };
377 struct ldb_message **res;
379 ret = gendb_search_dn(state->sam_ldb, mem_ctx, state->domain_dn, &res, attrs);
381 return NT_STATUS_INTERNAL_DB_CORRUPTION;
384 info->name.string = state->domain_name;
385 info->sid = state->domain_sid;
386 info->dns_domain.string = samdb_result_string(res[0], "dnsDomain", NULL);
387 info->dns_forest.string = samdb_result_string(res[0], "dnsDomain", NULL);
388 info->domain_guid = samdb_result_guid(res[0], "objectGUID");
396 static NTSTATUS lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
397 struct lsa_QueryInfoPolicy2 *r)
399 struct lsa_policy_state *state;
400 struct dcesrv_handle *h;
404 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
408 r->out.info = talloc(mem_ctx, union lsa_PolicyInformation);
410 return NT_STATUS_NO_MEMORY;
413 ZERO_STRUCTP(r->out.info);
415 switch (r->in.level) {
416 case LSA_POLICY_INFO_DOMAIN:
417 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
418 return lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
420 case LSA_POLICY_INFO_DNS:
421 return lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
424 return NT_STATUS_INVALID_INFO_CLASS;
430 static NTSTATUS lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
431 struct lsa_QueryInfoPolicy *r)
433 struct lsa_QueryInfoPolicy2 r2;
436 r2.in.handle = r->in.handle;
437 r2.in.level = r->in.level;
439 status = lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
441 r->out.info = r2.out.info;
449 static NTSTATUS lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
450 struct lsa_SetInfoPolicy *r)
452 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
459 static NTSTATUS lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
460 struct lsa_ClearAuditLog *r)
462 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
469 static NTSTATUS lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
470 struct lsa_CreateAccount *r)
472 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
479 static NTSTATUS lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
480 struct lsa_EnumAccounts *r)
482 struct dcesrv_handle *h;
483 struct lsa_policy_state *state;
485 struct ldb_message **res;
486 const char * const attrs[] = { "objectSid", NULL};
489 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
493 ret = gendb_search(state->sam_ldb, mem_ctx, state->builtin_dn, &res, attrs,
496 return NT_STATUS_NO_SUCH_USER;
499 if (*r->in.resume_handle >= ret) {
500 return NT_STATUS_NO_MORE_ENTRIES;
503 count = ret - *r->in.resume_handle;
504 if (count > r->in.num_entries) {
505 count = r->in.num_entries;
509 return NT_STATUS_NO_MORE_ENTRIES;
512 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, count);
513 if (r->out.sids->sids == NULL) {
514 return NT_STATUS_NO_MEMORY;
517 for (i=0;i<count;i++) {
518 r->out.sids->sids[i].sid =
519 samdb_result_dom_sid(r->out.sids->sids,
520 res[i + *r->in.resume_handle],
522 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
525 r->out.sids->num_sids = count;
526 *r->out.resume_handle = count + *r->in.resume_handle;
534 lsa_CreateTrustedDomainEx2
536 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
538 struct lsa_CreateTrustedDomainEx2 *r)
540 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
544 lsa_CreateTrustedDomainEx
546 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
548 struct lsa_CreateTrustedDomainEx *r)
550 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
554 lsa_CreateTrustedDomain
556 static NTSTATUS lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
557 struct lsa_CreateTrustedDomain *r)
559 struct dcesrv_handle *policy_handle;
560 struct lsa_policy_state *policy_state;
561 struct lsa_trusted_domain_state *trusted_domain_state;
562 struct dcesrv_handle *handle;
563 struct ldb_message **msgs, *msg;
564 const char *attrs[] = {
570 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
571 ZERO_STRUCTP(r->out.trustdom_handle);
573 policy_state = policy_handle->data;
575 if (!r->in.info->name.string) {
576 return NT_STATUS_INVALID_PARAMETER;
578 name = r->in.info->name.string;
580 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
581 if (!trusted_domain_state) {
582 return NT_STATUS_NO_MEMORY;
584 trusted_domain_state->policy = policy_state;
586 msg = ldb_msg_new(mem_ctx);
588 return NT_STATUS_NO_MEMORY;
591 /* search for the trusted_domain record */
592 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
593 mem_ctx, policy_state->system_dn, &msgs, attrs,
594 "(&(cn=%s)(objectclass=trustedDomain))",
595 r->in.info->name.string);
597 return NT_STATUS_OBJECT_NAME_COLLISION;
600 if (ret < 0 || ret > 1) {
601 DEBUG(0,("Found %d records matching DN %s\n", ret,
602 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
603 return NT_STATUS_INTERNAL_DB_CORRUPTION;
606 msg->dn = ldb_dn_build_child(mem_ctx, "cn",
607 r->in.info->name.string,
608 policy_state->system_dn);
610 return NT_STATUS_NO_MEMORY;
613 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "cn", name);
614 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "flatname", name);
616 if (r->in.info->sid) {
617 const char *sid_string = dom_sid_string(mem_ctx, r->in.info->sid);
619 return NT_STATUS_NO_MEMORY;
622 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "securityIdentifier", sid_string);
625 samdb_msg_add_string(trusted_domain_state->policy->sam_ldb, mem_ctx, msg, "objectClass", "trustedDomain");
627 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msg->dn);
629 /* create the trusted_domain */
630 ret = samdb_add(trusted_domain_state->policy->sam_ldb, mem_ctx, msg);
632 DEBUG(0,("Failed to create trusted_domain record %s\n",
633 ldb_dn_linearize(mem_ctx, msg->dn)));
634 return NT_STATUS_INTERNAL_DB_CORRUPTION;
637 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
639 return NT_STATUS_NO_MEMORY;
642 handle->data = talloc_steal(handle, trusted_domain_state);
644 trusted_domain_state->access_mask = r->in.access_mask;
645 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
647 *r->out.trustdom_handle = handle->wire_handle;
653 lsa_OpenTrustedDomain
655 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
656 struct lsa_OpenTrustedDomain *r)
658 struct dcesrv_handle *policy_handle;
660 struct lsa_policy_state *policy_state;
661 struct lsa_trusted_domain_state *trusted_domain_state;
662 struct dcesrv_handle *handle;
663 struct ldb_message **msgs;
664 const char *attrs[] = {
668 const char *sid_string;
671 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
672 ZERO_STRUCTP(r->out.trustdom_handle);
673 policy_state = policy_handle->data;
675 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
676 if (!trusted_domain_state) {
677 return NT_STATUS_NO_MEMORY;
679 trusted_domain_state->policy = policy_state;
681 sid_string = dom_sid_string(mem_ctx, r->in.sid);
683 return NT_STATUS_NO_MEMORY;
686 /* search for the trusted_domain record */
687 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
688 mem_ctx, policy_state->system_dn, &msgs, attrs,
689 "(&(securityIdentifier=%s)(objectclass=trustedDomain))",
692 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
696 DEBUG(0,("Found %d records matching DN %s\n", ret,
697 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
698 return NT_STATUS_INTERNAL_DB_CORRUPTION;
701 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
703 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
705 return NT_STATUS_NO_MEMORY;
708 handle->data = talloc_steal(handle, trusted_domain_state);
710 trusted_domain_state->access_mask = r->in.access_mask;
711 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
713 *r->out.trustdom_handle = handle->wire_handle;
720 lsa_OpenTrustedDomainByName
722 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
724 struct lsa_OpenTrustedDomainByName *r)
726 struct dcesrv_handle *policy_handle;
728 struct lsa_policy_state *policy_state;
729 struct lsa_trusted_domain_state *trusted_domain_state;
730 struct dcesrv_handle *handle;
731 struct ldb_message **msgs;
732 const char *attrs[] = {
738 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
739 ZERO_STRUCTP(r->out.trustdom_handle);
740 policy_state = policy_handle->data;
742 if (!r->in.name.string) {
743 return NT_STATUS_INVALID_PARAMETER;
746 trusted_domain_state = talloc(mem_ctx, struct lsa_trusted_domain_state);
747 if (!trusted_domain_state) {
748 return NT_STATUS_NO_MEMORY;
750 trusted_domain_state->policy = policy_state;
752 /* search for the trusted_domain record */
753 ret = gendb_search(trusted_domain_state->policy->sam_ldb,
754 mem_ctx, policy_state->system_dn, &msgs, attrs,
755 "(&(flatname=%s)(objectclass=trustedDomain))",
758 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
762 DEBUG(0,("Found %d records matching DN %s\n", ret,
763 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
764 return NT_STATUS_INTERNAL_DB_CORRUPTION;
767 trusted_domain_state->trusted_domain_dn = talloc_reference(trusted_domain_state, msgs[0]->dn);
769 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_TRUSTED_DOMAIN);
771 return NT_STATUS_NO_MEMORY;
774 handle->data = talloc_steal(handle, trusted_domain_state);
776 trusted_domain_state->access_mask = r->in.access_mask;
777 trusted_domain_state->policy = talloc_reference(trusted_domain_state, policy_state);
779 *r->out.trustdom_handle = handle->wire_handle;
786 lsa_QueryTrustedDomainInfoBySid
788 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
789 struct lsa_QueryTrustedDomainInfoBySid *r)
791 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
796 lsa_SetTrustDomainInfo
798 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
799 struct lsa_SetTrustDomainInfo *r)
801 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
806 lsa_DeleteTrustDomain
808 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
809 struct lsa_DeleteTrustDomain *r)
811 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
816 lsa_QueryTrustedDomainInfo
818 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
819 struct lsa_QueryTrustedDomainInfo *r)
821 struct dcesrv_handle *h;
822 struct lsa_trusted_domain_state *trusted_domain_state;
823 struct ldb_message *msg;
825 struct ldb_message **res;
826 const char *attrs[] = {
830 "securityIdentifier",
834 DCESRV_PULL_HANDLE(h, r->in.trustdom_handle, LSA_HANDLE_TRUSTED_DOMAIN);
836 trusted_domain_state = h->data;
838 /* pull all the user attributes */
839 ret = gendb_search_dn(trusted_domain_state->policy->sam_ldb, mem_ctx,
840 trusted_domain_state->trusted_domain_dn, &res, attrs);
842 return NT_STATUS_INTERNAL_DB_CORRUPTION;
846 r->out.info = talloc(mem_ctx, union lsa_TrustedDomainInfo);
848 return NT_STATUS_NO_MEMORY;
850 switch (r->in.level) {
851 case LSA_TRUSTED_DOMAIN_INFO_NAME:
852 r->out.info->name.netbios_name.string
853 = samdb_result_string(msg, "flatname", NULL);
855 case LSA_TRUSTED_DOMAIN_INFO_POSIX_OFFSET:
856 r->out.info->posix_offset.posix_offset
857 = samdb_result_uint(msg, "posixOffset", 0);
860 /* oops, we don't want to return the info after all */
861 talloc_free(r->out.info);
863 return NT_STATUS_INVALID_INFO_CLASS;
871 lsa_SetInformationTrustedDomain
873 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
874 struct lsa_SetInformationTrustedDomain *r)
876 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
881 lsa_QueryTrustedDomainInfoByName
883 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
885 struct lsa_QueryTrustedDomainInfoByName *r)
887 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
891 lsa_SetTrustedDomainInfoByName
893 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
895 struct lsa_SetTrustedDomainInfoByName *r)
897 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
901 lsa_EnumTrustedDomainsEx
903 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
905 struct lsa_EnumTrustedDomainsEx *r)
907 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
911 lsa_CloseTrustedDomainEx
913 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
915 struct lsa_CloseTrustedDomainEx *r)
917 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
922 comparison function for sorting lsa_DomainInformation array
924 static int compare_DomainInformation(struct lsa_DomainInformation *e1, struct lsa_DomainInformation *e2)
926 return strcasecmp(e1->name.string, e2->name.string);
932 static NTSTATUS lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
933 struct lsa_EnumTrustDom *r)
935 struct dcesrv_handle *policy_handle;
936 struct lsa_DomainInformation *entries;
937 struct lsa_policy_state *policy_state;
938 struct ldb_message **domains;
939 const char *attrs[] = {
941 "securityIdentifier",
948 *r->out.resume_handle = 0;
950 r->out.domains->domains = NULL;
951 r->out.domains->count = 0;
953 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
955 policy_state = policy_handle->data;
957 /* search for all users in this domain. This could possibly be cached and
958 resumed based on resume_key */
959 count = gendb_search(policy_state->sam_ldb, mem_ctx, policy_state->system_dn, &domains, attrs,
960 "objectclass=trustedDomain");
962 return NT_STATUS_INTERNAL_DB_CORRUPTION;
964 if (count == 0 || r->in.max_size == 0) {
968 /* convert to lsa_DomainInformation format */
969 entries = talloc_array(mem_ctx, struct lsa_DomainInformation, count);
971 return NT_STATUS_NO_MEMORY;
973 for (i=0;i<count;i++) {
974 entries[i].sid = samdb_result_dom_sid(mem_ctx, domains[i], "securityIdentifier");
975 entries[i].name.string = samdb_result_string(domains[i], "flatname", NULL);
978 /* sort the results by name */
979 qsort(entries, count, sizeof(struct lsa_DomainInformation),
980 (comparison_fn_t)compare_DomainInformation);
982 if (*r->in.resume_handle >= count) {
983 *r->out.resume_handle = -1;
985 return NT_STATUS_NO_MORE_ENTRIES;
988 /* return the rest, limit by max_size. Note that we
989 use the w2k3 element size value of 60 */
990 r->out.domains->count = count - *r->in.resume_handle;
991 r->out.domains->count = MIN(r->out.domains->count,
992 1+(r->in.max_size/LSA_ENUM_TRUST_DOMAIN_MULTIPLIER));
994 r->out.domains->domains = entries + *r->in.resume_handle;
995 r->out.domains->count = r->out.domains->count;
997 if (r->out.domains->count < count - *r->in.resume_handle) {
998 *r->out.resume_handle = *r->in.resume_handle + r->out.domains->count;
999 return STATUS_MORE_ENTRIES;
1002 return NT_STATUS_OK;
1007 return the authority name and authority sid, given a sid
1009 static NTSTATUS lsa_authority_name(struct lsa_policy_state *state,
1010 TALLOC_CTX *mem_ctx, struct dom_sid *sid,
1011 const char **authority_name,
1012 struct dom_sid **authority_sid)
1014 if (dom_sid_in_domain(state->domain_sid, sid)) {
1015 *authority_name = state->domain_name;
1016 *authority_sid = state->domain_sid;
1017 return NT_STATUS_OK;
1020 if (dom_sid_in_domain(state->builtin_sid, sid)) {
1021 *authority_name = "BUILTIN";
1022 *authority_sid = state->builtin_sid;
1023 return NT_STATUS_OK;
1026 *authority_sid = dom_sid_dup(mem_ctx, sid);
1027 if (*authority_sid == NULL) {
1028 return NT_STATUS_NO_MEMORY;
1030 (*authority_sid)->num_auths = 0;
1031 *authority_name = dom_sid_string(mem_ctx, *authority_sid);
1032 if (*authority_name == NULL) {
1033 return NT_STATUS_NO_MEMORY;
1036 return NT_STATUS_OK;
1040 add to the lsa_RefDomainList for LookupSids and LookupNames
1042 static NTSTATUS lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1043 struct dom_sid *sid,
1044 struct lsa_RefDomainList *domains,
1045 uint32_t *sid_index)
1048 const char *authority_name;
1049 struct dom_sid *authority_sid;
1052 /* work out the authority name */
1053 status = lsa_authority_name(state, mem_ctx, sid,
1054 &authority_name, &authority_sid);
1055 if (!NT_STATUS_IS_OK(status)) {
1059 /* see if we've already done this authority name */
1060 for (i=0;i<domains->count;i++) {
1061 if (strcmp(authority_name, domains->domains[i].name.string) == 0) {
1063 return NT_STATUS_OK;
1067 domains->domains = talloc_realloc(domains,
1069 struct lsa_TrustInformation,
1071 if (domains->domains == NULL) {
1072 return NT_STATUS_NO_MEMORY;
1074 domains->domains[i].name.string = authority_name;
1075 domains->domains[i].sid = authority_sid;
1079 return NT_STATUS_OK;
1083 lookup a name for 1 SID
1085 static NTSTATUS lsa_lookup_sid(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1086 struct dom_sid *sid, const char *sid_str,
1087 const char **name, uint32_t *atype)
1090 struct ldb_message **res;
1091 const char * const attrs[] = { "sAMAccountName", "sAMAccountType", "name", NULL};
1094 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1095 "objectSid=%s", ldap_encode_ndr_dom_sid(mem_ctx, sid));
1097 *name = ldb_msg_find_string(res[0], "sAMAccountName", NULL);
1099 *name = ldb_msg_find_string(res[0], "name", NULL);
1101 *name = talloc_strdup(mem_ctx, sid_str);
1102 NTSTATUS_TALLOC_CHECK(*name);
1106 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1108 return NT_STATUS_OK;
1111 status = sidmap_allocated_sid_lookup(state->sidmap, mem_ctx, sid, name, atype);
1120 static NTSTATUS lsa_LookupSids3(struct dcesrv_call_state *dce_call,
1121 TALLOC_CTX *mem_ctx,
1122 struct lsa_LookupSids3 *r)
1124 struct lsa_policy_state *state;
1126 NTSTATUS status = NT_STATUS_OK;
1128 r->out.domains = NULL;
1130 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
1131 if (!NT_STATUS_IS_OK(status)) {
1135 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
1136 if (r->out.domains == NULL) {
1137 return NT_STATUS_NO_MEMORY;
1140 r->out.names = talloc_zero(mem_ctx, struct lsa_TransNameArray2);
1141 if (r->out.names == NULL) {
1142 return NT_STATUS_NO_MEMORY;
1147 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName2,
1148 r->in.sids->num_sids);
1149 if (r->out.names->names == NULL) {
1150 return NT_STATUS_NO_MEMORY;
1153 for (i=0;i<r->in.sids->num_sids;i++) {
1154 struct dom_sid *sid = r->in.sids->sids[i].sid;
1155 char *sid_str = dom_sid_string(mem_ctx, sid);
1157 uint32_t atype, rtype, sid_index;
1160 r->out.names->count++;
1163 r->out.names->names[i].sid_type = SID_NAME_UNKNOWN;
1164 r->out.names->names[i].name.string = sid_str;
1165 r->out.names->names[i].sid_index = 0xFFFFFFFF;
1166 r->out.names->names[i].unknown = 0;
1168 if (sid_str == NULL) {
1169 r->out.names->names[i].name.string = "(SIDERROR)";
1170 status = STATUS_SOME_UNMAPPED;
1174 /* work out the authority name */
1175 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1176 if (!NT_STATUS_IS_OK(status2)) {
1180 status2 = lsa_lookup_sid(state, mem_ctx, sid, sid_str,
1182 if (!NT_STATUS_IS_OK(status2)) {
1183 status = STATUS_SOME_UNMAPPED;
1187 rtype = samdb_atype_map(atype);
1188 if (rtype == SID_NAME_UNKNOWN) {
1189 status = STATUS_SOME_UNMAPPED;
1193 r->out.names->names[i].sid_type = rtype;
1194 r->out.names->names[i].name.string = name;
1195 r->out.names->names[i].sid_index = sid_index;
1196 r->out.names->names[i].unknown = 0;
1206 static NTSTATUS lsa_LookupSids2(struct dcesrv_call_state *dce_call,
1207 TALLOC_CTX *mem_ctx,
1208 struct lsa_LookupSids2 *r)
1210 struct lsa_LookupSids3 r3;
1213 r3.in.sids = r->in.sids;
1214 r3.in.names = r->in.names;
1215 r3.in.level = r->in.level;
1216 r3.in.count = r->in.count;
1217 r3.in.unknown1 = r->in.unknown1;
1218 r3.in.unknown2 = r->in.unknown2;
1219 r3.out.count = r->out.count;
1220 r3.out.names = r->out.names;
1222 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1223 if (dce_call->fault_code != 0) {
1227 r->out.domains = r3.out.domains;
1228 r->out.names = r3.out.names;
1229 r->out.count = r3.out.count;
1238 static NTSTATUS lsa_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1239 struct lsa_LookupSids *r)
1241 struct lsa_LookupSids3 r3;
1245 r3.in.sids = r->in.sids;
1247 r3.in.level = r->in.level;
1248 r3.in.count = r->in.count;
1251 r3.out.count = r->out.count;
1253 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
1254 if (dce_call->fault_code != 0) {
1258 r->out.domains = r3.out.domains;
1259 r->out.names = talloc(mem_ctx, struct lsa_TransNameArray);
1260 if (r->out.names == NULL) {
1261 return NT_STATUS_NO_MEMORY;
1263 r->out.names->count = r3.out.names->count;
1264 r->out.names->names = talloc_array(r->out.names, struct lsa_TranslatedName,
1265 r->out.names->count);
1266 if (r->out.names->names == NULL) {
1267 return NT_STATUS_NO_MEMORY;
1269 for (i=0;i<r->out.names->count;i++) {
1270 r->out.names->names[i].sid_type = r3.out.names->names[i].sid_type;
1271 r->out.names->names[i].name.string = r3.out.names->names[i].name.string;
1272 r->out.names->names[i].sid_index = r3.out.names->names[i].sid_index;
1282 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1283 struct lsa_OpenAccount *r)
1285 struct dcesrv_handle *h, *ah;
1286 struct lsa_policy_state *state;
1287 struct lsa_account_state *astate;
1289 ZERO_STRUCTP(r->out.acct_handle);
1291 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1295 astate = talloc(dce_call->conn, struct lsa_account_state);
1296 if (astate == NULL) {
1297 return NT_STATUS_NO_MEMORY;
1300 astate->account_sid = dom_sid_dup(astate, r->in.sid);
1301 if (astate->account_sid == NULL) {
1302 talloc_free(astate);
1303 return NT_STATUS_NO_MEMORY;
1306 /* check it really exists */
1307 astate->account_dn =
1308 ldb_dn_explode(mem_ctx,
1309 samdb_search_string(state->sam_ldb, astate,
1311 "(&(objectSid=%s)(objectClass=group))",
1312 ldap_encode_ndr_dom_sid(mem_ctx,
1313 astate->account_sid)));
1314 if (astate->account_dn == NULL) {
1315 talloc_free(astate);
1316 return NT_STATUS_NO_SUCH_USER;
1319 astate->policy = talloc_reference(astate, state);
1320 astate->access_mask = r->in.access_mask;
1322 ah = dcesrv_handle_new(dce_call->context, LSA_HANDLE_ACCOUNT);
1324 talloc_free(astate);
1325 return NT_STATUS_NO_MEMORY;
1328 ah->data = talloc_steal(ah, astate);
1330 *r->out.acct_handle = ah->wire_handle;
1332 return NT_STATUS_OK;
1337 lsa_EnumPrivsAccount
1339 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
1340 TALLOC_CTX *mem_ctx,
1341 struct lsa_EnumPrivsAccount *r)
1343 struct dcesrv_handle *h;
1344 struct lsa_account_state *astate;
1346 struct ldb_message **res;
1347 const char * const attrs[] = { "privilege", NULL};
1348 struct ldb_message_element *el;
1350 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1354 r->out.privs = talloc(mem_ctx, struct lsa_PrivilegeSet);
1355 r->out.privs->count = 0;
1356 r->out.privs->unknown = 0;
1357 r->out.privs->set = NULL;
1359 ret = gendb_search_dn(astate->policy->sam_ldb, mem_ctx,
1360 astate->account_dn, &res, attrs);
1362 return NT_STATUS_OK;
1365 el = ldb_msg_find_element(res[0], "privilege");
1366 if (el == NULL || el->num_values == 0) {
1367 return NT_STATUS_OK;
1370 r->out.privs->set = talloc_array(r->out.privs,
1371 struct lsa_LUIDAttribute, el->num_values);
1372 if (r->out.privs->set == NULL) {
1373 return NT_STATUS_NO_MEMORY;
1376 for (i=0;i<el->num_values;i++) {
1377 int id = sec_privilege_id((const char *)el->values[i].data);
1379 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1381 r->out.privs->set[i].attribute = 0;
1382 r->out.privs->set[i].luid.low = id;
1383 r->out.privs->set[i].luid.high = 0;
1386 r->out.privs->count = el->num_values;
1388 return NT_STATUS_OK;
1392 lsa_EnumAccountRights
1394 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
1395 TALLOC_CTX *mem_ctx,
1396 struct lsa_EnumAccountRights *r)
1398 struct dcesrv_handle *h;
1399 struct lsa_policy_state *state;
1401 struct ldb_message **res;
1402 const char * const attrs[] = { "privilege", NULL};
1404 struct ldb_message_element *el;
1406 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1410 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, r->in.sid);
1411 if (sidstr == NULL) {
1412 return NT_STATUS_NO_MEMORY;
1415 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
1416 "objectSid=%s", sidstr);
1418 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1421 el = ldb_msg_find_element(res[0], "privilege");
1422 if (el == NULL || el->num_values == 0) {
1423 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1426 r->out.rights->count = el->num_values;
1427 r->out.rights->names = talloc_array(r->out.rights,
1428 struct lsa_String, r->out.rights->count);
1429 if (r->out.rights->names == NULL) {
1430 return NT_STATUS_NO_MEMORY;
1433 for (i=0;i<el->num_values;i++) {
1434 r->out.rights->names[i].string = (const char *)el->values[i].data;
1437 return NT_STATUS_OK;
1443 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
1445 static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
1446 TALLOC_CTX *mem_ctx,
1447 struct lsa_policy_state *state,
1449 struct dom_sid *sid,
1450 const struct lsa_RightSet *rights)
1453 struct ldb_message *msg;
1454 struct ldb_message_element el;
1457 struct lsa_EnumAccountRights r2;
1459 sidstr = ldap_encode_ndr_dom_sid(mem_ctx, sid);
1460 if (sidstr == NULL) {
1461 return NT_STATUS_NO_MEMORY;
1464 msg = ldb_msg_new(mem_ctx);
1466 return NT_STATUS_NO_MEMORY;
1469 dn = samdb_search_string(state->sam_ldb, mem_ctx, NULL, "dn",
1470 "objectSid=%s", sidstr);
1472 return NT_STATUS_NO_SUCH_USER;
1475 msg->dn = ldb_dn_explode(mem_ctx, dn);
1476 if (msg->dn == NULL) {
1477 return NT_STATUS_NO_MEMORY;
1480 if (ldb_msg_add_empty(state->sam_ldb, msg, "privilege", ldb_flag)) {
1481 return NT_STATUS_NO_MEMORY;
1484 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1487 r2.in.handle = &state->handle->wire_handle;
1489 r2.out.rights = talloc(mem_ctx, struct lsa_RightSet);
1491 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1492 if (!NT_STATUS_IS_OK(status)) {
1493 ZERO_STRUCTP(r2.out.rights);
1498 el.values = talloc_array(mem_ctx, struct ldb_val, rights->count);
1499 if (el.values == NULL) {
1500 return NT_STATUS_NO_MEMORY;
1502 for (i=0;i<rights->count;i++) {
1503 if (sec_privilege_id(rights->names[i].string) == -1) {
1504 return NT_STATUS_NO_SUCH_PRIVILEGE;
1507 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1509 for (j=0;j<r2.out.rights->count;j++) {
1510 if (StrCaseCmp(r2.out.rights->names[j].string,
1511 rights->names[i].string) == 0) {
1515 if (j != r2.out.rights->count) continue;
1519 el.values[el.num_values].length = strlen(rights->names[i].string);
1520 el.values[el.num_values].data = (uint8_t *)talloc_strdup(mem_ctx, rights->names[i].string);
1521 if (el.values[el.num_values].data == NULL) {
1522 return NT_STATUS_NO_MEMORY;
1527 if (el.num_values == 0) {
1528 return NT_STATUS_OK;
1531 ret = samdb_modify(state->sam_ldb, mem_ctx, msg);
1533 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1534 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1536 return NT_STATUS_UNEXPECTED_IO_ERROR;
1539 return NT_STATUS_OK;
1543 lsa_AddPrivilegesToAccount
1545 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1546 struct lsa_AddPrivilegesToAccount *r)
1548 struct lsa_RightSet rights;
1549 struct dcesrv_handle *h;
1550 struct lsa_account_state *astate;
1553 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1557 rights.count = r->in.privs->count;
1558 rights.names = talloc_array(mem_ctx, struct lsa_String, rights.count);
1559 if (rights.names == NULL) {
1560 return NT_STATUS_NO_MEMORY;
1562 for (i=0;i<rights.count;i++) {
1563 int id = r->in.privs->set[i].luid.low;
1564 if (r->in.privs->set[i].luid.high) {
1565 return NT_STATUS_NO_SUCH_PRIVILEGE;
1567 rights.names[i].string = sec_privilege_name(id);
1568 if (rights.names[i].string == NULL) {
1569 return NT_STATUS_NO_SUCH_PRIVILEGE;
1573 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1574 LDB_FLAG_MOD_ADD, astate->account_sid,
1580 lsa_RemovePrivilegesFromAccount
1582 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1583 struct lsa_RemovePrivilegesFromAccount *r)
1585 struct lsa_RightSet *rights;
1586 struct dcesrv_handle *h;
1587 struct lsa_account_state *astate;
1590 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1594 rights = talloc(mem_ctx, struct lsa_RightSet);
1596 if (r->in.remove_all == 1 &&
1597 r->in.privs == NULL) {
1598 struct lsa_EnumAccountRights r2;
1601 r2.in.handle = &astate->policy->handle->wire_handle;
1602 r2.in.sid = astate->account_sid;
1603 r2.out.rights = rights;
1605 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1606 if (!NT_STATUS_IS_OK(status)) {
1610 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1611 LDB_FLAG_MOD_DELETE, astate->account_sid,
1615 if (r->in.remove_all != 0) {
1616 return NT_STATUS_INVALID_PARAMETER;
1619 rights->count = r->in.privs->count;
1620 rights->names = talloc_array(mem_ctx, struct lsa_String, rights->count);
1621 if (rights->names == NULL) {
1622 return NT_STATUS_NO_MEMORY;
1624 for (i=0;i<rights->count;i++) {
1625 int id = r->in.privs->set[i].luid.low;
1626 if (r->in.privs->set[i].luid.high) {
1627 return NT_STATUS_NO_SUCH_PRIVILEGE;
1629 rights->names[i].string = sec_privilege_name(id);
1630 if (rights->names[i].string == NULL) {
1631 return NT_STATUS_NO_SUCH_PRIVILEGE;
1635 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1636 LDB_FLAG_MOD_DELETE, astate->account_sid,
1642 lsa_GetQuotasForAccount
1644 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1645 struct lsa_GetQuotasForAccount *r)
1647 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1652 lsa_SetQuotasForAccount
1654 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1655 struct lsa_SetQuotasForAccount *r)
1657 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1662 lsa_GetSystemAccessAccount
1664 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1665 struct lsa_GetSystemAccessAccount *r)
1667 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1672 lsa_SetSystemAccessAccount
1674 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1675 struct lsa_SetSystemAccessAccount *r)
1677 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1684 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1685 struct lsa_CreateSecret *r)
1687 struct dcesrv_handle *policy_handle;
1688 struct lsa_policy_state *policy_state;
1689 struct lsa_secret_state *secret_state;
1690 struct dcesrv_handle *handle;
1691 struct ldb_message **msgs, *msg;
1692 const char *attrs[] = {
1700 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1701 ZERO_STRUCTP(r->out.sec_handle);
1703 policy_state = policy_handle->data;
1705 if (!r->in.name.string) {
1706 return NT_STATUS_INVALID_PARAMETER;
1709 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1710 if (!secret_state) {
1711 return NT_STATUS_NO_MEMORY;
1713 secret_state->policy = policy_state;
1715 msg = ldb_msg_new(mem_ctx);
1717 return NT_STATUS_NO_MEMORY;
1720 if (strncmp("G$", r->in.name.string, 2) == 0) {
1722 name = &r->in.name.string[2];
1723 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1724 secret_state->global = True;
1726 if (strlen(name) < 1) {
1727 return NT_STATUS_INVALID_PARAMETER;
1730 name2 = talloc_asprintf(mem_ctx, "%s Secret", name);
1731 /* search for the secret record */
1732 ret = gendb_search(secret_state->sam_ldb,
1733 mem_ctx, policy_state->system_dn, &msgs, attrs,
1734 "(&(cn=%s)(objectclass=secret))",
1737 return NT_STATUS_OBJECT_NAME_COLLISION;
1740 if (ret < 0 || ret > 1) {
1741 DEBUG(0,("Found %d records matching DN %s\n", ret,
1742 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1743 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1746 msg->dn = ldb_dn_build_child(mem_ctx, "cn", name2, policy_state->system_dn);
1747 if (!name2 || !msg->dn) {
1748 return NT_STATUS_NO_MEMORY;
1751 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name2);
1754 secret_state->global = False;
1756 name = r->in.name.string;
1757 if (strlen(name) < 1) {
1758 return NT_STATUS_INVALID_PARAMETER;
1761 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1762 /* search for the secret record */
1763 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1764 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1766 "(&(cn=%s)(objectclass=secret))", name);
1768 return NT_STATUS_OBJECT_NAME_COLLISION;
1771 if (ret < 0 || ret > 1) {
1772 DEBUG(0,("Found %d records matching DN %s\n", ret,
1773 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1774 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1777 msg->dn = ldb_dn_string_compose(mem_ctx, NULL, "cn=%s,cn=LSA Secrets", name);
1778 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "cn", name);
1781 /* pull in all the template attributes. Note this is always from the global samdb */
1782 ret = samdb_copy_template(secret_state->policy->sam_ldb, mem_ctx, msg,
1783 "(&(name=TemplateSecret)(objectclass=secretTemplate))");
1785 DEBUG(0,("Failed to load TemplateSecret from samdb\n"));
1786 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1789 samdb_msg_add_string(secret_state->sam_ldb, mem_ctx, msg, "objectClass", "secret");
1791 secret_state->secret_dn = talloc_reference(secret_state, msg->dn);
1793 /* create the secret */
1794 ret = samdb_add(secret_state->sam_ldb, mem_ctx, msg);
1796 DEBUG(0,("Failed to create secret record %s\n",
1797 ldb_dn_linearize(mem_ctx, msg->dn)));
1798 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1801 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1803 return NT_STATUS_NO_MEMORY;
1806 handle->data = talloc_steal(handle, secret_state);
1808 secret_state->access_mask = r->in.access_mask;
1809 secret_state->policy = talloc_reference(secret_state, policy_state);
1811 *r->out.sec_handle = handle->wire_handle;
1813 return NT_STATUS_OK;
1820 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1821 struct lsa_OpenSecret *r)
1823 struct dcesrv_handle *policy_handle;
1825 struct lsa_policy_state *policy_state;
1826 struct lsa_secret_state *secret_state;
1827 struct dcesrv_handle *handle;
1828 struct ldb_message **msgs;
1829 const char *attrs[] = {
1837 DCESRV_PULL_HANDLE(policy_handle, r->in.handle, LSA_HANDLE_POLICY);
1838 ZERO_STRUCTP(r->out.sec_handle);
1839 policy_state = policy_handle->data;
1841 if (!r->in.name.string) {
1842 return NT_STATUS_INVALID_PARAMETER;
1845 secret_state = talloc(mem_ctx, struct lsa_secret_state);
1846 if (!secret_state) {
1847 return NT_STATUS_NO_MEMORY;
1849 secret_state->policy = policy_state;
1851 if (strncmp("G$", r->in.name.string, 2) == 0) {
1852 name = &r->in.name.string[2];
1853 secret_state->sam_ldb = talloc_reference(secret_state, policy_state->sam_ldb);
1854 secret_state->global = True;
1856 if (strlen(name) < 1) {
1857 return NT_STATUS_INVALID_PARAMETER;
1860 /* search for the secret record */
1861 ret = gendb_search(secret_state->sam_ldb,
1862 mem_ctx, policy_state->system_dn, &msgs, attrs,
1863 "(&(cn=%s Secret)(objectclass=secret))",
1866 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1870 DEBUG(0,("Found %d records matching DN %s\n", ret,
1871 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1872 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1876 secret_state->sam_ldb = talloc_reference(secret_state, secrets_db_connect(mem_ctx));
1878 secret_state->global = False;
1879 name = r->in.name.string;
1880 if (strlen(name) < 1) {
1881 return NT_STATUS_INVALID_PARAMETER;
1884 /* search for the secret record */
1885 ret = gendb_search(secret_state->sam_ldb, mem_ctx,
1886 ldb_dn_explode(mem_ctx, "cn=LSA Secrets"),
1888 "(&(cn=%s)(objectclass=secret))", name);
1890 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1894 DEBUG(0,("Found %d records matching DN %s\n", ret,
1895 ldb_dn_linearize(mem_ctx, policy_state->system_dn)));
1896 return NT_STATUS_INTERNAL_DB_CORRUPTION;
1900 secret_state->secret_dn = talloc_reference(secret_state, msgs[0]->dn);
1902 handle = dcesrv_handle_new(dce_call->context, LSA_HANDLE_SECRET);
1904 return NT_STATUS_NO_MEMORY;
1907 handle->data = talloc_steal(handle, secret_state);
1909 secret_state->access_mask = r->in.access_mask;
1910 secret_state->policy = talloc_reference(secret_state, policy_state);
1912 *r->out.sec_handle = handle->wire_handle;
1914 return NT_STATUS_OK;
1921 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1922 struct lsa_SetSecret *r)
1925 struct dcesrv_handle *h;
1926 struct lsa_secret_state *secret_state;
1927 struct ldb_message *msg;
1928 DATA_BLOB session_key;
1929 DATA_BLOB crypt_secret, secret;
1932 NTSTATUS status = NT_STATUS_OK;
1934 struct timeval now = timeval_current();
1935 NTTIME nt_now = timeval_to_nttime(&now);
1937 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
1939 secret_state = h->data;
1941 msg = ldb_msg_new(mem_ctx);
1943 return NT_STATUS_NO_MEMORY;
1946 msg->dn = talloc_reference(mem_ctx, secret_state->secret_dn);
1948 return NT_STATUS_NO_MEMORY;
1950 status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
1951 if (!NT_STATUS_IS_OK(status)) {
1955 if (r->in.old_val) {
1957 crypt_secret.data = r->in.old_val->data;
1958 crypt_secret.length = r->in.old_val->size;
1960 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
1961 if (!NT_STATUS_IS_OK(status)) {
1965 val.data = secret.data;
1966 val.length = secret.length;
1969 if (samdb_msg_add_value(secret_state->sam_ldb,
1970 mem_ctx, msg, "priorSecret", &val) != 0) {
1971 return NT_STATUS_NO_MEMORY;
1974 /* set old value mtime */
1975 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1976 mem_ctx, msg, "priorSetTime", nt_now) != 0) {
1977 return NT_STATUS_NO_MEMORY;
1980 if (!r->in.new_val) {
1981 /* This behaviour varies depending of if this is a local, or a global secret... */
1982 if (secret_state->global) {
1983 /* set old value mtime */
1984 if (samdb_msg_add_uint64(secret_state->sam_ldb,
1985 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
1986 return NT_STATUS_NO_MEMORY;
1989 if (samdb_msg_add_delete(secret_state->sam_ldb,
1990 mem_ctx, msg, "secret")) {
1991 return NT_STATUS_NO_MEMORY;
1993 if (samdb_msg_add_delete(secret_state->sam_ldb,
1994 mem_ctx, msg, "lastSetTime")) {
1995 return NT_STATUS_NO_MEMORY;
2001 if (r->in.new_val) {
2003 crypt_secret.data = r->in.new_val->data;
2004 crypt_secret.length = r->in.new_val->size;
2006 status = sess_decrypt_blob(mem_ctx, &crypt_secret, &session_key, &secret);
2007 if (!NT_STATUS_IS_OK(status)) {
2011 val.data = secret.data;
2012 val.length = secret.length;
2015 if (samdb_msg_add_value(secret_state->sam_ldb,
2016 mem_ctx, msg, "secret", &val) != 0) {
2017 return NT_STATUS_NO_MEMORY;
2020 /* set new value mtime */
2021 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2022 mem_ctx, msg, "lastSetTime", nt_now) != 0) {
2023 return NT_STATUS_NO_MEMORY;
2026 /* If the old value is not set, then migrate the
2027 * current value to the old value */
2028 if (!r->in.old_val) {
2029 const struct ldb_val *new_val;
2030 NTTIME last_set_time;
2031 struct ldb_message **res;
2032 const char *attrs[] = {
2038 /* search for the secret record */
2039 ret = gendb_search_dn(secret_state->sam_ldb,mem_ctx,
2040 secret_state->secret_dn, &res, attrs);
2042 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2046 DEBUG(0,("Found %d records matching dn=%s\n", ret,
2047 ldb_dn_linearize(mem_ctx, secret_state->secret_dn)));
2048 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2051 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2052 last_set_time = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2056 if (samdb_msg_add_value(secret_state->sam_ldb,
2057 mem_ctx, msg, "priorSecret",
2059 return NT_STATUS_NO_MEMORY;
2063 /* set new value mtime */
2064 if (ldb_msg_find_ldb_val(res[0], "lastSetTime")) {
2065 if (samdb_msg_add_uint64(secret_state->sam_ldb,
2066 mem_ctx, msg, "priorSetTime", last_set_time) != 0) {
2067 return NT_STATUS_NO_MEMORY;
2073 /* modify the samdb record */
2074 ret = samdb_replace(secret_state->sam_ldb, mem_ctx, msg);
2076 /* we really need samdb.c to return NTSTATUS */
2077 return NT_STATUS_UNSUCCESSFUL;
2080 return NT_STATUS_OK;
2087 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2088 struct lsa_QuerySecret *r)
2090 struct dcesrv_handle *h;
2091 struct lsa_secret_state *secret_state;
2092 struct ldb_message *msg;
2093 DATA_BLOB session_key;
2094 DATA_BLOB crypt_secret, secret;
2096 struct ldb_message **res;
2097 const char *attrs[] = {
2107 DCESRV_PULL_HANDLE(h, r->in.sec_handle, LSA_HANDLE_SECRET);
2109 secret_state = h->data;
2111 /* pull all the user attributes */
2112 ret = gendb_search_dn(secret_state->sam_ldb, mem_ctx,
2113 secret_state->secret_dn, &res, attrs);
2115 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2119 nt_status = dcesrv_fetch_session_key(dce_call->conn, &session_key);
2120 if (!NT_STATUS_IS_OK(nt_status)) {
2124 if (r->in.old_val) {
2125 const struct ldb_val *prior_val;
2126 r->out.old_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2127 if (!r->out.old_val) {
2128 return NT_STATUS_NO_MEMORY;
2131 prior_val = ldb_msg_find_ldb_val(res[0], "priorSecret");
2133 if (prior_val && prior_val->length) {
2134 secret.data = prior_val->data;
2135 secret.length = prior_val->length;
2137 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2138 if (!crypt_secret.length) {
2139 return NT_STATUS_NO_MEMORY;
2141 r->out.old_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2142 if (!r->out.old_val->buf) {
2143 return NT_STATUS_NO_MEMORY;
2145 r->out.old_val->buf->size = crypt_secret.length;
2146 r->out.old_val->buf->length = crypt_secret.length;
2147 r->out.old_val->buf->data = crypt_secret.data;
2151 if (r->in.old_mtime) {
2152 r->out.old_mtime = talloc(mem_ctx, NTTIME);
2153 if (!r->out.old_mtime) {
2154 return NT_STATUS_NO_MEMORY;
2156 *r->out.old_mtime = ldb_msg_find_uint64(res[0], "priorSetTime", 0);
2159 if (r->in.new_val) {
2160 const struct ldb_val *new_val;
2161 r->out.new_val = talloc_zero(mem_ctx, struct lsa_DATA_BUF_PTR);
2162 if (!r->out.new_val) {
2163 return NT_STATUS_NO_MEMORY;
2167 new_val = ldb_msg_find_ldb_val(res[0], "secret");
2169 if (new_val && new_val->length) {
2170 secret.data = new_val->data;
2171 secret.length = new_val->length;
2173 crypt_secret = sess_encrypt_blob(mem_ctx, &secret, &session_key);
2174 if (!crypt_secret.length) {
2175 return NT_STATUS_NO_MEMORY;
2177 r->out.new_val->buf = talloc(mem_ctx, struct lsa_DATA_BUF);
2178 if (!r->out.new_val->buf) {
2179 return NT_STATUS_NO_MEMORY;
2181 r->out.new_val->buf->length = crypt_secret.length;
2182 r->out.new_val->buf->size = crypt_secret.length;
2183 r->out.new_val->buf->data = crypt_secret.data;
2187 if (r->in.new_mtime) {
2188 r->out.new_mtime = talloc(mem_ctx, NTTIME);
2189 if (!r->out.new_mtime) {
2190 return NT_STATUS_NO_MEMORY;
2192 *r->out.new_mtime = ldb_msg_find_uint64(res[0], "lastSetTime", 0);
2195 return NT_STATUS_OK;
2202 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
2203 TALLOC_CTX *mem_ctx,
2204 struct lsa_LookupPrivValue *r)
2206 struct dcesrv_handle *h;
2207 struct lsa_policy_state *state;
2210 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2214 id = sec_privilege_id(r->in.name->string);
2216 return NT_STATUS_NO_SUCH_PRIVILEGE;
2219 r->out.luid->low = id;
2220 r->out.luid->high = 0;
2222 return NT_STATUS_OK;
2229 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
2230 TALLOC_CTX *mem_ctx,
2231 struct lsa_LookupPrivName *r)
2233 struct dcesrv_handle *h;
2234 struct lsa_policy_state *state;
2235 const char *privname;
2237 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2241 if (r->in.luid->high != 0) {
2242 return NT_STATUS_NO_SUCH_PRIVILEGE;
2245 privname = sec_privilege_name(r->in.luid->low);
2246 if (privname == NULL) {
2247 return NT_STATUS_NO_SUCH_PRIVILEGE;
2250 r->out.name = talloc(mem_ctx, struct lsa_String);
2251 if (r->out.name == NULL) {
2252 return NT_STATUS_NO_MEMORY;
2254 r->out.name->string = privname;
2256 return NT_STATUS_OK;
2261 lsa_LookupPrivDisplayName
2263 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
2264 TALLOC_CTX *mem_ctx,
2265 struct lsa_LookupPrivDisplayName *r)
2267 struct dcesrv_handle *h;
2268 struct lsa_policy_state *state;
2271 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2275 id = sec_privilege_id(r->in.name->string);
2277 return NT_STATUS_NO_SUCH_PRIVILEGE;
2280 r->out.disp_name = talloc(mem_ctx, struct lsa_String);
2281 if (r->out.disp_name == NULL) {
2282 return NT_STATUS_NO_MEMORY;
2285 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
2286 if (r->out.disp_name->string == NULL) {
2287 return NT_STATUS_INTERNAL_ERROR;
2290 return NT_STATUS_OK;
2297 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2298 struct lsa_DeleteObject *r)
2300 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2305 lsa_EnumAccountsWithUserRight
2307 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
2308 TALLOC_CTX *mem_ctx,
2309 struct lsa_EnumAccountsWithUserRight *r)
2311 struct dcesrv_handle *h;
2312 struct lsa_policy_state *state;
2314 struct ldb_message **res;
2315 const char * const attrs[] = { "objectSid", NULL};
2316 const char *privname;
2318 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2322 if (r->in.name == NULL) {
2323 return NT_STATUS_NO_SUCH_PRIVILEGE;
2326 privname = r->in.name->string;
2327 if (sec_privilege_id(privname) == -1) {
2328 return NT_STATUS_NO_SUCH_PRIVILEGE;
2331 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs,
2332 "privilege=%s", privname);
2334 return NT_STATUS_NO_SUCH_USER;
2337 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_SidPtr, ret);
2338 if (r->out.sids->sids == NULL) {
2339 return NT_STATUS_NO_MEMORY;
2341 for (i=0;i<ret;i++) {
2342 r->out.sids->sids[i].sid = samdb_result_dom_sid(r->out.sids->sids,
2343 res[i], "objectSid");
2344 NT_STATUS_HAVE_NO_MEMORY(r->out.sids->sids[i].sid);
2346 r->out.sids->num_sids = ret;
2348 return NT_STATUS_OK;
2353 lsa_AddAccountRights
2355 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
2356 TALLOC_CTX *mem_ctx,
2357 struct lsa_AddAccountRights *r)
2359 struct dcesrv_handle *h;
2360 struct lsa_policy_state *state;
2362 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2366 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2368 r->in.sid, r->in.rights);
2373 lsa_RemoveAccountRights
2375 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
2376 TALLOC_CTX *mem_ctx,
2377 struct lsa_RemoveAccountRights *r)
2379 struct dcesrv_handle *h;
2380 struct lsa_policy_state *state;
2382 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2386 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
2387 LDB_FLAG_MOD_DELETE,
2388 r->in.sid, r->in.rights);
2393 lsa_StorePrivateData
2395 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2396 struct lsa_StorePrivateData *r)
2398 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2403 lsa_RetrievePrivateData
2405 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2406 struct lsa_RetrievePrivateData *r)
2408 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2415 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2416 struct lsa_GetUserName *r)
2418 NTSTATUS status = NT_STATUS_OK;
2419 const char *account_name;
2420 const char *authority_name;
2421 struct lsa_String *_account_name;
2422 struct lsa_StringPointer *_authority_name = NULL;
2424 /* this is what w2k3 does */
2425 r->out.account_name = r->in.account_name;
2426 r->out.authority_name = r->in.authority_name;
2428 if (r->in.account_name && r->in.account_name->string) {
2429 return NT_STATUS_INVALID_PARAMETER;
2432 if (r->in.authority_name &&
2433 r->in.authority_name->string &&
2434 r->in.authority_name->string->string) {
2435 return NT_STATUS_INVALID_PARAMETER;
2438 /* TODO: this check should go and we should rely on the calling code that this is valid */
2439 if (!dce_call->conn->auth_state.session_info ||
2440 !dce_call->conn->auth_state.session_info->server_info ||
2441 !dce_call->conn->auth_state.session_info->server_info->account_name ||
2442 !dce_call->conn->auth_state.session_info->server_info->domain_name) {
2443 return NT_STATUS_INTERNAL_ERROR;
2446 account_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->account_name);
2447 authority_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->domain_name);
2449 _account_name = talloc(mem_ctx, struct lsa_String);
2450 NTSTATUS_TALLOC_CHECK(_account_name);
2451 _account_name->string = account_name;
2453 if (r->in.authority_name) {
2454 _authority_name = talloc(mem_ctx, struct lsa_StringPointer);
2455 NTSTATUS_TALLOC_CHECK(_authority_name);
2456 _authority_name->string = talloc(mem_ctx, struct lsa_String);
2457 NTSTATUS_TALLOC_CHECK(_authority_name->string);
2458 _authority_name->string->string = authority_name;
2461 r->out.account_name = _account_name;
2462 r->out.authority_name = _authority_name;
2470 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
2471 TALLOC_CTX *mem_ctx,
2472 struct lsa_SetInfoPolicy2 *r)
2474 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2478 lsa_QueryDomainInformationPolicy
2480 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
2481 TALLOC_CTX *mem_ctx,
2482 struct lsa_QueryDomainInformationPolicy *r)
2484 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2488 lsa_SetDomInfoPolicy
2490 static NTSTATUS lsa_SetDomInfoPolicy(struct dcesrv_call_state *dce_call,
2491 TALLOC_CTX *mem_ctx,
2492 struct lsa_SetDomInfoPolicy *r)
2494 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2500 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
2501 TALLOC_CTX *mem_ctx,
2502 struct lsa_TestCall *r)
2504 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2508 lookup a SID for 1 name
2510 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
2511 const char *name, struct dom_sid **sid, uint32_t *atype)
2514 struct ldb_message **res;
2515 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
2518 p = strchr_m(name, '\\');
2520 /* TODO: properly parse the domain prefix here, and use it to
2525 ret = gendb_search(state->sam_ldb, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", name);
2527 *sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
2529 return NT_STATUS_INVALID_SID;
2532 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
2534 return NT_STATUS_OK;
2537 /* need to add a call into sidmap to check for a allocated sid */
2539 return NT_STATUS_INVALID_SID;
2546 static NTSTATUS lsa_LookupNames3(struct dcesrv_call_state *dce_call,
2547 TALLOC_CTX *mem_ctx,
2548 struct lsa_LookupNames3 *r)
2550 struct lsa_policy_state *state;
2551 struct dcesrv_handle *h;
2553 NTSTATUS status = NT_STATUS_OK;
2555 r->out.domains = NULL;
2557 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2561 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2562 if (r->out.domains == NULL) {
2563 return NT_STATUS_NO_MEMORY;
2566 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray3);
2567 if (r->out.sids == NULL) {
2568 return NT_STATUS_NO_MEMORY;
2573 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid3,
2575 if (r->out.sids->sids == NULL) {
2576 return NT_STATUS_NO_MEMORY;
2579 for (i=0;i<r->in.num_names;i++) {
2580 const char *name = r->in.names[i].string;
2581 struct dom_sid *sid;
2582 uint32_t atype, rtype, sid_index;
2585 r->out.sids->count++;
2588 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2589 r->out.sids->sids[i].sid = NULL;
2590 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2591 r->out.sids->sids[i].unknown = 0;
2593 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2594 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2595 status = STATUS_SOME_UNMAPPED;
2599 rtype = samdb_atype_map(atype);
2600 if (rtype == SID_NAME_UNKNOWN) {
2601 status = STATUS_SOME_UNMAPPED;
2605 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2606 if (!NT_STATUS_IS_OK(status2)) {
2610 r->out.sids->sids[i].sid_type = rtype;
2611 r->out.sids->sids[i].sid = sid;
2612 r->out.sids->sids[i].sid_index = sid_index;
2613 r->out.sids->sids[i].unknown = 0;
2622 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
2623 TALLOC_CTX *mem_ctx,
2624 struct lsa_LookupNames2 *r)
2626 struct lsa_policy_state *state;
2627 struct dcesrv_handle *h;
2629 NTSTATUS status = NT_STATUS_OK;
2631 r->out.domains = NULL;
2633 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
2637 r->out.domains = talloc_zero(mem_ctx, struct lsa_RefDomainList);
2638 if (r->out.domains == NULL) {
2639 return NT_STATUS_NO_MEMORY;
2642 r->out.sids = talloc_zero(mem_ctx, struct lsa_TransSidArray2);
2643 if (r->out.sids == NULL) {
2644 return NT_STATUS_NO_MEMORY;
2649 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid2,
2651 if (r->out.sids->sids == NULL) {
2652 return NT_STATUS_NO_MEMORY;
2655 for (i=0;i<r->in.num_names;i++) {
2656 const char *name = r->in.names[i].string;
2657 struct dom_sid *sid;
2658 uint32_t atype, rtype, sid_index;
2661 r->out.sids->count++;
2664 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
2665 r->out.sids->sids[i].rid = 0xFFFFFFFF;
2666 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
2667 r->out.sids->sids[i].unknown = 0;
2669 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
2670 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
2671 status = STATUS_SOME_UNMAPPED;
2675 rtype = samdb_atype_map(atype);
2676 if (rtype == SID_NAME_UNKNOWN) {
2677 status = STATUS_SOME_UNMAPPED;
2681 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
2682 if (!NT_STATUS_IS_OK(status2)) {
2686 r->out.sids->sids[i].sid_type = rtype;
2687 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
2688 r->out.sids->sids[i].sid_index = sid_index;
2689 r->out.sids->sids[i].unknown = 0;
2698 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2699 struct lsa_LookupNames *r)
2701 struct lsa_LookupNames2 r2;
2705 r2.in.handle = r->in.handle;
2706 r2.in.num_names = r->in.num_names;
2707 r2.in.names = r->in.names;
2709 r2.in.level = r->in.level;
2710 r2.in.count = r->in.count;
2713 r2.out.count = r->out.count;
2715 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
2716 if (dce_call->fault_code != 0) {
2720 r->out.domains = r2.out.domains;
2721 r->out.sids = talloc(mem_ctx, struct lsa_TransSidArray);
2722 if (r->out.sids == NULL) {
2723 return NT_STATUS_NO_MEMORY;
2725 r->out.sids->count = r2.out.sids->count;
2726 r->out.sids->sids = talloc_array(r->out.sids, struct lsa_TranslatedSid,
2727 r->out.sids->count);
2728 if (r->out.sids->sids == NULL) {
2729 return NT_STATUS_NO_MEMORY;
2731 for (i=0;i<r->out.sids->count;i++) {
2732 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
2733 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
2734 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
2743 static NTSTATUS lsa_CREDRWRITE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2744 struct lsa_CREDRWRITE *r)
2746 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2753 static NTSTATUS lsa_CREDRREAD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2754 struct lsa_CREDRREAD *r)
2756 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2763 static NTSTATUS lsa_CREDRENUMERATE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2764 struct lsa_CREDRENUMERATE *r)
2766 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2771 lsa_CREDRWRITEDOMAINCREDENTIALS
2773 static NTSTATUS lsa_CREDRWRITEDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2774 struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
2776 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2781 lsa_CREDRREADDOMAINCREDENTIALS
2783 static NTSTATUS lsa_CREDRREADDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2784 struct lsa_CREDRREADDOMAINCREDENTIALS *r)
2786 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2793 static NTSTATUS lsa_CREDRDELETE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2794 struct lsa_CREDRDELETE *r)
2796 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2801 lsa_CREDRGETTARGETINFO
2803 static NTSTATUS lsa_CREDRGETTARGETINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2804 struct lsa_CREDRGETTARGETINFO *r)
2806 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2811 lsa_CREDRPROFILELOADED
2813 static NTSTATUS lsa_CREDRPROFILELOADED(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2814 struct lsa_CREDRPROFILELOADED *r)
2816 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2821 lsa_CREDRGETSESSIONTYPES
2823 static NTSTATUS lsa_CREDRGETSESSIONTYPES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2824 struct lsa_CREDRGETSESSIONTYPES *r)
2826 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2831 lsa_LSARREGISTERAUDITEVENT
2833 static NTSTATUS lsa_LSARREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2834 struct lsa_LSARREGISTERAUDITEVENT *r)
2836 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2841 lsa_LSARGENAUDITEVENT
2843 static NTSTATUS lsa_LSARGENAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2844 struct lsa_LSARGENAUDITEVENT *r)
2846 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2851 lsa_LSARUNREGISTERAUDITEVENT
2853 static NTSTATUS lsa_LSARUNREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2854 struct lsa_LSARUNREGISTERAUDITEVENT *r)
2856 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2861 lsa_LSARQUERYFORESTTRUSTINFORMATION
2863 static NTSTATUS lsa_LSARQUERYFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2864 struct lsa_LSARQUERYFORESTTRUSTINFORMATION *r)
2866 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2871 lsa_LSARSETFORESTTRUSTINFORMATION
2873 static NTSTATUS lsa_LSARSETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2874 struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2876 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2883 static NTSTATUS lsa_CREDRRENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2884 struct lsa_CREDRRENAME *r)
2886 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2891 lsa_LSARLOOKUPNAMES4
2893 static NTSTATUS lsa_LSARLOOKUPNAMES4(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2894 struct lsa_LSARLOOKUPNAMES4 *r)
2896 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2901 lsa_LSAROPENPOLICYSCE
2903 static NTSTATUS lsa_LSAROPENPOLICYSCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2904 struct lsa_LSAROPENPOLICYSCE *r)
2906 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2911 lsa_LSARADTREGISTERSECURITYEVENTSOURCE
2913 static NTSTATUS lsa_LSARADTREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2914 struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
2916 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2921 lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE
2923 static NTSTATUS lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2924 struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
2926 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2931 lsa_LSARADTREPORTSECURITYEVENT
2933 static NTSTATUS lsa_LSARADTREPORTSECURITYEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2934 struct lsa_LSARADTREPORTSECURITYEVENT *r)
2936 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2940 /* include the generated boilerplate */
2941 #include "librpc/gen_ndr/ndr_lsa_s.c"