Esempio n. 1
0
ATF_TC_BODY(t_session_init, tc)
{

	saslc_t *ctx;
	ATF_REQUIRE(ctx = saslc_alloc());
	ATF_REQUIRE_EQ(saslc_init(ctx, NULL, NULL), 0);
	ATF_REQUIRE_EQ(saslc_end(ctx), 0);
}
Esempio n. 2
0
ATF_TC_BODY(t_parser_test1, tc)
{
	saslc_t *ctx;

	ATF_REQUIRE(ctx = saslc_alloc());
	ATF_CHECK_EQ(saslc_init(ctx, "test1", NULL), 0);
	ATF_REQUIRE_EQ(saslc_end(ctx), 0);
}
Esempio n. 3
0
ATF_TC_BODY(t_saslc__error, tc)
{
	saslc_t *ctx;

	ATF_REQUIRE(ctx = saslc_alloc());
	ATF_REQUIRE_EQ(saslc_init(ctx, NULL, NULL), 0);
	saslc__error_set(ERR(ctx), ERROR_GENERAL, "test");
	ATF_CHECK_EQ(saslc__error_get_errno(ERR(ctx)), ERROR_GENERAL);
	ATF_CHECK_STREQ(saslc_strerror(ctx), "test");
	saslc__error_set_errno(ERR(ctx), ERROR_NOMEM);
	ATF_CHECK_STREQ(saslc_strerror(ctx), "no memory available");
	ATF_REQUIRE_EQ(saslc_end(ctx), 0);
}
Esempio n. 4
0
ATF_TC_BODY(t_parser_test2, tc)
{
	saslc_t *ctx;
	saslc_sess_t *sess;
	const char *val;

	ATF_REQUIRE(ctx = saslc_alloc());
	ATF_CHECK_EQ(saslc_init(ctx, "test2", NULL), 0);
	ATF_REQUIRE((sess = saslc_sess_init(ctx, "ANONYMOUS", NULL)));
	ATF_REQUIRE(val = saslc_sess_getprop(sess, "TEST"));
	ATF_CHECK_STREQ(val, "one");
	ATF_REQUIRE(val = saslc_sess_getprop(sess, "TEST2"));
	ATF_CHECK_STREQ(val, "one two");
	ATF_REQUIRE(val = saslc_sess_getprop(sess, "TEST3"));
	ATF_CHECK_STREQ(val, "one two three");
	ATF_REQUIRE(val = saslc_sess_getprop(sess, "ID"));
	ATF_CHECK_STREQ(val, "6669");
	saslc_sess_end(sess);
	ATF_REQUIRE_EQ(saslc_end(ctx), 0);
}
Esempio n. 5
0
ATF_TC_BODY(t_sess, tc)
{
	saslc_t *ctx;
	saslc_sess_t *sess;

	ATF_REQUIRE(ctx = saslc_alloc());
	ATF_REQUIRE_EQ(saslc_init(ctx, NULL, NULL), 0);
	ATF_CHECK(sess = saslc_sess_init(ctx, "PLAIN", NULL));
	if (sess != NULL)
		saslc_sess_end(sess);
	ATF_CHECK_EQ(sess = saslc_sess_init(ctx, "", NULL), NULL);
	ATF_CHECK(sess = saslc_sess_init(ctx, "NOTEXISTS,LOGIN", NULL));
	if (sess != NULL)
		saslc_sess_end(sess);
	ATF_CHECK(sess = saslc_sess_init(ctx, "LOGIN,NOTEXISTS", NULL));
	if (sess != NULL)
		saslc_sess_end(sess);
	ATF_REQUIRE(sess = saslc_sess_init(ctx, "LOGiN", NULL));
	ATF_CHECK_STREQ(saslc_sess_getmech(sess), "LOGIN");
	ATF_REQUIRE_EQ(saslc_end(ctx), -1);
	saslc_sess_end(sess);
	ATF_REQUIRE_EQ(saslc_end(ctx), 0);
}
Esempio n. 6
0
int
main(int argc, char **argv)
{
	int opt, n, cont;
	char *mechanism = NULL;
	saslc_t *ctx;
	saslc_sess_t *sess;
	char input[LINE_MAX];
	char *option, *var;
	char *output;
	static char empty[] = "";
	size_t input_len, output_len;

	while ((opt = getopt(argc, argv, "hm:l")) != -1) {
		switch (opt) {
		case 'm':
			/* mechanism */
			mechanism = optarg;
			break;
		case 'l':
			/* list mechanisms */
			list_mechanisms();
			return EXIT_SUCCESS;
		case 'h':
		default:
			/* ??? */
			print_help();
			return EXIT_FAILURE;
		}
	}

	if (mechanism == NULL) {
		printf("mechanism: ");
		if (nextline(input, sizeof(input), stdin) == NULL)
			goto eof;
		mechanism = input;
	}

	ctx = saslc_alloc();

	if (saslc_init(ctx, NULL, NULL) < 0)
		goto error;

	if ((sess = saslc_sess_init(ctx, mechanism, NULL)) == NULL)
		goto error;

	/* reading properties */
	if (nextline(input, sizeof(input), stdin) == NULL)
		goto eof;
	n = atoi(input);

	while (n--) {
		if (nextline(input, sizeof(input), stdin) == NULL)
			goto eof;
		var = strchr(input, ' ');
		if (var != NULL)
			*var++ = '\0';
		else
			var = empty;
		option = input;
		if (saslc_sess_setprop(sess, option, var) < 0)
			goto error;
	}

	printf("session:\n");

	for (;;) {
		if (nextline(input, sizeof(input), stdin) == NULL)
			break;
		input_len = strlen(input);
		cont = saslc_sess_cont(sess, input, input_len, (void **)&output,
		    &output_len);
		if (cont < 0)
			goto error_sess;
		printf("%s\n", output == NULL ? "empty line" : output);
		if (cont == 0)
			break;
	}

	saslc_sess_end(sess);
	if (saslc_end(ctx) < 0)
		goto error;

	return 0;
 eof:
	err(EXIT_FAILURE, "Unexpected EOF");
 error:
	errx(EXIT_FAILURE, "%s", saslc_strerror(ctx));
 error_sess:
	errx(EXIT_FAILURE, "%s", saslc_sess_strerror(sess));
}