Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef KAMID_H
18 #define KAMID_H
20 #include "compat.h"
22 #include <event.h>
23 #include <limits.h>
24 #include <stdint.h>
25 #include <tls.h>
27 /* TODO: make these customizable */
28 #define KD_CONF_FILE "/etc/kamid.conf"
29 #define KD_USER "_kamid"
30 #define KD_SOCKET "/var/run/kamid.sock"
32 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
34 struct imsgev {
35 struct imsgbuf ibuf;
36 void (*handler)(int, short, void *);
37 struct event ev;
38 short events;
39 };
41 enum imsg_type {
42 IMSG_NONE,
43 IMSG_CTL_LOG_VERBOSE,
44 IMSG_CTL_RELOAD,
45 IMSG_CONTROLFD,
46 IMSG_STARTUP,
47 IMSG_RECONF_CONF,
48 IMSG_RECONF_PKI,
49 IMSG_RECONF_PKI_CERT,
50 IMSG_RECONF_PKI_KEY,
51 IMSG_RECONF_LISTEN,
52 IMSG_RECONF_END,
53 IMSG_AUTH,
54 IMSG_AUTH_DIR,
55 IMSG_AUTH_TLS,
56 IMSG_CONN_GONE,
57 IMSG_BUF,
58 };
60 struct kd_options_conf {
61 /* ... */
62 };
64 enum table_type {
65 T_NONE = 0,
66 T_HASH = 0x01,
67 };
69 struct table {
70 char t_name[LINE_MAX];
71 enum table_type t_type;
72 char t_path[PATH_MAX];
73 void *t_handle;
74 struct table_backend *t_backend;
75 };
77 struct table_backend {
78 const char *name;
79 int (*open)(struct table *);
80 int (*add)(struct table *, const char *, const char *);
81 int (*lookup)(struct table *, const char *, char **);
82 void (*close)(struct table *);
83 };
85 /* table_static.c */
86 extern struct table_backend table_static;
88 struct kd_listen_conf {
89 SIMPLEQ_ENTRY(kd_listen_conf) entry;
90 uint32_t id;
91 int fd;
92 char iface[LINE_MAX];
93 uint16_t port;
94 struct table *auth_table;
95 char pki[LINE_MAX];
96 struct event ev;
97 struct tls *ctx;
98 };
100 struct kd_pki_conf {
101 SIMPLEQ_ENTRY(kd_pki_conf) entry;
102 char name[LINE_MAX];
103 uint8_t *cert;
104 size_t certlen;
105 uint8_t *key;
106 size_t keylen;
107 struct tls_config *tlsconf;
108 };
110 struct kd_tables_conf {
111 SIMPLEQ_ENTRY(kd_tables_conf) entry;
112 struct table *table;
113 };
115 struct kd_conf {
116 struct kd_options_conf kd_options;
117 SIMPLEQ_HEAD(kd_pki_conf_head, kd_pki_conf) pki_head;
118 SIMPLEQ_HEAD(kd_tables_conf_head, kd_tables_conf) table_head;
119 SIMPLEQ_HEAD(kd_listen_conf_head, kd_listen_conf) listen_head;
120 };
122 /* kamid.c */
123 extern int verbose;
124 int main_imsg_compose_listener(int, int, uint32_t, const void *, uint16_t);
125 void merge_config(struct kd_conf *, struct kd_conf *);
126 void imsg_event_add(struct imsgev *);
127 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
128 int, const void *, uint16_t);
130 struct kd_conf *config_new_empty(void);
131 void config_clear(struct kd_conf *);
133 /* parse.y */
134 struct kd_conf *parse_config(const char *);
135 int cmdline_symset(char *);
137 #endif