1263970Sdes/* $OpenBSD: servconf.h,v 1.112 2014/01/29 06:18:35 djm Exp $ */
2224642Sbrooks/* $FreeBSD$ */
392559Sdes
457429Smarkm/*
557429Smarkm * Author: Tatu Ylonen <ylo@cs.hut.fi>
657429Smarkm * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
757429Smarkm *                    All rights reserved
857429Smarkm * Definitions for server configuration data and for the functions reading it.
960576Skris *
1065674Skris * As far as I am concerned, the code I have written for this software
1165674Skris * can be used freely for any purpose.  Any derived versions of this
1265674Skris * software must be clearly marked as such, and if the derived work is
1365674Skris * incompatible with the protocol description in the RFC file, it must be
1465674Skris * called by a name other than "ssh" or "Secure Shell".
1557429Smarkm */
1657429Smarkm
1757429Smarkm#ifndef SERVCONF_H
1857429Smarkm#define SERVCONF_H
1957429Smarkm
2057429Smarkm#define MAX_PORTS		256	/* Max # ports. */
2157429Smarkm
2257429Smarkm#define MAX_ALLOW_USERS		256	/* Max # users on allow list. */
2357429Smarkm#define MAX_DENY_USERS		256	/* Max # users on deny list. */
2457429Smarkm#define MAX_ALLOW_GROUPS	256	/* Max # groups on allow list. */
2557429Smarkm#define MAX_DENY_GROUPS		256	/* Max # groups on deny list. */
2665674Skris#define MAX_SUBSYSTEMS		256	/* Max # subsystems. */
2776262Sgreen#define MAX_HOSTKEYS		256	/* Max # hostkeys. */
28204917Sdes#define MAX_HOSTCERTS		256	/* Max # host certificates. */
29137019Sdes#define MAX_ACCEPT_ENV		256	/* Max # of env vars. */
30162856Sdes#define MAX_MATCH_GROUPS	256	/* Max # of groups for Match. */
31247485Sdes#define MAX_AUTHKEYS_FILES	256	/* Max # of authorized_keys files. */
32251135Sdes#define MAX_AUTH_METHODS	256	/* Max # of AuthenticationMethods. */
3357429Smarkm
3476262Sgreen/* permit_root_login */
3576262Sgreen#define	PERMIT_NOT_SET		-1
3676262Sgreen#define	PERMIT_NO		0
3776262Sgreen#define	PERMIT_FORCED_ONLY	1
3876262Sgreen#define	PERMIT_NO_PASSWD	2
3976262Sgreen#define	PERMIT_YES		3
4076262Sgreen
41247485Sdes/* use_privsep */
42247485Sdes#define PRIVSEP_OFF		0
43247485Sdes#define PRIVSEP_ON		1
44247485Sdes#define PRIVSEP_NOSANDBOX	2
45247485Sdes
46251135Sdes/* AllowTCPForwarding */
47251135Sdes#define FORWARD_DENY		0
48251135Sdes#define FORWARD_REMOTE		(1)
49251135Sdes#define FORWARD_LOCAL		(1<<1)
50251135Sdes#define FORWARD_ALLOW		(FORWARD_REMOTE|FORWARD_LOCAL)
51251135Sdes
52137019Sdes#define DEFAULT_AUTH_FAIL_MAX	6	/* Default for MaxAuthTries */
53181111Sdes#define DEFAULT_SESSIONS_MAX	10	/* Default for MaxSessions */
5476262Sgreen
55181111Sdes/* Magic name for internal sftp-server */
56181111Sdes#define INTERNAL_SFTP_NAME	"internal-sftp"
57181111Sdes
5857429Smarkmtypedef struct {
59192595Sdes	u_int	num_ports;
60192595Sdes	u_int	ports_from_cmdline;
61192595Sdes	int	ports[MAX_PORTS];	/* Port number to listen on. */
6257429Smarkm	char   *listen_addr;		/* Address on which the server listens. */
6357429Smarkm	struct addrinfo *listen_addrs;	/* Addresses on which the server listens. */
64147005Sdes	int     address_family;		/* Address family used by the server. */
6576262Sgreen	char   *host_key_files[MAX_HOSTKEYS];	/* Files containing host keys. */
6676262Sgreen	int     num_host_key_files;     /* Number of files for host keys. */
67204917Sdes	char   *host_cert_files[MAX_HOSTCERTS];	/* Files containing host certs. */
68204917Sdes	int     num_host_cert_files;     /* Number of files for host certs. */
69263970Sdes	char   *host_key_agent;		 /* ssh-agent socket for host keys. */
7060576Skris	char   *pid_file;	/* Where to put our pid */
7157429Smarkm	int     server_key_bits;/* Size of the server key. */
7257429Smarkm	int     login_grace_time;	/* Disconnect if no auth in this time
7357429Smarkm					 * (sec). */
7457429Smarkm	int     key_regeneration_time;	/* Server key lifetime (seconds). */
7576262Sgreen	int     permit_root_login;	/* PERMIT_*, see above */
7657429Smarkm	int     ignore_rhosts;	/* Ignore .rhosts and .shosts. */
7757429Smarkm	int     ignore_user_known_hosts;	/* Ignore ~/.ssh/known_hosts
7857429Smarkm						 * for RhostsRsaAuth */
7957429Smarkm	int     print_motd;	/* If true, print /etc/motd. */
8076262Sgreen	int	print_lastlog;	/* If true, print lastlog */
8157429Smarkm	int     x11_forwarding;	/* If true, permit inet (spoofing) X11 fwd. */
8257429Smarkm	int     x11_display_offset;	/* What DISPLAY number to start
8357429Smarkm					 * searching at */
8492559Sdes	int     x11_use_localhost;	/* If true, use localhost for fake X11 server. */
8565674Skris	char   *xauth_location;	/* Location of xauth program */
86263970Sdes	int	permit_tty;	/* If false, deny pty allocation */
8757429Smarkm	int     strict_modes;	/* If true, require string home dir modes. */
88126277Sdes	int     tcp_keep_alive;	/* If true, set SO_KEEPALIVE. */
89221420Sdes	int	ip_qos_interactive;	/* IP ToS/DSCP/class for interactive */
90221420Sdes	int	ip_qos_bulk;		/* IP ToS/DSCP/class for bulk traffic */
9176262Sgreen	char   *ciphers;	/* Supported SSH2 ciphers. */
9276262Sgreen	char   *macs;		/* Supported SSH2 macs. */
93221420Sdes	char   *kex_algorithms;	/* SSH2 kex methods in order of preference. */
9476262Sgreen	int	protocol;	/* Supported protocol versions. */
9560576Skris	int     gateway_ports;	/* If true, allow remote connects to forwarded ports. */
9657429Smarkm	SyslogFacility log_facility;	/* Facility for system logging. */
9757429Smarkm	LogLevel log_level;	/* Level for system logging. */
9857429Smarkm	int     rhosts_rsa_authentication;	/* If true, permit rhosts RSA
9957429Smarkm						 * authentication. */
10076262Sgreen	int     hostbased_authentication;	/* If true, permit ssh2 hostbased auth */
10176262Sgreen	int     hostbased_uses_name_from_packet_only; /* experimental */
10257429Smarkm	int     rsa_authentication;	/* If true, permit RSA authentication. */
10392559Sdes	int     pubkey_authentication;	/* If true, permit ssh2 pubkey authentication. */
10492559Sdes	int     kerberos_authentication;	/* If true, permit Kerberos
10592559Sdes						 * authentication. */
10692559Sdes	int     kerberos_or_local_passwd;	/* If true, permit kerberos
10757429Smarkm						 * and any other password
10857429Smarkm						 * authentication mechanism,
10957429Smarkm						 * such as SecurID or
11057429Smarkm						 * /etc/passwd */
11192559Sdes	int     kerberos_ticket_cleanup;	/* If true, destroy ticket
11257429Smarkm						 * file on logout. */
113126277Sdes	int     kerberos_get_afs_token;		/* If true, try to get AFS token if
114126277Sdes						 * authenticated with Kerberos. */
115124211Sdes	int     gss_authentication;	/* If true, permit GSSAPI authentication */
116124211Sdes	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
11757429Smarkm	int     password_authentication;	/* If true, permit password
11857429Smarkm						 * authentication. */
11969591Sgreen	int     kbd_interactive_authentication;	/* If true, permit */
12092559Sdes	int     challenge_response_authentication;
12157429Smarkm	int     permit_empty_passwd;	/* If false, do not permit empty
12257429Smarkm					 * passwords. */
123106130Sdes	int     permit_user_env;	/* If true, read ~/.ssh/environment */
12457429Smarkm	int     use_login;	/* If true, login(1) is used */
12598684Sdes	int     compression;	/* If true, compression is allowed */
126251135Sdes	int	allow_tcp_forwarding; /* One of FORWARD_* */
127181111Sdes	int	allow_agent_forwarding;
12876262Sgreen	u_int num_allow_users;
12957429Smarkm	char   *allow_users[MAX_ALLOW_USERS];
13076262Sgreen	u_int num_deny_users;
13157429Smarkm	char   *deny_users[MAX_DENY_USERS];
13276262Sgreen	u_int num_allow_groups;
13357429Smarkm	char   *allow_groups[MAX_ALLOW_GROUPS];
13476262Sgreen	u_int num_deny_groups;
13557429Smarkm	char   *deny_groups[MAX_DENY_GROUPS];
13665674Skris
13776262Sgreen	u_int num_subsystems;
13865674Skris	char   *subsystem_name[MAX_SUBSYSTEMS];
13965674Skris	char   *subsystem_command[MAX_SUBSYSTEMS];
140162856Sdes	char   *subsystem_args[MAX_SUBSYSTEMS];
14165674Skris
142137019Sdes	u_int num_accept_env;
143137019Sdes	char   *accept_env[MAX_ACCEPT_ENV];
144137019Sdes
14565674Skris	int	max_startups_begin;
14665674Skris	int	max_startups_rate;
14765674Skris	int	max_startups;
148137019Sdes	int	max_authtries;
149181111Sdes	int	max_sessions;
15076262Sgreen	char   *banner;			/* SSH-2 banner message */
151124211Sdes	int	use_dns;
15276262Sgreen	int	client_alive_interval;	/*
15392559Sdes					 * poke the client this often to
15492559Sdes					 * see if it's still there
15576262Sgreen					 */
15676262Sgreen	int	client_alive_count_max;	/*
15792559Sdes					 * If the client is unresponsive
15892559Sdes					 * for this many intervals above,
15992559Sdes					 * disconnect the session
16076262Sgreen					 */
16165674Skris
162247485Sdes	u_int num_authkeys_files;	/* Files containing public keys */
163247485Sdes	char   *authorized_keys_files[MAX_AUTHKEYS_FILES];
164157019Sdes
165162856Sdes	char   *adm_forced_command;
166162856Sdes
167124211Sdes	int	use_pam;		/* Enable auth via PAM */
168157019Sdes
169157019Sdes	int	permit_tun;
170162856Sdes
171162856Sdes	int	num_permitted_opens;
172181111Sdes
173181111Sdes	char   *chroot_directory;
174204917Sdes	char   *revoked_keys_file;
175204917Sdes	char   *trusted_user_ca_keys;
176215116Sdes	char   *authorized_principals_file;
177251135Sdes	char   *authorized_keys_command;
178251135Sdes	char   *authorized_keys_command_user;
179224638Sbrooks
180263970Sdes	int64_t rekey_limit;
181263970Sdes	int	rekey_interval;
182263970Sdes
183247485Sdes	char   *version_addendum;	/* Appended to SSH banner */
184247485Sdes
185224638Sbrooks	int	hpn_disabled;		/* Disable HPN functionality. */
186224638Sbrooks	int	hpn_buffer_size;	/* Set HPN buffer size - default 2MB.*/
187224638Sbrooks	int	tcp_rcv_buf_poll;	/* Poll TCP rcv window in autotuning
188224638Sbrooks					 * kernels. */
189251135Sdes	u_int	num_auth_methods;
190251135Sdes	char   *auth_methods[MAX_AUTH_METHODS];
191224638Sbrooks
192224638Sbrooks#ifdef	NONE_CIPHER_ENABLED
193224638Sbrooks	int	none_enabled;		/* Enable NONE cipher switch. */
194224638Sbrooks#endif
19557429Smarkm}       ServerOptions;
19657429Smarkm
197247485Sdes/* Information about the incoming connection as used by Match */
198247485Sdesstruct connection_info {
199247485Sdes	const char *user;
200247485Sdes	const char *host;	/* possibly resolved hostname */
201247485Sdes	const char *address; 	/* remote address */
202247485Sdes	const char *laddress;	/* local address */
203247485Sdes	int lport;		/* local port */
204247485Sdes};
205247485Sdes
206247485Sdes
207247485Sdes/*
208247485Sdes * These are string config options that must be copied between the
209247485Sdes * Match sub-config and the main config, and must be sent from the
210247485Sdes * privsep slave to the privsep master. We use a macro to ensure all
211247485Sdes * the options are copied and the copies are done in the correct order.
212263970Sdes *
213263970Sdes * NB. an option must appear in servconf.c:copy_set_server_options() or
214263970Sdes * COPY_MATCH_STRING_OPTS here but never both.
215247485Sdes */
216247485Sdes#define COPY_MATCH_STRING_OPTS() do { \
217247485Sdes		M_CP_STROPT(banner); \
218247485Sdes		M_CP_STROPT(trusted_user_ca_keys); \
219247485Sdes		M_CP_STROPT(revoked_keys_file); \
220247485Sdes		M_CP_STROPT(authorized_principals_file); \
221251135Sdes		M_CP_STROPT(authorized_keys_command); \
222251135Sdes		M_CP_STROPT(authorized_keys_command_user); \
223247485Sdes		M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \
224247485Sdes		M_CP_STRARRAYOPT(allow_users, num_allow_users); \
225247485Sdes		M_CP_STRARRAYOPT(deny_users, num_deny_users); \
226247485Sdes		M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \
227247485Sdes		M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \
228247485Sdes		M_CP_STRARRAYOPT(accept_env, num_accept_env); \
229251135Sdes		M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \
230247485Sdes	} while (0)
231247485Sdes
232247485Sdesstruct connection_info *get_connection_info(int, int);
23392559Sdesvoid	 initialize_server_options(ServerOptions *);
23492559Sdesvoid	 fill_default_server_options(ServerOptions *);
235162856Sdesint	 process_server_config_line(ServerOptions *, char *, const char *, int,
236247485Sdes	     int *, struct connection_info *);
237137019Sdesvoid	 load_server_config(const char *, Buffer *);
238162856Sdesvoid	 parse_server_config(ServerOptions *, const char *, Buffer *,
239247485Sdes	     struct connection_info *);
240247485Sdesvoid	 parse_server_match_config(ServerOptions *, struct connection_info *);
241247485Sdesint	 parse_server_match_testspec(struct connection_info *, char *);
242247485Sdesint	 server_match_spec_complete(struct connection_info *);
243181111Sdesvoid	 copy_set_server_options(ServerOptions *, ServerOptions *, int);
244181111Sdesvoid	 dump_config(ServerOptions *);
245204917Sdeschar	*derelativise_path(const char *);
24657429Smarkm
24757429Smarkm#endif				/* SERVCONF_H */
248