Ejemplo n.º 1
0
/*
 * Parse the -n argument and populate -T if necessary.
 *
 * Run on every connect, must do some cleanup.
 *
 * XXX: It writes to stdout in addition to the logger because the logger
 * may not be operational yet. Not sure if this makes sense... At any rate,
 * the required bit is to write to the logger.
 */
static int
n_arg_sock(struct agent_core_t *core)
{
	struct VSM_data *vsd;
	struct vadmin_config_t *vadmin;
	char *p;
	GET_PRIV(core, vadmin);

	vsd = VSM_New();
	assert(VSL_Arg(vsd, 'n', core->config->n_arg));
	if (VSM_Open(vsd, 1)) {
		logger(vadmin->logger,"Couldn't open VSM");
		fprintf(stderr, "Couldn't open VSM\n");
		VSM_Delete(vsd);
		vsd = NULL;
	}

	if (core->config->T_arg_orig) {
		if (core->config->T_arg)
			free(core->config->T_arg);
		core->config->T_arg = strdup(core->config->T_arg_orig);
	} else {		
		if (vsd == NULL) {
			logger(vadmin->logger,"No -T arg and no shmlog readable.");
			return -1;
		}
		p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
		if (p == NULL)  {
			fprintf(stderr, "No -T arg in shared memory\n");
			logger(vadmin->logger, "No -T arg in shared memory.");
			return (-1);
		}
		core->config->T_arg = strdup(p);
	}

	if (core->config->S_arg == NULL && !vsd) {
		logger(vadmin->logger, "No shmlog and no -S arg. Unknown if authentication will work.");
	}
	if (vsd && core->config->S_arg == NULL) {
		p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL);
		if (p != NULL)
			core->config->S_arg = strdup(p);
	}

	p = strchr(core->config->T_arg, '\n');
	if (p) {
		assert(p);
		*p = '\0';
	}
	if (vsd)
		VSM_Delete(vsd);
	logger(vadmin->logger, "-T argument computed to: %s", core->config->T_arg ? core->config->T_arg : "(null)");
	return (1);
}
Ejemplo n.º 2
0
static int
n_arg_sock(const char *n_arg)
{
	char *T_arg = NULL, *T_start = NULL;
	char *S_arg = NULL;
	struct VSM_data *vsd;
	char *p;
	int sock;

	vsd = VSM_New();
	assert(VSL_Arg(vsd, 'n', n_arg));
	if (VSM_Open(vsd, 1)) {
		fprintf(stderr, "Could not open shared memory\n");
		return (-1);
	}
	if (T_arg == NULL) {
		p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
		if (p == NULL)  {
			fprintf(stderr, "No -T arg in shared memory\n");
			return (-1);
		}
		T_start = T_arg = strdup(p);
	}
	if (S_arg == NULL) {
		p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL);
		if (p != NULL)
			S_arg = strdup(p);
	}
	sock = -1;
	while (*T_arg) {
		p = strchr(T_arg, '\n');
		AN(p);
		*p = '\0';
		sock = cli_sock(T_arg, S_arg);
		if (sock >= 0)
			break;
		T_arg = p + 1;
	}
	free(T_start);
	free(S_arg);
	return (sock);
}