예제 #1
0
/* Recursively dump the object tree */
static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object_handle, int depth)
{
	hdb_handle_t object_handle;
	char object_name[1024];
	size_t object_name_len;
	char key_name[1024];
	size_t key_name_len;
	char key_value[1024];
	size_t key_value_len;
	int res;
	int i;

	/* Show the keys */
	res = confdb_key_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		printf( "error resetting key iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res);
		return;
	}

	while ( (res = confdb_key_iter(handle, parent_object_handle, key_name, &key_name_len,
				       key_value, &key_value_len)) == CS_OK) {
		key_name[key_name_len] = '\0';
		key_value[key_value_len] = '\0';
		for (i=0; i<depth; i++)	printf("  ");
		printf("  KEY %s=%s\n", key_name, key_value);
	}

	/* Show sub-objects */
	res = confdb_object_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		printf( "error resetting object iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res);
		return;
	}

	while ( (res = confdb_object_iter(handle, parent_object_handle, &object_handle, object_name, &object_name_len)) == CS_OK)	{
		hdb_handle_t parent;

		res = confdb_object_parent_get(handle, object_handle, &parent);
		if (res != CS_OK) {
			printf( "error getting parent for object "HDB_X_FORMAT": %d\n", object_handle, res);
			return;
		}

		for (i=0; i<depth; i++)	printf("  ");

		object_name[object_name_len] = '\0';
		printf("OBJECT: %s ("HDB_X_FORMAT", parent: "HDB_X_FORMAT")\n", object_name, object_handle, parent);

		/* Down we go ... */
		print_config_tree(handle, object_handle, depth+1);
	}
}
예제 #2
0
파일: xpathlite.c 프로젝트: smintz/cluster
static int get_data(confdb_handle_t handle, hdb_handle_t connection_handle,
		    hdb_handle_t query_handle, hdb_handle_t *list_handle,
		    char **rtn, char *curpos, int list, int is_oldlist)
{
	int cmp;
	char data[PATH_MAX];
	char *resval;
	char *keyval;
	hdb_handle_t new_obj_handle;
	unsigned int value = 0;
	confdb_value_types_t type;
	size_t datalen = 0, keyvallen = PATH_MAX;

	memset(data, 0, PATH_MAX);

	// we need to handle child::*[int value] in non list mode.
	cmp = strcmp(curpos, "child::*");
	if (cmp >= 0) {
		char *start = NULL, *end = NULL;

		// a pure child::* request should come down as list
		if (!cmp && !list)
			goto fail;

		if (confdb_object_iter_start(handle, query_handle) != CS_OK)
			goto fail;

		if (!is_oldlist)
			*list_handle = query_handle;

		if (cmp) {
			start = strstr(curpos, "[");
			if (!start)
				goto fail;

			start = start + 1;

			end = strstr(start, "]");
			if (!end)
				goto fail;

			memset(end, 0, 1);
			value = atoi(start);
			if (value <= 0)
				goto fail;
		} else {
			if (confdb_key_increment
			    (handle, connection_handle, "iterator_tracker",
			     strlen("iterator_tracker"), &value) != CS_OK)
				value = 1;
		}

		while (value != 0) {
			memset(data, 0, PATH_MAX);
			if (confdb_object_iter
			    (handle, query_handle, &new_obj_handle, data,
			     &datalen) != CS_OK) {
				reset_iterator(handle, connection_handle);
				goto fail;
			}

			value--;
		}

		resval = malloc(datalen + 2);
		if (!resval)
			goto fail;
		snprintf(resval, datalen + 2, "%s=", data);
		*rtn = resval;

	} else if (!strncmp(curpos, "@*", strlen("@*"))) {

		// this query makes sense only if we are in list mode
		if (!list)
			goto fail;

		if (confdb_key_iter_start(handle, query_handle) != CS_OK)
			goto fail;

		*list_handle = query_handle;

		if (confdb_key_increment
		    (handle, connection_handle, "iterator_tracker",
		     strlen("iterator_tracker"), &value) != CS_OK)
			value = 1;

		while (value != 0) {
			memset(data, 0, PATH_MAX);
			keyval = NULL;
			if (confdb_key_iter_typed2
			    (handle, query_handle, data, (void **)&keyval,
			     &keyvallen, &type) != CS_OK) {
				reset_iterator(handle, connection_handle);
				goto fail;
			}

			value--;
			if (value != 0) {
				free(keyval);
				keyval = NULL;
			}
		}
		datalen = strlen(data);
		resval = malloc(datalen + keyvallen + 2);
		if (!resval)
			goto fail;
		snprintf(resval, datalen + keyvallen + 2, "%s=%s", data, keyval);
		*rtn = resval;
		free(keyval);

	} else {		/* pure data request */
		char *query;

		// this query doesn't make sense in list mode
		if (list)
			goto fail;

		if (confdb_object_find_start(handle, query_handle) != CS_OK)
			goto fail;

		query = strstr(curpos, "@");
		if (!query)
			goto fail;

		query = query + 1;

		keyval = NULL;
		if (confdb_key_get_typed2
		    (handle, query_handle, query, (void **)&keyval,
		     &keyvallen, &type) != CS_OK)
			goto fail;

		*rtn = keyval;
	}

	return 0;

fail:
	errno = EINVAL;
	return -1;
}
예제 #3
0
/* Recursively dump the object tree */
static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object_handle, char * parent_name)
{
	hdb_handle_t object_handle;
	char object_name[OBJ_NAME_SIZE];
	size_t object_name_len;
	char key_name[OBJ_NAME_SIZE];
	char key_value[OBJ_NAME_SIZE];
	size_t key_value_len;
	cs_error_t res;
	int children_printed;
	confdb_value_types_t type;

	/* Show the keys */
	res = confdb_key_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		fprintf(stderr, "error resetting key iterator for object "HDB_X_FORMAT" %d\n", parent_object_handle, res);
		exit(EXIT_FAILURE);
	}
	children_printed = 0;

	while ( (res = confdb_key_iter_typed(handle,
								   parent_object_handle,
								   key_name,
								   key_value,
								   &key_value_len,
								   &type)) == CS_OK) {
		key_value[key_value_len] = '\0';
		if (parent_name != NULL)
			printf("%s%c", parent_name, SEPERATOR);

		print_key(key_name, key_value, key_value_len, type);

		children_printed++;
	}

	/* Show sub-objects */
	res = confdb_object_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		fprintf(stderr, "error resetting object iterator for object "HDB_X_FORMAT" %d\n", parent_object_handle, res);
		exit(EXIT_FAILURE);
	}

	while ( (res = confdb_object_iter(handle,
		parent_object_handle,
		&object_handle,
		object_name,
		&object_name_len)) == CS_OK)	{

		object_name[object_name_len] = '\0';
		if (parent_name != NULL) {
			snprintf(key_value, OBJ_NAME_SIZE, "%s%c%s", parent_name, SEPERATOR, object_name);
		} else {
			if ((action == ACTION_PRINT_DEFAULT) && strcmp(object_name, "internal_configuration") == 0) continue;
			snprintf(key_value, OBJ_NAME_SIZE, "%s", object_name);
		}
		print_config_tree(handle, object_handle, key_value);
		children_printed++;
	}
	if (children_printed == 0 && parent_name != NULL) {
			printf("%s\n", parent_name);
	}
}
예제 #4
0
/* Recursively dump the object tree */
static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object_handle, const char *dn, char *fulldn)
{
	hdb_handle_t object_handle;
	char object_name[1024];
	size_t object_name_len;
	char key_name[1024];
	char *key_value=NULL;
	confdb_value_types_t type;
	size_t key_value_len;
	char cumulative_dn[4096];
	int res;
	int keycount=0;

	printf("\ndn: %s\n", fulldn);

	/* Show the keys */
	res = confdb_key_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		printf( "error resetting key iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res);
		return;
	}

	while ( (res = confdb_key_iter_typed2(handle, parent_object_handle, key_name,
					      (void**)&key_value, &key_value_len, &type)) == CS_OK) {
		key_value[key_value_len] = '\0';

		printf("%s: %s\n", ldap_attr_name(key_name), key_value);
		keycount++;
		free(key_value);
		key_value=NULL;
	}
	if (strncmp(fulldn, "cn=", 3) == 0) {
		printf("cn: %s\n", dn);
	}


	/* Determine objectclass... */
	if (keycount == 0) {
		printf("objectclass: nsContainer\n");
	}
	else {
		printf("objectclass: %s\n", ldap_attr_name(dn));
	}

	/* Show sub-objects */
	res = confdb_object_iter_start(handle, parent_object_handle);
	if (res != CS_OK) {
		printf( "error resetting object iterator for object "HDB_X_FORMAT": %d\n", parent_object_handle, res);
		return;
	}

	while ( (res = confdb_object_iter(handle, parent_object_handle, &object_handle, object_name, &object_name_len)) == CS_OK)	{
		hdb_handle_t parent;

		res = confdb_object_parent_get(handle, object_handle, &parent);
		if (res != CS_OK) {
			printf( "error getting parent for object "HDB_X_FORMAT": %d\n", object_handle, res);
			return;
		}

		object_name[object_name_len] = '\0';

		/* Check for "name", and create dummy parent object */
		res = confdb_key_get_typed2(handle, object_handle, "name",  (void **)&key_value, &key_value_len, &type);
		if (res == CS_OK) {
			sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn);
			printf("\n");
			printf("dn: %s\n", cumulative_dn);
			printf("cn: %s\n", object_name);
			printf("objectclass: %s\n", "nsContainer");
			snprintf(cumulative_dn, sizeof(cumulative_dn) - 1, "name=%s,cn=%s,%s", key_value, object_name, fulldn);
			free(key_value);
			key_value = NULL;
		}
		else {
			sprintf(cumulative_dn, "cn=%s,%s", object_name, fulldn);
		}

		/* Down we go ... */
		print_config_tree(handle, object_handle, object_name, cumulative_dn);
	}
}