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