xref: /onnv-gate/usr/src/lib/passwdutil/__check_history.c (revision 1736:71d1464bf004)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1736Swy83408  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <nsswitch.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include "passwdutil.h"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  *	__check_history - check if a user's new password is in the user's
350Sstevel@tonic-gate  *		old password history.
360Sstevel@tonic-gate  *
370Sstevel@tonic-gate  *	Entry
380Sstevel@tonic-gate  *		user = username.
390Sstevel@tonic-gate  *		passwd = new clear text password.
400Sstevel@tonic-gate  *		rep = repositories to check.
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  *	Exit
430Sstevel@tonic-gate  *		PWU_SUCCESS, passwd found in user's old password history.
440Sstevel@tonic-gate  *			The caller should only be interested and fail if
450Sstevel@tonic-gate  *			PWU_SUCCESS is returned.
460Sstevel@tonic-gate  *		PWU_NOT_FOUND, passwd not in user's old password history.
470Sstevel@tonic-gate  *		PWU_errors, PWU_ errors from other routines.
480Sstevel@tonic-gate  *
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate int
__check_history(char * user,char * passwd,pwu_repository_t * rep)510Sstevel@tonic-gate __check_history(char *user, char *passwd, pwu_repository_t *rep)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	int repositories;
540Sstevel@tonic-gate 	int i;
550Sstevel@tonic-gate 	int res;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	repositories = get_ns(rep, PWU_READ);
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	if (repositories == 0)
600Sstevel@tonic-gate 		return (PWU_SYSTEM_ERROR);
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	if (repositories == REP_ERANGE)
630Sstevel@tonic-gate 		return (PWU_REPOSITORY_ERROR);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	i = REP_FILES;
660Sstevel@tonic-gate 	res = PWU_NOT_FOUND;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	/* Loop over repositories until the user is found */
690Sstevel@tonic-gate 	while ((i <= REP_LAST) && (res == PWU_NOT_FOUND)) {
700Sstevel@tonic-gate 		if (repositories & i)
71*1736Swy83408 			if (rops[i]->checkhistory != NULL)
72*1736Swy83408 				res = rops[i]->checkhistory(user, passwd, rep);
730Sstevel@tonic-gate 		i <<= 1;
740Sstevel@tonic-gate 	}
750Sstevel@tonic-gate 	return (res);
760Sstevel@tonic-gate }
77