xref: /freebsd/usr.sbin/ppp/chap.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
165309e5cSBrian Somers /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
465309e5cSBrian Somers  * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
565309e5cSBrian Somers  *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
665309e5cSBrian Somers  *                           Internet Initiative Japan, Inc (IIJ)
765309e5cSBrian Somers  * All rights reserved.
8af57ed9fSAtsushi Murai  *
965309e5cSBrian Somers  * Redistribution and use in source and binary forms, with or without
1065309e5cSBrian Somers  * modification, are permitted provided that the following conditions
1165309e5cSBrian Somers  * are met:
1265309e5cSBrian Somers  * 1. Redistributions of source code must retain the above copyright
1365309e5cSBrian Somers  *    notice, this list of conditions and the following disclaimer.
1465309e5cSBrian Somers  * 2. Redistributions in binary form must reproduce the above copyright
1565309e5cSBrian Somers  *    notice, this list of conditions and the following disclaimer in the
1665309e5cSBrian Somers  *    documentation and/or other materials provided with the distribution.
17af57ed9fSAtsushi Murai  *
1865309e5cSBrian Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1965309e5cSBrian Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2065309e5cSBrian Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2165309e5cSBrian Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2265309e5cSBrian Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2365309e5cSBrian Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2465309e5cSBrian Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2565309e5cSBrian Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2665309e5cSBrian Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2765309e5cSBrian Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2865309e5cSBrian Somers  * SUCH DAMAGE.
29af57ed9fSAtsushi Murai  */
30af57ed9fSAtsushi Murai 
312764b86aSBrian Somers struct mbuf;
3263b73463SBrian Somers struct physical;
3363b73463SBrian Somers 
34af57ed9fSAtsushi Murai #define	CHAP_CHALLENGE	1
35af57ed9fSAtsushi Murai #define	CHAP_RESPONSE	2
36af57ed9fSAtsushi Murai #define	CHAP_SUCCESS	3
37af57ed9fSAtsushi Murai #define	CHAP_FAILURE	4
3875240ed1SBrian Somers 
39e2ebb036SBrian Somers struct chap {
40f013f33eSBrian Somers   struct fdescriptor desc;
4158330d7bSBrian Somers   struct {
4258330d7bSBrian Somers     pid_t pid;
4358330d7bSBrian Somers     int fd;
4458330d7bSBrian Somers     struct {
4558330d7bSBrian Somers       char ptr[AUTHLEN * 2 + 3];	/* Allow for \r\n at the end (- NUL) */
4658330d7bSBrian Somers       int len;
4758330d7bSBrian Somers     } buf;
4858330d7bSBrian Somers   } child;
49e2ebb036SBrian Somers   struct authinfo auth;
50a38cc901SBrian Somers   struct {
51a38cc901SBrian Somers     u_char local[CHAPCHALLENGELEN + AUTHLEN];	/* I invented this one */
52a38cc901SBrian Somers     u_char peer[CHAPCHALLENGELEN + AUTHLEN];	/* Peer gave us this one */
53a38cc901SBrian Somers   } challenge;
54fb11a9c2SBrian Somers #ifndef NODES
555e315498SBrian Somers   unsigned NTRespSent : 1;		/* Our last response */
565e315498SBrian Somers   int peertries;
57a8d604abSBrian Somers   u_char authresponse[CHAPAUTHRESPONSELEN];	/* CHAP 81 response */
58f522bee0SBrian Somers #endif
59e2ebb036SBrian Somers };
606eaa6ac5SBrian Somers 
6158330d7bSBrian Somers #define descriptor2chap(d) \
6258330d7bSBrian Somers   ((d)->type == CHAP_DESCRIPTOR ? (struct chap *)(d) : NULL)
63a8d604abSBrian Somers #define auth2chap(a) \
6416e790daSJohn Birrell   ((struct chap *)((char *)a - (uintptr_t)&((struct chap *)0)->auth))
651ae349f5Scvs2svn 
66250be50bSBrian Somers struct MSCHAPv2_resp {		/* rfc2759 */
67250be50bSBrian Somers   char PeerChallenge[16];
68250be50bSBrian Somers   char Reserved[8];
69250be50bSBrian Somers   char NTResponse[24];
70250be50bSBrian Somers   char Flags;
71250be50bSBrian Somers };
72250be50bSBrian Somers 
73f0cdd9c0SBrian Somers extern void chap_Init(struct chap *, struct physical *);
7458330d7bSBrian Somers extern void chap_ReInit(struct chap *);
755d9e6103SBrian Somers extern struct mbuf *chap_Input(struct bundle *, struct link *, struct mbuf *);
76