2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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.
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.
26 /* TODO: make these customizable */
27 #define KD_CONF_FILE "/etc/kamid.conf"
28 #define KD_USER "_kamid"
29 #define KD_SOCKET "/var/run/kamid.sock"
31 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE)
33 #define MIN(a, b) ((a) < (b) ? (a) : (b))
37 void (*handler)(int, short, void *);
63 struct kd_options_conf {
73 char t_name[LINE_MAX];
74 enum table_type t_type;
75 char t_path[PATH_MAX];
77 struct table_backend *t_backend;
80 struct table_backend {
82 int (*open)(struct table *);
83 int (*add)(struct table *, const char *, const char *);
84 int (*lookup)(struct table *, const char *, char **);
85 void (*close)(struct table *);
89 extern struct table_backend table_static;
93 struct kd_listen_conf {
94 STAILQ_ENTRY(kd_listen_conf) entry;
101 /* certificate hash => (virtual) user */
102 struct table *auth_table;
104 /* virtual user => local user */
105 struct table *virtual_table;
107 /* (virtual) user => export directory */
108 struct table *userdata_table;
116 STAILQ_ENTRY(kd_pki_conf) entry;
122 struct tls_config *tlsconf;
125 struct kd_tables_conf {
126 STAILQ_ENTRY(kd_tables_conf) entry;
131 struct kd_options_conf kd_options;
132 STAILQ_HEAD(kd_pki_conf_head, kd_pki_conf) pki_head;
133 STAILQ_HEAD(kd_tables_conf_head, kd_tables_conf) table_head;
134 STAILQ_HEAD(kd_listen_conf_head, kd_listen_conf) listen_head;
145 * The message itself is len bytes long (counting the whole header
148 struct np_msg_header {
154 /* useful constants */
155 #define HEADERSIZE (4 + 1 + 2)
156 #define VERSION9P "9P2000"
157 #define MSIZE9P ((uint32_t)4*1024*1024)
158 #define NOTAG ((uint16_t)~0U)
159 #define NOFID ((uint32_t)~0U)
164 #define NPSTATSIZ(namlen, uidnam, gidnam, unam) \
165 (6 + QIDSIZE + 20 + 2 + namlen + 2 + uidnam + 2 + gidnam + 2 + unam)
167 /* bits in Qid.type */
168 #define QTDIR 0x80 /* type bit for directories */
169 #define QTAPPEND 0x40 /* type bit for append only files */
170 #define QTEXCL 0x20 /* type bit for exclusive use files */
171 #define QTMOUNT 0x10 /* type bit for mounted channel */
172 #define QTAUTH 0x08 /* type bit for authentication file */
173 #define QTTMP 0x04 /* type bit for non-backed-up file */
174 #define QTSYMLINK 0x02 /* type bit for symbolic link */
175 #define QTFILE 0x00 /* type bits for plain file */
177 /* Topen mode/flags */
183 #define KORCLOSE 0x40
185 /* 9p message types */
187 Treaddir = 40, /* .L */
196 Terror = 106, /* illegal */
221 * plan9ports' include/fcall.h also has a
226 * which it's not mentioned in the 9p "rfc" over at
227 * 9p.cat-v.org. Ignoring that for now.
233 int main_imsg_compose_listener(int, int, uint32_t, const void *, uint16_t);
234 void merge_config(struct kd_conf *, struct kd_conf *);
236 struct kd_conf *config_new_empty(void);
237 void config_clear(struct kd_conf *);
240 struct kd_conf *parse_config(const char *);
241 int cmdline_symset(char *);