1 | /* |
---|
2 | * Internal support functions for the remctld daemon. |
---|
3 | * |
---|
4 | * Written by Russ Allbery <rra@stanford.edu> |
---|
5 | * Copyright 2006, 2007, 2008, 2009 |
---|
6 | * Board of Trustees, Leland Stanford Jr. University |
---|
7 | * |
---|
8 | * See LICENSE for licensing terms. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef SERVER_INTERNAL_H |
---|
12 | #define SERVER_INTERNAL_H 1 |
---|
13 | |
---|
14 | #include <config.h> |
---|
15 | #include <portable/gssapi.h> |
---|
16 | #include <portable/macros.h> |
---|
17 | #include <portable/stdbool.h> |
---|
18 | |
---|
19 | #include <util/util.h> |
---|
20 | |
---|
21 | /* Forward declarations to avoid extra includes. */ |
---|
22 | struct iovec; |
---|
23 | |
---|
24 | /* |
---|
25 | * Used as the default max buffer for the argv passed into the server, and for |
---|
26 | * the return message from the server. |
---|
27 | */ |
---|
28 | #define MAXBUFFER 64000 |
---|
29 | |
---|
30 | /* |
---|
31 | * The maximum size of argc passed to the server. This is an arbitrary limit |
---|
32 | * to protect against memory-based denial of service attacks on the server. |
---|
33 | */ |
---|
34 | #define MAXCMDARGS (4 * 1024) |
---|
35 | |
---|
36 | BEGIN_DECLS |
---|
37 | |
---|
38 | /* Holds the information about a client connection. */ |
---|
39 | struct client { |
---|
40 | int fd; /* File descriptor of client connection. */ |
---|
41 | char *hostname; /* Hostname of client (if available). */ |
---|
42 | char *ipaddress; /* IP address of client as a string. */ |
---|
43 | int protocol; /* Protocol version number. */ |
---|
44 | gss_ctx_id_t context; /* GSS-API context. */ |
---|
45 | char *user; /* Name of the client as a string. */ |
---|
46 | OM_uint32 flags; /* Connection flags. */ |
---|
47 | bool keepalive; /* Whether keep-alive was set. */ |
---|
48 | char *output; /* Stores output to send to the client. */ |
---|
49 | size_t outlen; /* Length of output to send to client. */ |
---|
50 | bool fatal; /* Whether a fatal error has occurred. */ |
---|
51 | }; |
---|
52 | |
---|
53 | /* Holds the configuration for a single command. */ |
---|
54 | struct confline { |
---|
55 | char *file; /* Config file name. */ |
---|
56 | int lineno; /* Config file line number. */ |
---|
57 | struct vector *line; /* The split configuration line. */ |
---|
58 | char *command; /* Command (first argument). */ |
---|
59 | char *subcommand; /* Subcommand (second argument). */ |
---|
60 | char *program; /* Full file name of executable. */ |
---|
61 | unsigned int *logmask; /* Zero-terminated list of args to mask. */ |
---|
62 | long stdin_arg; /* Arg to pass on stdin, -1 for last. */ |
---|
63 | char **acls; /* Full file names of ACL files. */ |
---|
64 | }; |
---|
65 | |
---|
66 | /* Holds the complete parsed configuration for remctld. */ |
---|
67 | struct config { |
---|
68 | struct confline **rules; |
---|
69 | size_t count; |
---|
70 | size_t allocated; |
---|
71 | }; |
---|
72 | |
---|
73 | /* Logging functions. */ |
---|
74 | void warn_gssapi(const char *, OM_uint32 major, OM_uint32 minor); |
---|
75 | void warn_token(const char *, int status, OM_uint32 major, OM_uint32 minor); |
---|
76 | void server_log_command(struct iovec **, struct confline *, const char *user); |
---|
77 | |
---|
78 | /* Configuration file functions. */ |
---|
79 | struct config *server_config_load(const char *file); |
---|
80 | void server_config_free(struct config *); |
---|
81 | bool server_config_acl_permit(struct confline *, const char *user); |
---|
82 | void server_config_set_gput_file(char *file); |
---|
83 | |
---|
84 | /* Running commands. */ |
---|
85 | void server_run_command(struct client *, struct config *, struct iovec **); |
---|
86 | |
---|
87 | /* Freeing the command structure. */ |
---|
88 | void server_free_command(struct iovec **); |
---|
89 | |
---|
90 | /* Generic protocol functions. */ |
---|
91 | struct client *server_new_client(int fd, gss_cred_id_t creds); |
---|
92 | void server_free_client(struct client *); |
---|
93 | struct iovec **server_parse_command(struct client *, const char *, size_t); |
---|
94 | bool server_send_error(struct client *, enum error_codes, const char *); |
---|
95 | |
---|
96 | /* Protocol v1 functions. */ |
---|
97 | bool server_v1_send_output(struct client *, int status); |
---|
98 | void server_v1_handle_commands(struct client *, struct config *); |
---|
99 | |
---|
100 | /* Protocol v2 functions. */ |
---|
101 | bool server_v2_send_output(struct client *, int stream); |
---|
102 | bool server_v2_send_status(struct client *, int); |
---|
103 | bool server_v2_send_error(struct client *, enum error_codes, const char *); |
---|
104 | void server_v2_handle_commands(struct client *, struct config *); |
---|
105 | |
---|
106 | END_DECLS |
---|
107 | |
---|
108 | #endif /* !SERVER_INTERNAL_H */ |
---|