1255767Sdes/* $OpenBSD: servconf.h,v 1.109 2013/07/19 07:37:48 markus 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. */
31226046Sdes#define MAX_AUTHKEYS_FILES	256	/* Max # of authorized_keys files. */
32248619Sdes#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
41226046Sdes/* use_privsep */
42226046Sdes#define PRIVSEP_OFF		0
43226046Sdes#define PRIVSEP_ON		1
44240075Sdes#define PRIVSEP_NOSANDBOX	2
45226046Sdes
46248619Sdes/* AllowTCPForwarding */
47248619Sdes#define FORWARD_DENY		0
48248619Sdes#define FORWARD_REMOTE		(1)
49248619Sdes#define FORWARD_LOCAL		(1<<1)
50248619Sdes#define FORWARD_ALLOW		(FORWARD_REMOTE|FORWARD_LOCAL)
51248619Sdes
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. */
69255767Sdes	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 */
8657429Smarkm	int     strict_modes;	/* If true, require string home dir modes. */
87126277Sdes	int     tcp_keep_alive;	/* If true, set SO_KEEPALIVE. */
88221420Sdes	int	ip_qos_interactive;	/* IP ToS/DSCP/class for interactive */
89221420Sdes	int	ip_qos_bulk;		/* IP ToS/DSCP/class for bulk traffic */
9076262Sgreen	char   *ciphers;	/* Supported SSH2 ciphers. */
9176262Sgreen	char   *macs;		/* Supported SSH2 macs. */
92221420Sdes	char   *kex_algorithms;	/* SSH2 kex methods in order of preference. */
9376262Sgreen	int	protocol;	/* Supported protocol versions. */
9460576Skris	int     gateway_ports;	/* If true, allow remote connects to forwarded ports. */
9557429Smarkm	SyslogFacility log_facility;	/* Facility for system logging. */
9657429Smarkm	LogLevel log_level;	/* Level for system logging. */
9757429Smarkm	int     rhosts_rsa_authentication;	/* If true, permit rhosts RSA
9857429Smarkm						 * authentication. */
9976262Sgreen	int     hostbased_authentication;	/* If true, permit ssh2 hostbased auth */
10076262Sgreen	int     hostbased_uses_name_from_packet_only; /* experimental */
10157429Smarkm	int     rsa_authentication;	/* If true, permit RSA authentication. */
10292559Sdes	int     pubkey_authentication;	/* If true, permit ssh2 pubkey authentication. */
10392559Sdes	int     kerberos_authentication;	/* If true, permit Kerberos
10492559Sdes						 * authentication. */
10592559Sdes	int     kerberos_or_local_passwd;	/* If true, permit kerberos
10657429Smarkm						 * and any other password
10757429Smarkm						 * authentication mechanism,
10857429Smarkm						 * such as SecurID or
10957429Smarkm						 * /etc/passwd */
11092559Sdes	int     kerberos_ticket_cleanup;	/* If true, destroy ticket
11157429Smarkm						 * file on logout. */
112126277Sdes	int     kerberos_get_afs_token;		/* If true, try to get AFS token if
113126277Sdes						 * authenticated with Kerberos. */
114124211Sdes	int     gss_authentication;	/* If true, permit GSSAPI authentication */
115124211Sdes	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
11657429Smarkm	int     password_authentication;	/* If true, permit password
11757429Smarkm						 * authentication. */
11869591Sgreen	int     kbd_interactive_authentication;	/* If true, permit */
11992559Sdes	int     challenge_response_authentication;
120192595Sdes	int     zero_knowledge_password_authentication;
121192595Sdes					/* If true, permit jpake auth */
12257429Smarkm	int     permit_empty_passwd;	/* If false, do not permit empty
12357429Smarkm					 * passwords. */
124106130Sdes	int     permit_user_env;	/* If true, read ~/.ssh/environment */
12557429Smarkm	int     use_login;	/* If true, login(1) is used */
12698684Sdes	int     compression;	/* If true, compression is allowed */
127248619Sdes	int	allow_tcp_forwarding; /* One of FORWARD_* */
128181111Sdes	int	allow_agent_forwarding;
12976262Sgreen	u_int num_allow_users;
13057429Smarkm	char   *allow_users[MAX_ALLOW_USERS];
13176262Sgreen	u_int num_deny_users;
13257429Smarkm	char   *deny_users[MAX_DENY_USERS];
13376262Sgreen	u_int num_allow_groups;
13457429Smarkm	char   *allow_groups[MAX_ALLOW_GROUPS];
13576262Sgreen	u_int num_deny_groups;
13657429Smarkm	char   *deny_groups[MAX_DENY_GROUPS];
13765674Skris
13876262Sgreen	u_int num_subsystems;
13965674Skris	char   *subsystem_name[MAX_SUBSYSTEMS];
14065674Skris	char   *subsystem_command[MAX_SUBSYSTEMS];
141162856Sdes	char   *subsystem_args[MAX_SUBSYSTEMS];
14265674Skris
143137019Sdes	u_int num_accept_env;
144137019Sdes	char   *accept_env[MAX_ACCEPT_ENV];
145137019Sdes
14665674Skris	int	max_startups_begin;
14765674Skris	int	max_startups_rate;
14865674Skris	int	max_startups;
149137019Sdes	int	max_authtries;
150181111Sdes	int	max_sessions;
15176262Sgreen	char   *banner;			/* SSH-2 banner message */
152124211Sdes	int	use_dns;
15376262Sgreen	int	client_alive_interval;	/*
15492559Sdes					 * poke the client this often to
15592559Sdes					 * see if it's still there
15676262Sgreen					 */
15776262Sgreen	int	client_alive_count_max;	/*
15892559Sdes					 * If the client is unresponsive
15992559Sdes					 * for this many intervals above,
16092559Sdes					 * disconnect the session
16176262Sgreen					 */
16265674Skris
163226046Sdes	u_int num_authkeys_files;	/* Files containing public keys */
164226046Sdes	char   *authorized_keys_files[MAX_AUTHKEYS_FILES];
165157019Sdes
166162856Sdes	char   *adm_forced_command;
167162856Sdes
168124211Sdes	int	use_pam;		/* Enable auth via PAM */
169157019Sdes
170157019Sdes	int	permit_tun;
171162856Sdes
172162856Sdes	int	num_permitted_opens;
173181111Sdes
174181111Sdes	char   *chroot_directory;
175204917Sdes	char   *revoked_keys_file;
176204917Sdes	char   *trusted_user_ca_keys;
177215116Sdes	char   *authorized_principals_file;
178248619Sdes	char   *authorized_keys_command;
179248619Sdes	char   *authorized_keys_command_user;
180224638Sbrooks
181255767Sdes	int64_t rekey_limit;
182255767Sdes	int	rekey_interval;
183255767Sdes
184240075Sdes	char   *version_addendum;	/* Appended to SSH banner */
185240075Sdes
186224638Sbrooks	int	hpn_disabled;		/* Disable HPN functionality. */
187224638Sbrooks	int	hpn_buffer_size;	/* Set HPN buffer size - default 2MB.*/
188224638Sbrooks	int	tcp_rcv_buf_poll;	/* Poll TCP rcv window in autotuning
189224638Sbrooks					 * kernels. */
190248619Sdes	u_int	num_auth_methods;
191248619Sdes	char   *auth_methods[MAX_AUTH_METHODS];
192224638Sbrooks
193224638Sbrooks#ifdef	NONE_CIPHER_ENABLED
194224638Sbrooks	int	none_enabled;		/* Enable NONE cipher switch. */
195224638Sbrooks#endif
19657429Smarkm}       ServerOptions;
19757429Smarkm
198240075Sdes/* Information about the incoming connection as used by Match */
199240075Sdesstruct connection_info {
200240075Sdes	const char *user;
201240075Sdes	const char *host;	/* possibly resolved hostname */
202240075Sdes	const char *address; 	/* remote address */
203240075Sdes	const char *laddress;	/* local address */
204240075Sdes	int lport;		/* local port */
205240075Sdes};
206240075Sdes
207240075Sdes
208226046Sdes/*
209226046Sdes * These are string config options that must be copied between the
210226046Sdes * Match sub-config and the main config, and must be sent from the
211226046Sdes * privsep slave to the privsep master. We use a macro to ensure all
212226046Sdes * the options are copied and the copies are done in the correct order.
213226046Sdes */
214226046Sdes#define COPY_MATCH_STRING_OPTS() do { \
215226046Sdes		M_CP_STROPT(banner); \
216226046Sdes		M_CP_STROPT(trusted_user_ca_keys); \
217226046Sdes		M_CP_STROPT(revoked_keys_file); \
218226046Sdes		M_CP_STROPT(authorized_principals_file); \
219248619Sdes		M_CP_STROPT(authorized_keys_command); \
220248619Sdes		M_CP_STROPT(authorized_keys_command_user); \
221226046Sdes		M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \
222240075Sdes		M_CP_STRARRAYOPT(allow_users, num_allow_users); \
223240075Sdes		M_CP_STRARRAYOPT(deny_users, num_deny_users); \
224240075Sdes		M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \
225240075Sdes		M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \
226240075Sdes		M_CP_STRARRAYOPT(accept_env, num_accept_env); \
227248619Sdes		M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \
228226046Sdes	} while (0)
229226046Sdes
230240075Sdesstruct connection_info *get_connection_info(int, int);
23192559Sdesvoid	 initialize_server_options(ServerOptions *);
23292559Sdesvoid	 fill_default_server_options(ServerOptions *);
233162856Sdesint	 process_server_config_line(ServerOptions *, char *, const char *, int,
234240075Sdes	     int *, struct connection_info *);
235137019Sdesvoid	 load_server_config(const char *, Buffer *);
236162856Sdesvoid	 parse_server_config(ServerOptions *, const char *, Buffer *,
237240075Sdes	     struct connection_info *);
238240075Sdesvoid	 parse_server_match_config(ServerOptions *, struct connection_info *);
239240075Sdesint	 parse_server_match_testspec(struct connection_info *, char *);
240240075Sdesint	 server_match_spec_complete(struct connection_info *);
241181111Sdesvoid	 copy_set_server_options(ServerOptions *, ServerOptions *, int);
242181111Sdesvoid	 dump_config(ServerOptions *);
243204917Sdeschar	*derelativise_path(const char *);
24457429Smarkm
24557429Smarkm#endif				/* SERVCONF_H */
246