2 * auth.c - PPP authentication and phase control.
4 * Copyright (c) 1993 The Australian National University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the Australian National University. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 * Copyright (c) 1989 Carnegie Mellon University.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms are permitted
23 * provided that the above copyright notice and this paragraph are
24 * duplicated in all such forms and that any documentation,
25 * advertising materials, and other materials related to such
26 * distribution and use acknowledge that the software was developed
27 * by Carnegie Mellon University. The name of the
28 * University may not be used to endorse or promote products derived
29 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
32 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
35 #define RCSID "$Id: auth.c,v 1.80 2002/07/16 13:11:43 kad Exp $"
44 #include <sys/types.h>
46 #include <sys/socket.h>
49 #if defined(_PATH_LASTLOG) && defined(_linux_)
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
58 #include <security/pam_appl.h>
64 #define PW_PPP PW_LOGIN
80 #include "pathnames.h"
82 static const char rcsid[] = RCSID;
84 /* Bits in scan_authfile return value */
85 #define NONWILD_SERVER 1
86 #define NONWILD_CLIENT 2
88 #define ISWILD(word) (word[0] == '*' && word[1] == 0)
90 /* The name by which the peer authenticated itself to us. */
91 char peer_authname[MAXNAMELEN];
93 /* Records which authentication operations haven't completed yet. */
94 static int auth_pending[NUM_PPP];
96 /* Records which authentication operations have been completed. */
97 int auth_done[NUM_PPP];
99 /* Set if we have successfully called plogin() */
100 static int logged_in;
102 /* List of addresses which the peer may use. */
103 static struct permitted_ip *addresses[NUM_PPP];
105 /* Wordlist giving addresses which the peer may use
106 without authenticating itself. */
107 static struct wordlist *noauth_addrs;
109 /* Extra options to apply, from the secrets file entry for the peer. */
110 static struct wordlist *extra_options;
112 /* Number of network protocols which we have opened. */
113 static int num_np_open;
115 /* Number of network protocols which have come up. */
116 static int num_np_up;
118 /* Set if we got the contents of passwd[] from the pap-secrets file. */
119 static int passwd_from_file;
121 /* Set if we require authentication only because we have a default route. */
122 static bool default_auth;
124 /* Hook to enable a plugin to control the idle time limit */
125 int (*idle_time_hook) __P((struct ppp_idle *)) = NULL;
127 /* Hook for a plugin to say whether we can possibly authenticate any peer */
128 int (*pap_check_hook) __P((void)) = NULL;
130 /* Hook for a plugin to check the PAP user and password */
131 int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
132 struct wordlist **paddrs,
133 struct wordlist **popts)) = NULL;
135 /* Hook for a plugin to know about the PAP user logout */
136 void (*pap_logout_hook) __P((void)) = NULL;
138 /* Hook for a plugin to get the PAP password for authenticating us */
139 int (*pap_passwd_hook) __P((char *user, char *passwd)) = NULL;
141 /* Hook for a plugin to say whether it is OK if the peer
142 refuses to authenticate. */
143 int (*null_auth_hook) __P((struct wordlist **paddrs,
144 struct wordlist **popts)) = NULL;
146 int (*allowed_address_hook) __P((u_int32_t addr)) = NULL;
148 /* A notifier for when the peer has authenticated itself,
149 and we are proceeding to the network phase. */
150 struct notifier *auth_up_notifier = NULL;
152 /* A notifier for when the link goes down. */
153 struct notifier *link_down_notifier = NULL;
156 * This is used to ensure that we don't start an auth-up/down
157 * script while one is already running.
164 static enum script_state auth_state = s_down;
165 static enum script_state auth_script_state = s_down;
166 static pid_t auth_script_pid = 0;
168 static int used_login; /* peer authenticated against login database */
173 bool uselogin = 0; /* Use /etc/passwd for checking PAP */
174 bool cryptpap = 0; /* Passwords in pap-secrets are encrypted */
175 bool refuse_pap = 0; /* Don't wanna auth. ourselves with PAP */
176 bool refuse_chap = 0; /* Don't wanna auth. ourselves with CHAP */
178 bool refuse_mschap = 0; /* Don't wanna auth. ourselves with MS-CHAP */
179 bool refuse_mschap_v2 = 0; /* Don't wanna auth. ourselves with MS-CHAPv2 */
181 bool refuse_mschap = 1; /* Don't wanna auth. ourselves with MS-CHAP */
182 bool refuse_mschap_v2 = 1; /* Don't wanna auth. ourselves with MS-CHAPv2 */
184 bool usehostname = 0; /* Use hostname for our_name */
185 bool auth_required = 0; /* Always require authentication from peer */
186 bool allow_any_ip = 0; /* Allow peer to use any IP address */
187 bool explicit_remote = 0; /* User specified explicit remote name */
188 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
190 static char *uafname; /* name of most recent +ua file */
192 extern char *crypt __P((const char *, const char *));
194 /* Prototypes for procedures local to this file. */
196 static void network_phase __P((int));
197 static void check_idle __P((void *));
198 static void connect_time_expired __P((void *));
199 static int plogin __P((char *, char *, char **));
200 static void plogout __P((void));
201 static int null_login __P((int));
202 static int get_pap_passwd __P((char *));
203 static int have_pap_secret __P((int *));
204 static int have_chap_secret __P((char *, char *, int, int *));
205 static int ip_addr_check __P((u_int32_t, struct permitted_ip *));
206 static int scan_authfile __P((FILE *, char *, char *, char *,
207 struct wordlist **, struct wordlist **,
209 static void free_wordlist __P((struct wordlist *));
210 static void auth_script __P((char *));
211 static void auth_script_done __P((void *));
212 static void set_allowed_addrs __P((int, struct wordlist *, struct wordlist *));
213 static int some_ip_ok __P((struct wordlist *));
214 static int setupapfile __P((char **));
215 static int privgroup __P((char **));
216 static int set_noauth_addr __P((char **));
217 static void check_access __P((FILE *, char *));
218 static int wordlist_count __P((struct wordlist *));
221 static void check_maxoctets __P((void *));
225 * Authentication-related options.
227 option_t auth_options[] = {
228 { "auth", o_bool, &auth_required,
229 "Require authentication from peer", OPT_PRIO | 1 },
230 { "noauth", o_bool, &auth_required,
231 "Don't require peer to authenticate", OPT_PRIOSUB | OPT_PRIV | OPT_A2COPY,
233 { "require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
234 "Require PAP authentication from peer",
235 OPT_PRIOSUB | OPT_A2COPY | 1, &auth_required },
236 { "+pap", o_bool, &lcp_wantoptions[0].neg_upap,
237 "Require PAP authentication from peer",
238 OPT_ALIAS | OPT_PRIOSUB | OPT_A2COPY | 1, &auth_required },
239 { "require-chap", o_bool, &lcp_wantoptions[0].neg_chap,
240 "Require CHAP authentication from peer",
241 OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MD5,
242 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
243 { "+chap", o_bool, &lcp_wantoptions[0].neg_chap,
244 "Require CHAP authentication from peer",
245 OPT_ALIAS | OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MD5,
246 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
248 { "require-mschap", o_bool, &lcp_wantoptions[0].neg_chap,
249 "Require MS-CHAP authentication from peer",
250 OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MICROSOFT,
251 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
252 { "+mschap", o_bool, &lcp_wantoptions[0].neg_chap,
253 "Require MS-CHAP authentication from peer",
254 OPT_ALIAS | OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MICROSOFT,
255 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
256 { "require-mschap-v2", o_bool, &lcp_wantoptions[0].neg_chap,
257 "Require MS-CHAPv2 authentication from peer",
258 OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MICROSOFT_V2,
259 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
260 { "+mschap-v2", o_bool, &lcp_wantoptions[0].neg_chap,
261 "Require MS-CHAPv2 authentication from peer",
262 OPT_ALIAS | OPT_PRIOSUB | OPT_A2COPY | OPT_A3OR | MDTYPE_MICROSOFT_V2,
263 &auth_required, 0, 0, NULL, 0, 0, &lcp_wantoptions[0].chap_mdtype },
266 { "refuse-pap", o_bool, &refuse_pap,
267 "Don't agree to auth to peer with PAP", 1 },
268 { "-pap", o_bool, &refuse_pap,
269 "Don't allow PAP authentication with peer", OPT_ALIAS | 1 },
270 { "refuse-chap", o_bool, &refuse_chap,
271 "Don't agree to auth to peer with CHAP", OPT_A2CLRB | MDTYPE_MD5,
272 &lcp_allowoptions[0].chap_mdtype },
273 { "-chap", o_bool, &refuse_chap,
274 "Don't allow CHAP authentication with peer",
275 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MD5,
276 &lcp_allowoptions[0].chap_mdtype },
278 { "refuse-mschap", o_bool, &refuse_mschap,
279 "Don't agree to auth to peer with MS-CHAP",
280 OPT_A2CLRB | MDTYPE_MICROSOFT, &lcp_allowoptions[0].chap_mdtype },
281 { "-mschap", o_bool, &refuse_mschap,
282 "Don't allow MS-CHAP authentication with peer",
283 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MICROSOFT,
284 &lcp_allowoptions[0].chap_mdtype },
285 { "refuse-mschap-v2", o_bool, &refuse_mschap_v2,
286 "Don't agree to auth to peer with MS-CHAPv2",
287 OPT_A2CLRB | MDTYPE_MICROSOFT_V2, &lcp_allowoptions[0].chap_mdtype },
288 { "-mschap-v2", o_bool, &refuse_mschap_v2,
289 "Don't allow MS-CHAPv2 authentication with peer",
290 OPT_ALIAS | OPT_A2CLRB | MDTYPE_MICROSOFT_V2,
291 &lcp_allowoptions[0].chap_mdtype },
294 { "name", o_string, our_name,
295 "Set local name for authentication",
296 OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXNAMELEN },
298 { "+ua", o_special, (void *)setupapfile,
299 "Get PAP user and password from file",
300 OPT_PRIO | OPT_A2STRVAL, &uafname },
302 { "user", o_string, user,
303 "Set name for auth with peer", OPT_PRIO | OPT_STATIC, NULL, MAXNAMELEN },
305 { "password", o_string, passwd,
306 "Password for authenticating us to the peer",
307 OPT_PRIO | OPT_STATIC | OPT_HIDE, NULL, MAXSECRETLEN },
309 { "usehostname", o_bool, &usehostname,
310 "Must use hostname for authentication", 1 },
312 { "remotename", o_string, remote_name,
313 "Set remote name for authentication", OPT_PRIO | OPT_STATIC,
314 &explicit_remote, MAXNAMELEN },
316 { "login", o_bool, &uselogin,
317 "Use system password database for PAP", 1 },
319 { "papcrypt", o_bool, &cryptpap,
320 "PAP passwords are encrypted", 1 },
322 { "privgroup", o_special, (void *)privgroup,
323 "Allow group members to use privileged options", OPT_PRIV | OPT_A2LIST },
325 { "allow-ip", o_special, (void *)set_noauth_addr,
326 "Set IP address(es) which can be used without authentication",
327 OPT_PRIV | OPT_A2LIST },
333 * setupapfile - specifies UPAP info for authenticating with peer.
341 char u[MAXNAMELEN], p[MAXSECRETLEN];
344 lcp_allowoptions[0].neg_upap = 1;
346 /* open user info file */
347 fname = strdup(*argv);
349 novm("+ua file name");
351 ufile = fopen(fname, "r");
354 option_error("unable to open user login data file %s", fname);
357 check_access(ufile, fname);
361 if (fgets(u, MAXNAMELEN - 1, ufile) == NULL
362 || fgets(p, MAXSECRETLEN - 1, ufile) == NULL){
363 option_error("unable to read user login data file %s", fname);
368 /* get rid of newlines */
370 if (l > 0 && u[l-1] == '\n')
373 if (l > 0 && p[l-1] == '\n')
376 if (override_value("user", option_priority, fname))
377 strlcpy(user, u, sizeof(user));
378 if (override_value("passwd", option_priority, fname))
379 strlcpy(passwd, p, sizeof(passwd));
386 * privgroup - allow members of the group to have privileged access.
397 option_error("group %s is unknown", *argv);
400 for (i = 0; i < ngroups; ++i) {
401 if (groups[i] == g->gr_gid) {
411 * set_noauth_addr - set address(es) that can be used without authentication.
412 * Equivalent to specifying an entry like `"" * "" addr' in pap-secrets.
415 set_noauth_addr(argv)
419 int l = strlen(addr) + 1;
422 wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l);
424 novm("allow-ip argument");
425 wp->word = (char *) (wp + 1);
426 wp->next = noauth_addrs;
427 BCOPY(addr, wp->word, l);
434 * An Open on LCP has requested a change from Dead to Establish phase.
435 * Do what's necessary to bring the physical layer up.
444 * LCP has terminated the link; go to the Dead phase and take the
445 * physical layer down.
448 link_terminated(unit)
451 if (phase == PHASE_DEAD)
453 if (pap_logout_hook) {
459 new_phase(PHASE_DEAD);
460 notice("Connection terminated.");
464 * LCP has gone down; it will either die or try to re-establish.
471 struct protent *protp;
473 notify(link_down_notifier, 0);
475 if (auth_script_state == s_up && auth_script_pid == 0) {
476 update_link_stats(unit);
477 auth_script_state = s_down;
478 auth_script(_PATH_AUTHDOWN);
480 for (i = 0; (protp = protocols[i]) != NULL; ++i) {
481 if (!protp->enabled_flag)
483 if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
484 (*protp->lowerdown)(unit);
485 if (protp->protocol < 0xC000 && protp->close != NULL)
486 (*protp->close)(unit, "LCP down");
490 if (phase != PHASE_DEAD)
491 new_phase(PHASE_ESTABLISH);
495 * The link is established.
496 * Proceed to the Dead, Authenticate or Network phase as appropriate.
499 link_established(unit)
503 lcp_options *wo = &lcp_wantoptions[unit];
504 lcp_options *go = &lcp_gotoptions[unit];
505 lcp_options *ho = &lcp_hisoptions[unit];
507 struct protent *protp;
510 * Tell higher-level protocols that LCP is up.
512 for (i = 0; (protp = protocols[i]) != NULL; ++i)
513 if (protp->protocol != PPP_LCP && protp->enabled_flag
514 && protp->lowerup != NULL)
515 (*protp->lowerup)(unit);
517 if (auth_required && !(go->neg_upap || go->neg_chap)) {
519 * We wanted the peer to authenticate itself, and it refused:
520 * if we have some address(es) it can use without auth, fine,
521 * otherwise treat it as though it authenticated with PAP using
522 * a username of "" and a password of "". If that's not OK,
525 if (noauth_addrs != NULL) {
526 set_allowed_addrs(unit, NULL, NULL);
527 } else if (!wo->neg_upap || uselogin || !null_login(unit)) {
528 warn("peer refused to authenticate: terminating link");
529 lcp_close(unit, "peer refused to authenticate");
530 status = EXIT_PEER_AUTH_FAILED;
535 new_phase(PHASE_AUTHENTICATE);
539 ChapAuthPeer(unit, our_name, CHAP_DIGEST(go->chap_mdtype));
541 } else if (go->neg_upap) {
546 ChapAuthWithPeer(unit, user, CHAP_DIGEST(ho->chap_mdtype));
547 auth |= CHAP_WITHPEER;
548 } else if (ho->neg_upap) {
549 if (passwd[0] == 0) {
550 passwd_from_file = 1;
551 if (!get_pap_passwd(passwd))
552 error("No secret found for PAP login");
554 upap_authwithpeer(unit, user, passwd);
555 auth |= PAP_WITHPEER;
557 auth_pending[unit] = auth;
565 * Proceed to the network phase.
571 lcp_options *go = &lcp_gotoptions[unit];
574 * If the peer had to authenticate, run the auth-up script now.
576 if (go->neg_chap || go->neg_upap) {
577 notify(auth_up_notifier, 0);
579 if (auth_script_state == s_down && auth_script_pid == 0) {
580 auth_script_state = s_up;
581 auth_script(_PATH_AUTHUP);
587 * If we negotiated callback, do it now.
590 new_phase(PHASE_CALLBACK);
591 (*cbcp_protent.open)(unit);
597 * Process extra options from the secrets file
600 options_from_list(extra_options, 1);
601 free_wordlist(extra_options);
604 start_networks(unit);
611 static int started = 0;
613 struct protent *protp;
614 int ecp_required, mppe_required;
618 new_phase(PHASE_NETWORK);
620 #ifdef HAVE_MULTILINK
622 if (mp_join_bundle()) {
623 if (updetach && !nodetach)
628 #endif /* HAVE_MULTILINK */
632 set_filters(&pass_filter, &active_filter);
634 /* Start CCP and ECP */
635 for (i = 0; (protp = protocols[i]) != NULL; ++i)
636 if ((protp->protocol == PPP_ECP || protp->protocol == PPP_CCP)
637 && protp->enabled_flag && protp->open != NULL)
642 * Bring up other network protocols after encryption has completed.
643 * OPENED here merely means that negotiation has completed. It is
644 * up to the protocol to correctly terminate or disable LCP/NCP
645 * based on the result of the negotiation.
647 ecp_required = ecp_gotoptions[unit].required;
648 mppe_required = ccp_gotoptions[unit].mppe;
649 if ((!ecp_required && !mppe_required)
650 || (ecp_required && ecp_fsm[unit].state == OPENED)
651 || (mppe_required && ccp_fsm[unit].state == OPENED)) {
652 for (i = 0; (protp = protocols[i]) != NULL; ++i)
653 if (protp->protocol < 0xC000
654 && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP
655 && protp->enabled_flag && protp->open != NULL) {
660 if (num_np_open == 0)
662 lcp_close(0, "No network protocols running");
667 * The peer has failed to authenticate himself using `protocol'.
670 auth_peer_fail(unit, protocol)
674 * Authentication failure: take the link down
676 lcp_close(unit, "Authentication failed");
677 status = EXIT_PEER_AUTH_FAILED;
681 * The peer has been successfully authenticated using `protocol'.
684 auth_peer_success(unit, protocol, prot_flavor, name, namelen)
685 int unit, protocol, prot_flavor;
694 switch (prot_flavor) {
695 case CHAP_DIGEST_MD5:
696 bit |= CHAP_MD5_PEER;
702 case CHAP_MICROSOFT_V2:
703 bit |= CHAP_MS2_PEER;
712 warn("auth_peer_success: unknown protocol %x", protocol);
717 * Save the authenticated name of the peer for later.
719 if (namelen > sizeof(peer_authname) - 1)
720 namelen = sizeof(peer_authname) - 1;
721 BCOPY(name, peer_authname, namelen);
722 peer_authname[namelen] = 0;
723 script_setenv("PEERNAME", peer_authname, 0);
725 /* Save the authentication method for later. */
726 auth_done[unit] |= bit;
729 * If there is no more authentication still to be done,
730 * proceed to the network (or callback) phase.
732 if ((auth_pending[unit] &= ~bit) == 0)
737 * We have failed to authenticate ourselves to the peer using `protocol'.
740 auth_withpeer_fail(unit, protocol)
743 if (passwd_from_file)
744 BZERO(passwd, MAXSECRETLEN);
746 * We've failed to authenticate ourselves to our peer.
747 * Some servers keep sending CHAP challenges, but there
748 * is no point in persisting without any way to get updated
749 * authentication secrets.
751 lcp_close(unit, "Failed to authenticate ourselves to peer");
752 status = EXIT_AUTH_TOPEER_FAILED;
756 * We have successfully authenticated ourselves with the peer using `protocol'.
759 auth_withpeer_success(unit, protocol, prot_flavor)
760 int unit, protocol, prot_flavor;
767 switch (prot_flavor) {
768 case CHAP_DIGEST_MD5:
769 bit |= CHAP_MD5_WITHPEER;
773 bit |= CHAP_MS_WITHPEER;
775 case CHAP_MICROSOFT_V2:
776 bit |= CHAP_MS2_WITHPEER;
782 if (passwd_from_file)
783 BZERO(passwd, MAXSECRETLEN);
787 warn("auth_withpeer_success: unknown protocol %x", protocol);
791 /* Save the authentication method for later. */
792 auth_done[unit] |= bit;
795 * If there is no more authentication still being done,
796 * proceed to the network (or callback) phase.
798 if ((auth_pending[unit] &= ~bit) == 0)
804 * np_up - a network protocol has come up.
812 if (num_np_up == 0) {
814 * At this point we consider that the link has come up successfully.
818 new_phase(PHASE_RUNNING);
820 if (idle_time_hook != 0)
821 tlim = (*idle_time_hook)(NULL);
823 tlim = idle_time_limit;
825 TIMEOUT(check_idle, NULL, tlim);
828 * Set a timeout to close the connection once the maximum
829 * connect time has expired.
832 TIMEOUT(connect_time_expired, 0, maxconnect);
836 TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
840 * Detach now, if the updetach option was given.
842 if (updetach && !nodetach)
849 * np_down - a network protocol has gone down.
855 if (--num_np_up == 0) {
856 UNTIMEOUT(check_idle, NULL);
857 UNTIMEOUT(connect_time_expired, NULL);
859 UNTIMEOUT(check_maxoctets, NULL);
861 new_phase(PHASE_NETWORK);
866 * np_finished - a network protocol has finished using the link.
869 np_finished(unit, proto)
872 if (--num_np_open <= 0) {
873 /* no further use for the link: shut up shop. */
874 lcp_close(0, "No network protocols running");
886 update_link_stats(ifunit);
889 switch(maxoctets_dir) {
890 case PPP_OCTETS_DIRECTION_IN:
891 used = link_stats.bytes_in;
893 case PPP_OCTETS_DIRECTION_OUT:
894 used = link_stats.bytes_out;
896 case PPP_OCTETS_DIRECTION_MAXOVERAL:
897 case PPP_OCTETS_DIRECTION_MAXSESSION:
898 used = (link_stats.bytes_in > link_stats.bytes_out) ? link_stats.bytes_in : link_stats.bytes_out;
901 used = link_stats.bytes_in+link_stats.bytes_out;
904 diff = maxoctets - used;
906 notice("Traffic limit reached. Limit: %u Used: %u", maxoctets, used);
907 lcp_close(0, "Traffic limit");
909 status = EXIT_TRAFFIC_LIMIT;
911 TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
917 * check_idle - check whether the link has been idle for long
918 * enough that we can shut it down.
924 struct ppp_idle idle;
928 if (!get_idle_time(0, &idle))
930 if (idle_time_hook != 0) {
931 tlim = idle_time_hook(&idle);
933 itime = MIN(idle.xmit_idle, idle.recv_idle);
934 tlim = idle_time_limit - itime;
937 /* link is idle: shut it down. */
938 notice("Terminating connection due to lack of activity.");
939 lcp_close(0, "Link inactive");
941 status = EXIT_IDLE_TIMEOUT;
943 TIMEOUT(check_idle, NULL, tlim);
948 * connect_time_expired - log a message and close the connection.
951 connect_time_expired(arg)
954 info("Connect time expired");
955 lcp_close(0, "Connect time expired"); /* Close connection */
956 status = EXIT_CONNECT_TIME;
960 * auth_check_options - called to check authentication options.
965 lcp_options *wo = &lcp_wantoptions[0];
969 /* Default our_name to hostname, and user to our_name */
970 if (our_name[0] == 0 || usehostname)
971 strlcpy(our_name, hostname, sizeof(our_name));
973 strlcpy(user, our_name, sizeof(user));
976 * If we have a default route, require the peer to authenticate
977 * unless the noauth option was given or the real user is root.
979 if (!auth_required && !allow_any_ip && have_route_to(0) && !privileged) {
984 /* If authentication is required, ask peer for CHAP or PAP. */
987 if (!wo->neg_chap && !wo->neg_upap) {
988 wo->neg_chap = 1; wo->chap_mdtype = MDTYPE_ALL;
992 wo->neg_chap = 0; wo->chap_mdtype = MDTYPE_NONE;
997 * Check whether we have appropriate secrets to use
998 * to authenticate the peer.
1001 can_auth = wo->neg_upap && (uselogin || have_pap_secret(&lacks_ip));
1002 if (!can_auth && (wo->neg_chap)) {
1003 can_auth = have_chap_secret((explicit_remote? remote_name: NULL),
1004 our_name, 1, &lacks_ip);
1007 if (auth_required && !can_auth && noauth_addrs == NULL) {
1010 "By default the remote system is required to authenticate itself");
1012 "(because this system has a default route to the internet)");
1013 } else if (explicit_remote)
1015 "The remote system (%s) is required to authenticate itself",
1019 "The remote system is required to authenticate itself");
1021 "but I couldn't find any suitable secret (password) for it to use to do so.");
1024 "(None of the available passwords would let it use an IP address.)");
1031 * auth_reset - called when LCP is starting negotiations to recheck
1032 * authentication options, i.e. whether we have appropriate secrets
1033 * to use for authenticating ourselves and/or the peer.
1039 lcp_options *go = &lcp_gotoptions[unit];
1040 lcp_options *ao = &lcp_allowoptions[0];
1042 ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
1043 ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)
1045 || have_chap_secret(user, (explicit_remote? remote_name: NULL),
1048 if (go->neg_upap && !uselogin && !have_pap_secret(NULL))
1051 if (!have_chap_secret((explicit_remote? remote_name: NULL),
1059 * check_passwd - Check the user name and passwd against the PAP secrets
1060 * file. If requested, also check against the system password database,
1061 * and login the user if OK.
1064 * UPAP_AUTHNAK: Authentication failed.
1065 * UPAP_AUTHACK: Authentication succeeded.
1066 * In either case, msg points to an appropriate message.
1069 check_passwd(unit, auser, userlen, apasswd, passwdlen, msg)
1080 struct wordlist *addrs = NULL, *opts = NULL;
1081 char passwd[256], user[256];
1082 char secret[MAXWORDLEN];
1083 static int attempts = 0;
1086 * Make copies of apasswd and auser, then null-terminate them.
1087 * If there are unprintable characters in the password, make
1090 slprintf(passwd, sizeof(passwd), "%.*v", passwdlen, apasswd);
1091 slprintf(user, sizeof(user), "%.*v", userlen, auser);
1095 * Check if a plugin wants to handle this.
1097 if (pap_auth_hook) {
1098 ret = (*pap_auth_hook)(user, passwd, msg, &addrs, &opts);
1101 set_allowed_addrs(unit, addrs, opts);
1102 BZERO(passwd, sizeof(passwd));
1104 free_wordlist(addrs);
1106 free_wordlist(opts);
1108 return ret? UPAP_AUTHACK: UPAP_AUTHNAK;
1113 * Open the file of pap secrets and scan for a suitable secret
1114 * for authenticating this user.
1116 filename = _PATH_UPAPFILE;
1117 addrs = opts = NULL;
1119 f = fopen(filename, "r");
1121 error("Can't open PAP password file %s: %m", filename);
1124 check_access(f, filename);
1125 if (scan_authfile(f, user, our_name, secret, &addrs, &opts, filename) < 0) {
1126 warn("no PAP secret found for %s", user);
1129 * If the secret is "@login", it means to check
1130 * the password against the login database.
1132 int login_secret = strcmp(secret, "@login") == 0;
1134 if (uselogin || login_secret) {
1135 /* login option or secret is @login */
1136 ret = plogin(user, passwd, msg);
1137 if (ret == UPAP_AUTHNAK)
1138 warn("PAP login failure for %s", user);
1142 if (secret[0] != 0 && !login_secret) {
1143 /* password given in pap-secrets - must match */
1144 if ((cryptpap || strcmp(passwd, secret) != 0)
1145 && strcmp(crypt(passwd, secret), secret) != 0) {
1147 warn("PAP authentication failure for %s", user);
1154 if (ret == UPAP_AUTHNAK) {
1156 *msg = "Login incorrect";
1158 * XXX can we ever get here more than once??
1159 * Frustrate passwd stealer programs.
1160 * Allow 10 tries, but start backing off after 3 (stolen from login).
1161 * On 10'th, drop the connection.
1163 if (attempts++ >= 10) {
1164 warn("%d LOGIN FAILURES ON %s, %s", attempts, devnam, user);
1165 lcp_close(unit, "login failed");
1168 sleep((u_int) (attempts - 3) * 5);
1170 free_wordlist(opts);
1173 attempts = 0; /* Reset count */
1176 set_allowed_addrs(unit, addrs, opts);
1180 free_wordlist(addrs);
1181 BZERO(passwd, sizeof(passwd));
1182 BZERO(secret, sizeof(secret));
1188 * This function is needed for PAM.
1192 /* Static variables used to communicate between the conversation function
1193 * and the server_login function
1195 static char *PAM_username;
1196 static char *PAM_password;
1197 static int PAM_error = 0;
1198 static pam_handle_t *pamh = NULL;
1200 /* PAM conversation function
1201 * Here we assume (for now, at least) that echo on means login name, and
1202 * echo off means password.
1205 static int PAM_conv (int num_msg, const struct pam_message **msg,
1206 struct pam_response **resp, void *appdata_ptr)
1209 struct pam_response *reply = NULL;
1211 #define COPY_STRING(s) (s) ? strdup(s) : NULL
1213 reply = malloc(sizeof(struct pam_response) * num_msg);
1214 if (!reply) return PAM_CONV_ERR;
1216 for (replies = 0; replies < num_msg; replies++) {
1217 switch (msg[replies]->msg_style) {
1218 case PAM_PROMPT_ECHO_ON:
1219 reply[replies].resp_retcode = PAM_SUCCESS;
1220 reply[replies].resp = COPY_STRING(PAM_username);
1221 /* PAM frees resp */
1223 case PAM_PROMPT_ECHO_OFF:
1224 reply[replies].resp_retcode = PAM_SUCCESS;
1225 reply[replies].resp = COPY_STRING(PAM_password);
1226 /* PAM frees resp */
1231 /* ignore it, but pam still wants a NULL response... */
1232 reply[replies].resp_retcode = PAM_SUCCESS;
1233 reply[replies].resp = NULL;
1236 /* Must be an error of some sort... */
1239 return PAM_CONV_ERR;
1246 static struct pam_conv PAM_conversation = {
1250 #endif /* USE_PAM */
1253 * plogin - Check the user name and password against the system
1254 * password database, and login the user if OK.
1257 * UPAP_AUTHNAK: Login failed.
1258 * UPAP_AUTHACK: Login succeeded.
1259 * In either case, msg points to an appropriate message.
1263 plogin(user, passwd, msg)
1273 pam_error = pam_start ("ppp", user, &PAM_conversation, &pamh);
1274 if (pam_error != PAM_SUCCESS) {
1275 *msg = (char *) pam_strerror (pamh, pam_error);
1277 return UPAP_AUTHNAK;
1280 * Define the fields for the credential validation
1283 PAM_username = user;
1284 PAM_password = passwd;
1286 pam_set_item (pamh, PAM_TTY, devnam); /* this might be useful to some modules */
1291 pam_error = pam_authenticate (pamh, PAM_SILENT);
1292 if (pam_error == PAM_SUCCESS && !PAM_error) {
1293 pam_error = pam_acct_mgmt (pamh, PAM_SILENT);
1294 if (pam_error == PAM_SUCCESS)
1295 pam_error = pam_open_session (pamh, PAM_SILENT);
1298 *msg = (char *) pam_strerror (pamh, pam_error);
1303 reopen_log(); /* apparently the PAM stuff does closelog() */
1304 PAM_username = NULL;
1305 PAM_password = NULL;
1306 if (pam_error != PAM_SUCCESS)
1307 return UPAP_AUTHNAK;
1308 #else /* #ifdef USE_PAM */
1311 * Use the non-PAM methods directly
1316 struct spwd *getspnam();
1318 struct passwd *pw = getpwnam(user);
1322 return (UPAP_AUTHNAK);
1325 spwd = getspnam(user);
1328 /* check the age of the password entry */
1329 long now = time(NULL) / 86400L;
1331 if ((spwd->sp_expire > 0 && now >= spwd->sp_expire)
1332 || ((spwd->sp_max >= 0 && spwd->sp_max < 10000)
1333 && spwd->sp_lstchg >= 0
1334 && now >= spwd->sp_lstchg + spwd->sp_max)) {
1335 warn("Password for %s has expired", user);
1336 return (UPAP_AUTHNAK);
1338 pw->pw_passwd = spwd->sp_pwdp;
1343 * If no passwd, don't let them login.
1345 if (pw->pw_passwd == NULL || strlen(pw->pw_passwd) < 2
1346 || strcmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd) != 0)
1347 return (UPAP_AUTHNAK);
1349 #endif /* #ifdef USE_PAM */
1352 * Write a wtmp entry for this user.
1356 if (strncmp(tty, "/dev/", 5) == 0)
1358 logwtmp(tty, user, remote_name); /* Add wtmp login entry */
1360 #if defined(_PATH_LASTLOG) && !defined(USE_PAM)
1361 if (pw != (struct passwd *)NULL) {
1365 if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
1366 (void)lseek(fd, (off_t)(pw->pw_uid * sizeof(ll)), SEEK_SET);
1367 memset((void *)&ll, 0, sizeof(ll));
1368 (void)time(&ll.ll_time);
1369 (void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
1370 (void)write(fd, (char *)&ll, sizeof(ll));
1374 #endif /* _PATH_LASTLOG and not USE_PAM */
1376 info("user %s logged in", user);
1379 return (UPAP_AUTHACK);
1383 * plogout - Logout the user.
1392 pam_error = pam_close_session (pamh, PAM_SILENT);
1393 pam_end (pamh, pam_error);
1396 /* Apparently the pam stuff does closelog(). */
1398 #else /* ! USE_PAM */
1402 if (strncmp(tty, "/dev/", 5) == 0)
1404 logwtmp(tty, "", ""); /* Wipe out utmp logout entry */
1405 #endif /* ! USE_PAM */
1411 * null_login - Check if a username of "" and a password of "" are
1412 * acceptable, and iff so, set the list of acceptable IP addresses
1422 struct wordlist *addrs, *opts;
1423 char secret[MAXWORDLEN];
1426 * Check if a plugin wants to handle this.
1430 ret = (*null_auth_hook)(&addrs, &opts);
1433 * Open the file of pap secrets and scan for a suitable secret.
1436 filename = _PATH_UPAPFILE;
1438 f = fopen(filename, "r");
1441 check_access(f, filename);
1443 i = scan_authfile(f, "", our_name, secret, &addrs, &opts, filename);
1444 ret = i >= 0 && secret[0] == 0;
1445 BZERO(secret, sizeof(secret));
1450 set_allowed_addrs(unit, addrs, opts);
1452 free_wordlist(opts);
1454 free_wordlist(addrs);
1461 * get_pap_passwd - get a password for authenticating ourselves with
1462 * our peer using PAP. Returns 1 on success, 0 if no suitable password
1464 * Assumes passwd points to MAXSECRETLEN bytes of space (if non-null).
1467 get_pap_passwd(passwd)
1473 char secret[MAXWORDLEN];
1476 * Check whether a plugin wants to supply this.
1478 if (pap_passwd_hook) {
1479 ret = (*pap_passwd_hook)(user, passwd);
1484 filename = _PATH_UPAPFILE;
1485 f = fopen(filename, "r");
1488 check_access(f, filename);
1489 ret = scan_authfile(f, user,
1490 (remote_name[0]? remote_name: NULL),
1491 secret, NULL, NULL, filename);
1496 strlcpy(passwd, secret, MAXSECRETLEN);
1497 BZERO(secret, sizeof(secret));
1503 * have_pap_secret - check whether we have a PAP file with any
1504 * secrets that we could possibly use for authenticating the peer.
1507 have_pap_secret(lacks_ipp)
1513 struct wordlist *addrs;
1515 /* let the plugin decide, if there is one */
1516 if (pap_check_hook) {
1517 ret = (*pap_check_hook)();
1522 filename = _PATH_UPAPFILE;
1523 f = fopen(filename, "r");
1527 ret = scan_authfile(f, (explicit_remote? remote_name: NULL), our_name,
1528 NULL, &addrs, NULL, filename);
1530 if (ret >= 0 && !some_ip_ok(addrs)) {
1536 free_wordlist(addrs);
1543 * have_chap_secret - check whether we have a CHAP file with a
1544 * secret that we could possibly use for authenticating `client'
1545 * on `server'. Either can be the null string, meaning we don't
1546 * know the identity yet.
1549 have_chap_secret(client, server, need_ip, lacks_ipp)
1558 struct wordlist *addrs;
1560 if (chap_check_hook) {
1561 ret = (*chap_check_hook)();
1567 filename = _PATH_CHAPFILE;
1568 f = fopen(filename, "r");
1572 if (client != NULL && client[0] == 0)
1574 else if (server != NULL && server[0] == 0)
1577 ret = scan_authfile(f, client, server, NULL, &addrs, NULL, filename);
1579 if (ret >= 0 && need_ip && !some_ip_ok(addrs)) {
1585 free_wordlist(addrs);
1592 * get_secret - open the CHAP secret file and return the secret
1593 * for authenticating the given client on the given server.
1594 * (We could be either client or server).
1597 get_secret(unit, client, server, secret, secret_len, am_server)
1608 struct wordlist *addrs, *opts;
1609 char secbuf[MAXWORDLEN];
1611 if (!am_server && passwd[0] != 0) {
1612 strlcpy(secbuf, passwd, sizeof(secbuf));
1613 } else if (!am_server && chap_passwd_hook) {
1614 if ( (*chap_passwd_hook)(client, secbuf) < 0) {
1615 error("Unable to obtain CHAP password for %s on %s from plugin",
1620 filename = _PATH_CHAPFILE;
1624 f = fopen(filename, "r");
1626 error("Can't open chap secret file %s: %m", filename);
1629 check_access(f, filename);
1631 ret = scan_authfile(f, client, server, secbuf, &addrs, &opts, filename);
1637 set_allowed_addrs(unit, addrs, opts);
1639 free_wordlist(opts);
1641 free_wordlist(addrs);
1644 len = strlen(secbuf);
1645 if (len > MAXSECRETLEN) {
1646 error("Secret for %s on %s is too long", client, server);
1649 BCOPY(secbuf, secret, len);
1650 BZERO(secbuf, sizeof(secbuf));
1657 * set_allowed_addrs() - set the list of allowed addresses.
1658 * Also looks for `--' indicating options to apply for this peer
1659 * and leaves the following words in extra_options.
1662 set_allowed_addrs(unit, addrs, opts)
1664 struct wordlist *addrs;
1665 struct wordlist *opts;
1668 struct wordlist *ap, **plink;
1669 struct permitted_ip *ip;
1670 char *ptr_word, *ptr_mask;
1673 u_int32_t a, mask, ah, offset;
1674 struct ipcp_options *wo = &ipcp_wantoptions[unit];
1675 u_int32_t suggested_ip = 0;
1677 if (addresses[unit] != NULL)
1678 free(addresses[unit]);
1679 addresses[unit] = NULL;
1680 if (extra_options != NULL)
1681 free_wordlist(extra_options);
1682 extra_options = opts;
1685 * Count the number of IP addresses given.
1687 n = wordlist_count(addrs) + wordlist_count(noauth_addrs);
1690 ip = (struct permitted_ip *) malloc((n + 1) * sizeof(struct permitted_ip));
1694 /* temporarily append the noauth_addrs list to addrs */
1695 for (plink = &addrs; *plink != NULL; plink = &(*plink)->next)
1697 *plink = noauth_addrs;
1700 for (ap = addrs; ap != NULL; ap = ap->next) {
1701 /* "-" means no addresses authorized, "*" means any address allowed */
1702 ptr_word = ap->word;
1703 if (strcmp(ptr_word, "-") == 0)
1705 if (strcmp(ptr_word, "*") == 0) {
1707 ip[n].base = ip[n].mask = 0;
1713 if (*ptr_word == '!') {
1718 mask = ~ (u_int32_t) 0;
1720 ptr_mask = strchr (ptr_word, '/');
1721 if (ptr_mask != NULL) {
1725 bit_count = (int) strtol (ptr_mask+1, &endp, 10);
1726 if (bit_count <= 0 || bit_count > 32) {
1727 warn("invalid address length %v in auth. address list",
1731 bit_count = 32 - bit_count; /* # bits in host part */
1733 offset = ifunit + 1;
1737 warn("invalid address length syntax: %v", ptr_mask+1);
1744 hp = gethostbyname(ptr_word);
1745 if (hp != NULL && hp->h_addrtype == AF_INET) {
1746 a = *(u_int32_t *)hp->h_addr;
1748 np = getnetbyname (ptr_word);
1749 if (np != NULL && np->n_addrtype == AF_INET) {
1750 a = htonl (*(u_int32_t *)np->n_net);
1751 if (ptr_mask == NULL) {
1752 /* calculate appropriate mask for net */
1755 mask = IN_CLASSA_NET;
1756 else if (IN_CLASSB(ah))
1757 mask = IN_CLASSB_NET;
1758 else if (IN_CLASSC(ah))
1759 mask = IN_CLASSC_NET;
1762 a = inet_addr (ptr_word);
1766 if (ptr_mask != NULL)
1769 if (a == (u_int32_t)-1L) {
1770 warn("unknown host %s in auth. address list", ap->word);
1774 if (offset >= ~mask) {
1775 warn("interface unit %d too large for subnet %v",
1779 a = htonl((ntohl(a) & mask) + offset);
1780 mask = ~(u_int32_t)0;
1782 ip[n].mask = htonl(mask);
1783 ip[n].base = a & ip[n].mask;
1785 if (~mask == 0 && suggested_ip == 0)
1790 ip[n].permit = 0; /* make the last entry forbid all addresses */
1791 ip[n].base = 0; /* to terminate the list */
1794 addresses[unit] = ip;
1797 * If the address given for the peer isn't authorized, or if
1798 * the user hasn't given one, AND there is an authorized address
1799 * which is a single host, then use that if we find one.
1801 if (suggested_ip != 0
1802 && (wo->hisaddr == 0 || !auth_ip_addr(unit, wo->hisaddr))) {
1803 wo->hisaddr = suggested_ip;
1805 * Do we insist on this address? No, if there are other
1806 * addresses authorized than the suggested one.
1809 wo->accept_remote = 1;
1814 * auth_ip_addr - check whether the peer is authorized to use
1815 * a given IP address. Returns 1 if authorized, 0 otherwise.
1818 auth_ip_addr(unit, addr)
1824 /* don't allow loopback or multicast address */
1825 if (bad_ip_adrs(addr))
1828 if (allowed_address_hook) {
1829 ok = allowed_address_hook(addr);
1830 if (ok >= 0) return ok;
1833 if (addresses[unit] != NULL) {
1834 ok = ip_addr_check(addr, addresses[unit]);
1840 return 0; /* no addresses authorized */
1841 return allow_any_ip || privileged || !have_route_to(addr);
1845 ip_addr_check(addr, addrs)
1847 struct permitted_ip *addrs;
1850 if ((addr & addrs->mask) == addrs->base)
1851 return addrs->permit;
1855 * bad_ip_adrs - return 1 if the IP address is one we don't want
1856 * to use, such as an address in the loopback net or a multicast address.
1857 * addr is in network byte order.
1864 return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
1865 || IN_MULTICAST(addr) || IN_BADCLASS(addr);
1869 * some_ip_ok - check a wordlist to see if it authorizes any
1874 struct wordlist *addrs;
1876 for (; addrs != 0; addrs = addrs->next) {
1877 if (addrs->word[0] == '-')
1879 if (addrs->word[0] != '!')
1880 return 1; /* some IP address is allowed */
1886 * check_access - complain if a secret file has too-liberal permissions.
1889 check_access(f, filename)
1895 if (fstat(fileno(f), &sbuf) < 0) {
1896 warn("cannot stat secret file %s: %m", filename);
1897 } else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
1898 warn("Warning - secret file %s has world and/or group access",
1905 * scan_authfile - Scan an authorization file for a secret suitable
1906 * for authenticating `client' on `server'. The return value is -1
1907 * if no secret is found, otherwise >= 0. The return value has
1908 * NONWILD_CLIENT set if the secret didn't have "*" for the client, and
1909 * NONWILD_SERVER set if the secret didn't have "*" for the server.
1910 * Any following words on the line up to a "--" (i.e. address authorization
1911 * info) are placed in a wordlist and returned in *addrs. Any
1912 * following words (extra options) are placed in a wordlist and
1913 * returned in *opts.
1914 * We assume secret is NULL or points to MAXWORDLEN bytes of space.
1917 scan_authfile(f, client, server, secret, addrs, opts, filename)
1922 struct wordlist **addrs;
1923 struct wordlist **opts;
1927 int got_flag, best_flag;
1929 struct wordlist *ap, *addr_list, *alist, **app;
1930 char word[MAXWORDLEN];
1931 char atfile[MAXWORDLEN];
1932 char lsecret[MAXWORDLEN];
1939 if (!getword(f, word, &newline, filename))
1940 return -1; /* file is empty??? */
1945 * Skip until we find a word at the start of a line.
1947 while (!newline && getword(f, word, &newline, filename))
1950 break; /* got to end of file */
1953 * Got a client - check if it's a match or a wildcard.
1956 if (client != NULL && strcmp(word, client) != 0 && !ISWILD(word)) {
1961 got_flag = NONWILD_CLIENT;
1964 * Now get a server and check if it matches.
1966 if (!getword(f, word, &newline, filename))
1970 if (!ISWILD(word)) {
1971 if (server != NULL && strcmp(word, server) != 0)
1973 got_flag |= NONWILD_SERVER;
1977 * Got some sort of a match - see if it's better than what
1980 if (got_flag <= best_flag)
1986 if (!getword(f, word, &newline, filename))
1991 if (secret != NULL) {
1993 * Special syntax: @/pathname means read secret from file.
1995 if (word[0] == '@' && word[1] == '/') {
1996 strlcpy(atfile, word+1, sizeof(atfile));
1997 if ((sf = fopen(atfile, "r")) == NULL) {
1998 warn("can't open indirect secret file %s", atfile);
2001 check_access(sf, atfile);
2002 if (!getword(sf, word, &xxx, atfile)) {
2003 warn("no secret in indirect secret file %s", atfile);
2009 strlcpy(lsecret, word, sizeof(lsecret));
2013 * Now read address authorization info and make a wordlist.
2017 if (!getword(f, word, &newline, filename) || newline)
2019 ap = (struct wordlist *)
2020 malloc(sizeof(struct wordlist) + strlen(word) + 1);
2022 novm("authorized addresses");
2023 ap->word = (char *) (ap + 1);
2024 strcpy(ap->word, word);
2031 * This is the best so far; remember it.
2033 best_flag = got_flag;
2035 free_wordlist(addr_list);
2038 strlcpy(secret, lsecret, MAXWORDLEN);
2044 /* scan for a -- word indicating the start of options */
2045 for (app = &addr_list; (ap = *app) != NULL; app = &ap->next)
2046 if (strcmp(ap->word, "--") == 0)
2048 /* ap = start of options */
2050 ap = ap->next; /* first option */
2051 free(*app); /* free the "--" word */
2052 *app = NULL; /* terminate addr list */
2056 else if (ap != NULL)
2060 else if (addr_list != NULL)
2061 free_wordlist(addr_list);
2067 * wordlist_count - return the number of items in a wordlist
2071 struct wordlist *wp;
2075 for (n = 0; wp != NULL; wp = wp->next)
2081 * free_wordlist - release memory allocated for a wordlist.
2085 struct wordlist *wp;
2087 struct wordlist *next;
2089 while (wp != NULL) {
2097 * auth_script_done - called when the auth-up or auth-down script
2101 auth_script_done(arg)
2104 auth_script_pid = 0;
2105 switch (auth_script_state) {
2107 if (auth_state == s_down) {
2108 auth_script_state = s_down;
2109 auth_script(_PATH_AUTHDOWN);
2113 if (auth_state == s_up) {
2114 auth_script_state = s_up;
2115 auth_script(_PATH_AUTHUP);
2122 * auth_script - execute a script with arguments
2123 * interface-name peer-name real-user tty speed
2135 if ((pw = getpwuid(getuid())) != NULL && pw->pw_name != NULL)
2136 user_name = pw->pw_name;
2138 slprintf(struid, sizeof(struid), "%d", getuid());
2141 slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
2145 argv[2] = peer_authname;
2146 argv[3] = user_name;
2151 auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL);