extern PRIVS privs[];
+enum lsa_handle_type { LSA_HANDLE_POLICY_TYPE = 1, LSA_HANDLE_ACCOUNT_TYPE };
+
struct lsa_info {
DOM_SID sid;
uint32 access;
+ enum lsa_handle_type type;
+};
+
+const struct generic_mapping lsa_account_mapping = {
+ LSA_ACCOUNT_READ,
+ LSA_ACCOUNT_WRITE,
+ LSA_ACCOUNT_EXECUTE,
+ LSA_ACCOUNT_ALL_ACCESS
};
-const struct generic_mapping lsa_generic_mapping = {
+const struct generic_mapping lsa_policy_mapping = {
LSA_POLICY_READ,
LSA_POLICY_WRITE,
LSA_POLICY_EXECUTE,
return NT_STATUS_OK;
}
-static NTSTATUS lsa_get_generic_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size)
+static NTSTATUS make_lsa_object_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size,
+ const struct generic_mapping *map,
+ DOM_SID *sid, uint32_t sid_access)
{
- DOM_SID local_adm_sid;
DOM_SID adm_sid;
-
- SEC_ACE ace[3];
+ SEC_ACE ace[5];
+ size_t i = 0;
SEC_ACL *psa = NULL;
- init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
- LSA_POLICY_READ|LSA_POLICY_EXECUTE, 0);
+ /* READ|EXECUTE access for Everyone */
+
+ init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ map->generic_execute | map->generic_read, 0);
+
+ /* Add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
+
+ init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
+ SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
+ init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators,
+ SEC_ACE_TYPE_ACCESS_ALLOWED, map->generic_all, 0);
+ /* Add Full Access for Domain Admins */
sid_copy(&adm_sid, get_global_sam_sid());
sid_append_rid(&adm_sid, DOMAIN_GROUP_RID_ADMINS);
- init_sec_ace(&ace[1], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, LSA_POLICY_ALL_ACCESS, 0);
+ init_sec_ace(&ace[i++], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ map->generic_all, 0);
- sid_copy(&local_adm_sid, &global_sid_Builtin);
- sid_append_rid(&local_adm_sid, BUILTIN_ALIAS_RID_ADMINS);
- init_sec_ace(&ace[2], &local_adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, LSA_POLICY_ALL_ACCESS, 0);
+ /* If we have a sid, give it some special access */
- if((psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, 3, ace)) == NULL)
+ if (sid) {
+ init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ sid_access, 0);
+ }
+
+ if((psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, i, ace)) == NULL)
return NT_STATUS_NO_MEMORY;
if((*sd = make_sec_desc(mem_ctx, SECURITY_DESCRIPTOR_REVISION_1,
return NT_STATUS_OK;
}
-#if 0 /* AD DC work in ongoing in Samba 4 */
-
-/***************************************************************************
- Init_dns_dom_info.
-***************************************************************************/
-
-static void init_dns_dom_info(LSA_DNS_DOM_INFO *r_l, const char *nb_name,
- const char *dns_name, const char *forest_name,
- struct GUID *dom_guid, DOM_SID *dom_sid)
-{
- if (nb_name && *nb_name) {
- init_unistr2(&r_l->uni_nb_dom_name, nb_name, UNI_FLAGS_NONE);
- init_uni_hdr(&r_l->hdr_nb_dom_name, &r_l->uni_nb_dom_name);
- r_l->hdr_nb_dom_name.uni_max_len += 2;
- r_l->uni_nb_dom_name.uni_max_len += 1;
- }
-
- if (dns_name && *dns_name) {
- init_unistr2(&r_l->uni_dns_dom_name, dns_name, UNI_FLAGS_NONE);
- init_uni_hdr(&r_l->hdr_dns_dom_name, &r_l->uni_dns_dom_name);
- r_l->hdr_dns_dom_name.uni_max_len += 2;
- r_l->uni_dns_dom_name.uni_max_len += 1;
- }
-
- if (forest_name && *forest_name) {
- init_unistr2(&r_l->uni_forest_name, forest_name, UNI_FLAGS_NONE);
- init_uni_hdr(&r_l->hdr_forest_name, &r_l->uni_forest_name);
- r_l->hdr_forest_name.uni_max_len += 2;
- r_l->uni_forest_name.uni_max_len += 1;
- }
-
- /* how do we init the guid ? probably should write an init fn */
- if (dom_guid) {
- memcpy(&r_l->dom_guid, dom_guid, sizeof(struct GUID));
- }
-
- if (dom_sid) {
- r_l->ptr_dom_sid = 1;
- init_dom_sid2(&r_l->dom_sid, dom_sid);
- }
-}
-#endif /* AD DC work in ongoing in Samba 4 */
-
/***************************************************************************
_lsa_OpenPolicy2
map_max_allowed_access(p->server_info->ptok, &des_access);
/* map the generic bits to the lsa policy ones */
- se_map_generic(&des_access, &lsa_generic_mapping);
+ se_map_generic(&des_access, &lsa_policy_mapping);
/* get the generic lsa policy SD until we store it */
- lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size, &lsa_policy_mapping,
+ NULL, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
status = access_check_object(psd, p->server_info->ptok,
NULL, 0, des_access,
sid_copy(&info->sid,get_global_sam_sid());
info->access = acc_granted;
+ info->type = LSA_HANDLE_POLICY_TYPE;
/* set up the LSA QUERY INFO response */
if (!create_policy_hnd(p, r->out.handle, info))
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
+ if (info->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
if (!(info->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
return NT_STATUS_ACCESS_DENIED;
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
info = TALLOC_ZERO_P(p->mem_ctx, union lsa_PolicyInformation);
if (!info) {
return NT_STATUS_NO_MEMORY;
return NT_STATUS_INVALID_HANDLE;
}
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
if (!(handle->access & LSA_POLICY_LOOKUP_NAMES)) {
return NT_STATUS_ACCESS_DENIED;
return NT_STATUS_INVALID_HANDLE;
}
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
if (!(handle->access & LSA_POLICY_LOOKUP_NAMES)) {
return NT_STATUS_ACCESS_DENIED;
goto done;
}
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
if (!(handle->access & LSA_POLICY_LOOKUP_NAMES)) {
status = NT_STATUS_ACCESS_DENIED;
goto done;
}
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
if (!(handle->access & LSA_POLICY_LOOKUP_NAMES)) {
status = NT_STATUS_ACCESS_DENIED;
return NT_STATUS_INVALID_HANDLE;
}
- /* check to see if the pipe_user is root or a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
-
- if (p->server_info->utok.uid != sec_initial_uid() &&
- !nt_token_check_domain_rid(p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS)) {
+ if (!(info->access & STD_RIGHT_DELETE_ACCESS)) {
return NT_STATUS_ACCESS_DENIED;
}
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights
I don't know if it's the right one. not documented. */
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
/*
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
if (!(handle->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
return NT_STATUS_ACCESS_DENIED;
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
/* check if the user has enough rights */
/*
* I don't know if it's the right one. not documented.
* but guessed with rpcclient.
*/
- if (!(handle->access & LSA_POLICY_GET_PRIVATE_INFORMATION))
- return NT_STATUS_ACCESS_DENIED;
-
- /* check to see if the pipe_user is a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
-
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
+ if (!(handle->access & LSA_POLICY_CREATE_ACCOUNT))
return NT_STATUS_ACCESS_DENIED;
if ( is_privileged_sid( r->in.sid ) )
info->sid = *r->in.sid;
info->access = r->in.access_mask;
+ info->type = LSA_HANDLE_ACCOUNT_TYPE;
/* get a (unique) handle. open a policy on it. */
if (!create_policy_hnd(p, r->out.acct_handle, info))
{
struct lsa_info *handle;
struct lsa_info *info;
+ SEC_DESC *psd = NULL;
+ size_t sd_size;
+ uint32_t des_access = r->in.access_mask;
+ uint32_t acc_granted;
+ NTSTATUS status;
/* find the connection policy handle. */
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
- /* check if the user has enough rights */
+ if (handle->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
- /*
- * I don't know if it's the right one. not documented.
- * but guessed with rpcclient.
- */
- if (!(handle->access & LSA_POLICY_GET_PRIVATE_INFORMATION))
- return NT_STATUS_ACCESS_DENIED;
+ /* des_access is for the account here, not the policy
+ * handle - so don't check against policy handle. */
+
+ /* Work out max allowed. */
+ map_max_allowed_access(p->server_info->ptok, &des_access);
+
+ /* map the generic bits to the lsa account ones */
+ se_map_generic(&des_access, &lsa_account_mapping);
+
+ /* get the generic lsa account SD until we store it */
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size,
+ &lsa_account_mapping,
+ r->in.sid, LSA_ACCOUNT_ALL_ACCESS);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ status = access_check_object(psd, p->server_info->ptok,
+ NULL, 0, des_access,
+ &acc_granted, "_lsa_OpenAccount" );
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
/* TODO: Fis the parsing routine before reenabling this check! */
#if 0
}
info->sid = *r->in.sid;
- info->access = r->in.access_mask;
+ info->access = acc_granted;
+ info->type = LSA_HANDLE_ACCOUNT_TYPE;
/* get a (unique) handle. open a policy on it. */
if (!create_policy_hnd(p, r->out.acct_handle, info))
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- if (!(info->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
+ if (info->type != LSA_HANDLE_ACCOUNT_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
+ if (!(info->access & LSA_ACCOUNT_VIEW))
return NT_STATUS_ACCESS_DENIED;
- if ( !get_privileges_for_sids( &mask, &info->sid, 1 ) )
- return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ get_privileges_for_sids(&mask, &info->sid, 1);
privilege_set_init( &privileges );
+ priv_set = TALLOC_ZERO_P(p->mem_ctx, struct lsa_PrivilegeSet);
+ if (!priv_set) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
DEBUG(10,("_lsa_EnumPrivsAccount: %s has %d privileges\n",
sid_string_dbg(&info->sid),
privileges.count));
- priv_set = TALLOC_ZERO_P(p->mem_ctx, struct lsa_PrivilegeSet);
- if (!priv_set) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
luid_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx,
struct lsa_LUIDAttribute,
privileges.count);
priv_set->unknown = 0;
priv_set->set = luid_attrs;
- *r->out.privs = priv_set;
} else {
- status = NT_STATUS_NO_SUCH_PRIVILEGE;
+ priv_set->count = 0;
+ priv_set->unknown = 0;
+ priv_set->set = NULL;
}
+ *r->out.privs = priv_set;
+
done:
privilege_set_free( &privileges );
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- if (!(info->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
+ if (info->type != LSA_HANDLE_ACCOUNT_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
+ if (!(info->access & LSA_ACCOUNT_VIEW))
return NT_STATUS_ACCESS_DENIED;
privset = talloc_zero(p->mem_ctx, struct lsa_PrivilegeSet);
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- /* check to see if the pipe_user is a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
+ if (info->type != LSA_HANDLE_ACCOUNT_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
+ if (!(info->access & LSA_ACCOUNT_ADJUST_SYSTEM_ACCESS)) {
return NT_STATUS_ACCESS_DENIED;
+ }
if (!pdb_getgrsid(&map, info->sid))
return NT_STATUS_NO_SUCH_GROUP;
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- /* check to see if the pipe_user is root or a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
+ if (info->type != LSA_HANDLE_ACCOUNT_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
- {
+ if (!(info->access & LSA_ACCOUNT_ADJUST_PRIVILEGES)) {
return NT_STATUS_ACCESS_DENIED;
}
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- /* check to see if the pipe_user is root or a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
+ if (info->type != LSA_HANDLE_ACCOUNT_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
- {
+ if (!(info->access & LSA_ACCOUNT_ADJUST_PRIVILEGES)) {
return NT_STATUS_ACCESS_DENIED;
}
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
return NT_STATUS_INVALID_HANDLE;
- /* check if the user has enough rights */
- if (!(handle->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
- return NT_STATUS_ACCESS_DENIED;
+ if (handle->type == LSA_HANDLE_POLICY_TYPE) {
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size,
+ &lsa_policy_mapping, NULL, 0);
+ } else if (handle->type == LSA_HANDLE_ACCOUNT_TYPE) {
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size,
+ &lsa_account_mapping,
+ &handle->sid, LSA_ACCOUNT_ALL_ACCESS);
+ } else {
+ status = NT_STATUS_INVALID_HANDLE;
+ }
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
switch (r->in.sec_info) {
case 1:
/* SD contains only the owner */
-
- status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
- if(!NT_STATUS_IS_OK(status))
- return NT_STATUS_NO_MEMORY;
-
-
if((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
return NT_STATUS_NO_MEMORY;
break;
case 4:
/* SD contains only the ACL */
-
- status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
- if(!NT_STATUS_IS_OK(status))
- return NT_STATUS_NO_MEMORY;
-
if((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
return NT_STATUS_NO_MEMORY;
break;
return status;
}
-#if 0 /* AD DC work in ongoing in Samba 4 */
-
-/***************************************************************************
- ***************************************************************************/
-
- NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_INFO2 *r_u)
-{
- struct lsa_info *handle;
- const char *nb_name;
- char *dns_name = NULL;
- char *forest_name = NULL;
- DOM_SID *sid = NULL;
- struct GUID guid;
- fstring dnsdomname;
-
- ZERO_STRUCT(guid);
- r_u->status = NT_STATUS_OK;
-
- if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
- return NT_STATUS_INVALID_HANDLE;
-
- switch (q_u->info_class) {
- case 0x0c:
- /* check if the user has enough rights */
- if (!(handle->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
- return NT_STATUS_ACCESS_DENIED;
-
- /* Request PolicyPrimaryDomainInformation. */
- switch (lp_server_role()) {
- case ROLE_DOMAIN_PDC:
- case ROLE_DOMAIN_BDC:
- nb_name = get_global_sam_name();
- /* ugly temp hack for these next two */
-
- /* This should be a 'netbios domain -> DNS domain' mapping */
- dnsdomname = get_mydnsdomname(p->mem_ctx);
- if (!dnsdomname || !*dnsdomname) {
- return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
- }
- strlower_m(dnsdomname);
-
- dns_name = dnsdomname;
- forest_name = dnsdomname;
-
- sid = get_global_sam_sid();
- secrets_fetch_domain_guid(lp_workgroup(), &guid);
- break;
- default:
- return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
- }
- init_dns_dom_info(&r_u->info.dns_dom_info, nb_name, dns_name,
- forest_name,&guid,sid);
- break;
- default:
- DEBUG(0,("_lsa_query_info2: unknown info level in Lsa Query: %d\n", q_u->info_class));
- r_u->status = NT_STATUS_INVALID_INFO_CLASS;
- break;
- }
-
- if (NT_STATUS_IS_OK(r_u->status)) {
- r_u->ptr = 0x1;
- r_u->info_class = q_u->info_class;
- }
-
- return r_u->status;
-}
-#endif /* AD DC work in ongoing in Samba 4 */
-
/***************************************************************************
_lsa_AddAccountRights
***************************************************************************/
{
struct lsa_info *info = NULL;
int i = 0;
+ uint32_t acc_granted = 0;
+ SEC_DESC *psd = NULL;
+ size_t sd_size;
DOM_SID sid;
+ NTSTATUS status;
/* find the connection policy handle. */
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- /* check to see if the pipe_user is a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
-
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
- {
- return NT_STATUS_ACCESS_DENIED;
+ if (info->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
}
+ /* get the generic lsa account SD for this SID until we store it */
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size,
+ &lsa_account_mapping,
+ r->in.sid, LSA_ACCOUNT_ALL_ACCESS);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ /*
+ * From the MS DOCs. If the sid doesn't exist, ask for LSA_POLICY_CREATE_ACCOUNT
+ * on the policy handle. If it does, ask for
+ * LSA_ACCOUNT_ADJUST_PRIVILEGES|LSA_ACCOUNT_ADJUST_SYSTEM_ACCESS|LSA_ACCOUNT_VIEW,
+ * on the account sid. We don't check here so just use the latter. JRA.
+ */
+
+ status = access_check_object(psd, p->server_info->ptok,
+ NULL, 0, LSA_ACCOUNT_ADJUST_PRIVILEGES|LSA_ACCOUNT_ADJUST_SYSTEM_ACCESS|LSA_ACCOUNT_VIEW,
+ &acc_granted, "_lsa_AddAccountRights" );
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
/* according to an NT4 PDC, you can add privileges to SIDs even without
call_lsa_create_account() first. And you can use any arbitrary SID. */
{
struct lsa_info *info = NULL;
int i = 0;
+ SEC_DESC *psd = NULL;
+ size_t sd_size;
DOM_SID sid;
const char *privname = NULL;
+ uint32_t acc_granted = 0;
+ NTSTATUS status;
/* find the connection policy handle. */
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- /* check to see if the pipe_user is a Domain Admin since
- account_pol.tdb was already opened as root, this is all we have */
-
- if ( p->server_info->utok.uid != sec_initial_uid()
- && !nt_token_check_domain_rid( p->server_info->ptok,
- DOMAIN_GROUP_RID_ADMINS ) )
- {
- return NT_STATUS_ACCESS_DENIED;
+ if (info->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
}
+ /* get the generic lsa account SD for this SID until we store it */
+ status = make_lsa_object_sd(p->mem_ctx, &psd, &sd_size,
+ &lsa_account_mapping,
+ r->in.sid, LSA_ACCOUNT_ALL_ACCESS);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ /*
+ * From the MS DOCs. We need
+ * LSA_ACCOUNT_ADJUST_PRIVILEGES|LSA_ACCOUNT_ADJUST_SYSTEM_ACCESS|LSA_ACCOUNT_VIEW
+ * and DELETE on the account sid.
+ */
+
+ status = access_check_object(psd, p->server_info->ptok,
+ NULL, 0, LSA_ACCOUNT_ADJUST_PRIVILEGES|LSA_ACCOUNT_ADJUST_SYSTEM_ACCESS|
+ LSA_ACCOUNT_VIEW|STD_RIGHT_DELETE_ACCESS,
+ &acc_granted, "_lsa_AddAccountRights" );
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
sid_copy( &sid, r->in.sid );
if ( r->in.remove_all ) {
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- if (!(info->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
+ if (info->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
+ if (!(info->access & LSA_ACCOUNT_VIEW)) {
return NT_STATUS_ACCESS_DENIED;
+ }
/* according to an NT4 PDC, you can add privileges to SIDs even without
call_lsa_create_account() first. And you can use any arbitrary SID. */
sid_copy( &sid, r->in.sid );
- if ( !get_privileges_for_sids( &mask, &sid, 1 ) )
+ /* according to MS-LSAD 3.1.4.5.10 it is required to return
+ * NT_STATUS_OBJECT_NAME_NOT_FOUND if the account sid was not found in
+ * the lsa database */
+
+ if (!get_privileges_for_sids(&mask, &sid, 1)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
- privilege_set_init( &privileges );
+ status = privilege_set_init(&privileges);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
+ se_priv_to_privilege_set(&privileges, &mask);
- DEBUG(10,("_lsa_EnumAccountRights: %s has %d privileges\n",
- sid_string_dbg(&sid), privileges.count));
+ DEBUG(10,("_lsa_EnumAccountRights: %s has %d privileges\n",
+ sid_string_dbg(&sid), privileges.count));
- status = init_lsa_right_set(p->mem_ctx, r->out.rights, &privileges);
- } else {
- status = NT_STATUS_NO_SUCH_PRIVILEGE;
- }
+ status = init_lsa_right_set(p->mem_ctx, r->out.rights, &privileges);
privilege_set_free( &privileges );
if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
return NT_STATUS_INVALID_HANDLE;
- if (!(info->access & LSA_POLICY_VIEW_LOCAL_INFORMATION))
+ if (info->type != LSA_HANDLE_POLICY_TYPE) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
+
+ if (!(info->access & LSA_POLICY_LOOKUP_NAMES))
return NT_STATUS_ACCESS_DENIED;
name = r->in.name->string;