📄 auth.c
字号:
char **argv;{ char *number = *argv; int l = strlen(number) + 1; struct wordlist *wp; wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l); if (wp == NULL) novm("allow-number argument"); wp->word = (char *) (wp + 1); wp->next = permitted_numbers; BCOPY(number, wp->word, l); permitted_numbers = wp; return 1;}#endif /* INCLUDE *//* * An Open on LCP has requested a change from Dead to Establish phase. */voidlink_required(unit) int unit;{}/* * Bring the link up to the point of being able to do ppp. */void start_link(unit) int unit;{ char *msg; new_phase(PHASE_SERIALCONN); devfd = the_channel->connect(); msg = "Connect script failed"; if (devfd < 0) goto fail; /* set up the serial device as a ppp interface */ /* * N.B. we used to do tdb_writelock/tdb_writeunlock around this * (from establish_ppp to set_ifunit). However, we won't be * doing the set_ifunit in multilink mode, which is the only time * we need the atomicity that the tdb_writelock/tdb_writeunlock * gives us. Thus we don't need the tdb_writelock/tdb_writeunlock. */ fd_ppp = the_channel->establish_ppp(devfd); msg = "ppp establishment failed"; if (fd_ppp < 0) { status = EXIT_FATAL_ERROR; goto disconnect; } if (!demand && ifunit >= 0) set_ifunit(1); /* * Start opening the connection and wait for * incoming events (reply, timeout, etc.). */ if (ifunit >= 0) notice("Connect: %s <--> %s", ifname, ppp_devnam); else notice("Starting negotiation on %s", ppp_devnam); add_fd(fd_ppp); status = EXIT_NEGOTIATION_FAILED; new_phase(PHASE_ESTABLISH); lcp_lowerup(0); return; disconnect: new_phase(PHASE_DISCONNECT); if (the_channel->disconnect) the_channel->disconnect(); fail: new_phase(PHASE_DEAD); if (the_channel->cleanup) (*the_channel->cleanup)();}/* * LCP has terminated the link; go to the Dead phase and take the * physical layer down. */voidlink_terminated(unit) int unit;{ if (phase == PHASE_DEAD || phase == PHASE_MASTER) return; new_phase(PHASE_DISCONNECT); if (pap_logout_hook) { pap_logout_hook(); } else { /*/if (logged_in) plogout();*/ } if (!doing_multilink) { notice("Connection terminated."); print_link_stats(); } else notice("Link terminated."); /* * Delete pid files before disestablishing ppp. Otherwise it * can happen that another pppd gets the same unit and then * we delete its pid file. */ if (!doing_multilink && !demand) remove_pidfiles(); /* * If we may want to bring the link up again, transfer * the ppp unit back to the loopback. Set the * real serial device back to its normal mode of operation. */ if (fd_ppp >= 0) { remove_fd(fd_ppp); clean_check(); the_channel->disestablish_ppp(devfd); if (doing_multilink) mp_exit_bundle(); fd_ppp = -1; } if (!hungup) lcp_lowerdown(0); if (!doing_multilink && !demand) script_unsetenv("IFNAME"); /* * Run disconnector script, if requested. * XXX we may not be able to do this if the line has hung up! */ if (devfd >= 0 && the_channel->disconnect) { the_channel->disconnect(); devfd = -1; } if (the_channel->cleanup) (*the_channel->cleanup)(); if (doing_multilink && multilink_master) { if (!bundle_terminating) new_phase(PHASE_MASTER); else mp_bundle_terminated(); } else new_phase(PHASE_DEAD);}/* * LCP has gone down; it will either die or try to re-establish. */voidlink_down(unit) int unit;{ if (auth_state != s_down) { notify(link_down_notifier, 0); auth_state = s_down; if (auth_script_state == s_up && auth_script_pid == 0) { update_link_stats(unit); auth_script_state = s_down; auth_script(_PATH_AUTHDOWN); } } if (!doing_multilink) { upper_layers_down(unit); if (phase != PHASE_DEAD && phase != PHASE_MASTER) new_phase(PHASE_ESTABLISH); } /* XXX if doing_multilink, should do something to stop network-layer traffic on the link */}void upper_layers_down(int unit){ int i; struct protent *protp; for (i = 0; (protp = protocols[i]) != NULL; ++i) { if (!protp->enabled_flag) continue; if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) (*protp->lowerdown)(unit); if (protp->protocol < 0xC000 && protp->close != NULL) (*protp->close)(unit, "LCP down"); } num_np_open = 0; num_np_up = 0;}/* * The link is established. * Proceed to the Dead, Authenticate or Network phase as appropriate. */voidlink_established(unit) int unit;{ int auth; lcp_options *wo = &lcp_wantoptions[unit]; lcp_options *go = &lcp_gotoptions[unit]; lcp_options *ho = &lcp_hisoptions[unit]; int i; struct protent *protp; /* * Tell higher-level protocols that LCP is up. */ if (!doing_multilink) { for (i = 0; (protp = protocols[i]) != NULL; ++i) if (protp->protocol != PPP_LCP && protp->enabled_flag && protp->lowerup != NULL) (*protp->lowerup)(unit); } if (!auth_required && noauth_addrs != NULL) ;//set_allowed_addrs(unit, NULL, NULL); if (auth_required && !(go->neg_upap || go->neg_chap || go->neg_eap)) { /* * We wanted the peer to authenticate itself, and it refused: * if we have some address(es) it can use without auth, fine, * otherwise treat it as though it authenticated with PAP using * a username of "" and a password of "". If that's not OK, * boot it out. */ if (noauth_addrs != NULL) { ;//set_allowed_addrs(unit, NULL, NULL); //} else if (!wo->neg_upap || uselogin || !null_login(unit)) { } else if (!wo->neg_upap || uselogin) { warn("peer refused to authenticate: terminating link"); status = EXIT_PEER_AUTH_FAILED; lcp_close(unit, "peer refused to authenticate"); return; } } new_phase(PHASE_AUTHENTICATE); used_login = 0; auth = 0; /*/if (go->neg_eap) { eap_authpeer(unit, our_name); auth |= EAP_PEER; } else if (go->neg_chap) { chap_auth_peer(unit, our_name, CHAP_DIGEST(go->chap_mdtype)); auth |= CHAP_PEER; } else */if (go->neg_upap) { upap_authpeer(unit); auth |= PAP_PEER; } /*/if (ho->neg_eap) { eap_authwithpeer(unit, user); auth |= EAP_WITHPEER; } else if (ho->neg_chap) { chap_auth_with_peer(unit, user, CHAP_DIGEST(ho->chap_mdtype)); auth |= CHAP_WITHPEER; } else */if (ho->neg_upap) { /*/if (passwd[0] == 0) { passwd_from_file = 1; if (!get_pap_passwd(passwd)) error("No secret found for PAP login"); }*/ upap_authwithpeer(unit, user, passwd); auth |= PAP_WITHPEER; } auth_pending[unit] = auth; auth_done[unit] = 0; if (!auth) network_phase(unit);}/* * Proceed to the network phase. */static voidnetwork_phase(unit) int unit;{ lcp_options *go = &lcp_gotoptions[unit]; /* Log calling number. */ if (*remote_number) notice("peer from calling number %q authorized", remote_number); /* * If the peer had to authenticate, run the auth-up script now. */ if (go->neg_chap || go->neg_upap || go->neg_eap) { notify(auth_up_notifier, 0); auth_state = s_up; if (auth_script_state == s_down && auth_script_pid == 0) { auth_script_state = s_up; auth_script(_PATH_AUTHUP); } }#ifdef CBCP_SUPPORT /* * If we negotiated callback, do it now. */ if (go->neg_cbcp) { new_phase(PHASE_CALLBACK); (*cbcp_protent.open)(unit); return; }#endif /* * Process extra options from the secrets file */ /*if (extra_options) { options_from_list(extra_options, 1); free_wordlist(extra_options); extra_options = 0; }*/ start_networks(unit);}voidstart_networks(unit) int unit;{ int i; struct protent *protp; int ecp_required, mppe_required; new_phase(PHASE_NETWORK);#ifdef HAVE_MULTILINK if (multilink) { if (mp_join_bundle()) { if (updetach && !nodetach) detach(); return; } }#endif /* HAVE_MULTILINK */#ifdef PPP_FILTER if (!demand) set_filters(&pass_filter, &active_filter);#endif /* Start CCP and ECP */ for (i = 0; (protp = protocols[i]) != NULL; ++i) if ((protp->protocol == PPP_ECP || protp->protocol == PPP_CCP) && protp->enabled_flag && protp->open != NULL) (*protp->open)(0); /* * Bring up other network protocols iff encryption is not required. */ //ecp_required = ecp_gotoptions[unit].required; mppe_required = ccp_gotoptions[unit].mppe; if (!ecp_required && !mppe_required) continue_networks(unit);}voidcontinue_networks(unit) int unit;{ int i; struct protent *protp; /* * Start the "real" network protocols. */ for (i = 0; (protp = protocols[i]) != NULL; ++i) if (protp->protocol < 0xC000 && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP && protp->enabled_flag && protp->open != NULL) { (*protp->open)(0); ++num_np_open; } if (num_np_open == 0) /* nothing to do */ lcp_close(0, "No network protocols running");}/* * The peer has failed to authenticate himself using `protocol'. */voidauth_peer_fail(unit, protocol) int unit, protocol;{ /* * Authentication failure: take the link down */ status = EXIT_PEER_AUTH_FAILED; lcp_close(unit, "Authentication failed");}/* * The peer has been successfully authenticated using `protocol'. */voidauth_peer_success(unit, protocol, prot_flavor, name, namelen) int unit, protocol, prot_flavor; char *name; int namelen;{ int bit; switch (protocol) { case PPP_CHAP: bit = CHAP_PEER; switch (prot_flavor) { case CHAP_MD5: bit |= CHAP_MD5_PEER; break;#ifdef CHAPMS case CHAP_MICROSOFT: bit |= CHAP_MS_PEER; break; case CHAP_MICROSOFT_V2: bit |= CHAP_MS2_PEER; break;#endif } break; case PPP_PAP: bit = PAP_PEER; break; case PPP_EAP: bit = EAP_PEER; break; default: warn("auth_peer_success: unknown protocol %x", protocol); return; } /* * Save the authenticated name of the peer for later. */ if (namelen > sizeof(peer_authname) - 1) namelen = sizeof(peer_authname) - 1; BCOPY(name, peer_authname, namelen); peer_authname[namelen] = 0; script_setenv("PEERNAME", peer_authname, 0); /* Save the authentication method for later. */ auth_done[unit] |= bit; /* * If there is no more authentication still to be done, * proceed to the network (or callback) phase. */ if ((auth_pending[unit] &= ~bit) == 0) network_phase(unit);}/* * We have failed to authenticate ourselves to the peer using `protocol'. */voidauth_withpeer_fail(unit, protocol) int unit, protocol;{ if (passwd_from_file) BZERO(passwd, MAXSECRETLEN); /* * We've failed to authenticate ourselves to our peer. * Some servers keep sending CHAP challenges, but there * is no point in persisting without any way to get updated * authentication secrets. */ status = EXIT_AUTH_TOPEER_FAILED; lcp_close(unit, "Failed to authenticate ourselves to peer");}/* * We have successfully authenticated ourselves with the peer using `protocol'. */voidauth_withpeer_success(unit, protocol, prot_flavor) int unit, protocol, prot_flavor;{ int bit; const char *prot = ""; switch (protocol) { case PPP_CHAP: bit = CHAP_WITHPEER; prot = "CHAP"; switch (prot_flavor) { case CHAP_MD5: bit |= CHAP_MD5_WITHPEER; break;#ifdef CHAPMS case CHAP_MICROSOFT: bit |= CHAP_MS_WITHPEER; break; case CHAP_MICROSOFT_V2: bit |= CHAP_MS2_WITHPEER; break;#endif } break; case PPP_PAP: if (passwd_from_file) BZERO(passwd, MAXSECRETLEN); bit = PAP_WITHPEER; prot = "PAP"; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -