summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/misc.c64
-rw-r--r--usr.bin/ssh/misc.h26
-rw-r--r--usr.bin/ssh/servconf.c21
-rw-r--r--usr.bin/ssh/sshd.845
-rw-r--r--usr.bin/ssh/sshd.c12
5 files changed, 157 insertions, 11 deletions
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c
index 19487bea9b6..3e98cd95c94 100644
--- a/usr.bin/ssh/misc.c
+++ b/usr.bin/ssh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $ */
+/* $OpenBSD: misc.c,v 1.9 2001/05/19 19:43:57 stevesk Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -25,7 +25,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $");
+RCSID("$OpenBSD: misc.c,v 1.9 2001/05/19 19:43:57 stevesk Exp $");
#include "misc.h"
#include "log.h"
@@ -152,6 +152,66 @@ int a2port(const char *s)
return port;
}
+#define SECONDS 1
+#define MINUTES (SECONDS * 60)
+#define HOURS (MINUTES * 60)
+#define DAYS (HOURS * 24)
+#define WEEKS (DAYS * 7)
+
+long convtime(const char *s)
+{
+ long total, secs;
+ const char *p;
+ char *endp;
+
+ errno = 0;
+ total = 0;
+ p = s;
+
+ if (p == NULL || *p == '\0')
+ return -1;
+
+ while (*p) {
+ secs = strtol(p, &endp, 10);
+ if (p == endp ||
+ (errno == ERANGE && (secs == LONG_MIN || secs == LONG_MAX)) ||
+ secs < 0)
+ return -1;
+
+ switch (*endp++) {
+ case '\0':
+ endp--;
+ case 's':
+ case 'S':
+ break;
+ case 'm':
+ case 'M':
+ secs *= MINUTES;
+ break;
+ case 'h':
+ case 'H':
+ secs *= HOURS;
+ break;
+ case 'd':
+ case 'D':
+ secs *= DAYS;
+ break;
+ case 'w':
+ case 'W':
+ secs *= WEEKS;
+ break;
+ default:
+ return -1;
+ }
+ total += secs;
+ if (total < 0)
+ return -1;
+ p = endp;
+ }
+
+ return total;
+}
+
char *
cleanhostname(char *host)
{
diff --git a/usr.bin/ssh/misc.h b/usr.bin/ssh/misc.h
index 4f02f4ebaa5..11d231ac1f7 100644
--- a/usr.bin/ssh/misc.h
+++ b/usr.bin/ssh/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.7 2001/05/11 14:59:56 markus Exp $ */
+/* $OpenBSD: misc.h,v 1.8 2001/05/19 19:43:57 stevesk Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -34,6 +34,30 @@ int a2port(const char *s);
char *cleanhostname(char *host);
char *colon(char *cp);
+/*
+ * Convert a time string into seconds; format is
+ * a sequence of:
+ * time[qualifier]
+ *
+ * Valid time qualifiers are:
+ * <none> seconds
+ * s|S seconds
+ * m|M minutes
+ * h|H hours
+ * d|D days
+ * w|W weeks
+ *
+ * Examples:
+ * 90m 90 minutes
+ * 1h30m 90 minutes
+ * 2d 2 days
+ * 1w 1 week
+ *
+ * Return -1 if time string is invalid.
+ */
+
+long convtime(const char *s);
+
/* function to assist building execv() arguments */
typedef struct arglist arglist;
struct arglist {
diff --git a/usr.bin/ssh/servconf.c b/usr.bin/ssh/servconf.c
index 40c2e1035df..36c7f601d30 100644
--- a/usr.bin/ssh/servconf.c
+++ b/usr.bin/ssh/servconf.c
@@ -10,7 +10,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: servconf.c,v 1.80 2001/05/18 14:13:29 markus Exp $");
+RCSID("$OpenBSD: servconf.c,v 1.81 2001/05/19 19:43:57 stevesk Exp $");
#ifdef KRB4
#include <krb.h>
@@ -425,11 +425,21 @@ parse_int:
case sLoginGraceTime:
intptr = &options->login_grace_time;
- goto parse_int;
+parse_time:
+ arg = strdelim(&cp);
+ if (!arg || *arg == '\0')
+ fatal("%s line %d: missing time value.",
+ filename, linenum);
+ if ((value = convtime(arg)) == -1)
+ fatal("%s line %d: invalid time value.",
+ filename, linenum);
+ if (*intptr == -1)
+ *intptr = value;
+ break;
case sKeyRegenerationTime:
intptr = &options->key_regeneration_time;
- goto parse_int;
+ goto parse_time;
case sListenAddress:
arg = strdelim(&cp);
@@ -788,12 +798,15 @@ parse_flag:
case sBanner:
charptr = &options->banner;
goto parse_filename;
+
case sClientAliveInterval:
intptr = &options->client_alive_interval;
- goto parse_int;
+ goto parse_time;
+
case sClientAliveCountMax:
intptr = &options->client_alive_count_max;
goto parse_int;
+
default:
fatal("%s line %d: Missing handler for opcode %s (%d)",
filename, linenum, arg, opcode);
diff --git a/usr.bin/ssh/sshd.8 b/usr.bin/ssh/sshd.8
index 572f7cd0724..4e8abc7af28 100644
--- a/usr.bin/ssh/sshd.8
+++ b/usr.bin/ssh/sshd.8
@@ -34,7 +34,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: sshd.8,v 1.123 2001/05/19 16:46:19 markus Exp $
+.\" $OpenBSD: sshd.8,v 1.124 2001/05/19 19:43:57 stevesk Exp $
.Dd September 25, 1999
.Dt SSHD 8
.Os
@@ -786,6 +786,49 @@ program.
The default is
.Pa /usr/X11R6/bin/xauth .
.El
+.Ss Time Formats
+.Pp
+.Nm
+command-line arguments and configuration file options that specify time
+may be expressed using a sequence of the form:
+.Sm off
+.Ar time Oo Ar qualifier Oc ,
+.Sm on
+where
+.Ar time
+is a positive integer value and
+.Ar qualifier
+is one of the following:
+.Pp
+.Bl -tag -width Ds -compact -offset indent
+.It Cm <none>
+seconds
+.It Cm s | Cm S
+seconds
+.It Cm m | Cm M
+minutes
+.It Cm h | Cm H
+hours
+.It Cm d | Cm D
+days
+.It Cm w | Cm W
+weeks
+.El
+.Pp
+Each member of the sequence is added together to calculate
+the total time value.
+.Pp
+Time format examples:
+.Pp
+.Bl -tag -width Ds -compact -offset indent
+.It 600
+600 seconds (10 minutes)
+.It 10m
+10 minutes
+.It 1h30m
+1 hour 30 minutes (90 minutes)
+.El
+
.Sh LOGIN PROCESS
When a user successfully logs in,
.Nm
diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c
index 296a2cea9af..fb7e058b980 100644
--- a/usr.bin/ssh/sshd.c
+++ b/usr.bin/ssh/sshd.c
@@ -40,7 +40,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: sshd.c,v 1.196 2001/05/18 14:13:29 markus Exp $");
+RCSID("$OpenBSD: sshd.c,v 1.197 2001/05/19 19:43:57 stevesk Exp $");
#include <openssl/dh.h>
#include <openssl/bn.h>
@@ -605,10 +605,16 @@ main(int ac, char **av)
}
break;
case 'g':
- options.login_grace_time = atoi(optarg);
+ if ((options.login_grace_time = convtime(optarg)) == -1) {
+ fprintf(stderr, "Invalid login grace time.\n");
+ exit(1);
+ }
break;
case 'k':
- options.key_regeneration_time = atoi(optarg);
+ if ((options.key_regeneration_time = convtime(optarg)) == -1) {
+ fprintf(stderr, "Invalid key regeneration interval.\n");
+ exit(1);
+ }
break;
case 'h':
if (options.num_host_key_files >= MAX_HOSTKEYS) {