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 <limits.h>
21 #include <stdint.h>
22 #include <tls.h>
24 /* TODO: make these customizable */
25 #define KD_CONF_FILE "/etc/kamid.conf"
26 #define KD_USER "_kamid"
27 #define KD_SOCKET "/var/run/kamid.sock"
29 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
31 enum imsg_type {
32 IMSG_NONE,
33 IMSG_CTL_LOG_VERBOSE,
34 IMSG_CTL_RELOAD,
35 IMSG_CONTROLFD,
36 IMSG_STARTUP,
37 IMSG_RECONF_CONF,
38 IMSG_RECONF_PKI,
39 IMSG_RECONF_PKI_CERT,
40 IMSG_RECONF_PKI_KEY,
41 IMSG_RECONF_LISTEN,
42 IMSG_RECONF_END,
43 IMSG_AUTH,
44 IMSG_AUTH_DIR,
45 IMSG_AUTH_TLS,
46 IMSG_CONN_GONE,
47 IMSG_BUF,
48 IMSG_MSIZE,
49 IMSG_CLOSE,
50 };
52 struct kd_options_conf {
53 /* ... */
54 };
56 enum table_type {
57 T_NONE = 0,
58 T_HASH = 0x01,
59 };
61 struct table {
62 char t_name[LINE_MAX];
63 enum table_type t_type;
64 char t_path[PATH_MAX];
65 void *t_handle;
66 struct table_backend *t_backend;
67 };
69 struct table_backend {
70 const char *name;
71 int (*open)(struct table *);
72 int (*add)(struct table *, const char *, const char *);
73 int (*lookup)(struct table *, const char *, char **);
74 void (*close)(struct table *);
75 };
77 /* table_static.c */
78 extern struct table_backend table_static;
80 #define L_NONE 0x0
81 #define L_TLS 0x1
82 struct kd_listen_conf {
83 STAILQ_ENTRY(kd_listen_conf) entry;
84 uint32_t id;
85 uint32_t flags;
86 int fd;
87 char iface[LINE_MAX];
88 uint16_t port;
90 /* certificate hash => (virtual) user */
91 struct table *auth_table;
93 /* virtual user => local user */
94 struct table *virtual_table;
96 /* (virtual) user => export directory */
97 struct table *userdata_table;
99 char pki[LINE_MAX];
100 struct event ev;
101 struct tls *ctx;
102 };
104 struct kd_pki_conf {
105 STAILQ_ENTRY(kd_pki_conf) entry;
106 char name[LINE_MAX];
107 uint8_t *cert;
108 size_t certlen;
109 uint8_t *key;
110 size_t keylen;
111 struct tls_config *tlsconf;
112 };
114 struct kd_tables_conf {
115 STAILQ_ENTRY(kd_tables_conf) entry;
116 struct table *table;
117 };
119 struct kd_conf {
120 struct kd_options_conf kd_options;
121 STAILQ_HEAD(kd_pki_conf_head, kd_pki_conf) pki_head;
122 STAILQ_HEAD(kd_tables_conf_head, kd_tables_conf) table_head;
123 STAILQ_HEAD(kd_listen_conf_head, kd_listen_conf) listen_head;
124 };
126 struct kd_auth_req {
127 uint32_t listen_id;
128 char hash[128+1];
129 };
131 /* kamid.c */
132 extern int verbose;
133 int main_imsg_compose_listener(int, int, uint32_t, const void *, uint16_t);
134 void merge_config(struct kd_conf *, struct kd_conf *);
136 struct kd_conf *config_new_empty(void);
137 void config_clear(struct kd_conf *);
139 /* parse.y */
140 struct kd_conf *parse_config(const char *);
141 int cmdline_symset(char *);
143 #endif