xref: /freebsd/crypto/openssh/servconf.h (revision 2574974648c68c738aec3ff96644d888d7913a37)
1 /* $OpenBSD: servconf.h,v 1.176 2026/03/03 09:57:25 dtucker 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 	double	penalty_crash;
77 	double	penalty_grace;
78 	double	penalty_authfail;
79 	double	penalty_invaliduser;
80 	double	penalty_noauth;
81 	double	penalty_refuseconnection;
82 	double	penalty_max;
83 	double	penalty_min;
84 };
85 
86 typedef struct {
87 	u_int	num_ports;
88 	u_int	ports_from_cmdline;
89 	int	ports[MAX_PORTS];	/* Port number to listen on. */
90 	struct queued_listenaddr *queued_listen_addrs;
91 	u_int	num_queued_listens;
92 	struct listenaddr *listen_addrs;
93 	u_int	num_listen_addrs;
94 	int	address_family;		/* Address family used by the server. */
95 
96 	char	*routing_domain;	/* Bind session to routing domain */
97 
98 	char   **host_key_files;	/* Files containing host keys. */
99 	int	*host_key_file_userprovided; /* Key was specified by user. */
100 	u_int	num_host_key_files;     /* Number of files for host keys. */
101 	char   **host_cert_files;	/* Files containing host certs. */
102 	u_int	num_host_cert_files;	/* Number of files for host certs. */
103 
104 	char   *host_key_agent;		/* ssh-agent socket for host keys. */
105 	char   *pid_file;		/* Where to put our pid */
106 	char   *moduli_file;		/* moduli file for DH-GEX */
107 	int     login_grace_time;	/* Disconnect if no auth in this time
108 					 * (sec). */
109 	int     permit_root_login;	/* PERMIT_*, see above */
110 	int     ignore_rhosts;	/* Ignore .rhosts and .shosts. */
111 	int     ignore_user_known_hosts;	/* Ignore ~/.ssh/known_hosts
112 						 * for RhostsRsaAuth */
113 	int     print_motd;	/* If true, print /etc/motd. */
114 	int	print_lastlog;	/* If true, print lastlog */
115 	int     x11_forwarding;	/* If true, permit inet (spoofing) X11 fwd. */
116 	int     x11_display_offset;	/* What DISPLAY number to start
117 					 * searching at */
118 	int     x11_use_localhost;	/* If true, use localhost for fake X11 server. */
119 	char   *xauth_location;	/* Location of xauth program */
120 	int	permit_tty;	/* If false, deny pty allocation */
121 	int	permit_user_rc;	/* If false, deny ~/.ssh/rc execution */
122 	int     strict_modes;	/* If true, require string home dir modes. */
123 	int     tcp_keep_alive;	/* If true, set SO_KEEPALIVE. */
124 	int	ip_qos_interactive;	/* IP ToS/DSCP/class for interactive */
125 	int	ip_qos_bulk;		/* IP ToS/DSCP/class for bulk traffic */
126 	char   *ciphers;	/* Supported SSH2 ciphers. */
127 	char   *macs;		/* Supported SSH2 macs. */
128 	char   *kex_algorithms;	/* SSH2 kex methods in order of preference. */
129 	struct ForwardOptions fwd_opts;	/* forwarding options */
130 	SyslogFacility log_facility;	/* Facility for system logging. */
131 	LogLevel log_level;	/* Level for system logging. */
132 	u_int	num_log_verbose;	/* Verbose log overrides */
133 	char	**log_verbose;
134 	int     hostbased_authentication;	/* If true, permit ssh2 hostbased auth */
135 	int     hostbased_uses_name_from_packet_only; /* experimental */
136 	char   *hostbased_accepted_algos; /* Algos allowed for hostbased */
137 	char   *hostkeyalgorithms;	/* SSH2 server key types */
138 	char   *ca_sign_algorithms;	/* Allowed CA signature algorithms */
139 	int     pubkey_authentication;	/* If true, permit ssh2 pubkey authentication. */
140 	char   *pubkey_accepted_algos;	/* Signature algos allowed for pubkey */
141 	int	pubkey_auth_options;	/* -1 or mask of PUBKEYAUTH_* flags */
142 	int     kerberos_authentication;	/* If true, permit Kerberos
143 						 * authentication. */
144 	int     kerberos_or_local_passwd;	/* If true, permit kerberos
145 						 * and any other password
146 						 * authentication mechanism,
147 						 * such as SecurID or
148 						 * /etc/passwd */
149 	int     kerberos_ticket_cleanup;	/* If true, destroy ticket
150 						 * file on logout. */
151 	int     kerberos_get_afs_token;		/* If true, try to get AFS token if
152 						 * authenticated with Kerberos. */
153 	int     gss_authentication;	/* If true, permit GSSAPI authentication */
154 	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
155 	int     gss_deleg_creds;	/* If true, accept delegated GSS credentials */
156 	int     gss_strict_acceptor;	/* If true, restrict the GSSAPI acceptor name */
157 	int     password_authentication;	/* If true, permit password
158 						 * authentication. */
159 	int     kbd_interactive_authentication;	/* If true, permit */
160 	int     permit_empty_passwd;	/* If false, do not permit empty
161 					 * passwords. */
162 	int     permit_user_env;	/* If true, read ~/.ssh/environment */
163 	char   *permit_user_env_allowlist; /* pattern-list of allowed env names */
164 	int     compression;	/* If true, compression is allowed */
165 	int	allow_tcp_forwarding; /* One of FORWARD_* */
166 	int	allow_streamlocal_forwarding; /* One of FORWARD_* */
167 	int	allow_agent_forwarding;
168 	int	disable_forwarding;
169 	u_int num_allow_users;
170 	char   **allow_users;
171 	u_int num_deny_users;
172 	char   **deny_users;
173 	u_int num_allow_groups;
174 	char   **allow_groups;
175 	u_int num_deny_groups;
176 	char   **deny_groups;
177 
178 	u_int num_subsystems;
179 	char   **subsystem_name;
180 	char   **subsystem_command;
181 	char   **subsystem_args;
182 
183 	u_int num_accept_env;
184 	char   **accept_env;
185 	u_int num_setenv;
186 	char   **setenv;
187 
188 	int	max_startups_begin;
189 	int	max_startups_rate;
190 	int	max_startups;
191 	int	per_source_max_startups;
192 	int	per_source_masklen_ipv4;
193 	int	per_source_masklen_ipv6;
194 	char	*per_source_penalty_exempt;
195 	struct per_source_penalty per_source_penalty;
196 	int	max_authtries;
197 	int	max_sessions;
198 	char   *banner;			/* SSH-2 banner message */
199 	int	use_dns;
200 	int	client_alive_interval;	/*
201 					 * poke the client this often to
202 					 * see if it's still there
203 					 */
204 	int	client_alive_count_max;	/*
205 					 * If the client is unresponsive
206 					 * for this many intervals above,
207 					 * disconnect the session
208 					 */
209 
210 	u_int	num_authkeys_files;	/* Files containing public keys */
211 	char   **authorized_keys_files;
212 
213 	char   *adm_forced_command;
214 
215 	int	use_pam;		/* Enable auth via PAM */
216 	char   *pam_service_name;
217 
218 	int	permit_tun;
219 
220 	char   **permitted_opens;	/* May also be one of PERMITOPEN_* */
221 	u_int   num_permitted_opens;
222 	char   **permitted_listens; /* May also be one of PERMITOPEN_* */
223 	u_int   num_permitted_listens;
224 
225 	char   *chroot_directory;
226 	uint	num_revoked_keys_files;
227 	char   **revoked_keys_files;
228 	char   *trusted_user_ca_keys;
229 	char   *authorized_keys_command;
230 	char   *authorized_keys_command_user;
231 	char   *authorized_principals_file;
232 	char   *authorized_principals_command;
233 	char   *authorized_principals_command_user;
234 
235 	int64_t rekey_limit;
236 	int	rekey_interval;
237 
238 	char   *version_addendum;	/* Appended to SSH banner */
239 
240 	u_int	num_auth_methods;
241 	char   **auth_methods;
242 
243 	int	fingerprint_hash;
244 	int	expose_userauth_info;
245 	uint64_t timing_secret;
246 	char   *sk_provider;
247 	int	required_rsa_size;	/* minimum size of RSA keys */
248 
249 	char	**channel_timeouts;	/* inactivity timeout by channel type */
250 	u_int	num_channel_timeouts;
251 
252 	int	unused_connection_timeout;
253 
254 	char   *sshd_session_path;
255 	char   *sshd_auth_path;
256 
257 	int	refuse_connection;
258 
259 	int	use_blocklist;
260 }       ServerOptions;
261 
262 /* Information about the incoming connection as used by Match */
263 struct connection_info {
264 	const char *user;
265 	int user_invalid;
266 	const char *host;	/* possibly resolved hostname */
267 	const char *address;	/* remote address */
268 	const char *laddress;	/* local address */
269 	int lport;		/* local port */
270 	const char *rdomain;	/* routing domain if available */
271 	int test;		/* test mode, allow some attributes to be
272 				 * unspecified */
273 };
274 
275 /* List of included files for re-exec from the parsed configuration */
276 struct include_item {
277 	char *selector;
278 	char *filename;
279 	struct sshbuf *contents;
280 	TAILQ_ENTRY(include_item) entry;
281 };
282 TAILQ_HEAD(include_list, include_item);
283 
284 
285 /*
286  * These are string config options that must be copied between the
287  * Match sub-config and the main config, and must be sent from the
288  * privsep child to the privsep master. We use a macro to ensure all
289  * the options are copied and the copies are done in the correct order.
290  *
291  * NB. an option must appear in servconf.c:copy_set_server_options() or
292  * COPY_MATCH_STRING_OPTS here but never both.
293  */
294 #define COPY_MATCH_STRING_OPTS() do { \
295 		M_CP_STROPT(banner); \
296 		M_CP_STROPT(trusted_user_ca_keys); \
297 		M_CP_STROPT(authorized_keys_command); \
298 		M_CP_STROPT(authorized_keys_command_user); \
299 		M_CP_STROPT(authorized_principals_file); \
300 		M_CP_STROPT(authorized_principals_command); \
301 		M_CP_STROPT(authorized_principals_command_user); \
302 		M_CP_STROPT(hostbased_accepted_algos); \
303 		M_CP_STROPT(pubkey_accepted_algos); \
304 		M_CP_STROPT(ca_sign_algorithms); \
305 		M_CP_STROPT(routing_domain); \
306 		M_CP_STROPT(permit_user_env_allowlist); \
307 		M_CP_STROPT(pam_service_name); \
308 		M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files, 1);\
309 		M_CP_STRARRAYOPT(revoked_keys_files, \
310 		    num_revoked_keys_files, 1); \
311 		M_CP_STRARRAYOPT(allow_users, num_allow_users, 1); \
312 		M_CP_STRARRAYOPT(deny_users, num_deny_users, 1); \
313 		M_CP_STRARRAYOPT(allow_groups, num_allow_groups, 1); \
314 		M_CP_STRARRAYOPT(deny_groups, num_deny_groups, 1); \
315 		M_CP_STRARRAYOPT(accept_env, num_accept_env, 1); \
316 		M_CP_STRARRAYOPT(setenv, num_setenv, 1); \
317 		M_CP_STRARRAYOPT(auth_methods, num_auth_methods, 1); \
318 		M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens, 1); \
319 		M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens, 1); \
320 		M_CP_STRARRAYOPT(channel_timeouts, num_channel_timeouts, 1); \
321 		M_CP_STRARRAYOPT(log_verbose, num_log_verbose, 1); \
322 		/* Note: don't clobber num_subsystems until all copied */ \
323 		M_CP_STRARRAYOPT(subsystem_name, num_subsystems, 0); \
324 		M_CP_STRARRAYOPT(subsystem_command, num_subsystems, 0); \
325 		M_CP_STRARRAYOPT(subsystem_args, num_subsystems, 1); \
326 	} while (0)
327 
328 void	 initialize_server_options(ServerOptions *);
329 void	 fill_default_server_options(ServerOptions *);
330 int	 process_server_config_line(ServerOptions *, char *, const char *, int,
331 	    int *, struct connection_info *, struct include_list *includes);
332 void	 load_server_config(const char *, struct sshbuf *);
333 void	 parse_server_config(ServerOptions *, const char *, struct sshbuf *,
334 	    struct include_list *includes, struct connection_info *, int);
335 void	 parse_server_match_config(ServerOptions *,
336 	    struct include_list *includes, struct connection_info *);
337 int	 parse_server_match_testspec(struct connection_info *, char *);
338 void	 servconf_merge_subsystems(ServerOptions *, ServerOptions *);
339 void	 copy_set_server_options(ServerOptions *, ServerOptions *, int);
340 void	 dump_config(ServerOptions *);
341 char	*derelativise_path(const char *);
342 void	 servconf_add_hostkey(const char *, const int,
343 	    ServerOptions *, const char *path, int);
344 void	 servconf_add_hostcert(const char *, const int,
345 	    ServerOptions *, const char *path);
346 
347 #endif				/* SERVCONF_H */
348