[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
[331] | 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
[270] | 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
| 8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
| 9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
| 10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
| 11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
| 12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 14 | * スコード中に含まれていること.
|
---|
| 15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 18 | * の無保証規定を掲載すること.
|
---|
| 19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 20 | * 用できない形で再配布する場合には,次の条件を満たすこと.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | *
|
---|
| 26 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 27 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
| 28 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
| 29 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
| 30 | *
|
---|
| 31 | * @(#) $Id$
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * auth.c - PPP authentication and phase control.
|
---|
| 36 | *
|
---|
| 37 | * Copyright (c) 1993 The Australian National University.
|
---|
| 38 | * All rights reserved.
|
---|
| 39 | *
|
---|
| 40 | * Redistribution and use in source and binary forms are permitted
|
---|
| 41 | * provided that the above copyright notice and this paragraph are
|
---|
| 42 | * duplicated in all such forms and that any documentation,
|
---|
| 43 | * advertising materials, and other materials related to such
|
---|
| 44 | * distribution and use acknowledge that the software was developed
|
---|
| 45 | * by the Australian National University. The name of the University
|
---|
| 46 | * may not be used to endorse or promote products derived from this
|
---|
| 47 | * software without specific prior written permission.
|
---|
| 48 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
| 49 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
| 50 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 51 | *
|
---|
| 52 | * Copyright (c) 1989 Carnegie Mellon University.
|
---|
| 53 | * All rights reserved.
|
---|
| 54 | *
|
---|
| 55 | * Redistribution and use in source and binary forms are permitted
|
---|
| 56 | * provided that the above copyright notice and this paragraph are
|
---|
| 57 | * duplicated in all such forms and that any documentation,
|
---|
| 58 | * advertising materials, and other materials related to such
|
---|
| 59 | * distribution and use acknowledge that the software was developed
|
---|
| 60 | * by Carnegie Mellon University. The name of the
|
---|
| 61 | * University may not be used to endorse or promote products derived
|
---|
| 62 | * from this software without specific prior written permission.
|
---|
| 63 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
| 64 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
| 65 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 | /*
|
---|
| 69 | * PPP Secret Key Module
|
---|
| 70 | *
|
---|
| 71 | * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
---|
| 72 | *
|
---|
| 73 | * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
|
---|
| 74 | *
|
---|
| 75 | * Redistribution and use in source and binary forms are permitted
|
---|
| 76 | * provided that the above copyright notice and this paragraph are
|
---|
| 77 | * duplicated in all such forms and that any documentation,
|
---|
| 78 | * advertising materials, and other materials related to such
|
---|
| 79 | * distribution and use acknowledge that the software was developed
|
---|
| 80 | * by the Internet Initiative Japan, Inc. The name of the
|
---|
| 81 | * IIJ may not be used to endorse or promote products derived
|
---|
| 82 | * from this software without specific prior written permission.
|
---|
| 83 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
| 84 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
| 85 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 86 | *
|
---|
| 87 | * $FreeBSD: src/usr.sbin/ppp/auth.c,v 1.50 1999/12/27 11:43:30 brian Exp $
|
---|
| 88 | *
|
---|
| 89 | * TODO:
|
---|
| 90 | * o Implement check against with registered IP addresses.
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | #include <s_services.h>
|
---|
| 94 | #include <t_services.h>
|
---|
| 95 |
|
---|
| 96 | #include <tinet_defs.h>
|
---|
| 97 | #include <tinet_config.h>
|
---|
| 98 |
|
---|
| 99 | #include <net/if.h>
|
---|
| 100 | #include <net/if_ppp.h>
|
---|
| 101 | #include <net/net.h>
|
---|
[331] | 102 | #include <net/net_endian.h>
|
---|
[270] | 103 | #include <net/net_buf.h>
|
---|
| 104 | #include <net/ppp.h>
|
---|
| 105 | #include <net/ppp_var.h>
|
---|
| 106 | #include <net/ppp_auth.h>
|
---|
| 107 | #include <net/ppp_fsm.h>
|
---|
| 108 | #include <net/ppp_lcp.h>
|
---|
| 109 | #include <net/ppp_upap.h>
|
---|
| 110 |
|
---|
| 111 | #ifdef SUPPORT_PPP
|
---|
| 112 |
|
---|
| 113 | /*
|
---|
| 114 | * 定数
|
---|
| 115 | */
|
---|
| 116 |
|
---|
| 117 | #define PAP_PEND_SERVER UINT_C(0x01)
|
---|
| 118 | #define PAP_PEND_CLIENT UINT_C(0x02)
|
---|
| 119 | #define CHAP_PEND_SERVER UINT_C(0x04)
|
---|
| 120 | #define CHAP_PEND_CLIENT UINT_C(0x08)
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * network_phase -- コネクション確立
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | void
|
---|
| 127 | network_phase (void)
|
---|
| 128 | {
|
---|
| 129 | int_t num, ix;
|
---|
| 130 | T_PPP_PROTENT *proto;
|
---|
| 131 |
|
---|
| 132 | ppp_phase = PPP_PHASE_NETWORK;
|
---|
| 133 |
|
---|
| 134 | /* 上位プロトコルをオープンする */
|
---|
| 135 | num = 0;
|
---|
| 136 | for (ix = 0; (proto = protocols[ix]) != NULL; ix ++)
|
---|
| 137 | #if 0 /* 保留、削除禁止 */
|
---|
| 138 | if (proto->proto < 0xc000 && proto->open != NULL) {
|
---|
| 139 | #else /* of #if 0 */
|
---|
| 140 | if (proto->open != NULL) {
|
---|
| 141 | #endif /* of #if 0 */
|
---|
| 142 | (*proto->open)();
|
---|
| 143 | if (proto->proto != PPP_CCP)
|
---|
| 144 | num ++;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | if (num == 0)
|
---|
| 148 | /* 上位プロトコルがない */
|
---|
| 149 | lcp_close();
|
---|
| 150 | else
|
---|
| 151 | syslog(LOG_NOTICE, "[PPP] up.");
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /*
|
---|
| 155 | * link_required -- リンクを開設する。
|
---|
| 156 | */
|
---|
| 157 |
|
---|
| 158 | void
|
---|
| 159 | link_required (void)
|
---|
| 160 | {
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | * link_terminated -- ログアウトして、リンクを切断する。
|
---|
| 165 | */
|
---|
| 166 |
|
---|
| 167 | void
|
---|
| 168 | link_terminated (void)
|
---|
| 169 | {
|
---|
| 170 | ppp_phase = PPP_PHASE_DEAD;
|
---|
| 171 | ppp_open_mode = PPP_OPEN_PASSIVE;
|
---|
| 172 | syslog(LOG_NOTICE, "[PPP] down.");
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /*
|
---|
| 176 | * link_down -- リンクを解放する。
|
---|
| 177 | */
|
---|
| 178 |
|
---|
| 179 | void
|
---|
| 180 | link_down (void)
|
---|
| 181 | {
|
---|
| 182 | int_t ix;
|
---|
| 183 | T_PPP_PROTENT *proto;
|
---|
| 184 |
|
---|
| 185 | /* 上位プロトコルを解放する */
|
---|
| 186 | for (ix = 0; (proto = protocols[ix]) != NULL; ix ++) {
|
---|
| 187 | if (proto->proto != PPP_LCP && proto->lowerdown != NULL)
|
---|
| 188 | (*proto->lowerdown)();
|
---|
| 189 | if (proto->proto < 0xc000 && proto->close != NULL)
|
---|
| 190 | (*proto->close)();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | if (ppp_phase != PPP_PHASE_DEAD)
|
---|
| 194 | ppp_phase = PPP_PHASE_TERMINATE;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | /*
|
---|
| 198 | * link_established -- リンクの接続が確立した。
|
---|
| 199 | */
|
---|
| 200 |
|
---|
| 201 | void
|
---|
| 202 | link_established (void)
|
---|
| 203 | {
|
---|
| 204 | int_t ix;
|
---|
| 205 | T_PPP_PROTENT *proto;
|
---|
| 206 |
|
---|
| 207 | #if defined(LCP_CFG_CHAP) || defined(LCP_CFG_PAP)
|
---|
| 208 |
|
---|
| 209 | int auth;
|
---|
| 210 |
|
---|
| 211 | #endif /* of #if defined(LCP_CFG_CHAP) || defined(LCP_CFG_PAP) */
|
---|
| 212 |
|
---|
| 213 | /* 上位プロトコルを起動する */
|
---|
| 214 | for (ix = 0; (proto = protocols[ix]) != NULL; ix ++)
|
---|
| 215 | if (proto->lowerup != NULL)
|
---|
| 216 | (*proto->lowerup)();
|
---|
| 217 |
|
---|
| 218 | /* 認証オプションを確認する。【未実装】*/
|
---|
| 219 |
|
---|
| 220 | ppp_phase = PPP_PHASE_AUTHENTICATE;
|
---|
| 221 |
|
---|
| 222 | #if defined(LCP_CFG_CHAP) || defined(LCP_CFG_PAP)
|
---|
| 223 |
|
---|
| 224 | auth = 0;
|
---|
| 225 |
|
---|
| 226 | #ifdef AUTH_CFG_SERVER
|
---|
| 227 |
|
---|
| 228 | #if defined(LCP_CFG_CHAP)
|
---|
| 229 |
|
---|
| 230 | if (lcp_local_ack_cfg.options & LCP_CFG_CHAP) {
|
---|
| 231 | chap_auth_server();
|
---|
| 232 | auth |= CHAP_PEND_SERVER;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | #endif /* of #if defined(LCP_CFG_CHAP) */
|
---|
| 236 |
|
---|
| 237 | #if defined(LCP_CFG_PAP)
|
---|
| 238 |
|
---|
| 239 | if (lcp_local_ack_cfg.options & LCP_CFG_PAP) {
|
---|
| 240 | upap_auth_server();
|
---|
| 241 | auth |= PAP_PEND_SERVER;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | #endif /* of #if defined(LCP_CFG_PAP) */
|
---|
| 245 |
|
---|
| 246 | #endif /* of #ifdef AUTH_CFG_SERVER */
|
---|
| 247 |
|
---|
| 248 | #ifdef AUTH_CFG_CLIENT
|
---|
| 249 |
|
---|
| 250 | #if defined(LCP_CFG_PAP)
|
---|
| 251 |
|
---|
| 252 | if (lcp_remote_ack_cfg.options & LCP_CFG_PAP) {
|
---|
| 253 | upap_auth_client();
|
---|
| 254 | auth |= PAP_PEND_CLIENT;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | #endif /* of #if defined(LCP_CFG_PAP) */
|
---|
| 258 |
|
---|
| 259 | #endif /* of #ifdef AUTH_CFG_CLIENT */
|
---|
| 260 |
|
---|
| 261 | if (auth == 0)
|
---|
| 262 | network_phase();
|
---|
| 263 |
|
---|
| 264 | #else /* of #if defined(LCP_CFG_CHAP) || defined(LCP_CFG_PAP) */
|
---|
| 265 |
|
---|
| 266 | network_phase();
|
---|
| 267 |
|
---|
| 268 | #endif /* of #if defined(LCP_CFG_CHAP) || defined(LCP_CFG_PAP) */
|
---|
| 269 |
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | /*
|
---|
| 273 | * auth_reset -- 認証オプションを再確認する。
|
---|
| 274 | */
|
---|
| 275 |
|
---|
| 276 | void
|
---|
| 277 | auth_reset (void)
|
---|
| 278 | {
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | #endif /* fo #ifdef SUPPORT_PPP */
|
---|