⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srv_lsa_nt.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	PRIVILEGE_SET *set = NULL;	struct current_user user;	/* find the connection policy handle. */	if (!find_policy_by_hnd(p, &q_u->pol, (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 */	   	get_current_user( &user, p );	if ( user.uid != sec_initial_uid() 		&& !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )	{		return NT_STATUS_ACCESS_DENIED;	}	set = &q_u->set;	if ( !privilege_set_to_se_priv( &mask, set ) )		return NT_STATUS_NO_SUCH_PRIVILEGE;	if ( !grant_privilege( &info->sid, &mask ) ) {		DEBUG(3,("_lsa_addprivs: grant_privilege(%s) failed!\n",			sid_string_static(&info->sid) ));		DEBUG(3,("Privilege mask:\n"));		dump_se_priv( DBGC_ALL, 3, &mask );		return NT_STATUS_NO_SUCH_PRIVILEGE;	}	return NT_STATUS_OK;}/*************************************************************************** For a given SID, remove some privileges. ***************************************************************************/NTSTATUS _lsa_removeprivs(pipes_struct *p, LSA_Q_REMOVEPRIVS *q_u, LSA_R_REMOVEPRIVS *r_u){	struct lsa_info *info = NULL;	SE_PRIV mask;	PRIVILEGE_SET *set = NULL;	struct current_user user;	/* find the connection policy handle. */	if (!find_policy_by_hnd(p, &q_u->pol, (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 */	   	get_current_user( &user, p );	if ( user.uid != sec_initial_uid()		&& !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) ) 	{		return NT_STATUS_ACCESS_DENIED;	}	set = &q_u->set;	if ( !privilege_set_to_se_priv( &mask, set ) )		return NT_STATUS_NO_SUCH_PRIVILEGE;	if ( !revoke_privilege( &info->sid, &mask ) ) {		DEBUG(3,("_lsa_removeprivs: revoke_privilege(%s) failed!\n",			sid_string_static(&info->sid) ));		DEBUG(3,("Privilege mask:\n"));		dump_se_priv( DBGC_ALL, 3, &mask );		return NT_STATUS_NO_SUCH_PRIVILEGE;	}	return NT_STATUS_OK;}/*************************************************************************** For a given SID, remove some privileges. ***************************************************************************/NTSTATUS _lsa_query_secobj(pipes_struct *p, LSA_Q_QUERY_SEC_OBJ *q_u, LSA_R_QUERY_SEC_OBJ *r_u){	struct lsa_info *handle=NULL;	SEC_DESC *psd = NULL;	size_t sd_size;	NTSTATUS status;	r_u->status = NT_STATUS_OK;	/* find the connection policy handle. */	if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))		return NT_STATUS_INVALID_HANDLE;	/* check if the user have enough rights */	if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))		return NT_STATUS_ACCESS_DENIED;	switch (q_u->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_u->buf = 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_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)			return NT_STATUS_NO_MEMORY;		break;	default:		return NT_STATUS_INVALID_LEVEL;	}	r_u->ptr=1;	return r_u->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 uuid 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 have enough rights */		if (!(handle->access & 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[0] = '\0';				get_mydnsdomname(dnsdomname);				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 *//*************************************************************************** ***************************************************************************/NTSTATUS _lsa_add_acct_rights(pipes_struct *p, LSA_Q_ADD_ACCT_RIGHTS *q_u, LSA_R_ADD_ACCT_RIGHTS *r_u){	struct lsa_info *info = NULL;	int i = 0;	DOM_SID sid;	fstring privname;	UNISTR4_ARRAY *uni_privnames = q_u->rights;	struct current_user user;		/* find the connection policy handle. */	if (!find_policy_by_hnd(p, &q_u->pol, (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 */	   	get_current_user( &user, p );	if ( user.uid != sec_initial_uid()		&& !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) ) 	{		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, &q_u->sid.sid );		/* just a little sanity check */		if ( q_u->count != uni_privnames->count ) {		DEBUG(0,("_lsa_add_acct_rights: count != number of UNISTR2 elements!\n"));		return NT_STATUS_INVALID_HANDLE;		}			for ( i=0; i<q_u->count; i++ ) {		UNISTR4 *uni4_str = &uni_privnames->strings[i];		/* only try to add non-null strings */		if ( !uni4_str->string )			continue;		rpcstr_pull( privname, uni4_str->string->buffer, sizeof(privname), -1, STR_TERMINATE );				if ( !grant_privilege_by_name( &sid, privname ) ) {			DEBUG(2,("_lsa_add_acct_rights: Failed to add privilege [%s]\n", privname ));			return NT_STATUS_NO_SUCH_PRIVILEGE;		}	}	return NT_STATUS_OK;}/*************************************************************************** ***************************************************************************/NTSTATUS _lsa_remove_acct_rights(pipes_struct *p, LSA_Q_REMOVE_ACCT_RIGHTS *q_u, LSA_R_REMOVE_ACCT_RIGHTS *r_u){	struct lsa_info *info = NULL;	int i = 0;	DOM_SID sid;	fstring privname;	UNISTR4_ARRAY *uni_privnames = q_u->rights;	struct current_user user;		/* find the connection policy handle. */	if (!find_policy_by_hnd(p, &q_u->pol, (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 */	   	get_current_user( &user, p );	if ( user.uid != sec_initial_uid()		&& !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )	{		return NT_STATUS_ACCESS_DENIED;	}	sid_copy( &sid, &q_u->sid.sid );	if ( q_u->removeall ) {		if ( !revoke_all_privileges( &sid ) ) 			return NT_STATUS_ACCESS_DENIED;			return NT_STATUS_OK;	}		/* just a little sanity check */		if ( q_u->count != uni_privnames->count ) {		DEBUG(0,("_lsa_add_acct_rights: count != number of UNISTR2 elements!\n"));		return NT_STATUS_INVALID_HANDLE;		}			for ( i=0; i<q_u->count; i++ ) {		UNISTR4 *uni4_str = &uni_privnames->strings[i];		/* only try to add non-null strings */		if ( !uni4_str->string )			continue;		rpcstr_pull( privname, uni4_str->string->buffer, sizeof(privname), -1, STR_TERMINATE );				if ( !revoke_privilege_by_name( &sid, privname ) ) {			DEBUG(2,("_lsa_remove_acct_rights: Failed to revoke privilege [%s]\n", privname ));			return NT_STATUS_NO_SUCH_PRIVILEGE;		}	}	return NT_STATUS_OK;}/*************************************************************************** ***************************************************************************/NTSTATUS _lsa_enum_acct_rights(pipes_struct *p, LSA_Q_ENUM_ACCT_RIGHTS *q_u, LSA_R_ENUM_ACCT_RIGHTS *r_u){	struct lsa_info *info = NULL;	DOM_SID sid;	PRIVILEGE_SET privileges;	SE_PRIV mask;		/* find the connection policy handle. */		if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))		return NT_STATUS_INVALID_HANDLE;			/* 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, &q_u->sid.sid );		if ( !get_privileges_for_sids( &mask, &sid, 1 ) )		return NT_STATUS_OBJECT_NAME_NOT_FOUND;	privilege_set_init( &privileges );	if ( se_priv_to_privilege_set( &privileges, &mask ) ) {		DEBUG(10,("_lsa_enum_acct_rights: %s has %d privileges\n", 			sid_string_static(&sid), privileges.count));		r_u->status = init_r_enum_acct_rights( r_u, &privileges );	}	else 		r_u->status = NT_STATUS_NO_SUCH_PRIVILEGE;	privilege_set_free( &privileges );	return r_u->status;}/*************************************************************************** ***************************************************************************/NTSTATUS _lsa_lookup_priv_value(pipes_struct *p, LSA_Q_LOOKUP_PRIV_VALUE *q_u, LSA_R_LOOKUP_PRIV_VALUE *r_u){	struct lsa_info *info = NULL;	fstring name;	LUID_ATTR priv_luid;	SE_PRIV mask;		/* find the connection policy handle. */		if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))		return NT_STATUS_INVALID_HANDLE;			unistr2_to_ascii(name, &q_u->privname.unistring, sizeof(name));		DEBUG(10,("_lsa_lookup_priv_value: name = %s\n", name));	if ( !se_priv_from_name( name, &mask ) )		return NT_STATUS_NO_SUCH_PRIVILEGE;	priv_luid = get_privilege_luid( &mask );	r_u->luid.low  = priv_luid.luid.low;	r_u->luid.high = priv_luid.luid.high;			return NT_STATUS_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -