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