annotate packages/net/ppp/current/src/auth.c @ 1777:c16341b1bac6 default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Mon, 12 Oct 2009 02:26:09 +0100
parents 5629b7c30ed2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
1 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
2 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
3 // src/auth.c
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
4 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
5 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
6 //####ECOSGPLCOPYRIGHTBEGIN####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
7 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
8 // This file is part of eCos, the Embedded Configurable Operating System.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
9 // Portions created by Nick Garnett are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
10 // Copyright (C) 2003 eCosCentric Ltd.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
11 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
12 // eCos is free software; you can redistribute it and/or modify it under
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
13 // the terms of the GNU General Public License as published by the Free
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
14 // Software Foundation; either version 2 or (at your option) any later version.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
15 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
19 // for more details.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
20 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
21 // You should have received a copy of the GNU General Public License along
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
22 // with eCos; if not, write to the Free Software Foundation, Inc.,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
24 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
25 // As a special exception, if other files instantiate templates or use macros
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
26 // or inline functions from this file, or you compile this file and link it
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
27 // with other works to produce a work based on this file, this file does not
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
28 // by itself cause the resulting work to be covered by the GNU General Public
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
29 // License. However the source code for this file must still be made available
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
30 // in accordance with section (3) of the GNU General Public License.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
31 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
32 // This exception does not invalidate any other reasons why a work based on
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
33 // this file might be covered by the GNU General Public License.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
34 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
35 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
36 //####ECOSGPLCOPYRIGHTEND####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
37 //####BSDCOPYRIGHTBEGIN####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
38 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
39 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
40 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
41 // Portions of this software may have been derived from OpenBSD,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
42 // FreeBSD or other sources, and are covered by the appropriate
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
43 // copyright disclaimers included herein.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
44 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
45 // -------------------------------------------
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
46 //
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
47 //####BSDCOPYRIGHTEND####
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
48 //==========================================================================
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
49
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
50 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
51 * auth.c - PPP authentication and phase control.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
52 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
53 * Copyright (c) 1993 The Australian National University.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
54 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
55 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
56 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
57 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
58 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
59 * advertising materials, and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
60 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
61 * by the Australian National University. The name of the University
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
62 * may not be used to endorse or promote products derived from this
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
63 * software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
64 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
65 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
66 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
67 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
68 * Copyright (c) 1989 Carnegie Mellon University.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
69 * All rights reserved.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
70 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
71 * Redistribution and use in source and binary forms are permitted
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
72 * provided that the above copyright notice and this paragraph are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
73 * duplicated in all such forms and that any documentation,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
74 * advertising materials, and other materials related to such
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
75 * distribution and use acknowledge that the software was developed
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
76 * by Carnegie Mellon University. The name of the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
77 * University may not be used to endorse or promote products derived
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
78 * from this software without specific prior written permission.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
79 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
80 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
81 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
82 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
83
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
84 #ifndef lint
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
85 //static char rcsid[] = "$FreeBSD: src/usr.sbin/pppd/auth.c,v 1.24.2.1 2000/12/11 01:03:37 obrien Exp $";
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
86 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
87
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
88 #include <stdio.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
89 #include <stddef.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
90 #include <stdlib.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
91 #include <unistd.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
92 #include <cyg/ppp/syslog.h>
1628
2e1811d4f88c * src/auth.c: Don't use non-eCos <paths.h>
jlarmour
parents: 1586
diff changeset
93 #ifndef __ECOS
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
94 #include <paths.h>
1628
2e1811d4f88c * src/auth.c: Don't use non-eCos <paths.h>
jlarmour
parents: 1586
diff changeset
95 #endif
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
96 //#include <pwd.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
97 #include <string.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
98 #include <sys/types.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
99 #include <sys/stat.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
100 #include <sys/socket.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
101 //#include <utmp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
102 #include <fcntl.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
103 #if defined(_PATH_LASTLOG) && defined(_linux_)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
104 #include <lastlog.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
105 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
106
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
107 #include <netdb.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
108 #include <netinet/in.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
109 #include <arpa/inet.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
110 #include <sys/time.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
111 //#include <utmp.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
112
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
113 #ifdef USE_PAM
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
114 #include <security/pam_appl.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
115 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
116
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
117 #ifdef HAS_SHADOW
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
118 #include <shadow.h>
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
119 #ifndef PW_PPP
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
120 #define PW_PPP PW_LOGIN
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
121 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
122 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
123
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
124 #include "cyg/ppp/pppd.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
125 #include "cyg/ppp/fsm.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
126 #include "cyg/ppp/lcp.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
127 #include "cyg/ppp/ipcp.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
128 #include "cyg/ppp/upap.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
129 #include "cyg/ppp/chap.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
130 #ifdef CBCP_SUPPORT
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
131 #include "cyg/ppp/cbcp.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
132 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
133 //#include "cyg/ppp/pathnames.h"
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
134
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
135 /* Used for storing a sequence of words. Usually malloced. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
136 struct wordlist {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
137 struct wordlist *next;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
138 char word[1];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
139 };
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
140
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
141 /* Bits in scan_authfile return value */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
142 #define NONWILD_SERVER 1
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
143 #define NONWILD_CLIENT 2
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
144
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
145 #define ISWILD(word) (word[0] == '*' && word[1] == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
146
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
147 #define FALSE 0
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
148 #define TRUE 1
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
149
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
150 /* The name by which the peer authenticated itself to us. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
151 char peer_authname[MAXNAMELEN];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
152
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
153 /* Records which authentication operations haven't completed yet. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
154 static int auth_pending[NUM_PPP];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
155
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
156 /* Set if we have successfully called plogin() */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
157 //static int logged_in;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
158
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
159 /* Set if not wild or blank */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
160 //static int non_wildclient;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
161
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
162 /* Set if we have run the /etc/ppp/auth-up script. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
163 //static int did_authup;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
164
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
165 /* List of addresses which the peer may use. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
166 static struct wordlist *addresses[NUM_PPP];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
167
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
168 /* Number of network protocols which we have opened. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
169 static int num_np_open;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
170
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
171 /* Number of network protocols which have come up. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
172 static int num_np_up;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
173
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
174 /* Set if we got the contents of passwd[] from the pap-secrets file. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
175 static int passwd_from_file;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
176
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
177 /* Bits in auth_pending[] */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
178 #define PAP_WITHPEER 1
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
179 #define PAP_PEER 2
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
180 #define CHAP_WITHPEER 4
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
181 #define CHAP_PEER 8
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
182
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
183 extern char *crypt __P((const char *, const char *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
184
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
185 /* Prototypes for procedures local to this file. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
186
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
187 static void network_phase __P((int));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
188 static void check_idle __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
189 static void connect_time_expired __P((void *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
190 static int null_login __P((int));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
191 static int get_pap_passwd __P((char *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
192 static int have_pap_secret __P((void));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
193 static int have_chap_secret __P((char *, char *, u_int32_t));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
194 static int ip_addr_check __P((u_int32_t, struct wordlist *));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
195
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
196 static void auth_set_ip_addr __P((int));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
197
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
198 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
199 * An Open on LCP has requested a change from Dead to Establish phase.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
200 * Do what's necessary to bring the physical layer up.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
201 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
202 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
203 link_required(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
204 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
205 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
206 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
207
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
208 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
209 * LCP has terminated the link; go to the Dead phase and take the
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
210 * physical layer down.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
211 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
212 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
213 link_terminated(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
214 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
215 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
216 extern time_t etime, stime;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
217 extern int minutes;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
218
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
219 db_printf("%s()\n",__PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
220 if (phase == PHASE_DEAD)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
221 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
222 phase = PHASE_DEAD;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
223 etime = time((time_t *) NULL);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
224 minutes = (etime-stime)/60;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
225 syslog(LOG_NOTICE, "Connection terminated, connected for %d minutes\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
226 minutes > 1 ? minutes : 1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
227 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
228
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
229 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
230 * LCP has gone down; it will either die or try to re-establish.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
231 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
232 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
233 link_down(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
234 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
235 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
236 int i;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
237 struct protent *protp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
238
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
239 db_printf("%s()\n",__PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
240 for (i = 0; (protp = protocols[i]) != NULL; ++i) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
241 if (!protp->enabled_flag)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
242 continue;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
243 if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
244 (*protp->lowerdown)(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
245 if (protp->protocol < 0xC000 && protp->close != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
246 (*protp->close)(unit, "LCP down");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
247 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
248 num_np_open = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
249 num_np_up = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
250 if (phase != PHASE_DEAD)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
251 phase = PHASE_TERMINATE;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
252 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
253
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
254 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
255 * The link is established.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
256 * Proceed to the Dead, Authenticate or Network phase as appropriate.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
257 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
258 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
259 link_established(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
260 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
261 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
262 int auth;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
263 lcp_options *wo = &lcp_wantoptions[unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
264 lcp_options *go = &lcp_gotoptions[unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
265 lcp_options *ho = &lcp_hisoptions[unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
266 int i;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
267 struct protent *protp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
268
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
269 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
270 * Tell higher-level protocols that LCP is up.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
271 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
272 for (i = 0; (protp = protocols[i]) != NULL; ++i)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
273 if (protp->protocol != PPP_LCP && protp->enabled_flag
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
274 && protp->lowerup != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
275 (*protp->lowerup)(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
276
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
277 if (auth_required && !(go->neg_chap || go->neg_upap)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
278 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
279 * We wanted the peer to authenticate itself, and it refused:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
280 * treat it as though it authenticated with PAP using a username
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
281 * of "" and a password of "". If that's not OK, boot it out.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
282 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
283 if (!wo->neg_upap || !null_login(unit)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
284 syslog(LOG_WARNING, "peer refused to authenticate");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
285 lcp_close(unit, "peer refused to authenticate");
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
286 cyg_ppp_stats.auth_failures++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
287 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
288 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
289 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
290
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
291 phase = PHASE_AUTHENTICATE;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
292 auth = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
293 if (go->neg_chap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
294 ChapAuthPeer(unit, our_name, go->chap_mdtype);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
295 auth |= CHAP_PEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
296 } else if (go->neg_upap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
297 upap_authpeer(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
298 auth |= PAP_PEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
299 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
300 if (ho->neg_chap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
301 ChapAuthWithPeer(unit, user, ho->chap_mdtype);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
302 auth |= CHAP_WITHPEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
303 } else if (ho->neg_upap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
304 if (passwd[0] == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
305 passwd_from_file = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
306 if (!get_pap_passwd(passwd))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
307 syslog(LOG_ERR, "No secret found for PAP login");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
308 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
309 upap_authwithpeer(unit, user, passwd);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
310 auth |= PAP_WITHPEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
311 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
312 auth_pending[unit] = auth;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
313
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
314 if (!auth)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
315 network_phase(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
316 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
317
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
318 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
319 * Proceed to the network phase.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
320 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
321 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
322 network_phase(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
323 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
324 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
325 int i;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
326 struct protent *protp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
327
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
328 #ifdef CBCP_SUPPORT
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
329 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
330 * If we negotiated callback, do it now.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
331 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
332 if (go->neg_cbcp) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
333 phase = PHASE_CALLBACK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
334 (*cbcp_protent.open)(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
335 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
336 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
337 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
338
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
339 phase = PHASE_NETWORK;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
340 for (i = 0; (protp = protocols[i]) != NULL; ++i)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
341 if (protp->protocol < 0xC000 && protp->enabled_flag
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
342 && protp->open != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
343 (*protp->open)(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
344 if (protp->protocol != PPP_CCP)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
345 ++num_np_open;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
346 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
347
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
348 if (num_np_open == 0) {
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
349 /* nothing to do */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
350 lcp_close(0, "No network protocols running");
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
351 cyg_ppp_stats.no_proto++;
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
352 }
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
353 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
354
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
355 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
356 * The peer has failed to authenticate himself using `protocol'.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
357 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
358 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
359 auth_peer_fail(unit, protocol)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
360 int unit, protocol;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
361 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
362 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
363 * Authentication failure: take the link down
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
364 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
365 lcp_close(unit, "Authentication failed");
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
366 cyg_ppp_stats.auth_failures++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
367 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
368
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
369 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
370 * The peer has been successfully authenticated using `protocol'.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
371 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
372 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
373 auth_peer_success(unit, protocol, name, namelen)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
374 int unit, protocol;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
375 char *name;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
376 int namelen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
377 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
378 int bit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
379
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
380 switch (protocol) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
381 case PPP_CHAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
382 bit = CHAP_PEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
383 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
384 case PPP_PAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
385 bit = PAP_PEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
386 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
387 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
388 syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
389 protocol);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
390 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
391 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
392
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
393 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
394 * Save the authenticated name of the peer for later.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
395 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
396 if (namelen > sizeof(peer_authname) - 1)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
397 namelen = sizeof(peer_authname) - 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
398 BCOPY(name, peer_authname, namelen);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
399 peer_authname[namelen] = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
400
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
401 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
402 * If we have overridden addresses based on auth info
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
403 * then set that information now before continuing.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
404 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
405 auth_set_ip_addr(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
406
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
407 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
408 * If there is no more authentication still to be done,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
409 * proceed to the network (or callback) phase.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
410 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
411 if ((auth_pending[unit] &= ~bit) == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
412 network_phase(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
413 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
414
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
415 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
416 * We have failed to authenticate ourselves to the peer using `protocol'.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
417 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
418 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
419 auth_withpeer_fail(unit, protocol)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
420 int unit, protocol;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
421 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
422 if (passwd_from_file)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
423 BZERO(passwd, MAXSECRETLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
424 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
425 * We've failed to authenticate ourselves to our peer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
426 * He'll probably take the link down, and there's not much
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
427 * we can do except wait for that.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
428 */
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
429 cyg_ppp_stats.auth_failures++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
430 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
431
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
432 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
433 * We have successfully authenticated ourselves with the peer using `protocol'.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
434 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
435 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
436 auth_withpeer_success(unit, protocol)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
437 int unit, protocol;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
438 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
439 int bit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
440
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
441 switch (protocol) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
442 case PPP_CHAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
443 bit = CHAP_WITHPEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
444 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
445 case PPP_PAP:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
446 if (passwd_from_file)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
447 BZERO(passwd, MAXSECRETLEN);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
448 bit = PAP_WITHPEER;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
449 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
450 default:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
451 syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
452 protocol);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
453 bit = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
454 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
455
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
456 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
457 * If we have overridden addresses based on auth info
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
458 * then set that information now before continuing.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
459 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
460 auth_set_ip_addr(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
461
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
462 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
463 * If there is no more authentication still being done,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
464 * proceed to the network (or callback) phase.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
465 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
466 if ((auth_pending[unit] &= ~bit) == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
467 network_phase(unit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
468 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
469
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
470
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
471 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
472 * np_up - a network protocol has come up.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
473 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
474 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
475 np_up(unit, proto)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
476 int unit, proto;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
477 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
478 if (num_np_up == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
479 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
480 * At this point we consider that the link has come up successfully.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
481 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
482 need_holdoff = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
483
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
484 if (idle_time_limit > 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
485 TIMEOUT(check_idle, NULL, idle_time_limit);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
486
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
487 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
488 * Set a timeout to close the connection once the maximum
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
489 * connect time has expired.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
490 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
491 if (maxconnect > 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
492 TIMEOUT(connect_time_expired, 0, maxconnect);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
493
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
494 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
495 ++num_np_up;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
496 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
497
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
498 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
499 * np_down - a network protocol has gone down.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
500 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
501 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
502 np_down(unit, proto)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
503 int unit, proto;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
504 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
505 if (--num_np_up == 0 && idle_time_limit > 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
506 UNTIMEOUT(check_idle, NULL);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
507 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
508 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
509
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
510 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
511 * np_finished - a network protocol has finished using the link.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
512 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
513 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
514 np_finished(unit, proto)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
515 int unit, proto;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
516 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
517 if (--num_np_open <= 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
518 /* no further use for the link: shut up shop. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
519 lcp_close(0, "No network protocols running");
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
520 cyg_ppp_stats.no_proto++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
521 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
522 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
523
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
524 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
525 * check_idle - check whether the link has been idle for long
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
526 * enough that we can shut it down.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
527 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
528 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
529 check_idle(arg)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
530 void *arg;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
531 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
532 struct ppp_idle idle;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
533 time_t itime;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
534
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
535 if (!get_idle_time(0, &idle))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
536 return;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
537 itime = MIN(idle.xmit_idle, idle.recv_idle);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
538 if (itime >= idle_time_limit) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
539 /* link is idle: shut it down. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
540 syslog(LOG_INFO, "Terminating connection due to lack of activity.");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
541 lcp_close(0, "Link inactive");
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
542 cyg_ppp_stats.idle_timeout++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
543 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
544 TIMEOUT(check_idle, NULL, idle_time_limit - itime);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
545 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
546 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
547
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
548 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
549 * connect_time_expired - log a message and close the connection.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
550 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
551 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
552 connect_time_expired(arg)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
553 void *arg;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
554 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
555 syslog(LOG_INFO, "Connect time expired");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
556 lcp_close(0, "Connect time expired"); /* Close connection */
1694
5629b7c30ed2 Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents: 1628
diff changeset
557 cyg_ppp_stats.connect_time_expired++;
1586
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
558 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
559
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
560 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
561 * auth_check_options - called to check authentication options.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
562 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
563 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
564 auth_check_options()
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
565 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
566 lcp_options *wo = &lcp_wantoptions[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
567 int can_auth;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
568 ipcp_options *ipwo = &ipcp_wantoptions[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
569 u_int32_t remote;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
570
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
571 /* Default our_name to hostname, and user to our_name */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
572 if (our_name[0] == 0 || usehostname)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
573 strcpy(our_name, cyg_ppp_hostname);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
574 if (user[0] == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
575 strcpy(user, our_name);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
576
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
577 /* If authentication is required, ask peer for CHAP or PAP. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
578 if (auth_required && !wo->neg_chap && !wo->neg_upap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
579 wo->neg_chap = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
580 wo->neg_upap = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
581 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
582
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
583 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
584 * Check whether we have appropriate secrets to use
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
585 * to authenticate the peer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
586 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
587 can_auth = wo->neg_upap && (uselogin || have_pap_secret());
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
588 if (!can_auth && wo->neg_chap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
589 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
590 can_auth = have_chap_secret(remote_name, our_name, remote);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
591 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
592
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
593 if (auth_required && !can_auth) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
594 option_error("peer authentication required but no suitable secret(s) found\n");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
595 if (remote_name[0] == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
596 option_error("for authenticating any peer to us (%s)\n", our_name);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
597 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
598 option_error("for authenticating peer %s to us (%s)\n",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
599 remote_name, our_name);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
600 exit(1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
601 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
602
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
603 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
604 * Check whether the user tried to override certain values
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
605 * set by root.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
606 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
607 if (!auth_required && auth_req_info.priv > 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
608 if (!default_device && devnam_info.priv == 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
609 option_error("can't override device name when noauth option used");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
610 exit(1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
611 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
612 if ((connector != NULL && connector_info.priv == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
613 || (disconnector != NULL && disconnector_info.priv == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
614 || (welcomer != NULL && welcomer_info.priv == 0)) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
615 option_error("can't override connect, disconnect or welcome");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
616 option_error("option values when noauth option used");
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
617 exit(1);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
618 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
619 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
620 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
621
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
622 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
623 * auth_reset - called when LCP is starting negotiations to recheck
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
624 * authentication options, i.e. whether we have appropriate secrets
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
625 * to use for authenticating ourselves and/or the peer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
626 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
627 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
628 auth_reset(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
629 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
630 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
631 lcp_options *go = &lcp_gotoptions[unit];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
632 lcp_options *ao = &lcp_allowoptions[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
633 ipcp_options *ipwo = &ipcp_wantoptions[0];
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
634 u_int32_t remote;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
635 ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
636 ao->neg_chap = !refuse_chap
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
637 && have_chap_secret(user, remote_name, (u_int32_t)0);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
638 if (go->neg_upap && !uselogin && !have_pap_secret())
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
639 go->neg_upap = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
640 if (go->neg_chap) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
641 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
642 if (!have_chap_secret(remote_name, our_name, remote))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
643 go->neg_chap = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
644 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
645 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
646
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
647
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
648 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
649 * check_passwd - Check the user name and passwd against the PAP secrets
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
650 * file. If requested, also check against the system password database,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
651 * and login the user if OK.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
652 *
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
653 * returns:
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
654 * UPAP_AUTHNAK: Authentication failed.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
655 * UPAP_AUTHACK: Authentication succeeded.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
656 * In either case, msg points to an appropriate message.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
657 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
658 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
659 check_passwd(unit, auser, userlen, apasswd, passwdlen, msg, msglen)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
660 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
661 char *auser;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
662 int userlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
663 char *apasswd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
664 int passwdlen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
665 char **msg;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
666 int *msglen;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
667 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
668 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
669 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
670 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
671
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
672 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
673 * null_login - Check if a username of "" and a password of "" are
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
674 * acceptable, and iff so, set the list of acceptable IP addresses
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
675 * and return 1.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
676 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
677 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
678 null_login(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
679 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
680 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
681 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
682 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
683 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
684
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
685
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
686 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
687 * get_pap_passwd - get a password for authenticating ourselves with
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
688 * our peer using PAP. Returns 1 on success, 0 if no suitable password
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
689 * could be found.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
690 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
691 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
692 get_pap_passwd(passwd)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
693 char *passwd;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
694 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
695 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
696 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
697 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
698
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
699
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
700 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
701 * have_pap_secret - check whether we have a PAP file with any
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
702 * secrets that we could possibly use for authenticating the peer.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
703 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
704 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
705 have_pap_secret()
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
706 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
707 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
708 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
709 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
710
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
711
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
712 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
713 * have_chap_secret - check whether we have a CHAP file with a
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
714 * secret that we could possibly use for authenticating `client'
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
715 * on `server'. Either can be the null string, meaning we don't
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
716 * know the identity yet.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
717 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
718 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
719 have_chap_secret(client, server, remote)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
720 char *client;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
721 char *server;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
722 u_int32_t remote;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
723 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
724 // db_printf("%s(%s,%s,%d) called\n", __PRETTY_FUNCTION__,client,server,remote);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
725 return 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
726 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
727
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
728
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
729 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
730 * get_secret - open the CHAP secret file and return the secret
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
731 * for authenticating the given client on the given server.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
732 * (We could be either client or server).
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
733 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
734 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
735 get_secret(unit, client, server, secret, secret_len, save_addrs)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
736 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
737 char *client;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
738 char *server;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
739 char *secret;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
740 int *secret_len;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
741 int save_addrs;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
742 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
743 db_printf("%s(%d,%s,%s,%08x,%d,%d) called\n", __PRETTY_FUNCTION__,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
744 unit, client, server, secret, secret_len, save_addrs);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
745 // We use the PAP password as the CHAP secret also.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
746 strncpy( secret, passwd, MAXNAMELEN );
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
747 *secret_len = strlen(secret);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
748 return 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
749 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
750
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
751 static void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
752 auth_set_ip_addr(unit)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
753 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
754 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
755 db_printf("%s called\n", __PRETTY_FUNCTION__);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
756 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
757
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
758 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
759 * auth_ip_addr - check whether the peer is authorized to use
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
760 * a given IP address. Returns 1 if authorized, 0 otherwise.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
761 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
762 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
763 auth_ip_addr(unit, addr)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
764 int unit;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
765 u_int32_t addr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
766 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
767 return ip_addr_check(addr, addresses[unit]);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
768 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
769
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
770 static int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
771 ip_addr_check(addr, addrs)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
772 u_int32_t addr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
773 struct wordlist *addrs;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
774 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
775 int x, y;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
776 // u_int32_t a, mask, ah;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
777 u_int32_t a = -1, mask;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
778 int accept;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
779 char *ptr_word, *ptr_mask;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
780 // struct hostent *hp;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
781 // struct netent *np;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
782
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
783 /* don't allow loopback or multicast address */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
784 if (bad_ip_adrs(addr))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
785 return 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
786
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
787 if (addrs == NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
788 return !auth_required; /* no addresses authorized */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
789
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
790 x = y = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
791 for (; addrs != NULL; addrs = addrs->next) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
792 y++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
793 /* "-" means no addresses authorized, "*" means any address allowed */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
794 ptr_word = addrs->word;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
795 if (strcmp(ptr_word, "-") == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
796 break;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
797 if (strcmp(ptr_word, "*") == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
798 return 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
799
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
800 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
801 * A colon in the string means that we wish to force a specific
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
802 * local:remote address, but we ignore these for now.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
803 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
804 if (strchr(addrs->word, ':') != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
805 x++;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
806 else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
807
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
808 accept = 1;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
809 if (*ptr_word == '!') {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
810 accept = 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
811 ++ptr_word;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
812 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
813
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
814 mask = ~ (u_int32_t) 0;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
815 ptr_mask = strchr (ptr_word, '/');
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
816 if (ptr_mask != NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
817 int bit_count;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
818
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
819 bit_count = (int) strtol (ptr_mask+1, (char **) 0, 10);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
820 if (bit_count <= 0 || bit_count > 32) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
821 syslog (LOG_WARNING,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
822 "invalid address length %s in auth. address list",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
823 ptr_mask);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
824 continue;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
825 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
826 *ptr_mask = '\0';
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
827 mask <<= 32 - bit_count;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
828 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
829
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
830 #ifndef __ECOS
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
831 hp = gethostbyname(ptr_word);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
832 if (hp != NULL && hp->h_addrtype == AF_INET) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
833 a = *(u_int32_t *)hp->h_addr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
834 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
835 np = getnetbyname (ptr_word);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
836 if (np != NULL && np->n_addrtype == AF_INET) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
837 a = htonl (*(u_int32_t *)np->n_net);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
838 if (ptr_mask == NULL) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
839 /* calculate appropriate mask for net */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
840 ah = ntohl(a);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
841 if (IN_CLASSA(ah))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
842 mask = IN_CLASSA_NET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
843 else if (IN_CLASSB(ah))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
844 mask = IN_CLASSB_NET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
845 else if (IN_CLASSC(ah))
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
846 mask = IN_CLASSC_NET;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
847 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
848 } else {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
849 a = inet_addr (ptr_word);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
850 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
851 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
852 #endif
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
853
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
854 if (ptr_mask != NULL)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
855 *ptr_mask = '/';
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
856
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
857 if (a == (u_int32_t)-1L)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
858 syslog (LOG_WARNING,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
859 "unknown host %s in auth. address list",
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
860 addrs->word);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
861 else
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
862 /* Here a and addr are in network byte order,
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
863 and mask is in host order. */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
864 if (((addr ^ a) & htonl(mask)) == 0)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
865 return accept;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
866 } /* else */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
867 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
868 return x == y; /* not in list => can't have it */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
869 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
870
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
871 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
872 * bad_ip_adrs - return 1 if the IP address is one we don't want
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
873 * to use, such as an address in the loopback net or a multicast address.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
874 * addr is in network byte order.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
875 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
876 int
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
877 bad_ip_adrs(addr)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
878 u_int32_t addr;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
879 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
880 addr = ntohl(addr);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
881 return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
882 || IN_MULTICAST(addr) || IN_BADCLASS(addr);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
883 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
884
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
885 /*
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
886 * check_access - complain if a secret file has too-liberal permissions.
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
887 */
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
888 void
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
889 check_access(f, filename)
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
890 FILE *f;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
891 char *filename;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
892 {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
893 struct stat sbuf;
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
894
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
895 if (fstat(fileno(f), &sbuf) < 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
896 syslog(LOG_WARNING, "cannot stat secret file %s: %m", filename);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
897 } else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
898 syslog(LOG_WARNING, "Warning - secret file %s has world and/or group access", filename);
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
899 }
e0d88dc6a92f Added PPP network support.
nickg
parents:
diff changeset
900 }