1 /* $OpenBSD: servconf.h,v 1.163 2024/05/23 23:47:16 jsg 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 typedef struct { 69 u_int num_ports; 70 u_int ports_from_cmdline; 71 int ports[MAX_PORTS]; /* Port number to listen on. */ 72 struct queued_listenaddr *queued_listen_addrs; 73 u_int num_queued_listens; 74 struct listenaddr *listen_addrs; 75 u_int num_listen_addrs; 76 int address_family; /* Address family used by the server. */ 77 78 char *routing_domain; /* Bind session to routing domain */ 79 80 char **host_key_files; /* Files containing host keys. */ 81 int *host_key_file_userprovided; /* Key was specified by user. */ 82 u_int num_host_key_files; /* Number of files for host keys. */ 83 char **host_cert_files; /* Files containing host certs. */ 84 u_int num_host_cert_files; /* Number of files for host certs. */ 85 86 char *host_key_agent; /* ssh-agent socket for host keys. */ 87 char *pid_file; /* Where to put our pid */ 88 char *moduli_file; /* moduli file for DH-GEX */ 89 int login_grace_time; /* Disconnect if no auth in this time 90 * (sec). */ 91 int permit_root_login; /* PERMIT_*, see above */ 92 int ignore_rhosts; /* Ignore .rhosts and .shosts. */ 93 int ignore_user_known_hosts; /* Ignore ~/.ssh/known_hosts 94 * for RhostsRsaAuth */ 95 int print_motd; /* If true, print /etc/motd. */ 96 int print_lastlog; /* If true, print lastlog */ 97 int x11_forwarding; /* If true, permit inet (spoofing) X11 fwd. */ 98 int x11_display_offset; /* What DISPLAY number to start 99 * searching at */ 100 int x11_use_localhost; /* If true, use localhost for fake X11 server. */ 101 char *xauth_location; /* Location of xauth program */ 102 int permit_tty; /* If false, deny pty allocation */ 103 int permit_user_rc; /* If false, deny ~/.ssh/rc execution */ 104 int strict_modes; /* If true, require string home dir modes. */ 105 int tcp_keep_alive; /* If true, set SO_KEEPALIVE. */ 106 int ip_qos_interactive; /* IP ToS/DSCP/class for interactive */ 107 int ip_qos_bulk; /* IP ToS/DSCP/class for bulk traffic */ 108 char *ciphers; /* Supported SSH2 ciphers. */ 109 char *macs; /* Supported SSH2 macs. */ 110 char *kex_algorithms; /* SSH2 kex methods in order of preference. */ 111 struct ForwardOptions fwd_opts; /* forwarding options */ 112 SyslogFacility log_facility; /* Facility for system logging. */ 113 LogLevel log_level; /* Level for system logging. */ 114 u_int num_log_verbose; /* Verbose log overrides */ 115 char **log_verbose; 116 int hostbased_authentication; /* If true, permit ssh2 hostbased auth */ 117 int hostbased_uses_name_from_packet_only; /* experimental */ 118 char *hostbased_accepted_algos; /* Algos allowed for hostbased */ 119 char *hostkeyalgorithms; /* SSH2 server key types */ 120 char *ca_sign_algorithms; /* Allowed CA signature algorithms */ 121 int pubkey_authentication; /* If true, permit ssh2 pubkey authentication. */ 122 char *pubkey_accepted_algos; /* Signature algos allowed for pubkey */ 123 int pubkey_auth_options; /* -1 or mask of PUBKEYAUTH_* flags */ 124 int kerberos_authentication; /* If true, permit Kerberos 125 * authentication. */ 126 int kerberos_or_local_passwd; /* If true, permit kerberos 127 * and any other password 128 * authentication mechanism, 129 * such as SecurID or 130 * /etc/passwd */ 131 int kerberos_ticket_cleanup; /* If true, destroy ticket 132 * file on logout. */ 133 int kerberos_get_afs_token; /* If true, try to get AFS token if 134 * authenticated with Kerberos. */ 135 int gss_authentication; /* If true, permit GSSAPI authentication */ 136 int gss_cleanup_creds; /* If true, destroy cred cache on logout */ 137 int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */ 138 int password_authentication; /* If true, permit password 139 * authentication. */ 140 int kbd_interactive_authentication; /* If true, permit */ 141 int permit_empty_passwd; /* If false, do not permit empty 142 * passwords. */ 143 int permit_user_env; /* If true, read ~/.ssh/environment */ 144 char *permit_user_env_allowlist; /* pattern-list of allowed env names */ 145 int compression; /* If true, compression is allowed */ 146 int allow_tcp_forwarding; /* One of FORWARD_* */ 147 int allow_streamlocal_forwarding; /* One of FORWARD_* */ 148 int allow_agent_forwarding; 149 int disable_forwarding; 150 u_int num_allow_users; 151 char **allow_users; 152 u_int num_deny_users; 153 char **deny_users; 154 u_int num_allow_groups; 155 char **allow_groups; 156 u_int num_deny_groups; 157 char **deny_groups; 158 159 u_int num_subsystems; 160 char **subsystem_name; 161 char **subsystem_command; 162 char **subsystem_args; 163 164 u_int num_accept_env; 165 char **accept_env; 166 u_int num_setenv; 167 char **setenv; 168 169 int max_startups_begin; 170 int max_startups_rate; 171 int max_startups; 172 int per_source_max_startups; 173 int per_source_masklen_ipv4; 174 int per_source_masklen_ipv6; 175 int max_authtries; 176 int max_sessions; 177 char *banner; /* SSH-2 banner message */ 178 int use_dns; 179 int client_alive_interval; /* 180 * poke the client this often to 181 * see if it's still there 182 */ 183 int client_alive_count_max; /* 184 * If the client is unresponsive 185 * for this many intervals above, 186 * disconnect the session 187 */ 188 189 u_int num_authkeys_files; /* Files containing public keys */ 190 char **authorized_keys_files; 191 192 char *adm_forced_command; 193 194 int permit_tun; 195 196 char **permitted_opens; /* May also be one of PERMITOPEN_* */ 197 u_int num_permitted_opens; 198 char **permitted_listens; /* May also be one of PERMITOPEN_* */ 199 u_int num_permitted_listens; 200 201 char *chroot_directory; 202 char *revoked_keys_file; 203 char *trusted_user_ca_keys; 204 char *authorized_keys_command; 205 char *authorized_keys_command_user; 206 char *authorized_principals_file; 207 char *authorized_principals_command; 208 char *authorized_principals_command_user; 209 210 int64_t rekey_limit; 211 int rekey_interval; 212 213 char *version_addendum; /* Appended to SSH banner */ 214 215 u_int num_auth_methods; 216 char **auth_methods; 217 218 int fingerprint_hash; 219 int expose_userauth_info; 220 u_int64_t timing_secret; 221 char *sk_provider; 222 int required_rsa_size; /* minimum size of RSA keys */ 223 224 char **channel_timeouts; /* inactivity timeout by channel type */ 225 u_int num_channel_timeouts; 226 227 int unused_connection_timeout; 228 229 char *sshd_session_path; 230 } ServerOptions; 231 232 /* Information about the incoming connection as used by Match */ 233 struct connection_info { 234 const char *user; 235 const char *host; /* possibly resolved hostname */ 236 const char *address; /* remote address */ 237 const char *laddress; /* local address */ 238 int lport; /* local port */ 239 const char *rdomain; /* routing domain if available */ 240 int test; /* test mode, allow some attributes to be 241 * unspecified */ 242 }; 243 244 /* List of included files for re-exec from the parsed configuration */ 245 struct include_item { 246 char *selector; 247 char *filename; 248 struct sshbuf *contents; 249 TAILQ_ENTRY(include_item) entry; 250 }; 251 TAILQ_HEAD(include_list, include_item); 252 253 254 /* 255 * These are string config options that must be copied between the 256 * Match sub-config and the main config, and must be sent from the 257 * privsep child to the privsep master. We use a macro to ensure all 258 * the options are copied and the copies are done in the correct order. 259 * 260 * NB. an option must appear in servconf.c:copy_set_server_options() or 261 * COPY_MATCH_STRING_OPTS here but never both. 262 */ 263 #define COPY_MATCH_STRING_OPTS() do { \ 264 M_CP_STROPT(banner); \ 265 M_CP_STROPT(trusted_user_ca_keys); \ 266 M_CP_STROPT(revoked_keys_file); \ 267 M_CP_STROPT(authorized_keys_command); \ 268 M_CP_STROPT(authorized_keys_command_user); \ 269 M_CP_STROPT(authorized_principals_file); \ 270 M_CP_STROPT(authorized_principals_command); \ 271 M_CP_STROPT(authorized_principals_command_user); \ 272 M_CP_STROPT(hostbased_accepted_algos); \ 273 M_CP_STROPT(pubkey_accepted_algos); \ 274 M_CP_STROPT(ca_sign_algorithms); \ 275 M_CP_STROPT(routing_domain); \ 276 M_CP_STROPT(permit_user_env_allowlist); \ 277 M_CP_STRARRAYOPT(authorized_keys_files, num_authkeys_files); \ 278 M_CP_STRARRAYOPT(allow_users, num_allow_users); \ 279 M_CP_STRARRAYOPT(deny_users, num_deny_users); \ 280 M_CP_STRARRAYOPT(allow_groups, num_allow_groups); \ 281 M_CP_STRARRAYOPT(deny_groups, num_deny_groups); \ 282 M_CP_STRARRAYOPT(accept_env, num_accept_env); \ 283 M_CP_STRARRAYOPT(setenv, num_setenv); \ 284 M_CP_STRARRAYOPT(auth_methods, num_auth_methods); \ 285 M_CP_STRARRAYOPT(permitted_opens, num_permitted_opens); \ 286 M_CP_STRARRAYOPT(permitted_listens, num_permitted_listens); \ 287 M_CP_STRARRAYOPT(channel_timeouts, num_channel_timeouts); \ 288 M_CP_STRARRAYOPT(log_verbose, num_log_verbose); \ 289 M_CP_STRARRAYOPT(subsystem_name, num_subsystems); \ 290 M_CP_STRARRAYOPT(subsystem_command, num_subsystems); \ 291 M_CP_STRARRAYOPT(subsystem_args, num_subsystems); \ 292 } while (0) 293 294 void initialize_server_options(ServerOptions *); 295 void fill_default_server_options(ServerOptions *); 296 int process_server_config_line(ServerOptions *, char *, const char *, int, 297 int *, struct connection_info *, struct include_list *includes); 298 void load_server_config(const char *, struct sshbuf *); 299 void parse_server_config(ServerOptions *, const char *, struct sshbuf *, 300 struct include_list *includes, struct connection_info *, int); 301 void parse_server_match_config(ServerOptions *, 302 struct include_list *includes, struct connection_info *); 303 int parse_server_match_testspec(struct connection_info *, char *); 304 void servconf_merge_subsystems(ServerOptions *, ServerOptions *); 305 void copy_set_server_options(ServerOptions *, ServerOptions *, int); 306 void dump_config(ServerOptions *); 307 char *derelativise_path(const char *); 308 void servconf_add_hostkey(const char *, const int, 309 ServerOptions *, const char *path, int); 310 void servconf_add_hostcert(const char *, const int, 311 ServerOptions *, const char *path); 312 313 #endif /* SERVCONF_H */ 314