Merge from vendor branch BINUTILS:
[dragonfly.git] / secure / usr.sbin / sshd / auth-passwd-freebsd.c
1 /*
2  * $DragonFly: src/secure/usr.sbin/sshd/auth-passwd-freebsd.c,v 1.1 2004/07/31 20:05:00 geekgod Exp $
3  */
4
5 #include <unistd.h>
6
7 #include "auth.h"
8
9 int
10 sys_auth_passwd(Authctxt *authctxt, const char *password)
11 {
12         struct passwd *pw = authctxt->pw;
13         char *encrypted_password;
14         char *pw_password = pw->pw_passwd;
15
16         /* Check for users with no password. */
17         if (strcmp(pw_password, "") == 0 && strcmp(password, "") == 0)
18                 return (1);
19
20         /* Encrypt the candidate password using the proper salt. */
21         encrypted_password = crypt(password,
22             (pw_password[0] && pw_password[1]) ? pw_password : "xx");
23
24         /*
25          * Authentication is accepted if the encrypted passwords
26          * are identical.
27          */
28         return (strcmp(encrypted_password, pw_password) == 0);
29 }