Annotation of embedaddon/libpdel/ppp/ppp_auth.c, revision 1.1.1.1
1.1 misho 1:
2: /*
3: * Copyright (c) 2001-2002 Packet Design, LLC.
4: * All rights reserved.
5: *
6: * Subject to the following obligations and disclaimer of warranty,
7: * use and redistribution of this software, in source or object code
8: * forms, with or without modifications are expressly permitted by
9: * Packet Design; provided, however, that:
10: *
11: * (i) Any and all reproductions of the source or object code
12: * must include the copyright notice above and the following
13: * disclaimer of warranties; and
14: * (ii) No rights are granted, in any manner or form, to use
15: * Packet Design trademarks, including the mark "PACKET DESIGN"
16: * on advertising, endorsements, or otherwise except as such
17: * appears in the above copyright notice or in the software.
18: *
19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
36: * THE POSSIBILITY OF SUCH DAMAGE.
37: *
38: * Author: Archie Cobbs <archie@freebsd.org>
39: */
40:
41: #include "ppp/ppp_defs.h"
42: #include "ppp/ppp_log.h"
43: #include "ppp/ppp_fsm_option.h"
44: #include "ppp/ppp_auth.h"
45: #include "ppp/ppp_auth_pap.h"
46: #include "ppp/ppp_auth_chap.h"
47:
48: /***********************************************************************
49: AUTH TYPE FUNCTIONS
50: ***********************************************************************/
51:
52: /* Types of CHAP */
53: #define CHAP_PROTO_MD5 0x05
54: #define CHAP_PROTO_MSV1 0x80
55: #define CHAP_PROTO_MSV2 0x81
56:
57: #define PRBYT(x) ((PPP_PROTO_ ## x) >> 8), ((PPP_PROTO_ ## x) & 0xff)
58:
59: /* Keep consistent with "ppp_auth.h" */
60: static const struct ppp_auth_type ppp_auth_types[PPP_AUTH_MAX] = {
61: {
62: "None",
63: PPP_AUTH_NONE,
64: NULL,
65: NULL,
66: 0
67: },
68: {
69: "PAP",
70: PPP_AUTH_PAP,
71: ppp_auth_pap_start,
72: ppp_auth_pap_cancel,
73: ppp_auth_pap_input,
74: 2, { PRBYT(PAP) }
75: },
76: {
77: "CHAP-MSv1",
78: PPP_AUTH_CHAP_MSV1,
79: ppp_auth_chap_start,
80: ppp_auth_chap_cancel,
81: ppp_auth_chap_input,
82: 3, { PRBYT(CHAP), CHAP_PROTO_MSV1 }
83: },
84: {
85: "CHAP-MSv2",
86: PPP_AUTH_CHAP_MSV2,
87: ppp_auth_chap_start,
88: ppp_auth_chap_cancel,
89: ppp_auth_chap_input,
90: 3, { PRBYT(CHAP), CHAP_PROTO_MSV2 }
91: },
92: {
93: "CHAP-MD5",
94: PPP_AUTH_CHAP_MD5,
95: ppp_auth_chap_start,
96: ppp_auth_chap_cancel,
97: ppp_auth_chap_input,
98: 3, { PRBYT(CHAP), CHAP_PROTO_MD5 }
99: },
100: };
101:
102: /*
103: * Find auth type descriptor by LCP option.
104: */
105: const struct ppp_auth_type *
106: ppp_auth_by_option(const struct ppp_fsm_option *opt)
107: {
108: int i;
109:
110: for (i = 1; i < PPP_AUTH_MAX; i++) {
111: const struct ppp_auth_type *const auth = &ppp_auth_types[i];
112:
113: if (auth->index != PPP_AUTH_NONE /* saftey first! */
114: && opt->len == auth->len
115: && memcmp(opt->data, auth->data, auth->len) == 0)
116: return (auth);
117: }
118: return (NULL);
119: }
120:
121: /*
122: * Find auth type descriptor by index.
123: */
124: const struct ppp_auth_type *
125: ppp_auth_by_index(enum ppp_auth_index index)
126: {
127: if (index <= 0 || index > PPP_AUTH_MAX) {
128: errno = EINVAL;
129: return (NULL);
130: }
131: return (&ppp_auth_types[index]);
132: }
133:
134: /*
135: * Print out an auth type option.
136: */
137: void
138: ppp_auth_print(const struct ppp_fsm_optdesc *desc,
139: const struct ppp_fsm_option *opt, char *buf, size_t bmax)
140: {
141: const struct ppp_auth_type *const auth = ppp_auth_by_option(opt);
142:
143: if (auth != NULL) {
144: snprintf(buf, bmax, "%s", auth->name);
145: return;
146: }
147: if (opt->len < 2) {
148: snprintf(buf, bmax, "<truncated>");
149: return;
150: }
151: snprintf(buf, bmax, "?0x%02x%02x", opt->data[0], opt->data[1]);
152: }
153:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>