Demonstration release of the principles underpinning krsd.
[krsd] / src / rs-serve.h
1 /*
2  * rs-serve - (c) 2013 Niklas E. Cathor
3  *
4  * This program is distributed in the hope that it will be useful,
5  * but WITHOUT ANY WARRANTY; without even the implied warranty of
6  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7  * GNU Affero General Public License for more details.
8  *
9  * You should have received a copy of the GNU Affero General Public License
10  * along with this program. If not, see <http://www.gnu.org/licenses/>.
11  */
12
13 #ifndef RS_SERVE_H
14 #define RS_SERVE_H
15
16 #define _GNU_SOURCE
17
18 // standard headers
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <errno.h>
25 #include <time.h>
26 #include <unistd.h>
27 #include <dirent.h>
28 #include <fcntl.h>
29 #include <signal.h>
30 #include <getopt.h>
31 #include <libgen.h>
32 #include <pwd.h>
33 #include <grp.h>
34 #include <stdarg.h>
35 #include <search.h>
36 #include <limits.h>
37
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <sys/signalfd.h>
41 #include <sys/stat.h>
42 #include <sys/wait.h>
43 #include <sys/prctl.h>
44 #include <sys/un.h>
45
46 // libevent headers
47 #include <event2/event.h>
48 #include <event2/buffer.h>
49 #include <event2/util.h>
50
51 // libevhtp headers
52 #include <evhtp.h>
53
54 // libmagic headers
55 #include <magic.h>
56
57 // libattr headers
58
59 #include <attr/xattr.h>
60
61 // libssl headers (for SHA1 computation)
62
63 #include <openssl/sha.h>
64
65 // kerberos headers
66 #include <krb5.h>
67 #include <gssapi.h>
68 #include <gssapi/gssapi_krb5.h>
69
70 // rs-serve headers
71
72 #include "version.h"
73 #include "config.h"
74
75 #include "common/log.h"
76 #include "common/user.h"
77 #include "common/auth.h"
78 #include "common/json.h"
79 #include "common/attributes.h"
80
81 #include "handler/auth.h"
82 #include "handler/dispatch.h"
83 #include "handler/storage.h"
84 #include "handler/webfinger.h"
85
86 extern magic_t magic_cookie;
87
88 // users with UIDs that don't pass this test don't exist for rs-serve.
89 #define UID_ALLOWED(uid) ( (uid) >= RS_MIN_UID )
90
91 /* friendly accessors for requests (evhtp_request_t): */
92
93 // get username (string) from storage request path
94 #define REQUEST_GET_USER(req) (req)->uri->path->match_start
95 // get requested file path (i.e. relative path below user's storage_root)
96 // from storage request path.
97 #define REQUEST_GET_PATH(req) (req)->uri->path->match_end
98 // adds a response header. doesn't copy any values, so only works with
99 // static strings
100 #define ADD_RESP_HEADER(req, key, val)                                  \
101   evhtp_headers_add_header(req->headers_out, evhtp_header_new(key, val, 0, 0))
102 // same as ADD_RESP_HEADER, but value is copied (i.e. can be a volatile pointer)
103 #define ADD_RESP_HEADER_CP(req, key, val)                                  \
104   evhtp_headers_add_header(req->headers_out, evhtp_header_new(key, val, 0, 1))
105
106 #endif /* !RS_SERVE_H */