|
Lines 52-63
Link Here
|
| 52 |
#include "bufaux.h" |
52 |
#include "bufaux.h" |
| 53 |
#include "packet.h" |
53 |
#include "packet.h" |
| 54 |
|
54 |
|
|
|
55 |
#define PWCHG_FORCED "You must change your password now.\n" |
| 56 |
#define PWCHG_EXPIRED "Your password has expired, you must change it now.\n" |
| 57 |
|
| 55 |
/* import */ |
58 |
/* import */ |
| 56 |
extern ServerOptions options; |
59 |
extern ServerOptions options; |
| 57 |
|
60 |
|
| 58 |
/* Debugging messages */ |
61 |
/* Debugging messages */ |
| 59 |
Buffer auth_debug; |
62 |
Buffer auth_debug; |
| 60 |
int auth_debug_init; |
63 |
int auth_debug_init; |
|
|
64 |
extern int password_change_required; |
| 65 |
extern Buffer expire_message; |
| 61 |
|
66 |
|
| 62 |
/* |
67 |
/* |
| 63 |
* Check if the user is allowed to log in via ssh. If user is listed |
68 |
* Check if the user is allowed to log in via ssh. If user is listed |
|
Lines 75-87
Link Here
|
| 75 |
const char *hostname = NULL, *ipaddr = NULL, *passwd; |
80 |
const char *hostname = NULL, *ipaddr = NULL, *passwd; |
| 76 |
char *shell; |
81 |
char *shell; |
| 77 |
int i; |
82 |
int i; |
| 78 |
#ifdef WITH_AIXAUTHENTICATE |
|
|
| 79 |
char *loginmsg; |
| 80 |
#endif /* WITH_AIXAUTHENTICATE */ |
| 81 |
#if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
83 |
#if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
| 82 |
struct spwd *spw; |
84 |
struct spwd *spw; |
| 83 |
#if !defined(USE_PAM) && defined(HAS_SHADOW_EXPIRE) |
85 |
#if !defined(USE_PAM) && defined(HAS_SHADOW_EXPIRE) |
| 84 |
time_t today; |
86 |
time_t today, expiredate; |
| 85 |
#endif |
87 |
#endif |
| 86 |
#endif |
88 |
#endif |
| 87 |
|
89 |
|
|
Lines 106-118
Link Here
|
| 106 |
return 0; |
108 |
return 0; |
| 107 |
} |
109 |
} |
| 108 |
|
110 |
|
|
|
111 |
#define DAY (24L * 60 * 60) /* 1 day in seconds */ |
| 109 |
#if !defined(USE_PAM) && defined(HAVE_SHADOW_H) && \ |
112 |
#if !defined(USE_PAM) && defined(HAVE_SHADOW_H) && \ |
| 110 |
!defined(DISABLE_SHADOW) && defined(HAS_SHADOW_EXPIRE) |
113 |
!defined(DISABLE_SHADOW) && defined(HAS_SHADOW_EXPIRE) |
| 111 |
#define DAY (24L * 60 * 60) /* 1 day in seconds */ |
|
|
| 112 |
today = time(NULL) / DAY; |
114 |
today = time(NULL) / DAY; |
| 113 |
debug3("allowed_user: today %d sp_expire %d sp_lstchg %d" |
115 |
debug3("allowed_user: today %d sp_expire %d sp_lstchg %d" |
| 114 |
" sp_max %d", (int)today, (int)spw->sp_expire, |
116 |
" sp_max %d sp_warn %d", (int)today, (int)spw->sp_expire, |
| 115 |
(int)spw->sp_lstchg, (int)spw->sp_max); |
117 |
(int)spw->sp_lstchg, (int)spw->sp_max, (int)spw->sp_warn); |
| 116 |
|
118 |
|
| 117 |
/* |
119 |
/* |
| 118 |
* We assume account and password expiration occurs the |
120 |
* We assume account and password expiration occurs the |
|
Lines 121-142
Link Here
|
| 121 |
if (spw->sp_expire != -1 && today > spw->sp_expire) { |
123 |
if (spw->sp_expire != -1 && today > spw->sp_expire) { |
| 122 |
log("Account %.100s has expired", pw->pw_name); |
124 |
log("Account %.100s has expired", pw->pw_name); |
| 123 |
return 0; |
125 |
return 0; |
|
|
126 |
} else if (spw->sp_expire != -1 && |
| 127 |
spw->sp_expire - today < spw->sp_warn) { |
| 128 |
char msg[100]; |
| 129 |
|
| 130 |
snprintf(msg, 100, |
| 131 |
"Your account will expire in %d days.\n", |
| 132 |
(int)(spw->sp_expire - today)); |
| 133 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 124 |
} |
134 |
} |
| 125 |
|
135 |
|
|
|
136 |
expiredate = spw->sp_lstchg + spw->sp_max; |
| 126 |
if (spw->sp_lstchg == 0) { |
137 |
if (spw->sp_lstchg == 0) { |
| 127 |
log("User %.100s password has expired (root forced)", |
138 |
log("User %.100s password has expired (root forced)", |
| 128 |
pw->pw_name); |
139 |
pw->pw_name); |
| 129 |
return 0; |
140 |
flag_password_change_required(); |
| 130 |
} |
141 |
buffer_append(&expire_message, PWCHG_FORCED, |
| 131 |
|
142 |
strlen(PWCHG_FORCED)); |
| 132 |
if (spw->sp_max != -1 && |
143 |
} else if (spw->sp_max == -1) { |
| 133 |
today > spw->sp_lstchg + spw->sp_max) { |
144 |
debug3("%s password aging disabled", __func__); |
|
|
145 |
} else if (today > expiredate) { |
| 134 |
log("User %.100s password has expired (password aged)", |
146 |
log("User %.100s password has expired (password aged)", |
| 135 |
pw->pw_name); |
147 |
pw->pw_name); |
| 136 |
return 0; |
148 |
flag_password_change_required(); |
|
|
149 |
buffer_append(&expire_message, PWCHG_EXPIRED, |
| 150 |
strlen(PWCHG_EXPIRED)); |
| 151 |
} else if (expiredate - today < spw->sp_warn) { |
| 152 |
char msg[100]; |
| 153 |
|
| 154 |
snprintf(msg, 100, |
| 155 |
"Your password will expire in %d day%s.\n", |
| 156 |
(int)(expiredate - today), |
| 157 |
expiredate - today > 1 ? "s" : ""); |
| 158 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 137 |
} |
159 |
} |
| 138 |
#endif |
160 |
#endif |
| 139 |
|
161 |
|
|
|
162 |
#if !defined(USE_PAM) && defined(HAVE_STRUCT_PASSWD_PW_AGE) |
| 163 |
/* do /etc/passwd style password expiry */ |
| 164 |
if (pw->pw_age && pw->pw_age[0] != '\0') { |
| 165 |
long int max = -1 , min = -1, last = -1; |
| 166 |
int warnweeks = 2; |
| 167 |
char s[2] = "\0\0"; |
| 168 |
time_t thisweek, expireweek; |
| 169 |
|
| 170 |
/* |
| 171 |
* Decode expiry string. The components are base64 |
| 172 |
* encoded digits, and is of the * form "MmLL" where: |
| 173 |
* M = maximum password age in (weeks) |
| 174 |
* m = minimum password age in (weeks) |
| 175 |
* LL = last password change (weeks since 1 Jan 1970) |
| 176 |
*/ |
| 177 |
|
| 178 |
/* grab max age from 1st digit */ |
| 179 |
s[0] = pw->pw_age[0]; |
| 180 |
max = a64l(s); |
| 181 |
if (pw->pw_age[1] != '\0') { |
| 182 |
/* grab min age from 2nd digit */ |
| 183 |
s[0] = pw->pw_age[1]; |
| 184 |
min = a64l(s); |
| 185 |
if (pw->pw_age[2] != '\0') { |
| 186 |
/* grab last change time from remainder */ |
| 187 |
last = a64l((pw->pw_age)+2); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
thisweek = time(NULL) / DAY / 7; |
| 192 |
expireweek = last + max; |
| 193 |
debug3("%s: thisweek %d pw_age max %ld min %ld last %ld\n", |
| 194 |
__func__, (int)thisweek, max, min, last); |
| 195 |
|
| 196 |
if (max == -1) { |
| 197 |
debug3("%s: password aging disabled", __func__); |
| 198 |
} else if (min > max) { |
| 199 |
debug3("%s: min > max, password can't be changed", |
| 200 |
__func__); |
| 201 |
} else if (min == 0 && max == 0) { |
| 202 |
log("User %.100s password has expired (root forced)", |
| 203 |
pw->pw_name); |
| 204 |
flag_password_change_required(); |
| 205 |
buffer_append(&expire_message, PWCHG_FORCED, |
| 206 |
strlen(PWCHG_FORCED)); |
| 207 |
} else if (last + max < thisweek) { |
| 208 |
log("User %.100s password has expired (password aged)", |
| 209 |
pw->pw_name); |
| 210 |
flag_password_change_required(); |
| 211 |
buffer_append(&expire_message, PWCHG_EXPIRED, |
| 212 |
strlen(PWCHG_EXPIRED)); |
| 213 |
} else if (last + max - warnweeks <= thisweek ) { |
| 214 |
char msg[100]; |
| 215 |
|
| 216 |
snprintf(msg, 100, |
| 217 |
"Your password will expire in %d week%s.\n", |
| 218 |
(int)(expireweek - thisweek), |
| 219 |
expireweek - thisweek > 1 ? "s" : ""); |
| 220 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
#endif |
| 140 |
/* |
225 |
/* |
| 141 |
* Get the shell from the password data. An empty shell field is |
226 |
* Get the shell from the password data. An empty shell field is |
| 142 |
* legal, and means /bin/sh. |
227 |
* legal, and means /bin/sh. |
|
Lines 222-248
Link Here
|
| 222 |
* PermitRootLogin to control logins via ssh), or if running as |
307 |
* PermitRootLogin to control logins via ssh), or if running as |
| 223 |
* non-root user (since loginrestrictions will always fail). |
308 |
* non-root user (since loginrestrictions will always fail). |
| 224 |
*/ |
309 |
*/ |
| 225 |
if ( (pw->pw_uid != 0) && (geteuid() == 0) && |
310 |
if ( (pw->pw_uid != 0) && (geteuid() == 0) ) { |
| 226 |
loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &loginmsg) != 0) { |
|
|
| 227 |
int loginrestrict_errno = errno; |
311 |
int loginrestrict_errno = errno; |
|
|
312 |
char *msg; |
| 228 |
|
313 |
|
| 229 |
if (loginmsg && *loginmsg) { |
314 |
/* check for AIX account restrictions */ |
| 230 |
/* Remove embedded newlines (if any) */ |
315 |
if (loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &msg) != 0) { |
| 231 |
char *p; |
316 |
if (msg && *msg) { |
| 232 |
for (p = loginmsg; *p; p++) { |
317 |
aix_remove_embedded_newlines(msg); |
| 233 |
if (*p == '\n') |
318 |
log("Login restricted for %s: %.100s", |
| 234 |
*p = ' '; |
319 |
pw->pw_name, msg); |
|
|
320 |
xfree(msg); |
| 235 |
} |
321 |
} |
| 236 |
/* Remove trailing newline */ |
322 |
|
| 237 |
*--p = '\0'; |
323 |
/* Don't fail if /etc/nologin set */ |
| 238 |
log("Login restricted for %s: %.100s", pw->pw_name, |
324 |
if (!(loginrestrict_errno == EPERM && |
| 239 |
loginmsg); |
325 |
stat(_PATH_NOLOGIN, &st) == 0)) |
| 240 |
} |
326 |
return 0; |
| 241 |
/* Don't fail if /etc/nologin set */ |
327 |
} |
| 242 |
if (!(loginrestrict_errno == EPERM && |
|
|
| 243 |
stat(_PATH_NOLOGIN, &st) == 0)) |
| 244 |
return 0; |
| 245 |
} |
328 |
} |
|
|
329 |
|
| 330 |
/* |
| 331 |
* Check AIX password expiry. Only check when running as root. |
| 332 |
* Unpriv'ed users can't access /etc/security/passwd or |
| 333 |
* /etc/security/user so passwdexpired will always fail. |
| 334 |
*/ |
| 335 |
if (geteuid() == 0) { |
| 336 |
char *msg; |
| 337 |
int passexpcode; |
| 338 |
|
| 339 |
enduserdb(); /* flush cached results for passwdexpired */ |
| 340 |
passexpcode = passwdexpired(pw->pw_name, &msg); |
| 341 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 342 |
if (msg && *msg) |
| 343 |
aix_remove_embedded_newlines(msg); |
| 344 |
debug("AIX passwdexpired returned %d errno %d msg %.100s", |
| 345 |
errno, passexpcode, msg); |
| 346 |
|
| 347 |
switch (passexpcode) { |
| 348 |
case 0: /* success, password not expired */ |
| 349 |
break; |
| 350 |
case 1: /* expired, password change required */ |
| 351 |
flag_password_change_required(); |
| 352 |
break; |
| 353 |
default: /* only admin can change (2) or other error (-1) */ |
| 354 |
log("Password can't be changed for user %s: %.100s", |
| 355 |
pw->pw_name, msg); |
| 356 |
if (msg) |
| 357 |
xfree(msg); |
| 358 |
return 0; |
| 359 |
} |
| 360 |
if (msg) |
| 361 |
xfree(msg); |
| 362 |
|
| 363 |
} |
| 246 |
#endif /* WITH_AIXAUTHENTICATE */ |
364 |
#endif /* WITH_AIXAUTHENTICATE */ |
| 247 |
|
365 |
|
| 248 |
/* We found no reason not to let this user try to log on... */ |
366 |
/* We found no reason not to let this user try to log on... */ |
|
Lines 508-513
Link Here
|
| 508 |
#endif |
626 |
#endif |
| 509 |
struct passwd *pw; |
627 |
struct passwd *pw; |
| 510 |
|
628 |
|
|
|
629 |
buffer_init(&expire_message); |
| 511 |
pw = getpwnam(user); |
630 |
pw = getpwnam(user); |
| 512 |
if (pw == NULL) { |
631 |
if (pw == NULL) { |
| 513 |
log("Illegal user %.100s from %.100s", |
632 |
log("Illegal user %.100s from %.100s", |