Exemplo n.º 1
0
struct isns_config_s *
isns_new_config(void)
{
	struct isns_config_s *cfg_p;
	pthread_mutexattr_t mutexattr;

	cfg_p = (struct isns_config_s *)
	    isns_malloc(sizeof(struct isns_config_s));
	if (cfg_p == NULL) {
		DBG("isns_new_config: error on isns_malloc() [1]\n");
		return NULL;
	}
	cfg_p->kq = -1;
	cfg_p->pipe_fds[0] = -1;
	cfg_p->pipe_fds[1] = -1;
	cfg_p->curtask_p = NULL;
	cfg_p->sd_connected = 0;
	cfg_p->ai_p = NULL;
	cfg_p->pdu_in_p = NULL;

	cfg_p->refresh_p = NULL;

	pthread_mutexattr_init(&mutexattr);
	pthread_mutexattr_settype(&mutexattr, ISNS_MUTEX_TYPE_NORMAL);
	if (pthread_mutex_init(&cfg_p->taskq_mutex, &mutexattr) != 0) {
		DBG("isns_new_config: error on pthread_mutex_init() [1]\n");
		isns_free(cfg_p);
		return NULL;
	}

	pthread_mutexattr_init(&mutexattr);
	pthread_mutexattr_settype(&mutexattr, ISNS_MUTEX_TYPE_NORMAL);
	if (pthread_mutex_init(&cfg_p->trans_mutex, &mutexattr) != 0) {
		DBG("isns_new_config: error on pthread_mutex_init() [2]\n");
		pthread_mutex_destroy(&cfg_p->taskq_mutex);
		isns_free(cfg_p);
		return NULL;
	}

	SIMPLEQ_INIT(&cfg_p->taskq_head);

	cfg_p->control_thread_p = (pthread_t *)isns_malloc(sizeof(pthread_t));
	if (cfg_p->control_thread_p == NULL) {
		DBG("isns_new_config: error on isns_malloc() [1]\n");
		isns_destroy_config(cfg_p);
		return NULL;
	}

	return cfg_p;
}
Exemplo n.º 2
0
/*
 * Allocate an empty policy object
 */
isns_policy_t *
__isns_policy_alloc(const char *spi, size_t len)
{
	isns_policy_t	*policy;

	policy = isns_calloc(1, sizeof(*policy));
	policy->ip_name = isns_malloc(len + 1);
	policy->ip_users = 1;
	policy->ip_gen = isns_policy_gen;

	memcpy(policy->ip_name, spi, len);
	policy->ip_name[len] = '\0';

	/* Only register/query allowed */
	policy->ip_functions =
		(1 << ISNS_DEVICE_ATTRIBUTE_REGISTER) |
		(1 << ISNS_DEVICE_ATTRIBUTE_QUERY) |
		(1 << ISNS_DEVICE_GET_NEXT) |
		(1 << ISNS_DEVICE_DEREGISTER) |
		(1 << ISNS_SCN_REGISTER);

	/* Can only register initiator node(s) */
	policy->ip_node_types =
		ISNS_ISCSI_INITIATOR_MASK;

	/* Can only view/modify standard objects */
	policy->ip_object_types = ISNS_DEFAULT_OBJECT_ACCESS;

	return policy;
}
Exemplo n.º 3
0
/*
 * Load a DSA key from the cert store
 * In fact, this will load RSA keys as well.
 */
static EVP_PKEY *
__isns_simple_keystore_find(isns_keystore_t *store_base,
		const char *name, size_t namelen)
{
	isns_simple_keystore_t *store = (isns_simple_keystore_t *) store_base;
	char		*pathname;
	size_t		capacity;
	EVP_PKEY	*result;

	/* Refuse to open key files with names
	 * that refer to parent directories */
	if (memchr(name, '/', namelen) || name[0] == '.')
		return NULL;

	capacity = strlen(store->sc_dirpath) + 2 + namelen;
	pathname = isns_malloc(capacity);
	if (!pathname)
		isns_fatal("Out of memory.");
	snprintf(pathname, capacity,
			"%s/%.*s", store->sc_dirpath,
			(int) namelen, name);
	if (access(pathname, R_OK) < 0) {
		isns_free(pathname);
		return NULL;
	}
	result = isns_dsasig_load_public_pem(NULL, pathname);
	isns_free(pathname);
	return result;
}