summaryrefslogtreecommitdiffstats
path: root/misc.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2023-10-12 00:42:26 +0200
committerDamien Miller <djm@mindrot.org>2023-10-12 01:00:13 +0200
commita752a6c0e1001f93696d7025f0c867f0376e2ecf (patch)
treedbe5b78436bc288efe6f458e167864f38056f768 /misc.c
parentupstream: add support for reading ED25519 private keys in PEM PKCS8 (diff)
downloadopenssh-a752a6c0e1001f93696d7025f0c867f0376e2ecf.tar.xz
openssh-a752a6c0e1001f93696d7025f0c867f0376e2ecf.zip
upstream: add ChannelTimeout support to the client, mirroring the
same option in the server. ok markus@ OpenBSD-Commit-ID: 55630b26f390ac063980cfe7ad8c54b03284ef02
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index 42582c618..662b7c670 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.187 2023/08/28 03:31:16 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.188 2023/10/11 22:42:26 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -2493,6 +2493,43 @@ format_absolute_time(uint64_t t, char *buf, size_t len)
strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
}
+/*
+ * Parse a "pattern=interval" clause (e.g. a ChannelTimeout).
+ * Returns 0 on success or non-zero on failure.
+ * Caller must free *typep.
+ */
+int
+parse_pattern_interval(const char *s, char **typep, int *secsp)
+{
+ char *cp, *sdup;
+ int secs;
+
+ if (typep != NULL)
+ *typep = NULL;
+ if (secsp != NULL)
+ *secsp = 0;
+ if (s == NULL)
+ return -1;
+ sdup = xstrdup(s);
+
+ if ((cp = strchr(sdup, '=')) == NULL || cp == sdup) {
+ free(sdup);
+ return -1;
+ }
+ *cp++ = '\0';
+ if ((secs = convtime(cp)) < 0) {
+ free(sdup);
+ return -1;
+ }
+ /* success */
+ if (typep != NULL)
+ *typep = xstrdup(sdup);
+ if (secsp != NULL)
+ *secsp = secs;
+ free(sdup);
+ return 0;
+}
+
/* check if path is absolute */
int
path_absolute(const char *path)