8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / pppd / mschap_test.c
blob3202348a328549bae667384e9c769d2ba6de98e1
1 /*
2 * Test MS-CHAPv1 library code.
4 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
7 * Originally from the README.MSCHAP80 file written by:
8 * Eric Rosenquist rosenqui@strataware.com
9 * (updated by Paul Mackerras)
10 * (updated by Al Longyear)
11 * (updated by Farrell Woods)
14 #include <stdio.h>
16 #include "pppd.h"
17 #include "chap.h"
18 #include "chap_ms.h"
20 #pragma ident "%Z%%M% %I% %E% SMI"
22 static void
23 show_response(chap_state *cstate, const char *str)
25 int i;
27 printf("%s -- %d bytes:", str, cstate->resp_length);
29 for (i = 0; i < cstate->resp_length; i++) {
30 if (i % 8 == 0)
31 putchar('\n');
32 printf("%02X ", (unsigned int)cstate->response[i]);
35 putchar('\n');
38 int main(argc, argv)
39 int argc;
40 char *argv[];
42 u_char challenge[8];
43 int challengeInt[sizeof(challenge)];
44 chap_state cstate;
45 int i;
47 if (argc != 3) {
48 fprintf(stderr, "Usage: %s <16-hexchar challenge> <password>\n",
49 argv[0]); exit(1);
52 sscanf(argv[1], "%2x%2x%2x%2x%2x%2x%2x%2x",
53 challengeInt + 0, challengeInt + 1, challengeInt + 2,
54 challengeInt + 3, challengeInt + 4, challengeInt + 5,
55 challengeInt + 6, challengeInt + 7);
57 for (i = 0; i < sizeof(challenge); i++)
58 challenge[i] = (u_char)challengeInt[i];
60 BZERO(&cstate, sizeof(cstate));
61 ChapMS(&cstate, challenge, sizeof(challenge), argv[2], strlen(argv[2]));
62 #ifdef MSLANMAN
63 show_response(&cstate, "MS-CHAPv1 with LAN Manager");
64 #else
65 show_response(&cstate, "MS-CHAPv1");
66 #endif
68 cstate.chal_len = sizeof(challenge);
69 BCOPY(challenge, cstate.challenge, cstate.chal_len);
70 if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
71 argv[2], strlen(argv[2])))
72 printf("Cannot validate own MS-CHAPv1 response.\n");
74 #ifdef MSLANMAN
75 cstate.response[MS_CHAP_RESPONSE_LEN-1] = '\0';
76 if (!ChapMSValidate(&cstate, cstate.response, cstate.resp_length,
77 argv[2], strlen(argv[2])))
78 printf("Cannot validate own LAN Manager response.\n");
79 #endif
81 #ifdef CHAPMSV2
82 cstate.resp_name = "joe user";
83 ChapMSv2(&cstate, cstate.challenge, 16, argv[2], strlen(argv[2]));
84 show_response(&cstate, "MS-CHAPv2");
85 if (!ChapMSv2Validate(&cstate, cstate.resp_name, cstate.response,
86 cstate.resp_length, argv[2], strlen(argv[2])))
87 printf("Cannot validate own MS-CHAPv2 response.\n");
88 #endif
90 return (0);