xref: /freebsd/lib/libutil/login_crypt.c (revision a2f733abcff64628b7771a47089628b7327a88bd)
1c2534fa1SBrian Feldman /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
4c2534fa1SBrian Feldman  * Copyright (c) 2000 Brian Fundakowski Feldman
5c2534fa1SBrian Feldman  * All rights reserved.
6c2534fa1SBrian Feldman  *
7c2534fa1SBrian Feldman  * Redistribution and use in source and binary forms, with or without
8c2534fa1SBrian Feldman  * modification, are permitted provided that the following conditions
9c2534fa1SBrian Feldman  * are met:
10c2534fa1SBrian Feldman  * 1. Redistributions of source code must retain the above copyright
11c2534fa1SBrian Feldman  *    notice, this list of conditions and the following disclaimer.
12c2534fa1SBrian Feldman  * 2. Redistributions in binary form must reproduce the above copyright
13c2534fa1SBrian Feldman  *    notice, this list of conditions and the following disclaimer in the
14c2534fa1SBrian Feldman  *    documentation and/or other materials provided with the distribution.
15c2534fa1SBrian Feldman  *
16c2534fa1SBrian Feldman  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17c2534fa1SBrian Feldman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c2534fa1SBrian Feldman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c2534fa1SBrian Feldman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20c2534fa1SBrian Feldman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c2534fa1SBrian Feldman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c2534fa1SBrian Feldman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c2534fa1SBrian Feldman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c2534fa1SBrian Feldman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c2534fa1SBrian Feldman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c2534fa1SBrian Feldman  * SUCH DAMAGE.
27c2534fa1SBrian Feldman  */
28c2534fa1SBrian Feldman 
29c2534fa1SBrian Feldman #include <sys/types.h>
30c2534fa1SBrian Feldman 
31c2534fa1SBrian Feldman #include <login_cap.h>
32aa864558SBrian Feldman #include <stdio.h>
33aa864558SBrian Feldman #include <stdlib.h>
34c2534fa1SBrian Feldman #include <unistd.h>
35c2534fa1SBrian Feldman 
36c2534fa1SBrian Feldman const char *
login_setcryptfmt(login_cap_t * lc,const char * def,const char * error)37c2534fa1SBrian Feldman login_setcryptfmt(login_cap_t *lc, const char *def, const char *error) {
38c2534fa1SBrian Feldman 	const char *cipher;
39c2534fa1SBrian Feldman 
40b00ba4ccSRuslan Ermilov 	cipher = login_getcapstr(lc, "passwd_format", def, NULL);
41aa864558SBrian Feldman 	if (getenv("CRYPT_DEBUG") != NULL)
42aa864558SBrian Feldman 		fprintf(stderr, "login_setcryptfmt: "
43aa864558SBrian Feldman 		    "passwd_format = %s\n", cipher);
44c2534fa1SBrian Feldman 	if (cipher == NULL)
45c2534fa1SBrian Feldman 		return (error);
46c2534fa1SBrian Feldman 	if (!crypt_set_format(cipher))
47c2534fa1SBrian Feldman 		return (error);
48c2534fa1SBrian Feldman 	return (cipher);
49c2534fa1SBrian Feldman }
50