summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-04-16 18:29:15 +1000
committerDamien Miller <djm@mindrot.org>2001-04-16 18:29:15 +1000
commitcf205e8f353f3f7da38bab329951301ac2d69426 (patch)
treeafcdc1034f92c3b5a98ed0580ac1567268222f4b
parent0b1e0a12183461a38d6c59b3e2511fdb7f96d534 (diff)
- djm@cvs.openbsd.org 2001/04/16 08:19:31
[session.c] Split motd and hushlogin checks into seperate functions, helps for portable. From Chris Adams <cmadams@hiwaay.net>; ok markus@
-rw-r--r--ChangeLog6
-rw-r--r--session.c55
2 files changed, 47 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index de13da65d..611e001d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,10 @@
30 - deraadt@cvs.openbsd.org 2001/04/16 08:05:34 30 - deraadt@cvs.openbsd.org 2001/04/16 08:05:34
31 [xmalloc.c] 31 [xmalloc.c]
32 xrealloc dealing with ptr == nULL; mouring 32 xrealloc dealing with ptr == nULL; mouring
33 - djm@cvs.openbsd.org 2001/04/16 08:19:31
34 [session.c]
35 Split motd and hushlogin checks into seperate functions, helps for
36 portable. From Chris Adams <cmadams@hiwaay.net>; ok markus@
33 37
3420010415 3820010415
35 - OpenBSD CVS Sync 39 - OpenBSD CVS Sync
@@ -5115,4 +5119,4 @@
5115 - Wrote replacements for strlcpy and mkdtemp 5119 - Wrote replacements for strlcpy and mkdtemp
5116 - Released 1.0pre1 5120 - Released 1.0pre1
5117 5121
5118$Id: ChangeLog,v 1.1126 2001/04/16 08:27:07 djm Exp $ 5122$Id: ChangeLog,v 1.1127 2001/04/16 08:29:15 djm Exp $
diff --git a/session.c b/session.c
index ebefd91c4..77e11987e 100644
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
33 */ 33 */
34 34
35#include "includes.h" 35#include "includes.h"
36RCSID("$OpenBSD: session.c,v 1.72 2001/04/14 16:33:20 stevesk Exp $"); 36RCSID("$OpenBSD: session.c,v 1.73 2001/04/16 08:19:31 djm Exp $");
37 37
38#include "ssh.h" 38#include "ssh.h"
39#include "ssh1.h" 39#include "ssh1.h"
@@ -128,6 +128,8 @@ void do_exec_pty(Session *s, const char *command);
128void do_exec_no_pty(Session *s, const char *command); 128void do_exec_no_pty(Session *s, const char *command);
129void do_login(Session *s, const char *command); 129void do_login(Session *s, const char *command);
130void do_child(Session *s, const char *command); 130void do_child(Session *s, const char *command);
131void do_motd(void);
132int check_quietlogin(Session *s, const char *command);
131 133
132void do_authenticated1(Authctxt *authctxt); 134void do_authenticated1(Authctxt *authctxt);
133void do_authenticated2(Authctxt *authctxt); 135void do_authenticated2(Authctxt *authctxt);
@@ -681,13 +683,10 @@ do_exec_pty(Session *s, const char *command)
681void 683void
682do_login(Session *s, const char *command) 684do_login(Session *s, const char *command)
683{ 685{
684 FILE *f;
685 char *time_string; 686 char *time_string;
686 char buf[256];
687 char hostname[MAXHOSTNAMELEN]; 687 char hostname[MAXHOSTNAMELEN];
688 socklen_t fromlen; 688 socklen_t fromlen;
689 struct sockaddr_storage from; 689 struct sockaddr_storage from;
690 struct stat st;
691 time_t last_login_time; 690 time_t last_login_time;
692 struct passwd * pw = s->pw; 691 struct passwd * pw = s->pw;
693 pid_t pid = getpid(); 692 pid_t pid = getpid();
@@ -729,15 +728,7 @@ do_login(Session *s, const char *command)
729 } 728 }
730#endif 729#endif
731 730
732 /* Done if .hushlogin exists or a command given. */ 731 if (check_quietlogin(s, command))
733 if (command != NULL)
734 return;
735 snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir);
736#ifdef HAVE_LOGIN_CAP
737 if (login_getcapbool(lc, "hushlogin", 0) || stat(buf, &st) >= 0)
738#else
739 if (stat(buf, &st) >= 0)
740#endif
741 return; 732 return;
742 733
743#ifdef USE_PAM 734#ifdef USE_PAM
@@ -758,6 +749,19 @@ do_login(Session *s, const char *command)
758 else 749 else
759 printf("Last login: %s from %s\r\n", time_string, hostname); 750 printf("Last login: %s from %s\r\n", time_string, hostname);
760 } 751 }
752
753 do_motd();
754}
755
756/*
757 * Display the message of the day.
758 */
759void
760do_motd(void)
761{
762 FILE *f;
763 char buf[256];
764
761 if (options.print_motd) { 765 if (options.print_motd) {
762#ifdef HAVE_LOGIN_CAP 766#ifdef HAVE_LOGIN_CAP
763 f = fopen(login_getcapstr(lc, "welcome", "/etc/motd", 767 f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",
@@ -773,6 +777,31 @@ do_login(Session *s, const char *command)
773 } 777 }
774} 778}
775 779
780
781/*
782 * Check for quiet login, either .hushlogin or command given.
783 */
784int
785check_quietlogin(Session *s, const char *command)
786{
787 char buf[256];
788 struct passwd * pw = s->pw;
789 struct stat st;
790
791 /* Return 1 if .hushlogin exists or a command given. */
792 if (command != NULL)
793 return 1;
794 snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir);
795#ifdef HAVE_LOGIN_CAP
796 if (login_getcapbool(lc, "hushlogin", 0) || stat(buf, &st) >= 0)
797 return 1;
798#else
799 if (stat(buf, &st) >= 0)
800 return 1;
801#endif
802 return 0;
803}
804
776/* 805/*
777 * Sets the value of the given variable in the environment. If the variable 806 * Sets the value of the given variable in the environment. If the variable
778 * already exists, its value is overriden. 807 * already exists, its value is overriden.