summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/misc.c b/misc.c
index 8cb411ccc..2e366f81b 100644
--- a/misc.c
+++ b/misc.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: misc.c,v 1.25 2004/08/11 21:43:05 avsm Exp $"); 26RCSID("$OpenBSD: misc.c,v 1.28 2005/03/01 10:09:52 djm Exp $");
27 27
28#include "misc.h" 28#include "misc.h"
29#include "log.h" 29#include "log.h"
@@ -275,6 +275,48 @@ convtime(const char *s)
275 return total; 275 return total;
276} 276}
277 277
278/*
279 * Search for next delimiter between hostnames/addresses and ports.
280 * Argument may be modified (for termination).
281 * Returns *cp if parsing succeeds.
282 * *cp is set to the start of the next delimiter, if one was found.
283 * If this is the last field, *cp is set to NULL.
284 */
285char *
286hpdelim(char **cp)
287{
288 char *s, *old;
289
290 if (cp == NULL || *cp == NULL)
291 return NULL;
292
293 old = s = *cp;
294 if (*s == '[') {
295 if ((s = strchr(s, ']')) == NULL)
296 return NULL;
297 else
298 s++;
299 } else if ((s = strpbrk(s, ":/")) == NULL)
300 s = *cp + strlen(*cp); /* skip to end (see first case below) */
301
302 switch (*s) {
303 case '\0':
304 *cp = NULL; /* no more fields*/
305 break;
306
307 case ':':
308 case '/':
309 *s = '\0'; /* terminate */
310 *cp = s + 1;
311 break;
312
313 default:
314 return NULL;
315 }
316
317 return old;
318}
319
278char * 320char *
279cleanhostname(char *host) 321cleanhostname(char *host)
280{ 322{
@@ -332,3 +374,26 @@ addargs(arglist *args, char *fmt, ...)
332 args->list[args->num++] = xstrdup(buf); 374 args->list[args->num++] = xstrdup(buf);
333 args->list[args->num] = NULL; 375 args->list[args->num] = NULL;
334} 376}
377
378/*
379 * Read an entire line from a public key file into a static buffer, discarding
380 * lines that exceed the buffer size. Returns 0 on success, -1 on failure.
381 */
382int
383read_keyfile_line(FILE *f, const char *filename, char *buf, size_t bufsz,
384 u_long *lineno)
385{
386 while (fgets(buf, bufsz, f) != NULL) {
387 (*lineno)++;
388 if (buf[strlen(buf) - 1] == '\n' || feof(f)) {
389 return 0;
390 } else {
391 debug("%s: %s line %lu exceeds size limit", __func__,
392 filename, *lineno);
393 /* discard remainder of line */
394 while(fgetc(f) != '\n' && !feof(f))
395 ; /* nothing */
396 }
397 }
398 return -1;
399}