Merge branch 'vendor/MDOCML'
[dragonfly.git] / contrib / opie / opieserv.c
CommitLineData
984263bc
MD
1/* opieserv.c: Sample OTP server based on the opiechallenge() and
2 opieverify() library routines.
3
4%%% copyright-cmetz-96
5This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
6The Inner Net License Version 3 applies to this software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10 History:
11
12 Modified by cmetz for OPIE 2.3. Send debug info to syslog.
13 Created by cmetz for OPIE 2.2.
14*/
15#include "opie_cfg.h"
16#include <stdio.h>
17#if DEBUG
18#include <syslog.h>
19#endif /* DEBUG */
20#include "opie.h"
21
22int main FUNCTION((argc, argv), int argc AND char *argv[])
23{
24 struct opie opie;
25 char *principal;
26 char buffer[1024];
27 char challenge[OPIE_CHALLENGE_MAX+1];
28 char response[OPIE_RESPONSE_MAX+1];
29 int result;
30
31 if (argc <= 1) {
32 fputs("Principal: ", stderr);
33 if (!opiereadpass(buffer, sizeof(buffer)-1, 1))
34 fprintf(stderr, "Error reading principal!");
35 principal = buffer;
36 } else {
37 principal = argv[1];
38 }
39#if DEBUG
40 syslog(LOG_DEBUG, "Principal is +%s+", principal);
41#endif /* DEBUG */
42
43 switch (result = opiechallenge(&opie, principal, challenge)) {
44 case -1:
45 fputs("System error!\n", stderr);
46 exit(1);
47 case 0:
48 break;
49 case 1:
50 fputs("User not found!\n", stderr);
51 exit(1);
52 case 2:
53 fputs("System error!\n", stderr);
54 exit(1);
55 default:
56 fprintf(stderr, "Unknown error %d!\n", result);
57 exit(1);
58 };
59
60 fputs(challenge, stdout);
61 fputc('\n', stdout);
62 fflush(stdout);
63 fputs("Response: ", stderr);
64 if (!opiereadpass(response, OPIE_RESPONSE_MAX, 1)) {
65 fputs("Error reading response!\n", stderr);
66 exit(1);
67 };
68
69 switch (result = opieverify(&opie, response)) {
70 case -1:
71 fputs("System error!\n", stderr);
72 exit(1);
73 case 0:
74 fputs("User verified.\n", stderr);
75 exit(0);
76 case 1:
77 fputs("Verify failed!\n", stderr);
78 exit(1);
79 default:
80 fprintf(stderr, "Unknown error %d!\n", result);
81 exit(1);
82 }
83}