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

📄 mapping.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		mapt= SMB_REALLOC_ARRAY((*pp_rmap), GROUP_MAP, entries+1);		if (!mapt) {			DEBUG(0,("enum_group_mapping: Unable to enlarge group map!\n"));			SAFE_FREE(*pp_rmap);			return False;		}		else			(*pp_rmap) = mapt;		mapt[entries].gid = map.gid;		sid_copy( &mapt[entries].sid, &map.sid);		mapt[entries].sid_name_use = map.sid_name_use;		fstrcpy(mapt[entries].nt_name, map.nt_name);		fstrcpy(mapt[entries].comment, map.comment);		entries++;	}	*p_num_entries=entries;	return True;}/* This operation happens on session setup, so it should better be fast. We * store a list of aliases a SID is member of hanging off MEMBEROF/SID. */static NTSTATUS one_alias_membership(const DOM_SID *member,				     DOM_SID **sids, size_t *num){	fstring key, string_sid;	TDB_DATA kbuf, dbuf;	const char *p;	if (!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return NT_STATUS_ACCESS_DENIED;	}	sid_to_string(string_sid, member);	slprintf(key, sizeof(key), "%s%s", MEMBEROF_PREFIX, string_sid);	kbuf.dsize = strlen(key)+1;	kbuf.dptr = key;	dbuf = tdb_fetch(tdb, kbuf);	if (dbuf.dptr == NULL) {		return NT_STATUS_OK;	}	p = dbuf.dptr;	while (next_token(&p, string_sid, " ", sizeof(string_sid))) {		DOM_SID alias;		if (!string_to_sid(&alias, string_sid))			continue;		add_sid_to_array_unique(NULL, &alias, sids, num);		if (sids == NULL)			return NT_STATUS_NO_MEMORY;	}	SAFE_FREE(dbuf.dptr);	return NT_STATUS_OK;}static NTSTATUS alias_memberships(const DOM_SID *members, size_t num_members,				  DOM_SID **sids, size_t *num){	size_t i;	*num = 0;	*sids = NULL;	for (i=0; i<num_members; i++) {		NTSTATUS status = one_alias_membership(&members[i], sids, num);		if (!NT_STATUS_IS_OK(status))			return status;	}	return NT_STATUS_OK;}static BOOL is_aliasmem(const DOM_SID *alias, const DOM_SID *member){	DOM_SID *sids;	size_t i, num;	/* This feels the wrong way round, but the on-disk data structure	 * dictates it this way. */	if (!NT_STATUS_IS_OK(alias_memberships(member, 1, &sids, &num)))		return False;	for (i=0; i<num; i++) {		if (sid_compare(alias, &sids[i]) == 0) {			SAFE_FREE(sids);			return True;		}	}	SAFE_FREE(sids);	return False;}static NTSTATUS add_aliasmem(const DOM_SID *alias, const DOM_SID *member){	GROUP_MAP map;	TDB_DATA kbuf, dbuf;	pstring key;	fstring string_sid;	char *new_memberstring;	int result;	if(!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return NT_STATUS_ACCESS_DENIED;	}	if (!get_group_map_from_sid(*alias, &map))		return NT_STATUS_NO_SUCH_ALIAS;	if ( (map.sid_name_use != SID_NAME_ALIAS) &&	     (map.sid_name_use != SID_NAME_WKN_GRP) )		return NT_STATUS_NO_SUCH_ALIAS;	if (is_aliasmem(alias, member))		return NT_STATUS_MEMBER_IN_ALIAS;	sid_to_string(string_sid, member);	slprintf(key, sizeof(key), "%s%s", MEMBEROF_PREFIX, string_sid);	kbuf.dsize = strlen(key)+1;	kbuf.dptr = key;	dbuf = tdb_fetch(tdb, kbuf);	sid_to_string(string_sid, alias);	if (dbuf.dptr != NULL) {		asprintf(&new_memberstring, "%s %s", (char *)(dbuf.dptr),			 string_sid);	} else {		new_memberstring = SMB_STRDUP(string_sid);	}	if (new_memberstring == NULL)		return NT_STATUS_NO_MEMORY;	SAFE_FREE(dbuf.dptr);	dbuf.dsize = strlen(new_memberstring)+1;	dbuf.dptr = new_memberstring;	result = tdb_store(tdb, kbuf, dbuf, 0);	SAFE_FREE(new_memberstring);	return (result == 0 ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED);}struct aliasmem_closure {	const DOM_SID *alias;	DOM_SID **sids;	size_t *num;};static int collect_aliasmem(TDB_CONTEXT *tdb_ctx, TDB_DATA key, TDB_DATA data,			    void *state){	struct aliasmem_closure *closure = (struct aliasmem_closure *)state;	const char *p;	fstring alias_string;	if (strncmp(key.dptr, MEMBEROF_PREFIX,		    strlen(MEMBEROF_PREFIX)) != 0)		return 0;	p = data.dptr;	while (next_token(&p, alias_string, " ", sizeof(alias_string))) {		DOM_SID alias, member;		const char *member_string;				if (!string_to_sid(&alias, alias_string))			continue;		if (sid_compare(closure->alias, &alias) != 0)			continue;		/* Ok, we found the alias we're looking for in the membership		 * list currently scanned. The key represents the alias		 * member. Add that. */		member_string = strchr(key.dptr, '/');		/* Above we tested for MEMBEROF_PREFIX which includes the		 * slash. */		SMB_ASSERT(member_string != NULL);		member_string += 1;		if (!string_to_sid(&member, member_string))			continue;				add_sid_to_array(NULL, &member, closure->sids, closure->num);	}	return 0;}static NTSTATUS enum_aliasmem(const DOM_SID *alias, DOM_SID **sids, size_t *num){	GROUP_MAP map;	struct aliasmem_closure closure;	if(!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return NT_STATUS_ACCESS_DENIED;	}	if (!get_group_map_from_sid(*alias, &map))		return NT_STATUS_NO_SUCH_ALIAS;	if ( (map.sid_name_use != SID_NAME_ALIAS) &&	     (map.sid_name_use != SID_NAME_WKN_GRP) )		return NT_STATUS_NO_SUCH_ALIAS;	*sids = NULL;	*num = 0;	closure.alias = alias;	closure.sids = sids;	closure.num = num;	tdb_traverse(tdb, collect_aliasmem, &closure);	return NT_STATUS_OK;}static NTSTATUS del_aliasmem(const DOM_SID *alias, const DOM_SID *member){	NTSTATUS result;	DOM_SID *sids;	size_t i, num;	BOOL found = False;	char *member_string;	TDB_DATA kbuf, dbuf;	pstring key;	fstring sid_string;	result = alias_memberships(member, 1, &sids, &num);	if (!NT_STATUS_IS_OK(result))		return result;	for (i=0; i<num; i++) {		if (sid_compare(&sids[i], alias) == 0) {			found = True;			break;		}	}	if (!found) {		SAFE_FREE(sids);		return NT_STATUS_MEMBER_NOT_IN_ALIAS;	}	if (i < num)		sids[i] = sids[num-1];	num -= 1;	sid_to_string(sid_string, member);	slprintf(key, sizeof(key), "%s%s", MEMBEROF_PREFIX, sid_string);	kbuf.dsize = strlen(key)+1;	kbuf.dptr = key;	if (num == 0)		return tdb_delete(tdb, kbuf) == 0 ?			NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;	member_string = SMB_STRDUP("");	if (member_string == NULL) {		SAFE_FREE(sids);		return NT_STATUS_NO_MEMORY;	}	for (i=0; i<num; i++) {		char *s = member_string;		sid_to_string(sid_string, &sids[i]);		asprintf(&member_string, "%s %s", s, sid_string);		SAFE_FREE(s);		if (member_string == NULL) {			SAFE_FREE(sids);			return NT_STATUS_NO_MEMORY;		}	}	dbuf.dsize = strlen(member_string)+1;	dbuf.dptr = member_string;	result = tdb_store(tdb, kbuf, dbuf, 0) == 0 ?		NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;	SAFE_FREE(sids);	SAFE_FREE(member_string);	return result;}/* * * High level functions * better to use them than the lower ones. * * we are checking if the group is in the mapping file * and if the group is an existing unix group * *//* get a domain group from it's SID */BOOL get_domain_group_from_sid(DOM_SID sid, GROUP_MAP *map){	struct group *grp;	BOOL ret;		if(!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return(False);	}	DEBUG(10, ("get_domain_group_from_sid\n"));	/* if the group is NOT in the database, it CAN NOT be a domain group */		become_root();	ret = pdb_getgrsid(map, sid);	unbecome_root();		if ( !ret ) 		return False;	DEBUG(10, ("get_domain_group_from_sid: SID found in the TDB\n"));	/* if it's not a domain group, continue */	if (map->sid_name_use!=SID_NAME_DOM_GRP) {		return False;	}	DEBUG(10, ("get_domain_group_from_sid: SID is a domain group\n")); 		if (map->gid==-1) {		return False;	}	DEBUG(10, ("get_domain_group_from_sid: SID is mapped to gid:%lu\n",(unsigned long)map->gid));		grp = getgrgid(map->gid);	if ( !grp ) {		DEBUG(10, ("get_domain_group_from_sid: gid DOESN'T exist in UNIX security\n"));		return False;	}	DEBUG(10, ("get_domain_group_from_sid: gid exists in UNIX security\n"));	return True;}/* get a local (alias) group from it's SID */BOOL get_local_group_from_sid(DOM_SID *sid, GROUP_MAP *map){	BOOL ret;		if(!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return(False);	}	/* The group is in the mapping table */	become_root();	ret = pdb_getgrsid(map, *sid);	unbecome_root();		if ( !ret )		return False;			if ( ( (map->sid_name_use != SID_NAME_ALIAS) &&	       (map->sid_name_use != SID_NAME_WKN_GRP) )		|| (map->gid == -1)		|| (getgrgid(map->gid) == NULL) ) 	{		return False;	} 					#if 1 	/* JERRY */	/* local groups only exist in the group mapping DB so this 	   is not necessary */	   	else {		/* the group isn't in the mapping table.		 * make one based on the unix information */		uint32 alias_rid;		struct group *grp;		sid_peek_rid(sid, &alias_rid);		map->gid=pdb_group_rid_to_gid(alias_rid);				grp = getgrgid(map->gid);		if ( !grp ) {			DEBUG(3,("get_local_group_from_sid: No unix group for [%ul]\n", map->gid));			return False;		}		map->sid_name_use=SID_NAME_ALIAS;		fstrcpy(map->nt_name, grp->gr_name);		fstrcpy(map->comment, "Local Unix Group");		sid_copy(&map->sid, sid);	}#endif	return True;}/* get a builtin group from it's SID */BOOL get_builtin_group_from_sid(DOM_SID *sid, GROUP_MAP *map){	BOOL ret;		if(!init_group_mapping()) {		DEBUG(0,("failed to initialize group mapping\n"));		return(False);	}	become_root();	ret = pdb_getgrsid(map, *sid);	unbecome_root();		if ( !ret )		return False;	if (map->sid_name_use!=SID_NAME_WKN_GRP) {		return False;	}	if (map->gid==-1) {		return False;	}

⌨️ 快捷键说明

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