File: dynalogin_tester.c

package info (click to toggle)
dynalogin 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, sid, stretch
  • size: 1,864 kB
  • ctags: 439
  • sloc: sh: 11,691; ansic: 2,552; php: 276; makefile: 103; sql: 13
file content (86 lines) | stat: -rw-r--r-- 1,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * dynalogin_tester.c
 *
 */

#include <stdio.h>
#include <stdlib.h>

#include "dynalogin.h"

#define MY_DS "example_ds"
/* #define MY_DS "fs_ds" */
/* #define MY_DS "odbc_ds" */

#define MAX_CODE 32

int main(int argc, char *argv[])
{
	dynalogin_userid_t userid;
	dynalogin_scheme_t scheme;
	char code_buf[MAX_CODE];
	dynalogin_code_t code = (dynalogin_code_t)code_buf;
	dynalogin_session_t *h;
	dynalogin_result_t res;

	apr_pool_t *pool;
	apr_hash_t *config;

	if(apr_initialize() != APR_SUCCESS)
	{
		fprintf(stderr, "apr_initialize failed\n");
		return 1;
	}

	if(argc != 3)
	{
		fprintf(stderr, "Must specify a user ID and scheme\n");
		return 1;
	}
	userid = (dynalogin_userid_t)argv[1];
	scheme = get_scheme_by_name(argv[2]);

	if(apr_pool_create(&pool, NULL) != APR_SUCCESS)
	{
		return 1;
	}
	if((config = apr_hash_make(pool)) == NULL)
	{
		return 1;
	}
	apr_hash_set(config, "dynalogin.datasource",
			APR_HASH_KEY_STRING, MY_DS);

	fprintf(stderr, "Trying to initialise the stack...\n");
	if(dynalogin_init(&h, pool, config) != DYNALOGIN_SUCCESS)
	{
		fprintf(stderr, "Failed to initialise dynalogin\n");
		return 1;
	}

	while(1)
	{
		printf("Enter the code for %s: ", (char *)userid);
		scanf("%s", code_buf);
		printf("\nYou entered code [%s].\n", code_buf);

		res = dynalogin_authenticate(h, userid, scheme, code);

		switch(res)
		{
		case DYNALOGIN_SUCCESS:
			printf("Authentication success\n");
			break;
		case DYNALOGIN_DENY:
			printf("Authentication denied\n");
			break;
		case DYNALOGIN_ERROR:
			printf("Error processing the request\n");
			break;
		default:
			printf("Unexpected result\n");
		}
	}

	return 0;
}