=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/misc.c,v retrieving revision 1.187 retrieving revision 1.188 diff -u -r1.187 -r1.188 --- src/usr.bin/ssh/misc.c 2023/08/28 03:31:16 1.187 +++ src/usr.bin/ssh/misc.c 2023/10/11 22:42:26 1.188 @@ -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. @@ -2384,6 +2384,43 @@ localtime_r(&tt, &tm); 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 */