summaryrefslogtreecommitdiff
path: root/hostfile.h
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-01-18 21:40:23 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 00:20:43 +1100
commitc29811cc480a260e42fd88849fc86a80c1e91038 (patch)
treeeeda69798eed42d7eba5a425288684486055f340 /hostfile.h
parentf101d8291da01bbbfd6fb8c569cfd0cc61c0d346 (diff)
upstream commit
introduce hostkeys_foreach() to allow iteration over a known_hosts file or controlled subset thereof. This will allow us to pull out some ugly and duplicated code, and will be used to implement hostkey rotation later. feedback and ok markus
Diffstat (limited to 'hostfile.h')
-rw-r--r--hostfile.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/hostfile.h b/hostfile.h
index d90973f42..24c3813aa 100644
--- a/hostfile.h
+++ b/hostfile.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.h,v 1.21 2015/01/15 09:40:00 djm Exp $ */ 1/* $OpenBSD: hostfile.h,v 1.22 2015/01/18 21:40:24 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -52,4 +52,45 @@ int add_host_to_hostfile(const char *, const char *,
52 52
53char *host_hash(const char *, const char *, u_int); 53char *host_hash(const char *, const char *, u_int);
54 54
55/*
56 * Iterate through a hostkeys file, optionally parsing keys and matching
57 * hostnames. Allows access to the raw keyfile lines to allow
58 * streaming edits to the file to take place.
59 */
60#define HKF_WANT_MATCH_HOST (1) /* return only matching hosts */
61#define HKF_WANT_PARSE_KEY (1<<1) /* need key parsed */
62
63#define HKF_STATUS_OK 1 /* Line parsed, didn't match host */
64#define HKF_STATUS_INVALID 2 /* line had parse error */
65#define HKF_STATUS_COMMENT 3 /* valid line contained no key */
66#define HKF_STATUS_HOST_MATCHED 4 /* hostname matched */
67
68/*
69 * The callback function receives this as an argument for each matching
70 * hostkey line. The callback may "steal" the 'key' field by setting it to NULL.
71 * If a parse error occurred, then "hosts" and subsequent options may be NULL.
72 */
73struct hostkey_foreach_line {
74 const char *path; /* Path of file */
75 u_long linenum; /* Line number */
76 int status; /* One of HKF_STATUS_* */
77 char *line; /* Entire key line; mutable by callback */
78 int marker; /* CA/revocation markers; indicated by MRK_* value */
79 const char *hosts; /* Raw hosts text, may be hashed or list multiple */
80 int was_hashed; /* Non-zero if hostname was hashed */
81 const char *rawkey; /* Text of key and any comment following it */
82 struct sshkey *key; /* Key, if parsed ok and HKF_WANT_MATCH_HOST set */
83 const char *comment; /* Any comment following the key */
84};
85
86/*
87 * Callback fires for each line (or matching line if a HKF_WANT_* option
88 * is set). The foreach loop will terminate if the callback returns a non-
89 * zero exit status.
90 */
91typedef int hostkeys_foreach_fn(struct hostkey_foreach_line *l, void *ctx);
92
93int hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
94 const char *host, u_int options);
95
55#endif 96#endif