summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'session.c')
-rw-r--r--session.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/session.c b/session.c
index 3678b8f09..d5faf4cf3 100644
--- a/session.c
+++ b/session.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10#include "includes.h" 10#include "includes.h"
11RCSID("$OpenBSD: session.c,v 1.31 2000/08/28 03:50:54 deraadt Exp $"); 11RCSID("$OpenBSD: session.c,v 1.35 2000/09/04 19:07:21 markus Exp $");
12 12
13#include "xmalloc.h" 13#include "xmalloc.h"
14#include "ssh.h" 14#include "ssh.h"
@@ -113,6 +113,9 @@ extern int startup_pipe;
113/* Local Xauthority file. */ 113/* Local Xauthority file. */
114static char *xauthfile; 114static char *xauthfile;
115 115
116/* original command from peer. */
117char *original_command = NULL;
118
116/* data */ 119/* data */
117#define MAX_SESSIONS 10 120#define MAX_SESSIONS 10
118Session sessions[MAX_SESSIONS]; 121Session sessions[MAX_SESSIONS];
@@ -177,7 +180,7 @@ void
177do_authenticated(struct passwd * pw) 180do_authenticated(struct passwd * pw)
178{ 181{
179 Session *s; 182 Session *s;
180 int type; 183 int type, fd;
181 int compression_level = 0, enable_compression_after_reply = 0; 184 int compression_level = 0, enable_compression_after_reply = 0;
182 int have_pty = 0; 185 int have_pty = 0;
183 char *command; 186 char *command;
@@ -332,7 +335,9 @@ do_authenticated(struct passwd * pw)
332 break; 335 break;
333 } 336 }
334 strlcat(xauthfile, "/cookies", MAXPATHLEN); 337 strlcat(xauthfile, "/cookies", MAXPATHLEN);
335 open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600); 338 fd = open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);
339 if (fd >= 0)
340 close(fd);
336 restore_uid(); 341 restore_uid();
337 fatal_add_cleanup(xauthfile_cleanup_proc, NULL); 342 fatal_add_cleanup(xauthfile_cleanup_proc, NULL);
338 success = 1; 343 success = 1;
@@ -377,6 +382,7 @@ do_authenticated(struct passwd * pw)
377 packet_integrity_check(plen, 0, type); 382 packet_integrity_check(plen, 0, type);
378 } 383 }
379 if (forced_command != NULL) { 384 if (forced_command != NULL) {
385 original_command = command;
380 command = forced_command; 386 command = forced_command;
381 debug("Forced command '%.500s'", forced_command); 387 debug("Forced command '%.500s'", forced_command);
382 } 388 }
@@ -638,6 +644,7 @@ do_login(Session *s)
638 FILE *f; 644 FILE *f;
639 char *time_string; 645 char *time_string;
640 char buf[256]; 646 char buf[256];
647 char hostname[MAXHOSTNAMELEN];
641 socklen_t fromlen; 648 socklen_t fromlen;
642 struct sockaddr_storage from; 649 struct sockaddr_storage from;
643 struct stat st; 650 struct stat st;
@@ -659,6 +666,10 @@ do_login(Session *s)
659 } 666 }
660 } 667 }
661 668
669 /* Get the time and hostname when the user last logged in. */
670 last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name,
671 hostname, sizeof(hostname));
672
662 /* Record that there was a login on that tty from the remote host. */ 673 /* Record that there was a login on that tty from the remote host. */
663 record_login(pid, s->tty, pw->pw_name, pw->pw_uid, 674 record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
664 get_remote_name_or_ip(), (struct sockaddr *)&from); 675 get_remote_name_or_ip(), (struct sockaddr *)&from);
@@ -680,12 +691,6 @@ do_login(Session *s)
680 printf("%s\n", aixloginmsg); 691 printf("%s\n", aixloginmsg);
681#endif /* WITH_AIXAUTHENTICATE */ 692#endif /* WITH_AIXAUTHENTICATE */
682 693
683 /*
684 * Get the time when the user last logged in. 'buf' will be set
685 * to contain the hostname the last login was from.
686 */
687 last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name,
688 buf, sizeof(buf));
689 if (last_login_time != 0) { 694 if (last_login_time != 0) {
690 time_string = ctime(&last_login_time); 695 time_string = ctime(&last_login_time);
691 if (strchr(time_string, '\n')) 696 if (strchr(time_string, '\n'))
@@ -911,7 +916,7 @@ do_child(const char *command, struct passwd * pw, const char *term,
911 const char *display, const char *auth_proto, 916 const char *display, const char *auth_proto,
912 const char *auth_data, const char *ttyname) 917 const char *auth_data, const char *ttyname)
913{ 918{
914 const char *shell, *hostname, *cp = NULL; 919 const char *shell, *hostname = NULL, *cp = NULL;
915 char buf[256]; 920 char buf[256];
916 char cmd[1024]; 921 char cmd[1024];
917 FILE *f = NULL; 922 FILE *f = NULL;
@@ -1089,6 +1094,9 @@ do_child(const char *command, struct passwd * pw, const char *term,
1089 child_set_env(&env, &envsize, "TERM", term); 1094 child_set_env(&env, &envsize, "TERM", term);
1090 if (display) 1095 if (display)
1091 child_set_env(&env, &envsize, "DISPLAY", display); 1096 child_set_env(&env, &envsize, "DISPLAY", display);
1097 if (original_command)
1098 child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND",
1099 original_command);
1092 1100
1093#ifdef _AIX 1101#ifdef _AIX
1094 { 1102 {
@@ -1511,6 +1519,7 @@ session_subsystem_req(Session *s)
1511int 1519int
1512session_x11_req(Session *s) 1520session_x11_req(Session *s)
1513{ 1521{
1522 int fd;
1514 if (no_x11_forwarding_flag) { 1523 if (no_x11_forwarding_flag) {
1515 debug("X11 forwarding disabled in user configuration file."); 1524 debug("X11 forwarding disabled in user configuration file.");
1516 return 0; 1525 return 0;
@@ -1555,7 +1564,9 @@ session_x11_req(Session *s)
1555 return 0; 1564 return 0;
1556 } 1565 }
1557 strlcat(xauthfile, "/cookies", MAXPATHLEN); 1566 strlcat(xauthfile, "/cookies", MAXPATHLEN);
1558 open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600); 1567 fd = open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);
1568 if (fd >= 0)
1569 close(fd);
1559 restore_uid(); 1570 restore_uid();
1560 fatal_add_cleanup(xauthfile_cleanup_proc, s); 1571 fatal_add_cleanup(xauthfile_cleanup_proc, s);
1561 return 1; 1572 return 1;
@@ -1582,7 +1593,7 @@ session_exec_req(Session *s)
1582 char *command = packet_get_string(&len); 1593 char *command = packet_get_string(&len);
1583 packet_done(); 1594 packet_done();
1584 if (forced_command) { 1595 if (forced_command) {
1585 xfree(command); 1596 original_command = command;
1586 command = forced_command; 1597 command = forced_command;
1587 debug("Forced command '%.500s'", forced_command); 1598 debug("Forced command '%.500s'", forced_command);
1588 } 1599 }