krb5_password.c revision 0be37caa4e8536519ad4fdbfc883320bf36d7760
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <krb5.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <security/pam_impl.h>
#include <syslog.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <libintl.h>
#include <netdb.h>
#include "utils.h"
#include "krb5_repository.h"
#define MISC_EXIT_STATUS 6
#define DONT_DISP_POLICY 0
#define DISP_POLICY 1
extern int attempt_krb5_auth(void *, krb5_module_data_t *, char *, char **,
static char *get_passwd(pam_handle_t *, char *);
static void display_msg(pam_handle_t *, int, char *);
static void display_msgs(pam_handle_t *, int, int,
char msgs[][PAM_MAX_MSG_SIZE]);
static int krb5_changepw(pam_handle_t *, char *, char *, char *, int);
/*
* set_ccname()
*
* set KRB5CCNAME shell var
*/
static void
int login_result,
int debug)
{
int result;
if (debug)
"PAM-KRB5 (password): password: finalize"
" ccname env, login_result =%d, env ='%s'",
if (login_result == PAM_SUCCESS) {
/*
* Put ccname into the pamh so that login
* apps can pick this up when they run
* pam_getenvlist().
*/
!= PAM_SUCCESS) {
/* should not happen but... */
"PAM-KRB5 (password):"
" pam_putenv failed: result: %d"),
result);
goto cleanupccname;
}
} else {
/* for lack of a Solaris unputenv() */
}
}
}
/*
* get_set_creds()
*
* do a krb5 login to get and set krb5 creds (needed after a pw change
* on pw expire on login)
*/
static void
char *user,
char *newpass,
int debug)
{
int login_result;
return;
/*
*
* pwchange verified user sufficiently, so don't request strict
* tgt verification (will cause rcache perm issues possibly anyways)
*/
if (debug)
"PAM-KRB5 (password): get_set_creds: login_result= %d",
/*
* the krb5 login should not fail, but if so,
* warn the user they have to kinit(1)
*/
if (login_result != PAM_SUCCESS) {
"Warning: "
"Could not cache Kerberos"
" credentials, please run "
"kinit(1) or re-login\n"));
}
}
/*
* This is the PAM Kerberos Password Change module
*
*/
int
int flags,
int argc,
const char **argv)
{
char *user;
int i;
int debug = 0;
char *pam_service;
int promptforold = 0;
int promptfornew = 0;
for (i = 0; i < argc; i++) {
debug = 1;
else
"PAM-KRB5 (password): illegal option %s"),
argv[i]);
}
if (debug)
"PAM-KRB5 (password): start: flags = %x",
flags);
if (debug)
"repository found (%s), returning "
return (PAM_IGNORE);
}
}
if (flags & PAM_PRELIM_CHECK) {
/* Nothing to do here */
if (debug)
"PAM-KRB5 (password): prelim check");
return (PAM_IGNORE);
}
/* make sure PAM framework is telling us to update passwords */
if (!(flags & PAM_UPDATE_AUTHTOK)) {
"PAM-KRB5 (password): bad flags: %d"),
flags);
return (PAM_SYSTEM_ERR);
}
!= PAM_SUCCESS) {
if (debug)
"PAM-KRB5 (password): get mod data failed %d",
err);
}
if (flags & PAM_CHANGE_EXPIRED_AUTHTOK) {
/* let's make sure we know the krb5 pw has expired */
if (debug)
"PAM-KRB5 (password): kmd age status %d",
return (PAM_IGNORE);
}
if (err != PAM_SUCCESS) {
"PAM-KRB5 (password): error getting SERVICE");
return (PAM_SYSTEM_ERR);
}
if (err != PAM_SUCCESS) {
"PAM-KRB5 (password): error getting USER");
return (PAM_SYSTEM_ERR);
}
"PAM-KRB5 (password): username is empty");
return (PAM_SYSTEM_ERR);
}
"PAM-KRB5 (password): can't get uid for %s",
user);
return (PAM_AUTHTOK_ERR);
}
/*
* if root key exists in the keytab, it's a random key so no
* need to prompt for pw and we just return IGNORE
*/
if (debug)
"PAM-KRB5 (password): "
"key for '%s' in keytab, returning IGNORE", user);
result = PAM_IGNORE;
goto out;
}
(void **) &newpass)) < 0)
return (err);
(void **) &oldpass)) < 0)
return (err);
promptforold = 1;
promptfornew = 1;
} else {
/*
* OLDAUTHTOK not set, we're probably the first password
* module but the AUTHTOK is probably set from an auth mod
*/
promptfornew = 1;
}
if (debug)
"PAM-KRB5 (password): verifypw first %d",
result);
/*
* If this fails and is not bad passwd, then it might
* be a non-rpcsec_gss KDC so drop thru.
*
* (note in S9 change pw should work on non-rpcsec_gss KDCs
* such as MIT & MS)
*/
if (result != 0)
promptforold = 1;
}
if (promptforold) {
"Old Kerberos password: "));
/* Need a password to proceed */
"Need the old password"
" to proceed \n"));
return (PAM_AUTHTOK_ERR);
}
DISP_POLICY, debug);
if (debug)
"PAM-KRB5 (password): verifypw prforold %d",
result);
/*
* If it's a bad password, we are done.
* Else, continue and try the pwch with oldpass.
*/
if (result == 2) {
"Old Kerberos"
" password incorrect\n"));
return (PAM_AUTHTOK_ERR);
}
}
if (promptfornew) {
"New Kerberos password: "));
/* Need a password to proceed */
"Need a password to proceed \n"));
goto out;
}
"Re-enter new Kerberos password: "));
/* Need a password to proceed */
"Need a password to proceed \n"));
goto out;
}
"Passwords do not match \n"));
goto out;
}
}
if (result == PAM_SUCCESS) {
"Kerberos password "
"successfully changed\n"));
}
out:
if (promptforold && oldpass) {
}
if (newpass) {
}
if (vnewpass) {
}
if (debug)
"PAM-KRB5 (password): out: returns %d",
result);
return (result);
}
int
/*ARGSUSED*/
char ***ga_getattr,
int repository,
const char *nisdomain,
int argc,
const char **argv)
{
return (PAM_SUCCESS);
}
int
/*ARGSUSED*/
const char **pam_setattr,
int repository,
const char *nisdomain,
int argc,
const char **argv)
{
return (PAM_SUCCESS);
}
int
char *princ_str,
char *old_password,
int debug)
{
krb5_principal princ = 0;
char admin_realm[1024];
char *cpw_service;
void *server_handle;
#define MSG_ROWS 5
return (6);
}
2*MAXHOSTNAMELEN)) != 0) {
return (code);
}
/* Need to get a krb5_principal struct */
if (code != 0) {
return (MISC_EXIT_STATUS);
}
if (strlen(old_password) == 0) {
return (5);
}
(void) strlcpy(admin_realm,
sizeof (admin_realm));
"PAM-KRB5 (password): unable to get host based "
"service name for realm %s\n"),
return (3);
}
if (code != 0) {
if (debug)
"PAM-KRB5: krb5_verifypw: init_with_pw"
}
if (disp_flag &&
/*
* Note: copy of this exists in login
*/
if (code != 0) {
(void) kadm5_destroy(server_handle);
}
&policy_entry);
if (code != 0) {
/*
* doesn't matter which error comes back,
* there's no nice recovery or need to
* differentiate to the user
*/
(void) kadm5_destroy(server_handle);
return (MISC_EXIT_STATUS);
}
"Principal string is %s"), princ_str);
"Minimum password length is %d"),
"Minimum password classes is %d"),
&principal_entry)) {
(void) kadm5_free_policy_ent(server_handle,
&policy_entry);
(void) kadm5_destroy(server_handle);
return (MISC_EXIT_STATUS);
}
&policy_entry)) {
(void) kadm5_destroy(server_handle);
return (MISC_EXIT_STATUS);
}
} else {
/*
* kpasswd *COULD* output something here to encourage
* the choice of good passwords, in the absence of
* an enforced policy.
*/
&principal_entry)) {
(void) kadm5_destroy(server_handle);
return (MISC_EXIT_STATUS);
}
}
}
(void) kadm5_destroy(server_handle);
return (0);
}
/*
* Function: krb5_changepw
*
* Purpose: Initialize and call lower level routines to change a password
*
* Arguments:
*
* princ_str principal name to use, optional
* old_password old password
* new_password new password
*
* Returns:
* exit status of PAM_SUCCESS for success
* 1 principal unknown
* 2 old password wrong
* 3 cannot initialize admin server session
* 4 new passwd mismatch or error trying to change pw
* 5 password not typed
* 6 misc error
* 7 incorrect usage
*
* Requires:
* Passwords cannot be more than 255 characters long.
*
* Modifies:
*
* Changes the principal's password.
*
*/
static int
char *princ_str,
char *old_password,
char *new_password,
int debug)
{
krb5_principal princ = 0;
char *cpw_service;
void *server_handle;
return (6);
}
2*MAXHOSTNAMELEN)) != 0) {
return (code);
}
/* Need to get a krb5_principal struct */
if (code != 0) {
return (MISC_EXIT_STATUS);
}
if (strlen(old_password) == 0) {
return (5);
}
"PAM-KRB5 (password):unable to get host based "
"service name for realm %s\n"),
return (3);
}
if (code != 0) {
if (debug)
"PAM-KRB5 (password): changepw: "
}
NULL /* don't need pw back */,
sizeof (msg_ret));
if (code) {
"Kerberos password not changed: "));
}
(void) kadm5_destroy(server_handle);
if (debug)
"PAM-KRB5 (password): changepw: end %d", code);
if (code == KRB5_LIBOS_CANTREADPWD)
return (5);
else if (code)
return (4);
else
return (PAM_SUCCESS);
}
static char *
char *prompt)
{
int err;
char *p;
if (err != PAM_SUCCESS) {
return (NULL);
}
return (p);
}
static void
{
}
static void
{
}