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_CTL_DEBUG,
36 IMSG_CTL_DEBUG_BACK, /* kd_debug_info */
37 IMSG_CTL_DEBUG_END,
38 IMSG_STARTUP,
39 IMSG_RECONF_CONF,
40 IMSG_RECONF_PKI,
41 IMSG_RECONF_PKI_CERT,
42 IMSG_RECONF_PKI_KEY,
43 IMSG_RECONF_LISTEN,
44 IMSG_RECONF_END,
45 IMSG_AUTH, /* kd_auth_proc */
46 IMSG_AUTH_TLS, /* kd_auth_req */
47 IMSG_CONN_GONE,
48 IMSG_BUF,
49 IMSG_BUF_CONT,
50 IMSG_MSIZE,
51 IMSG_CLOSE,
52 };
54 struct kd_options_conf {
55 /* ... */
56 };
58 struct table;
60 #define L_NONE 0x0
61 #define L_TLS 0x1
62 struct kd_listen_conf {
63 STAILQ_ENTRY(kd_listen_conf) entry;
64 uint32_t id;
65 uint32_t flags;
66 int fd;
67 char iface[LINE_MAX];
68 uint16_t port;
70 /* certificate hash => (virtual) user */
71 struct table *auth_table;
73 /* virtual user => local user */
74 struct table *virtual_table;
76 /* (virtual) user => export directory */
77 struct table *userdata_table;
79 char pki[LINE_MAX];
80 struct event ev;
81 struct tls *ctx;
82 };
84 struct kd_pki_conf {
85 STAILQ_ENTRY(kd_pki_conf) entry;
86 char name[LINE_MAX];
87 uint8_t *cert;
88 size_t certlen;
89 uint8_t *key;
90 size_t keylen;
91 struct tls_config *tlsconf;
92 };
94 struct kd_tables_conf {
95 STAILQ_ENTRY(kd_tables_conf) entry;
96 struct table *table;
97 };
99 struct kd_conf {
100 struct kd_options_conf kd_options;
101 STAILQ_HEAD(kd_pki_conf_head, kd_pki_conf) pki_head;
102 STAILQ_HEAD(kd_tables_conf_head, kd_tables_conf) table_head;
103 STAILQ_HEAD(kd_listen_conf_head, kd_listen_conf) listen_head;
104 };
106 struct kd_auth_req {
107 uint32_t listen_id;
108 char hash[128+1];
109 };
111 struct kd_auth_proc {
112 char uname[LOGIN_NAME_MAX];
113 char dir[PATH_MAX];
114 };
116 struct kd_debug_info {
117 uint32_t client_id;
118 uint32_t fid;
119 char path[NAME_MAX];
120 };
122 /* kamid.c */
123 extern int verbose;
124 int main_reload(void);
125 int main_imsg_compose_listener(int, int, uint32_t, const void *, uint16_t);
126 void merge_config(struct kd_conf *, struct kd_conf *);
128 struct kd_conf *config_new_empty(void);
129 void config_clear(struct kd_conf *);
131 /* parse.y */
132 struct kd_conf *parse_config(const char *);
133 int cmdline_symset(char *);
134 void clear_config(struct kd_conf *);
136 #endif