|
Lines 42-47
Link Here
|
| 42 |
#include "log.h" |
42 |
#include "log.h" |
| 43 |
#include "servconf.h" |
43 |
#include "servconf.h" |
| 44 |
#include "auth.h" |
44 |
#include "auth.h" |
|
|
45 |
#include "buffer.h" |
| 46 |
#include "misc.h" |
| 47 |
#include "channels.h" |
| 48 |
#include "monitor_wrap.h" |
| 49 |
#include "auth-options.h" |
| 45 |
|
50 |
|
| 46 |
#if !defined(USE_PAM) && !defined(HAVE_OSF_SIA) |
51 |
#if !defined(USE_PAM) && !defined(HAVE_OSF_SIA) |
| 47 |
/* Don't need any of these headers for the PAM or SIA cases */ |
52 |
/* Don't need any of these headers for the PAM or SIA cases */ |
|
Lines 81-89
Link Here
|
| 81 |
#endif /* !USE_PAM && !HAVE_OSF_SIA */ |
86 |
#endif /* !USE_PAM && !HAVE_OSF_SIA */ |
| 82 |
|
87 |
|
| 83 |
extern ServerOptions options; |
88 |
extern ServerOptions options; |
| 84 |
#ifdef WITH_AIXAUTHENTICATE |
89 |
extern Buffer login_message; |
| 85 |
extern char *aixloginmsg; |
90 |
extern int password_change_required; |
| 86 |
#endif |
91 |
pid_t password_change_pid; /* pid used to reset forwarding flags */ |
| 87 |
|
92 |
|
| 88 |
/* |
93 |
/* |
| 89 |
* Tries to authenticate the user using password. Returns true if |
94 |
* Tries to authenticate the user using password. Returns true if |
|
Lines 123-128
Link Here
|
| 123 |
/* deny if no user. */ |
128 |
/* deny if no user. */ |
| 124 |
if (pw == NULL) |
129 |
if (pw == NULL) |
| 125 |
return 0; |
130 |
return 0; |
|
|
131 |
buffer_init(&login_message); |
| 126 |
#ifndef HAVE_CYGWIN |
132 |
#ifndef HAVE_CYGWIN |
| 127 |
if (pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES) |
133 |
if (pw->pw_uid == 0 && options.permit_root_login != PERMIT_YES) |
| 128 |
return 0; |
134 |
return 0; |
|
Lines 149-161
Link Here
|
| 149 |
#endif |
155 |
#endif |
| 150 |
#ifdef WITH_AIXAUTHENTICATE |
156 |
#ifdef WITH_AIXAUTHENTICATE |
| 151 |
authsuccess = (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0); |
157 |
authsuccess = (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0); |
|
|
158 |
aix_remove_embedded_newlines(authmsg); |
| 152 |
|
159 |
|
| 153 |
if (authsuccess) |
160 |
if (authsuccess) { |
|
|
161 |
char *msg; |
| 162 |
|
| 163 |
debug("authenticate() succeeded for user %s: %.100s", |
| 164 |
pw->pw_name, authmsg); |
| 154 |
/* We don't have a pty yet, so just label the line as "ssh" */ |
165 |
/* We don't have a pty yet, so just label the line as "ssh" */ |
| 155 |
if (loginsuccess(authctxt->user, |
166 |
if (loginsuccess(authctxt->user, |
| 156 |
get_canonical_hostname(options.verify_reverse_mapping), |
167 |
get_canonical_hostname(options.verify_reverse_mapping), |
| 157 |
"ssh", &aixloginmsg) < 0) |
168 |
"ssh", &msg) < 0) |
| 158 |
aixloginmsg = NULL; |
169 |
msg = NULL; |
|
|
170 |
buffer_append(&login_message, msg, strlen(msg)); |
| 171 |
} else { |
| 172 |
debug("AIX authenticate() failed for user %s: %.100s", |
| 173 |
pw->pw_name, authmsg); |
| 174 |
} |
| 175 |
if (authmsg) |
| 176 |
xfree(authmsg); |
| 159 |
|
177 |
|
| 160 |
return(authsuccess); |
178 |
return(authsuccess); |
| 161 |
#endif |
179 |
#endif |
|
Lines 232-235
Link Here
|
| 232 |
/* Authentication is accepted if the encrypted passwords are identical. */ |
250 |
/* Authentication is accepted if the encrypted passwords are identical. */ |
| 233 |
return (strcmp(encrypted_password, pw_password) == 0); |
251 |
return (strcmp(encrypted_password, pw_password) == 0); |
| 234 |
#endif /* !USE_PAM && !HAVE_OSF_SIA */ |
252 |
#endif /* !USE_PAM && !HAVE_OSF_SIA */ |
|
|
253 |
} |
| 254 |
|
| 255 |
/* |
| 256 |
* Perform generic password change via tty. Like do_pam_chauthtok(), |
| 257 |
* it throws a fatal error if the password can't be changed. |
| 258 |
*/ |
| 259 |
int |
| 260 |
do_tty_change_password(struct passwd *pw) |
| 261 |
{ |
| 262 |
pid_t pid; |
| 263 |
int status; |
| 264 |
mysig_t old_signal; |
| 265 |
|
| 266 |
old_signal = mysignal(SIGCHLD, SIG_DFL); |
| 267 |
|
| 268 |
if ((pid = fork()) == -1) |
| 269 |
fatal("Couldn't fork: %s", strerror(errno)); |
| 270 |
|
| 271 |
if (pid == 0) { |
| 272 |
setuid(pw->pw_uid); |
| 273 |
if (geteuid() == 0) |
| 274 |
execl(PASSWD_PROGRAM_PATH, "passwd", pw->pw_name, |
| 275 |
(char *)NULL); |
| 276 |
else |
| 277 |
execl(PASSWD_PROGRAM_PATH, "passwd", (char *)NULL); |
| 278 |
|
| 279 |
/* execl shouldn't return */ |
| 280 |
fatal("Couldn't exec %s", PASSWD_PROGRAM_PATH); |
| 281 |
exit(1); |
| 282 |
} |
| 283 |
|
| 284 |
if (waitpid(pid, &status, 0) == -1) |
| 285 |
fatal("Couldn't wait for child: %s", strerror(errno)); |
| 286 |
mysignal(SIGCHLD, old_signal); |
| 287 |
|
| 288 |
/* |
| 289 |
* passwd sometimes returns 0 when the password has not been changed |
| 290 |
* so we re-test via getpwnamallow |
| 291 |
*/ |
| 292 |
if (WIFEXITED(status) && (WEXITSTATUS(status) == 0) && |
| 293 |
PRIVSEP(getpwnamallow(pw->pw_name)) != NULL) { |
| 294 |
debug("password changed sucessfully"); |
| 295 |
flag_password_change_successful(); |
| 296 |
return 1; |
| 297 |
} else { |
| 298 |
fatal("Failed to change password for %s, passwd returned %d", |
| 299 |
pw->pw_name, status); |
| 300 |
return 0; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
/* |
| 305 |
* Because an expired password is changed after forking to exec the user's |
| 306 |
* shell, restoring the port forwarding flags is done by sending a |
| 307 |
* USR1 signal to the parent after the password is changed successfully. |
| 308 |
*/ |
| 309 |
void |
| 310 |
flag_password_change_required(void) |
| 311 |
{ |
| 312 |
debug("%s disabling forwarding flags", __func__); |
| 313 |
/* flag that password change is necessary */ |
| 314 |
password_change_required = 1; |
| 315 |
|
| 316 |
/* disallow other functionality for now */ |
| 317 |
no_port_forwarding_flag |= 2; |
| 318 |
no_agent_forwarding_flag |= 2; |
| 319 |
no_x11_forwarding_flag |= 2; |
| 320 |
|
| 321 |
/* set handler to reset flags */ |
| 322 |
password_change_pid = getpid(); |
| 323 |
mysignal(SIGUSR1, password_change_successful_handler); |
| 324 |
} |
| 325 |
|
| 326 |
/* |
| 327 |
* password change successful, tell parent to restore port |
| 328 |
* forwarding flags |
| 329 |
*/ |
| 330 |
void |
| 331 |
flag_password_change_successful(void) |
| 332 |
{ |
| 333 |
debug("%s signalling parent to reset forwarding flags", __func__); |
| 334 |
kill(password_change_pid, SIGUSR1); |
| 335 |
|
| 336 |
/* reset flags in local process too */ |
| 337 |
password_change_required = 0; |
| 338 |
no_port_forwarding_flag &= ~2; |
| 339 |
no_agent_forwarding_flag &= ~2; |
| 340 |
no_x11_forwarding_flag &= ~2; |
| 341 |
} |
| 342 |
|
| 343 |
/* |
| 344 |
* signal handler to reset change flags |
| 345 |
*/ |
| 346 |
void |
| 347 |
password_change_successful_handler(int sig) |
| 348 |
{ |
| 349 |
debug("%s restoring port forwarding flags", __func__); |
| 350 |
mysignal(SIGUSR1, SIG_DFL); /* unset handler */ |
| 351 |
|
| 352 |
password_change_required = 0; |
| 353 |
no_port_forwarding_flag &= ~2; |
| 354 |
no_agent_forwarding_flag &= ~2; |
| 355 |
no_x11_forwarding_flag &= ~2; |
| 356 |
if (!no_port_forwarding_flag && options.allow_tcp_forwarding) |
| 357 |
channel_permit_all_opens(); |
| 235 |
} |
358 |
} |