ftp://ftp.smr.ru/pub/0/FreeBSD/releases/distfiles/xscreensaver-3.16.tar.gz
[xscreensaver] / driver / vms-validate.c
1 /*
2  *      validate a password for a user
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 /*
14  * Includes
15  */
16 #include <stdio.h>
17 #include <ctype.h>
18 #include <string.h>
19
20 #include "vms-pwd.h"
21 int hash_vms_password(char *output_buf,char *input_buf,int input_length,
22                       char *username,int encryption_type,unsigned short salt);
23
24 /*
25  *
26  *      Validate a VMS UserName/Password pair.
27  *
28  */
29
30 int validate_user(name,password)
31 char *name;
32 char *password;
33 {
34         char password_buf[64];
35         char username_buf[31];
36         char encrypt_buf[8];
37         register int i;
38         register char *cp,*cp1;
39         struct passwd *user_entry;
40
41         /*
42          *      Get the users UAF entry
43          */
44         user_entry = getpwnam(name);
45
46         /*
47          *      If user_entry == NULL then we got a bad error
48          *      return -1 to indicate a bad error
49          */
50         if (user_entry == NULL) return (-1);
51
52         /*
53          *      Uppercase the password
54          */
55         cp = password;
56         cp1 = password_buf;
57         while (*cp)
58            if (islower(*cp))
59                 *cp1++ = toupper(*cp++);
60            else
61                 *cp1++ = *cp++;
62         /*
63          *      Get the length of the password
64          */
65         i = strlen(password);
66         /*
67          *      Encrypt the password
68          */
69         hash_vms_password(encrypt_buf,password_buf,i,user_entry->pw_name,
70                           user_entry->pw_encrypt, user_entry->pw_salt);
71         if (memcmp(encrypt_buf,user_entry->pw_passwd,8) == 0)
72                 return(1);
73         else    return(0);
74 }
75