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.
36 static char rcsid[] = "$Id: auth.c,v 1.24 1996/06/26 00:56:11 paulus Exp $";
46 #include <sys/types.h>
48 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
63 #include <security/pam_appl.h>
64 #include <security/pam_modules.h>
69 #include <shadow/pwauth.h>
71 #define PW_PPP PW_LOGIN
81 #include "pathnames.h"
83 #if defined(sun) && defined(sparc)
87 /* Used for storing a sequence of words. Usually malloced. */
89 struct wordlist *next;
93 /* Bits in scan_authfile return value */
94 #define NONWILD_SERVER 1
95 #define NONWILD_CLIENT 2
97 #define ISWILD(word) (word[0] == '*' && word[1] == 0)
102 /* The name by which the peer authenticated itself to us. */
103 char peer_authname[MAXNAMELEN];
105 /* Records which authentication operations haven't completed yet. */
106 static int auth_pending[NUM_PPP];
108 /* Set if we have successfully called login() */
109 static int logged_in;
111 /* Set if we have run the /etc/ppp/auth-up script. */
112 static int did_authup;
114 /* List of addresses which the peer may use. */
115 static struct wordlist *addresses[NUM_PPP];
117 /* Number of network protocols which we have opened. */
118 static int num_np_open;
120 /* Number of network protocols which have come up. */
121 static int num_np_up;
123 /* Bits in auth_pending[] */
124 #define UPAP_WITHPEER 1
126 #define CHAP_WITHPEER 4
129 /* Prototypes for procedures local to this file. */
131 static void network_phase __P((int));
132 static void check_idle __P((caddr_t));
133 static int login __P((char *, char *, char **, int *));
134 static void logout __P((void));
135 static int null_login __P((int));
136 static int get_upap_passwd __P((void));
137 static int have_upap_secret __P((void));
138 static int have_chap_secret __P((char *, char *, u_int32_t));
139 static int ip_addr_check __P((u_int32_t, struct wordlist *));
140 static int scan_authfile __P((FILE *, char *, char *, u_int32_t, char *,
141 struct wordlist **, char *));
142 static void free_wordlist __P((struct wordlist *));
143 static void auth_script __P((char *));
146 * An Open on LCP has requested a change from Dead to Establish phase.
147 * Do what's necessary to bring the physical layer up.
156 * LCP has terminated the link; go to the Dead phase and take the
157 * physical layer down.
160 link_terminated(unit)
163 if (phase == PHASE_DEAD)
168 syslog(LOG_NOTICE, "Connection terminated.");
172 * LCP has gone down; it will either die or try to re-establish.
179 struct protent *protp;
182 auth_script(_PATH_AUTHDOWN);
185 for (i = 0; (protp = protocols[i]) != NULL; ++i) {
186 if (!protp->enabled_flag)
188 if (protp->protocol != PPP_LCP && protp->lowerdown != NULL)
189 (*protp->lowerdown)(unit);
190 if (protp->protocol < 0xC000 && protp->close != NULL)
191 (*protp->close)(unit, "LCP down");
195 phase = PHASE_TERMINATE;
199 * The link is established.
200 * Proceed to the Dead, Authenticate or Network phase as appropriate.
203 link_established(unit)
207 lcp_options *wo = &lcp_wantoptions[unit];
208 lcp_options *go = &lcp_gotoptions[unit];
209 lcp_options *ho = &lcp_hisoptions[unit];
211 struct protent *protp;
214 * Tell higher-level protocols that LCP is up.
216 for (i = 0; (protp = protocols[i]) != NULL; ++i)
217 if (protp->protocol != PPP_LCP && protp->enabled_flag
218 && protp->lowerup != NULL)
219 (*protp->lowerup)(unit);
221 if (auth_required && !(go->neg_chap || go->neg_upap)) {
223 * We wanted the peer to authenticate itself, and it refused:
224 * treat it as though it authenticated with PAP using a username
225 * of "" and a password of "". If that's not OK, boot it out.
227 if (!wo->neg_upap || !null_login(unit)) {
228 syslog(LOG_WARNING, "peer refused to authenticate");
229 lcp_close(unit, "peer refused to authenticate");
230 phase = PHASE_TERMINATE;
235 phase = PHASE_AUTHENTICATE;
238 ChapAuthPeer(unit, our_name, go->chap_mdtype);
240 } else if (go->neg_upap) {
245 ChapAuthWithPeer(unit, our_name, ho->chap_mdtype);
246 auth |= CHAP_WITHPEER;
247 } else if (ho->neg_upap) {
248 upap_authwithpeer(unit, user, passwd);
249 auth |= UPAP_WITHPEER;
251 auth_pending[unit] = auth;
258 * Proceed to the network phase.
265 struct protent *protp;
266 lcp_options *go = &lcp_gotoptions[unit];
269 * If the peer had to authenticate, run the auth-up script now.
271 if ((go->neg_chap || go->neg_upap) && !did_authup) {
272 auth_script(_PATH_AUTHUP);
276 phase = PHASE_NETWORK;
279 set_filters(&pass_filter, &active_filter);
281 for (i = 0; (protp = protocols[i]) != NULL; ++i)
282 if (protp->protocol < 0xC000 && protp->enabled_flag
283 && protp->open != NULL) {
284 (*protp->open)(unit);
285 if (protp->protocol != PPP_CCP)
291 * The peer has failed to authenticate himself using `protocol'.
294 auth_peer_fail(unit, protocol)
298 * Authentication failure: take the link down
300 lcp_close(unit, "Authentication failed");
301 phase = PHASE_TERMINATE;
305 * The peer has been successfully authenticated using `protocol'.
308 auth_peer_success(unit, protocol, name, namelen)
323 syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
329 * Save the authenticated name of the peer for later.
331 if (namelen > sizeof(peer_authname) - 1)
332 namelen = sizeof(peer_authname) - 1;
333 BCOPY(name, peer_authname, namelen);
334 peer_authname[namelen] = 0;
337 * If there is no more authentication still to be done,
338 * proceed to the network phase.
340 if ((auth_pending[unit] &= ~bit) == 0)
345 * We have failed to authenticate ourselves to the peer using `protocol'.
348 auth_withpeer_fail(unit, protocol)
352 * We've failed to authenticate ourselves to our peer.
353 * He'll probably take the link down, and there's not much
354 * we can do except wait for that.
359 * We have successfully authenticated ourselves with the peer using `protocol'.
362 auth_withpeer_success(unit, protocol)
375 syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
381 * If there is no more authentication still being done,
382 * proceed to the network phase.
384 if ((auth_pending[unit] &= ~bit) == 0)
390 * np_up - a network protocol has come up.
396 if (num_np_up == 0 && idle_time_limit > 0) {
397 TIMEOUT(check_idle, NULL, idle_time_limit);
403 * np_down - a network protocol has gone down.
409 if (--num_np_up == 0 && idle_time_limit > 0) {
410 UNTIMEOUT(check_idle, NULL);
415 * np_finished - a network protocol has finished using the link.
418 np_finished(unit, proto)
421 if (--num_np_open <= 0) {
422 /* no further use for the link: shut up shop. */
423 lcp_close(0, "No network protocols running");
428 * check_idle - check whether the link has been idle for long
429 * enough that we can shut it down.
435 struct ppp_idle idle;
438 if (!get_idle_time(0, &idle))
440 itime = MIN(idle.xmit_idle, idle.recv_idle);
441 if (itime >= idle_time_limit) {
442 /* link is idle: shut it down. */
443 syslog(LOG_INFO, "Terminating connection due to lack of activity.");
444 lcp_close(0, "Link inactive");
446 TIMEOUT(check_idle, NULL, idle_time_limit - itime);
451 * auth_check_options - called to check authentication options.
456 lcp_options *wo = &lcp_wantoptions[0];
457 lcp_options *ao = &lcp_allowoptions[0];
458 ipcp_options *ipwo = &ipcp_wantoptions[0];
461 /* Default our_name to hostname, and user to our_name */
462 if (our_name[0] == 0 || usehostname)
463 strcpy(our_name, hostname);
465 strcpy(user, our_name);
467 /* If authentication is required, ask peer for CHAP or PAP. */
468 if (auth_required && !wo->neg_chap && !wo->neg_upap) {
474 * Check whether we have appropriate secrets to use
475 * to authenticate ourselves and/or the peer.
477 if (ao->neg_upap && passwd[0] == 0 && !get_upap_passwd())
479 if (wo->neg_upap && !uselogin && !have_upap_secret())
481 if (ao->neg_chap && !have_chap_secret(our_name, remote_name, (u_int32_t)0))
484 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
485 if (!have_chap_secret(remote_name, our_name, remote))
489 if (auth_required && !wo->neg_chap && !wo->neg_upap) {
491 pppd: peer authentication required but no suitable secret(s) found\n");
499 * check_passwd - Check the user name and passwd against the PAP secrets
500 * file. If requested, also check against the system password database,
501 * and login the user if OK.
504 * UPAP_AUTHNAK: Authentication failed.
505 * UPAP_AUTHACK: Authentication succeeded.
506 * In either case, msg points to an appropriate message.
509 check_passwd(unit, auser, userlen, apasswd, passwdlen, msg, msglen)
521 struct wordlist *addrs;
523 ipcp_options *ipwo = &ipcp_wantoptions[unit];
524 char passwd[256], user[256];
525 char secret[MAXWORDLEN];
526 static int attempts = 0;
529 * Make copies of apasswd and auser, then null-terminate them.
531 BCOPY(apasswd, passwd, passwdlen);
532 passwd[passwdlen] = '\0';
533 BCOPY(auser, user, userlen);
534 user[userlen] = '\0';
538 * Open the file of upap secrets and scan for a suitable secret
539 * for authenticating this user.
541 filename = _PATH_UPAPFILE;
544 f = fopen(filename, "r");
547 syslog(LOG_ERR, "Can't open PAP password file %s: %m", filename);
552 check_access(f, filename);
553 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
554 if (scan_authfile(f, user, our_name, remote,
555 secret, &addrs, filename) < 0
556 || (secret[0] != 0 && (cryptpap || strcmp(passwd, secret) != 0)
557 && strcmp(crypt(passwd, secret), secret) != 0)) {
558 syslog(LOG_WARNING, "PAP authentication failure for %s", user);
564 if (uselogin && ret == UPAP_AUTHACK) {
565 ret = login(user, passwd, msg, msglen);
566 if (ret == UPAP_AUTHNAK) {
567 syslog(LOG_WARNING, "PAP login failure for %s", user);
571 if (ret == UPAP_AUTHNAK) {
572 if (*msg == (char *) 0)
573 *msg = "Login incorrect";
574 *msglen = strlen(*msg);
576 * Frustrate passwd stealer programs.
577 * Allow 10 tries, but start backing off after 3 (stolen from login).
578 * On 10'th, drop the connection.
580 if (attempts++ >= 10) {
581 syslog(LOG_WARNING, "%d LOGIN FAILURES ON %s, %s",
582 attempts, devnam, user);
586 sleep((u_int) (attempts - 3) * 5);
588 free_wordlist(addrs);
591 attempts = 0; /* Reset count */
592 if (*msg == (char *) 0)
594 *msglen = strlen(*msg);
595 if (addresses[unit] != NULL)
596 free_wordlist(addresses[unit]);
597 addresses[unit] = addrs;
605 * This function was lifted from the shadow-3.3.2 version by John Haugh II.
606 * It is included because the function was not in the standard libshadow
607 * library. If it is included in the library then I can remove it from here.
610 #define DAY (24L*3600L)
612 * isexpired - determine if account is expired yet
614 * isexpired calculates the expiration date based on the
615 * password expiration criteria.
626 clock = time ((time_t *) 0) / DAY;
629 * Quick and easy - there is an expired account field
630 * along with an inactive account field. Do the expired
631 * one first since it is worse.
634 if (sp->sp_expire > 0 && sp->sp_expire < clock)
637 if (sp->sp_inact > 0 && sp->sp_lstchg > 0 && sp->sp_max > 0 &&
638 sp->sp_inact + sp->sp_lstchg + sp->sp_max < clock)
642 * The last and max fields must be present for an account
643 * to have an expired password. A maximum of >10000 days
644 * is considered to be infinite.
647 if (sp->sp_lstchg == -1 ||
648 sp->sp_max == -1 || sp->sp_max >= 10000L)
652 * Calculate today's day and the day on which the password
653 * is going to expire. If that date has already passed,
654 * the password has expired.
657 if (sp->sp_lstchg + sp->sp_max < clock)
666 * This function is needed for PAM. However, it should not be called.
667 * If it is, return the error code.
671 static int pam_conv(int num_msg, const struct pam_message **msg,
672 struct pam_response **resp, void *appdata_ptr)
679 * login - Check the user name and password against the system
680 * password database, and login the user if OK.
683 * UPAP_AUTHNAK: Login failed.
684 * UPAP_AUTHACK: Login succeeded.
685 * In either case, msg points to an appropriate message.
689 login(user, passwd, msg, msglen)
698 struct pam_conv pam_conversation;
704 * Fill the pam_conversion structure
706 memset (&pam_conversation, '\0', sizeof (struct pam_conv));
707 pam_conversation.conv = &pam_conv;
709 pam_error = pam_start ("ppp", user, &pam_conversation, &pamh);
710 if (pam_error != PAM_SUCCESS) {
711 *msg = (char *) pam_strerror (pam_error);
715 * Define the fields for the credintial validation
717 (void) pam_set_item (pamh, PAM_AUTHTOK, passwd);
718 (void) pam_set_item (pamh, PAM_TTY, devnam);
722 pam_error = pam_authenticate (pamh, PAM_SILENT);
723 if (pam_error == PAM_SUCCESS)
724 pam_error = pam_acct_mgmt (pamh, PAM_SILENT);
726 *msg = (char *) pam_strerror (pam_error);
730 (void) pam_end (pamh, pam_error);
732 if (pam_error != PAM_SUCCESS)
735 * Use the non-PAM methods directly
737 #else /* #ifdef USE_PAM */
744 struct spwd *getspnam();
747 if ((pw = getpwnam(user)) == NULL) {
748 return (UPAP_AUTHNAK);
752 if ((spwd = getspnam(user)) == NULL) {
755 pw->pw_passwd = spwd->sp_pwdp;
760 * XXX If no passwd, let them login without one.
762 if (pw->pw_passwd == '\0') {
763 return (UPAP_AUTHACK);
768 if (pw->pw_passwd[0] == '@') {
769 if (pw_auth (pw->pw_passwd+1, pw->pw_name, PW_PPP, NULL)) {
770 return (UPAP_AUTHNAK);
773 epasswd = pw_encrypt(passwd, pw->pw_passwd);
774 if (strcmp(epasswd, pw->pw_passwd)) {
775 return (UPAP_AUTHNAK);
778 /* check the age of the password entry */
779 if (spwd && (isexpired (pw, spwd) != 0)) {
780 return (UPAP_AUTHNAK);
784 epasswd = crypt(passwd, pw->pw_passwd);
785 if (strcmp(epasswd, pw->pw_passwd)) {
786 return (UPAP_AUTHNAK);
789 #endif /* #ifdef USE_PAM */
791 syslog(LOG_INFO, "user %s logged in", user);
794 * Write a wtmp entry for this user.
797 if (strncmp(tty, "/dev/", 5) == 0)
799 logwtmp(tty, user, remote_name); /* Add wtmp login entry */
802 return (UPAP_AUTHACK);
806 * logout - Logout the user.
814 if (strncmp(tty, "/dev/", 5) == 0)
816 logwtmp(tty, "", ""); /* Wipe out wtmp logout entry */
822 * null_login - Check if a username of "" and a password of "" are
823 * acceptable, and iff so, set the list of acceptable IP addresses
833 struct wordlist *addrs;
834 char secret[MAXWORDLEN];
837 * Open the file of upap secrets and scan for a suitable secret.
838 * We don't accept a wildcard client.
840 filename = _PATH_UPAPFILE;
842 f = fopen(filename, "r");
845 check_access(f, filename);
847 i = scan_authfile(f, "", our_name, (u_int32_t)0, secret, &addrs, filename);
848 ret = i >= 0 && (i & NONWILD_CLIENT) != 0 && secret[0] == 0;
851 if (addresses[unit] != NULL)
852 free_wordlist(addresses[unit]);
853 addresses[unit] = addrs;
862 * get_upap_passwd - get a password for authenticating ourselves with
863 * our peer using PAP. Returns 1 on success, 0 if no suitable password
871 struct wordlist *addrs;
872 char secret[MAXWORDLEN];
874 filename = _PATH_UPAPFILE;
876 f = fopen(filename, "r");
879 check_access(f, filename);
880 if (scan_authfile(f, user, remote_name, (u_int32_t)0,
881 secret, NULL, filename) < 0)
883 strncpy(passwd, secret, MAXSECRETLEN);
884 passwd[MAXSECRETLEN-1] = 0;
890 * have_upap_secret - check whether we have a PAP file with any
891 * secrets that we could possibly use for authenticating the peer.
899 ipcp_options *ipwo = &ipcp_wantoptions[0];
902 filename = _PATH_UPAPFILE;
903 f = fopen(filename, "r");
907 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
908 ret = scan_authfile(f, NULL, our_name, remote, NULL, NULL, filename);
918 * have_chap_secret - check whether we have a CHAP file with a
919 * secret that we could possibly use for authenticating `client'
920 * on `server'. Either can be the null string, meaning we don't
921 * know the identity yet.
924 have_chap_secret(client, server, remote)
933 filename = _PATH_CHAPFILE;
934 f = fopen(filename, "r");
940 else if (server[0] == 0)
943 ret = scan_authfile(f, client, server, remote, NULL, NULL, filename);
953 * get_secret - open the CHAP secret file and return the secret
954 * for authenticating the given client on the given server.
955 * (We could be either client or server).
958 get_secret(unit, client, server, secret, secret_len, save_addrs)
969 struct wordlist *addrs;
970 char secbuf[MAXWORDLEN];
972 filename = _PATH_CHAPFILE;
976 f = fopen(filename, "r");
978 syslog(LOG_ERR, "Can't open chap secret file %s: %m", filename);
981 check_access(f, filename);
983 ret = scan_authfile(f, client, server, (u_int32_t)0,
984 secbuf, &addrs, filename);
990 if (addresses[unit] != NULL)
991 free_wordlist(addresses[unit]);
992 addresses[unit] = addrs;
995 len = strlen(secbuf);
996 if (len > MAXSECRETLEN) {
997 syslog(LOG_ERR, "Secret for %s on %s is too long", client, server);
1000 BCOPY(secbuf, secret, len);
1007 * auth_ip_addr - check whether the peer is authorized to use
1008 * a given IP address. Returns 1 if authorized, 0 otherwise.
1011 auth_ip_addr(unit, addr)
1015 return ip_addr_check(addr, addresses[unit]);
1019 ip_addr_check(addr, addrs)
1021 struct wordlist *addrs;
1023 u_int32_t a, mask, ah;
1025 char *ptr_word, *ptr_mask;
1029 /* don't allow loopback or multicast address */
1030 if (bad_ip_adrs(addr))
1034 return 1; /* no restriction */
1036 for (; addrs != NULL; addrs = addrs->next) {
1037 /* "-" means no addresses authorized */
1038 ptr_word = addrs->word;
1039 if (strcmp(ptr_word, "-") == 0)
1043 if (*ptr_word == '!') {
1048 mask = ~ (u_int32_t) 0;
1049 ptr_mask = strchr (ptr_word, '/');
1050 if (ptr_mask != NULL) {
1053 bit_count = (int) strtol (ptr_mask+1, (char **) 0, 10);
1054 if (bit_count <= 0 || bit_count > 32) {
1055 syslog (LOG_WARNING,
1056 "invalid address length %s in auth. address list",
1061 mask <<= 32 - bit_count;
1064 hp = gethostbyname(ptr_word);
1065 if (hp != NULL && hp->h_addrtype == AF_INET) {
1066 a = *(u_int32_t *)hp->h_addr;
1067 mask = ~ (u_int32_t) 0; /* are we sure we want this? */
1069 np = getnetbyname (ptr_word);
1070 if (np != NULL && np->n_addrtype == AF_INET)
1071 a = htonl (*(u_int32_t *)np->n_net);
1073 a = inet_addr (ptr_word);
1074 if (ptr_mask == NULL) {
1075 /* calculate appropriate mask for net */
1078 mask = IN_CLASSA_NET;
1079 else if (IN_CLASSB(ah))
1080 mask = IN_CLASSB_NET;
1081 else if (IN_CLASSC(ah))
1082 mask = IN_CLASSC_NET;
1086 if (ptr_mask != NULL)
1090 syslog (LOG_WARNING,
1091 "unknown host %s in auth. address list",
1094 if (((addr ^ a) & htonl(mask)) == 0)
1097 return 0; /* not in list => can't have it */
1101 * bad_ip_adrs - return 1 if the IP address is one we don't want
1102 * to use, such as an address in the loopback net or a multicast address.
1103 * addr is in network byte order.
1110 return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
1111 || IN_MULTICAST(addr) || IN_BADCLASS(addr);
1115 * check_access - complain if a secret file has too-liberal permissions.
1118 check_access(f, filename)
1124 if (fstat(fileno(f), &sbuf) < 0) {
1125 syslog(LOG_WARNING, "cannot stat secret file %s: %m", filename);
1126 } else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
1127 syslog(LOG_WARNING, "Warning - secret file %s has world and/or group access", filename);
1133 * scan_authfile - Scan an authorization file for a secret suitable
1134 * for authenticating `client' on `server'. The return value is -1
1135 * if no secret is found, otherwise >= 0. The return value has
1136 * NONWILD_CLIENT set if the secret didn't have "*" for the client, and
1137 * NONWILD_SERVER set if the secret didn't have "*" for the server.
1138 * Any following words on the line (i.e. address authorization
1139 * info) are placed in a wordlist and returned in *addrs.
1142 scan_authfile(f, client, server, ipaddr, secret, addrs, filename)
1148 struct wordlist **addrs;
1152 int got_flag, best_flag;
1154 struct wordlist *ap, *addr_list, *alist, *alast;
1155 char word[MAXWORDLEN];
1156 char atfile[MAXWORDLEN];
1157 char lsecret[MAXWORDLEN];
1162 if (!getword(f, word, &newline, filename))
1163 return -1; /* file is empty??? */
1168 * Skip until we find a word at the start of a line.
1170 while (!newline && getword(f, word, &newline, filename))
1173 break; /* got to end of file */
1176 * Got a client - check if it's a match or a wildcard.
1179 if (client != NULL && strcmp(word, client) != 0 && !ISWILD(word)) {
1184 got_flag = NONWILD_CLIENT;
1187 * Now get a server and check if it matches.
1189 if (!getword(f, word, &newline, filename))
1193 if (server != NULL && strcmp(word, server) != 0 && !ISWILD(word))
1196 got_flag |= NONWILD_SERVER;
1199 * Got some sort of a match - see if it's better than what
1202 if (got_flag <= best_flag)
1208 if (!getword(f, word, &newline, filename))
1214 * Special syntax: @filename means read secret from file.
1216 if (word[0] == '@') {
1217 strcpy(atfile, word+1);
1218 if ((sf = fopen(atfile, "r")) == NULL) {
1219 syslog(LOG_WARNING, "can't open indirect secret file %s",
1223 check_access(sf, atfile);
1224 if (!getword(sf, word, &xxx, atfile)) {
1225 syslog(LOG_WARNING, "no secret in indirect secret file %s",
1233 strcpy(lsecret, word);
1236 * Now read address authorization info and make a wordlist.
1238 alist = alast = NULL;
1240 if (!getword(f, word, &newline, filename) || newline)
1242 ap = (struct wordlist *) malloc(sizeof(struct wordlist)
1245 novm("authorized addresses");
1247 strcpy(ap->word, word);
1256 * Check if the given IP address is allowed by the wordlist.
1258 if (ipaddr != 0 && !ip_addr_check(ipaddr, alist)) {
1259 free_wordlist(alist);
1264 * This is the best so far; remember it.
1266 best_flag = got_flag;
1268 free_wordlist(addr_list);
1271 strcpy(secret, lsecret);
1279 else if (addr_list != NULL)
1280 free_wordlist(addr_list);
1286 * free_wordlist - release memory allocated for a wordlist.
1290 struct wordlist *wp;
1292 struct wordlist *next;
1294 while (wp != NULL) {
1302 * auth_script - execute a script with arguments
1303 * interface-name peer-name real-user tty speed
1315 if ((pw = getpwuid(getuid())) != NULL && pw->pw_name != NULL)
1316 user_name = pw->pw_name;
1318 sprintf(struid, "%d", getuid());
1321 sprintf(strspeed, "%d", baud_rate);
1325 argv[2] = peer_authname;
1326 argv[3] = user_name;
1331 run_program(script, argv, 0);