/*
  Return the sid and the type of the unix group.
*/
static bool get_group_map_from_ntname(const char *name, GROUP_MAP *map)
{
	int ret;
	char *expr;
	struct ldb_result *res=NULL;

	expr = talloc_asprintf(ldb, "(&(ntName=%s)(objectClass=groupMap))", name);
	if (expr == NULL) goto failed;

	ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res);
	if (ret != LDB_SUCCESS) {
		goto failed;
	}
	talloc_steal(expr, res);
	if (res->count != 1) {
		goto failed;
	}
	
	if (!msg_to_group_map(res->msgs[0], map)) goto failed;

	talloc_free(expr);
	return True;

failed:
	talloc_free(expr);
	return False;
}
/*
 return a group map entry for a given sid
*/
static bool get_group_map_from_sid(DOM_SID sid, GROUP_MAP *map)
{
	int ret;
	struct ldb_dn *dn;
	struct ldb_result *res=NULL;
	
	dn = mapping_dn(ldb, &sid);
	if (dn == NULL) goto failed;

	ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res);
	if (ret != LDB_SUCCESS) {
		goto failed;
	}
	talloc_steal(dn, res);
	if (res->count != 1) {
		goto failed;
	}

	if (!msg_to_group_map(res->msgs[0], map)) goto failed;

	talloc_free(dn);
	return True;

failed:
	talloc_free(dn);
	return False;
}
Exemple #3
0
/*
 return a group map entry for a given sid
*/
static bool get_group_map_from_sid(DOM_SID sid, GROUP_MAP *map)
{
	int ret;
	struct ldb_dn *dn;
	struct ldb_result *res=NULL;
	bool result = false;

	dn = mapping_dn(talloc_tos(), &sid);
	if (dn == NULL) {
		goto failed;
	}

	ret = ldb_search(ldb, dn, &res, dn, LDB_SCOPE_BASE, NULL, NULL);
	if (ret != LDB_SUCCESS || res->count != 1) {
		goto failed;
	}

	if (!msg_to_group_map(res->msgs[0], map)) {
		goto failed;
	}

	result = true;
 failed:
	talloc_free(dn);
	return result;
}
Exemple #4
0
/*
  Enumerate the group mappings for a domain
*/
static bool enum_group_mapping(const DOM_SID *domsid, enum lsa_SidType sid_name_use, 
			       GROUP_MAP **pp_rmap,
			       size_t *p_num_entries, bool unix_only)
{
	int i, ret;
	char *expr;
	fstring name;
	struct ldb_result *res = NULL;
	struct ldb_dn *basedn=NULL;
	TALLOC_CTX *tmp_ctx;

	tmp_ctx = talloc_new(ldb);
	if (tmp_ctx == NULL) goto failed;

	if (sid_name_use == SID_NAME_UNKNOWN) {
		expr = talloc_asprintf(tmp_ctx, "(&(objectClass=groupMap))");
	} else {
		expr = talloc_asprintf(tmp_ctx, "(&(sidNameUse=%u)(objectClass=groupMap))",
				       sid_name_use);
	}
	if (expr == NULL) goto failed;

	/* we do a subtree search on the domain */
	if (domsid != NULL) {
		sid_to_fstring(name, domsid);
		basedn = ldb_dn_string_compose(tmp_ctx, NULL, "domain=%s", name);
		if (basedn == NULL) goto failed;
	}

	ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, NULL, &res);
	talloc_steal(tmp_ctx, res);
	if (ret != LDB_SUCCESS) goto failed;

	(*pp_rmap) = NULL;
	*p_num_entries = 0;

	for (i=0;i<res->count;i++) {
		(*pp_rmap) = SMB_REALLOC_ARRAY((*pp_rmap), GROUP_MAP, 
					       (*p_num_entries)+1);
		if (!(*pp_rmap)) goto failed;

		if (!msg_to_group_map(res->msgs[i], &(*pp_rmap)[*p_num_entries])) {
			goto failed;
		}

		(*p_num_entries)++;
	}

	talloc_free(tmp_ctx);
	return True;

failed:
	talloc_free(tmp_ctx);
	return False;	
}
Exemple #5
0
/*
  Return the sid and the type of the unix group.
*/
static bool get_group_map_from_ntname(const char *name, GROUP_MAP *map)
{
	int ret;
	struct ldb_result *res=NULL;
	bool result = false;

	ret = ldb_search(ldb, talloc_tos(), &res, NULL, LDB_SCOPE_SUBTREE,
			 NULL, "(&(ntName=%s)(objectClass=groupMap))", name);
	if (ret != LDB_SUCCESS || res->count != 1) {
		goto failed;
	}

	if (!msg_to_group_map(res->msgs[0], map)) {
		goto failed;
	}

	result = true;
 failed:
	TALLOC_FREE(res);
	return result;
}
Exemple #6
0
/*
 return a group map entry for a given gid
*/
static bool get_group_map_from_gid(gid_t gid, GROUP_MAP *map)
{
	int ret;
	struct ldb_result *res=NULL;
	bool result = false;

	ret = ldb_search(ldb, talloc_tos(), &res, NULL, LDB_SCOPE_SUBTREE,
			 NULL, "(&(gidNumber=%u)(objectClass=groupMap))",
			 (unsigned)gid);
	if (ret != LDB_SUCCESS || res->count != 1) {
		goto failed;
	}

	if (!msg_to_group_map(res->msgs[0], map)) {
		goto failed;
	}

	result = true;
failed:
	TALLOC_FREE(res);
	return result;
}
Exemple #7
0
/*
 return a group map entry for a given gid
*/
static bool get_group_map_from_gid(gid_t gid, GROUP_MAP *map)
{
	int ret;
	char *expr;
	struct ldb_result *res=NULL;

	expr = talloc_asprintf(ldb, "(&(gidNumber=%u)(objectClass=groupMap))", 
			       (unsigned)gid);
	if (expr == NULL) goto failed;

	ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res);
	talloc_steal(expr, res);
	if (ret != LDB_SUCCESS || res->count != 1) goto failed;
	
	if (!msg_to_group_map(res->msgs[0], map)) goto failed;

	talloc_free(expr);
	return True;

failed:
	talloc_free(expr);
	return False;
}