xref: /openbsd/usr.bin/ssh/servconf.h (revision cd187d0b)
1 /* $OpenBSD: servconf.h,v 1.165 2024/06/12 22:36:00 djm Exp $ */
2 
3 /*
4  * Author: Tatu Ylonen <ylo@cs.hut.fi>
5  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6  *                    All rights reserved
7  * Definitions for server configuration data and for the functions reading it.
8  *
9  * As far as I am concerned, the code I have written for this software
10  * can be used freely for any purpose.  Any derived versions of this
11  * software must be clearly marked as such, and if the derived work is
12  * incompatible with the protocol description in the RFC file, it must be
13  * called by a name other than "ssh" or "Secure Shell".
14  */
15 
16 #ifndef SERVCONF_H
17 #define SERVCONF_H
18 
19 #include <sys/queue.h>
20 
21 #define MAX_PORTS		256	/* Max # ports. */
22 
23 /* permit_root_login */
24 #define	PERMIT_NOT_SET		-1
25 #define	PERMIT_NO		0
26 #define	PERMIT_FORCED_ONLY	1
27 #define	PERMIT_NO_PASSWD	2
28 #define	PERMIT_YES		3
29 
30 /* PermitOpen */
31 #define PERMITOPEN_ANY		0
32 #define PERMITOPEN_NONE		-2
33 
34 /* IgnoreRhosts */
35 #define IGNORE_RHOSTS_NO	0
36 #define IGNORE_RHOSTS_YES	1
37 #define IGNORE_RHOSTS_SHOSTS	2
38 
39 #define DEFAULT_AUTH_FAIL_MAX	6	/* Default for MaxAuthTries */
40 #define DEFAULT_SESSIONS_MAX	10	/* Default for MaxSessions */
41 
42 /* Magic name for internal sftp-server */
43 #define INTERNAL_SFTP_NAME	"internal-sftp"
44 
45 /* PubkeyAuthOptions flags */
46 #define PUBKEYAUTH_TOUCH_REQUIRED	(1)
47 #define PUBKEYAUTH_VERIFY_REQUIRED	(1<<1)
48 
49 struct ssh;
50 
51 /*
52  * Used to store addresses from ListenAddr directives. These may be
53  * incomplete, as they may specify addresses that need to be merged
54  * with any ports requested by ListenPort.
55  */
56 struct queued_listenaddr {
57 	char *addr;
58 	int port; /* <=0 if unspecified */
59 	char *rdomain;
60 };
61 
62 /* Resolved listen addresses, grouped by optional routing domain */
63 struct listenaddr {
64 	char *rdomain;
65 	struct addrinfo *addrs;
66 };
67 
68 #define PER_SOURCE_PENALTY_OVERFLOW_DENY_ALL	1
69 #define PER_SOURCE_PENALTY_OVERFLOW_PERMISSIVE	2
70 struct per_source_penalty {
71 	int	enabled;
72 	int	max_sources4;
73 	int	max_sources6;
74 	int	overflow_mode;
75 	int	overflow_mode6;
76 	int	penalty_crash;
77 	int	penalty_grace;
78 	int	penalty_authfail;
79 	int	penalty_noauth;
80 	int	penalty_max;
81 	int	penalty_min;
82 };
83 
84 typedef struct {
85 	u_int	num_ports;
86 	u_int	ports_from_cmdline;
87 	int	ports[MAX_PORTS];	/* Port number to listen on. */
88 	struct queued_listenaddr *queued_listen_addrs;
89 	u_int	num_queued_listens;
90 	struct listenaddr *listen_addrs;
91 	u_int	num_listen_addrs;
92 	int	address_family;		/* Address family used by the server. */
93 
94 	char	*routing_domain;	/* Bind session to routing domain */
95 
96 	char   **host_key_files;	/* Files containing host keys. */
97 	int	*host_key_file_userprovided; /* Key was specified by user. */
98 	u_int	num_host_key_files;     /* Number of files for host keys. */
99 	char   **host_cert_files;	/* Files containing host certs. */
100 	u_int	num_host_cert_files;	/* Number of files for host certs. */
101 
102 	char   *host_key_agent;		/* ssh-agent socket for host keys. */
103 	char   *pid_file;		/* Where to put our pid */
104 	char   *moduli_file;		/* moduli file for DH-GEX */
105 	int     login_grace_time;	/* Disconnect if no auth in this time
106 					 * (sec). */
107 	int     permit_root_login;	/* PERMIT_*, see above */
108 	int     ignore_rhosts;	/* Ignore .rhosts and .shosts. */
109 	int     ignore_user_known_hosts;	/* Ignore ~/.ssh/known_hosts
110 						 * for RhostsRsaAuth */
111 	int     print_motd;	/* If true, print /etc/motd. */
112 	int	print_lastlog;	/* If true, print lastlog */
113 	int     x11_forwarding;	/* If true, permit inet (spoofing) X11 fwd. */
114 	int     x11_display_offset;	/* What DISPLAY number to start
115 					 * searching at */
116 	int     x11_use_localhost;	/* If true, use localhost for fake X11 server. */
117 	char   *xauth_location;	/* Location of xauth program */
118 	int	permit_tty;	/* If false, deny pty allocation */
119 	int	permit_user_rc;	/* If false, deny ~/.ssh/rc execution */
120 	int     strict_modes;	/* If true, require string home dir modes. */
121 	int     tcp_keep_alive;	/* If true, set SO_KEEPALIVE. */
122 	int	ip_qos_interactive;	/* IP ToS/DSCP/class for interactive */
123 	int	ip_qos_bulk;		/* IP ToS/DSCP/class for bulk traffic */
124 	char   *ciphers;	/* Supported SSH2 ciphers. */
125 	char   *macs;		/* Supported SSH2 macs. */
126 	char   *kex_algorithms;	/* SSH2 kex methods in order of preference. */
127 	struct ForwardOptions fwd_opts;	/* forwarding options */
128 	SyslogFacility log_facility;	/* Facility for system logging. */
129 	LogLevel log_level;	/* Level for system logging. */
130 	u_int	num_log_verbose;	/* Verbose log overrides */
131 	char	**log_verbose;
132 	int     hostbased_authentication;	/* If true, permit ssh2 hostbased auth */
133 	int     hostbased_uses_name_from_packet_only; /* experimental */
134 	char   *hostbased_accepted_algos; /* Algos allowed for hostbased */
135 	char   *hostkeyalgorithms;	/* SSH2 server key types */
136 	char   *ca_sign_algorithms;	/* Allowed CA signature algorithms */
137 	int     pubkey_authentication;	/* If true, permit ssh2 pubkey authentication. */
138 	char   *pubkey_accepted_algos;	/* Signature algos allowed for pubkey */
139 	int	pubkey_auth_options;	/* -1 or mask of PUBKEYAUTH_* flags */
140 	int     kerberos_authentication;	/* If true, permit Kerberos
141 						 * authentication. */
142 	int     kerberos_or_local_passwd;	/* If true, permit kerberos
143 						 * and any other password
144 						 * authentication mechanism,
145 						 * such as SecurID or
146 						 * /etc/passwd */
147 	int     kerberos_ticket_cleanup;	/* If true, destroy ticket
148 						 * file on logout. */
149 	int     kerberos_get_afs_token;		/* If true, try to get AFS token if
150 						 * authenticated with Kerberos. */
151 	int     gss_authentication;	/* If true, permit GSSAPI authentication */
152 	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
153 	int     gss_strict_acceptor;	/* If true, restrict the GSSAPI acceptor name */
154 	int     password_authentication;	/* If true, permit password
155 						 * authentication. */
156 	int     kbd_interactive_authentication;	/* If true, permit */
157 	int     permit_empty_passwd;	/* If false, do not permit empty
158 					 * passwords. */
159 	int     permit_user_env;	/* If true, read ~/.ssh/environment */
160 	char   *permit_user_env_allowlist; /* pattern-list of allowed env names */
161 	int     compression;	/* If true, compression is allowed */
162 	int	allow_tcp_forwarding; /* One of FORWARD_* */
163 	int	allow_streamlocal_forwarding; /* One of FORWARD_* */
164 	int	allow_agent_forwarding;
165 	int	disable_forwarding;
166 	u_int num_allow_users;
167 	char   **allow_users;
168 	u_int num_deny_users;
169 	char   **deny_users;
170 	u_int num_allow_groups;
171 	char   **allow_groups;
172 	u_int num_deny_groups;
173 	char   **deny_groups;
174 
175 	u_int num_subsystems;
176 	char   **subsystem_name;
177 	char   **subsystem_command;
178 	char   **subsystem_args;
179 
180 	u_int num_accept_env;
181 	char   **accept_env;
182 	u_int num_setenv;
183 	char   **setenv;
184 
185 	int	max_startups_begin;
186 	int	max_startups_rate;
187 	int	max_startups;
188 	int	per_source_max_startups;
189 	int	per_source_masklen_ipv4;
190 	int	per_source_masklen_ipv6;
191 	char	*per_source_penalty_exempt;
192 	struct per_source_penalty per_source_penalty;
193 	int	max_authtries;
194 	int	max_sessions;
195 	char   *banner;			/* SSH-2 banner message */
196 	int	use_dns;
197 	int	client_alive_interval;	/*
198 					 * poke the client this often to
199 					 * see if it's still there
200 					 */
201 	int	client_alive_count_max;	/*
202 					 * If the client is unresponsive
203 					 * for this many intervals above,
204 					 * disconnect the session
205 					 */
206 
207 	u_int	num_authkeys_files;	/* Files containing public keys */
208 	char   **authorized_keys_files;
209 
210 	char   *adm_forced_command;
211 
212 	int	permit_tun;
213 
214 	char   **permitted_opens;	/* May also be one of PERMITOPEN_* */
215 	u_int   num_permitted_opens;
216 	char   **permitted_listens; /* May also be one of PERMITOPEN_* */
217 	u_int   num_permitted_listens;
218 
219 	char   *chroot_directory;
220 	char   *revoked_keys_file;
221 	char   *trusted_user_ca_keys;
222 	char   *authorized_keys_command;
223 	char   *authorized_keys_command_user;
224 	char   *authorized_principals_file;
225 	char   *authorized_principals_command;
226 	char   *authorized_principals_command_user;
227 
228 	int64_t rekey_limit;
229 	int	rekey_interval;
230 
231 	char   *version_addendum;	/* Appended to SSH banner */
232 
233 	u_int	num_auth_methods;
234 	char   **auth_methods;
235 
236 	int	fingerprint_hash;
237 	int	expose_userauth_info;
238 	u_int64_t timing_secret;
239 	char   *sk_provider;
240 	int	required_rsa_size;	/* minimum size of RSA keys */
241 
242 	char	**channel_timeouts;	/* inactivity timeout by channel type */
243 	u_int	num_channel_timeouts;
244 
245 	int	unused_connection_timeout;
246 
247 	char   *sshd_session_path;
248 }       ServerOptions;
249 
250 /* Information about the incoming connection as used by Match */
251 struct connection_info {
252 	const char *user;
253 	const char *host;	/* possibly resolved hostname */
254 	const char *address;	/* remote address */
255 	const char *laddress;	/* local address */
256 	int lport;		/* local port */
257 	const char *rdomain;	/* routing domain if available */
258 	int test;		/* test mode, allow some attributes to be
259 				 * unspecified */
260 };
261 
262 /* List of included files for re-exec from the parsed configuration */
263 struct include_item {
264 	char *selector;
265 	char *filename;
266 	struct sshbuf *contents;
267 	TAILQ_ENTRY(include_item) entry;
268 };
269 TAILQ_HEAD(include_list, include_item);
270 
271 
272 /*
273  * These are string config options that must be copied between the
274  * Match sub-config and the main config, and must be sent from the
275  * privsep child to the privsep master. We use a macro to ensure all
276  * the options are copied and the copies are done in the correct order.
277  *
278  * NB. an option must appear in servconf.c:copy_set_server_options() or
279  * COPY_MATCH_STRING_OPTS here but never both.
280  */
281 #define COPY_MATCH_STRING_OPTS() do { \
282 		M_CP_STROPT(banner); \
283 		M_CP_STROPT(trusted_user_ca_keys); \
284 		M_CP_STROPT(revoked_keys_file); \
285 		M_CP_STROPT(authorized_keys_command); \
286 		M_CP_STROPT(authorized_keys_command_user); \
287 		M_CP_STROPT(authorized_principals_file); \
288 		M_CP_STROPT(authorized_principals_command); \
289 		M_CP_STROPT(authorized_principals_command_user); \
290 		M_CP_STROPT(hostbased_accepted_algos); \
291 		M_CP_STROPT(pubkey_accepted_algos); \
292 		M_CP_STROPT(ca_sign_algorithms); \
293 		M_CP_STROPT(routing_domain); \
294 		M_CP_STROPT(permit_user_env_allowlist); \
295 		M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \
296 		M_CP_STRARRAYOPT(allow_users, num_allow_users); \
297 		M_CP_STRARRAYOPT(deny_users, num_deny_users); \
298 		M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \
299 		M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \
300 		M_CP_STRARRAYOPT(accept_env, num_accept_env); \
301 		M_CP_STRARRAYOPT(setenv, num_setenv); \
302 		M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \
303 		M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens); \
304 		M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens); \
305 		M_CP_STRARRAYOPT(channel_timeouts, num_channel_timeouts); \
306 		M_CP_STRARRAYOPT(log_verbose, num_log_verbose); \
307 		M_CP_STRARRAYOPT(subsystem_name, num_subsystems); \
308 		M_CP_STRARRAYOPT(subsystem_command, num_subsystems); \
309 		M_CP_STRARRAYOPT(subsystem_args, num_subsystems); \
310 	} while (0)
311 
312 void	 initialize_server_options(ServerOptions *);
313 void	 fill_default_server_options(ServerOptions *);
314 int	 process_server_config_line(ServerOptions *, char *, const char *, int,
315 	    int *, struct connection_info *, struct include_list *includes);
316 void	 load_server_config(const char *, struct sshbuf *);
317 void	 parse_server_config(ServerOptions *, const char *, struct sshbuf *,
318 	    struct include_list *includes, struct connection_info *, int);
319 void	 parse_server_match_config(ServerOptions *,
320 	    struct include_list *includes, struct connection_info *);
321 int	 parse_server_match_testspec(struct connection_info *, char *);
322 void	 servconf_merge_subsystems(ServerOptions *, ServerOptions *);
323 void	 copy_set_server_options(ServerOptions *, ServerOptions *, int);
324 void	 dump_config(ServerOptions *);
325 char	*derelativise_path(const char *);
326 void	 servconf_add_hostkey(const char *, const int,
327 	    ServerOptions *, const char *path, int);
328 void	 servconf_add_hostcert(const char *, const int,
329 	    ServerOptions *, const char *path);
330 
331 #endif				/* SERVCONF_H */
332