[BACK]Return to hostfile.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/hostfile.h, Revision 1.28

1.28    ! djm         1: /* $OpenBSD: hostfile.h,v 1.27 2020/10/04 09:45:01 djm Exp $ */
1.6       niklas      2:
1.3       deraadt     3: /*
1.4       markus      4:  * Author: Tatu Ylonen <ylo@cs.hut.fi>
                      5:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      6:  *                    All rights reserved
1.3       deraadt     7:  *
1.4       markus      8:  * As far as I am concerned, the code I have written for this software
                      9:  * can be used freely for any purpose.  Any derived versions of this
                     10:  * software must be clearly marked as such, and if the derived work is
                     11:  * incompatible with the protocol description in the RFC file, it must be
                     12:  * called by a name other than "ssh" or "Secure Shell".
1.3       deraadt    13:  */
1.1       markus     14: #ifndef HOSTFILE_H
                     15: #define HOSTFILE_H
1.7       itojun     16:
1.1       markus     17: typedef enum {
1.18      djm        18:        HOST_OK, HOST_NEW, HOST_CHANGED, HOST_REVOKED, HOST_FOUND
1.1       markus     19: }       HostStatus;
1.5       markus     20:
1.19      djm        21: typedef enum {
                     22:        MRK_ERROR, MRK_NONE, MRK_REVOKE, MRK_CA
                     23: }      HostkeyMarker;
                     24:
                     25: struct hostkey_entry {
                     26:        char *host;
                     27:        char *file;
                     28:        u_long line;
1.21      djm        29:        struct sshkey *key;
1.19      djm        30:        HostkeyMarker marker;
1.28    ! djm        31:        u_int note; /* caller-specific note/flag */
1.19      djm        32: };
                     33: struct hostkeys;
                     34:
                     35: struct hostkeys *init_hostkeys(void);
1.28    ! djm        36: void    load_hostkeys(struct hostkeys *, const char *,
        !            37:     const char *, u_int);
        !            38: void    load_hostkeys_file(struct hostkeys *, const char *,
        !            39:     const char *, FILE *, u_int note);
1.19      djm        40: void    free_hostkeys(struct hostkeys *);
                     41:
1.21      djm        42: HostStatus check_key_in_hostkeys(struct hostkeys *, struct sshkey *,
1.19      djm        43:     const struct hostkey_entry **);
1.27      djm        44: int     lookup_key_in_hostkeys_by_type(struct hostkeys *, int, int,
1.19      djm        45:     const struct hostkey_entry **);
1.25      djm        46: int     lookup_marker_in_hostkeys(struct hostkeys *, int);
1.19      djm        47:
1.21      djm        48: int     hostfile_read_key(char **, u_int *, struct sshkey *);
                     49: int     add_host_to_hostfile(const char *, const char *,
                     50:     const struct sshkey *, int);
1.23      djm        51:
1.24      djm        52: int     hostfile_replace_entries(const char *filename,
                     53:     const char *host, const char *ip, struct sshkey **keys, size_t nkeys,
                     54:     int store_hash, int quiet, int hash_alg);
1.15      djm        55:
                     56: #define HASH_MAGIC     "|1|"
                     57: #define HASH_DELIM     '|'
1.17      djm        58:
                     59: #define CA_MARKER      "@cert-authority"
1.18      djm        60: #define REVOKE_MARKER  "@revoked"
1.15      djm        61:
                     62: char   *host_hash(const char *, const char *, u_int);
1.22      djm        63:
                     64: /*
                     65:  * Iterate through a hostkeys file, optionally parsing keys and matching
                     66:  * hostnames. Allows access to the raw keyfile lines to allow
                     67:  * streaming edits to the file to take place.
                     68:  */
1.24      djm        69: #define HKF_WANT_MATCH         (1)     /* return only matching hosts/addrs */
1.22      djm        70: #define HKF_WANT_PARSE_KEY     (1<<1)  /* need key parsed */
                     71:
1.24      djm        72: #define HKF_STATUS_OK          0       /* Line parsed, didn't match host */
                     73: #define HKF_STATUS_INVALID     1       /* line had parse error */
                     74: #define HKF_STATUS_COMMENT     2       /* valid line contained no key */
                     75: #define HKF_STATUS_MATCHED     3       /* hostname or IP matched */
                     76:
                     77: #define HKF_MATCH_HOST         (1)     /* hostname matched */
                     78: #define HKF_MATCH_IP           (1<<1)  /* address matched */
                     79: #define HKF_MATCH_HOST_HASHED  (1<<2)  /* hostname was hashed */
                     80: #define HKF_MATCH_IP_HASHED    (1<<3)  /* address was hashed */
                     81: /* XXX HKF_MATCH_KEY_TYPE? */
1.22      djm        82:
                     83: /*
                     84:  * The callback function receives this as an argument for each matching
                     85:  * hostkey line. The callback may "steal" the 'key' field by setting it to NULL.
                     86:  * If a parse error occurred, then "hosts" and subsequent options may be NULL.
                     87:  */
                     88: struct hostkey_foreach_line {
                     89:        const char *path; /* Path of file */
                     90:        u_long linenum; /* Line number */
1.24      djm        91:        u_int status;   /* One of HKF_STATUS_* */
                     92:        u_int match;    /* Zero or more of HKF_MATCH_* OR'd together */
1.22      djm        93:        char *line;     /* Entire key line; mutable by callback */
                     94:        int marker;     /* CA/revocation markers; indicated by MRK_* value */
                     95:        const char *hosts; /* Raw hosts text, may be hashed or list multiple */
                     96:        const char *rawkey; /* Text of key and any comment following it */
1.24      djm        97:        int keytype;    /* Type of key; KEY_UNSPEC for invalid/comment lines */
1.22      djm        98:        struct sshkey *key; /* Key, if parsed ok and HKF_WANT_MATCH_HOST set */
                     99:        const char *comment; /* Any comment following the key */
1.28    ! djm       100:        u_int note;     /* caller-specified note copied from arguments */
1.22      djm       101: };
                    102:
                    103: /*
                    104:  * Callback fires for each line (or matching line if a HKF_WANT_* option
                    105:  * is set). The foreach loop will terminate if the callback returns a non-
                    106:  * zero exit status.
                    107:  */
                    108: typedef int hostkeys_foreach_fn(struct hostkey_foreach_line *l, void *ctx);
                    109:
1.24      djm       110: /* Iterate over a hostkeys file */
1.28    ! djm       111: int hostkeys_foreach(const char *path,
        !           112:     hostkeys_foreach_fn *callback, void *ctx,
        !           113:     const char *host, const char *ip, u_int options, u_int note);
        !           114: int hostkeys_foreach_file(const char *path, FILE *f,
        !           115:     hostkeys_foreach_fn *callback, void *ctx,
        !           116:     const char *host, const char *ip, u_int options, u_int note);
1.26      dtucker   117:
                    118: void hostfile_create_user_ssh_dir(const char *, int);
1.1       markus    119:
                    120: #endif