164990Sgreen/*-
264990Sgreen * Copyright (c) 2000 Brian Fundakowski Feldman
364990Sgreen * All rights reserved.
464990Sgreen *
564990Sgreen * Redistribution and use in source and binary forms, with or without
664990Sgreen * modification, are permitted provided that the following conditions
764990Sgreen * are met:
864990Sgreen * 1. Redistributions of source code must retain the above copyright
964990Sgreen *    notice, this list of conditions and the following disclaimer.
1064990Sgreen * 2. Redistributions in binary form must reproduce the above copyright
1164990Sgreen *    notice, this list of conditions and the following disclaimer in the
1264990Sgreen *    documentation and/or other materials provided with the distribution.
1364990Sgreen *
1464990Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1564990Sgreen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1664990Sgreen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1764990Sgreen * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1864990Sgreen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1964990Sgreen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2064990Sgreen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2164990Sgreen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2264990Sgreen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2364990Sgreen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2464990Sgreen * SUCH DAMAGE.
2564990Sgreen */
2664990Sgreen
2784225Sdillon#include <sys/cdefs.h>
2884225Sdillon__FBSDID("$FreeBSD$");
2984225Sdillon
3064990Sgreen#include <sys/types.h>
3164990Sgreen
3264990Sgreen#include <login_cap.h>
3367671Sgreen#include <stdio.h>
3467671Sgreen#include <stdlib.h>
3564990Sgreen#include <unistd.h>
3664990Sgreen
3764990Sgreenconst char *
3864990Sgreenlogin_setcryptfmt(login_cap_t *lc, const char *def, const char *error) {
3964990Sgreen	const char *cipher;
4064990Sgreen
4194202Sru	cipher = login_getcapstr(lc, "passwd_format", def, NULL);
4267671Sgreen	if (getenv("CRYPT_DEBUG") != NULL)
4367671Sgreen		fprintf(stderr, "login_setcryptfmt: "
4467671Sgreen		    "passwd_format = %s\n", cipher);
4564990Sgreen	if (cipher == NULL)
4664990Sgreen		return (error);
4764990Sgreen	if (!crypt_set_format(cipher))
4864990Sgreen		return (error);
4964990Sgreen	return (cipher);
5064990Sgreen}
51