83 #include <sys/types.h> 88 #if defined(_PATH_LASTLOG) && defined(__linux__) 93 #include <netinet/in.h> 94 #include <arpa/inet.h> 99 #define PW_PPP PW_LOGIN 127 #include "netif/ppp/cbcp.h" 136 #define NONWILD_SERVER 1 137 #define NONWILD_CLIENT 2 139 #define ISWILD(word) (word[0] == '*' && word[1] == 0) 144 static struct permitted_ip *addresses[NUM_PPP];
148 static struct wordlist *noauth_addrs;
151 char remote_number[MAXNAMELEN];
154 static struct wordlist *permitted_numbers;
157 static struct wordlist *extra_options;
162 static bool default_auth;
165 int (*idle_time_hook) (
struct ppp_idle *) =
NULL;
168 int (*pap_check_hook) (void) =
NULL;
171 int (*pap_auth_hook) (
char *user,
char *passwd,
char **msgp,
172 struct wordlist **paddrs,
173 struct wordlist **popts) =
NULL;
176 void (*pap_logout_hook) (void) =
NULL;
179 int (*pap_passwd_hook) (
char *user,
char *passwd) =
NULL;
182 int (*chap_check_hook) (void) =
NULL;
185 int (*chap_passwd_hook) (
char *user,
char *passwd) =
NULL;
189 int (*null_auth_hook) (
struct wordlist **paddrs,
190 struct wordlist **popts) =
NULL;
192 int (*allowed_address_hook) (
u32_t addr) =
NULL;
195 #ifdef HAVE_MULTILINK 197 void (*multilink_join_hook) (void) =
NULL;
203 struct notifier *auth_up_notifier =
NULL;
206 struct notifier *link_down_notifier =
NULL;
214 bool session_mgmt = 0;
217 bool refuse_chap = 0;
220 bool refuse_mschap = 0;
221 bool refuse_mschap_v2 = 0;
223 bool refuse_mschap = 1;
224 bool refuse_mschap_v2 = 1;
226 bool usehostname = 0;
227 bool auth_required = 0;
228 bool allow_any_ip = 0;
229 bool explicit_remote = 0;
230 bool explicit_user = 0;
231 bool explicit_passwd = 0;
232 char remote_name[MAXNAMELEN];
233 static char *uafname;
235 extern char *crypt (
const char *,
const char *);
239 static void network_phase(ppp_pcb *pcb);
240 #if PPP_IDLETIMELIMIT 241 static void check_idle(
void *arg);
244 static void connect_time_expired(
void *arg);
247 static int null_login (
int);
249 static int have_pap_secret (
int *);
250 static int have_chap_secret (
char *,
char *,
int,
int *);
251 static int have_srp_secret (
char *client,
char *server,
int need_ip,
253 static int ip_addr_check (
u32_t,
struct permitted_ip *);
254 static int scan_authfile (FILE *,
char *,
char *,
char *,
255 struct wordlist **,
struct wordlist **,
257 static void free_wordlist (
struct wordlist *);
258 static void set_allowed_addrs (
int,
struct wordlist *,
struct wordlist *);
259 static int some_ip_ok (
struct wordlist *);
260 static int setupapfile (
char **);
261 static int privgroup (
char **);
262 static int set_noauth_addr (
char **);
263 static int set_permitted_number (
char **);
264 static void check_access (FILE *,
char *);
265 static int wordlist_count (
struct wordlist *);
269 static void check_maxoctets (
void *);
276 option_t auth_options[] = {
277 {
"auth", o_bool, &auth_required,
278 "Require authentication from peer", OPT_PRIO | 1 },
279 {
"noauth", o_bool, &auth_required,
280 "Don't require peer to authenticate", OPT_PRIOSUB | OPT_PRIV,
282 {
"require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
283 "Require PAP authentication from peer",
284 OPT_PRIOSUB | 1, &auth_required },
285 {
"+pap", o_bool, &lcp_wantoptions[0].neg_upap,
286 "Require PAP authentication from peer",
287 OPT_ALIAS | OPT_PRIOSUB | 1, &auth_required },
288 {
"require-chap", o_bool, &auth_required,
289 "Require CHAP authentication from peer",
290 OPT_PRIOSUB | OPT_A2OR | MDTYPE_MD5,
291 &lcp_wantoptions[0].chap_mdtype },
292 {
"+chap", o_bool, &auth_required,
293 "Require CHAP authentication from peer",
294 OPT_ALIAS | OPT_PRIOSUB | OPT_A2OR | MDTYPE_MD5,
295 &lcp_wantoptions[0].chap_mdtype },
297 {
"require-mschap", o_bool, &auth_required,
298 "Require MS-CHAP authentication from peer",
299 OPT_PRIOSUB | OPT_A2OR | MDTYPE_MICROSOFT,
300 &lcp_wantoptions[0].chap_mdtype },
301 {
"+mschap", o_bool, &auth_required,
302 "Require MS-CHAP authentication from peer",
303 OPT_ALIAS | OPT_PRIOSUB | OPT_A2OR | MDTYPE_MICROSOFT,
304 &lcp_wantoptions[0].chap_mdtype },
305 {
"require-mschap-v2", o_bool, &auth_required,
306 "Require MS-CHAPv2 authentication from peer",
307 OPT_PRIOSUB | OPT_A2OR | MDTYPE_MICROSOFT_V2,
308 &lcp_wantoptions[0].chap_mdtype },
309 {
"+mschap-v2", o_bool, &auth_required,
310 "Require MS-CHAPv2 authentication from peer",
311 OPT_ALIAS | OPT_PRIOSUB | OPT_A2OR | MDTYPE_MICROSOFT_V2,
312 &lcp_wantoptions[0].chap_mdtype },
315 {
"refuse-pap", o_bool, &refuse_pap,
316 "Don't agree to auth to peer with PAP", 1 },
317 {
"-pap", o_bool, &refuse_pap,
318 "Don't allow PAP authentication with peer", OPT_ALIAS | 1 },
319 {
"refuse-chap", o_bool, &refuse_chap,
320 "Don't agree to auth to peer with CHAP",
321 OPT_A2CLRB | MDTYPE_MD5,
322 &lcp_allowoptions[0].chap_mdtype },
323 {
"-chap", o_bool, &refuse_chap,
324 "Don't allow CHAP authentication with peer",
325 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MD5,
326 &lcp_allowoptions[0].chap_mdtype },
330 {
"refuse-mschap", o_bool, &refuse_mschap,
331 "Don't agree to auth to peer with MS-CHAP",
332 OPT_A2CLRB | MDTYPE_MICROSOFT,
333 &lcp_allowoptions[0].chap_mdtype },
334 {
"-mschap", o_bool, &refuse_mschap,
335 "Don't allow MS-CHAP authentication with peer",
336 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MICROSOFT,
337 &lcp_allowoptions[0].chap_mdtype },
338 {
"refuse-mschap-v2", o_bool, &refuse_mschap_v2,
339 "Don't agree to auth to peer with MS-CHAPv2",
340 OPT_A2CLRB | MDTYPE_MICROSOFT_V2,
341 &lcp_allowoptions[0].chap_mdtype },
342 {
"-mschap-v2", o_bool, &refuse_mschap_v2,
343 "Don't allow MS-CHAPv2 authentication with peer",
344 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MICROSOFT_V2,
345 &lcp_allowoptions[0].chap_mdtype },
349 {
"require-eap", o_bool, &lcp_wantoptions[0].neg_eap,
350 "Require EAP authentication from peer", OPT_PRIOSUB | 1,
353 {
"refuse-eap", o_bool, &refuse_eap,
354 "Don't agree to authenticate to peer with EAP", 1 },
357 {
"name", o_string, our_name,
358 "Set local name for authentication",
359 OPT_PRIO | OPT_PRIV | OPT_STATIC,
NULL, MAXNAMELEN },
361 {
"+ua", o_special, (
void *)setupapfile,
362 "Get PAP user and password from file",
363 OPT_PRIO | OPT_A2STRVAL, &uafname },
366 {
"user", o_string, user,
367 "Set name for auth with peer", OPT_PRIO | OPT_STATIC,
368 &explicit_user, MAXNAMELEN },
370 {
"password", o_string, passwd,
371 "Password for authenticating us to the peer",
372 OPT_PRIO | OPT_STATIC | OPT_HIDE,
373 &explicit_passwd, MAXSECRETLEN },
376 {
"usehostname", o_bool, &usehostname,
377 "Must use hostname for authentication", 1 },
379 {
"remotename", o_string, remote_name,
380 "Set remote name for authentication", OPT_PRIO | OPT_STATIC,
381 &explicit_remote, MAXNAMELEN },
383 {
"login", o_bool, &uselogin,
384 "Use system password database for PAP", OPT_A2COPY | 1 ,
386 {
"enable-session", o_bool, &session_mgmt,
387 "Enable session accounting for remote peers", OPT_PRIV | 1 },
389 {
"papcrypt", o_bool, &cryptpap,
390 "PAP passwords are encrypted", 1 },
392 {
"privgroup", o_special, (
void *)privgroup,
393 "Allow group members to use privileged options", OPT_PRIV | OPT_A2LIST },
395 {
"allow-ip", o_special, (
void *)set_noauth_addr,
396 "Set IP address(es) which can be used without authentication",
397 OPT_PRIV | OPT_A2LIST },
399 {
"remotenumber", o_string, remote_number,
400 "Set remote telephone number for authentication", OPT_PRIO | OPT_STATIC,
403 {
"allow-number", o_special, (
void *)set_permitted_number,
404 "Set telephone number(s) which are allowed to connect",
405 OPT_PRIV | OPT_A2LIST },
422 char u[MAXNAMELEN], p[MAXSECRETLEN];
425 lcp_allowoptions[0].neg_upap = 1;
428 fname = strdup(*argv);
430 novm(
"+ua file name");
432 if (seteuid(getuid()) == -1) {
433 option_error(
"unable to reset uid before opening %s: %m", fname);
436 ufile = fopen(fname,
"r");
437 if (seteuid(euid) == -1)
438 fatal(
"unable to regain privileges: %m");
440 option_error(
"unable to open user login data file %s", fname);
443 check_access(ufile, fname);
447 if (fgets(u, MAXNAMELEN - 1, ufile) ==
NULL 448 || fgets(p, MAXSECRETLEN - 1, ufile) ==
NULL) {
450 option_error(
"unable to read user login data file %s", fname);
457 if (l > 0 && u[l-1] ==
'\n')
460 if (l > 0 && p[l-1] ==
'\n')
463 if (override_value(
"user", option_priority, fname)) {
464 strlcpy(ppp_settings.user, u,
sizeof(ppp_settings.user));
467 if (override_value(
"passwd", option_priority, fname)) {
468 strlcpy(ppp_settings.passwd, p,
sizeof(ppp_settings.passwd));
487 option_error(
"group %s is unknown", *argv);
490 for (i = 0; i < ngroups; ++i) {
491 if (groups[i] == g->gr_gid) {
505 set_noauth_addr(argv)
509 int l = strlen(addr) + 1;
512 wp = (
struct wordlist *) malloc(
sizeof(
struct wordlist) + l);
514 novm(
"allow-ip argument");
515 wp->word = (
char *) (wp + 1);
516 wp->next = noauth_addrs;
517 MEMCPY(wp->word, addr, l);
527 set_permitted_number(argv)
530 char *number = *argv;
531 int l = strlen(number) + 1;
534 wp = (
struct wordlist *) malloc(
sizeof(
struct wordlist) + l);
536 novm(
"allow-number argument");
537 wp->word = (
char *) (wp + 1);
538 wp->next = permitted_numbers;
539 MEMCPY(wp->word, number, l);
540 permitted_numbers = wp;
548 void link_required(ppp_pcb *pcb) {
556 void start_link(unit)
559 ppp_pcb *pcb = &ppp_pcb_list[unit];
562 status = EXIT_NEGOTIATION_FAILED;
563 new_phase(pcb, PPP_PHASE_SERIALCONN);
566 devfd = the_channel->connect();
567 msg =
"Connect script failed";
579 fd_ppp = the_channel->establish_ppp(devfd);
580 msg =
"ppp establishment failed";
582 status = EXIT_FATAL_ERROR;
586 if (!demand && ifunit >= 0)
594 ppp_notice(
"Connect: %s <--> %s", ifname, ppp_devnam);
596 ppp_notice(
"Starting negotiation on %s", ppp_devnam);
599 new_phase(pcb, PPP_PHASE_ESTABLISH);
605 new_phase(pcb, PPP_PHASE_DISCONNECT);
606 if (the_channel->disconnect)
607 the_channel->disconnect();
610 new_phase(pcb, PPP_PHASE_DEAD);
611 if (the_channel->cleanup)
612 (*the_channel->cleanup)();
620 void link_terminated(ppp_pcb *pcb) {
621 if (pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_MASTER)
623 new_phase(pcb, PPP_PHASE_DISCONNECT);
626 if (pap_logout_hook) {
632 if (!doing_multilink) {
633 ppp_notice(
"Connection terminated.");
634 #if PPP_STATS_SUPPORT 638 ppp_notice(
"Link terminated.");
642 new_phase(pcb, PPP_PHASE_DEAD);
643 ppp_link_terminated(pcb);
650 if (!doing_multilink && !demand)
661 the_channel->disestablish_ppp(devfd);
668 if (!doing_multilink && !demand)
669 script_unsetenv(
"IFNAME");
675 if (devfd >= 0 && the_channel->disconnect) {
676 the_channel->disconnect();
679 if (the_channel->cleanup)
680 (*the_channel->cleanup)();
682 if (doing_multilink && multilink_master) {
683 if (!bundle_terminating)
684 new_phase(pcb, PPP_PHASE_MASTER);
686 mp_bundle_terminated();
688 new_phase(pcb, PPP_PHASE_DEAD);
695 void link_down(ppp_pcb *pcb) {
697 notify(link_down_notifier, 0);
700 if (!doing_multilink) {
701 upper_layers_down(pcb);
702 if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER)
703 new_phase(pcb, PPP_PHASE_ESTABLISH);
709 void upper_layers_down(ppp_pcb *pcb) {
711 const struct protent *protp;
713 for (i = 0; (protp = protocols[i]) !=
NULL; ++i) {
714 if (protp->protocol != PPP_LCP && protp->lowerdown !=
NULL)
715 (*protp->lowerdown)(pcb);
716 if (protp->protocol < 0xC000 && protp->close !=
NULL)
717 (*protp->close)(pcb,
"LCP down");
719 pcb->num_np_open = 0;
727 void link_established(ppp_pcb *pcb) {
731 lcp_options *wo = &pcb->lcp_wantoptions;
732 lcp_options *go = &pcb->lcp_gotoptions;
734 lcp_options *ho = &pcb->lcp_hisoptions;
737 const struct protent *protp;
742 if (!doing_multilink) {
743 for (i = 0; (protp = protocols[i]) !=
NULL; ++i)
744 if (protp->protocol != PPP_LCP
745 && protp->lowerup !=
NULL)
746 (*protp->lowerup)(pcb);
751 #if PPP_ALLOWED_ADDRS 752 if (!auth_required && noauth_addrs !=
NULL)
753 set_allowed_addrs(unit,
NULL,
NULL);
756 if (pcb->settings.auth_required && !(0
768 #if PPP_ALLOWED_ADDRS 776 if (noauth_addrs !=
NULL) {
777 set_allowed_addrs(unit,
NULL,
NULL);
780 if (!wo->neg_upap || !pcb->settings.null_login) {
781 ppp_warn(
"peer refused to authenticate: terminating link");
783 status = EXIT_PEER_AUTH_FAILED;
785 pcb->err_code = PPPERR_AUTHFAIL;
786 lcp_close(pcb,
"peer refused to authenticate");
792 new_phase(pcb, PPP_PHASE_AUTHENTICATE);
797 eap_authpeer(pcb, PPP_OUR_NAME);
803 chap_auth_peer(pcb, PPP_OUR_NAME, CHAP_DIGEST(go->chap_mdtype));
818 eap_authwithpeer(pcb, pcb->settings.user);
819 auth |= EAP_WITHPEER;
824 chap_auth_with_peer(pcb, pcb->settings.user, CHAP_DIGEST(ho->chap_mdtype));
825 auth |= CHAP_WITHPEER;
830 upap_authwithpeer(pcb, pcb->settings.user, pcb->settings.passwd);
831 auth |= PAP_WITHPEER;
836 pcb->auth_pending = auth;
847 static void network_phase(ppp_pcb *pcb) {
849 ppp_pcb *pcb = &ppp_pcb_list[unit];
852 lcp_options *go = &lcp_gotoptions[unit];
858 ppp_notice(
"peer from calling number %q authorized", remote_number);
876 notify(auth_up_notifier, 0);
885 new_phase(pcb, PPP_PHASE_CALLBACK);
886 (*cbcp_protent.open)(pcb);
896 options_from_list(extra_options, 1);
897 free_wordlist(extra_options);
904 void start_networks(ppp_pcb *pcb) {
905 #if CCP_SUPPORT || ECP_SUPPORT 907 const struct protent *protp;
910 new_phase(pcb, PPP_PHASE_NETWORK);
912 #ifdef HAVE_MULTILINK 914 if (mp_join_bundle()) {
915 if (multilink_join_hook)
916 (*multilink_join_hook)();
917 if (updetach && !nodetach)
926 set_filters(&pass_filter, &active_filter);
928 #if CCP_SUPPORT || ECP_SUPPORT 930 for (i = 0; (protp = protocols[i]) !=
NULL; ++i)
934 || protp->protocol == PPP_ECP
937 || protp->protocol == PPP_CCP
940 && protp->open !=
NULL)
949 && !ecp_gotoptions[unit].required
952 && !pcb->ccp_gotoptions.mppe
955 continue_networks(pcb);
958 void continue_networks(ppp_pcb *pcb) {
960 const struct protent *protp;
965 for (i = 0; (protp = protocols[i]) !=
NULL; ++i)
966 if (protp->protocol < 0xC000
968 && protp->protocol != PPP_CCP
971 && protp->protocol != PPP_ECP
973 && protp->open !=
NULL) {
978 if (pcb->num_np_open == 0)
980 lcp_close(pcb,
"No network protocols running");
993 int auth_check_passwd(ppp_pcb *pcb,
char *auser,
int userlen,
char *apasswd,
int passwdlen,
const char **msg,
int *msglen) {
997 if (pcb->settings.user && pcb->settings.passwd) {
998 secretuserlen = (int)strlen(pcb->settings.user);
999 secretpasswdlen = (int)strlen(pcb->settings.passwd);
1000 if (secretuserlen == userlen
1001 && secretpasswdlen == passwdlen
1002 && !memcmp(auser, pcb->settings.user, userlen)
1003 && !memcmp(apasswd, pcb->settings.passwd, passwdlen) ) {
1005 *msglen =
sizeof(
"Login ok")-1;
1010 *msg =
"Login incorrect";
1011 *msglen =
sizeof(
"Login incorrect")-1;
1018 void auth_peer_fail(ppp_pcb *pcb,
int protocol) {
1024 status = EXIT_PEER_AUTH_FAILED;
1026 pcb->err_code = PPPERR_AUTHFAIL;
1027 lcp_close(pcb,
"Authentication failed");
1033 void auth_peer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor,
const char *name,
int namelen) {
1035 #ifndef HAVE_MULTILINK 1044 switch (prot_flavor) {
1046 bit |= CHAP_MD5_PEER;
1049 case CHAP_MICROSOFT:
1050 bit |= CHAP_MS_PEER;
1052 case CHAP_MICROSOFT_V2:
1053 bit |= CHAP_MS2_PEER;
1072 ppp_warn(
"auth_peer_success: unknown protocol %x", protocol);
1076 #ifdef HAVE_MULTILINK 1080 if (namelen > (
int)
sizeof(pcb->peer_authname) - 1)
1081 namelen = (int)
sizeof(pcb->peer_authname) - 1;
1082 MEMCPY(pcb->peer_authname, name, namelen);
1083 pcb->peer_authname[namelen] = 0;
1086 script_setenv(
"PEERNAME", , 0);
1090 pcb->auth_done |= bit;
1096 if ((pcb->auth_pending &= ~bit) == 0)
1104 void auth_withpeer_fail(ppp_pcb *pcb,
int protocol) {
1116 pcb->err_code = PPPERR_AUTHFAIL;
1117 lcp_close(pcb,
"Failed to authenticate ourselves to peer");
1123 void auth_withpeer_success(ppp_pcb *pcb,
int protocol,
int prot_flavor) {
1125 const char *prot =
"";
1130 bit = CHAP_WITHPEER;
1132 switch (prot_flavor) {
1134 bit |= CHAP_MD5_WITHPEER;
1137 case CHAP_MICROSOFT:
1138 bit |= CHAP_MS_WITHPEER;
1140 case CHAP_MICROSOFT_V2:
1141 bit |= CHAP_MS2_WITHPEER;
1162 ppp_warn(
"auth_withpeer_success: unknown protocol %x", protocol);
1167 ppp_notice(
"%s authentication succeeded", prot);
1170 pcb->auth_done |= bit;
1176 if ((pcb->auth_pending &= ~bit) == 0)
1185 void np_up(ppp_pcb *pcb,
int proto) {
1186 #if PPP_IDLETIMELIMIT 1191 if (pcb->num_np_up == 0) {
1195 new_phase(pcb, PPP_PHASE_RUNNING);
1197 #if PPP_IDLETIMELIMIT 1199 if (idle_time_hook != 0)
1200 tlim = (*idle_time_hook)(
NULL);
1203 tlim = pcb->settings.idle_time_limit;
1205 TIMEOUT(check_idle, (
void*)pcb, tlim);
1213 if (pcb->settings.maxconnect > 0)
1214 TIMEOUT(connect_time_expired, (
void*)pcb, pcb->settings.maxconnect);
1219 TIMEOUT(check_maxoctets,
NULL, maxoctets_timeout);
1226 if (updetach && !nodetach)
1236 void np_down(ppp_pcb *pcb,
int proto) {
1238 if (--pcb->num_np_up == 0) {
1239 #if PPP_IDLETIMELIMIT 1240 UNTIMEOUT(check_idle, (
void*)pcb);
1243 UNTIMEOUT(connect_time_expired,
NULL);
1246 UNTIMEOUT(check_maxoctets,
NULL);
1248 new_phase(pcb, PPP_PHASE_NETWORK);
1255 void np_finished(ppp_pcb *pcb,
int proto) {
1257 if (--pcb->num_np_open <= 0) {
1259 lcp_close(pcb,
"No network protocols running");
1265 check_maxoctets(arg)
1268 #if PPP_STATS_SUPPORT 1271 update_link_stats(ifunit);
1274 switch(maxoctets_dir) {
1275 case PPP_OCTETS_DIRECTION_IN:
1276 used = link_stats.bytes_in;
1278 case PPP_OCTETS_DIRECTION_OUT:
1279 used = link_stats.bytes_out;
1281 case PPP_OCTETS_DIRECTION_MAXOVERAL:
1282 case PPP_OCTETS_DIRECTION_MAXSESSION:
1283 used = (link_stats.bytes_in > link_stats.bytes_out) ? link_stats.bytes_in : link_stats.bytes_out;
1286 used = link_stats.bytes_in+link_stats.bytes_out;
1289 if (used > maxoctets) {
1290 ppp_notice(
"Traffic limit reached. Limit: %u Used: %u", maxoctets, used);
1291 status = EXIT_TRAFFIC_LIMIT;
1292 lcp_close(pcb,
"Traffic limit");
1297 TIMEOUT(check_maxoctets,
NULL, maxoctets_timeout);
1303 #if PPP_IDLETIMELIMIT 1308 static void check_idle(
void *arg) {
1309 ppp_pcb *pcb = (ppp_pcb*)arg;
1310 struct ppp_idle idle;
1314 if (!get_idle_time(pcb, &idle))
1317 if (idle_time_hook != 0) {
1318 tlim = idle_time_hook(&idle);
1321 itime =
LWIP_MIN(idle.xmit_idle, idle.recv_idle);
1322 tlim = pcb->settings.idle_time_limit - itime;
1328 ppp_notice(
"Terminating connection due to lack of activity.");
1329 pcb->err_code = PPPERR_IDLETIMEOUT;
1330 lcp_close(pcb,
"Link inactive");
1335 TIMEOUT(check_idle, (
void*)pcb, tlim);
1344 static void connect_time_expired(
void *arg) {
1345 ppp_pcb *pcb = (ppp_pcb*)arg;
1346 ppp_info(
"Connect time expired");
1347 pcb->err_code = PPPERR_CONNECTTIME;
1348 lcp_close(pcb,
"Connect time expired");
1357 auth_check_options()
1359 lcp_options *wo = &lcp_wantoptions[0];
1364 if (our_name[0] == 0 || usehostname)
1365 strlcpy(our_name, hostname,
sizeof(our_name));
1368 if (ppp_settings.user[0] == 0 && !explicit_user)
1369 strlcpy(ppp_settings.user, our_name,
sizeof(ppp_settings.user));
1375 if (!auth_required && !allow_any_ip && have_route_to(0) && !privileged) {
1382 if (wo->chap_mdtype)
1387 if (auth_required) {
1401 wo->neg_chap = CHAP_MDTYPE_SUPPORTED != MDTYPE_NONE;
1402 wo->chap_mdtype = CHAP_MDTYPE_SUPPORTED;
1414 wo->chap_mdtype = MDTYPE_NONE;
1431 can_auth = wo->neg_upap && (uselogin || have_pap_secret(&lacks_ip));
1444 can_auth = have_chap_secret((explicit_remote? remote_name:
NULL),
1445 our_name, 1, &lacks_ip);
1455 can_auth = have_srp_secret((explicit_remote? remote_name:
NULL),
1456 our_name, 1, &lacks_ip);
1459 if (auth_required && !can_auth && noauth_addrs ==
NULL) {
1462 "By default the remote system is required to authenticate itself");
1464 "(because this system has a default route to the internet)");
1465 }
else if (explicit_remote)
1467 "The remote system (%s) is required to authenticate itself",
1471 "The remote system is required to authenticate itself");
1473 "but I couldn't find any suitable secret (password) for it to use to do so.");
1476 "(None of the available passwords would let it use an IP address.)");
1484 if (!auth_number()) {
1485 ppp_warn(
"calling number %q is not authorized", remote_number);
1486 exit(EXIT_CNID_AUTH_FAILED);
1501 lcp_options *go = &lcp_gotoptions[unit];
1502 lcp_options *ao = &lcp_allowoptions[unit];
1506 ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(
NULL));
1507 ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)
1508 && (passwd[0] != 0 ||
1509 (hadchap = have_chap_secret(user, (explicit_remote? remote_name:
1511 ao->neg_eap = !refuse_eap && (
1513 (hadchap == 1 || (hadchap == -1 && have_chap_secret(user,
1514 (explicit_remote? remote_name: NULL), 0, NULL))) ||
1515 have_srp_secret(user, (explicit_remote? remote_name: NULL), 0, NULL));
1518 if (go->neg_upap && !uselogin && !have_pap_secret(NULL))
1521 if (!(hadchap = have_chap_secret((explicit_remote? remote_name: NULL),
1522 our_name, 1, NULL)))
1526 (hadchap == 0 || (hadchap == -1 &&
1527 !have_chap_secret((explicit_remote? remote_name: NULL), our_name,
1529 !have_srp_secret((explicit_remote? remote_name: NULL), our_name, 1,
1545 check_passwd(unit, auser, userlen, apasswd, passwdlen, msg)
1553 return UPAP_AUTHNAK;
1557 struct wordlist *addrs =
NULL, *opts =
NULL;
1558 char passwd[256], user[256];
1559 char secret[MAXWORDLEN];
1560 static int attempts = 0;
1567 slprintf(ppp_settings.passwd,
sizeof(ppp_settings.passwd),
"%.*v", passwdlen, apasswd);
1568 slprintf(ppp_settings.user,
sizeof(ppp_settings.user),
"%.*v", userlen, auser);
1574 if (pap_auth_hook) {
1575 ret = (*pap_auth_hook)(ppp_settings.user, ppp_settings.passwd, msg, &addrs, &opts);
1580 set_allowed_addrs(unit, addrs, opts);
1582 free_wordlist(opts);
1584 free_wordlist(addrs);
1585 BZERO(ppp_settings.passwd,
sizeof(ppp_settings.passwd));
1586 return ret? UPAP_AUTHACK: UPAP_AUTHNAK;
1594 filename = _PATH_UPAPFILE;
1595 addrs = opts =
NULL;
1597 f = fopen(filename,
"r");
1599 ppp_error(
"Can't open PAP password file %s: %m", filename);
1602 check_access(f, filename);
1603 if (scan_authfile(f, ppp_settings.user, our_name, secret, &addrs, &opts, filename, 0) < 0) {
1604 ppp_warn(
"no PAP secret found for %s", user);
1610 int login_secret = strcmp(secret,
"@login") == 0;
1612 if (uselogin || login_secret) {
1614 if (session_full(ppp_settings.user, ppp_settings.passwd, devnam, msg) == 0) {
1617 }
else if (session_mgmt) {
1618 if (session_check(ppp_settings.user, NULL, devnam, NULL) == 0) {
1619 ppp_warn(
"Peer %q failed PAP Session verification", user);
1623 if (secret[0] != 0 && !login_secret) {
1625 if ((cryptpap || strcmp(ppp_settings.passwd, secret) != 0)
1626 && strcmp(crypt(ppp_settings.passwd, secret), secret) != 0)
1633 if (ret == UPAP_AUTHNAK) {
1635 *msg =
"Login incorrect";
1642 if (attempts++ >= 10) {
1643 ppp_warn(
"%d LOGIN FAILURES ON %s, %s", attempts, devnam, user);
1644 lcp_close(pcb,
"login failed");
1647 sleep((u_int) (attempts - 3) * 5);
1649 free_wordlist(opts);
1655 set_allowed_addrs(unit, addrs, opts);
1659 free_wordlist(addrs);
1660 BZERO(ppp_settings.passwd,
sizeof(ppp_settings.passwd));
1661 BZERO(secret,
sizeof(secret));
1678 struct wordlist *addrs, *opts;
1679 char secret[MAXWORDLEN];
1686 ret = (*null_auth_hook)(&addrs, &opts);
1692 filename = _PATH_UPAPFILE;
1694 f = fopen(filename,
"r");
1697 check_access(f, filename);
1699 i = scan_authfile(f,
"", our_name, secret, &addrs, &opts, filename, 0);
1700 ret = i >= 0 && secret[0] == 0;
1701 BZERO(secret,
sizeof(secret));
1706 set_allowed_addrs(unit, addrs, opts);
1708 free_wordlist(opts);
1710 free_wordlist(addrs);
1722 get_pap_passwd(passwd)
1728 char secret[MAXWORDLEN];
1733 if (pap_passwd_hook) {
1734 ret = (*pap_passwd_hook)(ppp_settings,user, ppp_settings.passwd);
1739 filename = _PATH_UPAPFILE;
1740 f = fopen(filename,
"r");
1743 check_access(f, filename);
1744 ret = scan_authfile(f, user,
1745 (remote_name[0]? remote_name: NULL),
1746 secret, NULL, NULL, filename, 0);
1751 strlcpy(passwd, secret, MAXSECRETLEN);
1752 BZERO(secret,
sizeof(secret));
1761 have_pap_secret(lacks_ipp)
1767 struct wordlist *addrs;
1770 if (pap_check_hook) {
1771 ret = (*pap_check_hook)();
1776 filename = _PATH_UPAPFILE;
1777 f = fopen(filename,
"r");
1781 ret = scan_authfile(f, (explicit_remote? remote_name: NULL), our_name,
1782 NULL, &addrs, NULL, filename, 0);
1784 if (ret >= 0 && !some_ip_ok(addrs)) {
1790 free_wordlist(addrs);
1802 have_chap_secret(client, server, need_ip, lacks_ipp)
1811 struct wordlist *addrs;
1813 if (chap_check_hook) {
1814 ret = (*chap_check_hook)();
1820 filename = _PATH_CHAPFILE;
1821 f = fopen(filename,
"r");
1825 if (client != NULL && client[0] == 0)
1827 else if (server != NULL && server[0] == 0)
1830 ret = scan_authfile(f, client, server, NULL, &addrs, NULL, filename, 0);
1832 if (ret >= 0 && need_ip && !some_ip_ok(addrs)) {
1838 free_wordlist(addrs);
1850 have_srp_secret(client, server, need_ip, lacks_ipp)
1859 struct wordlist *addrs;
1861 filename = _PATH_SRPFILE;
1862 f = fopen(filename,
"r");
1866 if (client != NULL && client[0] == 0)
1868 else if (server != NULL && server[0] == 0)
1871 ret = scan_authfile(f, client, server, NULL, &addrs, NULL, filename, 0);
1873 if (ret >= 0 && need_ip && !some_ip_ok(addrs)) {
1879 free_wordlist(addrs);
1885 #if PPP_AUTH_SUPPORT 1891 int get_secret(ppp_pcb *pcb,
const char *client,
const char *server,
char *secret,
int *secret_len,
int am_server) {
1896 if (!client || !client[0] || !pcb->settings.user || !pcb->settings.passwd || strcmp(client, pcb->settings.user)) {
1900 len = (int)strlen(pcb->settings.passwd);
1901 if (len > MAXSECRETLEN) {
1902 ppp_error(
"Secret for %s on %s is too long", client, server);
1906 MEMCPY(secret, pcb->settings.passwd, len);
1914 struct wordlist *addrs, *opts;
1915 char secbuf[MAXWORDLEN];
1916 struct wordlist *addrs;
1919 if (!am_server && ppp_settings.passwd[0] != 0) {
1920 strlcpy(secbuf, ppp_settings.passwd,
sizeof(secbuf));
1921 }
else if (!am_server && chap_passwd_hook) {
1922 if ( (*chap_passwd_hook)(client, secbuf) < 0) {
1923 ppp_error(
"Unable to obtain CHAP password for %s on %s from plugin",
1928 filename = _PATH_CHAPFILE;
1932 f = fopen(filename,
"r");
1934 ppp_error(
"Can't open chap secret file %s: %m", filename);
1937 check_access(f, filename);
1939 ret = scan_authfile(f, client, server, secbuf, &addrs, &opts, filename, 0);
1945 set_allowed_addrs(unit, addrs, opts);
1947 free_wordlist(opts);
1949 free_wordlist(addrs);
1952 len = strlen(secbuf);
1953 if (len > MAXSECRETLEN) {
1954 ppp_error(
"Secret for %s on %s is too long", client, server);
1957 MEMCPY(secret, secbuf, len);
1958 BZERO(secbuf,
sizeof(secbuf));
1974 get_srp_secret(unit, client, server, secret, am_server)
1984 struct wordlist *addrs, *opts;
1986 if (!am_server && ppp_settings.passwd[0] !=
'\0') {
1987 strlcpy(secret, ppp_settings.passwd, MAXWORDLEN);
1989 filename = _PATH_SRPFILE;
1992 fp = fopen(filename,
"r");
1994 ppp_error(
"Can't open srp secret file %s: %m", filename);
1997 check_access(fp, filename);
2000 ret = scan_authfile(fp, client, server, secret, &addrs, &opts,
2001 filename, am_server);
2007 set_allowed_addrs(unit, addrs, opts);
2008 else if (opts != NULL)
2009 free_wordlist(opts);
2011 free_wordlist(addrs);
2023 set_allowed_addrs(unit, addrs, opts)
2025 struct wordlist *addrs;
2026 struct wordlist *opts;
2029 struct wordlist *ap, **plink;
2030 struct permitted_ip *ip;
2031 char *ptr_word, *ptr_mask;
2034 u32_t a, mask, ah, offset;
2035 struct ipcp_options *wo = &ipcp_wantoptions[unit];
2036 u32_t suggested_ip = 0;
2038 if (addresses[unit] != NULL)
2039 free(addresses[unit]);
2040 addresses[unit] =
NULL;
2041 if (extra_options != NULL)
2042 free_wordlist(extra_options);
2043 extra_options = opts;
2048 n = wordlist_count(addrs) + wordlist_count(noauth_addrs);
2051 ip = (
struct permitted_ip *) malloc((n + 1) *
sizeof(
struct permitted_ip));
2056 for (plink = &addrs; *plink !=
NULL; plink = &(*plink)->next)
2058 *plink = noauth_addrs;
2061 for (ap = addrs; ap !=
NULL; ap = ap->next) {
2063 ptr_word = ap->word;
2064 if (strcmp(ptr_word,
"-") == 0)
2066 if (strcmp(ptr_word,
"*") == 0) {
2068 ip[n].base = ip[n].mask = 0;
2074 if (*ptr_word ==
'!') {
2081 ptr_mask = strchr (ptr_word,
'/');
2082 if (ptr_mask != NULL) {
2086 bit_count = (int) strtol (ptr_mask+1, &endp, 10);
2087 if (bit_count <= 0 || bit_count > 32) {
2088 ppp_warn(
"invalid address length %v in auth. address list",
2092 bit_count = 32 - bit_count;
2094 offset = ifunit + 1;
2098 ppp_warn(
"invalid address length syntax: %v", ptr_mask+1);
2105 hp = gethostbyname(ptr_word);
2106 if (hp != NULL && hp->h_addrtype == AF_INET) {
2107 a = *(
u32_t *)hp->h_addr;
2109 np = getnetbyname (ptr_word);
2110 if (np != NULL && np->n_addrtype == AF_INET) {
2112 if (ptr_mask == NULL) {
2123 a = inet_addr (ptr_word);
2127 if (ptr_mask != NULL)
2130 if (a == (
u32_t)-1L) {
2131 ppp_warn(
"unknown host %s in auth. address list", ap->word);
2135 if (offset >= ~mask) {
2136 ppp_warn(
"interface unit %d too large for subnet %v",
2143 ip[n].mask =
htonl(mask);
2144 ip[n].base = a & ip[n].mask;
2146 if (~mask == 0 && suggested_ip == 0)
2155 addresses[unit] = ip;
2162 if (suggested_ip != 0
2163 && (wo->hisaddr == 0 || !auth_ip_addr(unit, wo->hisaddr))) {
2164 wo->hisaddr = suggested_ip;
2170 wo->accept_remote = 1;
2179 auth_ip_addr(unit, addr)
2186 if (bad_ip_adrs(addr))
2189 if (allowed_address_hook) {
2190 ok = allowed_address_hook(addr);
2191 if (ok >= 0)
return ok;
2194 if (addresses[unit] != NULL) {
2195 ok = ip_addr_check(addr, addresses[unit]);
2202 return allow_any_ip || privileged || !have_route_to(addr);
2206 ip_addr_check(addr, addrs)
2208 struct permitted_ip *addrs;
2211 if ((addr & addrs->mask) == addrs->base)
2212 return addrs->permit;
2235 struct wordlist *addrs;
2237 for (; addrs != 0; addrs = addrs->next) {
2238 if (addrs->word[0] ==
'-')
2240 if (addrs->word[0] !=
'!')
2253 struct wordlist *wp = permitted_numbers;
2263 l = strlen(wp->word);
2264 if ((wp->word)[l - 1] ==
'*')
2266 if (!strncasecmp(wp->word, remote_number, l))
2278 check_access(f, filename)
2284 if (fstat(fileno(f), &sbuf) < 0) {
2285 ppp_warn(
"cannot stat secret file %s: %m", filename);
2286 }
else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
2287 ppp_warn(
"Warning - secret file %s has world and/or group access",
2307 scan_authfile(f, client, server, secret, addrs, opts, filename, flags)
2312 struct wordlist **addrs;
2313 struct wordlist **opts;
2318 int got_flag, best_flag;
2320 struct wordlist *ap, *addr_list, *alist, **app;
2321 char word[MAXWORDLEN];
2322 char atfile[MAXWORDLEN];
2323 char lsecret[MAXWORDLEN];
2331 if (!getword(f, word, &newline, filename))
2339 while (!newline && getword(f, word, &newline, filename))
2348 if (client != NULL && strcmp(word, client) != 0 && !ISWILD(word)) {
2353 got_flag = NONWILD_CLIENT;
2358 if (!getword(f, word, &newline, filename))
2362 if (!ISWILD(word)) {
2363 if (server != NULL && strcmp(word, server) != 0)
2365 got_flag |= NONWILD_SERVER;
2372 if (got_flag <= best_flag)
2378 if (!getword(f, word, &newline, filename))
2387 if (flags && ((cp = strchr(word,
':')) == NULL ||
2388 strchr(cp + 1,
':') == NULL))
2391 if (secret != NULL) {
2395 if (word[0] ==
'@' && word[1] ==
'/') {
2396 strlcpy(atfile, word+1,
sizeof(atfile));
2397 if ((sf = fopen(atfile,
"r")) == NULL) {
2398 ppp_warn(
"can't open indirect secret file %s", atfile);
2401 check_access(sf, atfile);
2402 if (!getword(sf, word, &xxx, atfile)) {
2403 ppp_warn(
"no secret in indirect secret file %s", atfile);
2409 strlcpy(lsecret, word,
sizeof(lsecret));
2417 if (!getword(f, word, &newline, filename) || newline)
2419 ap = (
struct wordlist *)
2420 malloc(
sizeof(
struct wordlist) + strlen(word) + 1);
2422 novm(
"authorized addresses");
2423 ap->word = (
char *) (ap + 1);
2424 strcpy(ap->word, word);
2433 best_flag = got_flag;
2435 free_wordlist(addr_list);
2438 strlcpy(secret, lsecret, MAXWORDLEN);
2445 for (app = &addr_list; (ap = *app) != NULL; app = &ap->next)
2446 if (strcmp(ap->word,
"--") == 0)
2456 else if (ap != NULL)
2460 else if (addr_list != NULL)
2461 free_wordlist(addr_list);
2471 struct wordlist *wp;
2475 for (n = 0; wp !=
NULL; wp = wp->next)
2485 struct wordlist *wp;
2487 struct wordlist *next;
2489 while (wp != NULL) {
#define MEMCPY(dst, src, len)
#define LWIP_UNUSED_ARG(x)