1*664f4763Szrj /* $OpenBSD: servconf.h,v 1.139 2019/01/19 21:37:48 djm Exp $ */ 218de8d7fSPeter Avalos 318de8d7fSPeter Avalos /* 418de8d7fSPeter Avalos * Author: Tatu Ylonen <ylo@cs.hut.fi> 518de8d7fSPeter Avalos * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 618de8d7fSPeter Avalos * All rights reserved 718de8d7fSPeter Avalos * Definitions for server configuration data and for the functions reading it. 818de8d7fSPeter Avalos * 918de8d7fSPeter Avalos * As far as I am concerned, the code I have written for this software 1018de8d7fSPeter Avalos * can be used freely for any purpose. Any derived versions of this 1118de8d7fSPeter Avalos * software must be clearly marked as such, and if the derived work is 1218de8d7fSPeter Avalos * incompatible with the protocol description in the RFC file, it must be 1318de8d7fSPeter Avalos * called by a name other than "ssh" or "Secure Shell". 1418de8d7fSPeter Avalos */ 1518de8d7fSPeter Avalos 1618de8d7fSPeter Avalos #ifndef SERVCONF_H 1718de8d7fSPeter Avalos #define SERVCONF_H 1818de8d7fSPeter Avalos 1918de8d7fSPeter Avalos #define MAX_PORTS 256 /* Max # ports. */ 2018de8d7fSPeter Avalos 2118de8d7fSPeter Avalos #define MAX_SUBSYSTEMS 256 /* Max # subsystems. */ 2218de8d7fSPeter Avalos 2318de8d7fSPeter Avalos /* permit_root_login */ 2418de8d7fSPeter Avalos #define PERMIT_NOT_SET -1 2518de8d7fSPeter Avalos #define PERMIT_NO 0 2618de8d7fSPeter Avalos #define PERMIT_FORCED_ONLY 1 2718de8d7fSPeter Avalos #define PERMIT_NO_PASSWD 2 2818de8d7fSPeter Avalos #define PERMIT_YES 3 2918de8d7fSPeter Avalos 301c188a7fSPeter Avalos /* use_privsep */ 311c188a7fSPeter Avalos #define PRIVSEP_OFF 0 321c188a7fSPeter Avalos #define PRIVSEP_ON 1 3399e85e0dSPeter Avalos #define PRIVSEP_NOSANDBOX 2 341c188a7fSPeter Avalos 35ce74bacaSMatthew Dillon /* PermitOpen */ 36ce74bacaSMatthew Dillon #define PERMITOPEN_ANY 0 37ce74bacaSMatthew Dillon #define PERMITOPEN_NONE -2 38ce74bacaSMatthew Dillon 3918de8d7fSPeter Avalos #define DEFAULT_AUTH_FAIL_MAX 6 /* Default for MaxAuthTries */ 4018de8d7fSPeter Avalos #define DEFAULT_SESSIONS_MAX 10 /* Default for MaxSessions */ 4118de8d7fSPeter Avalos 4218de8d7fSPeter Avalos /* Magic name for internal sftp-server */ 4318de8d7fSPeter Avalos #define INTERNAL_SFTP_NAME "internal-sftp" 4418de8d7fSPeter Avalos 45ce74bacaSMatthew Dillon struct ssh; 46ce74bacaSMatthew Dillon struct fwd_perm_list; 47ce74bacaSMatthew Dillon 48*664f4763Szrj /* 49*664f4763Szrj * Used to store addresses from ListenAddr directives. These may be 50*664f4763Szrj * incomplete, as they may specify addresses that need to be merged 51*664f4763Szrj * with any ports requested by ListenPort. 52*664f4763Szrj */ 53*664f4763Szrj struct queued_listenaddr { 54*664f4763Szrj char *addr; 55*664f4763Szrj int port; /* <=0 if unspecified */ 56*664f4763Szrj char *rdomain; 57*664f4763Szrj }; 58*664f4763Szrj 59*664f4763Szrj /* Resolved listen addresses, grouped by optional routing domain */ 60*664f4763Szrj struct listenaddr { 61*664f4763Szrj char *rdomain; 62*664f4763Szrj struct addrinfo *addrs; 63*664f4763Szrj }; 64*664f4763Szrj 6518de8d7fSPeter Avalos typedef struct { 6618de8d7fSPeter Avalos u_int num_ports; 6718de8d7fSPeter Avalos u_int ports_from_cmdline; 68cb5eb4f1SPeter Avalos int ports[MAX_PORTS]; /* Port number to listen on. */ 69*664f4763Szrj struct queued_listenaddr *queued_listen_addrs; 70e9778795SPeter Avalos u_int num_queued_listens; 71*664f4763Szrj struct listenaddr *listen_addrs; 72*664f4763Szrj u_int num_listen_addrs; 7318de8d7fSPeter Avalos int address_family; /* Address family used by the server. */ 74*664f4763Szrj 75*664f4763Szrj char *routing_domain; /* Bind session to routing domain */ 76*664f4763Szrj 77*664f4763Szrj char **host_key_files; /* Files containing host keys. */ 78*664f4763Szrj int *host_key_file_userprovided; /* Key was specified by user. */ 79*664f4763Szrj u_int num_host_key_files; /* Number of files for host keys. */ 80*664f4763Szrj char **host_cert_files; /* Files containing host certs. */ 81*664f4763Szrj u_int num_host_cert_files; /* Number of files for host certs. */ 82*664f4763Szrj 8336e94dc5SPeter Avalos char *host_key_agent; /* ssh-agent socket for host keys. */ 8418de8d7fSPeter Avalos char *pid_file; /* Where to put our pid */ 8518de8d7fSPeter Avalos int login_grace_time; /* Disconnect if no auth in this time 8618de8d7fSPeter Avalos * (sec). */ 8718de8d7fSPeter Avalos int permit_root_login; /* PERMIT_*, see above */ 8818de8d7fSPeter Avalos int ignore_rhosts; /* Ignore .rhosts and .shosts. */ 8918de8d7fSPeter Avalos int ignore_user_known_hosts; /* Ignore ~/.ssh/known_hosts 9018de8d7fSPeter Avalos * for RhostsRsaAuth */ 9118de8d7fSPeter Avalos int print_motd; /* If true, print /etc/motd. */ 9218de8d7fSPeter Avalos int print_lastlog; /* If true, print lastlog */ 9318de8d7fSPeter Avalos int x11_forwarding; /* If true, permit inet (spoofing) X11 fwd. */ 9418de8d7fSPeter Avalos int x11_display_offset; /* What DISPLAY number to start 9518de8d7fSPeter Avalos * searching at */ 9618de8d7fSPeter Avalos int x11_use_localhost; /* If true, use localhost for fake X11 server. */ 9718de8d7fSPeter Avalos char *xauth_location; /* Location of xauth program */ 9836e94dc5SPeter Avalos int permit_tty; /* If false, deny pty allocation */ 9936e94dc5SPeter Avalos int permit_user_rc; /* If false, deny ~/.ssh/rc execution */ 10018de8d7fSPeter Avalos int strict_modes; /* If true, require string home dir modes. */ 10118de8d7fSPeter Avalos int tcp_keep_alive; /* If true, set SO_KEEPALIVE. */ 1029f304aafSPeter Avalos int ip_qos_interactive; /* IP ToS/DSCP/class for interactive */ 1039f304aafSPeter Avalos int ip_qos_bulk; /* IP ToS/DSCP/class for bulk traffic */ 10418de8d7fSPeter Avalos char *ciphers; /* Supported SSH2 ciphers. */ 10518de8d7fSPeter Avalos char *macs; /* Supported SSH2 macs. */ 1069f304aafSPeter Avalos char *kex_algorithms; /* SSH2 kex methods in order of preference. */ 10736e94dc5SPeter Avalos struct ForwardOptions fwd_opts; /* forwarding options */ 10818de8d7fSPeter Avalos SyslogFacility log_facility; /* Facility for system logging. */ 10918de8d7fSPeter Avalos LogLevel log_level; /* Level for system logging. */ 11018de8d7fSPeter Avalos int hostbased_authentication; /* If true, permit ssh2 hostbased auth */ 11118de8d7fSPeter Avalos int hostbased_uses_name_from_packet_only; /* experimental */ 112e9778795SPeter Avalos char *hostbased_key_types; /* Key types allowed for hostbased */ 113e9778795SPeter Avalos char *hostkeyalgorithms; /* SSH2 server key types */ 114*664f4763Szrj char *ca_sign_algorithms; /* Allowed CA signature algorithms */ 11518de8d7fSPeter Avalos int pubkey_authentication; /* If true, permit ssh2 pubkey authentication. */ 116e9778795SPeter Avalos char *pubkey_key_types; /* Key types allowed for public key */ 11718de8d7fSPeter Avalos int kerberos_authentication; /* If true, permit Kerberos 11818de8d7fSPeter Avalos * authentication. */ 11918de8d7fSPeter Avalos int kerberos_or_local_passwd; /* If true, permit kerberos 12018de8d7fSPeter Avalos * and any other password 12118de8d7fSPeter Avalos * authentication mechanism, 12218de8d7fSPeter Avalos * such as SecurID or 12318de8d7fSPeter Avalos * /etc/passwd */ 12418de8d7fSPeter Avalos int kerberos_ticket_cleanup; /* If true, destroy ticket 12518de8d7fSPeter Avalos * file on logout. */ 12618de8d7fSPeter Avalos int kerberos_get_afs_token; /* If true, try to get AFS token if 12718de8d7fSPeter Avalos * authenticated with Kerberos. */ 12818de8d7fSPeter Avalos int gss_authentication; /* If true, permit GSSAPI authentication */ 12918de8d7fSPeter Avalos int gss_cleanup_creds; /* If true, destroy cred cache on logout */ 130e9778795SPeter Avalos int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */ 13118de8d7fSPeter Avalos int password_authentication; /* If true, permit password 13218de8d7fSPeter Avalos * authentication. */ 13318de8d7fSPeter Avalos int kbd_interactive_authentication; /* If true, permit */ 13418de8d7fSPeter Avalos int challenge_response_authentication; 13518de8d7fSPeter Avalos int permit_empty_passwd; /* If false, do not permit empty 13618de8d7fSPeter Avalos * passwords. */ 13718de8d7fSPeter Avalos int permit_user_env; /* If true, read ~/.ssh/environment */ 138*664f4763Szrj char *permit_user_env_whitelist; /* pattern-list whitelist */ 13918de8d7fSPeter Avalos int compression; /* If true, compression is allowed */ 14036e94dc5SPeter Avalos int allow_tcp_forwarding; /* One of FORWARD_* */ 14136e94dc5SPeter Avalos int allow_streamlocal_forwarding; /* One of FORWARD_* */ 14218de8d7fSPeter Avalos int allow_agent_forwarding; 143ce74bacaSMatthew Dillon int disable_forwarding; 14418de8d7fSPeter Avalos u_int num_allow_users; 145*664f4763Szrj char **allow_users; 14618de8d7fSPeter Avalos u_int num_deny_users; 147*664f4763Szrj char **deny_users; 14818de8d7fSPeter Avalos u_int num_allow_groups; 149*664f4763Szrj char **allow_groups; 15018de8d7fSPeter Avalos u_int num_deny_groups; 151*664f4763Szrj char **deny_groups; 15218de8d7fSPeter Avalos 15318de8d7fSPeter Avalos u_int num_subsystems; 15418de8d7fSPeter Avalos char *subsystem_name[MAX_SUBSYSTEMS]; 15518de8d7fSPeter Avalos char *subsystem_command[MAX_SUBSYSTEMS]; 15618de8d7fSPeter Avalos char *subsystem_args[MAX_SUBSYSTEMS]; 15718de8d7fSPeter Avalos 15818de8d7fSPeter Avalos u_int num_accept_env; 159*664f4763Szrj char **accept_env; 160*664f4763Szrj u_int num_setenv; 161*664f4763Szrj char **setenv; 16218de8d7fSPeter Avalos 16318de8d7fSPeter Avalos int max_startups_begin; 16418de8d7fSPeter Avalos int max_startups_rate; 16518de8d7fSPeter Avalos int max_startups; 16618de8d7fSPeter Avalos int max_authtries; 16718de8d7fSPeter Avalos int max_sessions; 16818de8d7fSPeter Avalos char *banner; /* SSH-2 banner message */ 16918de8d7fSPeter Avalos int use_dns; 17018de8d7fSPeter Avalos int client_alive_interval; /* 17118de8d7fSPeter Avalos * poke the client this often to 17218de8d7fSPeter Avalos * see if it's still there 17318de8d7fSPeter Avalos */ 17418de8d7fSPeter Avalos int client_alive_count_max; /* 17518de8d7fSPeter Avalos * If the client is unresponsive 17618de8d7fSPeter Avalos * for this many intervals above, 17718de8d7fSPeter Avalos * disconnect the session 17818de8d7fSPeter Avalos */ 17918de8d7fSPeter Avalos 1801c188a7fSPeter Avalos u_int num_authkeys_files; /* Files containing public keys */ 181*664f4763Szrj char **authorized_keys_files; 18218de8d7fSPeter Avalos 18318de8d7fSPeter Avalos char *adm_forced_command; 18418de8d7fSPeter Avalos 18518de8d7fSPeter Avalos int use_pam; /* Enable auth via PAM */ 18618de8d7fSPeter Avalos 18718de8d7fSPeter Avalos int permit_tun; 18818de8d7fSPeter Avalos 189*664f4763Szrj char **permitted_opens; /* May also be one of PERMITOPEN_* */ 190*664f4763Szrj u_int num_permitted_opens; 191*664f4763Szrj char **permitted_listens; /* May also be one of PERMITOPEN_* */ 192*664f4763Szrj u_int num_permitted_listens; 19318de8d7fSPeter Avalos 19418de8d7fSPeter Avalos char *chroot_directory; 195856ea928SPeter Avalos char *revoked_keys_file; 196856ea928SPeter Avalos char *trusted_user_ca_keys; 19736e94dc5SPeter Avalos char *authorized_keys_command; 19836e94dc5SPeter Avalos char *authorized_keys_command_user; 199e9778795SPeter Avalos char *authorized_principals_file; 200e9778795SPeter Avalos char *authorized_principals_command; 201e9778795SPeter Avalos char *authorized_principals_command_user; 20236e94dc5SPeter Avalos 20336e94dc5SPeter Avalos int64_t rekey_limit; 20436e94dc5SPeter Avalos int rekey_interval; 20599e85e0dSPeter Avalos 20699e85e0dSPeter Avalos char *version_addendum; /* Appended to SSH banner */ 20736e94dc5SPeter Avalos 20836e94dc5SPeter Avalos u_int num_auth_methods; 209*664f4763Szrj char **auth_methods; 210e9778795SPeter Avalos 211e9778795SPeter Avalos int fingerprint_hash; 212ce74bacaSMatthew Dillon int expose_userauth_info; 213*664f4763Szrj u_int64_t timing_secret; 21418de8d7fSPeter Avalos } ServerOptions; 21518de8d7fSPeter Avalos 21699e85e0dSPeter Avalos /* Information about the incoming connection as used by Match */ 21799e85e0dSPeter Avalos struct connection_info { 21899e85e0dSPeter Avalos const char *user; 21999e85e0dSPeter Avalos const char *host; /* possibly resolved hostname */ 22099e85e0dSPeter Avalos const char *address; /* remote address */ 22199e85e0dSPeter Avalos const char *laddress; /* local address */ 22299e85e0dSPeter Avalos int lport; /* local port */ 223*664f4763Szrj const char *rdomain; /* routing domain if available */ 22499e85e0dSPeter Avalos }; 22599e85e0dSPeter Avalos 22699e85e0dSPeter Avalos 2271c188a7fSPeter Avalos /* 2281c188a7fSPeter Avalos * These are string config options that must be copied between the 2291c188a7fSPeter Avalos * Match sub-config and the main config, and must be sent from the 2301c188a7fSPeter Avalos * privsep slave to the privsep master. We use a macro to ensure all 2311c188a7fSPeter Avalos * the options are copied and the copies are done in the correct order. 23236e94dc5SPeter Avalos * 23336e94dc5SPeter Avalos * NB. an option must appear in servconf.c:copy_set_server_options() or 23436e94dc5SPeter Avalos * COPY_MATCH_STRING_OPTS here but never both. 2351c188a7fSPeter Avalos */ 2361c188a7fSPeter Avalos #define COPY_MATCH_STRING_OPTS() do { \ 2371c188a7fSPeter Avalos M_CP_STROPT(banner); \ 2381c188a7fSPeter Avalos M_CP_STROPT(trusted_user_ca_keys); \ 2391c188a7fSPeter Avalos M_CP_STROPT(revoked_keys_file); \ 24036e94dc5SPeter Avalos M_CP_STROPT(authorized_keys_command); \ 24136e94dc5SPeter Avalos M_CP_STROPT(authorized_keys_command_user); \ 242e9778795SPeter Avalos M_CP_STROPT(authorized_principals_file); \ 243e9778795SPeter Avalos M_CP_STROPT(authorized_principals_command); \ 244e9778795SPeter Avalos M_CP_STROPT(authorized_principals_command_user); \ 245e9778795SPeter Avalos M_CP_STROPT(hostbased_key_types); \ 246e9778795SPeter Avalos M_CP_STROPT(pubkey_key_types); \ 247*664f4763Szrj M_CP_STROPT(ca_sign_algorithms); \ 248*664f4763Szrj M_CP_STROPT(routing_domain); \ 249*664f4763Szrj M_CP_STROPT(permit_user_env_whitelist); \ 2501c188a7fSPeter Avalos M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \ 25199e85e0dSPeter Avalos M_CP_STRARRAYOPT(allow_users, num_allow_users); \ 25299e85e0dSPeter Avalos M_CP_STRARRAYOPT(deny_users, num_deny_users); \ 25399e85e0dSPeter Avalos M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \ 25499e85e0dSPeter Avalos M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \ 25599e85e0dSPeter Avalos M_CP_STRARRAYOPT(accept_env, num_accept_env); \ 25636e94dc5SPeter Avalos M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \ 257*664f4763Szrj M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens); \ 258*664f4763Szrj M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens); \ 2591c188a7fSPeter Avalos } while (0) 2601c188a7fSPeter Avalos 261*664f4763Szrj struct connection_info *get_connection_info(struct ssh *, int, int); 26218de8d7fSPeter Avalos void initialize_server_options(ServerOptions *); 26318de8d7fSPeter Avalos void fill_default_server_options(ServerOptions *); 26418de8d7fSPeter Avalos int process_server_config_line(ServerOptions *, char *, const char *, int, 26599e85e0dSPeter Avalos int *, struct connection_info *); 266ce74bacaSMatthew Dillon void process_permitopen(struct ssh *ssh, ServerOptions *options); 267*664f4763Szrj void load_server_config(const char *, struct sshbuf *); 268*664f4763Szrj void parse_server_config(ServerOptions *, const char *, struct sshbuf *, 26999e85e0dSPeter Avalos struct connection_info *); 27099e85e0dSPeter Avalos void parse_server_match_config(ServerOptions *, struct connection_info *); 27199e85e0dSPeter Avalos int parse_server_match_testspec(struct connection_info *, char *); 27299e85e0dSPeter Avalos int server_match_spec_complete(struct connection_info *); 27318de8d7fSPeter Avalos void copy_set_server_options(ServerOptions *, ServerOptions *, int); 27418de8d7fSPeter Avalos void dump_config(ServerOptions *); 275856ea928SPeter Avalos char *derelativise_path(const char *); 276*664f4763Szrj void servconf_add_hostkey(const char *, const int, 277*664f4763Szrj ServerOptions *, const char *path, int); 278*664f4763Szrj void servconf_add_hostcert(const char *, const int, 279*664f4763Szrj ServerOptions *, const char *path); 28018de8d7fSPeter Avalos 28118de8d7fSPeter Avalos #endif /* SERVCONF_H */ 282