Esempio n. 1
0
void
mgt_cli_setup(int fdi, int fdo, int auth, const char *ident,
    mgt_cli_close_f *closefunc, void *priv)
{
	struct cli *cli;
	struct vev *ev;

	cli = VCLS_AddFd(mgt_cls, fdi, fdo, closefunc, priv);

	REPLACE(cli->ident, ident);

	if (!auth && secret_file != NULL) {
		cli->auth = MCF_NOAUTH;
		mgt_cli_challenge(cli);
	} else {
		cli->auth = MCF_AUTH;
		mcf_banner(cli, NULL, NULL);
	}
	AZ(VSB_finish(cli->sb));
	(void)VCLI_WriteResult(fdo, cli->result, VSB_data(cli->sb));

	ev = VEV_Alloc();
	AN(ev);
	ev->name = cli->ident;
	ev->fd = fdi;
	ev->fd_flags = VEV__RD;
	ev->callback = mgt_cli_callback2;
	ev->priv = cli;
	AZ(VEV_Start(mgt_evb, ev));
}
Esempio n. 2
0
void
mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident,
    mgt_cli_close_f *closefunc, void *priv)
{
	struct cli *cli;
	struct vev *ev;

	(void)ident;
	(void)verbose;

	cli = VCLS_AddFd(mgt_cls, fdi, fdo, closefunc, priv);

	cli->ident = strdup(ident);

	if (fdi != 0 && secret_file != NULL) {
		cli->auth = MCF_NOAUTH;
		mgt_cli_challenge(cli);
	} else {
		cli->auth = MCF_AUTH;
		mcf_banner(cli, NULL, NULL);
	}
	AZ(VSB_finish(cli->sb));
	(void)VCLI_WriteResult(fdo, cli->result, VSB_data(cli->sb));


	ev = vev_new();
	AN(ev);
	ev->name = cli->ident;
	ev->fd = fdi;
	ev->fd_flags = EV_RD;
	ev->callback = mgt_cli_callback2;
	ev->priv = cli;
	AZ(vev_add(mgt_evb, ev));
}
Esempio n. 3
0
/*
 * A command was apparently issued.
 *
 * Commands now have 16 bytes of decimal-encoded size.
 *
 * Note that &ret must be populated with something we can free().
 */
static int ipc_cmd(int fd, struct ipc_t *ipc)
{
	char buffer[11];
	struct ipc_ret_t ret;
	int length = 0;
	char *data;
	int i, oldi;

	i = read(fd, buffer, 10);
	assert(i == 10);
	assert(buffer[9] == ' ');
	length = atoi(buffer);
	assert(length >= 0);
	
	data = malloc(length+1);
	assert(data);
	for (i = 0, oldi = 0; i < length; ) {
		i += read(fd, data + i, length - i);
		assert(i != oldi);
	}
		
	if (i != length) {
		fprintf(stderr,"Wanted %d data, got %d", length, i);
	}
	assert(i == length);
	data[length] = '\0';
	ipc->cb(ipc->priv, data, &ret);

	VCLI_WriteResult(fd, ret.status, ret.answer);
	free(data);
	if (ret.answer)
		free(ret.answer);
	return 1;
}