2020-10-04 09:45:01 +00:00
|
|
|
/* $OpenBSD: hostfile.h,v 1.27 2020/10/04 09:45:01 djm Exp $ */
|
2001-01-29 07:39:26 +00:00
|
|
|
|
2000-09-16 02:29:08 +00:00
|
|
|
/*
|
|
|
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* As far as I am concerned, the code I have written for this software
|
|
|
|
* can be used freely for any purpose. Any derived versions of this
|
|
|
|
* software must be clearly marked as such, and if the derived work is
|
|
|
|
* incompatible with the protocol description in the RFC file, it must be
|
|
|
|
* called by a name other than "ssh" or "Secure Shell".
|
|
|
|
*/
|
2000-03-26 03:04:51 +00:00
|
|
|
#ifndef HOSTFILE_H
|
|
|
|
#define HOSTFILE_H
|
|
|
|
|
|
|
|
typedef enum {
|
2010-03-04 10:53:35 +00:00
|
|
|
HOST_OK, HOST_NEW, HOST_CHANGED, HOST_REVOKED, HOST_FOUND
|
2000-03-26 03:04:51 +00:00
|
|
|
} HostStatus;
|
2000-12-22 01:43:59 +00:00
|
|
|
|
2010-12-01 01:21:51 +00:00
|
|
|
typedef enum {
|
|
|
|
MRK_ERROR, MRK_NONE, MRK_REVOKE, MRK_CA
|
|
|
|
} HostkeyMarker;
|
|
|
|
|
|
|
|
struct hostkey_entry {
|
|
|
|
char *host;
|
|
|
|
char *file;
|
|
|
|
u_long line;
|
2015-01-15 09:40:00 +00:00
|
|
|
struct sshkey *key;
|
2010-12-01 01:21:51 +00:00
|
|
|
HostkeyMarker marker;
|
|
|
|
};
|
|
|
|
struct hostkeys;
|
|
|
|
|
|
|
|
struct hostkeys *init_hostkeys(void);
|
|
|
|
void load_hostkeys(struct hostkeys *, const char *, const char *);
|
|
|
|
void free_hostkeys(struct hostkeys *);
|
|
|
|
|
2015-01-15 09:40:00 +00:00
|
|
|
HostStatus check_key_in_hostkeys(struct hostkeys *, struct sshkey *,
|
2010-12-01 01:21:51 +00:00
|
|
|
const struct hostkey_entry **);
|
2020-10-04 09:45:01 +00:00
|
|
|
int lookup_key_in_hostkeys_by_type(struct hostkeys *, int, int,
|
2010-12-01 01:21:51 +00:00
|
|
|
const struct hostkey_entry **);
|
2020-05-13 09:52:41 +00:00
|
|
|
int lookup_marker_in_hostkeys(struct hostkeys *, int);
|
2010-12-01 01:21:51 +00:00
|
|
|
|
2015-01-15 09:40:00 +00:00
|
|
|
int hostfile_read_key(char **, u_int *, struct sshkey *);
|
|
|
|
int add_host_to_hostfile(const char *, const char *,
|
|
|
|
const struct sshkey *, int);
|
2000-03-26 03:04:51 +00:00
|
|
|
|
2015-02-16 22:08:57 +00:00
|
|
|
int hostfile_replace_entries(const char *filename,
|
|
|
|
const char *host, const char *ip, struct sshkey **keys, size_t nkeys,
|
|
|
|
int store_hash, int quiet, int hash_alg);
|
2015-01-26 03:04:45 +00:00
|
|
|
|
2005-03-01 10:47:37 +00:00
|
|
|
#define HASH_MAGIC "|1|"
|
|
|
|
#define HASH_DELIM '|'
|
|
|
|
|
2010-02-26 20:55:05 +00:00
|
|
|
#define CA_MARKER "@cert-authority"
|
2010-03-04 10:53:35 +00:00
|
|
|
#define REVOKE_MARKER "@revoked"
|
2010-02-26 20:55:05 +00:00
|
|
|
|
2005-03-01 10:47:37 +00:00
|
|
|
char *host_hash(const char *, const char *, u_int);
|
|
|
|
|
2015-01-18 21:40:23 +00:00
|
|
|
/*
|
|
|
|
* Iterate through a hostkeys file, optionally parsing keys and matching
|
|
|
|
* hostnames. Allows access to the raw keyfile lines to allow
|
|
|
|
* streaming edits to the file to take place.
|
|
|
|
*/
|
2015-02-16 22:08:57 +00:00
|
|
|
#define HKF_WANT_MATCH (1) /* return only matching hosts/addrs */
|
2015-01-18 21:40:23 +00:00
|
|
|
#define HKF_WANT_PARSE_KEY (1<<1) /* need key parsed */
|
|
|
|
|
2015-02-16 22:08:57 +00:00
|
|
|
#define HKF_STATUS_OK 0 /* Line parsed, didn't match host */
|
|
|
|
#define HKF_STATUS_INVALID 1 /* line had parse error */
|
|
|
|
#define HKF_STATUS_COMMENT 2 /* valid line contained no key */
|
|
|
|
#define HKF_STATUS_MATCHED 3 /* hostname or IP matched */
|
|
|
|
|
|
|
|
#define HKF_MATCH_HOST (1) /* hostname matched */
|
|
|
|
#define HKF_MATCH_IP (1<<1) /* address matched */
|
|
|
|
#define HKF_MATCH_HOST_HASHED (1<<2) /* hostname was hashed */
|
|
|
|
#define HKF_MATCH_IP_HASHED (1<<3) /* address was hashed */
|
|
|
|
/* XXX HKF_MATCH_KEY_TYPE? */
|
2015-01-18 21:40:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The callback function receives this as an argument for each matching
|
|
|
|
* hostkey line. The callback may "steal" the 'key' field by setting it to NULL.
|
|
|
|
* If a parse error occurred, then "hosts" and subsequent options may be NULL.
|
|
|
|
*/
|
|
|
|
struct hostkey_foreach_line {
|
|
|
|
const char *path; /* Path of file */
|
|
|
|
u_long linenum; /* Line number */
|
2015-02-16 22:08:57 +00:00
|
|
|
u_int status; /* One of HKF_STATUS_* */
|
|
|
|
u_int match; /* Zero or more of HKF_MATCH_* OR'd together */
|
2015-01-18 21:40:23 +00:00
|
|
|
char *line; /* Entire key line; mutable by callback */
|
|
|
|
int marker; /* CA/revocation markers; indicated by MRK_* value */
|
|
|
|
const char *hosts; /* Raw hosts text, may be hashed or list multiple */
|
|
|
|
const char *rawkey; /* Text of key and any comment following it */
|
2015-02-16 22:08:57 +00:00
|
|
|
int keytype; /* Type of key; KEY_UNSPEC for invalid/comment lines */
|
2015-01-18 21:40:23 +00:00
|
|
|
struct sshkey *key; /* Key, if parsed ok and HKF_WANT_MATCH_HOST set */
|
|
|
|
const char *comment; /* Any comment following the key */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback fires for each line (or matching line if a HKF_WANT_* option
|
|
|
|
* is set). The foreach loop will terminate if the callback returns a non-
|
|
|
|
* zero exit status.
|
|
|
|
*/
|
|
|
|
typedef int hostkeys_foreach_fn(struct hostkey_foreach_line *l, void *ctx);
|
|
|
|
|
2015-02-16 22:08:57 +00:00
|
|
|
/* Iterate over a hostkeys file */
|
2015-01-18 21:40:23 +00:00
|
|
|
int hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx,
|
2015-02-16 22:08:57 +00:00
|
|
|
const char *host, const char *ip, u_int options);
|
2015-01-18 21:40:23 +00:00
|
|
|
|
2020-06-26 05:02:03 +00:00
|
|
|
void hostfile_create_user_ssh_dir(const char *, int);
|
|
|
|
|
2000-03-26 03:04:51 +00:00
|
|
|
#endif
|