View | Details | Raw Unified | Return to bug 463 | Differences between
and this patch

Collapse All | Expand All

(-)auth-passwd.c (-13 / +2 lines)
Lines 81-89 Link Here
81
#endif /* !USE_PAM && !HAVE_OSF_SIA */
81
#endif /* !USE_PAM && !HAVE_OSF_SIA */
82
82
83
extern ServerOptions options;
83
extern ServerOptions options;
84
#ifdef WITH_AIXAUTHENTICATE
85
extern char *aixloginmsg;
86
#endif
87
84
88
/*
85
/*
89
 * Tries to authenticate the user using password.  Returns true if
86
 * Tries to authenticate the user using password.  Returns true if
Lines 147-162 Link Here
147
	}
144
	}
148
# endif
145
# endif
149
# ifdef WITH_AIXAUTHENTICATE
146
# ifdef WITH_AIXAUTHENTICATE
150
	authsuccess = (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
147
	/* XXX: should loop until reenter == 0 */
151
148
	return(authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
152
	if (authsuccess)
153
	        /* We don't have a pty yet, so just label the line as "ssh" */
154
	        if (loginsuccess(authctxt->user,
155
			get_canonical_hostname(options.verify_reverse_mapping),
156
			"ssh", &aixloginmsg) < 0)
157
				aixloginmsg = NULL;
158
159
	return(authsuccess);
160
# endif
149
# endif
161
# ifdef KRB4
150
# ifdef KRB4
162
	if (options.kerberos_authentication == 1) {
151
	if (options.kerberos_authentication == 1) {
(-)loginrec.c (+11 lines)
Lines 162-167 Link Here
162
#include "loginrec.h"
162
#include "loginrec.h"
163
#include "log.h"
163
#include "log.h"
164
#include "atomicio.h"
164
#include "atomicio.h"
165
#include "buffer.h"
165
166
166
RCSID("$Id: loginrec.c,v 1.46 2003/01/07 05:46:58 djm Exp $");
167
RCSID("$Id: loginrec.c,v 1.46 2003/01/07 05:46:58 djm Exp $");
167
168
Lines 202-207 Link Here
202
/* pick the shortest string */
203
/* pick the shortest string */
203
#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) )
204
#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) )
204
205
206
extern Buffer login_message;
207
205
/**
208
/**
206
 ** platform-independent login functions
209
 ** platform-independent login functions
207
 **/
210
 **/
Lines 439-444 Link Here
439
#endif
442
#endif
440
#ifdef USE_WTMPX
443
#ifdef USE_WTMPX
441
	wtmpx_write_entry(li);
444
	wtmpx_write_entry(li);
445
#endif
446
#ifdef WITH_AIXAUTHENTICATE
447
	if (li->type == LTYPE_LOGIN) {
448
		char *msg;
449
450
		if (loginsuccess(li->username,li->hostname,li->line, &msg) >= 0)
451
			buffer_append(&login_message, msg, strlen(msg));
452
	}
442
#endif
453
#endif
443
	return 0;
454
	return 0;
444
}
455
}
(-)monitor.c (+20 lines)
Lines 110-115 Link Here
110
int mm_answer_pty(int, Buffer *);
110
int mm_answer_pty(int, Buffer *);
111
int mm_answer_pty_cleanup(int, Buffer *);
111
int mm_answer_pty_cleanup(int, Buffer *);
112
int mm_answer_term(int, Buffer *);
112
int mm_answer_term(int, Buffer *);
113
int mm_answer_getloginmsg(int, Buffer *);
113
int mm_answer_rsa_keyallowed(int, Buffer *);
114
int mm_answer_rsa_keyallowed(int, Buffer *);
114
int mm_answer_rsa_challenge(int, Buffer *);
115
int mm_answer_rsa_challenge(int, Buffer *);
115
int mm_answer_rsa_response(int, Buffer *);
116
int mm_answer_rsa_response(int, Buffer *);
Lines 183-188 Link Here
183
    {MONITOR_REQ_PTY, 0, mm_answer_pty},
184
    {MONITOR_REQ_PTY, 0, mm_answer_pty},
184
    {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
185
    {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
185
    {MONITOR_REQ_TERM, 0, mm_answer_term},
186
    {MONITOR_REQ_TERM, 0, mm_answer_term},
187
    {MONITOR_REQ_LOGINMSG, 0, mm_answer_getloginmsg},
186
    {0, 0, NULL}
188
    {0, 0, NULL}
187
};
189
};
188
190
Lines 219-224 Link Here
219
    {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
221
    {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
220
    {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
222
    {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
221
    {MONITOR_REQ_TERM, 0, mm_answer_term},
223
    {MONITOR_REQ_TERM, 0, mm_answer_term},
224
    {MONITOR_REQ_LOGINMSG, 0, mm_answer_getloginmsg},
222
    {0, 0, NULL}
225
    {0, 0, NULL}
223
};
226
};
224
227
Lines 328-333 Link Here
328
	if (!no_pty_flag) {
331
	if (!no_pty_flag) {
329
		monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
332
		monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
330
		monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
333
		monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
334
		monitor_permit(mon_dispatch, MONITOR_REQ_LOGINMSG, 1);
331
	}
335
	}
332
336
333
	for (;;)
337
	for (;;)
Lines 1101-1106 Link Here
1101
		mm_session_close(s);
1105
		mm_session_close(s);
1102
	buffer_put_int(m, 0);
1106
	buffer_put_int(m, 0);
1103
	mm_request_send(socket, MONITOR_ANS_PTY, m);
1107
	mm_request_send(socket, MONITOR_ANS_PTY, m);
1108
	return (0);
1109
}
1110
1111
int
1112
mm_answer_getloginmsg(int socket, Buffer *m)
1113
{
1114
	char *msg;
1115
1116
	debug3("%s entering", __func__);
1117
1118
	/* retrieve stored login message */
1119
	msg = get_login_message();
1120
1121
	buffer_clear(m);
1122
	buffer_put_string(m, msg, strlen(msg));
1123
	mm_request_send(socket, MONITOR_ANS_LOGINMSG, m);
1104
	return (0);
1124
	return (0);
1105
}
1125
}
1106
1126
(-)monitor.h (+1 lines)
Lines 43-48 Link Here
43
	MONITOR_REQ_KEYVERIFY, MONITOR_ANS_KEYVERIFY,
43
	MONITOR_REQ_KEYVERIFY, MONITOR_ANS_KEYVERIFY,
44
	MONITOR_REQ_KEYEXPORT,
44
	MONITOR_REQ_KEYEXPORT,
45
	MONITOR_REQ_PTY, MONITOR_ANS_PTY,
45
	MONITOR_REQ_PTY, MONITOR_ANS_PTY,
46
	MONITOR_REQ_LOGINMSG, MONITOR_ANS_LOGINMSG,
46
	MONITOR_REQ_PTYCLEANUP,
47
	MONITOR_REQ_PTYCLEANUP,
47
	MONITOR_REQ_SESSKEY, MONITOR_ANS_SESSKEY,
48
	MONITOR_REQ_SESSKEY, MONITOR_ANS_SESSKEY,
48
	MONITOR_REQ_SESSID,
49
	MONITOR_REQ_SESSID,
(-)monitor_wrap.c (+19 lines)
Lines 648-653 Link Here
648
	s->ttyfd = -1;
648
	s->ttyfd = -1;
649
}
649
}
650
650
651
char *
652
mm_get_login_message(void)
653
{
654
	Buffer m;
655
	char *msg;
656
657
	debug3("%s entering", __func__);
658
659
	buffer_init(&m);
660
	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_LOGINMSG, &m);
661
662
	debug3("%s waiting for MONITOR_ANS_LOGINMSG", __func__);
663
	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_LOGINMSG, &m);
664
	msg = buffer_get_string(&m, NULL);
665
	buffer_free(&m);
666
667
	return(msg);
668
}
669
651
#ifdef USE_PAM
670
#ifdef USE_PAM
652
void
671
void
653
mm_start_pam(char *user)
672
mm_start_pam(char *user)
(-)monitor_wrap.h (+1 lines)
Lines 62-67 Link Here
62
void mm_terminate(void);
62
void mm_terminate(void);
63
int mm_pty_allocate(int *, int *, char *, int);
63
int mm_pty_allocate(int *, int *, char *, int);
64
void mm_session_pty_cleanup2(void *);
64
void mm_session_pty_cleanup2(void *);
65
char *mm_get_login_message(void);
65
66
66
/* SSHv1 interfaces */
67
/* SSHv1 interfaces */
67
void mm_ssh1_session_id(u_char *);
68
void mm_ssh1_session_id(u_char *);
(-)session.c (-28 / +13 lines)
Lines 95-100 Link Here
95
extern u_int utmp_len;
95
extern u_int utmp_len;
96
extern int startup_pipe;
96
extern int startup_pipe;
97
extern void destroy_sensitive_data(void);
97
extern void destroy_sensitive_data(void);
98
extern Buffer login_message;
98
99
99
/* original command from peer. */
100
/* original command from peer. */
100
const char *original_command = NULL;
101
const char *original_command = NULL;
Lines 103-112 Link Here
103
#define MAX_SESSIONS 10
104
#define MAX_SESSIONS 10
104
Session	sessions[MAX_SESSIONS];
105
Session	sessions[MAX_SESSIONS];
105
106
106
#ifdef WITH_AIXAUTHENTICATE
107
char *aixloginmsg;
108
#endif /* WITH_AIXAUTHENTICATE */
109
110
#ifdef HAVE_LOGIN_CAP
107
#ifdef HAVE_LOGIN_CAP
111
login_cap_t *lc;
108
login_cap_t *lc;
112
#endif
109
#endif
Lines 719-725 Link Here
719
void
716
void
720
do_login(Session *s, const char *command)
717
do_login(Session *s, const char *command)
721
{
718
{
722
	char *time_string;
723
	socklen_t fromlen;
719
	socklen_t fromlen;
724
	struct sockaddr_storage from;
720
	struct sockaddr_storage from;
725
	struct passwd * pw = s->pw;
721
	struct passwd * pw = s->pw;
Lines 764-786 Link Here
764
	if (!is_pam_password_change_required())
760
	if (!is_pam_password_change_required())
765
		print_pam_messages();
761
		print_pam_messages();
766
#endif /* USE_PAM */
762
#endif /* USE_PAM */
767
#ifdef WITH_AIXAUTHENTICATE
763
768
	if (aixloginmsg && *aixloginmsg)
764
	/* print login messages */
769
		printf("%s\n", aixloginmsg);
765
	printf("%s", get_login_message());
770
#endif /* WITH_AIXAUTHENTICATE */
771
772
#ifndef NO_SSH_LASTLOG
773
	if (options.print_lastlog && s->last_login_time != 0) {
774
		time_string = ctime(&s->last_login_time);
775
		if (strchr(time_string, '\n'))
776
			*strchr(time_string, '\n') = 0;
777
		if (strcmp(s->hostname, "") == 0)
778
			printf("Last login: %s\r\n", time_string);
779
		else
780
			printf("Last login: %s from %s\r\n", time_string,
781
			    s->hostname);
782
	}
783
#endif /* NO_SSH_LASTLOG */
784
766
785
	do_motd();
767
	do_motd();
786
}
768
}
Lines 1597-1608 Link Here
1597
		packet_disconnect("Protocol error: you already have a pty.");
1579
		packet_disconnect("Protocol error: you already have a pty.");
1598
		return 0;
1580
		return 0;
1599
	}
1581
	}
1600
	/* Get the time and hostname when the user last logged in. */
1601
	if (options.print_lastlog) {
1602
		s->hostname[0] = '\0';
1603
		s->last_login_time = get_last_login_time(s->pw->pw_uid,
1604
		    s->pw->pw_name, s->hostname, sizeof(s->hostname));
1605
	}
1606
1582
1607
	s->term = packet_get_string(&len);
1583
	s->term = packet_get_string(&len);
1608
1584
Lines 1633-1638 Link Here
1633
		return 0;
1609
		return 0;
1634
	}
1610
	}
1635
	debug("session_pty_req: session %d alloc %s", s->self, s->tty);
1611
	debug("session_pty_req: session %d alloc %s", s->self, s->tty);
1612
1613
	/* copy login_message from monitor to display after fork */
1614
	if (use_privsep) {
1615
		char *msg;
1616
1617
		msg = PRIVSEP(get_login_message());
1618
		buffer_clear(&login_message);
1619
		buffer_append(&login_message, msg, strlen(msg));
1620
	}
1636
1621
1637
	/* for SSH1 the tty modes length is not given */
1622
	/* for SSH1 the tty modes length is not given */
1638
	if (!compat20)
1623
	if (!compat20)
(-)session.h (-3 lines)
Lines 39-47 Link Here
39
	int	ptyfd, ttyfd, ptymaster;
39
	int	ptyfd, ttyfd, ptymaster;
40
	u_int	row, col, xpixel, ypixel;
40
	u_int	row, col, xpixel, ypixel;
41
	char	tty[TTYSZ];
41
	char	tty[TTYSZ];
42
	/* last login */
43
	char	hostname[MAXHOSTNAMELEN];
44
	time_t	last_login_time;
45
	/* X11 */
42
	/* X11 */
46
	u_int	display_number;
43
	u_int	display_number;
47
	char	*display;
44
	char	*display;
(-)sshd.c (+6 lines)
Lines 205-210 Link Here
205
extern struct monitor *pmonitor;
205
extern struct monitor *pmonitor;
206
extern int use_privsep;
206
extern int use_privsep;
207
207
208
/* Buffer that will collect authentication messages for display after login */
209
Buffer login_message;
210
208
/* Prototypes for various functions defined later in this file. */
211
/* Prototypes for various functions defined later in this file. */
209
void destroy_sensitive_data(void);
212
void destroy_sensitive_data(void);
210
void demote_sensitive_data(void);
213
void demote_sensitive_data(void);
Lines 1501-1506 Link Here
1501
	if (use_privsep)
1504
	if (use_privsep)
1502
		if ((authctxt = privsep_preauth()) != NULL)
1505
		if ((authctxt = privsep_preauth()) != NULL)
1503
			goto authenticated;
1506
			goto authenticated;
1507
1508
	/* prepare buffer to collect authentication messages */
1509
	buffer_init(&login_message);
1504
1510
1505
	/* perform the key exchange */
1511
	/* perform the key exchange */
1506
	/* authenticate user and start session */
1512
	/* authenticate user and start session */
(-)sshlogin.c (-7 / +58 lines)
Lines 42-47 Link Here
42
RCSID("$OpenBSD: sshlogin.c,v 1.5 2002/08/29 15:57:25 stevesk Exp $");
42
RCSID("$OpenBSD: sshlogin.c,v 1.5 2002/08/29 15:57:25 stevesk Exp $");
43
43
44
#include "loginrec.h"
44
#include "loginrec.h"
45
#include "xmalloc.h"
46
#include "buffer.h"
47
#include "log.h"
48
#include "servconf.h"
49
50
extern Buffer login_message;
51
extern ServerOptions options;
45
52
46
/*
53
/*
47
 * Returns the time when the user last logged in.  Returns 0 if the
54
 * Returns the time when the user last logged in.  Returns 0 if the
Lines 60-78 Link Here
60
}
67
}
61
68
62
/*
69
/*
63
 * Records that the user has logged in.  I these parts of operating systems
70
 * Retrieves login_message.  Returns empty string if no message exists.
64
 * were more standardized.
71
 */
72
char *
73
get_login_message(void)
74
{
75
	buffer_append(&login_message, "", 1);	/* null terminate string */
76
	return(buffer_ptr(&login_message));
77
}
78
79
/*
80
 * Generate and store last login message.  This must be done before
81
 * login_login() is called and lastlog is updated.
82
 */
83
void
84
store_lastlog_message(const char *user, uid_t uid)
85
{
86
#if !defined(NO_SSH_LASTLOG)
87
	if (options.print_lastlog) {
88
		char *time_string, lasthost[MAXHOSTNAMELEN], buf[256];
89
		time_t last_login_time;
90
91
		last_login_time = get_last_login_time(uid, user, lasthost,
92
		    sizeof(lasthost));
93
94
		if (last_login_time != 0) {
95
			time_string = ctime(&last_login_time);
96
			if (strchr(time_string, '\n'))
97
				*strchr(time_string, '\n') = 0;
98
			if (strcmp(lasthost, "") == 0)
99
				snprintf(buf, sizeof(buf),
100
				    "Last login: %s\r\n",
101
				    time_string);
102
			else
103
				snprintf(buf, sizeof(buf),
104
				    "Last login: %s from %s\r\n",
105
				    time_string, lasthost);
106
			buffer_append(&login_message, buf, strlen(buf));
107
		}
108
	}
109
#endif
110
}
111
112
/*
113
 * Records that the user has logged in.  I wish these parts of operating
114
 * systems were more standardized.
65
 */
115
 */
66
void
116
void
67
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
117
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
68
    const char *host, struct sockaddr * addr, socklen_t addrlen)
118
    const char *host, struct sockaddr * addr, socklen_t addrlen)
69
{
119
{
70
  struct logininfo *li;
120
	struct logininfo *li;
71
121
72
  li = login_alloc_entry(pid, user, host, ttyname);
122
	store_lastlog_message(user, uid); /* save previous before writing new */
73
  login_set_addr(li, addr, addrlen);
123
	li = login_alloc_entry(pid, user, host, ttyname);
74
  login_login(li);
124
	login_set_addr(li, addr, addrlen);
75
  login_free_entry(li);
125
	login_login(li);
126
	login_free_entry(li);
76
}
127
}
77
128
78
#ifdef LOGIN_NEEDS_UTMPX
129
#ifdef LOGIN_NEEDS_UTMPX
(-)sshlogin.h (+5 lines)
Lines 19-28 Link Here
19
    const char *, struct sockaddr *, socklen_t);
19
    const char *, struct sockaddr *, socklen_t);
20
void   record_logout(pid_t, const char *, const char *);
20
void   record_logout(pid_t, const char *, const char *);
21
u_long         get_last_login_time(uid_t, const char *, char *, u_int);
21
u_long         get_last_login_time(uid_t, const char *, char *, u_int);
22
char *get_login_message(void);
22
23
23
#ifdef LOGIN_NEEDS_UTMPX
24
#ifdef LOGIN_NEEDS_UTMPX
24
void	record_utmp_only(pid_t, const char *, const char *, const char *,
25
void	record_utmp_only(pid_t, const char *, const char *, const char *,
25
		struct sockaddr *, socklen_t);
26
		struct sockaddr *, socklen_t);
27
#endif
28
29
#ifdef WITH_AIXAUTHENTICATE
30
# include <login.h>
26
#endif
31
#endif
27
32
28
#endif
33
#endif

Return to bug 463