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