1 /* $OpenBSD: servconf.h,v 1.169 2024/10/14 01:57:50 djm Exp $ */ 2 3 /* 4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 5 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 6 * All rights reserved 7 * Definitions for server configuration data and for the functions reading it. 8 * 9 * As far as I am concerned, the code I have written for this software 10 * can be used freely for any purpose. Any derived versions of this 11 * software must be clearly marked as such, and if the derived work is 12 * incompatible with the protocol description in the RFC file, it must be 13 * called by a name other than "ssh" or "Secure Shell". 14 */ 15 16 #ifndef SERVCONF_H 17 #define SERVCONF_H 18 19 #include <sys/queue.h> 20 21 #define MAX_PORTS 256 /* Max # ports. */ 22 23 /* permit_root_login */ 24 #define PERMIT_NOT_SET -1 25 #define PERMIT_NO 0 26 #define PERMIT_FORCED_ONLY 1 27 #define PERMIT_NO_PASSWD 2 28 #define PERMIT_YES 3 29 30 /* PermitOpen */ 31 #define PERMITOPEN_ANY 0 32 #define PERMITOPEN_NONE -2 33 34 /* IgnoreRhosts */ 35 #define IGNORE_RHOSTS_NO 0 36 #define IGNORE_RHOSTS_YES 1 37 #define IGNORE_RHOSTS_SHOSTS 2 38 39 #define DEFAULT_AUTH_FAIL_MAX 6 /* Default for MaxAuthTries */ 40 #define DEFAULT_SESSIONS_MAX 10 /* Default for MaxSessions */ 41 42 /* Magic name for internal sftp-server */ 43 #define INTERNAL_SFTP_NAME "internal-sftp" 44 45 /* PubkeyAuthOptions flags */ 46 #define PUBKEYAUTH_TOUCH_REQUIRED (1) 47 #define PUBKEYAUTH_VERIFY_REQUIRED (1<<1) 48 49 struct ssh; 50 51 /* 52 * Used to store addresses from ListenAddr directives. These may be 53 * incomplete, as they may specify addresses that need to be merged 54 * with any ports requested by ListenPort. 55 */ 56 struct queued_listenaddr { 57 char *addr; 58 int port; /* <=0 if unspecified */ 59 char *rdomain; 60 }; 61 62 /* Resolved listen addresses, grouped by optional routing domain */ 63 struct listenaddr { 64 char *rdomain; 65 struct addrinfo *addrs; 66 }; 67 68 #define PER_SOURCE_PENALTY_OVERFLOW_DENY_ALL 1 69 #define PER_SOURCE_PENALTY_OVERFLOW_PERMISSIVE 2 70 struct per_source_penalty { 71 int enabled; 72 int max_sources4; 73 int max_sources6; 74 int overflow_mode; 75 int overflow_mode6; 76 int penalty_crash; 77 int penalty_grace; 78 int penalty_authfail; 79 int penalty_noauth; 80 int penalty_refuseconnection; 81 int penalty_max; 82 int penalty_min; 83 }; 84 85 typedef struct { 86 u_int num_ports; 87 u_int ports_from_cmdline; 88 int ports[MAX_PORTS]; /* Port number to listen on. */ 89 struct queued_listenaddr *queued_listen_addrs; 90 u_int num_queued_listens; 91 struct listenaddr *listen_addrs; 92 u_int num_listen_addrs; 93 int address_family; /* Address family used by the server. */ 94 95 char *routing_domain; /* Bind session to routing domain */ 96 97 char **host_key_files; /* Files containing host keys. */ 98 int *host_key_file_userprovided; /* Key was specified by user. */ 99 u_int num_host_key_files; /* Number of files for host keys. */ 100 char **host_cert_files; /* Files containing host certs. */ 101 u_int num_host_cert_files; /* Number of files for host certs. */ 102 103 char *host_key_agent; /* ssh-agent socket for host keys. */ 104 char *pid_file; /* Where to put our pid */ 105 char *moduli_file; /* moduli file for DH-GEX */ 106 int login_grace_time; /* Disconnect if no auth in this time 107 * (sec). */ 108 int permit_root_login; /* PERMIT_*, see above */ 109 int ignore_rhosts; /* Ignore .rhosts and .shosts. */ 110 int ignore_user_known_hosts; /* Ignore ~/.ssh/known_hosts 111 * for RhostsRsaAuth */ 112 int print_motd; /* If true, print /etc/motd. */ 113 int print_lastlog; /* If true, print lastlog */ 114 int x11_forwarding; /* If true, permit inet (spoofing) X11 fwd. */ 115 int x11_display_offset; /* What DISPLAY number to start 116 * searching at */ 117 int x11_use_localhost; /* If true, use localhost for fake X11 server. */ 118 char *xauth_location; /* Location of xauth program */ 119 int permit_tty; /* If false, deny pty allocation */ 120 int permit_user_rc; /* If false, deny ~/.ssh/rc execution */ 121 int strict_modes; /* If true, require string home dir modes. */ 122 int tcp_keep_alive; /* If true, set SO_KEEPALIVE. */ 123 int ip_qos_interactive; /* IP ToS/DSCP/class for interactive */ 124 int ip_qos_bulk; /* IP ToS/DSCP/class for bulk traffic */ 125 char *ciphers; /* Supported SSH2 ciphers. */ 126 char *macs; /* Supported SSH2 macs. */ 127 char *kex_algorithms; /* SSH2 kex methods in order of preference. */ 128 struct ForwardOptions fwd_opts; /* forwarding options */ 129 SyslogFacility log_facility; /* Facility for system logging. */ 130 LogLevel log_level; /* Level for system logging. */ 131 u_int num_log_verbose; /* Verbose log overrides */ 132 char **log_verbose; 133 int hostbased_authentication; /* If true, permit ssh2 hostbased auth */ 134 int hostbased_uses_name_from_packet_only; /* experimental */ 135 char *hostbased_accepted_algos; /* Algos allowed for hostbased */ 136 char *hostkeyalgorithms; /* SSH2 server key types */ 137 char *ca_sign_algorithms; /* Allowed CA signature algorithms */ 138 int pubkey_authentication; /* If true, permit ssh2 pubkey authentication. */ 139 char *pubkey_accepted_algos; /* Signature algos allowed for pubkey */ 140 int pubkey_auth_options; /* -1 or mask of PUBKEYAUTH_* flags */ 141 int kerberos_authentication; /* If true, permit Kerberos 142 * authentication. */ 143 int kerberos_or_local_passwd; /* If true, permit kerberos 144 * and any other password 145 * authentication mechanism, 146 * such as SecurID or 147 * /etc/passwd */ 148 int kerberos_ticket_cleanup; /* If true, destroy ticket 149 * file on logout. */ 150 int kerberos_get_afs_token; /* If true, try to get AFS token if 151 * authenticated with Kerberos. */ 152 int gss_authentication; /* If true, permit GSSAPI authentication */ 153 int gss_cleanup_creds; /* If true, destroy cred cache on logout */ 154 int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */ 155 int password_authentication; /* If true, permit password 156 * authentication. */ 157 int kbd_interactive_authentication; /* If true, permit */ 158 int permit_empty_passwd; /* If false, do not permit empty 159 * passwords. */ 160 int permit_user_env; /* If true, read ~/.ssh/environment */ 161 char *permit_user_env_allowlist; /* pattern-list of allowed env names */ 162 int compression; /* If true, compression is allowed */ 163 int allow_tcp_forwarding; /* One of FORWARD_* */ 164 int allow_streamlocal_forwarding; /* One of FORWARD_* */ 165 int allow_agent_forwarding; 166 int disable_forwarding; 167 u_int num_allow_users; 168 char **allow_users; 169 u_int num_deny_users; 170 char **deny_users; 171 u_int num_allow_groups; 172 char **allow_groups; 173 u_int num_deny_groups; 174 char **deny_groups; 175 176 u_int num_subsystems; 177 char **subsystem_name; 178 char **subsystem_command; 179 char **subsystem_args; 180 181 u_int num_accept_env; 182 char **accept_env; 183 u_int num_setenv; 184 char **setenv; 185 186 int max_startups_begin; 187 int max_startups_rate; 188 int max_startups; 189 int per_source_max_startups; 190 int per_source_masklen_ipv4; 191 int per_source_masklen_ipv6; 192 char *per_source_penalty_exempt; 193 struct per_source_penalty per_source_penalty; 194 int max_authtries; 195 int max_sessions; 196 char *banner; /* SSH-2 banner message */ 197 int use_dns; 198 int client_alive_interval; /* 199 * poke the client this often to 200 * see if it's still there 201 */ 202 int client_alive_count_max; /* 203 * If the client is unresponsive 204 * for this many intervals above, 205 * disconnect the session 206 */ 207 208 u_int num_authkeys_files; /* Files containing public keys */ 209 char **authorized_keys_files; 210 211 char *adm_forced_command; 212 213 int permit_tun; 214 215 char **permitted_opens; /* May also be one of PERMITOPEN_* */ 216 u_int num_permitted_opens; 217 char **permitted_listens; /* May also be one of PERMITOPEN_* */ 218 u_int num_permitted_listens; 219 220 char *chroot_directory; 221 char *revoked_keys_file; 222 char *trusted_user_ca_keys; 223 char *authorized_keys_command; 224 char *authorized_keys_command_user; 225 char *authorized_principals_file; 226 char *authorized_principals_command; 227 char *authorized_principals_command_user; 228 229 int64_t rekey_limit; 230 int rekey_interval; 231 232 char *version_addendum; /* Appended to SSH banner */ 233 234 u_int num_auth_methods; 235 char **auth_methods; 236 237 int fingerprint_hash; 238 int expose_userauth_info; 239 u_int64_t timing_secret; 240 char *sk_provider; 241 int required_rsa_size; /* minimum size of RSA keys */ 242 243 char **channel_timeouts; /* inactivity timeout by channel type */ 244 u_int num_channel_timeouts; 245 246 int unused_connection_timeout; 247 248 char *sshd_session_path; 249 char *sshd_auth_path; 250 251 int refuse_connection; 252 } ServerOptions; 253 254 /* Information about the incoming connection as used by Match */ 255 struct connection_info { 256 const char *user; 257 int user_invalid; 258 const char *host; /* possibly resolved hostname */ 259 const char *address; /* remote address */ 260 const char *laddress; /* local address */ 261 int lport; /* local port */ 262 const char *rdomain; /* routing domain if available */ 263 int test; /* test mode, allow some attributes to be 264 * unspecified */ 265 }; 266 267 /* List of included files for re-exec from the parsed configuration */ 268 struct include_item { 269 char *selector; 270 char *filename; 271 struct sshbuf *contents; 272 TAILQ_ENTRY(include_item) entry; 273 }; 274 TAILQ_HEAD(include_list, include_item); 275 276 277 /* 278 * These are string config options that must be copied between the 279 * Match sub-config and the main config, and must be sent from the 280 * privsep child to the privsep master. We use a macro to ensure all 281 * the options are copied and the copies are done in the correct order. 282 * 283 * NB. an option must appear in servconf.c:copy_set_server_options() or 284 * COPY_MATCH_STRING_OPTS here but never both. 285 */ 286 #define COPY_MATCH_STRING_OPTS() do { \ 287 M_CP_STROPT(banner); \ 288 M_CP_STROPT(trusted_user_ca_keys); \ 289 M_CP_STROPT(revoked_keys_file); \ 290 M_CP_STROPT(authorized_keys_command); \ 291 M_CP_STROPT(authorized_keys_command_user); \ 292 M_CP_STROPT(authorized_principals_file); \ 293 M_CP_STROPT(authorized_principals_command); \ 294 M_CP_STROPT(authorized_principals_command_user); \ 295 M_CP_STROPT(hostbased_accepted_algos); \ 296 M_CP_STROPT(pubkey_accepted_algos); \ 297 M_CP_STROPT(ca_sign_algorithms); \ 298 M_CP_STROPT(routing_domain); \ 299 M_CP_STROPT(permit_user_env_allowlist); \ 300 M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \ 301 M_CP_STRARRAYOPT(allow_users, num_allow_users); \ 302 M_CP_STRARRAYOPT(deny_users, num_deny_users); \ 303 M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \ 304 M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \ 305 M_CP_STRARRAYOPT(accept_env, num_accept_env); \ 306 M_CP_STRARRAYOPT(setenv, num_setenv); \ 307 M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \ 308 M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens); \ 309 M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens); \ 310 M_CP_STRARRAYOPT(channel_timeouts, num_channel_timeouts); \ 311 M_CP_STRARRAYOPT(log_verbose, num_log_verbose); \ 312 M_CP_STRARRAYOPT(subsystem_name, num_subsystems); \ 313 M_CP_STRARRAYOPT(subsystem_command, num_subsystems); \ 314 M_CP_STRARRAYOPT(subsystem_args, num_subsystems); \ 315 } while (0) 316 317 void initialize_server_options(ServerOptions *); 318 void fill_default_server_options(ServerOptions *); 319 int process_server_config_line(ServerOptions *, char *, const char *, int, 320 int *, struct connection_info *, struct include_list *includes); 321 void load_server_config(const char *, struct sshbuf *); 322 void parse_server_config(ServerOptions *, const char *, struct sshbuf *, 323 struct include_list *includes, struct connection_info *, int); 324 void parse_server_match_config(ServerOptions *, 325 struct include_list *includes, struct connection_info *); 326 int parse_server_match_testspec(struct connection_info *, char *); 327 void servconf_merge_subsystems(ServerOptions *, ServerOptions *); 328 void copy_set_server_options(ServerOptions *, ServerOptions *, int); 329 void dump_config(ServerOptions *); 330 char *derelativise_path(const char *); 331 void servconf_add_hostkey(const char *, const int, 332 ServerOptions *, const char *path, int); 333 void servconf_add_hostcert(const char *, const int, 334 ServerOptions *, const char *path); 335 336 #endif /* SERVCONF_H */ 337