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"
31 this type allows us to distinguish handle types
40 state associated with a lsa_OpenPolicy() operation
42 struct lsa_policy_state {
44 struct sidmap_context *sidmap;
46 const char *domain_dn;
47 const char *domain_name;
48 struct dom_sid *domain_sid;
49 struct dom_sid *builtin_sid;
54 destroy an open policy. This closes the database connection
56 static void lsa_Policy_destroy(struct dcesrv_connection *conn, struct dcesrv_handle *h)
58 struct lsa_policy_state *state = h->data;
65 static NTSTATUS lsa_Close(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
68 struct dcesrv_handle *h;
70 *r->out.handle = *r->in.handle;
72 DCESRV_PULL_HANDLE(h, r->in.handle, DCESRV_HANDLE_ANY);
74 /* this causes the callback samr_XXX_destroy() to be called by
75 the handle destroy code which destroys the state associated
77 dcesrv_handle_destroy(dce_call->conn, h);
79 ZERO_STRUCTP(r->out.handle);
88 static NTSTATUS lsa_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
91 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
98 static NTSTATUS lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
99 struct lsa_EnumPrivs *r)
101 struct dcesrv_handle *h;
102 struct lsa_policy_state *state;
104 const char *privname;
106 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
110 i = *r->in.resume_handle;
113 while ((privname = sec_privilege_name(i)) &&
114 r->out.privs->count < r->in.max_count) {
115 struct lsa_PrivEntry *e;
117 r->out.privs->privs = talloc_realloc_p(r->out.privs,
119 struct lsa_PrivEntry,
120 r->out.privs->count+1);
121 if (r->out.privs->privs == NULL) {
122 return NT_STATUS_NO_MEMORY;
124 e = &r->out.privs->privs[r->out.privs->count];
127 e->name.string = privname;
128 r->out.privs->count++;
132 *r->in.resume_handle = i;
141 static NTSTATUS lsa_QuerySecurity(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
142 struct lsa_QuerySecurity *r)
144 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
151 static NTSTATUS lsa_SetSecObj(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
152 struct lsa_SetSecObj *r)
154 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
161 static NTSTATUS lsa_ChangePassword(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
162 struct lsa_ChangePassword *r)
164 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
171 static NTSTATUS lsa_OpenPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
172 struct lsa_OpenPolicy2 *r)
174 struct lsa_policy_state *state;
175 struct dcesrv_handle *handle;
178 ZERO_STRUCTP(r->out.handle);
180 state = talloc_p(dce_call->conn, struct lsa_policy_state);
182 return NT_STATUS_NO_MEMORY;
185 /* make sure the sam database is accessible */
186 state->sam_ctx = samdb_connect(state);
187 if (state->sam_ctx == NULL) {
189 return NT_STATUS_INVALID_SYSTEM_SERVICE;
192 state->sidmap = sidmap_open(state);
193 if (state->sidmap == NULL) {
195 return NT_STATUS_INVALID_SYSTEM_SERVICE;
198 /* work out the domain_dn - useful for so many calls its worth
200 state->domain_dn = samdb_search_string(state->sam_ctx, state, NULL,
201 "dn", "(&(objectClass=domain)(!(objectclass=builtinDomain)))");
202 if (!state->domain_dn) {
204 return NT_STATUS_NO_SUCH_DOMAIN;
207 sid_str = samdb_search_string(state->sam_ctx, state, NULL,
208 "objectSid", "dn=%s", state->domain_dn);
211 return NT_STATUS_NO_SUCH_DOMAIN;
214 state->domain_sid = dom_sid_parse_talloc(state, sid_str);
215 if (!state->domain_sid) {
217 return NT_STATUS_NO_SUCH_DOMAIN;
220 state->builtin_sid = dom_sid_parse_talloc(state, SID_BUILTIN);
221 if (!state->builtin_sid) {
223 return NT_STATUS_NO_SUCH_DOMAIN;
226 state->domain_name = samdb_search_string(state->sam_ctx, state, NULL,
227 "name", "dn=%s", state->domain_dn);
228 if (!state->domain_name) {
230 return NT_STATUS_NO_SUCH_DOMAIN;
234 handle = dcesrv_handle_new(dce_call->conn, LSA_HANDLE_POLICY);
237 return NT_STATUS_NO_MEMORY;
240 handle->data = state;
241 handle->destroy = lsa_Policy_destroy;
243 state->access_mask = r->in.access_mask;
244 *r->out.handle = handle->wire_handle;
246 /* note that we have completely ignored the attr element of
247 the OpenPolicy. As far as I can tell, this is what w2k3
255 a wrapper around lsa_OpenPolicy2
257 static NTSTATUS lsa_OpenPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
258 struct lsa_OpenPolicy *r)
260 struct lsa_OpenPolicy2 r2;
262 r2.in.system_name = NULL;
263 r2.in.attr = r->in.attr;
264 r2.in.access_mask = r->in.access_mask;
265 r2.out.handle = r->out.handle;
267 return lsa_OpenPolicy2(dce_call, mem_ctx, &r2);
274 fill in the AccountDomain info
276 static NTSTATUS lsa_info_AccountDomain(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
277 struct lsa_DomainInfo *info)
279 const char * const attrs[] = { "objectSid", "name", NULL};
281 struct ldb_message **res;
283 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
284 "dn=%s", state->domain_dn);
286 return NT_STATUS_INTERNAL_DB_CORRUPTION;
289 info->name.string = samdb_result_string(res[0], "name", NULL);
290 info->sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
296 fill in the DNS domain info
298 static NTSTATUS lsa_info_DNS(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
299 struct lsa_DnsDomainInfo *info)
301 const char * const attrs[] = { "name", "dnsDomain", "objectGUID", "objectSid", NULL };
303 struct ldb_message **res;
305 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
306 "dn=%s", state->domain_dn);
308 return NT_STATUS_INTERNAL_DB_CORRUPTION;
311 info->name.string = samdb_result_string(res[0], "name", NULL);
312 info->dns_domain.string = samdb_result_string(res[0], "dnsDomain", NULL);
313 info->dns_forest.string = samdb_result_string(res[0], "dnsDomain", NULL);
314 info->domain_guid = samdb_result_guid(res[0], "objectGUID");
315 info->sid = samdb_result_dom_sid(mem_ctx, res[0], "objectSid");
323 static NTSTATUS lsa_QueryInfoPolicy2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
324 struct lsa_QueryInfoPolicy2 *r)
326 struct lsa_policy_state *state;
327 struct dcesrv_handle *h;
331 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
335 r->out.info = talloc_p(mem_ctx, union lsa_PolicyInformation);
337 return NT_STATUS_NO_MEMORY;
340 ZERO_STRUCTP(r->out.info);
342 switch (r->in.level) {
343 case LSA_POLICY_INFO_DOMAIN:
344 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
345 return lsa_info_AccountDomain(state, mem_ctx, &r->out.info->account_domain);
347 case LSA_POLICY_INFO_DNS:
348 return lsa_info_DNS(state, mem_ctx, &r->out.info->dns);
351 return NT_STATUS_INVALID_INFO_CLASS;
357 static NTSTATUS lsa_QueryInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
358 struct lsa_QueryInfoPolicy *r)
360 struct lsa_QueryInfoPolicy2 r2;
363 r2.in.handle = r->in.handle;
364 r2.in.level = r->in.level;
366 status = lsa_QueryInfoPolicy2(dce_call, mem_ctx, &r2);
368 r->out.info = r2.out.info;
376 static NTSTATUS lsa_SetInfoPolicy(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
377 struct lsa_SetInfoPolicy *r)
379 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
386 static NTSTATUS lsa_ClearAuditLog(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
387 struct lsa_ClearAuditLog *r)
389 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
396 static NTSTATUS lsa_CreateAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
397 struct lsa_CreateAccount *r)
399 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
406 static NTSTATUS lsa_EnumAccounts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
407 struct lsa_EnumAccounts *r)
409 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
414 lsa_CreateTrustedDomain
416 static NTSTATUS lsa_CreateTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
417 struct lsa_CreateTrustedDomain *r)
419 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
426 static NTSTATUS lsa_EnumTrustDom(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
427 struct lsa_EnumTrustDom *r)
429 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
434 return the authority name and authority sid, given a sid
436 static NTSTATUS lsa_authority_name(struct lsa_policy_state *state,
437 TALLOC_CTX *mem_ctx, struct dom_sid *sid,
438 const char **authority_name,
439 struct dom_sid **authority_sid)
441 if (dom_sid_in_domain(state->domain_sid, sid)) {
442 *authority_name = state->domain_name;
443 *authority_sid = state->domain_sid;
447 if (dom_sid_in_domain(state->builtin_sid, sid)) {
448 *authority_name = "BUILTIN";
449 *authority_sid = state->builtin_sid;
453 *authority_sid = dom_sid_dup(mem_ctx, sid);
454 if (*authority_sid == NULL) {
455 return NT_STATUS_NO_MEMORY;
457 (*authority_sid)->num_auths = 0;
458 *authority_name = dom_sid_string(mem_ctx, *authority_sid);
459 if (*authority_name == NULL) {
460 return NT_STATUS_NO_MEMORY;
467 add to the lsa_RefDomainList for LookupSids and LookupNames
469 static NTSTATUS lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
471 struct lsa_RefDomainList *domains,
475 const char *authority_name;
476 struct dom_sid *authority_sid;
479 /* work out the authority name */
480 status = lsa_authority_name(state, mem_ctx, sid,
481 &authority_name, &authority_sid);
482 if (!NT_STATUS_IS_OK(status)) {
486 /* see if we've already done this authority name */
487 for (i=0;i<domains->count;i++) {
488 if (strcmp(authority_name, domains->domains[i].name.string) == 0) {
494 domains->domains = talloc_realloc_p(domains,
496 struct lsa_TrustInformation,
498 if (domains->domains == NULL) {
499 return NT_STATUS_NO_MEMORY;
501 domains->domains[i].name.string = authority_name;
502 domains->domains[i].sid = authority_sid;
510 lookup a name for 1 SID
512 static NTSTATUS lsa_lookup_sid(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
513 struct dom_sid *sid, const char *sid_str,
514 const char **name, uint32_t *atype)
517 struct ldb_message **res;
518 const char * const attrs[] = { "sAMAccountName", "sAMAccountType", NULL};
521 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
522 "objectSid=%s", sid_str);
524 *name = ldb_msg_find_string(res[0], "sAMAccountName", NULL);
526 return NT_STATUS_NO_MEMORY;
529 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
534 status = sidmap_allocated_sid_lookup(state->sidmap, mem_ctx, sid, name, atype);
543 static NTSTATUS lsa_LookupSids2(struct dcesrv_call_state *dce_call,
545 struct lsa_LookupSids2 *r)
547 struct lsa_policy_state *state;
548 struct dcesrv_handle *h;
550 NTSTATUS status = NT_STATUS_OK;
552 r->out.domains = NULL;
554 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
558 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
559 if (r->out.domains == NULL) {
560 return NT_STATUS_NO_MEMORY;
563 r->out.names = talloc_zero_p(mem_ctx, struct lsa_TransNameArray2);
564 if (r->out.names == NULL) {
565 return NT_STATUS_NO_MEMORY;
570 r->out.names->names = talloc_array_p(r->out.names, struct lsa_TranslatedName2,
571 r->in.sids->num_sids);
572 if (r->out.names->names == NULL) {
573 return NT_STATUS_NO_MEMORY;
576 for (i=0;i<r->in.sids->num_sids;i++) {
577 struct dom_sid *sid = r->in.sids->sids[i].sid;
578 char *sid_str = dom_sid_string(mem_ctx, sid);
580 uint32_t atype, rtype, sid_index;
583 r->out.names->count++;
586 r->out.names->names[i].sid_type = SID_NAME_UNKNOWN;
587 r->out.names->names[i].name.string = sid_str;
588 r->out.names->names[i].sid_index = 0xFFFFFFFF;
589 r->out.names->names[i].unknown = 0;
591 if (sid_str == NULL) {
592 r->out.names->names[i].name.string = "(SIDERROR)";
593 status = STATUS_SOME_UNMAPPED;
597 /* work out the authority name */
598 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
599 if (!NT_STATUS_IS_OK(status2)) {
603 status2 = lsa_lookup_sid(state, mem_ctx, sid, sid_str,
605 if (!NT_STATUS_IS_OK(status2)) {
606 status = STATUS_SOME_UNMAPPED;
610 rtype = samdb_atype_map(atype);
611 if (rtype == SID_NAME_UNKNOWN) {
612 status = STATUS_SOME_UNMAPPED;
616 r->out.names->names[i].sid_type = rtype;
617 r->out.names->names[i].name.string = name;
618 r->out.names->names[i].sid_index = sid_index;
619 r->out.names->names[i].unknown = 0;
629 static NTSTATUS lsa_LookupSids(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
630 struct lsa_LookupSids *r)
632 struct lsa_LookupSids2 r2;
636 r2.in.handle = r->in.handle;
637 r2.in.sids = r->in.sids;
639 r2.in.level = r->in.level;
640 r2.in.count = r->in.count;
643 r2.out.count = r->out.count;
645 status = lsa_LookupSids2(dce_call, mem_ctx, &r2);
646 if (dce_call->fault_code != 0) {
650 r->out.domains = r2.out.domains;
651 r->out.names = talloc_p(mem_ctx, struct lsa_TransNameArray);
652 if (r->out.names == NULL) {
653 return NT_STATUS_NO_MEMORY;
655 r->out.names->count = r2.out.names->count;
656 r->out.names->names = talloc_array_p(r->out.names, struct lsa_TranslatedName,
657 r->out.names->count);
658 if (r->out.names->names == NULL) {
659 return NT_STATUS_NO_MEMORY;
661 for (i=0;i<r->out.names->count;i++) {
662 r->out.names->names[i].sid_type = r2.out.names->names[i].sid_type;
663 r->out.names->names[i].name.string = r2.out.names->names[i].name.string;
664 r->out.names->names[i].sid_index = r2.out.names->names[i].sid_index;
674 static NTSTATUS lsa_CreateSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
675 struct lsa_CreateSecret *r)
677 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
684 static NTSTATUS lsa_OpenAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
685 struct lsa_OpenAccount *r)
687 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
694 static NTSTATUS lsa_EnumPrivsAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
695 struct lsa_EnumPrivsAccount *r)
697 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
702 lsa_AddPrivilegesToAccount
704 static NTSTATUS lsa_AddPrivilegesToAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
705 struct lsa_AddPrivilegesToAccount *r)
707 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
712 lsa_RemovePrivilegesFromAccount
714 static NTSTATUS lsa_RemovePrivilegesFromAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
715 struct lsa_RemovePrivilegesFromAccount *r)
717 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
722 lsa_GetQuotasForAccount
724 static NTSTATUS lsa_GetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
725 struct lsa_GetQuotasForAccount *r)
727 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
732 lsa_SetQuotasForAccount
734 static NTSTATUS lsa_SetQuotasForAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
735 struct lsa_SetQuotasForAccount *r)
737 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
742 lsa_GetSystemAccessAccount
744 static NTSTATUS lsa_GetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
745 struct lsa_GetSystemAccessAccount *r)
747 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
752 lsa_SetSystemAccessAccount
754 static NTSTATUS lsa_SetSystemAccessAccount(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
755 struct lsa_SetSystemAccessAccount *r)
757 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
762 lsa_OpenTrustedDomain
764 static NTSTATUS lsa_OpenTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
765 struct lsa_OpenTrustedDomain *r)
767 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
772 lsa_QueryTrustedDomainInfo
774 static NTSTATUS lsa_QueryTrustedDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
775 struct lsa_QueryTrustedDomainInfo *r)
777 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
782 lsa_SetInformationTrustedDomain
784 static NTSTATUS lsa_SetInformationTrustedDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
785 struct lsa_SetInformationTrustedDomain *r)
787 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
794 static NTSTATUS lsa_OpenSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
795 struct lsa_OpenSecret *r)
797 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
804 static NTSTATUS lsa_SetSecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
805 struct lsa_SetSecret *r)
807 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
814 static NTSTATUS lsa_QuerySecret(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
815 struct lsa_QuerySecret *r)
817 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
824 static NTSTATUS lsa_LookupPrivValue(struct dcesrv_call_state *dce_call,
826 struct lsa_LookupPrivValue *r)
828 struct dcesrv_handle *h;
829 struct lsa_policy_state *state;
832 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
836 id = sec_privilege_id(r->in.name->string);
838 return NT_STATUS_NO_SUCH_PRIVILEGE;
841 r->out.luid->low = id;
842 r->out.luid->high = 0;
851 static NTSTATUS lsa_LookupPrivName(struct dcesrv_call_state *dce_call,
853 struct lsa_LookupPrivName *r)
855 struct dcesrv_handle *h;
856 struct lsa_policy_state *state;
857 const char *privname;
859 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
863 if (r->in.luid->high != 0) {
864 return NT_STATUS_NO_SUCH_PRIVILEGE;
867 privname = sec_privilege_name(r->in.luid->low);
868 if (privname == NULL) {
869 return NT_STATUS_NO_SUCH_PRIVILEGE;
872 r->out.name = talloc_p(mem_ctx, struct lsa_String);
873 if (r->out.name == NULL) {
874 return NT_STATUS_NO_MEMORY;
876 r->out.name->string = privname;
883 lsa_LookupPrivDisplayName
885 static NTSTATUS lsa_LookupPrivDisplayName(struct dcesrv_call_state *dce_call,
887 struct lsa_LookupPrivDisplayName *r)
889 struct dcesrv_handle *h;
890 struct lsa_policy_state *state;
893 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
897 id = sec_privilege_id(r->in.name->string);
899 return NT_STATUS_NO_SUCH_PRIVILEGE;
902 r->out.disp_name = talloc_p(mem_ctx, struct lsa_String);
903 if (r->out.disp_name == NULL) {
904 return NT_STATUS_NO_MEMORY;
907 r->out.disp_name->string = sec_privilege_display_name(id, r->in.language_id);
908 if (r->out.disp_name->string == NULL) {
909 return NT_STATUS_INTERNAL_ERROR;
919 static NTSTATUS lsa_DeleteObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
920 struct lsa_DeleteObject *r)
922 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
927 lsa_EnumAccountsWithUserRight
929 static NTSTATUS lsa_EnumAccountsWithUserRight(struct dcesrv_call_state *dce_call,
931 struct lsa_EnumAccountsWithUserRight *r)
933 struct dcesrv_handle *h;
934 struct lsa_policy_state *state;
936 struct ldb_message **res;
937 const char * const attrs[] = { "objectSid", NULL};
938 const char *privname;
940 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
944 if (r->in.name == NULL) {
945 return NT_STATUS_NO_SUCH_PRIVILEGE;
948 privname = r->in.name->string;
949 if (sec_privilege_id(privname) == -1) {
950 return NT_STATUS_NO_SUCH_PRIVILEGE;
953 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
954 "privilege=%s", privname);
956 return NT_STATUS_NO_SUCH_USER;
959 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_SidPtr, ret);
960 if (r->out.sids->sids == NULL) {
961 return NT_STATUS_NO_MEMORY;
963 for (i=0;i<ret;i++) {
965 sidstr = samdb_result_string(res[i], "objectSid", NULL);
966 if (sidstr == NULL) {
967 return NT_STATUS_NO_MEMORY;
969 r->out.sids->sids[i].sid = dom_sid_parse_talloc(r->out.sids->sids,
971 if (r->out.sids->sids[i].sid == NULL) {
972 return NT_STATUS_NO_MEMORY;
975 r->out.sids->num_sids = ret;
982 lsa_EnumAccountRights
984 static NTSTATUS lsa_EnumAccountRights(struct dcesrv_call_state *dce_call,
986 struct lsa_EnumAccountRights *r)
988 struct dcesrv_handle *h;
989 struct lsa_policy_state *state;
991 struct ldb_message **res;
992 const char * const attrs[] = { "privilege", NULL};
994 struct ldb_message_element *el;
996 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1000 sidstr = dom_sid_string(mem_ctx, r->in.sid);
1001 if (sidstr == NULL) {
1002 return NT_STATUS_NO_MEMORY;
1005 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs,
1006 "objectSid=%s", sidstr);
1008 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1011 el = ldb_msg_find_element(res[0], "privilege");
1012 if (el == NULL || el->num_values == 0) {
1013 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1016 r->out.rights->count = el->num_values;
1017 r->out.rights->names = talloc_array_p(r->out.rights,
1018 struct lsa_String, r->out.rights->count);
1019 if (r->out.rights->names == NULL) {
1020 return NT_STATUS_NO_MEMORY;
1023 for (i=0;i<el->num_values;i++) {
1024 r->out.rights->names[i].string = el->values[i].data;
1027 return NT_STATUS_OK;
1032 lsa_AddAccountRights
1034 static NTSTATUS lsa_AddAccountRights(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1035 struct lsa_AddAccountRights *r)
1037 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1042 lsa_RemoveAccountRights
1044 static NTSTATUS lsa_RemoveAccountRights(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1045 struct lsa_RemoveAccountRights *r)
1047 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1052 lsa_QueryTrustedDomainInfoBySid
1054 static NTSTATUS lsa_QueryTrustedDomainInfoBySid(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1055 struct lsa_QueryTrustedDomainInfoBySid *r)
1057 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1062 lsa_SetTrustDomainInfo
1064 static NTSTATUS lsa_SetTrustDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1065 struct lsa_SetTrustDomainInfo *r)
1067 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1072 lsa_DeleteTrustDomain
1074 static NTSTATUS lsa_DeleteTrustDomain(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1075 struct lsa_DeleteTrustDomain *r)
1077 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1082 lsa_StorePrivateData
1084 static NTSTATUS lsa_StorePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1085 struct lsa_StorePrivateData *r)
1087 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1092 lsa_RetrievePrivateData
1094 static NTSTATUS lsa_RetrievePrivateData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1095 struct lsa_RetrievePrivateData *r)
1097 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1104 static NTSTATUS lsa_GetUserName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1105 struct lsa_GetUserName *r)
1107 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1113 static NTSTATUS lsa_SetInfoPolicy2(struct dcesrv_call_state *dce_call,
1114 TALLOC_CTX *mem_ctx,
1115 struct lsa_SetInfoPolicy2 *r)
1117 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1121 lsa_QueryTrustedDomainInfoByName
1123 static NTSTATUS lsa_QueryTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1124 TALLOC_CTX *mem_ctx,
1125 struct lsa_QueryTrustedDomainInfoByName *r)
1127 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1131 lsa_SetTrustedDomainInfoByName
1133 static NTSTATUS lsa_SetTrustedDomainInfoByName(struct dcesrv_call_state *dce_call,
1134 TALLOC_CTX *mem_ctx,
1135 struct lsa_SetTrustedDomainInfoByName *r)
1137 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1141 lsa_EnumTrustedDomainsEx
1143 static NTSTATUS lsa_EnumTrustedDomainsEx(struct dcesrv_call_state *dce_call,
1144 TALLOC_CTX *mem_ctx,
1145 struct lsa_EnumTrustedDomainsEx *r)
1147 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1151 lsa_CreateTrustedDomainEx
1153 static NTSTATUS lsa_CreateTrustedDomainEx(struct dcesrv_call_state *dce_call,
1154 TALLOC_CTX *mem_ctx,
1155 struct lsa_CreateTrustedDomainEx *r)
1157 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1161 lsa_CloseTrustedDomainEx
1163 static NTSTATUS lsa_CloseTrustedDomainEx(struct dcesrv_call_state *dce_call,
1164 TALLOC_CTX *mem_ctx,
1165 struct lsa_CloseTrustedDomainEx *r)
1167 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1171 lsa_QueryDomainInformationPolicy
1173 static NTSTATUS lsa_QueryDomainInformationPolicy(struct dcesrv_call_state *dce_call,
1174 TALLOC_CTX *mem_ctx,
1175 struct lsa_QueryDomainInformationPolicy *r)
1177 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1181 lsa_SetDomInfoPolicy
1183 static NTSTATUS lsa_SetDomInfoPolicy(struct dcesrv_call_state *dce_call,
1184 TALLOC_CTX *mem_ctx,
1185 struct lsa_SetDomInfoPolicy *r)
1187 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1191 lsa_OpenTrustedDomainByName
1193 static NTSTATUS lsa_OpenTrustedDomainByName(struct dcesrv_call_state *dce_call,
1194 TALLOC_CTX *mem_ctx,
1195 struct lsa_OpenTrustedDomainByName *r)
1197 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1203 static NTSTATUS lsa_TestCall(struct dcesrv_call_state *dce_call,
1204 TALLOC_CTX *mem_ctx,
1205 struct lsa_TestCall *r)
1207 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1211 lookup a SID for 1 name
1213 static NTSTATUS lsa_lookup_name(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
1214 const char *name, struct dom_sid **sid, uint32_t *atype)
1217 struct ldb_message **res;
1218 const char * const attrs[] = { "objectSid", "sAMAccountType", NULL};
1220 ret = samdb_search(state->sam_ctx, mem_ctx, NULL, &res, attrs, "sAMAccountName=%s", name);
1222 const char *sid_str = ldb_msg_find_string(res[0], "objectSid", NULL);
1223 if (sid_str == NULL) {
1224 return NT_STATUS_INVALID_SID;
1227 *sid = dom_sid_parse_talloc(mem_ctx, sid_str);
1229 return NT_STATUS_INVALID_SID;
1232 *atype = samdb_result_uint(res[0], "sAMAccountType", 0);
1234 return NT_STATUS_OK;
1237 /* need to add a call into sidmap to check for a allocated sid */
1239 return NT_STATUS_INVALID_SID;
1245 static NTSTATUS lsa_LookupNames2(struct dcesrv_call_state *dce_call,
1246 TALLOC_CTX *mem_ctx,
1247 struct lsa_LookupNames2 *r)
1249 struct lsa_policy_state *state;
1250 struct dcesrv_handle *h;
1252 NTSTATUS status = NT_STATUS_OK;
1254 r->out.domains = NULL;
1256 DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
1260 r->out.domains = talloc_zero_p(mem_ctx, struct lsa_RefDomainList);
1261 if (r->out.domains == NULL) {
1262 return NT_STATUS_NO_MEMORY;
1265 r->out.sids = talloc_zero_p(mem_ctx, struct lsa_TransSidArray2);
1266 if (r->out.sids == NULL) {
1267 return NT_STATUS_NO_MEMORY;
1272 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid2,
1274 if (r->out.sids->sids == NULL) {
1275 return NT_STATUS_NO_MEMORY;
1278 for (i=0;i<r->in.num_names;i++) {
1279 const char *name = r->in.names[i].string;
1280 struct dom_sid *sid;
1281 uint32_t atype, rtype, sid_index;
1284 r->out.sids->count++;
1287 r->out.sids->sids[i].sid_type = SID_NAME_UNKNOWN;
1288 r->out.sids->sids[i].rid = 0xFFFFFFFF;
1289 r->out.sids->sids[i].sid_index = 0xFFFFFFFF;
1290 r->out.sids->sids[i].unknown = 0;
1292 status2 = lsa_lookup_name(state, mem_ctx, name, &sid, &atype);
1293 if (!NT_STATUS_IS_OK(status) || sid->num_auths == 0) {
1294 status = STATUS_SOME_UNMAPPED;
1298 rtype = samdb_atype_map(atype);
1299 if (rtype == SID_NAME_UNKNOWN) {
1300 status = STATUS_SOME_UNMAPPED;
1304 status2 = lsa_authority_list(state, mem_ctx, sid, r->out.domains, &sid_index);
1305 if (!NT_STATUS_IS_OK(status2)) {
1309 r->out.sids->sids[i].sid_type = rtype;
1310 r->out.sids->sids[i].rid = sid->sub_auths[sid->num_auths-1];
1311 r->out.sids->sids[i].sid_index = sid_index;
1312 r->out.sids->sids[i].unknown = 0;
1321 static NTSTATUS lsa_LookupNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1322 struct lsa_LookupNames *r)
1324 struct lsa_LookupNames2 r2;
1328 r2.in.handle = r->in.handle;
1329 r2.in.num_names = r->in.num_names;
1330 r2.in.names = r->in.names;
1332 r2.in.level = r->in.level;
1333 r2.in.count = r->in.count;
1336 r2.out.count = r->out.count;
1338 status = lsa_LookupNames2(dce_call, mem_ctx, &r2);
1339 if (dce_call->fault_code != 0) {
1343 r->out.domains = r2.out.domains;
1344 r->out.sids = talloc_p(mem_ctx, struct lsa_TransSidArray);
1345 if (r->out.sids == NULL) {
1346 return NT_STATUS_NO_MEMORY;
1348 r->out.sids->count = r2.out.sids->count;
1349 r->out.sids->sids = talloc_array_p(r->out.sids, struct lsa_TranslatedSid,
1350 r->out.sids->count);
1351 if (r->out.sids->sids == NULL) {
1352 return NT_STATUS_NO_MEMORY;
1354 for (i=0;i<r->out.sids->count;i++) {
1355 r->out.sids->sids[i].sid_type = r2.out.sids->sids[i].sid_type;
1356 r->out.sids->sids[i].rid = r2.out.sids->sids[i].rid;
1357 r->out.sids->sids[i].sid_index = r2.out.sids->sids[i].sid_index;
1366 lsa_CreateTrustedDomainEx2
1368 static NTSTATUS lsa_CreateTrustedDomainEx2(struct dcesrv_call_state *dce_call,
1369 TALLOC_CTX *mem_ctx,
1370 struct lsa_CreateTrustedDomainEx2 *r)
1372 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1375 /* include the generated boilerplate */
1376 #include "librpc/gen_ndr/ndr_lsa_s.c"