void
tc_connect_lud_serverdup(const char *sockname)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *s  = NULL;
	struct achat_channel    *s2 = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(s->euid != (uid_t)-1, "euid expected -1 but is %i", s->euid);
	fail_if(s->egid != (gid_t)-1, "egid expected -1 but is %i", s->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	s2 = acc_opendup(s);
	fail_if(s2 == NULL, "server opendup failed [%s]",
		anoubis_strerror(errno));
	fail_if(s2->euid != geteuid(), "server retrieved bogus uid %d, "
	    "expected %d", s2->euid, geteuid());
	fail_if(s2->egid != getegid(), "server retrieved bogus gid %d, "
	    "expected %d", s2->egid, getegid());

	rc = acc_destroy(s);
	fail_if(rc != ACHAT_RC_OK, "server org destroy failed with rc=%d",
	    rc);

	rc = acc_destroy(s2);
	fail_if(rc != ACHAT_RC_OK, "server dup destroy failed with rc=%d",
	    rc);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(tc_core_sslmode)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setsslmode(NULL, ACC_SSLMODE_NONE);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setsslmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setsslmode(c, 1024);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setsslmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	fail_if(c->sslmode != ACC_SSLMODE_CLEAR, "sslmode not set correctly");
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 3
0
END_TEST

START_TEST(tc_core_tail)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_settail(NULL, ACC_TAIL_NONE);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "settail expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_settail(c, 1024);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "settail expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_settail(c, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	fail_if(c->tail != ACC_TAIL_SERVER, "tail not set correctly");
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 4
0
static krb5_error_code KRB5_CALLCONV
acc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
{
    krb5_acc *afrom = ACACHE(from);
    krb5_acc *ato = ACACHE(to);
    int32_t error;

    if (ato->ccache == NULL) {
	cc_string_t name;

	error = (*afrom->ccache->func->get_principal)(afrom->ccache,
						      cc_credentials_v5,
						      &name);
	if (error)
	    return translate_cc_error(context, error);

	error = (*ato->context->func->create_new_ccache)(ato->context,
							 cc_credentials_v5,
							 name->data,
							 &ato->ccache);
	(*name->func->release)(name);
	if (error)
	    return translate_cc_error(context, error);
    }

    error = (*ato->ccache->func->move)(afrom->ccache, ato->ccache);

    acc_destroy(context, from);

    return translate_cc_error(context, error);
}
Ejemplo n.º 5
0
void
ComThread::disconnect(void)
{
	if (client_ != 0) {
		anoubis_client_close(client_);
		anoubis_client_destroy(client_);
		client_ = 0;
	}

	if (channel_ != 0) {
		acc_destroy(channel_);
		channel_ = 0;
	}
}
void
tc_connect_lip_client(short port)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_in	in;
	} sa;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(port);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_in));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	sleep(4); /* give the server time to open his socket */
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "client open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	fail_unless(c->euid == (uid_t)-1, "euid: -1 expected but is %i",
	    c->euid);
	fail_unless(c->egid == (gid_t)-1, "egid: -1 expected but is %i",
	    c->egid);

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	exit(0);
}
void
tc_connect_lud_client(const char *sockname)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);
	mark_point();

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	sleep(4); /* give the server time to open his socket */
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "client open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));

	fail_if(c->euid == (uid_t)-1, "euid != -1 expected, is %i", c->euid);
	fail_if(c->egid == (gid_t)-1, "egid != -1 expected, is %i", c->egid);

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	exit(0);
}
Ejemplo n.º 8
0
END_TEST

START_TEST(tc_core_state_initialised)
{
	struct achat_channel    *c = NULL;
	union {
		struct sockaddr_storage	st;
		struct sockaddr_in	in;
	} sa;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(ACHAT_SERVER_PORT);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
#ifdef OPENBSD
	sa.in.sin_len = sizeof(struct sockaddr_in);
#endif

	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_in));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_in),
		"socket address not set correctly");
	mark_point();

	rc = acc_settail(c, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	fail_if(c->tail != ACC_TAIL_SERVER, "tail not set correctly");
	mark_point();

	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	fail_if(c->sslmode != ACC_SSLMODE_CLEAR, "sslmode not set correctly");

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 9
0
END_TEST

START_TEST(tc_core_blocking)
{
	struct achat_channel    *c  = NULL;
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setblockingmode(c, ACC_BLOCKING);
	fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc);
	fail_if(c->blocking != ACC_BLOCKING, "blocking not set correctly");
	mark_point();

	rc = acc_setblockingmode(c, ACC_NON_BLOCKING);
	fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc);
	fail_if(c->blocking != ACC_NON_BLOCKING, "blocking not set correctly");
	mark_point();

	rc = acc_setblockingmode(c, -1);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "blockingmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setblockingmode(c, 2);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "blockingmode expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 10
0
END_TEST


START_TEST(tc_connect_localip)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_in	in;
	} sa;
	struct achat_channel    *s  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	pid_t			 childpid;
	socklen_t		 sslen;

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(s->euid != (uid_t)-1, "euid expected -1 but is %i", s->euid);
	fail_if(s->egid != (gid_t)-1, "egid expected -1 but is %i", s->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = 0;
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_in));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sslen = sizeof(sa.ss);
	if (getsockname(s->fd, (struct sockaddr *)&sa.ss, &sslen) == -1)
		fail("error while asking about server socket name [%s]",
		    anoubis_strerror(errno));
	fail_if(sa.in.sin_port == 0,
	    "couldn't determine port of server socket");
	mark_point();

	switch (childpid = check_fork()) {
	case -1:
		fail("couldn't fork");
		break;
	case 0:
		/* child / client */
		tc_connect_lip_client(ntohs(sa.in.sin_port));
		check_waitpid_and_exit(0);
		break;
	default:
		/* parent / server */
		rc = acc_open(s);
		fail_if(rc != ACHAT_RC_OK, "server open failed with rc=%d [%s]",
		    rc, anoubis_strerror(errno));
		fail_unless(s->euid == (uid_t)-1, "euid: -1 expected but is %i",
			s->euid);
		fail_unless(s->egid == (gid_t)-1, "egid: -1 expected but is %i",
			s->egid);

		rc = acc_destroy(s);
		fail_if(rc != ACHAT_RC_OK, "server destroy failed with rc=%d",
		    rc);

		check_waitpid_and_exit(childpid);
		break;
	}
}
Ejemplo n.º 11
0
END_TEST


/*
 * This test prepares the client and server unix domain socket and run
 * a destroy on the client first. This should check/trigger bug #334 or
 * verify it's solution: the client may not unlink the server socket.
 */
START_TEST(tc_connect_localunixdomain_clientclose)
{
	char *sockname;
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel    *s  = NULL;
	struct achat_channel    *c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;

	sockname = tempnam(NULL, "ac");

	c = acc_create();
	fail_if(c == NULL, "couldn't create client channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "client settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "client setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("client setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "client prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	s = acc_create();
	fail_if(s == NULL, "couldn't create server channel");
	fail_if(c->euid != (uid_t)-1, "euid expected -1 but is %i", c->euid);
	fail_if(c->egid != (gid_t)-1, "egid expected -1 but is %i", c->egid);

	rc = acc_settail(s, ACC_TAIL_SERVER);
	fail_if(rc != ACHAT_RC_OK, "server settail failed with rc=%d", rc);
	rc = acc_setsslmode(s, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "server setsslmode failed with rc=%d", rc);
	mark_point();

	rc = acc_setaddr(s, &sa.ss, sizeof(struct sockaddr_un));
	if (rc != ACHAT_RC_OK)
		fail("server setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(s);
	fail_if(rc != ACHAT_RC_OK, "server prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	if (access(sockname, F_OK) != 0)
		fail("unix domain socket not created!");

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "client destroy failed with rc=%d", rc);

	if (access(sockname, F_OK) != 0)
		fail("unix domain socket (of server) removed by client!");

	rc = acc_destroy(s);
	fail_if(rc != ACHAT_RC_OK, "server destroy failed with rc=%d", rc);

	if (access(sockname, F_OK) == 0)
		fail("unix domain test: socket not removed!");
}
Ejemplo n.º 12
0
END_TEST

START_TEST(tc_core_addr)
{
	struct achat_channel    *c = NULL;
	union {
		struct sockaddr_storage	 st;
		struct sockaddr_un	 un;
		struct sockaddr_in	 in;
	} sa;
	char			 testpath[] = "The road goes ever on and on";
	achat_rc                 rc = ACHAT_RC_ERROR;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	mark_point();

	rc = acc_setaddr(NULL, NULL, 0);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setaddr expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	rc = acc_setaddr(c, NULL, 0);
	fail_if(rc != ACHAT_RC_INVALPARAM,
	    "setaddr expected to fail with rc=%d but returned rc=%d",
	    ACHAT_RC_INVALPARAM, rc);
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, testpath, sizeof(sa.un.sun_path));
#ifdef OPENBSD
	sa.un.sun_len = SUN_LEN(&sa.un);
#endif
	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_un),
		"socket address not set correctly");
	mark_point();

	bzero(&sa.st, sizeof(sa.st));
	sa.in.sin_family = AF_INET;
	sa.in.sin_port = htons(ACHAT_SERVER_PORT);
	inet_aton("127.0.0.1", &(sa.in.sin_addr));
#ifdef OPENBSD
	sa.in.sin_len = sizeof(struct sockaddr_in);
#endif
	rc = acc_setaddr(c, &sa.st, sizeof(struct sockaddr_in));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	if (memcmp(&c->addr, &sa.st, sizeof(sa.st)) != 0)
		fail("socket address not set correctly");
	fail_if(c->addrsize != sizeof(struct sockaddr_in),
		"socket address not set correctly");
	mark_point();

	/* XXX by ch: test of AF_INET6 is missing here */

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 13
0
END_TEST

START_TEST(tc_Sessions_three)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel	*c  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	struct anoubis_client   *client;
	struct anoubis_transaction * t;
	int count = 0;
	int ret;

	c = acc_create();
	fail_if(c == NULL, "couldn't create channel");
	rc = acc_settail(c, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "settail failed with rc=%d", rc);
	rc = acc_setsslmode(c, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "setsslmode failed with rc=%d", rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c);
	fail_if(rc != ACHAT_RC_OK, "prepare failed with rc=%d [%s]", rc,
	    anoubis_strerror(errno));
	rc = acc_open(c);
	fail_if(rc != ACHAT_RC_OK, "open failed with rc=%d [%s]", rc,
	    anoubis_strerror(errno));
	mark_point();

	client = anoubis_client_create(c, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client, "Failed to create client");
	mark_point();

	ret = anoubis_client_connect(client, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "client connect failed with code %d", ret);
	mark_point();

	t = anoubis_client_register_start(client, 0x123, 0, 0,
	    ANOUBIS_SOURCE_STAT);
	fail_if(!t, "Failed to register for stat events");
	while(count < 3) {
		struct anoubis_msg * m = anoubis_msg_new(4000);
		size_t length = 4000;
		fail_if(!m, "Cannot allocate message");
		rc = acc_receivemsg(c, m->u.buf, &length);
		fail_if(rc != ACHAT_RC_OK, "receive message returned %d", rc);
		anoubis_msg_resize(m, length);
		rc = anoubis_client_process(client, m);
		fail_if(rc != 1, "client process failed");
		m = anoubis_client_getnotify(client);
		if (m) {
			anoubis_dump(m, "NOTIFY");
			anoubis_msg_free(m);
			count++;
		}
	}
	anoubis_client_close(client);
	mark_point();

	rc = acc_destroy(c);
	fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc);
}
Ejemplo n.º 14
0
END_TEST

START_TEST(tc_Sessions_two)
{
	union {
		struct sockaddr_storage	ss;
		struct sockaddr_un	un;
	} sa;
	struct achat_channel	*c1  = NULL;
	struct achat_channel	*c2  = NULL;
	achat_rc		 rc = ACHAT_RC_ERROR;
	struct anoubis_client   *client1, *client2;
	int			 ret;

	c1 = acc_create();
	fail_if(c1 == NULL, "couldn't create first channel");
	rc = acc_settail(c1, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "1st channel settail failed with rc=%d", rc);
	rc = acc_setsslmode(c1, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "1st channel setsslmode failed with rc=%d",
	    rc);
	mark_point();

	c2 = acc_create();
	fail_if(c2 == NULL, "couldn't create second channel");
	rc = acc_settail(c2, ACC_TAIL_CLIENT);
	fail_if(rc != ACHAT_RC_OK, "2nd channel settail failed with rc=%d", rc);
	rc = acc_setsslmode(c2, ACC_SSLMODE_CLEAR);
	fail_if(rc != ACHAT_RC_OK, "2nd channel setsslmode failed with rc=%d",
	    rc);
	mark_point();

	bzero(&sa.ss, sizeof(sa.ss));
	sa.un.sun_family = AF_UNIX;
	strlcpy(sa.un.sun_path, sockname, sizeof(sa.un.sun_path));
	rc = acc_setaddr(c1, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "1st channel setaddr failed with rc=%d", rc);
	rc = acc_setaddr(c2, &sa.ss, sizeof(struct sockaddr_un));
	fail_if(rc != ACHAT_RC_OK, "2nd channel setaddr failed with rc=%d", rc);
	mark_point();

	rc = acc_prepare(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	rc = acc_open(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();

	client1 = anoubis_client_create(c1, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client1, "1st client create failed");
	mark_point();

	rc = acc_prepare(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel prepare failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	rc = acc_open(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel open failed with rc=%d [%s]",
	    rc, anoubis_strerror(errno));
	mark_point();
	client2 = anoubis_client_create(c2, ANOUBIS_AUTH_TRANSPORT, NULL);
	fail_if(!client1, "2nd client create failed");
	mark_point();

	ret = anoubis_client_connect(client1, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "1st client connect failed with %d", ret);
	mark_point();

	ret = anoubis_client_connect(client2, ANOUBIS_PROTO_BOTH);
	fail_if(ret < 0, "2nd client connect failed with %d", ret);
	mark_point();

	rc = acc_destroy(c1);
	fail_if(rc != ACHAT_RC_OK, "1st channel destroy failed with rc=%d", rc);

	rc = acc_destroy(c2);
	fail_if(rc != ACHAT_RC_OK, "2nd channel destroy failed with rc=%d", rc);
}