2 * Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org>
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.
17 #include "got_compat.h"
33 void (*handler)(int, short, void *);
35 struct privsep_proc *proc;
40 #define IMSG_SIZE_CHECK(imsg, p) do { \
41 if (IMSG_DATA_SIZE(imsg) < sizeof(*p)) \
42 fatalx("bad length imsg received (%s)", #p); \
44 #define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE)
47 TAILQ_ENTRY(ctl_conn) entry;
50 #define CTL_CONN_NOTIFY 0x01
54 TAILQ_HEAD(ctl_connlist, ctl_conn);
55 extern struct ctl_connlist ctl_conns;
63 extern enum privsep_procid privsep_process;
65 #define CONFIG_RELOAD 0x00
66 #define CONFIG_SOCKS 0x01
67 #define CONFIG_ALL 0xff
69 struct privsep_pipes {
70 int *pp_pipes[PROC_MAX];
74 struct privsep_pipes *ps_pipes[PROC_MAX];
75 struct privsep_pipes *ps_pp;
77 struct imsgev *ps_ievs[PROC_MAX];
78 const char *ps_title[PROC_MAX];
79 uint8_t ps_what[PROC_MAX];
84 unsigned int ps_instances[PROC_MAX];
85 unsigned int ps_instance;
87 /* Event and signal handlers */
88 struct event ps_evsigint;
89 struct event ps_evsigterm;
90 struct event ps_evsigchld;
91 struct event ps_evsighup;
92 struct event ps_evsigpipe;
93 struct event ps_evsigusr1;
100 enum privsep_procid p_id;
101 int (*p_cb)(int, struct privsep_proc *,
103 void (*p_init)(struct privsep *,
104 struct privsep_proc *);
105 void (*p_shutdown)(void);
106 const char *p_chroot;
108 struct privsep *p_ps;
112 enum privsep_procid pf_procid;
113 unsigned int pf_instance;
117 #define DPRINTF log_debug
119 #define DPRINTF(x...) do {} while(0)
122 #define PROC_GOTWEBD_SOCK_FILENO 3
123 #define PROC_MAX_INSTANCES 32
126 void proc_init(struct privsep *, struct privsep_proc *, unsigned int,
127 int, char **, enum privsep_procid);
128 void proc_kill(struct privsep *);
129 void proc_connect(struct privsep *ps);
130 void proc_dispatch(int, short event, void *);
131 void proc_range(struct privsep *, enum privsep_procid, int *, int *);
132 void proc_run(struct privsep *, struct privsep_proc *,
133 struct privsep_proc *, unsigned int,
134 void (*)(struct privsep *, struct privsep_proc *, void *), void *);
135 void imsg_event_add(struct imsgev *);
136 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
137 pid_t, int, void *, uint16_t);
138 int imsg_composev_event(struct imsgev *, uint16_t, uint32_t,
139 pid_t, int, const struct iovec *, int);
140 int proc_compose_imsg(struct privsep *, enum privsep_procid, int,
141 uint16_t, uint32_t, int, void *, uint16_t);
142 int proc_compose(struct privsep *, enum privsep_procid,
143 uint16_t, void *data, uint16_t);
144 int proc_composev_imsg(struct privsep *, enum privsep_procid, int,
145 uint16_t, uint32_t, int, const struct iovec *, int);
146 int proc_composev(struct privsep *, enum privsep_procid,
147 uint16_t, const struct iovec *, int);
148 int proc_forward_imsg(struct privsep *, struct imsg *,
149 enum privsep_procid, int);
151 proc_ibuf(struct privsep *, enum privsep_procid, int);
153 proc_iev(struct privsep *, enum privsep_procid, int);
155 proc_getid(struct privsep_proc *, unsigned int, const char *);
156 int proc_flush_imsg(struct privsep *, enum privsep_procid, int);
159 void log_init(int, int);
160 void log_procinit(const char *);
161 void log_setverbose(int);
162 int log_getverbose(void);
163 void log_warn(const char *, ...)
164 __attribute__((__format__ (printf, 1, 2)));
165 void log_warnx(const char *, ...)
166 __attribute__((__format__ (printf, 1, 2)));
167 void log_info(const char *, ...)
168 __attribute__((__format__ (printf, 1, 2)));
169 void log_debug(const char *, ...)
170 __attribute__((__format__ (printf, 1, 2)));
171 void logit(int, const char *, ...)
172 __attribute__((__format__ (printf, 2, 3)));
173 void vlog(int, const char *, va_list)
174 __attribute__((__format__ (printf, 2, 0)));
175 __dead void fatal(const char *, ...)
176 __attribute__((__format__ (printf, 1, 2)));
177 __dead void fatalx(const char *, ...)
178 __attribute__((__format__ (printf, 1, 2)));