1999-11-28 22:40:28 +00:00
|
|
|
--- /usr/ports/distfiles/OpenSSH-1.2/src/usr.bin/ssh/sshd.c Sun Nov 28 16:50:26 1999
|
|
|
|
+++ sshd.c Sun Nov 28 17:22:27 1999
|
|
|
|
@@ -32,6 +32,16 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
int deny_severity = LOG_WARNING;
|
|
|
|
#endif /* LIBWRAP */
|
|
|
|
|
|
|
|
+#ifdef __FreeBSD__
|
|
|
|
+#include <libutil.h>
|
|
|
|
+#include <syslog.h>
|
|
|
|
+#define LOGIN_CAP
|
|
|
|
+#endif /* __FreeBSD__ */
|
|
|
|
+
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+#include <login_cap.h>
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
+
|
|
|
|
#ifndef O_NOCTTY
|
|
|
|
#define O_NOCTTY 0
|
|
|
|
#endif
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -1048,6 +1058,14 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ /* Fail if the account's expiration time has passed. */
|
|
|
|
+ if (pw->pw_expire != 0) {
|
|
|
|
+ struct timeval tv;
|
|
|
|
+
|
1999-11-28 22:40:28 +00:00
|
|
|
+ (void)gettimeofday(&tv, NULL);
|
|
|
|
+ if (tv.tv_sec >= pw->pw_expire)
|
|
|
|
+ return 0;
|
1999-11-24 03:36:23 +00:00
|
|
|
+ }
|
|
|
|
/* We found no reason not to let this user try to log on... */
|
|
|
|
return 1;
|
|
|
|
}
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -1083,6 +1101,9 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
pwcopy.pw_gid = pw->pw_gid;
|
|
|
|
pwcopy.pw_dir = xstrdup(pw->pw_dir);
|
|
|
|
pwcopy.pw_shell = xstrdup(pw->pw_shell);
|
|
|
|
+ pwcopy.pw_class = xstrdup(pw->pw_class);
|
|
|
|
+ pwcopy.pw_expire = pw->pw_expire;
|
|
|
|
+ pwcopy.pw_change = pw->pw_change;
|
|
|
|
pw = &pwcopy;
|
|
|
|
|
1999-11-28 22:40:28 +00:00
|
|
|
/*
|
|
|
|
@@ -1871,6 +1892,10 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
struct sockaddr_in from;
|
|
|
|
int fromlen;
|
|
|
|
struct pty_cleanup_context cleanup_context;
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ login_cap_t *lc;
|
|
|
|
+ char *fname;
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
|
|
|
/* Get remote host name. */
|
|
|
|
hostname = get_canonical_hostname();
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -1935,6 +1960,12 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
/* Check if .hushlogin exists. */
|
|
|
|
snprintf(line, sizeof line, "%.200s/.hushlogin", pw->pw_dir);
|
|
|
|
quiet_login = stat(line, &st) >= 0;
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ lc = login_getpwclass(pw);
|
|
|
|
+ if (lc == NULL)
|
|
|
|
+ lc = login_getclassbyname(NULL, pw);
|
|
|
|
+ quiet_login = login_getcapbool(lc, "hushlogin", quiet_login);
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
1999-11-28 22:40:28 +00:00
|
|
|
/*
|
|
|
|
* If the user has logged in before, display the time of last
|
|
|
|
@@ -1958,6 +1989,20 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
else
|
|
|
|
printf("Last login: %s from %s\r\n", time_string, buf);
|
|
|
|
}
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ if (command == NULL && !quiet_login && !options.use_login) {
|
|
|
|
+ fname = login_getcapstr(lc, "copyright", NULL, NULL);
|
|
|
|
+ if (fname != NULL && (f = fopen(fname, "r")) != NULL) {
|
1999-11-28 22:40:28 +00:00
|
|
|
+ while (fgets(line, sizeof(line), f) != NULL)
|
1999-11-24 03:36:23 +00:00
|
|
|
+ fputs(line, stdout);
|
|
|
|
+ fclose(f);
|
|
|
|
+ } else
|
|
|
|
+ (void)printf("%s\n\t%s %s\n",
|
|
|
|
+ "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994",
|
|
|
|
+ "The Regents of the University of California. ",
|
|
|
|
+ "All rights reserved.");
|
|
|
|
+ }
|
|
|
|
+#endif /* LOGIN_CAP */
|
1999-11-28 22:40:28 +00:00
|
|
|
/*
|
|
|
|
* Print /etc/motd unless a command was specified or printing
|
|
|
|
* it was disabled in server options or login(1) will be
|
|
|
|
@@ -1966,14 +2011,22 @@
|
|
|
|
*/
|
1999-11-24 03:36:23 +00:00
|
|
|
if (command == NULL && options.print_motd && !quiet_login &&
|
|
|
|
!options.use_login) {
|
1999-11-28 22:40:28 +00:00
|
|
|
- /* Print /etc/motd if it exists. */
|
1999-11-24 03:36:23 +00:00
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ fname = login_getcapstr(lc, "welcome", NULL, NULL);
|
|
|
|
+ login_close(lc);
|
|
|
|
+ if (fname == NULL || (f = fopen(fname, "r")) == NULL)
|
1999-11-28 22:40:28 +00:00
|
|
|
+ f = fopen("/etc/motd", "r");
|
|
|
|
+#else /* LOGIN_CAP */
|
1999-11-24 03:36:23 +00:00
|
|
|
f = fopen("/etc/motd", "r");
|
1999-11-28 22:40:28 +00:00
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
+ /* Print /etc/motd if it exists. */
|
1999-11-24 03:36:23 +00:00
|
|
|
if (f) {
|
1999-11-28 22:40:28 +00:00
|
|
|
while (fgets(line, sizeof(line), f))
|
|
|
|
fputs(line, stdout);
|
1999-11-24 03:36:23 +00:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
/* Do common processing for the child, such as execing the command. */
|
|
|
|
do_child(command, pw, term, display, auth_proto, auth_data, ttyname);
|
|
|
|
/* NOTREACHED */
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -2117,15 +2170,34 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
extern char **environ;
|
|
|
|
struct stat st;
|
|
|
|
char *argv[10];
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ login_cap_t *lc;
|
|
|
|
+
|
|
|
|
+ lc = login_getpwclass(pw);
|
|
|
|
+ if (lc == NULL)
|
|
|
|
+ lc = login_getclassbyname(NULL, pw);
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
|
|
|
f = fopen("/etc/nologin", "r");
|
|
|
|
+#ifdef __FreeBSD__
|
|
|
|
+ if (f == NULL)
|
|
|
|
+ f = fopen("/var/run/nologin", "r");
|
|
|
|
+#endif /* __FreeBSD__ */
|
|
|
|
if (f) {
|
1999-11-28 22:40:28 +00:00
|
|
|
/* /etc/nologin exists. Print its contents and exit. */
|
1999-11-24 03:36:23 +00:00
|
|
|
- while (fgets(buf, sizeof(buf), f))
|
|
|
|
- fputs(buf, stderr);
|
|
|
|
- fclose(f);
|
|
|
|
- if (pw->pw_uid != 0)
|
|
|
|
- exit(254);
|
|
|
|
+#ifdef LOGIN_CAP
|
1999-11-28 22:40:28 +00:00
|
|
|
+ /* On FreeBSD, etc., allow overriding nologin via login.conf. */
|
1999-11-24 03:36:23 +00:00
|
|
|
+ if (!login_getcapbool(lc, "ignorenologin", 0)) {
|
1999-11-28 22:40:28 +00:00
|
|
|
+#else /* LOGIN_CAP */
|
|
|
|
+ if (1) {
|
1999-11-24 03:36:23 +00:00
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
+ while (fgets(buf, sizeof(buf), f))
|
|
|
|
+ fputs(buf, stderr);
|
|
|
|
+ fclose(f);
|
|
|
|
+ if (pw->pw_uid != 0)
|
|
|
|
+ exit(254);
|
|
|
|
+ }
|
1999-11-28 22:40:28 +00:00
|
|
|
+
|
|
|
|
}
|
1999-11-24 03:36:23 +00:00
|
|
|
/* Set login name in the kernel. */
|
|
|
|
if (setlogin(pw->pw_name) < 0)
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -2135,6 +2207,13 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
/* Login(1) does this as well, and it needs uid 0 for the "-h"
|
|
|
|
switch, so we let login(1) to this for us. */
|
|
|
|
if (!options.use_login) {
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ if (setclasscontext(pw->pw_class, LOGIN_SETPRIORITY |
|
|
|
|
+ LOGIN_SETRESOURCES | LOGIN_SETUMASK) == -1) {
|
|
|
|
+ perror("setclasscontext");
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
if (getuid() == 0 || geteuid() == 0) {
|
|
|
|
if (setgid(pw->pw_gid) < 0) {
|
|
|
|
perror("setgid");
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -2157,7 +2236,14 @@
|
|
|
|
* Get the shell from the password data. An empty shell field is
|
|
|
|
* legal, and means /bin/sh.
|
|
|
|
*/
|
1999-11-24 03:36:23 +00:00
|
|
|
+#ifdef LOGIN_CAP
|
1999-11-28 22:40:28 +00:00
|
|
|
+ shell = pw->pw_shell;
|
|
|
|
+ shell = login_getcapstr(lc, "shell", shell, shell);
|
1999-11-24 03:36:23 +00:00
|
|
|
+ if (shell[0] == '\0')
|
|
|
|
+ shell = _PATH_BSHELL;
|
|
|
|
+#else /* LOGIN_CAP */
|
|
|
|
shell = (pw->pw_shell[0] == '\0') ? _PATH_BSHELL : pw->pw_shell;
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
|
|
|
#ifdef AFS
|
|
|
|
/* Try to get AFS tokens for the local cell. */
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -2181,7 +2267,12 @@
|
1999-11-24 03:36:23 +00:00
|
|
|
child_set_env(&env, &envsize, "USER", pw->pw_name);
|
|
|
|
child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
|
|
|
|
child_set_env(&env, &envsize, "HOME", pw->pw_dir);
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ child_set_env(&env, &envsize, "PATH",
|
|
|
|
+ login_getpath(lc, "path", _PATH_STDPATH));
|
|
|
|
+#else /* LOGIN_CAP */
|
|
|
|
child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "%.200s/%.50s",
|
|
|
|
_PATH_MAILDIR, pw->pw_name);
|
1999-11-28 22:40:28 +00:00
|
|
|
@@ -2271,6 +2362,9 @@
|
|
|
|
*/
|
1999-11-24 03:36:23 +00:00
|
|
|
endpwent();
|
|
|
|
endhostent();
|
|
|
|
+#ifdef LOGIN_CAP
|
|
|
|
+ login_close(lc);
|
|
|
|
+#endif /* LOGIN_CAP */
|
|
|
|
|
1999-11-28 22:40:28 +00:00
|
|
|
/*
|
|
|
|
* Close any extra open file descriptors so that we don\'t have them
|
|
|
|
@@ -2278,7 +2372,7 @@
|
|
|
|
* initgroups, because at least on Solaris 2.3 it leaves file
|
|
|
|
* descriptors open.
|
|
|
|
*/
|
1999-11-24 03:36:23 +00:00
|
|
|
- for (i = 3; i < 64; i++)
|
|
|
|
+ for (i = 3; i < getdtablesize(); i++)
|
|
|
|
close(i);
|
1999-11-28 22:40:28 +00:00
|
|
|
|
|
|
|
/* Change current directory to the user\'s home directory. */
|
|
|
|
@@ -2297,6 +2391,26 @@
|
|
|
|
* in this order).
|
|
|
|
*/
|
|
|
|
if (!options.use_login) {
|
1999-11-24 03:36:23 +00:00
|
|
|
+#ifdef __FreeBSD__
|
1999-11-28 22:40:28 +00:00
|
|
|
+ /*
|
|
|
|
+ * If the password change time is set and has passed, give the
|
|
|
|
+ * user a password expiry notice and chance to change it.
|
|
|
|
+ */
|
|
|
|
+ if (pw->pw_change != 0) {
|
|
|
|
+ struct timeval tv;
|
1999-11-24 03:36:23 +00:00
|
|
|
+
|
1999-11-28 22:40:28 +00:00
|
|
|
+ (void)gettimeofday(&tv, NULL);
|
|
|
|
+ if (tv.tv_sec >= pw->pw_change) {
|
|
|
|
+ (void)printf(
|
|
|
|
+ "Sorry -- your password has expired.\n");
|
|
|
|
+ syslog(LOG_INFO,
|
|
|
|
+ "%s Password expired - forcing change",
|
|
|
|
+ pw->pw_name);
|
|
|
|
+ if (system("/usr/bin/passwd") != 0)
|
|
|
|
+ perror("/usr/bin/passwd");
|
|
|
|
+ }
|
1999-11-24 03:36:23 +00:00
|
|
|
+ }
|
|
|
|
+#endif /* __FreeBSD__ */
|
1999-11-28 22:40:28 +00:00
|
|
|
if (stat(SSH_USER_RC, &st) >= 0) {
|
|
|
|
if (debug_flag)
|
|
|
|
fprintf(stderr, "Running /bin/sh %s\n", SSH_USER_RC);
|