2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1992 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2008 - 2009, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifndef USE_PAM
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:17:33 +05:30
|
|
|
#include <errno.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
2007-10-07 17:17:33 +05:30
|
|
|
#include <signal.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
2007-10-07 17:17:33 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "pwauth.h"
|
|
|
|
#include "getdef.h"
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifdef SKEY
|
|
|
|
#include <skey.h>
|
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifdef __linux__ /* standard password prompt by default */
|
|
|
|
static const char *PROMPT = gettext_noop ("Password: ");
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:16:07 +05:30
|
|
|
static const char *PROMPT = gettext_noop ("%s's Password: ");
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
bool wipe_clear_pass = true;
|
|
|
|
/*@null@*/char *clear_pass = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:15:23 +05:30
|
|
|
* pw_auth - perform getpass/crypt authentication
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2007-10-07 17:15:23 +05:30
|
|
|
* pw_auth gets the user's cleartext password and encrypts it
|
|
|
|
* using the salt in the encrypted password. The results are
|
2007-10-07 17:14:02 +05:30
|
|
|
* compared.
|
|
|
|
*/
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
int pw_auth (const char *cipher,
|
|
|
|
const char *user,
|
|
|
|
int reason,
|
|
|
|
/*@null@*/const char *input)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
char prompt[1024];
|
|
|
|
char *clear = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
const char *cp;
|
2013-07-28 22:11:11 +05:30
|
|
|
const char *encrypted;
|
2007-10-07 17:16:07 +05:30
|
|
|
int retval;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifdef SKEY
|
2009-04-24 02:16:01 +05:30
|
|
|
bool use_skey = false;
|
2007-10-07 17:16:34 +05:30
|
|
|
char challenge_info[40];
|
|
|
|
struct skey skey;
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* There are programs for adding and deleting authentication data.
|
|
|
|
*/
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((PW_ADD == reason) || (PW_DELETE == reason)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* There are even programs for changing the user name ...
|
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((PW_CHANGE == reason) && (NULL != input)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING:
|
|
|
|
*
|
|
|
|
* When we change a password and we are root, we don't prompt.
|
|
|
|
* This is so root can change any password without having to
|
|
|
|
* know it. This is a policy decision that might have to be
|
|
|
|
* revisited.
|
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((PW_CHANGE == reason) && (getuid () == 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING:
|
|
|
|
*
|
|
|
|
* When we are logging in a user with no ciphertext password,
|
|
|
|
* we don't prompt for the password or anything. In reality
|
|
|
|
* the user could just hit <ENTER>, so it doesn't really
|
|
|
|
* matter.
|
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((NULL == cipher) || ('\0' == *cipher)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifdef SKEY
|
|
|
|
/*
|
|
|
|
* If the user has an S/KEY entry show them the pertinent info
|
2021-08-18 23:36:02 +05:30
|
|
|
* and then we can try validating the created ciphertext and the SKEY.
|
2007-10-07 17:16:34 +05:30
|
|
|
* If there is no SKEY information we default to not using SKEY.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
# ifdef SKEY_BSD_STYLE
|
|
|
|
/*
|
|
|
|
* Some BSD updates to the S/KEY API adds a fourth parameter; the
|
|
|
|
* sizeof of the challenge info buffer.
|
|
|
|
*/
|
|
|
|
# define skeychallenge(s,u,c) skeychallenge(s,u,c,sizeof(c))
|
|
|
|
# endif
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if (skeychallenge (&skey, user, challenge_info) == 0) {
|
|
|
|
use_skey = true;
|
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Prompt for the password as required. FTPD and REXECD both
|
|
|
|
* get the cleartext password for us.
|
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((PW_FTP != reason) && (PW_REXEC != reason) && (NULL == input)) {
|
|
|
|
cp = getdef_str ("LOGIN_STRING");
|
|
|
|
if (NULL == cp) {
|
2007-10-07 17:14:08 +05:30
|
|
|
cp = _(PROMPT);
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifdef SKEY
|
2009-04-24 02:16:01 +05:30
|
|
|
if (use_skey) {
|
2007-10-07 17:16:34 +05:30
|
|
|
printf ("[%s]\n", challenge_info);
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
snprintf (prompt, sizeof prompt, cp, user);
|
|
|
|
clear = getpass (prompt);
|
2009-04-24 02:16:01 +05:30
|
|
|
if (NULL == clear) {
|
2007-10-07 17:14:02 +05:30
|
|
|
static char c[1];
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
c[0] = '\0';
|
|
|
|
clear = c;
|
|
|
|
}
|
|
|
|
input = clear;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the cleartext password into a ciphertext string.
|
|
|
|
* If the two match, the return value will be zero, which is
|
2007-10-07 17:16:34 +05:30
|
|
|
* SUCCESS. Otherwise we see if SKEY is being used and check
|
|
|
|
* the results there as well.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2013-07-28 22:11:11 +05:30
|
|
|
encrypted = pw_encrypt (input, cipher);
|
2013-08-04 02:37:06 +05:30
|
|
|
if (NULL != encrypted) {
|
2013-07-28 22:11:11 +05:30
|
|
|
retval = strcmp (encrypted, cipher);
|
2013-08-04 02:37:06 +05:30
|
|
|
} else {
|
2013-07-28 22:11:11 +05:30
|
|
|
retval = -1;
|
2013-08-04 02:37:06 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifdef SKEY
|
|
|
|
/*
|
|
|
|
* If (1) The password fails to match, and
|
|
|
|
* (2) The password is empty and
|
|
|
|
* (3) We are using OPIE or S/Key, then
|
|
|
|
* ...Re-prompt, with echo on.
|
|
|
|
* -- AR 8/22/1999
|
|
|
|
*/
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((0 != retval) && ('\0' == input[0]) && use_skey) {
|
2007-10-07 17:17:45 +05:30
|
|
|
clear = getpass (prompt);
|
2009-04-24 02:16:01 +05:30
|
|
|
if (NULL == clear) {
|
2007-10-07 17:16:34 +05:30
|
|
|
static char c[1];
|
|
|
|
|
|
|
|
c[0] = '\0';
|
|
|
|
clear = c;
|
|
|
|
}
|
|
|
|
input = clear;
|
|
|
|
}
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if ((0 != retval) && use_skey) {
|
2007-10-07 17:16:34 +05:30
|
|
|
int passcheck = -1;
|
|
|
|
|
2009-04-24 02:16:01 +05:30
|
|
|
if (skeyverify (&skey, input) == 0) {
|
2007-10-07 17:16:34 +05:30
|
|
|
passcheck = skey.n;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
|
|
|
if (passcheck > 0) {
|
2007-10-07 17:16:34 +05:30
|
|
|
retval = 0;
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Things like RADIUS authentication may need the password -
|
|
|
|
* if the external variable wipe_clear_pass is zero, we will
|
|
|
|
* not wipe it (the caller should wipe clear_pass when it is
|
|
|
|
* no longer needed). --marekm
|
|
|
|
*/
|
2007-10-07 17:16:34 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
clear_pass = clear;
|
2009-04-24 02:16:01 +05:30
|
|
|
if (wipe_clear_pass && (NULL != clear) && ('\0' != *clear)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
strzero (clear);
|
2009-04-24 02:16:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
return retval;
|
|
|
|
}
|
2008-01-01 20:02:41 +05:30
|
|
|
#else /* !USE_PAM */
|
2022-12-21 23:32:25 +05:30
|
|
|
extern int ISO_C_forbids_an_empty_translation_unit;
|
2007-10-07 17:16:07 +05:30
|
|
|
#endif /* !USE_PAM */
|