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 /* Linux and OpenBSD have LOGIN_NAME_MAX, FreeBSD MAXLOGNAME. */
25 #ifndef LOGIN_NAME_MAX
26 # if defined(MAXLOGNAME)
27 # define LOGIN_NAME_MAX MAXLOGNAME
28 # elif defined(_POSIX_LOGIN_NAME_MAX)
29 # define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
30 # else
31 # define LOGIN_NAME_MAX 32
32 # endif
33 #endif
35 /* TODO: make these customizable */
36 #define KD_CONF_FILE "/etc/kamid.conf"
37 #define KD_USER "_kamid"
38 #define KD_SOCKET "/var/run/kamid.sock"
40 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
42 enum imsg_type {
43 IMSG_NONE,
44 IMSG_CTL_LOG_VERBOSE,
45 IMSG_CTL_RELOAD,
46 IMSG_CTL_DEBUG,
47 IMSG_CTL_DEBUG_BACK, /* kd_debug_info */
48 IMSG_CTL_DEBUG_END,
49 IMSG_STARTUP,
50 IMSG_RECONF_CONF,
51 IMSG_RECONF_PKI,
52 IMSG_RECONF_PKI_CERT,
53 IMSG_RECONF_PKI_KEY,
54 IMSG_RECONF_LISTEN,
55 IMSG_RECONF_END,
56 IMSG_AUTH, /* kd_auth_proc */
57 IMSG_AUTH_TLS, /* kd_auth_req */
58 IMSG_CONN_GONE,
59 IMSG_BUF,
60 IMSG_BUF_CONT,
61 IMSG_MSIZE,
62 IMSG_CLOSE,
63 };
65 struct kd_options_conf {
66 /* ... */
67 };
69 struct table;
71 #define L_NONE 0x0
72 #define L_TLS 0x1
73 struct kd_listen_conf {
74 STAILQ_ENTRY(kd_listen_conf) entry;
75 uint32_t id;
76 uint32_t flags;
77 int fd;
78 char iface[LINE_MAX];
79 uint16_t port;
81 /* certificate hash => (virtual) user */
82 struct table *auth_table;
84 /* virtual user => local user */
85 struct table *virtual_table;
87 /* (virtual) user => export directory */
88 struct table *userdata_table;
90 char pki[LINE_MAX];
91 struct event ev;
92 struct tls *ctx;
93 };
95 struct kd_pki_conf {
96 STAILQ_ENTRY(kd_pki_conf) entry;
97 char name[LINE_MAX];
98 uint8_t *cert;
99 size_t certlen;
100 uint8_t *key;
101 size_t keylen;
102 struct tls_config *tlsconf;
103 };
105 struct kd_tables_conf {
106 STAILQ_ENTRY(kd_tables_conf) entry;
107 struct table *table;
108 };
110 struct kd_conf {
111 struct kd_options_conf kd_options;
112 STAILQ_HEAD(kd_pki_conf_head, kd_pki_conf) pki_head;
113 STAILQ_HEAD(kd_tables_conf_head, kd_tables_conf) table_head;
114 STAILQ_HEAD(kd_listen_conf_head, kd_listen_conf) listen_head;
115 };
117 struct kd_auth_req {
118 uint32_t listen_id;
119 char hash[128+1];
120 };
122 struct kd_auth_proc {
123 char uname[LOGIN_NAME_MAX];
124 char dir[PATH_MAX];
125 };
127 struct kd_debug_info {
128 uint32_t client_id;
129 uint32_t fid;
130 char path[NAME_MAX];
131 };
133 /* kamid.c */
134 extern int verbose;
135 int main_reload(void);
136 int main_imsg_compose_listener(int, int, uint32_t, const void *, uint16_t);
137 void merge_config(struct kd_conf *, struct kd_conf *);
139 struct kd_conf *config_new_empty(void);
140 void config_clear(struct kd_conf *);
142 /* parse.y */
143 struct kd_conf *parse_config(const char *);
144 int cmdline_symset(char *);
145 void clear_config(struct kd_conf *);
147 #endif