summaryrefslogtreecommitdiffstats
path: root/lib/libskey/skey_crypt.c
blob: 4e3a141333a56432aafbbce1af899f748066985d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Author: Wietse Venema, Eindhoven University of Technology. */

#include <string.h>
#include <stdio.h>
#include <pwd.h>
#include <unistd.h>

#include "skey.h"

/* skey_crypt - return encrypted UNIX passwd if s/key or regular password ok */

const char *skey_crypt(pp, salt, pwd, pwok)
char *pp;
char *salt;
struct passwd *pwd;
int     pwok;
{
    struct skey skey;
    char   *p;

    /* Try s/key authentication even when the UNIX password is permitted. */

    if (pwd != 0 && skeyinfo(&skey, pwd->pw_name, (char *) 0) == 0
	&& skeyverify(&skey, pp) == 0) {
	/* s/key authentication succeeded */
	return (pwd->pw_passwd);
    }

    /* When s/key authentication does not work, always invoke crypt(). */

    p = crypt(pp, salt);
    if (pwok && pwd != 0 && strcmp(p, pwd->pw_passwd) == 0)
	return (pwd->pw_passwd);

    /* The user does not exist or entered bad input. */

    return (":");
}
OpenPOWER on IntegriCloud