1*9469f4f1Schristos /* $NetBSD: servconf.h,v 1.32 2024/09/24 21:32:18 christos Exp $ */ 2*9469f4f1Schristos /* $OpenBSD: servconf.h,v 1.168 2024/09/15 01:18:26 djm Exp $ */ 3ca32bd8dSchristos 4ca32bd8dSchristos /* 5ca32bd8dSchristos * Author: Tatu Ylonen <ylo@cs.hut.fi> 6ca32bd8dSchristos * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 7ca32bd8dSchristos * All rights reserved 8ca32bd8dSchristos * Definitions for server configuration data and for the functions reading it. 9ca32bd8dSchristos * 10ca32bd8dSchristos * As far as I am concerned, the code I have written for this software 11ca32bd8dSchristos * can be used freely for any purpose. Any derived versions of this 12ca32bd8dSchristos * software must be clearly marked as such, and if the derived work is 13ca32bd8dSchristos * incompatible with the protocol description in the RFC file, it must be 14ca32bd8dSchristos * called by a name other than "ssh" or "Secure Shell". 15ca32bd8dSchristos */ 16ca32bd8dSchristos 17ca32bd8dSchristos #ifndef SERVCONF_H 18ca32bd8dSchristos #define SERVCONF_H 19ca32bd8dSchristos 20aef795aaSadam #ifdef WITH_LDAP_PUBKEY 21aef795aaSadam #include "ldapauth.h" 22aef795aaSadam #endif 23aef795aaSadam 24ed75d7a8Schristos #include <sys/queue.h> 25ed75d7a8Schristos 26ca32bd8dSchristos #define MAX_PORTS 256 /* Max # ports. */ 27ca32bd8dSchristos 28ca32bd8dSchristos /* permit_root_login */ 29ca32bd8dSchristos #define PERMIT_NOT_SET -1 30ca32bd8dSchristos #define PERMIT_NO 0 31ca32bd8dSchristos #define PERMIT_FORCED_ONLY 1 32ca32bd8dSchristos #define PERMIT_NO_PASSWD 2 33ca32bd8dSchristos #define PERMIT_YES 3 34ca32bd8dSchristos 357a183406Schristos /* PermitOpen */ 367a183406Schristos #define PERMITOPEN_ANY 0 377a183406Schristos #define PERMITOPEN_NONE -2 387a183406Schristos 398db691beSchristos /* IgnoreRhosts */ 408db691beSchristos #define IGNORE_RHOSTS_NO 0 418db691beSchristos #define IGNORE_RHOSTS_YES 1 428db691beSchristos #define IGNORE_RHOSTS_SHOSTS 2 438db691beSchristos 44ca32bd8dSchristos #define DEFAULT_AUTH_FAIL_MAX 6 /* Default for MaxAuthTries */ 45ca32bd8dSchristos #define DEFAULT_SESSIONS_MAX 10 /* Default for MaxSessions */ 46ca32bd8dSchristos 47ca32bd8dSchristos /* Magic name for internal sftp-server */ 48ca32bd8dSchristos #define INTERNAL_SFTP_NAME "internal-sftp" 49ca32bd8dSchristos 50ed75d7a8Schristos /* PubkeyAuthOptions flags */ 512d3b0f52Schristos #define PUBKEYAUTH_TOUCH_REQUIRED (1) 522d3b0f52Schristos #define PUBKEYAUTH_VERIFY_REQUIRED (1<<1) 53ed75d7a8Schristos 547a183406Schristos struct ssh; 557a183406Schristos 56ffae97bbSchristos /* 57ffae97bbSchristos * Used to store addresses from ListenAddr directives. These may be 58ffae97bbSchristos * incomplete, as they may specify addresses that need to be merged 59ffae97bbSchristos * with any ports requested by ListenPort. 60ffae97bbSchristos */ 61ffae97bbSchristos struct queued_listenaddr { 62ffae97bbSchristos char *addr; 63ffae97bbSchristos int port; /* <=0 if unspecified */ 64ffae97bbSchristos char *rdomain; 65ffae97bbSchristos }; 66ffae97bbSchristos 67ffae97bbSchristos /* Resolved listen addresses, grouped by optional routing domain */ 68ffae97bbSchristos struct listenaddr { 69ffae97bbSchristos char *rdomain; 70ffae97bbSchristos struct addrinfo *addrs; 71ffae97bbSchristos }; 72ffae97bbSchristos 731c7715ddSchristos #define PER_SOURCE_PENALTY_OVERFLOW_DENY_ALL 1 741c7715ddSchristos #define PER_SOURCE_PENALTY_OVERFLOW_PERMISSIVE 2 751c7715ddSchristos struct per_source_penalty { 761c7715ddSchristos int enabled; 771c7715ddSchristos int max_sources4; 781c7715ddSchristos int max_sources6; 791c7715ddSchristos int overflow_mode; 801c7715ddSchristos int overflow_mode6; 811c7715ddSchristos int penalty_crash; 821c7715ddSchristos int penalty_grace; 831c7715ddSchristos int penalty_authfail; 841c7715ddSchristos int penalty_noauth; 85*9469f4f1Schristos int penalty_refuseconnection; 861c7715ddSchristos int penalty_max; 871c7715ddSchristos int penalty_min; 881c7715ddSchristos }; 891c7715ddSchristos 90ca32bd8dSchristos typedef struct { 91ca32bd8dSchristos u_int num_ports; 92ca32bd8dSchristos u_int ports_from_cmdline; 93ca32bd8dSchristos int ports[MAX_PORTS]; /* Port number to listen on. */ 94ffae97bbSchristos struct queued_listenaddr *queued_listen_addrs; 954054ffb0Schristos u_int num_queued_listens; 96ffae97bbSchristos struct listenaddr *listen_addrs; 97ffae97bbSchristos u_int num_listen_addrs; 98ca32bd8dSchristos int address_family; /* Address family used by the server. */ 99ffae97bbSchristos 100ffae97bbSchristos char *routing_domain; /* Bind session to routing domain */ 101ffae97bbSchristos 102ffae97bbSchristos char **host_key_files; /* Files containing host keys. */ 103aa36fcacSchristos int *host_key_file_userprovided; /* Key was specified by user. */ 104ffae97bbSchristos u_int num_host_key_files; /* Number of files for host keys. */ 105ffae97bbSchristos char **host_cert_files; /* Files containing host certs. */ 106ffae97bbSchristos u_int num_host_cert_files; /* Number of files for host certs. */ 107ffae97bbSchristos 10800a838c4Schristos char *host_key_agent; /* ssh-agent socket for host keys. */ 109ca32bd8dSchristos char *pid_file; /* Where to put our pid */ 110e8c0841bSchristos char *moduli_file; /* moduli file for DH-GEX */ 111ca32bd8dSchristos int login_grace_time; /* Disconnect if no auth in this time 112ca32bd8dSchristos * (sec). */ 113ca32bd8dSchristos int permit_root_login; /* PERMIT_*, see above */ 114ca32bd8dSchristos int ignore_rhosts; /* Ignore .rhosts and .shosts. */ 115313c6c94Schristos int ignore_root_rhosts; /* Ignore .rhosts and .shosts for root; 116313c6c94Schristos defaults to ignore_rhosts if not 117313c6c94Schristos given. */ 118ca32bd8dSchristos int ignore_user_known_hosts; /* Ignore ~/.ssh/known_hosts 119ca32bd8dSchristos * for RhostsRsaAuth */ 120ca32bd8dSchristos int print_motd; /* If true, print /etc/motd. */ 121ca32bd8dSchristos int print_lastlog; /* If true, print lastlog */ 122ca32bd8dSchristos int x11_forwarding; /* If true, permit inet (spoofing) X11 fwd. */ 123ca32bd8dSchristos int x11_display_offset; /* What DISPLAY number to start 124ca32bd8dSchristos * searching at */ 125ca32bd8dSchristos int x11_use_localhost; /* If true, use localhost for fake X11 server. */ 126ca32bd8dSchristos char *xauth_location; /* Location of xauth program */ 1278a4530f9Schristos int permit_tty; /* If false, deny pty allocation */ 1288a4530f9Schristos int permit_user_rc; /* If false, deny ~/.ssh/rc execution */ 129ca32bd8dSchristos int strict_modes; /* If true, require string home dir modes. */ 130ca32bd8dSchristos int tcp_keep_alive; /* If true, set SO_KEEPALIVE. */ 131185c8f97Schristos int ip_qos_interactive; /* IP ToS/DSCP/class for interactive */ 132185c8f97Schristos int ip_qos_bulk; /* IP ToS/DSCP/class for bulk traffic */ 133ca32bd8dSchristos char *ciphers; /* Supported SSH2 ciphers. */ 134ca32bd8dSchristos char *macs; /* Supported SSH2 macs. */ 135185c8f97Schristos char *kex_algorithms; /* SSH2 kex methods in order of preference. */ 1368a4530f9Schristos struct ForwardOptions fwd_opts; /* forwarding options */ 137ca32bd8dSchristos SyslogFacility log_facility; /* Facility for system logging. */ 138ca32bd8dSchristos LogLevel log_level; /* Level for system logging. */ 13917418e98Schristos u_int num_log_verbose; /* Verbose log overrides */ 14017418e98Schristos char **log_verbose; 141ca32bd8dSchristos int hostbased_authentication; /* If true, permit ssh2 hostbased auth */ 142ca32bd8dSchristos int hostbased_uses_name_from_packet_only; /* experimental */ 14317418e98Schristos char *hostbased_accepted_algos; /* Algos allowed for hostbased */ 1448395c133Schristos char *hostkeyalgorithms; /* SSH2 server key types */ 145aa36fcacSchristos char *ca_sign_algorithms; /* Allowed CA signature algorithms */ 146ca32bd8dSchristos int pubkey_authentication; /* If true, permit ssh2 pubkey authentication. */ 14717418e98Schristos char *pubkey_accepted_algos; /* Signature algos allowed for pubkey */ 148ed75d7a8Schristos int pubkey_auth_options; /* -1 or mask of PUBKEYAUTH_* flags */ 149ca32bd8dSchristos int kerberos_authentication; /* If true, permit Kerberos 150ca32bd8dSchristos * authentication. */ 151ca32bd8dSchristos int kerberos_or_local_passwd; /* If true, permit kerberos 152ca32bd8dSchristos * and any other password 153ca32bd8dSchristos * authentication mechanism, 154ca32bd8dSchristos * such as SecurID or 155ca32bd8dSchristos * /etc/passwd */ 156ca32bd8dSchristos int kerberos_ticket_cleanup; /* If true, destroy ticket 157ca32bd8dSchristos * file on logout. */ 158313c6c94Schristos int kerberos_tgt_passing; /* If true, permit Kerberos TGT 159313c6c94Schristos * passing. */ 160ca32bd8dSchristos int kerberos_get_afs_token; /* If true, try to get AFS token if 161ca32bd8dSchristos * authenticated with Kerberos. */ 162313c6c94Schristos #ifdef AFS 163313c6c94Schristos int afs_token_passing; /* If true, permit AFS token passing. */ 164313c6c94Schristos #endif 165ca32bd8dSchristos int gss_authentication; /* If true, permit GSSAPI authentication */ 166ca32bd8dSchristos int gss_cleanup_creds; /* If true, destroy cred cache on logout */ 1674054ffb0Schristos int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */ 168ca32bd8dSchristos int password_authentication; /* If true, permit password 169ca32bd8dSchristos * authentication. */ 170ca32bd8dSchristos int kbd_interactive_authentication; /* If true, permit */ 171ca32bd8dSchristos int permit_empty_passwd; /* If false, do not permit empty 172ca32bd8dSchristos * passwords. */ 173ca32bd8dSchristos int permit_user_env; /* If true, read ~/.ssh/environment */ 1742d3b0f52Schristos char *permit_user_env_allowlist; /* pattern-list of allowed env names */ 175ca32bd8dSchristos int compression; /* If true, compression is allowed */ 176ce11a51fSchristos int allow_tcp_forwarding; /* One of FORWARD_* */ 1778a4530f9Schristos int allow_streamlocal_forwarding; /* One of FORWARD_* */ 178ca32bd8dSchristos int allow_agent_forwarding; 179ee85abc4Schristos int disable_forwarding; 180ca32bd8dSchristos u_int num_allow_users; 181ffae97bbSchristos char **allow_users; 182ca32bd8dSchristos u_int num_deny_users; 183ffae97bbSchristos char **deny_users; 184ca32bd8dSchristos u_int num_allow_groups; 185ffae97bbSchristos char **allow_groups; 186ca32bd8dSchristos u_int num_deny_groups; 187ffae97bbSchristos char **deny_groups; 188ca32bd8dSchristos 189ca32bd8dSchristos u_int num_subsystems; 190a629fefcSchristos char **subsystem_name; 191a629fefcSchristos char **subsystem_command; 192a629fefcSchristos char **subsystem_args; 193ca32bd8dSchristos 194ca32bd8dSchristos u_int num_accept_env; 195ffae97bbSchristos char **accept_env; 19655a4608bSchristos u_int num_setenv; 19755a4608bSchristos char **setenv; 198ca32bd8dSchristos 199ca32bd8dSchristos int max_startups_begin; 200ca32bd8dSchristos int max_startups_rate; 201ca32bd8dSchristos int max_startups; 20217418e98Schristos int per_source_max_startups; 20317418e98Schristos int per_source_masklen_ipv4; 20417418e98Schristos int per_source_masklen_ipv6; 2051c7715ddSchristos char *per_source_penalty_exempt; 2061c7715ddSchristos struct per_source_penalty per_source_penalty; 207ca32bd8dSchristos int max_authtries; 208ca32bd8dSchristos int max_sessions; 209ca32bd8dSchristos char *banner; /* SSH-2 banner message */ 210ca32bd8dSchristos int use_dns; 211ca32bd8dSchristos int client_alive_interval; /* 212ca32bd8dSchristos * poke the client this often to 213ca32bd8dSchristos * see if it's still there 214ca32bd8dSchristos */ 215ca32bd8dSchristos int client_alive_count_max; /* 216ca32bd8dSchristos * If the client is unresponsive 217ca32bd8dSchristos * for this many intervals above, 218ca32bd8dSchristos * disconnect the session 219ca32bd8dSchristos */ 220ca32bd8dSchristos 2216f47b660Schristos u_int num_authkeys_files; /* Files containing public keys */ 222ffae97bbSchristos char **authorized_keys_files; 223ca32bd8dSchristos 224313c6c94Schristos int use_pam; /* Enable auth via PAM */ 2251c7715ddSchristos char *pam_service_name; 226313c6c94Schristos int none_enabled; /* enable NONE cipher switch */ 227313c6c94Schristos int tcp_rcv_buf_poll; /* poll tcp rcv window in autotuning kernels*/ 228313c6c94Schristos int hpn_disabled; /* disable hpn functionality. false by default */ 229313c6c94Schristos int hpn_buffer_size; /* set the hpn buffer size - default 3MB */ 230313c6c94Schristos 231ca32bd8dSchristos char *adm_forced_command; 232ca32bd8dSchristos 233ca32bd8dSchristos int permit_tun; 234aef795aaSadam #ifdef WITH_LDAP_PUBKEY 235aef795aaSadam ldap_opt_t lpk; 236aef795aaSadam #endif 237ca32bd8dSchristos 23855a4608bSchristos char **permitted_opens; /* May also be one of PERMITOPEN_* */ 23955a4608bSchristos u_int num_permitted_opens; 24055a4608bSchristos char **permitted_listens; /* May also be one of PERMITOPEN_* */ 24155a4608bSchristos u_int num_permitted_listens; 242ca32bd8dSchristos 243ca32bd8dSchristos char *chroot_directory; 24434b27b53Sadam char *revoked_keys_file; 24534b27b53Sadam char *trusted_user_ca_keys; 246ce11a51fSchristos char *authorized_keys_command; 247ce11a51fSchristos char *authorized_keys_command_user; 2484054ffb0Schristos char *authorized_principals_file; 2494054ffb0Schristos char *authorized_principals_command; 2504054ffb0Schristos char *authorized_principals_command_user; 2512649c700Schristos 25200a838c4Schristos int64_t rekey_limit; 25300a838c4Schristos int rekey_interval; 25400a838c4Schristos 2552649c700Schristos char *version_addendum; /* Appended to SSH banner */ 256ce11a51fSchristos 257ce11a51fSchristos u_int num_auth_methods; 258ffae97bbSchristos char **auth_methods; 259e4d43b82Schristos 260e4d43b82Schristos int fingerprint_hash; 2617a183406Schristos int expose_userauth_info; 26255a4608bSchristos u_int64_t timing_secret; 263ed75d7a8Schristos char *sk_provider; 264e160b4e8Schristos int required_rsa_size; /* minimum size of RSA keys */ 265b1066cf3Schristos 266b1066cf3Schristos char **channel_timeouts; /* inactivity timeout by channel type */ 267b1066cf3Schristos u_int num_channel_timeouts; 268b1066cf3Schristos 269b1066cf3Schristos int unused_connection_timeout; 2701c7715ddSchristos 2711c7715ddSchristos char *sshd_session_path; 272*9469f4f1Schristos 273*9469f4f1Schristos int refuse_connection; 274ca32bd8dSchristos } ServerOptions; 275ca32bd8dSchristos 2762649c700Schristos /* Information about the incoming connection as used by Match */ 2772649c700Schristos struct connection_info { 2782649c700Schristos const char *user; 279*9469f4f1Schristos int user_invalid; 2802649c700Schristos const char *host; /* possibly resolved hostname */ 2812649c700Schristos const char *address; /* remote address */ 2822649c700Schristos const char *laddress; /* local address */ 2832649c700Schristos int lport; /* local port */ 284ffae97bbSchristos const char *rdomain; /* routing domain if available */ 285cd4ada6aSchristos int test; /* test mode, allow some attributes to be 286cd4ada6aSchristos * unspecified */ 2872649c700Schristos }; 2882649c700Schristos 289ed75d7a8Schristos /* List of included files for re-exec from the parsed configuration */ 290ed75d7a8Schristos struct include_item { 291ed75d7a8Schristos char *selector; 292ed75d7a8Schristos char *filename; 293ed75d7a8Schristos struct sshbuf *contents; 294ed75d7a8Schristos TAILQ_ENTRY(include_item) entry; 295ed75d7a8Schristos }; 296ed75d7a8Schristos TAILQ_HEAD(include_list, include_item); 297ed75d7a8Schristos 2982649c700Schristos 2996f47b660Schristos /* 3006f47b660Schristos * These are string config options that must be copied between the 3016f47b660Schristos * Match sub-config and the main config, and must be sent from the 3022d3b0f52Schristos * privsep child to the privsep master. We use a macro to ensure all 3036f47b660Schristos * the options are copied and the copies are done in the correct order. 3048a4530f9Schristos * 3058a4530f9Schristos * NB. an option must appear in servconf.c:copy_set_server_options() or 3068a4530f9Schristos * COPY_MATCH_STRING_OPTS here but never both. 3076f47b660Schristos */ 3086f47b660Schristos #define COPY_MATCH_STRING_OPTS() do { \ 3096f47b660Schristos M_CP_STROPT(banner); \ 3106f47b660Schristos M_CP_STROPT(trusted_user_ca_keys); \ 3116f47b660Schristos M_CP_STROPT(revoked_keys_file); \ 312ce11a51fSchristos M_CP_STROPT(authorized_keys_command); \ 313ce11a51fSchristos M_CP_STROPT(authorized_keys_command_user); \ 3144054ffb0Schristos M_CP_STROPT(authorized_principals_file); \ 3154054ffb0Schristos M_CP_STROPT(authorized_principals_command); \ 3164054ffb0Schristos M_CP_STROPT(authorized_principals_command_user); \ 31717418e98Schristos M_CP_STROPT(hostbased_accepted_algos); \ 31817418e98Schristos M_CP_STROPT(pubkey_accepted_algos); \ 319aa36fcacSchristos M_CP_STROPT(ca_sign_algorithms); \ 320ffae97bbSchristos M_CP_STROPT(routing_domain); \ 3212d3b0f52Schristos M_CP_STROPT(permit_user_env_allowlist); \ 3226f47b660Schristos M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \ 3232649c700Schristos M_CP_STRARRAYOPT(allow_users, num_allow_users); \ 3242649c700Schristos M_CP_STRARRAYOPT(deny_users, num_deny_users); \ 3252649c700Schristos M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \ 3262649c700Schristos M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \ 3272649c700Schristos M_CP_STRARRAYOPT(accept_env, num_accept_env); \ 32817418e98Schristos M_CP_STRARRAYOPT(setenv, num_setenv); \ 329ce11a51fSchristos M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \ 330ffae97bbSchristos M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens); \ 33155a4608bSchristos M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens); \ 332b1066cf3Schristos M_CP_STRARRAYOPT(channel_timeouts, num_channel_timeouts); \ 33317418e98Schristos M_CP_STRARRAYOPT(log_verbose, num_log_verbose); \ 334a629fefcSchristos M_CP_STRARRAYOPT(subsystem_name, num_subsystems); \ 335a629fefcSchristos M_CP_STRARRAYOPT(subsystem_command, num_subsystems); \ 336a629fefcSchristos M_CP_STRARRAYOPT(subsystem_args, num_subsystems); \ 3376f47b660Schristos } while (0) 3386f47b660Schristos 339ca32bd8dSchristos void initialize_server_options(ServerOptions *); 340ca32bd8dSchristos void fill_default_server_options(ServerOptions *); 341ca32bd8dSchristos int process_server_config_line(ServerOptions *, char *, const char *, int, 342ed75d7a8Schristos int *, struct connection_info *, struct include_list *includes); 34355a4608bSchristos void load_server_config(const char *, struct sshbuf *); 34455a4608bSchristos void parse_server_config(ServerOptions *, const char *, struct sshbuf *, 345c4271af5Schristos struct include_list *includes, struct connection_info *, int); 346ed75d7a8Schristos void parse_server_match_config(ServerOptions *, 347ed75d7a8Schristos struct include_list *includes, struct connection_info *); 3482649c700Schristos int parse_server_match_testspec(struct connection_info *, char *); 349a629fefcSchristos void servconf_merge_subsystems(ServerOptions *, ServerOptions *); 350ca32bd8dSchristos void copy_set_server_options(ServerOptions *, ServerOptions *, int); 351ca32bd8dSchristos void dump_config(ServerOptions *); 35234b27b53Sadam char *derelativise_path(const char *); 353ffae97bbSchristos void servconf_add_hostkey(const char *, const int, 354aa36fcacSchristos ServerOptions *, const char *path, int); 355ffae97bbSchristos void servconf_add_hostcert(const char *, const int, 356ffae97bbSchristos ServerOptions *, const char *path); 357ca32bd8dSchristos 358ca32bd8dSchristos #endif /* SERVCONF_H */ 359