servconf.h 11 KB

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