2001-10-29 16:12:16 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* Dave Safford. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-10-01 16:04:55 +00:00
|
|
|
#include <sys/cdefs.h>
|
2001-11-30 21:06:38 +00:00
|
|
|
|
2001-10-01 16:04:55 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2000-07-16 05:48:49 +00:00
|
|
|
|
1999-08-16 11:24:29 +00:00
|
|
|
#ifdef SRA
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef ENCRYPTION
|
1999-08-16 11:24:29 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <arpa/telnet.h>
|
2001-11-30 21:06:38 +00:00
|
|
|
#include <pwd.h>
|
1999-08-16 11:24:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-11-30 21:06:38 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <ttyent.h>
|
1999-08-16 11:24:29 +00:00
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifndef NOPAM
|
2001-05-07 20:42:02 +00:00
|
|
|
#include <security/pam_appl.h>
|
2001-08-20 12:28:40 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2001-05-07 20:42:02 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-16 11:24:29 +00:00
|
|
|
#include "auth.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "encrypt.h"
|
|
|
|
#include "pk.h"
|
|
|
|
|
|
|
|
char pka[HEXKEYBYTES+1], ska[HEXKEYBYTES+1], pkb[HEXKEYBYTES+1];
|
2001-11-30 21:06:38 +00:00
|
|
|
char *user, *pass, *xuser, *xpass;
|
1999-08-16 11:24:29 +00:00
|
|
|
DesData ck;
|
|
|
|
IdeaData ik;
|
|
|
|
|
|
|
|
extern int auth_debug_mode;
|
2002-05-06 09:46:29 +00:00
|
|
|
extern char line[];
|
2001-05-15 04:47:14 +00:00
|
|
|
|
2001-08-20 12:28:40 +00:00
|
|
|
static int sra_valid = 0;
|
|
|
|
static int passwd_sent = 0;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
|
|
|
|
AUTHTYPE_SRA, };
|
|
|
|
|
|
|
|
#define SRA_KEY 0
|
|
|
|
#define SRA_USER 1
|
|
|
|
#define SRA_CONTINUE 2
|
|
|
|
#define SRA_PASS 3
|
|
|
|
#define SRA_ACCEPT 4
|
|
|
|
#define SRA_REJECT 5
|
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
static int check_user(char *, char *);
|
2001-08-20 12:28:40 +00:00
|
|
|
|
1999-08-16 11:24:29 +00:00
|
|
|
/* support routine to send out authentication message */
|
2001-08-20 12:28:40 +00:00
|
|
|
static int
|
|
|
|
Data(Authenticator *ap, int type, void *d, int c)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
unsigned char *p = str_data + 4;
|
|
|
|
unsigned char *cd = (unsigned char *)d;
|
|
|
|
|
|
|
|
if (c == -1)
|
|
|
|
c = strlen((char *)cd);
|
|
|
|
|
|
|
|
if (auth_debug_mode) {
|
|
|
|
printf("%s:%d: [%d] (%d)",
|
|
|
|
str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
|
|
|
|
str_data[3],
|
|
|
|
type, c);
|
|
|
|
printd(d, c);
|
|
|
|
printf("\r\n");
|
|
|
|
}
|
|
|
|
*p++ = ap->type;
|
|
|
|
*p++ = ap->way;
|
|
|
|
*p++ = type;
|
|
|
|
while (c-- > 0) {
|
|
|
|
if ((*p++ = *cd++) == IAC)
|
|
|
|
*p++ = IAC;
|
|
|
|
}
|
|
|
|
*p++ = IAC;
|
|
|
|
*p++ = SE;
|
|
|
|
if (str_data[3] == TELQUAL_IS)
|
|
|
|
printsub('>', &str_data[2], p - (&str_data[2]));
|
|
|
|
return(net_write(str_data, p - str_data));
|
|
|
|
}
|
|
|
|
|
2001-08-20 12:28:40 +00:00
|
|
|
int
|
2001-11-30 21:06:38 +00:00
|
|
|
sra_init(Authenticator *ap __unused, int server)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
if (server)
|
|
|
|
str_data[3] = TELQUAL_REPLY;
|
|
|
|
else
|
|
|
|
str_data[3] = TELQUAL_IS;
|
|
|
|
|
|
|
|
user = (char *)malloc(256);
|
2001-05-16 18:27:09 +00:00
|
|
|
xuser = (char *)malloc(513);
|
1999-08-16 11:24:29 +00:00
|
|
|
pass = (char *)malloc(256);
|
2001-05-16 18:27:09 +00:00
|
|
|
xpass = (char *)malloc(513);
|
2001-05-16 18:17:55 +00:00
|
|
|
|
|
|
|
if (user == NULL || xuser == NULL || pass == NULL || xpass ==
|
|
|
|
NULL)
|
|
|
|
return 0; /* malloc failed */
|
|
|
|
|
1999-08-16 11:24:29 +00:00
|
|
|
passwd_sent = 0;
|
|
|
|
|
|
|
|
genkeys(pka,ska);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* client received a go-ahead for sra */
|
2001-08-20 12:28:40 +00:00
|
|
|
int
|
|
|
|
sra_send(Authenticator *ap)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
/* send PKA */
|
|
|
|
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Sent PKA to server.\r\n" );
|
|
|
|
printf("Trying SRA secure login:\r\n");
|
|
|
|
if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Not enough room for authentication data\r\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* server received an IS -- could be SRA KEY, USER, or PASS */
|
2001-08-20 12:28:40 +00:00
|
|
|
void
|
|
|
|
sra_is(Authenticator *ap, unsigned char *data, int cnt)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
int valid;
|
|
|
|
Session_Key skey;
|
|
|
|
|
|
|
|
if (cnt-- < 1)
|
2001-05-16 20:24:58 +00:00
|
|
|
goto bad;
|
1999-08-16 11:24:29 +00:00
|
|
|
switch (*data++) {
|
|
|
|
|
|
|
|
case SRA_KEY:
|
|
|
|
if (cnt < HEXKEYBYTES) {
|
|
|
|
Data(ap, SRA_REJECT, (void *)0, 0);
|
|
|
|
auth_finished(ap, AUTH_USER);
|
|
|
|
if (auth_debug_mode) {
|
|
|
|
printf("SRA user rejected for bad PKB\r\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Sent pka\r\n");
|
|
|
|
if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Not enough room\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(pkb,data,HEXKEYBYTES);
|
|
|
|
pkb[HEXKEYBYTES] = '\0';
|
|
|
|
common_key(ska,pkb,&ik,&ck);
|
2001-05-16 20:24:58 +00:00
|
|
|
return;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
case SRA_USER:
|
|
|
|
/* decode KAB(u) */
|
2001-05-16 18:27:09 +00:00
|
|
|
if (cnt > 512) /* Attempted buffer overflow */
|
|
|
|
break;
|
1999-08-16 11:24:29 +00:00
|
|
|
memcpy(xuser,data,cnt);
|
|
|
|
xuser[cnt] = '\0';
|
|
|
|
pk_decode(xuser,user,&ck);
|
|
|
|
auth_encrypt_user(user);
|
|
|
|
Data(ap, SRA_CONTINUE, (void *)0, 0);
|
|
|
|
|
2001-05-16 20:24:58 +00:00
|
|
|
return;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
case SRA_PASS:
|
2001-05-16 18:27:09 +00:00
|
|
|
if (cnt > 512) /* Attempted buffer overflow */
|
|
|
|
break;
|
1999-08-16 11:24:29 +00:00
|
|
|
/* decode KAB(P) */
|
|
|
|
memcpy(xpass,data,cnt);
|
|
|
|
xpass[cnt] = '\0';
|
|
|
|
pk_decode(xpass,pass,&ck);
|
|
|
|
|
|
|
|
/* check user's password */
|
|
|
|
valid = check_user(user,pass);
|
|
|
|
|
|
|
|
if(valid) {
|
|
|
|
Data(ap, SRA_ACCEPT, (void *)0, 0);
|
|
|
|
skey.data = ck;
|
|
|
|
skey.type = SK_DES;
|
|
|
|
skey.length = 8;
|
|
|
|
encrypt_session_key(&skey, 1);
|
|
|
|
|
|
|
|
sra_valid = 1;
|
|
|
|
auth_finished(ap, AUTH_VALID);
|
|
|
|
if (auth_debug_mode) {
|
|
|
|
printf("SRA user accepted\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Data(ap, SRA_CONTINUE, (void *)0, 0);
|
|
|
|
/*
|
|
|
|
Data(ap, SRA_REJECT, (void *)0, 0);
|
|
|
|
sra_valid = 0;
|
|
|
|
auth_finished(ap, AUTH_REJECT);
|
|
|
|
*/
|
|
|
|
if (auth_debug_mode) {
|
|
|
|
printf("SRA user failed\r\n");
|
|
|
|
}
|
|
|
|
}
|
2001-05-16 20:24:58 +00:00
|
|
|
return;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Unknown SRA option %d\r\n", data[-1]);
|
|
|
|
}
|
2001-05-16 20:24:58 +00:00
|
|
|
bad:
|
|
|
|
Data(ap, SRA_REJECT, 0, 0);
|
|
|
|
sra_valid = 0;
|
|
|
|
auth_finished(ap, AUTH_REJECT);
|
1999-08-16 11:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* client received REPLY -- could be SRA KEY, CONTINUE, ACCEPT, or REJECT */
|
2001-08-20 12:28:40 +00:00
|
|
|
void
|
|
|
|
sra_reply(Authenticator *ap, unsigned char *data, int cnt)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
char uprompt[256],tuser[256];
|
|
|
|
Session_Key skey;
|
2001-11-30 21:06:38 +00:00
|
|
|
size_t i;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
if (cnt-- < 1)
|
|
|
|
return;
|
|
|
|
switch (*data++) {
|
|
|
|
|
|
|
|
case SRA_KEY:
|
|
|
|
/* calculate common key */
|
|
|
|
if (cnt < HEXKEYBYTES) {
|
|
|
|
if (auth_debug_mode) {
|
|
|
|
printf("SRA user rejected for bad PKB\r\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(pkb,data,HEXKEYBYTES);
|
|
|
|
pkb[HEXKEYBYTES] = '\0';
|
|
|
|
|
|
|
|
common_key(ska,pkb,&ik,&ck);
|
|
|
|
|
|
|
|
enc_user:
|
|
|
|
|
|
|
|
/* encode user */
|
|
|
|
memset(tuser,0,sizeof(tuser));
|
|
|
|
sprintf(uprompt,"User (%s): ",UserNameRequested);
|
|
|
|
telnet_gets(uprompt,tuser,255,1);
|
|
|
|
if (tuser[0] == '\n' || tuser[0] == '\r' )
|
|
|
|
strcpy(user,UserNameRequested);
|
|
|
|
else {
|
|
|
|
/* telnet_gets leaves the newline on */
|
|
|
|
for(i=0;i<sizeof(tuser);i++) {
|
|
|
|
if (tuser[i] == '\n') {
|
|
|
|
tuser[i] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(user,tuser);
|
|
|
|
}
|
|
|
|
pk_encode(user,xuser,&ck);
|
|
|
|
|
|
|
|
/* send it off */
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Sent KAB(U)\r\n");
|
|
|
|
if (!Data(ap, SRA_USER, (void *)xuser, strlen(xuser))) {
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Not enough room\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRA_CONTINUE:
|
|
|
|
if (passwd_sent) {
|
|
|
|
passwd_sent = 0;
|
|
|
|
printf("[ SRA login failed ]\r\n");
|
|
|
|
goto enc_user;
|
|
|
|
}
|
|
|
|
/* encode password */
|
2011-12-16 00:48:53 +00:00
|
|
|
memset(pass,0,256);
|
1999-08-16 11:24:29 +00:00
|
|
|
telnet_gets("Password: ",pass,255,0);
|
|
|
|
pk_encode(pass,xpass,&ck);
|
|
|
|
/* send it off */
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Sent KAB(P)\r\n");
|
|
|
|
if (!Data(ap, SRA_PASS, (void *)xpass, strlen(xpass))) {
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Not enough room\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
passwd_sent = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRA_REJECT:
|
|
|
|
printf("[ SRA refuses authentication ]\r\n");
|
|
|
|
printf("Trying plaintext login:\r\n");
|
|
|
|
auth_finished(0,AUTH_REJECT);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case SRA_ACCEPT:
|
|
|
|
printf("[ SRA accepts you ]\r\n");
|
|
|
|
skey.data = ck;
|
|
|
|
skey.type = SK_DES;
|
|
|
|
skey.length = 8;
|
|
|
|
encrypt_session_key(&skey, 0);
|
|
|
|
|
|
|
|
auth_finished(ap, AUTH_VALID);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
if (auth_debug_mode)
|
|
|
|
printf("Unknown SRA option %d\r\n", data[-1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-20 12:28:40 +00:00
|
|
|
int
|
2001-11-30 21:06:38 +00:00
|
|
|
sra_status(Authenticator *ap __unused, char *name, int level)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
if (level < AUTH_USER)
|
|
|
|
return(level);
|
|
|
|
if (UserNameRequested && sra_valid) {
|
|
|
|
strcpy(name, UserNameRequested);
|
|
|
|
return(AUTH_VALID);
|
|
|
|
} else
|
|
|
|
return(AUTH_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
|
|
|
|
#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
|
|
|
|
|
2001-08-20 12:28:40 +00:00
|
|
|
void
|
|
|
|
sra_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
|
|
|
char lbuf[32];
|
2001-11-30 21:06:38 +00:00
|
|
|
int i;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
|
|
|
buf[buflen-1] = '\0'; /* make sure its NULL terminated */
|
|
|
|
buflen -= 1;
|
|
|
|
|
|
|
|
switch(data[3]) {
|
|
|
|
|
|
|
|
case SRA_CONTINUE:
|
|
|
|
strncpy((char *)buf, " CONTINUE ", buflen);
|
|
|
|
goto common;
|
|
|
|
|
|
|
|
case SRA_REJECT: /* Rejected (reason might follow) */
|
|
|
|
strncpy((char *)buf, " REJECT ", buflen);
|
|
|
|
goto common;
|
|
|
|
|
|
|
|
case SRA_ACCEPT: /* Accepted (name might follow) */
|
|
|
|
strncpy((char *)buf, " ACCEPT ", buflen);
|
|
|
|
|
|
|
|
common:
|
|
|
|
BUMP(buf, buflen);
|
|
|
|
if (cnt <= 4)
|
|
|
|
break;
|
|
|
|
ADDC(buf, buflen, '"');
|
|
|
|
for (i = 4; i < cnt; i++)
|
|
|
|
ADDC(buf, buflen, data[i]);
|
|
|
|
ADDC(buf, buflen, '"');
|
|
|
|
ADDC(buf, buflen, '\0');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRA_KEY: /* Authentication data follows */
|
|
|
|
strncpy((char *)buf, " KEY ", buflen);
|
|
|
|
goto common2;
|
|
|
|
|
|
|
|
case SRA_USER:
|
|
|
|
strncpy((char *)buf, " USER ", buflen);
|
|
|
|
goto common2;
|
|
|
|
|
|
|
|
case SRA_PASS:
|
|
|
|
strncpy((char *)buf, " PASS ", buflen);
|
|
|
|
goto common2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sprintf(lbuf, " %d (unknown)", data[3]);
|
|
|
|
strncpy((char *)buf, lbuf, buflen);
|
|
|
|
common2:
|
|
|
|
BUMP(buf, buflen);
|
|
|
|
for (i = 4; i < cnt; i++) {
|
|
|
|
sprintf(lbuf, " %d", data[i]);
|
|
|
|
strncpy((char *)buf, lbuf, buflen);
|
|
|
|
BUMP(buf, buflen);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 04:47:14 +00:00
|
|
|
static int
|
2001-11-30 21:06:38 +00:00
|
|
|
isroot(const char *usr)
|
2001-05-15 04:47:14 +00:00
|
|
|
{
|
2001-11-30 21:06:38 +00:00
|
|
|
struct passwd *pwd;
|
2001-05-15 04:47:14 +00:00
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
if ((pwd=getpwnam(usr))==NULL)
|
2001-05-15 04:47:14 +00:00
|
|
|
return 0;
|
2001-11-30 21:06:38 +00:00
|
|
|
return (!pwd->pw_uid);
|
2001-05-15 04:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-08-20 12:28:40 +00:00
|
|
|
rootterm(char *ttyn)
|
2001-05-15 04:47:14 +00:00
|
|
|
{
|
|
|
|
struct ttyent *t;
|
|
|
|
|
|
|
|
return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
|
|
|
|
}
|
|
|
|
|
2001-05-07 20:42:02 +00:00
|
|
|
#ifdef NOPAM
|
2001-08-20 12:28:40 +00:00
|
|
|
static int
|
2001-11-30 21:06:38 +00:00
|
|
|
check_user(char *name, char *cred)
|
1999-08-16 11:24:29 +00:00
|
|
|
{
|
2001-11-30 21:06:38 +00:00
|
|
|
char *cp;
|
1999-08-16 11:24:29 +00:00
|
|
|
char *xpasswd, *salt;
|
|
|
|
|
2001-05-15 04:47:14 +00:00
|
|
|
if (isroot(name) && !rootterm(line))
|
|
|
|
{
|
|
|
|
crypt("AA","*"); /* Waste some time to simulate success */
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1999-08-16 11:24:29 +00:00
|
|
|
if (pw = sgetpwnam(name)) {
|
|
|
|
if (pw->pw_shell == NULL) {
|
|
|
|
pw = (struct passwd *) NULL;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
salt = pw->pw_passwd;
|
2001-11-30 21:06:38 +00:00
|
|
|
xpasswd = crypt(cred, salt);
|
1999-08-16 11:24:29 +00:00
|
|
|
/* The strcmp does not catch null passwords! */
|
|
|
|
if (pw == NULL || *pw->pw_passwd == '\0' ||
|
|
|
|
strcmp(xpasswd, pw->pw_passwd)) {
|
|
|
|
pw = (struct passwd *) NULL;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
2001-05-07 20:42:02 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is stolen from ftpd, which stole it from the imap-uw
|
|
|
|
* PAM module and login.c. It is needed because we can't really
|
|
|
|
* "converse" with the user, having already gone to the trouble of
|
|
|
|
* getting their username and password through an encrypted channel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COPY_STRING(s) (s ? strdup(s):NULL)
|
|
|
|
|
|
|
|
struct cred_t {
|
|
|
|
const char *uname;
|
|
|
|
const char *pass;
|
|
|
|
};
|
|
|
|
typedef struct cred_t cred_t;
|
1999-08-16 11:24:29 +00:00
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
static int
|
|
|
|
auth_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata)
|
2001-05-07 20:42:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
cred_t *cred = (cred_t *) appdata;
|
|
|
|
struct pam_response *reply =
|
|
|
|
malloc(sizeof(struct pam_response) * num_msg);
|
|
|
|
|
2001-05-16 18:17:55 +00:00
|
|
|
if (reply == NULL)
|
|
|
|
return PAM_BUF_ERR;
|
|
|
|
|
2001-05-07 20:42:02 +00:00
|
|
|
for (i = 0; i < num_msg; i++) {
|
|
|
|
switch (msg[i]->msg_style) {
|
|
|
|
case PAM_PROMPT_ECHO_ON: /* assume want user name */
|
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
reply[i].resp = COPY_STRING(cred->uname);
|
|
|
|
/* PAM frees resp. */
|
|
|
|
break;
|
|
|
|
case PAM_PROMPT_ECHO_OFF: /* assume want password */
|
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
reply[i].resp = COPY_STRING(cred->pass);
|
|
|
|
/* PAM frees resp. */
|
|
|
|
break;
|
|
|
|
case PAM_TEXT_INFO:
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
reply[i].resp = NULL;
|
|
|
|
break;
|
|
|
|
default: /* unknown message style */
|
|
|
|
free(reply);
|
|
|
|
return PAM_CONV_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*resp = reply;
|
|
|
|
return PAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-17 16:28:11 +00:00
|
|
|
* The PAM version as a side effect may put a new username in *name.
|
2001-05-07 20:42:02 +00:00
|
|
|
*/
|
2001-08-20 12:28:40 +00:00
|
|
|
static int
|
2001-11-30 21:06:38 +00:00
|
|
|
check_user(char *name, char *cred)
|
2001-05-07 20:42:02 +00:00
|
|
|
{
|
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
const void *item;
|
|
|
|
int rval;
|
|
|
|
int e;
|
2001-11-30 21:06:38 +00:00
|
|
|
cred_t auth_cred = { name, cred };
|
2001-05-07 20:42:02 +00:00
|
|
|
struct pam_conv conv = { &auth_conv, &auth_cred };
|
|
|
|
|
|
|
|
e = pam_start("telnetd", name, &conv, &pamh);
|
|
|
|
if (e != PAM_SUCCESS) {
|
|
|
|
syslog(LOG_ERR, "pam_start: %s", pam_strerror(pamh, e));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* Where can we find this value? */
|
|
|
|
e = pam_set_item(pamh, PAM_RHOST, remotehost);
|
|
|
|
if (e != PAM_SUCCESS) {
|
|
|
|
syslog(LOG_ERR, "pam_set_item(PAM_RHOST): %s",
|
|
|
|
pam_strerror(pamh, e));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
e = pam_authenticate(pamh, 0);
|
|
|
|
switch (e) {
|
|
|
|
case PAM_SUCCESS:
|
|
|
|
/*
|
|
|
|
* With PAM we support the concept of a "template"
|
|
|
|
* user. The user enters a login name which is
|
|
|
|
* authenticated by PAM, usually via a remote service
|
|
|
|
* such as RADIUS or TACACS+. If authentication
|
|
|
|
* succeeds, a different but related "template" name
|
|
|
|
* is used for setting the credentials, shell, and
|
|
|
|
* home directory. The name the user enters need only
|
|
|
|
* exist on the remote authentication server, but the
|
|
|
|
* template name must be present in the local password
|
|
|
|
* database.
|
|
|
|
*
|
|
|
|
* This is supported by two various mechanisms in the
|
|
|
|
* individual modules. However, from the application's
|
|
|
|
* point of view, the template user is always passed
|
|
|
|
* back as a changed value of the PAM_USER item.
|
|
|
|
*/
|
|
|
|
if ((e = pam_get_item(pamh, PAM_USER, &item)) ==
|
|
|
|
PAM_SUCCESS) {
|
2001-11-30 21:06:38 +00:00
|
|
|
strcpy(name, item);
|
2001-05-07 20:42:02 +00:00
|
|
|
} else
|
|
|
|
syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
|
|
|
|
pam_strerror(pamh, e));
|
2001-05-17 16:28:11 +00:00
|
|
|
if (isroot(name) && !rootterm(line))
|
2001-05-15 04:47:14 +00:00
|
|
|
rval = 0;
|
|
|
|
else
|
|
|
|
rval = 1;
|
2001-05-07 20:42:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAM_AUTH_ERR:
|
|
|
|
case PAM_USER_UNKNOWN:
|
|
|
|
case PAM_MAXTRIES:
|
|
|
|
rval = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
syslog(LOG_ERR, "auth_pam: %s", pam_strerror(pamh, e));
|
|
|
|
rval = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((e = pam_end(pamh, e)) != PAM_SUCCESS) {
|
|
|
|
syslog(LOG_ERR, "pam_end: %s", pam_strerror(pamh, e));
|
|
|
|
rval = 0;
|
|
|
|
}
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
1999-08-16 11:24:29 +00:00
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
#endif /* ENCRYPTION */
|
|
|
|
#endif /* SRA */
|