auth.c (2ff64793adea3c27c1a987f61c8b6a3c2c00b86b) auth.c (972a1bcf5db5ee4c5520a1d29d3c81e81bdec84f)
1/*
2 * PPP Secret Key Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Secret Key Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: auth.c,v 1.33 1998/08/26 17:39:36 brian Exp $
20 * $Id: auth.c,v 1.34 1998/12/17 00:28:12 brian Exp $
21 *
22 * TODO:
23 * o Implement check against with registered IP addresses.
24 */
21 *
22 * TODO:
23 * o Implement check against with registered IP addresses.
24 */
25#include <sys/types.h>
25#include <sys/param.h>
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>
29#include <sys/un.h>
30
31#include <pwd.h>
32#include <stdio.h>
33#include <string.h>

--- 14 unchanged lines hidden (view full) ---

48#include "lcp.h"
49#include "ccp.h"
50#include "link.h"
51#include "descriptor.h"
52#include "chat.h"
53#include "lcpproto.h"
54#include "filter.h"
55#include "mp.h"
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>
29#include <sys/un.h>
30
31#include <pwd.h>
32#include <stdio.h>
33#include <string.h>

--- 14 unchanged lines hidden (view full) ---

48#include "lcp.h"
49#include "ccp.h"
50#include "link.h"
51#include "descriptor.h"
52#include "chat.h"
53#include "lcpproto.h"
54#include "filter.h"
55#include "mp.h"
56#ifndef NORADIUS
57#include "radius.h"
58#endif
56#include "bundle.h"
57
58const char *
59Auth2Nam(u_short auth)
60{
61 switch (auth) {
62 case PROTO_PAP:
63 return "PAP";

--- 36 unchanged lines hidden (view full) ---

100 if (buff[0] == '#')
101 continue;
102 buff[strlen(buff) - 1] = '\0';
103 memset(vector, '\0', sizeof vector);
104 n = MakeArgs(buff, vector, VECSIZE(vector));
105 if (n < 5)
106 continue;
107 if (strcmp(vector[0], name) == 0) {
59#include "bundle.h"
60
61const char *
62Auth2Nam(u_short auth)
63{
64 switch (auth) {
65 case PROTO_PAP:
66 return "PAP";

--- 36 unchanged lines hidden (view full) ---

103 if (buff[0] == '#')
104 continue;
105 buff[strlen(buff) - 1] = '\0';
106 memset(vector, '\0', sizeof vector);
107 n = MakeArgs(buff, vector, VECSIZE(vector));
108 if (n < 5)
109 continue;
110 if (strcmp(vector[0], name) == 0) {
108 CloseSecret(fp);
109 if (*vector[4] == '\0')
111 CloseSecret(fp);
112 if (*vector[4] == '\0')
110 return 0;
111 strncpy(phone, vector[4], phonelen - 1);
112 phone[phonelen - 1] = '\0';
113 return 0;
114 strncpy(phone, vector[4], phonelen - 1);
115 phone[phonelen - 1] = '\0';
113 return 1; /* Valid */
116 return 1; /* Valid */
114 }
115 }
116 CloseSecret(fp);
117 }
118 *phone = '\0';
119 return 0;
120}
121
122int
123auth_Select(struct bundle *bundle, const char *name)
124{
125 FILE *fp;
126 int n;
127 char *vector[5];
128 char buff[LINE_LEN];
129
130 if (*name == '\0') {
117 }
118 }
119 CloseSecret(fp);
120 }
121 *phone = '\0';
122 return 0;
123}
124
125int
126auth_Select(struct bundle *bundle, const char *name)
127{
128 FILE *fp;
129 int n;
130 char *vector[5];
131 char buff[LINE_LEN];
132
133 if (*name == '\0') {
131 ipcp_Setup(&bundle->ncp.ipcp);
134 ipcp_Setup(&bundle->ncp.ipcp, INADDR_NONE);
132 return 1;
133 }
134
135 return 1;
136 }
137
138#ifndef NORADIUS
139 if (bundle->radius.valid && bundle->radius.ip.s_addr != INADDR_NONE) {
140 /* We've got a radius IP - it overrides everything */
141 if (!ipcp_UseHisIPaddr(bundle, bundle->radius.ip))
142 return 0;
143 ipcp_Setup(&bundle->ncp.ipcp, bundle->radius.mask.s_addr);
144 /* Continue with ppp.secret in case we've got a new label */
145 }
146#endif
147
135 fp = OpenSecret(SECRETFILE);
136 if (fp != NULL) {
137 while (fgets(buff, sizeof buff, fp)) {
138 if (buff[0] == '#')
139 continue;
140 buff[strlen(buff) - 1] = '\0';
141 memset(vector, '\0', sizeof vector);
142 n = MakeArgs(buff, vector, VECSIZE(vector));
143 if (n < 2)
144 continue;
145 if (strcmp(vector[0], name) == 0) {
148 fp = OpenSecret(SECRETFILE);
149 if (fp != NULL) {
150 while (fgets(buff, sizeof buff, fp)) {
151 if (buff[0] == '#')
152 continue;
153 buff[strlen(buff) - 1] = '\0';
154 memset(vector, '\0', sizeof vector);
155 n = MakeArgs(buff, vector, VECSIZE(vector));
156 if (n < 2)
157 continue;
158 if (strcmp(vector[0], name) == 0) {
146 CloseSecret(fp);
147 if (n > 2 && *vector[2] && strcmp(vector[2], "*") &&
148 !ipcp_UseHisaddr(bundle, vector[2], 1))
149 return 0;
150 ipcp_Setup(&bundle->ncp.ipcp);
151 if (n > 3 && *vector[3] && strcmp(vector[3], "*"))
152 bundle_SetLabel(bundle, vector[3]);
153 return 1; /* Valid */
159 CloseSecret(fp);
160#ifndef NORADIUS
161 if (!bundle->radius.valid || bundle->radius.ip.s_addr == INADDR_NONE) {
162#endif
163 if (n > 2 && *vector[2] && strcmp(vector[2], "*") &&
164 !ipcp_UseHisaddr(bundle, vector[2], 1))
165 return 0;
166 ipcp_Setup(&bundle->ncp.ipcp, INADDR_NONE);
167#ifndef NORADIUS
168 }
169#endif
170 if (n > 3 && *vector[3] && strcmp(vector[3], "*"))
171 bundle_SetLabel(bundle, vector[3]);
172 return 1; /* Valid */
154 }
155 }
156 CloseSecret(fp);
157 }
158
159#ifndef NOPASSWDAUTH
160 /* Let 'em in anyway - they must have been in the passwd file */
173 }
174 }
175 CloseSecret(fp);
176 }
177
178#ifndef NOPASSWDAUTH
179 /* Let 'em in anyway - they must have been in the passwd file */
161 ipcp_Setup(&bundle->ncp.ipcp);
180 ipcp_Setup(&bundle->ncp.ipcp, INADDR_NONE);
162 return 1;
163#else
181 return 1;
182#else
164 /* Disappeared from ppp.secret ? */
183#ifndef NORADIUS
184 if (bundle->radius.valid)
185 return 1;
186#endif
187
188 /* Disappeared from ppp.secret ??? */
165 return 0;
166#endif
167}
168
169int
189 return 0;
190#endif
191}
192
193int
170auth_Validate(struct bundle *bundle, const char *system,
194auth_Validate(struct bundle *bundle, const char *name,
171 const char *key, struct physical *physical)
172{
173 /* Used by PAP routines */
174
175 FILE *fp;
176 int n;
177 char *vector[5];
178 char buff[LINE_LEN];
179
195 const char *key, struct physical *physical)
196{
197 /* Used by PAP routines */
198
199 FILE *fp;
200 int n;
201 char *vector[5];
202 char buff[LINE_LEN];
203
204#ifndef NORADIUS
205 if (*bundle->radius.cfg.file)
206 return radius_Authenticate(&bundle->radius, bundle, name, key, NULL);
207#endif
208
180 fp = OpenSecret(SECRETFILE);
181 if (fp != NULL) {
182 while (fgets(buff, sizeof buff, fp)) {
183 if (buff[0] == '#')
184 continue;
185 buff[strlen(buff) - 1] = 0;
186 memset(vector, '\0', sizeof vector);
187 n = MakeArgs(buff, vector, VECSIZE(vector));
188 if (n < 2)
189 continue;
209 fp = OpenSecret(SECRETFILE);
210 if (fp != NULL) {
211 while (fgets(buff, sizeof buff, fp)) {
212 if (buff[0] == '#')
213 continue;
214 buff[strlen(buff) - 1] = 0;
215 memset(vector, '\0', sizeof vector);
216 n = MakeArgs(buff, vector, VECSIZE(vector));
217 if (n < 2)
218 continue;
190 if (strcmp(vector[0], system) == 0) {
191 CloseSecret(fp);
192 return auth_CheckPasswd(vector[0], vector[1], key);
219 if (strcmp(vector[0], name) == 0) {
220 CloseSecret(fp);
221 return auth_CheckPasswd(name, vector[1], key);
193 }
194 }
195 CloseSecret(fp);
196 }
197
198#ifndef NOPASSWDAUTH
199 if (Enabled(bundle, OPT_PASSWDAUTH))
222 }
223 }
224 CloseSecret(fp);
225 }
226
227#ifndef NOPASSWDAUTH
228 if (Enabled(bundle, OPT_PASSWDAUTH))
200 return auth_CheckPasswd(system, "*", key);
229 return auth_CheckPasswd(name, "*", key);
201#endif
202
203 return 0; /* Invalid */
204}
205
206char *
230#endif
231
232 return 0; /* Invalid */
233}
234
235char *
207auth_GetSecret(struct bundle *bundle, const char *system, int len,
236auth_GetSecret(struct bundle *bundle, const char *name, int len,
208 struct physical *physical)
209{
210 /* Used by CHAP routines */
211
212 FILE *fp;
213 int n;
214 char *vector[5];
215 static char buff[LINE_LEN];

--- 5 unchanged lines hidden (view full) ---

221 while (fgets(buff, sizeof buff, fp)) {
222 if (buff[0] == '#')
223 continue;
224 buff[strlen(buff) - 1] = 0;
225 memset(vector, '\0', sizeof vector);
226 n = MakeArgs(buff, vector, VECSIZE(vector));
227 if (n < 2)
228 continue;
237 struct physical *physical)
238{
239 /* Used by CHAP routines */
240
241 FILE *fp;
242 int n;
243 char *vector[5];
244 static char buff[LINE_LEN];

--- 5 unchanged lines hidden (view full) ---

250 while (fgets(buff, sizeof buff, fp)) {
251 if (buff[0] == '#')
252 continue;
253 buff[strlen(buff) - 1] = 0;
254 memset(vector, '\0', sizeof vector);
255 n = MakeArgs(buff, vector, VECSIZE(vector));
256 if (n < 2)
257 continue;
229 if (strlen(vector[0]) == len && strncmp(vector[0], system, len) == 0) {
258 if (strlen(vector[0]) == len && strncmp(vector[0], name, len) == 0) {
230 CloseSecret(fp);
231 return vector[1];
232 }
233 }
234 CloseSecret(fp);
235 return (NULL); /* Invalid */
236}
237

--- 42 unchanged lines hidden ---
259 CloseSecret(fp);
260 return vector[1];
261 }
262 }
263 CloseSecret(fp);
264 return (NULL); /* Invalid */
265}
266

--- 42 unchanged lines hidden ---