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->in.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_LookupSids2(struct dcesrv_call_state *dce_call,
647 struct lsa_LookupSids2 *r)
649 struct lsa_policy_state *state;
650 struct dcesrv_handle *h;
652 NTSTATUS status = NT_STATUS_OK;
654 r->out.domains = NULL;
656 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
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_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
732 struct lsa_LookupSids *r)
734 struct lsa_LookupSids2 r2;
738 r2.in.handle = r->in.handle;
739 r2.in.sids = r->in.sids;
741 r2.in.level = r->in.level;
742 r2.in.count = r->in.count;
745 r2.out.count = r->out.count;
747 status = lsa_LookupSids2(dce_call, mem_ctx, &r2);
748 if (dce_call->fault_code != 0) {
752 r->out.domains = r2.out.domains;
753 r->out.names = talloc_p(mem_ctx, struct lsa_TransNameArray);
754 if (r->out.names == NULL) {
755 return NT_STATUS_NO_MEMORY;
757 r->out.names->count = r2.out.names->count;
758 r->out.names->names = talloc_array_p(r->out.names, struct lsa_TranslatedName,
759 r->out.names->count);
760 if (r->out.names->names == NULL) {
761 return NT_STATUS_NO_MEMORY;
763 for (i=0;i<r->out.names->count;i++) {
764 r->out.names->names[i].sid_type = r2.out.names->names[i].sid_type;
765 r->out.names->names[i].name.string = r2.out.names->names[i].name.string;
766 r->out.names->names[i].sid_index = r2.out.names->names[i].sid_index;
776 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
777 struct lsa_CreateSecret *r)
779 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
786 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
787 struct lsa_OpenAccount *r)
789 struct dcesrv_handle *h, *ah;
790 struct lsa_policy_state *state;
791 struct lsa_account_state *astate;
793 ZERO_STRUCTP(r->out.acct_handle);
795 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
799 astate = talloc_p(dce_call->conn, struct lsa_account_state);
800 if (astate == NULL) {
801 return NT_STATUS_NO_MEMORY;
804 astate->account_sid = dom_sid_dup(astate, r->in.sid);
805 if (astate->account_sid == NULL) {
807 return NT_STATUS_NO_MEMORY;
810 astate->account_sid_str = dom_sid_string(astate, astate->account_sid);
811 if (astate->account_sid_str == NULL) {
813 return NT_STATUS_NO_MEMORY;
816 /* check it really exists */
817 astate->account_dn = samdb_search_string(state->sam_ctx, astate,
819 "(&(objectSid=%s)(objectClass=group))",
820 astate->account_sid_str);
821 if (astate->account_dn == NULL) {
823 return NT_STATUS_NO_SUCH_USER;
826 astate->policy = talloc_reference(astate, state);
827 astate->access_mask = r->in.access_mask;
829 ah = dcesrv_handle_new(dce_call->conn, LSA_HANDLE_ACCOUNT);
832 return NT_STATUS_NO_MEMORY;
836 ah->destroy = lsa_Account_destroy;
838 *r->out.acct_handle = ah->wire_handle;
847 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call,
849 struct lsa_EnumPrivsAccount *r)
851 struct dcesrv_handle *h;
852 struct lsa_account_state *astate;
854 struct ldb_message **res;
855 const char * const attrs[] = { "privilege", NULL};
856 struct ldb_message_element *el;
858 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
862 r->out.privs = talloc_p(mem_ctx, struct lsa_PrivilegeSet);
863 r->out.privs->count = 0;
864 r->out.privs->unknown = 0;
865 r->out.privs->set = NULL;
867 ret = samdb_search(astate->policy->sam_ctx, mem_ctx, NULL, &res, attrs,
868 "dn=%s", astate->account_dn);
873 el = ldb_msg_find_element(res[0], "privilege");
874 if (el == NULL || el->num_values == 0) {
878 r->out.privs->set = talloc_array_p(r->out.privs,
879 struct lsa_LUIDAttribute, el->num_values);
880 if (r->out.privs->set == NULL) {
881 return NT_STATUS_NO_MEMORY;
884 for (i=0;i<el->num_values;i++) {
885 int id = sec_privilege_id(el->values[i].data);
887 return NT_STATUS_INTERNAL_DB_CORRUPTION;
889 r->out.privs->set[i].attribute = 0;
890 r->out.privs->set[i].luid.low = id;
891 r->out.privs->set[i].luid.high = 0;
894 r->out.privs->count = el->num_values;
900 lsa_EnumAccountRights
902 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
904 struct lsa_EnumAccountRights *r)
906 struct dcesrv_handle *h;
907 struct lsa_policy_state *state;
909 struct ldb_message **res;
910 const char * const attrs[] = { "privilege", NULL};
912 struct ldb_message_element *el;
914 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
918 sidstr = dom_sid_string(mem_ctx, r->in.sid);
919 if (sidstr == NULL) {
920 return NT_STATUS_NO_MEMORY;
923 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
924 "objectSid=%s", sidstr);
926 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
929 el = ldb_msg_find_element(res[0], "privilege");
930 if (el == NULL || el->num_values == 0) {
931 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
934 r->out.rights->count = el->num_values;
935 r->out.rights->names = talloc_array_p(r->out.rights,
936 struct lsa_String, r->out.rights->count);
937 if (r->out.rights->names == NULL) {
938 return NT_STATUS_NO_MEMORY;
941 for (i=0;i<el->num_values;i++) {
942 r->out.rights->names[i].string = el->values[i].data;
951 helper for lsa_AddAccountRights and lsa_RemoveAccountRights
953 static NTSTATUS lsa_AddRemoveAccountRights(struct dcesrv_call_state *dce_call,
955 struct lsa_policy_state *state,
958 const struct lsa_RightSet *rights)
961 struct ldb_message msg;
962 struct ldb_message_element el;
965 struct lsa_EnumAccountRights r2;
967 sidstr = dom_sid_string(mem_ctx, sid);
968 if (sidstr == NULL) {
969 return NT_STATUS_NO_MEMORY;
972 dn = samdb_search_string(state->sam_ctx, mem_ctx, NULL, "dn",
973 "objectSid=%s", sidstr);
975 return NT_STATUS_NO_SUCH_USER;
978 msg.dn = talloc_strdup(mem_ctx, dn);
979 if (msg.dn == NULL) {
980 return NT_STATUS_NO_MEMORY;
982 msg.num_elements = 1;
985 el.name = talloc_strdup(mem_ctx, "privilege");
986 if (el.name == NULL) {
987 return NT_STATUS_NO_MEMORY;
990 if (ldb_flag == LDB_FLAG_MOD_ADD) {
993 r2.in.handle = &state->handle->wire_handle;
995 r2.out.rights = talloc_p(mem_ctx, struct lsa_RightSet);
997 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
998 if (!NT_STATUS_IS_OK(status)) {
999 ZERO_STRUCTP(r2.out.rights);
1004 el.values = talloc_array_p(mem_ctx, struct ldb_val, rights->count);
1005 if (el.values == NULL) {
1006 return NT_STATUS_NO_MEMORY;
1008 for (i=0;i<rights->count;i++) {
1009 if (sec_privilege_id(rights->names[i].string) == -1) {
1010 return NT_STATUS_NO_SUCH_PRIVILEGE;
1013 if (ldb_flag == LDB_FLAG_MOD_ADD) {
1015 for (j=0;j<r2.out.rights->count;j++) {
1016 if (StrCaseCmp(r2.out.rights->names[j].string,
1017 rights->names[i].string) == 0) {
1021 if (j != r2.out.rights->count) continue;
1025 el.values[el.num_values].length = strlen(rights->names[i].string);
1026 el.values[el.num_values].data = talloc_strdup(mem_ctx, rights->names[i].string);
1027 if (el.values[el.num_values].data == NULL) {
1028 return NT_STATUS_NO_MEMORY;
1033 if (el.num_values == 0) {
1034 return NT_STATUS_OK;
1037 ret = samdb_modify(state->sam_ctx, mem_ctx, &msg);
1039 if (ldb_flag == LDB_FLAG_MOD_DELETE) {
1040 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1042 return NT_STATUS_UNEXPECTED_IO_ERROR;
1045 return NT_STATUS_OK;
1049 lsa_AddPrivilegesToAccount
1051 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1052 struct lsa_AddPrivilegesToAccount *r)
1054 struct lsa_RightSet rights;
1055 struct dcesrv_handle *h;
1056 struct lsa_account_state *astate;
1059 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1063 rights.count = r->in.privs->count;
1064 rights.names = talloc_array_p(mem_ctx, struct lsa_String, rights.count);
1065 if (rights.names == NULL) {
1066 return NT_STATUS_NO_MEMORY;
1068 for (i=0;i<rights.count;i++) {
1069 int id = r->in.privs->set[i].luid.low;
1070 if (r->in.privs->set[i].luid.high) {
1071 return NT_STATUS_NO_SUCH_PRIVILEGE;
1073 rights.names[i].string = sec_privilege_name(id);
1074 if (rights.names[i].string == NULL) {
1075 return NT_STATUS_NO_SUCH_PRIVILEGE;
1079 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1080 LDB_FLAG_MOD_ADD, astate->account_sid,
1086 lsa_RemovePrivilegesFromAccount
1088 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1089 struct lsa_RemovePrivilegesFromAccount *r)
1091 struct lsa_RightSet *rights;
1092 struct dcesrv_handle *h;
1093 struct lsa_account_state *astate;
1096 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_ACCOUNT);
1100 rights = talloc_p(mem_ctx, struct lsa_RightSet);
1102 if (r->in.remove_all == 1 &&
1103 r->in.privs == NULL) {
1104 struct lsa_EnumAccountRights r2;
1107 r2.in.handle = &astate->policy->handle->wire_handle;
1108 r2.in.sid = astate->account_sid;
1109 r2.out.rights = rights;
1111 status = lsa_EnumAccountRights(dce_call, mem_ctx, &r2);
1112 if (!NT_STATUS_IS_OK(status)) {
1116 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1117 LDB_FLAG_MOD_DELETE, astate->account_sid,
1121 if (r->in.remove_all != 0) {
1122 return NT_STATUS_INVALID_PARAMETER;
1125 rights->count = r->in.privs->count;
1126 rights->names = talloc_array_p(mem_ctx, struct lsa_String, rights->count);
1127 if (rights->names == NULL) {
1128 return NT_STATUS_NO_MEMORY;
1130 for (i=0;i<rights->count;i++) {
1131 int id = r->in.privs->set[i].luid.low;
1132 if (r->in.privs->set[i].luid.high) {
1133 return NT_STATUS_NO_SUCH_PRIVILEGE;
1135 rights->names[i].string = sec_privilege_name(id);
1136 if (rights->names[i].string == NULL) {
1137 return NT_STATUS_NO_SUCH_PRIVILEGE;
1141 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, astate->policy,
1142 LDB_FLAG_MOD_DELETE, astate->account_sid,
1148 lsa_GetQuotasForAccount
1150 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1151 struct lsa_GetQuotasForAccount *r)
1153 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1158 lsa_SetQuotasForAccount
1160 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1161 struct lsa_SetQuotasForAccount *r)
1163 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1168 lsa_GetSystemAccessAccount
1170 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1171 struct lsa_GetSystemAccessAccount *r)
1173 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1178 lsa_SetSystemAccessAccount
1180 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1181 struct lsa_SetSystemAccessAccount *r)
1183 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1188 lsa_OpenTrustedDomain
1190 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1191 struct lsa_OpenTrustedDomain *r)
1193 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1198 lsa_QueryTrustedDomainInfo
1200 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1201 struct lsa_QueryTrustedDomainInfo *r)
1203 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1208 lsa_SetInformationTrustedDomain
1210 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1211 struct lsa_SetInformationTrustedDomain *r)
1213 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1220 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1221 struct lsa_OpenSecret *r)
1223 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1230 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1231 struct lsa_SetSecret *r)
1233 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1240 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1241 struct lsa_QuerySecret *r)
1243 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1250 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
1251 TALLOC_CTX *mem_ctx,
1252 struct lsa_LookupPrivValue *r)
1254 struct dcesrv_handle *h;
1255 struct lsa_policy_state *state;
1258 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1262 id = sec_privilege_id(r->in.name->string);
1264 return NT_STATUS_NO_SUCH_PRIVILEGE;
1267 r->out.luid->low = id;
1268 r->out.luid->high = 0;
1270 return NT_STATUS_OK;
1277 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
1278 TALLOC_CTX *mem_ctx,
1279 struct lsa_LookupPrivName *r)
1281 struct dcesrv_handle *h;
1282 struct lsa_policy_state *state;
1283 const char *privname;
1285 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1289 if (r->in.luid->high != 0) {
1290 return NT_STATUS_NO_SUCH_PRIVILEGE;
1293 privname = sec_privilege_name(r->in.luid->low);
1294 if (privname == NULL) {
1295 return NT_STATUS_NO_SUCH_PRIVILEGE;
1298 r->out.name = talloc_p(mem_ctx, struct lsa_String);
1299 if (r->out.name == NULL) {
1300 return NT_STATUS_NO_MEMORY;
1302 r->out.name->string = privname;
1304 return NT_STATUS_OK;
1309 lsa_LookupPrivDisplayName
1311 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
1312 TALLOC_CTX *mem_ctx,
1313 struct lsa_LookupPrivDisplayName *r)
1315 struct dcesrv_handle *h;
1316 struct lsa_policy_state *state;
1319 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1323 id = sec_privilege_id(r->in.name->string);
1325 return NT_STATUS_NO_SUCH_PRIVILEGE;
1328 r->out.disp_name = talloc_p(mem_ctx, struct lsa_String);
1329 if (r->out.disp_name == NULL) {
1330 return NT_STATUS_NO_MEMORY;
1333 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
1334 if (r->out.disp_name->string == NULL) {
1335 return NT_STATUS_INTERNAL_ERROR;
1338 return NT_STATUS_OK;
1345 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1346 struct lsa_DeleteObject *r)
1348 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1353 lsa_EnumAccountsWithUserRight
1355 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
1356 TALLOC_CTX *mem_ctx,
1357 struct lsa_EnumAccountsWithUserRight *r)
1359 struct dcesrv_handle *h;
1360 struct lsa_policy_state *state;
1362 struct ldb_message **res;
1363 const char * const attrs[] = { "objectSid", NULL};
1364 const char *privname;
1366 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1370 if (r->in.name == NULL) {
1371 return NT_STATUS_NO_SUCH_PRIVILEGE;
1374 privname = r->in.name->string;
1375 if (sec_privilege_id(privname) == -1) {
1376 return NT_STATUS_NO_SUCH_PRIVILEGE;
1379 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
1380 "privilege=%s", privname);
1382 return NT_STATUS_NO_SUCH_USER;
1385 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_SidPtr, ret);
1386 if (r->out.sids->sids == NULL) {
1387 return NT_STATUS_NO_MEMORY;
1389 for (i=0;i<ret;i++) {
1391 sidstr = samdb_result_string(res[i], "objectSid", NULL);
1392 if (sidstr == NULL) {
1393 return NT_STATUS_NO_MEMORY;
1395 r->out.sids->sids[i].sid = dom_sid_parse_talloc(r->out.sids->sids,
1397 if (r->out.sids->sids[i].sid == NULL) {
1398 return NT_STATUS_NO_MEMORY;
1401 r->out.sids->num_sids = ret;
1403 return NT_STATUS_OK;
1408 lsa_AddAccountRights
1410 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call,
1411 TALLOC_CTX *mem_ctx,
1412 struct lsa_AddAccountRights *r)
1414 struct dcesrv_handle *h;
1415 struct lsa_policy_state *state;
1417 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1421 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
1423 r->in.sid, r->in.rights);
1428 lsa_RemoveAccountRights
1430 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call,
1431 TALLOC_CTX *mem_ctx,
1432 struct lsa_RemoveAccountRights *r)
1434 struct dcesrv_handle *h;
1435 struct lsa_policy_state *state;
1437 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1441 return lsa_AddRemoveAccountRights(dce_call, mem_ctx, state,
1442 LDB_FLAG_MOD_DELETE,
1443 r->in.sid, r->in.rights);
1448 lsa_QueryTrustedDomainInfoBySid
1450 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1451 struct lsa_QueryTrustedDomainInfoBySid *r)
1453 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1458 lsa_SetTrustDomainInfo
1460 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1461 struct lsa_SetTrustDomainInfo *r)
1463 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1468 lsa_DeleteTrustDomain
1470 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1471 struct lsa_DeleteTrustDomain *r)
1473 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1478 lsa_StorePrivateData
1480 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1481 struct lsa_StorePrivateData *r)
1483 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1488 lsa_RetrievePrivateData
1490 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1491 struct lsa_RetrievePrivateData *r)
1493 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1500 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1501 struct lsa_GetUserName *r)
1503 NTSTATUS status = NT_STATUS_OK;
1504 struct lsa_policy_state *state;
1506 struct dom_sid *account_sid;
1507 struct dom_sid *authority_sid;
1508 const char *account_sid_str;
1509 const char *account_name;
1510 const char *authority_name;
1511 struct lsa_String *_account_name;
1512 struct lsa_StringPointer *_authority_name = NULL;
1514 /* this is what w2k3 does */
1515 r->out.account_name = r->in.account_name;
1516 r->out.authority_name = r->in.authority_name;
1518 if (r->in.account_name && r->in.account_name->string) {
1519 return NT_STATUS_INVALID_PARAMETER;
1522 if (r->in.authority_name &&
1523 r->in.authority_name->string &&
1524 r->in.authority_name->string->string) {
1525 return NT_STATUS_INVALID_PARAMETER;
1528 /* TODO: this check should go and we should rely on the calling code that this is valid */
1529 if (!dce_call->conn->auth_state.session_info ||
1530 !dce_call->conn->auth_state.session_info->security_token ||
1531 !dce_call->conn->auth_state.session_info->security_token->user_sid) {
1532 return NT_STATUS_INTERNAL_ERROR;
1535 account_sid = dce_call->conn->auth_state.session_info->security_token->user_sid;
1537 account_sid_str = dom_sid_string(mem_ctx, account_sid);
1538 NTSTATUS_TALLOC_CHECK(account_sid_str);
1540 status = lsa_get_policy_state(dce_call, mem_ctx, &state);
1541 if (!NT_STATUS_IS_OK(status)) {
1545 status = lsa_lookup_sid(state, mem_ctx,
1546 account_sid, account_sid_str,
1547 &account_name, &atype);
1548 if (!NT_STATUS_IS_OK(status)) {
1552 _account_name = talloc_p(mem_ctx, struct lsa_String);
1553 NTSTATUS_TALLOC_CHECK(_account_name);
1554 _account_name->string = account_name;
1556 if (r->in.authority_name) {
1557 status = lsa_authority_name(state, mem_ctx, account_sid,
1558 &authority_name, &authority_sid);
1559 if (!NT_STATUS_IS_OK(status)) {
1563 _authority_name = talloc_p(mem_ctx, struct lsa_StringPointer);
1564 NTSTATUS_TALLOC_CHECK(_authority_name);
1565 _authority_name->string = talloc_p(mem_ctx, struct lsa_String);
1566 NTSTATUS_TALLOC_CHECK(_authority_name->string);
1567 _authority_name->string->string = authority_name;
1570 r->out.account_name = _account_name;
1571 r->out.authority_name = _authority_name;
1579 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
1580 TALLOC_CTX *mem_ctx,
1581 struct lsa_SetInfoPolicy2 *r)
1583 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1587 lsa_QueryTrustedDomainInfoByName
1589 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1590 TALLOC_CTX *mem_ctx,
1591 struct lsa_QueryTrustedDomainInfoByName *r)
1593 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1597 lsa_SetTrustedDomainInfoByName
1599 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1600 TALLOC_CTX *mem_ctx,
1601 struct lsa_SetTrustedDomainInfoByName *r)
1603 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1607 lsa_EnumTrustedDomainsEx
1609 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
1610 TALLOC_CTX *mem_ctx,
1611 struct lsa_EnumTrustedDomainsEx *r)
1613 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1617 lsa_CreateTrustedDomainEx
1619 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
1620 TALLOC_CTX *mem_ctx,
1621 struct lsa_CreateTrustedDomainEx *r)
1623 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1627 lsa_CloseTrustedDomainEx
1629 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
1630 TALLOC_CTX *mem_ctx,
1631 struct lsa_CloseTrustedDomainEx *r)
1633 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1637 lsa_QueryDomainInformationPolicy
1639 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
1640 TALLOC_CTX *mem_ctx,
1641 struct lsa_QueryDomainInformationPolicy *r)
1643 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1647 lsa_SetDomInfoPolicy
1649 static NTSTATUS lsa_SetDomInfoPolicy(struct dcesrv_call_state *dce_call,
1650 TALLOC_CTX *mem_ctx,
1651 struct lsa_SetDomInfoPolicy *r)
1653 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1657 lsa_OpenTrustedDomainByName
1659 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
1660 TALLOC_CTX *mem_ctx,
1661 struct lsa_OpenTrustedDomainByName *r)
1663 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1669 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
1670 TALLOC_CTX *mem_ctx,
1671 struct lsa_TestCall *r)
1673 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1677 lookup a SID for 1 name
1679 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1680 const char *name, struct dom_sid **sid, uint32_t *atype)
1683 struct ldb_message **res;
1684 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
1686 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", name);
1688 const char *sid_str = ldb_msg_find_string(res[0], "objectSid", NULL);
1689 if (sid_str == NULL) {
1690 return NT_STATUS_INVALID_SID;
1693 *sid = dom_sid_parse_talloc(mem_ctx, sid_str);
1695 return NT_STATUS_INVALID_SID;
1698 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1700 return NT_STATUS_OK;
1703 /* need to add a call into sidmap to check for a allocated sid */
1705 return NT_STATUS_INVALID_SID;
1711 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
1712 TALLOC_CTX *mem_ctx,
1713 struct lsa_LookupNames2 *r)
1715 struct lsa_policy_state *state;
1716 struct dcesrv_handle *h;
1718 NTSTATUS status = NT_STATUS_OK;
1720 r->out.domains = NULL;
1722 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1726 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
1727 if (r->out.domains == NULL) {
1728 return NT_STATUS_NO_MEMORY;
1731 r->out.sids = talloc_zero_p(mem_ctx, struct lsa_TransSidArray2);
1732 if (r->out.sids == NULL) {
1733 return NT_STATUS_NO_MEMORY;
1738 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid2,
1740 if (r->out.sids->sids == NULL) {
1741 return NT_STATUS_NO_MEMORY;
1744 for (i=0;i<r->in.num_names;i++) {
1745 const char *name = r->in.names[i].string;
1746 struct dom_sid *sid;
1747 uint32_t atype, rtype, sid_index;
1750 r->out.sids->count++;
1753 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
1754 r->out.sids->sids[i].rid = 0xFFFFFFFF;
1755 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
1756 r->out.sids->sids[i].unknown = 0;
1758 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
1759 if (!NT_STATUS_IS_OK(status2) || sid->num_auths == 0) {
1760 status = STATUS_SOME_UNMAPPED;
1764 rtype = samdb_atype_map(atype);
1765 if (rtype == SID_NAME_UNKNOWN) {
1766 status = STATUS_SOME_UNMAPPED;
1770 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1771 if (!NT_STATUS_IS_OK(status2)) {
1775 r->out.sids->sids[i].sid_type = rtype;
1776 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
1777 r->out.sids->sids[i].sid_index = sid_index;
1778 r->out.sids->sids[i].unknown = 0;
1787 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1788 struct lsa_LookupNames *r)
1790 struct lsa_LookupNames2 r2;
1794 r2.in.handle = r->in.handle;
1795 r2.in.num_names = r->in.num_names;
1796 r2.in.names = r->in.names;
1798 r2.in.level = r->in.level;
1799 r2.in.count = r->in.count;
1802 r2.out.count = r->out.count;
1804 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
1805 if (dce_call->fault_code != 0) {
1809 r->out.domains = r2.out.domains;
1810 r->out.sids = talloc_p(mem_ctx, struct lsa_TransSidArray);
1811 if (r->out.sids == NULL) {
1812 return NT_STATUS_NO_MEMORY;
1814 r->out.sids->count = r2.out.sids->count;
1815 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid,
1816 r->out.sids->count);
1817 if (r->out.sids->sids == NULL) {
1818 return NT_STATUS_NO_MEMORY;
1820 for (i=0;i<r->out.sids->count;i++) {
1821 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
1822 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
1823 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
1832 lsa_CreateTrustedDomainEx2
1834 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
1835 TALLOC_CTX *mem_ctx,
1836 struct lsa_CreateTrustedDomainEx2 *r)
1838 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1841 /* include the generated boilerplate */
1842 #include "librpc/gen_ndr/ndr_lsa_s.c"