summaryrefslogtreecommitdiffstats
path: root/contrib/opie/opieserv.c
blob: db5c66b0189b6cbc9deca9f06561678c1d8754d7 (plain)
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
/* opieserv.c: Sample OTP server based on the opiechallenge() and
               opieverify() library routines.

%%% copyright-cmetz-96
This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
The Inner Net License Version 3 applies to this software.
You should have received a copy of the license with this software. If
you didn't get a copy, you may request one from <license@inner.net>.

        History:

	Modified by cmetz for OPIE 2.3. Send debug info to syslog.
        Created by cmetz for OPIE 2.2.
*/
#include "opie_cfg.h"
#include <stdio.h>
#if DEBUG
#include <syslog.h>
#endif /* DEBUG */
#include "opie.h"

int main FUNCTION((argc, argv), int argc AND char *argv[])
{
	struct opie opie;
	char *principal;
	char buffer[1024];
        char challenge[OPIE_CHALLENGE_MAX+1];
        char response[OPIE_RESPONSE_MAX+1];
	int result;

	if (argc <= 1) {
		fputs("Principal: ", stderr);
                if (!opiereadpass(buffer, sizeof(buffer)-1, 1))
                  fprintf(stderr, "Error reading principal!");
		principal = buffer;
	} else {
		principal = argv[1];
	}
#if DEBUG
       	syslog(LOG_DEBUG, "Principal is +%s+", principal);
#endif /* DEBUG */

	switch (result = opiechallenge(&opie, principal, challenge)) {
		case -1:
			fputs("System error!\n", stderr);
			exit(1);
		case 0:
			break;
		case 1:
			fputs("User not found!\n", stderr);
			exit(1);
		case 2:
			fputs("System error!\n", stderr);
			exit(1);
		default:
			fprintf(stderr, "Unknown error %d!\n", result);
			exit(1);
	};

	fputs(challenge, stdout);
        fputc('\n', stdout);
        fflush(stdout);
	fputs("Response: ", stderr);
        if (!opiereadpass(response, OPIE_RESPONSE_MAX, 1)) {
          fputs("Error reading response!\n", stderr);
          exit(1);
        };

	switch (result = opieverify(&opie, response)) {
		case -1:
			fputs("System error!\n", stderr);
			exit(1);
		case 0:
			fputs("User verified.\n", stderr);
			exit(0);
		case 1:
			fputs("Verify failed!\n", stderr);
			exit(1);
		default:
			fprintf(stderr, "Unknown error %d!\n", result);
			exit(1);
	}
}
OpenPOWER on IntegriCloud