2 Unix SMB/CIFS implementation.
4 endpoint server for the lsarpc pipe
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "librpc/gen_ndr/ndr_lsa.h"
25 #include "librpc/gen_ndr/ndr_samr.h"
26 #include "rpc_server/dcerpc_server.h"
27 #include "rpc_server/common/common.h"
28 #include "lib/ldb/include/ldb.h"
29 #include "auth/auth.h"
32 this type allows us to distinguish handle types
41 state associated with a lsa_OpenPolicy() operation
43 struct lsa_policy_state {
44 struct dcesrv_handle *handle;
46 struct sidmap_context *sidmap;
48 const char *domain_dn;
49 const char *builtin_dn;
50 const char *domain_name;
51 struct dom_sid *domain_sid;
52 struct dom_sid *builtin_sid;
57 state associated with a lsa_OpenAccount() operation
59 struct lsa_account_state {
60 struct lsa_policy_state *policy;
62 struct dom_sid *account_sid;
63 const char *account_sid_str;
64 const char *account_dn;
69 destroy an open policy. This closes the database connection
71 static void lsa_Policy_destroy(struct dcesrv_connection *conn, struct dcesrv_handle *h)
73 struct lsa_policy_state *state = h->data;
78 destroy an open account.
80 static void lsa_Account_destroy(struct dcesrv_connection *conn, struct dcesrv_handle *h)
82 struct lsa_account_state *astate = h->data;
89 static NTSTATUS lsa_Close(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
92 struct dcesrv_handle *h;
94 *r->out.handle = *r->in.handle;
96 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
98 /* this causes the callback samr_XXX_destroy() to be called by
99 the handle destroy code which destroys the state associated
101 dcesrv_handle_destroy(dce_call->conn, h);
103 ZERO_STRUCTP(r->out.handle);
112 static NTSTATUS lsa_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
113 struct lsa_Delete *r)
115 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
122 static NTSTATUS lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
123 struct lsa_EnumPrivs *r)
125 struct dcesrv_handle *h;
126 struct lsa_policy_state *state;
128 const char *privname;
130 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
134 i = *r->in.resume_handle;
137 while ((privname = sec_privilege_name(i)) &&
138 r->out.privs->count < r->in.max_count) {
139 struct lsa_PrivEntry *e;
141 r->out.privs->privs = talloc_realloc_p(r->out.privs,
143 struct lsa_PrivEntry,
144 r->out.privs->count+1);
145 if (r->out.privs->privs == NULL) {
146 return NT_STATUS_NO_MEMORY;
148 e = &r->out.privs->privs[r->out.privs->count];
151 e->name.string = privname;
152 r->out.privs->count++;
156 *r->out.resume_handle = i;
165 static NTSTATUS lsa_QuerySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
166 struct lsa_QuerySecurity *r)
168 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
175 static NTSTATUS lsa_SetSecObj(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
176 struct lsa_SetSecObj *r)
178 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
185 static NTSTATUS lsa_ChangePassword(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
186 struct lsa_ChangePassword *r)
188 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
191 static NTSTATUS lsa_get_policy_state(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
192 struct lsa_policy_state **_state)
194 struct lsa_policy_state *state;
197 state = talloc_p(mem_ctx, struct lsa_policy_state);
199 return NT_STATUS_NO_MEMORY;
202 /* make sure the sam database is accessible */
203 state->sam_ctx = samdb_connect(state);
204 if (state->sam_ctx == NULL) {
206 return NT_STATUS_INVALID_SYSTEM_SERVICE;
209 state->sidmap = sidmap_open(state);
210 if (state->sidmap == NULL) {
212 return NT_STATUS_INVALID_SYSTEM_SERVICE;
215 /* work out the domain_dn - useful for so many calls its worth
217 state->domain_dn = samdb_search_string(state->sam_ctx, state, NULL,
218 "dn", "(&(objectClass=domain)(!(objectclass=builtinDomain)))");
219 if (!state->domain_dn) {
221 return NT_STATUS_NO_SUCH_DOMAIN;
224 /* work out the builtin_dn - useful for so many calls its worth
226 state->builtin_dn = samdb_search_string(state->sam_ctx, state, NULL,
227 "dn", "objectClass=builtinDomain");
228 if (!state->builtin_dn) {
230 return NT_STATUS_NO_SUCH_DOMAIN;
233 sid_str = samdb_search_string(state->sam_ctx, state, NULL,
234 "objectSid", "dn=%s", state->domain_dn);
237 return NT_STATUS_NO_SUCH_DOMAIN;
240 state->domain_sid = dom_sid_parse_talloc(state, sid_str);
241 if (!state->domain_sid) {
243 return NT_STATUS_NO_SUCH_DOMAIN;
246 state->builtin_sid = dom_sid_parse_talloc(state, SID_BUILTIN);
247 if (!state->builtin_sid) {
249 return NT_STATUS_NO_SUCH_DOMAIN;
252 state->domain_name = samdb_search_string(state->sam_ctx, state, NULL,
253 "name", "dn=%s", state->domain_dn);
254 if (!state->domain_name) {
256 return NT_STATUS_NO_SUCH_DOMAIN;
267 static NTSTATUS lsa_OpenPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
268 struct lsa_OpenPolicy2 *r)
271 struct lsa_policy_state *state;
272 struct dcesrv_handle *handle;
274 ZERO_STRUCTP(r->out.handle);
276 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
277 if (!NT_STATUS_IS_OK(status)) {
281 handle = dcesrv_handle_new(dce_call->conn, LSA_HANDLE_POLICY);
283 return NT_STATUS_NO_MEMORY;
286 handle->data = talloc_reference(handle, state);
287 handle->destroy = lsa_Policy_destroy;
289 state->access_mask = r->in.access_mask;
290 state->handle = handle;
291 *r->out.handle = handle->wire_handle;
293 /* note that we have completely ignored the attr element of
294 the OpenPolicy. As far as I can tell, this is what w2k3
302 a wrapper around lsa_OpenPolicy2
304 static NTSTATUS lsa_OpenPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
305 struct lsa_OpenPolicy *r)
307 struct lsa_OpenPolicy2 r2;
309 r2.in.system_name = NULL;
310 r2.in.attr = r->in.attr;
311 r2.in.access_mask = r->in.access_mask;
312 r2.out.handle = r->out.handle;
314 return lsa_OpenPolicy2(dce_call, mem_ctx, &r2);
321 fill in the AccountDomain info
323 static NTSTATUS lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
324 struct lsa_DomainInfo *info)
326 const char * const attrs[] = { "objectSid", "name", NULL};
328 struct ldb_message **res;
330 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
331 "dn=%s", state->domain_dn);
333 return NT_STATUS_INTERNAL_DB_CORRUPTION;
336 info->name.string = samdb_result_string(res[0], "name", NULL);
337 info->sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
343 fill in the DNS domain info
345 static NTSTATUS lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
346 struct lsa_DnsDomainInfo *info)
348 const char * const attrs[] = { "name", "dnsDomain", "objectGUID", "objectSid", NULL };
350 struct ldb_message **res;
352 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
353 "dn=%s", state->domain_dn);
355 return NT_STATUS_INTERNAL_DB_CORRUPTION;
358 info->name.string = samdb_result_string(res[0], "name", NULL);
359 info->dns_domain.string = samdb_result_string(res[0], "dnsDomain", NULL);
360 info->dns_forest.string = samdb_result_string(res[0], "dnsDomain", NULL);
361 info->domain_guid = samdb_result_guid(res[0], "objectGUID");
362 info->sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
370 static NTSTATUS lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
371 struct lsa_QueryInfoPolicy2 *r)
373 struct lsa_policy_state *state;
374 struct dcesrv_handle *h;
378 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
382 r->out.info = talloc_p(mem_ctx, union lsa_PolicyInformation);
384 return NT_STATUS_NO_MEMORY;
387 ZERO_STRUCTP(r->out.info);
389 switch (r->in.level) {
390 case LSA_POLICY_INFO_DOMAIN:
391 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
392 return lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
394 case LSA_POLICY_INFO_DNS:
395 return lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
398 return NT_STATUS_INVALID_INFO_CLASS;
404 static NTSTATUS lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
405 struct lsa_QueryInfoPolicy *r)
407 struct lsa_QueryInfoPolicy2 r2;
410 r2.in.handle = r->in.handle;
411 r2.in.level = r->in.level;
413 status = lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
415 r->out.info = r2.out.info;
423 static NTSTATUS lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
424 struct lsa_SetInfoPolicy *r)
426 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
433 static NTSTATUS lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
434 struct lsa_ClearAuditLog *r)
436 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
443 static NTSTATUS lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
444 struct lsa_CreateAccount *r)
446 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
453 static NTSTATUS lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
454 struct lsa_EnumAccounts *r)
456 struct dcesrv_handle *h;
457 struct lsa_policy_state *state;
459 struct ldb_message **res;
460 const char * const attrs[] = { "objectSid", NULL};
463 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
467 ret = samdb_search(state->sam_ctx, mem_ctx, state->builtin_dn, &res, attrs, "objectClass=group");
469 return NT_STATUS_NO_SUCH_USER;
472 if (*r->in.resume_handle >= ret) {
473 return NT_STATUS_NO_MORE_ENTRIES;
476 count = ret - *r->in.resume_handle;
477 if (count > r->in.num_entries) {
478 count = r->in.num_entries;
482 return NT_STATUS_NO_MORE_ENTRIES;
485 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_SidPtr, count);
486 if (r->out.sids->sids == NULL) {
487 return NT_STATUS_NO_MEMORY;
490 for (i=0;i<count;i++) {
493 sidstr = samdb_result_string(res[i + *r->in.resume_handle], "objectSid", NULL);
494 if (sidstr == NULL) {
495 return NT_STATUS_NO_MEMORY;
497 r->out.sids->sids[i].sid = dom_sid_parse_talloc(r->out.sids->sids, sidstr);
498 if (r->out.sids->sids[i].sid == NULL) {
499 return NT_STATUS_NO_MEMORY;
503 r->out.sids->num_sids = count;
504 *r->out.resume_handle = count + *r->in.resume_handle;
512 lsa_CreateTrustedDomain
514 static NTSTATUS lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
515 struct lsa_CreateTrustedDomain *r)
517 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
524 static NTSTATUS lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
525 struct lsa_EnumTrustDom *r)
527 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
532 return the authority name and authority sid, given a sid
534 static NTSTATUS lsa_authority_name(struct lsa_policy_state *state,
535 TALLOC_CTX *mem_ctx, struct dom_sid *sid,
536 const char **authority_name,
537 struct dom_sid **authority_sid)
539 if (dom_sid_in_domain(state->domain_sid, sid)) {
540 *authority_name = state->domain_name;
541 *authority_sid = state->domain_sid;
545 if (dom_sid_in_domain(state->builtin_sid, sid)) {
546 *authority_name = "BUILTIN";
547 *authority_sid = state->builtin_sid;
551 *authority_sid = dom_sid_dup(mem_ctx, sid);
552 if (*authority_sid == NULL) {
553 return NT_STATUS_NO_MEMORY;
555 (*authority_sid)->num_auths = 0;
556 *authority_name = dom_sid_string(mem_ctx, *authority_sid);
557 if (*authority_name == NULL) {
558 return NT_STATUS_NO_MEMORY;
565 add to the lsa_RefDomainList for LookupSids and LookupNames
567 static NTSTATUS lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
569 struct lsa_RefDomainList *domains,
573 const char *authority_name;
574 struct dom_sid *authority_sid;
577 /* work out the authority name */
578 status = lsa_authority_name(state, mem_ctx, sid,
579 &authority_name, &authority_sid);
580 if (!NT_STATUS_IS_OK(status)) {
584 /* see if we've already done this authority name */
585 for (i=0;i<domains->count;i++) {
586 if (strcmp(authority_name, domains->domains[i].name.string) == 0) {
592 domains->domains = talloc_realloc_p(domains,
594 struct lsa_TrustInformation,
596 if (domains->domains == NULL) {
597 return NT_STATUS_NO_MEMORY;
599 domains->domains[i].name.string = authority_name;
600 domains->domains[i].sid = authority_sid;
608 lookup a name for 1 SID
610 static NTSTATUS lsa_lookup_sid(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
611 struct dom_sid *sid, const char *sid_str,
612 const char **name, uint32_t *atype)
615 struct ldb_message **res;
616 const char * const attrs[] = { "sAMAccountName", "sAMAccountType", "name", NULL};
619 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
620 "objectSid=%s", sid_str);
622 *name = ldb_msg_find_string(res[0], "sAMAccountName", NULL);
624 *name = ldb_msg_find_string(res[0], "name", NULL);
626 *name = talloc_strdup(mem_ctx, sid_str);
627 NTSTATUS_TALLOC_CHECK(*name);
631 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
636 status = sidmap_allocated_sid_lookup(state->sidmap, mem_ctx, sid, name, atype);
645 static NTSTATUS lsa_LookupSids3(struct dcesrv_call_state *dce_call,
647 struct lsa_LookupSids3 *r)
649 struct lsa_policy_state *state;
651 NTSTATUS status = NT_STATUS_OK;
653 r->out.domains = NULL;
655 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
656 if (!NT_STATUS_IS_OK(status)) {
660 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
661 if (r->out.domains == NULL) {
662 return NT_STATUS_NO_MEMORY;
665 r->out.names = talloc_zero_p(mem_ctx, struct lsa_TransNameArray2);
666 if (r->out.names == NULL) {
667 return NT_STATUS_NO_MEMORY;
672 r->out.names->names = talloc_array_p(r->out.names, struct lsa_TranslatedName2,
673 r->in.sids->num_sids);
674 if (r->out.names->names == NULL) {
675 return NT_STATUS_NO_MEMORY;
678 for (i=0;i<r->in.sids->num_sids;i++) {
679 struct dom_sid *sid = r->in.sids->sids[i].sid;
680 char *sid_str = dom_sid_string(mem_ctx, sid);
682 uint32_t atype, rtype, sid_index;
685 r->out.names->count++;
688 r->out.names->names[i].sid_type = SID_NAME_UNKNOWN;
689 r->out.names->names[i].name.string = sid_str;
690 r->out.names->names[i].sid_index = 0xFFFFFFFF;
691 r->out.names->names[i].unknown = 0;
693 if (sid_str == NULL) {
694 r->out.names->names[i].name.string = "(SIDERROR)";
695 status = STATUS_SOME_UNMAPPED;
699 /* work out the authority name */
700 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
701 if (!NT_STATUS_IS_OK(status2)) {
705 status2 = lsa_lookup_sid(state, mem_ctx, sid, sid_str,
707 if (!NT_STATUS_IS_OK(status2)) {
708 status = STATUS_SOME_UNMAPPED;
712 rtype = samdb_atype_map(atype);
713 if (rtype == SID_NAME_UNKNOWN) {
714 status = STATUS_SOME_UNMAPPED;
718 r->out.names->names[i].sid_type = rtype;
719 r->out.names->names[i].name.string = name;
720 r->out.names->names[i].sid_index = sid_index;
721 r->out.names->names[i].unknown = 0;
731 static NTSTATUS lsa_LookupSids2(struct dcesrv_call_state *dce_call,
733 struct lsa_LookupSids2 *r)
735 struct lsa_LookupSids3 r3;
738 r3.in.sids = r->in.sids;
739 r3.in.names = r->in.names;
740 r3.in.level = r->in.level;
741 r3.in.count = r->in.count;
742 r3.in.unknown1 = r->in.unknown1;
743 r3.in.unknown2 = r->in.unknown2;
744 r3.out.count = r->out.count;
745 r3.out.names = r->out.names;
747 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
748 if (dce_call->fault_code != 0) {
752 r->out.domains = r3.out.domains;
753 r->out.names = r3.out.names;
754 r->out.count = r3.out.count;
763 static NTSTATUS lsa_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
764 struct lsa_LookupSids *r)
766 struct lsa_LookupSids3 r3;
770 r3.in.sids = r->in.sids;
772 r3.in.level = r->in.level;
773 r3.in.count = r->in.count;
776 r3.out.count = r->out.count;
778 status = lsa_LookupSids3(dce_call, mem_ctx, &r3);
779 if (dce_call->fault_code != 0) {
783 r->out.domains = r3.out.domains;
784 r->out.names = talloc_p(mem_ctx, struct lsa_TransNameArray);
785 if (r->out.names == NULL) {
786 return NT_STATUS_NO_MEMORY;
788 r->out.names->count = r3.out.names->count;
789 r->out.names->names = talloc_array_p(r->out.names, struct lsa_TranslatedName,
790 r->out.names->count);
791 if (r->out.names->names == NULL) {
792 return NT_STATUS_NO_MEMORY;
794 for (i=0;i<r->out.names->count;i++) {
795 r->out.names->names[i].sid_type = r3.out.names->names[i].sid_type;
796 r->out.names->names[i].name.string = r3.out.names->names[i].name.string;
797 r->out.names->names[i].sid_index = r3.out.names->names[i].sid_index;
807 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
808 struct lsa_CreateSecret *r)
810 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
817 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
818 struct lsa_OpenAccount *r)
820 struct dcesrv_handle *h, *ah;
821 struct lsa_policy_state *state;
822 struct lsa_account_state *astate;
824 ZERO_STRUCTP(r->out.acct_handle);
826 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
830 astate = talloc_p(dce_call->conn, struct lsa_account_state);
831 if (astate == NULL) {
832 return NT_STATUS_NO_MEMORY;
835 astate->account_sid = dom_sid_dup(astate, r->in.sid);
836 if (astate->account_sid == NULL) {
838 return NT_STATUS_NO_MEMORY;
841 astate->account_sid_str = dom_sid_string(astate, astate->account_sid);
842 if (astate->account_sid_str == NULL) {
844 return NT_STATUS_NO_MEMORY;
847 /* check it really exists */
848 astate->account_dn = samdb_search_string(state->sam_ctx, astate,
850 "(&(objectSid=%s)(objectClass=group))",
851 astate->account_sid_str);
852 if (astate->account_dn == NULL) {
854 return NT_STATUS_NO_SUCH_USER;
857 astate->policy = talloc_reference(astate, state);
858 astate->access_mask = r->in.access_mask;
860 ah = dcesrv_handle_new(dce_call->conn, LSA_HANDLE_ACCOUNT);
863 return NT_STATUS_NO_MEMORY;
867 ah->destroy = lsa_Account_destroy;
869 *r->out.acct_handle = ah->wire_handle;
878 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
880 struct lsa_EnumPrivsAccount *r)
882 struct dcesrv_handle *h;
883 struct lsa_account_state *astate;
885 struct ldb_message **res;
886 const char * const attrs[] = { "privilege", NULL};
887 struct ldb_message_element *el;
889 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
893 r->out.privs = talloc_p(mem_ctx, struct lsa_PrivilegeSet);
894 r->out.privs->count = 0;
895 r->out.privs->unknown = 0;
896 r->out.privs->set = NULL;
898 ret = samdb_search(astate->policy->sam_ctx, mem_ctx, NULL, &res, attrs,
899 "dn=%s", astate->account_dn);
904 el = ldb_msg_find_element(res[0], "privilege");
905 if (el == NULL || el->num_values == 0) {
909 r->out.privs->set = talloc_array_p(r->out.privs,
910 struct lsa_LUIDAttribute, el->num_values);
911 if (r->out.privs->set == NULL) {
912 return NT_STATUS_NO_MEMORY;
915 for (i=0;i<el->num_values;i++) {
916 int id = sec_privilege_id(el->values[i].data);
918 return NT_STATUS_INTERNAL_DB_CORRUPTION;
920 r->out.privs->set[i].attribute = 0;
921 r->out.privs->set[i].luid.low = id;
922 r->out.privs->set[i].luid.high = 0;
925 r->out.privs->count = el->num_values;
931 lsa_EnumAccountRights
933 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
935 struct lsa_EnumAccountRights *r)
937 struct dcesrv_handle *h;
938 struct lsa_policy_state *state;
940 struct ldb_message **res;
941 const char * const attrs[] = { "privilege", NULL};
943 struct ldb_message_element *el;
945 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
949 sidstr = dom_sid_string(mem_ctx, r->in.sid);
950 if (sidstr == NULL) {
951 return NT_STATUS_NO_MEMORY;
954 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
955 "objectSid=%s", sidstr);
957 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
960 el = ldb_msg_find_element(res[0], "privilege");
961 if (el == NULL || el->num_values == 0) {
962 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
965 r->out.rights->count = el->num_values;
966 r->out.rights->names = talloc_array_p(r->out.rights,
967 struct lsa_String, r->out.rights->count);
968 if (r->out.rights->names == NULL) {
969 return NT_STATUS_NO_MEMORY;
972 for (i=0;i<el->num_values;i++) {
973 r->out.rights->names[i].string = el->values[i].data;
982 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
984 static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
986 struct lsa_policy_state *state,
989 const struct lsa_RightSet *rights)
992 struct ldb_message msg;
993 struct ldb_message_element el;
996 struct lsa_EnumAccountRights r2;
998 sidstr = dom_sid_string(mem_ctx, sid);
999 if (sidstr == NULL) {
1000 return NT_STATUS_NO_MEMORY;
1003 dn = samdb_search_string(state->sam_ctx, mem_ctx, NULL, "dn",
1004 "objectSid=%s", sidstr);
1006 return NT_STATUS_NO_SUCH_USER;
1009 msg.dn = talloc_strdup(mem_ctx, dn);
1010 if (msg.dn == NULL) {
1011 return NT_STATUS_NO_MEMORY;
1013 msg.num_elements = 1;
1015 el.flags = ldb_flag;
1016 el.name = talloc_strdup(mem_ctx, "privilege");
1017 if (el.name == NULL) {
1018 return NT_STATUS_NO_MEMORY;
1021 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1024 r2.in.handle = &state->handle->wire_handle;
1026 r2.out.rights = talloc_p(mem_ctx, struct lsa_RightSet);
1028 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1029 if (!NT_STATUS_IS_OK(status)) {
1030 ZERO_STRUCTP(r2.out.rights);
1035 el.values = talloc_array_p(mem_ctx, struct ldb_val, rights->count);
1036 if (el.values == NULL) {
1037 return NT_STATUS_NO_MEMORY;
1039 for (i=0;i<rights->count;i++) {
1040 if (sec_privilege_id(rights->names[i].string) == -1) {
1041 return NT_STATUS_NO_SUCH_PRIVILEGE;
1044 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1046 for (j=0;j<r2.out.rights->count;j++) {
1047 if (StrCaseCmp(r2.out.rights->names[j].string,
1048 rights->names[i].string) == 0) {
1052 if (j != r2.out.rights->count) continue;
1056 el.values[el.num_values].length = strlen(rights->names[i].string);
1057 el.values[el.num_values].data = talloc_strdup(mem_ctx, rights->names[i].string);
1058 if (el.values[el.num_values].data == NULL) {
1059 return NT_STATUS_NO_MEMORY;
1064 if (el.num_values == 0) {
1065 return NT_STATUS_OK;
1068 ret = samdb_modify(state->sam_ctx, mem_ctx, &msg);
1070 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1071 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1073 return NT_STATUS_UNEXPECTED_IO_ERROR;
1076 return NT_STATUS_OK;
1080 lsa_AddPrivilegesToAccount
1082 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1083 struct lsa_AddPrivilegesToAccount *r)
1085 struct lsa_RightSet rights;
1086 struct dcesrv_handle *h;
1087 struct lsa_account_state *astate;
1090 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1094 rights.count = r->in.privs->count;
1095 rights.names = talloc_array_p(mem_ctx, struct lsa_String, rights.count);
1096 if (rights.names == NULL) {
1097 return NT_STATUS_NO_MEMORY;
1099 for (i=0;i<rights.count;i++) {
1100 int id = r->in.privs->set[i].luid.low;
1101 if (r->in.privs->set[i].luid.high) {
1102 return NT_STATUS_NO_SUCH_PRIVILEGE;
1104 rights.names[i].string = sec_privilege_name(id);
1105 if (rights.names[i].string == NULL) {
1106 return NT_STATUS_NO_SUCH_PRIVILEGE;
1110 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1111 LDB_FLAG_MOD_ADD, astate->account_sid,
1117 lsa_RemovePrivilegesFromAccount
1119 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1120 struct lsa_RemovePrivilegesFromAccount *r)
1122 struct lsa_RightSet *rights;
1123 struct dcesrv_handle *h;
1124 struct lsa_account_state *astate;
1127 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1131 rights = talloc_p(mem_ctx, struct lsa_RightSet);
1133 if (r->in.remove_all == 1 &&
1134 r->in.privs == NULL) {
1135 struct lsa_EnumAccountRights r2;
1138 r2.in.handle = &astate->policy->handle->wire_handle;
1139 r2.in.sid = astate->account_sid;
1140 r2.out.rights = rights;
1142 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1143 if (!NT_STATUS_IS_OK(status)) {
1147 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1148 LDB_FLAG_MOD_DELETE, astate->account_sid,
1152 if (r->in.remove_all != 0) {
1153 return NT_STATUS_INVALID_PARAMETER;
1156 rights->count = r->in.privs->count;
1157 rights->names = talloc_array_p(mem_ctx, struct lsa_String, rights->count);
1158 if (rights->names == NULL) {
1159 return NT_STATUS_NO_MEMORY;
1161 for (i=0;i<rights->count;i++) {
1162 int id = r->in.privs->set[i].luid.low;
1163 if (r->in.privs->set[i].luid.high) {
1164 return NT_STATUS_NO_SUCH_PRIVILEGE;
1166 rights->names[i].string = sec_privilege_name(id);
1167 if (rights->names[i].string == NULL) {
1168 return NT_STATUS_NO_SUCH_PRIVILEGE;
1172 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1173 LDB_FLAG_MOD_DELETE, astate->account_sid,
1179 lsa_GetQuotasForAccount
1181 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1182 struct lsa_GetQuotasForAccount *r)
1184 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1189 lsa_SetQuotasForAccount
1191 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1192 struct lsa_SetQuotasForAccount *r)
1194 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1199 lsa_GetSystemAccessAccount
1201 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1202 struct lsa_GetSystemAccessAccount *r)
1204 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1209 lsa_SetSystemAccessAccount
1211 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1212 struct lsa_SetSystemAccessAccount *r)
1214 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1219 lsa_OpenTrustedDomain
1221 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1222 struct lsa_OpenTrustedDomain *r)
1224 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1229 lsa_QueryTrustedDomainInfo
1231 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1232 struct lsa_QueryTrustedDomainInfo *r)
1234 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1239 lsa_SetInformationTrustedDomain
1241 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1242 struct lsa_SetInformationTrustedDomain *r)
1244 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1251 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1252 struct lsa_OpenSecret *r)
1254 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1261 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1262 struct lsa_SetSecret *r)
1264 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1271 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1272 struct lsa_QuerySecret *r)
1274 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1281 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
1282 TALLOC_CTX *mem_ctx,
1283 struct lsa_LookupPrivValue *r)
1285 struct dcesrv_handle *h;
1286 struct lsa_policy_state *state;
1289 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1293 id = sec_privilege_id(r->in.name->string);
1295 return NT_STATUS_NO_SUCH_PRIVILEGE;
1298 r->out.luid->low = id;
1299 r->out.luid->high = 0;
1301 return NT_STATUS_OK;
1308 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
1309 TALLOC_CTX *mem_ctx,
1310 struct lsa_LookupPrivName *r)
1312 struct dcesrv_handle *h;
1313 struct lsa_policy_state *state;
1314 const char *privname;
1316 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1320 if (r->in.luid->high != 0) {
1321 return NT_STATUS_NO_SUCH_PRIVILEGE;
1324 privname = sec_privilege_name(r->in.luid->low);
1325 if (privname == NULL) {
1326 return NT_STATUS_NO_SUCH_PRIVILEGE;
1329 r->out.name = talloc_p(mem_ctx, struct lsa_String);
1330 if (r->out.name == NULL) {
1331 return NT_STATUS_NO_MEMORY;
1333 r->out.name->string = privname;
1335 return NT_STATUS_OK;
1340 lsa_LookupPrivDisplayName
1342 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
1343 TALLOC_CTX *mem_ctx,
1344 struct lsa_LookupPrivDisplayName *r)
1346 struct dcesrv_handle *h;
1347 struct lsa_policy_state *state;
1350 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1354 id = sec_privilege_id(r->in.name->string);
1356 return NT_STATUS_NO_SUCH_PRIVILEGE;
1359 r->out.disp_name = talloc_p(mem_ctx, struct lsa_String);
1360 if (r->out.disp_name == NULL) {
1361 return NT_STATUS_NO_MEMORY;
1364 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
1365 if (r->out.disp_name->string == NULL) {
1366 return NT_STATUS_INTERNAL_ERROR;
1369 return NT_STATUS_OK;
1376 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1377 struct lsa_DeleteObject *r)
1379 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1384 lsa_EnumAccountsWithUserRight
1386 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
1387 TALLOC_CTX *mem_ctx,
1388 struct lsa_EnumAccountsWithUserRight *r)
1390 struct dcesrv_handle *h;
1391 struct lsa_policy_state *state;
1393 struct ldb_message **res;
1394 const char * const attrs[] = { "objectSid", NULL};
1395 const char *privname;
1397 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1401 if (r->in.name == NULL) {
1402 return NT_STATUS_NO_SUCH_PRIVILEGE;
1405 privname = r->in.name->string;
1406 if (sec_privilege_id(privname) == -1) {
1407 return NT_STATUS_NO_SUCH_PRIVILEGE;
1410 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
1411 "privilege=%s", privname);
1413 return NT_STATUS_NO_SUCH_USER;
1416 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_SidPtr, ret);
1417 if (r->out.sids->sids == NULL) {
1418 return NT_STATUS_NO_MEMORY;
1420 for (i=0;i<ret;i++) {
1422 sidstr = samdb_result_string(res[i], "objectSid", NULL);
1423 if (sidstr == NULL) {
1424 return NT_STATUS_NO_MEMORY;
1426 r->out.sids->sids[i].sid = dom_sid_parse_talloc(r->out.sids->sids,
1428 if (r->out.sids->sids[i].sid == NULL) {
1429 return NT_STATUS_NO_MEMORY;
1432 r->out.sids->num_sids = ret;
1434 return NT_STATUS_OK;
1439 lsa_AddAccountRights
1441 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
1442 TALLOC_CTX *mem_ctx,
1443 struct lsa_AddAccountRights *r)
1445 struct dcesrv_handle *h;
1446 struct lsa_policy_state *state;
1448 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1452 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
1454 r->in.sid, r->in.rights);
1459 lsa_RemoveAccountRights
1461 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
1462 TALLOC_CTX *mem_ctx,
1463 struct lsa_RemoveAccountRights *r)
1465 struct dcesrv_handle *h;
1466 struct lsa_policy_state *state;
1468 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1472 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
1473 LDB_FLAG_MOD_DELETE,
1474 r->in.sid, r->in.rights);
1479 lsa_QueryTrustedDomainInfoBySid
1481 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1482 struct lsa_QueryTrustedDomainInfoBySid *r)
1484 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1489 lsa_SetTrustDomainInfo
1491 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1492 struct lsa_SetTrustDomainInfo *r)
1494 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1499 lsa_DeleteTrustDomain
1501 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1502 struct lsa_DeleteTrustDomain *r)
1504 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1509 lsa_StorePrivateData
1511 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1512 struct lsa_StorePrivateData *r)
1514 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1519 lsa_RetrievePrivateData
1521 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1522 struct lsa_RetrievePrivateData *r)
1524 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1531 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1532 struct lsa_GetUserName *r)
1534 NTSTATUS status = NT_STATUS_OK;
1535 const char *account_name;
1536 const char *authority_name;
1537 struct lsa_String *_account_name;
1538 struct lsa_StringPointer *_authority_name = NULL;
1540 /* this is what w2k3 does */
1541 r->out.account_name = r->in.account_name;
1542 r->out.authority_name = r->in.authority_name;
1544 if (r->in.account_name && r->in.account_name->string) {
1545 return NT_STATUS_INVALID_PARAMETER;
1548 if (r->in.authority_name &&
1549 r->in.authority_name->string &&
1550 r->in.authority_name->string->string) {
1551 return NT_STATUS_INVALID_PARAMETER;
1554 /* TODO: this check should go and we should rely on the calling code that this is valid */
1555 if (!dce_call->conn->auth_state.session_info ||
1556 !dce_call->conn->auth_state.session_info->server_info ||
1557 !dce_call->conn->auth_state.session_info->server_info->account_name ||
1558 !dce_call->conn->auth_state.session_info->server_info->domain) {
1559 return NT_STATUS_INTERNAL_ERROR;
1562 account_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->account_name);
1563 authority_name = talloc_reference(mem_ctx, dce_call->conn->auth_state.session_info->server_info->domain);
1565 _account_name = talloc_p(mem_ctx, struct lsa_String);
1566 NTSTATUS_TALLOC_CHECK(_account_name);
1567 _account_name->string = account_name;
1569 if (r->in.authority_name) {
1570 _authority_name = talloc_p(mem_ctx, struct lsa_StringPointer);
1571 NTSTATUS_TALLOC_CHECK(_authority_name);
1572 _authority_name->string = talloc_p(mem_ctx, struct lsa_String);
1573 NTSTATUS_TALLOC_CHECK(_authority_name->string);
1574 _authority_name->string->string = authority_name;
1577 r->out.account_name = _account_name;
1578 r->out.authority_name = _authority_name;
1586 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
1587 TALLOC_CTX *mem_ctx,
1588 struct lsa_SetInfoPolicy2 *r)
1590 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1594 lsa_QueryTrustedDomainInfoByName
1596 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1597 TALLOC_CTX *mem_ctx,
1598 struct lsa_QueryTrustedDomainInfoByName *r)
1600 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1604 lsa_SetTrustedDomainInfoByName
1606 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1607 TALLOC_CTX *mem_ctx,
1608 struct lsa_SetTrustedDomainInfoByName *r)
1610 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1614 lsa_EnumTrustedDomainsEx
1616 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
1617 TALLOC_CTX *mem_ctx,
1618 struct lsa_EnumTrustedDomainsEx *r)
1620 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1624 lsa_CreateTrustedDomainEx
1626 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
1627 TALLOC_CTX *mem_ctx,
1628 struct lsa_CreateTrustedDomainEx *r)
1630 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1634 lsa_CloseTrustedDomainEx
1636 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
1637 TALLOC_CTX *mem_ctx,
1638 struct lsa_CloseTrustedDomainEx *r)
1640 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1644 lsa_QueryDomainInformationPolicy
1646 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
1647 TALLOC_CTX *mem_ctx,
1648 struct lsa_QueryDomainInformationPolicy *r)
1650 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1654 lsa_SetDomInfoPolicy
1656 static NTSTATUS lsa_SetDomInfoPolicy(struct dcesrv_call_state *dce_call,
1657 TALLOC_CTX *mem_ctx,
1658 struct lsa_SetDomInfoPolicy *r)
1660 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1664 lsa_OpenTrustedDomainByName
1666 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
1667 TALLOC_CTX *mem_ctx,
1668 struct lsa_OpenTrustedDomainByName *r)
1670 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1676 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
1677 TALLOC_CTX *mem_ctx,
1678 struct lsa_TestCall *r)
1680 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1684 lookup a SID for 1 name
1686 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1687 const char *name, struct dom_sid **sid, uint32_t *atype)
1690 struct ldb_message **res;
1691 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
1694 p = strchr_m(name, '\\');
1696 /* TODO: properly parse the domain prefix here, and use it to
1701 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", name);
1703 const char *sid_str = ldb_msg_find_string(res[0], "objectSid", NULL);
1704 if (sid_str == NULL) {
1705 return NT_STATUS_INVALID_SID;
1708 *sid = dom_sid_parse_talloc(mem_ctx, sid_str);
1710 return NT_STATUS_INVALID_SID;
1713 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1715 return NT_STATUS_OK;
1718 /* need to add a call into sidmap to check for a allocated sid */
1720 return NT_STATUS_INVALID_SID;
1727 static NTSTATUS lsa_LookupNames3(struct dcesrv_call_state *dce_call,
1728 TALLOC_CTX *mem_ctx,
1729 struct lsa_LookupNames3 *r)
1731 struct lsa_policy_state *state;
1732 struct dcesrv_handle *h;
1734 NTSTATUS status = NT_STATUS_OK;
1736 r->out.domains = NULL;
1738 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1742 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
1743 if (r->out.domains == NULL) {
1744 return NT_STATUS_NO_MEMORY;
1747 r->out.sids = talloc_zero_p(mem_ctx, struct lsa_TransSidArray3);
1748 if (r->out.sids == NULL) {
1749 return NT_STATUS_NO_MEMORY;
1754 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid3,
1756 if (r->out.sids->sids == NULL) {
1757 return NT_STATUS_NO_MEMORY;
1760 for (i=0;i<r->in.num_names;i++) {
1761 const char *name = r->in.names[i].string;
1762 struct dom_sid *sid;
1763 uint32_t atype, rtype, sid_index;
1766 r->out.sids->count++;
1769 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
1770 r->out.sids->sids[i].sid = NULL;
1771 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
1772 r->out.sids->sids[i].unknown = 0;
1774 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
1775 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
1776 status = STATUS_SOME_UNMAPPED;
1780 rtype = samdb_atype_map(atype);
1781 if (rtype == SID_NAME_UNKNOWN) {
1782 status = STATUS_SOME_UNMAPPED;
1786 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1787 if (!NT_STATUS_IS_OK(status2)) {
1791 r->out.sids->sids[i].sid_type = rtype;
1792 r->out.sids->sids[i].sid = sid;
1793 r->out.sids->sids[i].sid_index = sid_index;
1794 r->out.sids->sids[i].unknown = 0;
1803 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
1804 TALLOC_CTX *mem_ctx,
1805 struct lsa_LookupNames2 *r)
1807 struct lsa_policy_state *state;
1808 struct dcesrv_handle *h;
1810 NTSTATUS status = NT_STATUS_OK;
1812 r->out.domains = NULL;
1814 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1818 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
1819 if (r->out.domains == NULL) {
1820 return NT_STATUS_NO_MEMORY;
1823 r->out.sids = talloc_zero_p(mem_ctx, struct lsa_TransSidArray2);
1824 if (r->out.sids == NULL) {
1825 return NT_STATUS_NO_MEMORY;
1830 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid2,
1832 if (r->out.sids->sids == NULL) {
1833 return NT_STATUS_NO_MEMORY;
1836 for (i=0;i<r->in.num_names;i++) {
1837 const char *name = r->in.names[i].string;
1838 struct dom_sid *sid;
1839 uint32_t atype, rtype, sid_index;
1842 r->out.sids->count++;
1845 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
1846 r->out.sids->sids[i].rid = 0xFFFFFFFF;
1847 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
1848 r->out.sids->sids[i].unknown = 0;
1850 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
1851 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
1852 status = STATUS_SOME_UNMAPPED;
1856 rtype = samdb_atype_map(atype);
1857 if (rtype == SID_NAME_UNKNOWN) {
1858 status = STATUS_SOME_UNMAPPED;
1862 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1863 if (!NT_STATUS_IS_OK(status2)) {
1867 r->out.sids->sids[i].sid_type = rtype;
1868 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
1869 r->out.sids->sids[i].sid_index = sid_index;
1870 r->out.sids->sids[i].unknown = 0;
1879 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1880 struct lsa_LookupNames *r)
1882 struct lsa_LookupNames2 r2;
1886 r2.in.handle = r->in.handle;
1887 r2.in.num_names = r->in.num_names;
1888 r2.in.names = r->in.names;
1890 r2.in.level = r->in.level;
1891 r2.in.count = r->in.count;
1894 r2.out.count = r->out.count;
1896 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
1897 if (dce_call->fault_code != 0) {
1901 r->out.domains = r2.out.domains;
1902 r->out.sids = talloc_p(mem_ctx, struct lsa_TransSidArray);
1903 if (r->out.sids == NULL) {
1904 return NT_STATUS_NO_MEMORY;
1906 r->out.sids->count = r2.out.sids->count;
1907 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid,
1908 r->out.sids->count);
1909 if (r->out.sids->sids == NULL) {
1910 return NT_STATUS_NO_MEMORY;
1912 for (i=0;i<r->out.sids->count;i++) {
1913 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
1914 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
1915 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
1924 lsa_CreateTrustedDomainEx2
1926 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
1927 TALLOC_CTX *mem_ctx,
1928 struct lsa_CreateTrustedDomainEx2 *r)
1930 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1936 static NTSTATUS lsa_CREDRWRITE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1937 struct lsa_CREDRWRITE *r)
1939 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1946 static NTSTATUS lsa_CREDRREAD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1947 struct lsa_CREDRREAD *r)
1949 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1956 static NTSTATUS lsa_CREDRENUMERATE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1957 struct lsa_CREDRENUMERATE *r)
1959 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1964 lsa_CREDRWRITEDOMAINCREDENTIALS
1966 static NTSTATUS lsa_CREDRWRITEDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1967 struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
1969 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1974 lsa_CREDRREADDOMAINCREDENTIALS
1976 static NTSTATUS lsa_CREDRREADDOMAINCREDENTIALS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1977 struct lsa_CREDRREADDOMAINCREDENTIALS *r)
1979 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1986 static NTSTATUS lsa_CREDRDELETE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1987 struct lsa_CREDRDELETE *r)
1989 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1994 lsa_CREDRGETTARGETINFO
1996 static NTSTATUS lsa_CREDRGETTARGETINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1997 struct lsa_CREDRGETTARGETINFO *r)
1999 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2004 lsa_CREDRPROFILELOADED
2006 static NTSTATUS lsa_CREDRPROFILELOADED(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2007 struct lsa_CREDRPROFILELOADED *r)
2009 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2014 lsa_CREDRGETSESSIONTYPES
2016 static NTSTATUS lsa_CREDRGETSESSIONTYPES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2017 struct lsa_CREDRGETSESSIONTYPES *r)
2019 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2024 lsa_LSARREGISTERAUDITEVENT
2026 static NTSTATUS lsa_LSARREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2027 struct lsa_LSARREGISTERAUDITEVENT *r)
2029 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2034 lsa_LSARGENAUDITEVENT
2036 static NTSTATUS lsa_LSARGENAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2037 struct lsa_LSARGENAUDITEVENT *r)
2039 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2044 lsa_LSARUNREGISTERAUDITEVENT
2046 static NTSTATUS lsa_LSARUNREGISTERAUDITEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2047 struct lsa_LSARUNREGISTERAUDITEVENT *r)
2049 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2054 lsa_LSARQUERYFORESTTRUSTINFORMATION
2056 static NTSTATUS lsa_LSARQUERYFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2057 struct lsa_LSARQUERYFORESTTRUSTINFORMATION *r)
2059 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2064 lsa_LSARSETFORESTTRUSTINFORMATION
2066 static NTSTATUS lsa_LSARSETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2067 struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2069 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2076 static NTSTATUS lsa_CREDRRENAME(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2077 struct lsa_CREDRRENAME *r)
2079 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2084 lsa_LSARLOOKUPNAMES4
2086 static NTSTATUS lsa_LSARLOOKUPNAMES4(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2087 struct lsa_LSARLOOKUPNAMES4 *r)
2089 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2094 lsa_LSAROPENPOLICYSCE
2096 static NTSTATUS lsa_LSAROPENPOLICYSCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2097 struct lsa_LSAROPENPOLICYSCE *r)
2099 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2104 lsa_LSARADTREGISTERSECURITYEVENTSOURCE
2106 static NTSTATUS lsa_LSARADTREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2107 struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
2109 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2114 lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE
2116 static NTSTATUS lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2117 struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
2119 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2124 lsa_LSARADTREPORTSECURITYEVENT
2126 static NTSTATUS lsa_LSARADTREPORTSECURITYEVENT(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
2127 struct lsa_LSARADTREPORTSECURITYEVENT *r)
2129 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
2133 /* include the generated boilerplate */
2134 #include "librpc/gen_ndr/ndr_lsa_s.c"