|
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 111-118
Link Here
|
| 111 |
#define DAY (24L * 60 * 60) /* 1 day in seconds */ |
113 |
#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-139
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 days.\n", |
| 156 |
(int)(expiredate - today)); |
| 157 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 137 |
} |
158 |
} |
| 138 |
#endif |
159 |
#endif |
| 139 |
|
160 |
|
|
Lines 222-248
Link Here
|
| 222 |
* PermitRootLogin to control logins via ssh), or if running as |
243 |
* PermitRootLogin to control logins via ssh), or if running as |
| 223 |
* non-root user (since loginrestrictions will always fail). |
244 |
* non-root user (since loginrestrictions will always fail). |
| 224 |
*/ |
245 |
*/ |
| 225 |
if ( (pw->pw_uid != 0) && (geteuid() == 0) && |
246 |
if ( (pw->pw_uid != 0) && (geteuid() == 0) ) { |
| 226 |
loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &loginmsg) != 0) { |
|
|
| 227 |
int loginrestrict_errno = errno; |
247 |
int loginrestrict_errno = errno; |
|
|
248 |
char *msg; |
| 228 |
|
249 |
|
| 229 |
if (loginmsg && *loginmsg) { |
250 |
/* check for AIX account restrictions */ |
| 230 |
/* Remove embedded newlines (if any) */ |
251 |
if (loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &msg) != 0) { |
| 231 |
char *p; |
252 |
if (msg && *msg) { |
| 232 |
for (p = loginmsg; *p; p++) { |
253 |
aix_remove_embedded_newlines(msg); |
| 233 |
if (*p == '\n') |
254 |
log("Login restricted for %s: %.100s", |
| 234 |
*p = ' '; |
255 |
pw->pw_name, msg); |
|
|
256 |
xfree(msg); |
| 235 |
} |
257 |
} |
| 236 |
/* Remove trailing newline */ |
258 |
|
| 237 |
*--p = '\0'; |
259 |
/* Don't fail if /etc/nologin set */ |
| 238 |
log("Login restricted for %s: %.100s", pw->pw_name, |
260 |
if (!(loginrestrict_errno == EPERM && |
| 239 |
loginmsg); |
261 |
stat(_PATH_NOLOGIN, &st) == 0)) |
| 240 |
} |
262 |
return 0; |
| 241 |
/* Don't fail if /etc/nologin set */ |
263 |
} |
| 242 |
if (!(loginrestrict_errno == EPERM && |
|
|
| 243 |
stat(_PATH_NOLOGIN, &st) == 0)) |
| 244 |
return 0; |
| 245 |
} |
264 |
} |
|
|
265 |
|
| 266 |
/* |
| 267 |
* Check AIX password expiry. Only check when running as root. |
| 268 |
* Unpriv'ed users can't access /etc/security/passwd or |
| 269 |
* /etc/security/user so passwdexpired will always fail. |
| 270 |
*/ |
| 271 |
if (geteuid() == 0) { |
| 272 |
char *msg; |
| 273 |
int passexpcode; |
| 274 |
|
| 275 |
enduserdb(); /* flush cached results for passwdexpired */ |
| 276 |
passexpcode = passwdexpired(pw->pw_name, &msg); |
| 277 |
buffer_append(&expire_message, msg, strlen(msg)); |
| 278 |
if (msg && *msg) |
| 279 |
aix_remove_embedded_newlines(msg); |
| 280 |
debug("AIX passwdexpired returned %d errno %d msg %.100s", |
| 281 |
errno, passexpcode, msg); |
| 282 |
|
| 283 |
switch (passexpcode) { |
| 284 |
case 0: /* success, password not expired */ |
| 285 |
break; |
| 286 |
case 1: /* expired, password change required */ |
| 287 |
flag_password_change_required(); |
| 288 |
break; |
| 289 |
default: /* only admin can change (2) or other error (-1) */ |
| 290 |
log("Password can't be changed for user %s: %.100s", |
| 291 |
pw->pw_name, msg); |
| 292 |
if (msg) |
| 293 |
xfree(msg); |
| 294 |
return 0; |
| 295 |
} |
| 296 |
if (msg) |
| 297 |
xfree(msg); |
| 298 |
|
| 299 |
} |
| 246 |
#endif /* WITH_AIXAUTHENTICATE */ |
300 |
#endif /* WITH_AIXAUTHENTICATE */ |
| 247 |
|
301 |
|
| 248 |
/* We found no reason not to let this user try to log on... */ |
302 |
/* We found no reason not to let this user try to log on... */ |
|
Lines 508-513
Link Here
|
| 508 |
#endif |
562 |
#endif |
| 509 |
struct passwd *pw; |
563 |
struct passwd *pw; |
| 510 |
|
564 |
|
|
|
565 |
buffer_init(&expire_message); |
| 511 |
pw = getpwnam(user); |
566 |
pw = getpwnam(user); |
| 512 |
if (pw == NULL) { |
567 |
if (pw == NULL) { |
| 513 |
log("Illegal user %.100s from %.100s", |
568 |
log("Illegal user %.100s from %.100s", |