]>
Commit | Line | Data |
---|---|---|
4c653d8e | 1 | /* |
2 | * Copyright (c) 2005 The SCO Group. All rights reserved. | |
3 | * Copyright (c) 2005 Tim Rice. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * | |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #include "includes.h" | |
27 | ||
d2a3abef | 28 | #ifdef HAVE_LIBIAF |
4c653d8e | 29 | #ifdef HAVE_CRYPT_H |
30 | #include <crypt.h> | |
31 | #endif | |
32 | #include "packet.h" | |
33 | #include "buffer.h" | |
34 | #include "log.h" | |
35 | #include "servconf.h" | |
36 | #include "auth.h" | |
37 | #include "auth-options.h" | |
38 | ||
39 | int nischeck(char *); | |
40 | ||
41 | int | |
42 | sys_auth_passwd(Authctxt *authctxt, const char *password) | |
43 | { | |
44 | struct passwd *pw = authctxt->pw; | |
4c653d8e | 45 | char *salt; |
26d07095 | 46 | int result; |
4c653d8e | 47 | |
48 | /* Just use the supplied fake password if authctxt is invalid */ | |
49 | char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd; | |
50 | ||
51 | /* Check for users with no password. */ | |
52 | if (strcmp(pw_password, "") == 0 && strcmp(password, "") == 0) | |
53 | return (1); | |
54 | ||
26d07095 | 55 | /* Encrypt the candidate password using the proper salt. */ |
4c653d8e | 56 | salt = (pw_password[0] && pw_password[1]) ? pw_password : "xx"; |
26d07095 | 57 | |
58 | /* | |
59 | * Authentication is accepted if the encrypted passwords | |
60 | * are identical. | |
61 | */ | |
d2a3abef | 62 | #ifdef UNIXWARE_LONG_PASSWORDS |
63 | if (!nischeck(pw->pw_name)) { | |
64 | result = ((strcmp(bigcrypt(password, salt), pw_password) == 0) | |
65 | || (strcmp(osr5bigcrypt(password, salt), pw_password) == 0)); | |
66 | } | |
67 | else | |
68 | #endif /* UNIXWARE_LONG_PASSWORDS */ | |
69 | result = (strcmp(xcrypt(password, salt), pw_password) == 0); | |
26d07095 | 70 | |
d2a3abef | 71 | #if !defined(BROKEN_LIBIAF) |
26d07095 | 72 | if (authctxt->valid) |
73 | free(pw_password); | |
d2a3abef | 74 | #endif |
26d07095 | 75 | return(result); |
4c653d8e | 76 | } |
77 | ||
26d07095 | 78 | #ifdef UNIXWARE_LONG_PASSWORDS |
4c653d8e | 79 | int |
80 | nischeck(char *namep) | |
81 | { | |
82 | char password_file[] = "/etc/passwd"; | |
83 | FILE *fd; | |
84 | struct passwd *ent = NULL; | |
85 | ||
86 | if ((fd = fopen (password_file, "r")) == NULL) { | |
87 | /* | |
88 | * If the passwd file has dissapeared we are in a bad state. | |
89 | * However, returning 0 will send us back through the | |
90 | * authentication scheme that has checked the ia database for | |
91 | * passwords earlier. | |
92 | */ | |
93 | return(0); | |
94 | } | |
95 | ||
96 | /* | |
97 | * fgetpwent() only reads from password file, so we know for certain | |
98 | * that the user is local. | |
99 | */ | |
100 | while (ent = fgetpwent(fd)) { | |
101 | if (strcmp (ent->pw_name, namep) == 0) { | |
102 | /* Local user */ | |
103 | fclose (fd); | |
104 | return(0); | |
105 | } | |
106 | } | |
107 | ||
108 | fclose (fd); | |
109 | return (1); | |
110 | } | |
111 | ||
112 | #endif /* UNIXWARE_LONG_PASSWORDS */ | |
113 | ||
26d07095 | 114 | /* |
115 | NOTE: ia_get_logpwd() allocates memory for arg 2 | |
116 | functions that call shadow_pw() will need to free | |
117 | */ | |
118 | ||
d2a3abef | 119 | #if !defined(BROKEN_LIBIAF) |
4c653d8e | 120 | char * |
121 | get_iaf_password(struct passwd *pw) | |
122 | { | |
123 | char *pw_password = NULL; | |
124 | ||
125 | uinfo_t uinfo; | |
126 | if (!ia_openinfo(pw->pw_name,&uinfo)) { | |
127 | ia_get_logpwd(uinfo, &pw_password); | |
128 | if (pw_password == NULL) | |
26d07095 | 129 | fatal("ia_get_logpwd: Unable to get the shadow passwd"); |
4c653d8e | 130 | ia_closeinfo(uinfo); |
131 | return pw_password; | |
132 | } | |
133 | else | |
26d07095 | 134 | fatal("ia_openinfo: Unable to open the shadow passwd file"); |
4c653d8e | 135 | } |
d2a3abef | 136 | #endif /* !BROKEN_LIBIAF */ |
137 | #endif /* HAVE_LIBIAF */ | |
4c653d8e | 138 |