4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
6 * Copyright (C) 1993-94, Internet Initiative Japan, Inc.
7 * All rights reserverd.
9 * Redistribution and use in source and binary forms are permitted
10 * provided that the above copyright notice and this paragraph are
11 * duplicated in all such forms and that any documentation,
12 * advertising materials, and other materials related to such
13 * distribution and use acknowledge that the software was developed
14 * by the Internet Initiative Japan, Inc. The name of the
15 * IIJ may not be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * $Id: pap.c,v 1.21 1998/02/19 02:10:13 brian Exp $
25 #include <sys/param.h>
26 #include <netinet/in.h>
48 #include "loadalias.h"
56 static const char *papcodes[] = { "???", "REQUEST", "ACK", "NAK" };
59 SendPapChallenge(int papid)
64 int namelen, keylen, plen;
66 namelen = strlen(VarAuthName);
67 keylen = strlen(VarAuthKey);
68 plen = namelen + keylen + 2;
69 LogPrintf(LogDEBUG, "SendPapChallenge: namelen = %d, keylen = %d\n",
71 if (LogIsKept(LogDEBUG))
72 LogPrintf(LogPHASE, "PAP: %s (%s)\n", VarAuthName, VarAuthKey);
74 LogPrintf(LogPHASE, "PAP: %s\n", VarAuthName);
75 lh.code = PAP_REQUEST;
77 lh.length = htons(plen + sizeof(struct fsmheader));
78 bp = mballoc(plen + sizeof(struct fsmheader), MB_FSM);
79 memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
80 cp = MBUF_CTOP(bp) + sizeof(struct fsmheader);
82 memcpy(cp, VarAuthName, namelen);
85 memcpy(cp, VarAuthKey, keylen);
87 HdlcOutput(PRI_LINK, PROTO_PAP, bp);
90 struct authinfo AuthPapInfo = {
95 SendPapCode(int id, int code, const char *message)
104 mlen = strlen(message);
106 lh.length = htons(plen + sizeof(struct fsmheader));
107 bp = mballoc(plen + sizeof(struct fsmheader), MB_FSM);
108 memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
109 cp = MBUF_CTOP(bp) + sizeof(struct fsmheader);
111 memcpy(cp, message, mlen);
112 LogPrintf(LogPHASE, "PapOutput: %s\n", papcodes[code]);
113 HdlcOutput(PRI_LINK, PROTO_PAP, bp);
117 * Validate given username and passwrd against with secret table
120 PapValidate(u_char * name, u_char * key)
128 LogPrintf(LogDEBUG, "PapValidate: name %s (%d), key %s (%d)\n",
129 name, nlen, key, klen);
132 if (Enabled(ConfPasswdAuth)) {
136 LogPrintf(LogLCP, "Using PasswdAuth\n");
137 result = (pwd = getpwnam(name)) &&
138 !strcmp(crypt(key, pwd->pw_passwd), pwd->pw_passwd);
144 return (AuthValidate(SECRETFILE, name, key));
148 PapInput(struct mbuf * bp)
150 int len = plength(bp);
151 struct fsmheader *php;
152 struct lcpstate *lcp = &LcpInfo;
155 if (len >= sizeof(struct fsmheader)) {
156 php = (struct fsmheader *) MBUF_CTOP(bp);
157 if (len >= ntohs(php->length)) {
158 if (php->code < PAP_REQUEST || php->code > PAP_NAK)
160 LogPrintf(LogPHASE, "PapInput: %s\n", papcodes[php->code]);
164 cp = (u_char *) (php + 1);
165 if (PapValidate(cp, cp + *cp + 1)) {
166 SendPapCode(php->id, PAP_ACK, "Greetings!!");
168 if (lcp->auth_iwait == 0) {
169 if ((mode & MODE_DIRECT) && isatty(modem) && Enabled(ConfUtmp)) {
171 LogPrintf(LogERROR, "Oops, already logged in on %s\n",
175 memset(&ut, 0, sizeof ut);
177 strncpy(ut.ut_name, cp+1, sizeof ut.ut_name);
178 strncpy(ut.ut_line, VarBaseDevice, sizeof ut.ut_line - 1);
183 NewPhase(PHASE_NETWORK);
186 SendPapCode(php->id, PAP_NAK, "Login incorrect");
187 reconnect(RECON_FALSE);
192 StopAuthTimer(&AuthPapInfo);
193 cp = (u_char *) (php + 1);
196 LogPrintf(LogPHASE, "Received PAP_ACK (%s)\n", cp);
197 if (lcp->auth_iwait == PROTO_PAP) {
199 if (lcp->auth_ineed == 0)
200 NewPhase(PHASE_NETWORK);
204 StopAuthTimer(&AuthPapInfo);
205 cp = (u_char *) (php + 1);
208 LogPrintf(LogPHASE, "Received PAP_NAK (%s)\n", cp);
209 reconnect(RECON_FALSE);