All pastes #67526 Raw Edit

Someone

public c v1 · immutable
#67526 ·published 2006-06-20 04:27 UTC
rendered paste body
/ extract the jail structure from the filegboolean get_jail_struct(GKeyFile* settings, gchar* canonical_name, struct jail* out) {	char jail_path[MAX_PATH+1];	gsize size;	gchar** groups = NULL;	gchar** groups_iter;	gchar* ret;	GKeyFile* jail_settings = NULL;	struct host* current_host;	GError *err = NULL;	gboolean error = FALSE;		out->hosts = NULL;		memset(out, 0, sizeof(struct jail));		snprintf(jail_path, MAX_PATH, "policy/%s", canonical_name);		// open the policy file	jail_settings  = key_file_load_from_file(jail_path, FALSE,  FALSE);	if (jail_settings == NULL) {        g_warning("get_jail_struct:error during open settings %s\n%s\n", jail_path, strerror(errno));		return FALSE;	}					// get all the hosts for the jail	groups_iter = groups = g_key_file_get_groups(jail_settings, &size);	if (groups == NULL) {		g_key_file_free(jail_settings);		g_warning("get_jail_struct:error during g_key_file_get_groups for %s\n", jail_path);		return FALSE;	}		// iterate over all the hosts	while (*groups_iter) {		if (error) {			g_warning("get_jail_struct:error during g_key_get_string:command for %s\n", jail_path);			free_jail_struct(out);			g_strfreev(groups);				g_key_file_free(jail_settings);				break;		}						if (strstr(*groups_iter, "host#") == *groups_iter) {											current_host = (struct host*)malloc(sizeof(struct host));			memset(current_host, 0, sizeof(struct host));							out->hosts = g_list_append(out->hosts, current_host);	 	// add it to the jail list											strncpy(current_host->host_addr, get_host(*groups_iter), MAX_URL);					ret = g_key_file_get_string(jail_settings, *groups_iter, "command", &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;						strncpy(current_host->command, ret?ret:"", MAX_PATH);						ret = g_key_file_get_string(jail_settings, *groups_iter, "binary", &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;			strncpy(current_host->binary, ret?ret:"", MAX_PATH);						ret = g_key_file_get_string(jail_settings, *groups_iter, "binary_params", &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;			strncpy(current_host->binary_params, ret?ret:"", MAX_PATH);						ret = g_key_file_get_string(jail_settings, *groups_iter, "url", &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;			strncpy(current_host->url, ret?ret:"", MAX_PATH);						current_host->execve = g_key_file_get_string_list(jail_settings, *groups_iter, "execve",  &size, &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;						if (current_host->execve)	// duplicate the list				current_host->execve = g_strdupv(current_host->execve);			current_host->primary = g_key_file_get_boolean(jail_settings, *groups_iter, "primary", &err);			if (err && err->code !=  G_KEY_FILE_ERROR_KEY_NOT_FOUND) {					error = TRUE;				continue;			}			err = NULL;			ret = g_key_file_get_string(jail_settings, *groups_iter, "action", &err);			if (err) {					error = TRUE;				continue;			}			err = NULL;																		current_host->action  = char2enum(ret);		}				groups_iter++;			}			if (groups) g_strfreev(groups);	if (jail_settings) g_key_file_free(jail_settings);	return error==FALSE;}