]>
Commit | Line | Data |
---|---|---|
8efc0c15 | 1 | /* |
5260325f | 2 | * |
3 | * ssh.h | |
4 | * | |
5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | |
6 | * | |
7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | |
8 | * All rights reserved | |
9 | * | |
10 | * Created: Fri Mar 17 17:09:37 1995 ylo | |
11 | * | |
12 | * Generic header file for ssh. | |
13 | * | |
14 | */ | |
8efc0c15 | 15 | |
16 | /* RCSID("$Id$"); */ | |
17 | ||
18 | #ifndef SSH_H | |
19 | #define SSH_H | |
20 | ||
4cca272e | 21 | #include <netinet/in.h> /* For struct sockaddr_in */ |
22 | #include <pwd.h> /* For struct pw */ | |
6a17f9c2 | 23 | #include <stdarg.h> /* For va_list */ |
48e671d5 | 24 | #include <sys/socket.h> /* For struct sockaddr_storage */ |
25 | #include "fake-socket.h" /* For struct sockaddr_storage */ | |
eef6f7e9 | 26 | #ifdef HAVE_SYS_SELECT_H |
27 | # include <sys/select.h> | |
28 | #endif | |
8efc0c15 | 29 | #include "rsa.h" |
30 | #include "cipher.h" | |
31 | ||
aa3378df | 32 | /* |
33 | * The default cipher used if IDEA is not supported by the remote host. It is | |
34 | * recommended that this be one of the mandatory ciphers (DES, 3DES), though | |
35 | * that is not required. | |
36 | */ | |
8efc0c15 | 37 | #define SSH_FALLBACK_CIPHER SSH_CIPHER_3DES |
38 | ||
39 | /* Cipher used for encrypting authentication files. */ | |
40 | #define SSH_AUTHFILE_CIPHER SSH_CIPHER_3DES | |
41 | ||
42 | /* Default port number. */ | |
43 | #define SSH_DEFAULT_PORT 22 | |
44 | ||
45 | /* Maximum number of TCP/IP ports forwarded per direction. */ | |
46 | #define SSH_MAX_FORWARDS_PER_DIRECTION 100 | |
47 | ||
aa3378df | 48 | /* |
49 | * Maximum number of RSA authentication identity files that can be specified | |
50 | * in configuration files or on the command line. | |
51 | */ | |
8efc0c15 | 52 | #define SSH_MAX_IDENTITY_FILES 100 |
53 | ||
aa3378df | 54 | /* |
55 | * Major protocol version. Different version indicates major incompatiblity | |
56 | * that prevents communication. | |
57 | */ | |
8efc0c15 | 58 | #define PROTOCOL_MAJOR 1 |
59 | ||
aa3378df | 60 | /* |
61 | * Minor protocol version. Different version indicates minor incompatibility | |
62 | * that does not prevent interoperation. | |
63 | */ | |
8efc0c15 | 64 | #define PROTOCOL_MINOR 5 |
65 | ||
aa3378df | 66 | /* |
67 | * Name for the service. The port named by this service overrides the | |
68 | * default port if present. | |
69 | */ | |
8efc0c15 | 70 | #define SSH_SERVICE_NAME "ssh" |
71 | ||
72 | #ifndef ETCDIR | |
73 | #define ETCDIR "/etc" | |
74 | #endif /* ETCDIR */ | |
75 | ||
5260325f | 76 | #ifndef PIDDIR |
8efc0c15 | 77 | #define PIDDIR "/var/run" |
5260325f | 78 | #endif /* PIDDIR */ |
8efc0c15 | 79 | |
aa3378df | 80 | /* |
81 | * System-wide file containing host keys of known hosts. This file should be | |
82 | * world-readable. | |
83 | */ | |
8efc0c15 | 84 | #define SSH_SYSTEM_HOSTFILE ETCDIR "/ssh_known_hosts" |
85 | ||
aa3378df | 86 | /* |
87 | * Of these, ssh_host_key must be readable only by root, whereas ssh_config | |
88 | * should be world-readable. | |
89 | */ | |
8efc0c15 | 90 | #define HOST_KEY_FILE ETCDIR "/ssh_host_key" |
91 | #define SERVER_CONFIG_FILE ETCDIR "/sshd_config" | |
92 | #define HOST_CONFIG_FILE ETCDIR "/ssh_config" | |
93 | ||
e1a9c08d | 94 | #ifndef SSH_PROGRAM |
5260325f | 95 | #define SSH_PROGRAM "/usr/bin/ssh" |
e1a9c08d | 96 | #endif /* SSH_PROGRAM */ |
97 | ||
98 | #ifndef LOGIN_PROGRAM | |
5260325f | 99 | #define LOGIN_PROGRAM "/usr/bin/login" |
e1a9c08d | 100 | #endif /* LOGIN_PROGRAM */ |
8efc0c15 | 101 | |
d4f11b59 | 102 | #ifndef ASKPASS_PROGRAM |
5260325f | 103 | #define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass" |
d4f11b59 | 104 | #endif /* ASKPASS_PROGRAM */ |
105 | ||
aa3378df | 106 | /* |
107 | * The process id of the daemon listening for connections is saved here to | |
108 | * make it easier to kill the correct daemon when necessary. | |
109 | */ | |
f1bcacf9 | 110 | #define SSH_DAEMON_PID_FILE PIDDIR "/sshd.pid" |
8efc0c15 | 111 | |
aa3378df | 112 | /* |
113 | * The directory in user\'s home directory in which the files reside. The | |
114 | * directory should be world-readable (though not all files are). | |
115 | */ | |
8efc0c15 | 116 | #define SSH_USER_DIR ".ssh" |
117 | ||
aa3378df | 118 | /* |
119 | * Per-user file containing host keys of known hosts. This file need not be | |
120 | * readable by anyone except the user him/herself, though this does not | |
121 | * contain anything particularly secret. | |
122 | */ | |
8efc0c15 | 123 | #define SSH_USER_HOSTFILE "~/.ssh/known_hosts" |
124 | ||
aa3378df | 125 | /* |
126 | * Name of the default file containing client-side authentication key. This | |
127 | * file should only be readable by the user him/herself. | |
128 | */ | |
8efc0c15 | 129 | #define SSH_CLIENT_IDENTITY ".ssh/identity" |
130 | ||
aa3378df | 131 | /* |
132 | * Configuration file in user\'s home directory. This file need not be | |
133 | * readable by anyone but the user him/herself, but does not contain anything | |
134 | * particularly secret. If the user\'s home directory resides on an NFS | |
135 | * volume where root is mapped to nobody, this may need to be world-readable. | |
136 | */ | |
8efc0c15 | 137 | #define SSH_USER_CONFFILE ".ssh/config" |
138 | ||
aa3378df | 139 | /* |
140 | * File containing a list of those rsa keys that permit logging in as this | |
141 | * user. This file need not be readable by anyone but the user him/herself, | |
142 | * but does not contain anything particularly secret. If the user\'s home | |
143 | * directory resides on an NFS volume where root is mapped to nobody, this | |
144 | * may need to be world-readable. (This file is read by the daemon which is | |
145 | * running as root.) | |
146 | */ | |
8efc0c15 | 147 | #define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys" |
148 | ||
aa3378df | 149 | /* |
150 | * Per-user and system-wide ssh "rc" files. These files are executed with | |
151 | * /bin/sh before starting the shell or command if they exist. They will be | |
152 | * passed "proto cookie" as arguments if X11 forwarding with spoofing is in | |
153 | * use. xauth will be run if neither of these exists. | |
154 | */ | |
8efc0c15 | 155 | #define SSH_USER_RC ".ssh/rc" |
156 | #define SSH_SYSTEM_RC ETCDIR "/sshrc" | |
157 | ||
aa3378df | 158 | /* |
159 | * Ssh-only version of /etc/hosts.equiv. Additionally, the daemon may use | |
160 | * ~/.rhosts and /etc/hosts.equiv if rhosts authentication is enabled. | |
161 | */ | |
8efc0c15 | 162 | #define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv" |
163 | ||
aa3378df | 164 | /* |
165 | * Name of the environment variable containing the pathname of the | |
166 | * authentication socket. | |
167 | */ | |
8efc0c15 | 168 | #define SSH_AUTHSOCKET_ENV_NAME "SSH_AUTH_SOCK" |
169 | ||
aa3378df | 170 | /* |
171 | * Name of the environment variable containing the pathname of the | |
172 | * authentication socket. | |
173 | */ | |
b4748e2f | 174 | #define SSH_AGENTPID_ENV_NAME "SSH_AGENT_PID" |
50da1126 | 175 | |
57112b5a | 176 | /* |
177 | * Default path to ssh-askpass used by ssh-add, | |
178 | * environment variable for overwriting the default location | |
179 | */ | |
db28aeb5 | 180 | #ifndef SSH_ASKPASS_DEFAULT |
181 | # define SSH_ASKPASS_DEFAULT "/usr/X11R6/bin/ssh-askpass" | |
182 | #endif | |
57112b5a | 183 | #define SSH_ASKPASS_ENV "SSH_ASKPASS" |
184 | ||
aa3378df | 185 | /* |
186 | * Force host key length and server key length to differ by at least this | |
187 | * many bits. This is to make double encryption with rsaref work. | |
188 | */ | |
8efc0c15 | 189 | #define SSH_KEY_BITS_RESERVED 128 |
190 | ||
aa3378df | 191 | /* |
192 | * Length of the session key in bytes. (Specified as 256 bits in the | |
193 | * protocol.) | |
194 | */ | |
8efc0c15 | 195 | #define SSH_SESSION_KEY_LENGTH 32 |
196 | ||
197 | /* Name of Kerberos service for SSH to use. */ | |
198 | #define KRB4_SERVICE_NAME "rcmd" | |
199 | ||
aa3378df | 200 | /* |
201 | * Authentication methods. New types can be added, but old types should not | |
202 | * be removed for compatibility. The maximum allowed value is 31. | |
203 | */ | |
8efc0c15 | 204 | #define SSH_AUTH_RHOSTS 1 |
205 | #define SSH_AUTH_RSA 2 | |
206 | #define SSH_AUTH_PASSWORD 3 | |
207 | #define SSH_AUTH_RHOSTS_RSA 4 | |
5260325f | 208 | #define SSH_AUTH_TIS 5 |
8efc0c15 | 209 | #define SSH_AUTH_KERBEROS 6 |
210 | #define SSH_PASS_KERBEROS_TGT 7 | |
aa3378df | 211 | /* 8 to 15 are reserved */ |
8efc0c15 | 212 | #define SSH_PASS_AFS_TOKEN 21 |
213 | ||
214 | /* Protocol flags. These are bit masks. */ | |
aa3378df | 215 | #define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes screen */ |
216 | #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain host */ | |
217 | ||
218 | /* | |
219 | * Definition of message types. New values can be added, but old values | |
220 | * should not be removed or without careful consideration of the consequences | |
221 | * for compatibility. The maximum value is 254; value 255 is reserved for | |
222 | * future extension. | |
223 | */ | |
224 | /* Message name */ /* msg code */ /* arguments */ | |
8efc0c15 | 225 | #define SSH_MSG_NONE 0 /* no message */ |
226 | #define SSH_MSG_DISCONNECT 1 /* cause (string) */ | |
227 | #define SSH_SMSG_PUBLIC_KEY 2 /* ck,msk,srvk,hostk */ | |
228 | #define SSH_CMSG_SESSION_KEY 3 /* key (BIGNUM) */ | |
229 | #define SSH_CMSG_USER 4 /* user (string) */ | |
230 | #define SSH_CMSG_AUTH_RHOSTS 5 /* user (string) */ | |
231 | #define SSH_CMSG_AUTH_RSA 6 /* modulus (BIGNUM) */ | |
232 | #define SSH_SMSG_AUTH_RSA_CHALLENGE 7 /* int (BIGNUM) */ | |
233 | #define SSH_CMSG_AUTH_RSA_RESPONSE 8 /* int (BIGNUM) */ | |
234 | #define SSH_CMSG_AUTH_PASSWORD 9 /* pass (string) */ | |
235 | #define SSH_CMSG_REQUEST_PTY 10 /* TERM, tty modes */ | |
236 | #define SSH_CMSG_WINDOW_SIZE 11 /* row,col,xpix,ypix */ | |
237 | #define SSH_CMSG_EXEC_SHELL 12 /* */ | |
238 | #define SSH_CMSG_EXEC_CMD 13 /* cmd (string) */ | |
239 | #define SSH_SMSG_SUCCESS 14 /* */ | |
240 | #define SSH_SMSG_FAILURE 15 /* */ | |
241 | #define SSH_CMSG_STDIN_DATA 16 /* data (string) */ | |
242 | #define SSH_SMSG_STDOUT_DATA 17 /* data (string) */ | |
243 | #define SSH_SMSG_STDERR_DATA 18 /* data (string) */ | |
244 | #define SSH_CMSG_EOF 19 /* */ | |
245 | #define SSH_SMSG_EXITSTATUS 20 /* status (int) */ | |
246 | #define SSH_MSG_CHANNEL_OPEN_CONFIRMATION 21 /* channel (int) */ | |
247 | #define SSH_MSG_CHANNEL_OPEN_FAILURE 22 /* channel (int) */ | |
248 | #define SSH_MSG_CHANNEL_DATA 23 /* ch,data (int,str) */ | |
249 | #define SSH_MSG_CHANNEL_CLOSE 24 /* channel (int) */ | |
250 | #define SSH_MSG_CHANNEL_CLOSE_CONFIRMATION 25 /* channel (int) */ | |
251 | /* SSH_CMSG_X11_REQUEST_FORWARDING 26 OBSOLETE */ | |
252 | #define SSH_SMSG_X11_OPEN 27 /* channel (int) */ | |
253 | #define SSH_CMSG_PORT_FORWARD_REQUEST 28 /* p,host,hp (i,s,i) */ | |
254 | #define SSH_MSG_PORT_OPEN 29 /* ch,h,p (i,s,i) */ | |
255 | #define SSH_CMSG_AGENT_REQUEST_FORWARDING 30 /* */ | |
256 | #define SSH_SMSG_AGENT_OPEN 31 /* port (int) */ | |
257 | #define SSH_MSG_IGNORE 32 /* string */ | |
258 | #define SSH_CMSG_EXIT_CONFIRMATION 33 /* */ | |
259 | #define SSH_CMSG_X11_REQUEST_FORWARDING 34 /* proto,data (s,s) */ | |
260 | #define SSH_CMSG_AUTH_RHOSTS_RSA 35 /* user,mod (s,mpi) */ | |
261 | #define SSH_MSG_DEBUG 36 /* string */ | |
262 | #define SSH_CMSG_REQUEST_COMPRESSION 37 /* level 1-9 (int) */ | |
263 | #define SSH_CMSG_MAX_PACKET_SIZE 38 /* size 4k-1024k (int) */ | |
5260325f | 264 | #define SSH_CMSG_AUTH_TIS 39 /* we use this for s/key */ |
265 | #define SSH_SMSG_AUTH_TIS_CHALLENGE 40 /* challenge (string) */ | |
266 | #define SSH_CMSG_AUTH_TIS_RESPONSE 41 /* response (string) */ | |
8efc0c15 | 267 | #define SSH_CMSG_AUTH_KERBEROS 42 /* (KTEXT) */ |
268 | #define SSH_SMSG_AUTH_KERBEROS_RESPONSE 43 /* (KTEXT) */ | |
269 | #define SSH_CMSG_HAVE_KERBEROS_TGT 44 /* credentials (s) */ | |
270 | #define SSH_CMSG_HAVE_AFS_TOKEN 65 /* token (s) */ | |
271 | ||
8efc0c15 | 272 | /*------------ definitions for login.c -------------*/ |
273 | ||
aa3378df | 274 | /* |
275 | * Returns the time when the user last logged in. Returns 0 if the | |
276 | * information is not available. This must be called before record_login. | |
277 | * The host from which the user logged in is stored in buf. | |
278 | */ | |
5260325f | 279 | unsigned long |
280 | get_last_login_time(uid_t uid, const char *logname, | |
281 | char *buf, unsigned int bufsize); | |
8efc0c15 | 282 | |
aa3378df | 283 | /* |
284 | * Records that the user has logged in. This does many things normally done | |
285 | * by login(1). | |
286 | */ | |
5260325f | 287 | void |
288 | record_login(int pid, const char *ttyname, const char *user, uid_t uid, | |
48e671d5 | 289 | const char *host, struct sockaddr *addr); |
8efc0c15 | 290 | |
aa3378df | 291 | /* |
292 | * Records that the user has logged out. This does many thigs normally done | |
293 | * by login(1) or init. | |
294 | */ | |
5260325f | 295 | void record_logout(int pid, const char *ttyname); |
8efc0c15 | 296 | |
297 | /*------------ definitions for sshconnect.c ----------*/ | |
298 | ||
aa3378df | 299 | /* |
300 | * Opens a TCP/IP connection to the remote server on the given host. If port | |
301 | * is 0, the default port will be used. If anonymous is zero, a privileged | |
302 | * port will be allocated to make the connection. This requires super-user | |
303 | * privileges if anonymous is false. Connection_attempts specifies the | |
304 | * maximum number of tries, one per second. This returns true on success, | |
305 | * and zero on failure. If the connection is successful, this calls | |
306 | * packet_set_connection for the connection. | |
307 | */ | |
5260325f | 308 | int |
48e671d5 | 309 | ssh_connect(const char *host, struct sockaddr_storage * hostaddr, |
57112b5a | 310 | u_short port, int connection_attempts, |
5260325f | 311 | int anonymous, uid_t original_real_uid, |
312 | const char *proxy_command); | |
8efc0c15 | 313 | |
aa3378df | 314 | /* |
315 | * Starts a dialog with the server, and authenticates the current user on the | |
316 | * server. This does not need any extra privileges. The basic connection to | |
317 | * the server must already have been established before this is called. If | |
318 | * login fails, this function prints an error and never returns. This | |
319 | * initializes the random state, and leaves it initialized (it will also have | |
320 | * references from the packet module). | |
321 | */ | |
6a17f9c2 | 322 | |
5260325f | 323 | void |
324 | ssh_login(int host_key_valid, RSA * host_key, const char *host, | |
48e671d5 | 325 | struct sockaddr * hostaddr, uid_t original_real_uid); |
8efc0c15 | 326 | |
327 | /*------------ Definitions for various authentication methods. -------*/ | |
328 | ||
aa3378df | 329 | /* |
330 | * Tries to authenticate the user using the .rhosts file. Returns true if | |
331 | * authentication succeeds. If ignore_rhosts is non-zero, this will not | |
332 | * consider .rhosts and .shosts (/etc/hosts.equiv will still be used). | |
333 | */ | |
5260325f | 334 | int auth_rhosts(struct passwd * pw, const char *client_user); |
8efc0c15 | 335 | |
aa3378df | 336 | /* |
337 | * Tries to authenticate the user using the .rhosts file and the host using | |
338 | * its host key. Returns true if authentication succeeds. | |
339 | */ | |
5260325f | 340 | int |
341 | auth_rhosts_rsa(struct passwd * pw, const char *client_user, | |
342 | BIGNUM * client_host_key_e, BIGNUM * client_host_key_n); | |
8efc0c15 | 343 | |
aa3378df | 344 | /* |
345 | * Tries to authenticate the user using password. Returns true if | |
346 | * authentication succeeds. | |
347 | */ | |
5260325f | 348 | int auth_password(struct passwd * pw, const char *password); |
8efc0c15 | 349 | |
aa3378df | 350 | /* |
351 | * Performs the RSA authentication dialog with the client. This returns 0 if | |
352 | * the client could not be authenticated, and 1 if authentication was | |
353 | * successful. This may exit if there is a serious protocol violation. | |
354 | */ | |
5260325f | 355 | int auth_rsa(struct passwd * pw, BIGNUM * client_n); |
8efc0c15 | 356 | |
aa3378df | 357 | /* |
358 | * Parses an RSA key (number of bits, e, n) from a string. Moves the pointer | |
359 | * over the key. Skips any whitespace at the beginning and at end. | |
360 | */ | |
5260325f | 361 | int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM * e, BIGNUM * n); |
8efc0c15 | 362 | |
aa3378df | 363 | /* |
364 | * Returns the name of the machine at the other end of the socket. The | |
365 | * returned string should be freed by the caller. | |
366 | */ | |
5260325f | 367 | char *get_remote_hostname(int socket); |
8efc0c15 | 368 | |
aa3378df | 369 | /* |
370 | * Return the canonical name of the host in the other side of the current | |
371 | * connection (as returned by packet_get_connection). The host name is | |
372 | * cached, so it is efficient to call this several times. | |
373 | */ | |
8efc0c15 | 374 | const char *get_canonical_hostname(void); |
375 | ||
aa3378df | 376 | /* |
377 | * Returns the remote IP address as an ascii string. The value need not be | |
378 | * freed by the caller. | |
379 | */ | |
8efc0c15 | 380 | const char *get_remote_ipaddr(void); |
381 | ||
382 | /* Returns the port number of the peer of the socket. */ | |
5260325f | 383 | int get_peer_port(int sock); |
8efc0c15 | 384 | |
48e671d5 | 385 | /* Returns the port number of the remote/local host. */ |
5260325f | 386 | int get_remote_port(void); |
48e671d5 | 387 | int get_local_port(void); |
388 | ||
8efc0c15 | 389 | |
aa3378df | 390 | /* |
391 | * Tries to match the host name (which must be in all lowercase) against the | |
392 | * comma-separated sequence of subpatterns (each possibly preceded by ! to | |
393 | * indicate negation). Returns true if there is a positive match; zero | |
394 | * otherwise. | |
395 | */ | |
5260325f | 396 | int match_hostname(const char *host, const char *pattern, unsigned int len); |
8efc0c15 | 397 | |
aa3378df | 398 | /* |
399 | * Checks whether the given host is already in the list of our known hosts. | |
400 | * Returns HOST_OK if the host is known and has the specified key, HOST_NEW | |
401 | * if the host is not known, and HOST_CHANGED if the host is known but used | |
402 | * to have a different host key. The host must be in all lowercase. | |
403 | */ | |
5260325f | 404 | typedef enum { |
405 | HOST_OK, HOST_NEW, HOST_CHANGED | |
406 | } HostStatus; | |
407 | HostStatus | |
408 | check_host_in_hostfile(const char *filename, const char *host, | |
409 | BIGNUM * e, BIGNUM * n, BIGNUM * ke, BIGNUM * kn); | |
8efc0c15 | 410 | |
aa3378df | 411 | /* |
412 | * Appends an entry to the host file. Returns false if the entry could not | |
413 | * be appended. | |
414 | */ | |
5260325f | 415 | int |
416 | add_host_to_hostfile(const char *filename, const char *host, | |
417 | BIGNUM * e, BIGNUM * n); | |
8efc0c15 | 418 | |
aa3378df | 419 | /* |
420 | * Performs the RSA authentication challenge-response dialog with the client, | |
421 | * and returns true (non-zero) if the client gave the correct answer to our | |
422 | * challenge; returns zero if the client gives a wrong answer. | |
423 | */ | |
5260325f | 424 | int auth_rsa_challenge_dialog(BIGNUM * e, BIGNUM * n); |
8efc0c15 | 425 | |
aa3378df | 426 | /* |
427 | * Reads a passphrase from /dev/tty with echo turned off. Returns the | |
428 | * passphrase (allocated with xmalloc). Exits if EOF is encountered. If | |
429 | * from_stdin is true, the passphrase will be read from stdin instead. | |
430 | */ | |
5260325f | 431 | char *read_passphrase(const char *prompt, int from_stdin); |
8efc0c15 | 432 | |
aa3378df | 433 | /* |
434 | * Saves the authentication (private) key in a file, encrypting it with | |
435 | * passphrase. The identification of the file (lowest 64 bits of n) will | |
436 | * precede the key to provide identification of the key without needing a | |
437 | * passphrase. | |
438 | */ | |
5260325f | 439 | int |
440 | save_private_key(const char *filename, const char *passphrase, | |
441 | RSA * private_key, const char *comment); | |
8efc0c15 | 442 | |
aa3378df | 443 | /* |
444 | * Loads the public part of the key file (public key and comment). Returns 0 | |
445 | * if an error occurred; zero if the public key was successfully read. The | |
446 | * comment of the key is returned in comment_return if it is non-NULL; the | |
447 | * caller must free the value with xfree. | |
448 | */ | |
5260325f | 449 | int |
450 | load_public_key(const char *filename, RSA * pub, | |
451 | char **comment_return); | |
8efc0c15 | 452 | |
aa3378df | 453 | /* |
454 | * Loads the private key from the file. Returns 0 if an error is encountered | |
455 | * (file does not exist or is not readable, or passphrase is bad). This | |
456 | * initializes the private key. The comment of the key is returned in | |
457 | * comment_return if it is non-NULL; the caller must free the value with | |
458 | * xfree. | |
459 | */ | |
5260325f | 460 | int |
461 | load_private_key(const char *filename, const char *passphrase, | |
462 | RSA * private_key, char **comment_return); | |
8efc0c15 | 463 | |
6fa724bc | 464 | /*------------ Definitions for logging. -----------------------*/ |
465 | ||
466 | /* Supported syslog facilities and levels. */ | |
5260325f | 467 | typedef enum { |
468 | SYSLOG_FACILITY_DAEMON, | |
469 | SYSLOG_FACILITY_USER, | |
470 | SYSLOG_FACILITY_AUTH, | |
471 | SYSLOG_FACILITY_LOCAL0, | |
472 | SYSLOG_FACILITY_LOCAL1, | |
473 | SYSLOG_FACILITY_LOCAL2, | |
474 | SYSLOG_FACILITY_LOCAL3, | |
475 | SYSLOG_FACILITY_LOCAL4, | |
476 | SYSLOG_FACILITY_LOCAL5, | |
477 | SYSLOG_FACILITY_LOCAL6, | |
478 | SYSLOG_FACILITY_LOCAL7 | |
479 | } SyslogFacility; | |
480 | ||
481 | typedef enum { | |
482 | SYSLOG_LEVEL_QUIET, | |
483 | SYSLOG_LEVEL_FATAL, | |
484 | SYSLOG_LEVEL_ERROR, | |
485 | SYSLOG_LEVEL_INFO, | |
486 | SYSLOG_LEVEL_VERBOSE, | |
487 | SYSLOG_LEVEL_DEBUG | |
488 | } LogLevel; | |
6fa724bc | 489 | /* Initializes logging. */ |
5260325f | 490 | void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr); |
6fa724bc | 491 | |
492 | /* Logging implementation, depending on server or client */ | |
5260325f | 493 | void do_log(LogLevel level, const char *fmt, va_list args); |
6fa724bc | 494 | |
9d6b7add | 495 | /* name to facility/level */ |
496 | SyslogFacility log_facility_number(char *name); | |
497 | LogLevel log_level_number(char *name); | |
498 | ||
6fa724bc | 499 | /* Output a message to syslog or stderr */ |
5260325f | 500 | void fatal(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
501 | void error(const char *fmt,...) __attribute__((format(printf, 1, 2))); | |
502 | void log(const char *fmt,...) __attribute__((format(printf, 1, 2))); | |
503 | void verbose(const char *fmt,...) __attribute__((format(printf, 1, 2))); | |
504 | void debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); | |
6fa724bc | 505 | |
506 | /* same as fatal() but w/o logging */ | |
5260325f | 507 | void fatal_cleanup(void); |
6fa724bc | 508 | |
aa3378df | 509 | /* |
510 | * Registers a cleanup function to be called by fatal()/fatal_cleanup() | |
511 | * before exiting. It is permissible to call fatal_remove_cleanup for the | |
512 | * function itself from the function. | |
513 | */ | |
5260325f | 514 | void fatal_add_cleanup(void (*proc) (void *context), void *context); |
6fa724bc | 515 | |
516 | /* Removes a cleanup function to be called at fatal(). */ | |
5260325f | 517 | void fatal_remove_cleanup(void (*proc) (void *context), void *context); |
6fa724bc | 518 | |
8efc0c15 | 519 | /*---------------- definitions for channels ------------------*/ |
520 | ||
521 | /* Sets specific protocol options. */ | |
5260325f | 522 | void channel_set_options(int hostname_in_open); |
8efc0c15 | 523 | |
aa3378df | 524 | /* |
525 | * Allocate a new channel object and set its type and socket. Remote_name | |
526 | * must have been allocated with xmalloc; this will free it when the channel | |
527 | * is freed. | |
528 | */ | |
5260325f | 529 | int channel_allocate(int type, int sock, char *remote_name); |
8efc0c15 | 530 | |
531 | /* Free the channel and close its socket. */ | |
5260325f | 532 | void channel_free(int channel); |
8efc0c15 | 533 | |
534 | /* Add any bits relevant to channels in select bitmasks. */ | |
5260325f | 535 | void channel_prepare_select(fd_set * readset, fd_set * writeset); |
8efc0c15 | 536 | |
aa3378df | 537 | /* |
538 | * After select, perform any appropriate operations for channels which have | |
539 | * events pending. | |
540 | */ | |
5260325f | 541 | void channel_after_select(fd_set * readset, fd_set * writeset); |
8efc0c15 | 542 | |
543 | /* If there is data to send to the connection, send some of it now. */ | |
5260325f | 544 | void channel_output_poll(void); |
8efc0c15 | 545 | |
aa3378df | 546 | /* |
547 | * This is called when a packet of type CHANNEL_DATA has just been received. | |
548 | * The message type has already been consumed, but channel number and data is | |
549 | * still there. | |
550 | */ | |
5260325f | 551 | void channel_input_data(int payload_len); |
8efc0c15 | 552 | |
553 | /* Returns true if no channel has too much buffered data. */ | |
5260325f | 554 | int channel_not_very_much_buffered_data(void); |
8efc0c15 | 555 | |
556 | /* This is called after receiving CHANNEL_CLOSE. */ | |
5260325f | 557 | void channel_input_close(void); |
8efc0c15 | 558 | |
559 | /* This is called after receiving CHANNEL_CLOSE_CONFIRMATION. */ | |
5260325f | 560 | void channel_input_close_confirmation(void); |
8efc0c15 | 561 | |
562 | /* This is called after receiving CHANNEL_OPEN_CONFIRMATION. */ | |
5260325f | 563 | void channel_input_open_confirmation(void); |
8efc0c15 | 564 | |
565 | /* This is called after receiving CHANNEL_OPEN_FAILURE from the other side. */ | |
5260325f | 566 | void channel_input_open_failure(void); |
8efc0c15 | 567 | |
568 | /* This closes any sockets that are listening for connections; this removes | |
569 | any unix domain sockets. */ | |
5260325f | 570 | void channel_stop_listening(void); |
8efc0c15 | 571 | |
aa3378df | 572 | /* |
573 | * Closes the sockets of all channels. This is used to close extra file | |
574 | * descriptors after a fork. | |
575 | */ | |
5260325f | 576 | void channel_close_all(void); |
8efc0c15 | 577 | |
578 | /* Returns the maximum file descriptor number used by the channels. */ | |
5260325f | 579 | int channel_max_fd(void); |
8efc0c15 | 580 | |
581 | /* Returns true if there is still an open channel over the connection. */ | |
5260325f | 582 | int channel_still_open(void); |
8efc0c15 | 583 | |
aa3378df | 584 | /* |
585 | * Returns a string containing a list of all open channels. The list is | |
586 | * suitable for displaying to the user. It uses crlf instead of newlines. | |
587 | * The caller should free the string with xfree. | |
588 | */ | |
5260325f | 589 | char *channel_open_message(void); |
8efc0c15 | 590 | |
aa3378df | 591 | /* |
592 | * Initiate forwarding of connections to local port "port" through the secure | |
593 | * channel to host:port from remote side. This never returns if there was an | |
594 | * error. | |
595 | */ | |
5260325f | 596 | void |
57112b5a | 597 | channel_request_local_forwarding(u_short port, const char *host, |
95f1eccc | 598 | u_short remote_port, int gateway_ports); |
8efc0c15 | 599 | |
aa3378df | 600 | /* |
601 | * Initiate forwarding of connections to port "port" on remote host through | |
602 | * the secure channel to host:port from local side. This never returns if | |
603 | * there was an error. This registers that open requests for that port are | |
604 | * permitted. | |
605 | */ | |
5260325f | 606 | void |
57112b5a | 607 | channel_request_remote_forwarding(u_short port, const char *host, |
608 | u_short remote_port); | |
8efc0c15 | 609 | |
aa3378df | 610 | /* |
611 | * Permits opening to any host/port in SSH_MSG_PORT_OPEN. This is usually | |
612 | * called by the server, because the user could connect to any port anyway, | |
613 | * and the server has no way to know but to trust the client anyway. | |
614 | */ | |
5260325f | 615 | void channel_permit_all_opens(void); |
8efc0c15 | 616 | |
aa3378df | 617 | /* |
618 | * This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates | |
619 | * listening for the port, and sends back a success reply (or disconnect | |
620 | * message if there was an error). This never returns if there was an error. | |
621 | */ | |
5260325f | 622 | void channel_input_port_forward_request(int is_root); |
8efc0c15 | 623 | |
aa3378df | 624 | /* |
625 | * This is called after receiving PORT_OPEN message. This attempts to | |
626 | * connect to the given host:port, and sends back CHANNEL_OPEN_CONFIRMATION | |
627 | * or CHANNEL_OPEN_FAILURE. | |
628 | */ | |
5260325f | 629 | void channel_input_port_open(int payload_len); |
8efc0c15 | 630 | |
aa3378df | 631 | /* |
632 | * Creates a port for X11 connections, and starts listening for it. Returns | |
633 | * the display name, or NULL if an error was encountered. | |
634 | */ | |
5260325f | 635 | char *x11_create_display(int screen); |
8efc0c15 | 636 | |
aa3378df | 637 | /* |
638 | * Creates an internet domain socket for listening for X11 connections. | |
639 | * Returns a suitable value for the DISPLAY variable, or NULL if an error | |
640 | * occurs. | |
641 | */ | |
95f1eccc | 642 | char *x11_create_display_inet(int screen, int x11_display_offset); |
8efc0c15 | 643 | |
aa3378df | 644 | /* |
645 | * This is called when SSH_SMSG_X11_OPEN is received. The packet contains | |
646 | * the remote channel number. We should do whatever we want, and respond | |
647 | * with either SSH_MSG_OPEN_CONFIRMATION or SSH_MSG_OPEN_FAILURE. | |
648 | */ | |
5260325f | 649 | void x11_input_open(int payload_len); |
8efc0c15 | 650 | |
aa3378df | 651 | /* |
652 | * Requests forwarding of X11 connections. This should be called on the | |
653 | * client only. | |
654 | */ | |
5260325f | 655 | void x11_request_forwarding(void); |
8efc0c15 | 656 | |
aa3378df | 657 | /* |
658 | * Requests forwarding for X11 connections, with authentication spoofing. | |
659 | * This should be called in the client only. | |
660 | */ | |
5260325f | 661 | void x11_request_forwarding_with_spoofing(const char *proto, const char *data); |
8efc0c15 | 662 | |
8efc0c15 | 663 | /* Sends a message to the server to request authentication fd forwarding. */ |
5260325f | 664 | void auth_request_forwarding(void); |
8efc0c15 | 665 | |
aa3378df | 666 | /* |
667 | * Returns the name of the forwarded authentication socket. Returns NULL if | |
668 | * there is no forwarded authentication socket. The returned value points to | |
669 | * a static buffer. | |
670 | */ | |
5260325f | 671 | char *auth_get_socket_name(void); |
8efc0c15 | 672 | |
aa3378df | 673 | /* |
674 | * This if called to process SSH_CMSG_AGENT_REQUEST_FORWARDING on the server. | |
675 | * This starts forwarding authentication requests. | |
676 | */ | |
5260325f | 677 | void auth_input_request_forwarding(struct passwd * pw); |
8efc0c15 | 678 | |
679 | /* This is called to process an SSH_SMSG_AGENT_OPEN message. */ | |
5260325f | 680 | void auth_input_open_request(void); |
8efc0c15 | 681 | |
aa3378df | 682 | /* |
683 | * Returns true if the given string matches the pattern (which may contain ? | |
684 | * and * as wildcards), and zero if it does not match. | |
685 | */ | |
5260325f | 686 | int match_pattern(const char *s, const char *pattern); |
8efc0c15 | 687 | |
aa3378df | 688 | /* |
689 | * Expands tildes in the file name. Returns data allocated by xmalloc. | |
690 | * Warning: this calls getpw*. | |
691 | */ | |
5260325f | 692 | char *tilde_expand_filename(const char *filename, uid_t my_uid); |
8efc0c15 | 693 | |
aa3378df | 694 | /* |
695 | * Performs the interactive session. This handles data transmission between | |
696 | * the client and the program. Note that the notion of stdin, stdout, and | |
697 | * stderr in this function is sort of reversed: this function writes to stdin | |
698 | * (of the child program), and reads from stdout and stderr (of the child | |
699 | * program). | |
700 | */ | |
5260325f | 701 | void server_loop(int pid, int fdin, int fdout, int fderr); |
8efc0c15 | 702 | |
703 | /* Client side main loop for the interactive session. */ | |
5260325f | 704 | int client_loop(int have_pty, int escape_char); |
8efc0c15 | 705 | |
706 | /* Linked list of custom environment strings (see auth-rsa.c). */ | |
707 | struct envstring { | |
5260325f | 708 | struct envstring *next; |
709 | char *s; | |
8efc0c15 | 710 | }; |
a408af76 | 711 | |
712 | /* | |
713 | * Ensure all of data on socket comes through. f==read || f==write | |
714 | */ | |
715 | int atomicio(int (*f)(), int fd, void *s, size_t n); | |
716 | ||
8efc0c15 | 717 | #ifdef KRB4 |
718 | #include <krb.h> | |
aa3378df | 719 | /* |
720 | * Performs Kerberos v4 mutual authentication with the client. This returns 0 | |
721 | * if the client could not be authenticated, and 1 if authentication was | |
722 | * successful. This may exit if there is a serious protocol violation. | |
723 | */ | |
5260325f | 724 | int auth_krb4(const char *server_user, KTEXT auth, char **client); |
725 | int krb4_init(uid_t uid); | |
726 | void krb4_cleanup_proc(void *ignore); | |
57112b5a | 727 | int auth_krb4_password(struct passwd * pw, const char *password); |
8efc0c15 | 728 | |
729 | #ifdef AFS | |
730 | #include <kafs.h> | |
731 | ||
732 | /* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */ | |
5260325f | 733 | int auth_kerberos_tgt(struct passwd * pw, const char *string); |
734 | int auth_afs_token(struct passwd * pw, const char *token_string); | |
8efc0c15 | 735 | |
5260325f | 736 | int creds_to_radix(CREDENTIALS * creds, unsigned char *buf); |
737 | int radix_to_creds(const char *buf, CREDENTIALS * creds); | |
738 | #endif /* AFS */ | |
8efc0c15 | 739 | |
5260325f | 740 | #endif /* KRB4 */ |
8efc0c15 | 741 | |
742 | #ifdef SKEY | |
743 | #include <skey.h> | |
5260325f | 744 | char *skey_fake_keyinfo(char *username); |
57112b5a | 745 | int auth_skey_password(struct passwd * pw, const char *password); |
5260325f | 746 | #endif /* SKEY */ |
8efc0c15 | 747 | |
48e671d5 | 748 | /* AF_UNSPEC or AF_INET or AF_INET6 */ |
749 | extern int IPv4or6; | |
750 | ||
a5c9cd31 | 751 | #ifdef USE_PAM |
752 | #include "auth-pam.h" | |
753 | #endif /* USE_PAM */ | |
754 | ||
4c40f834 | 755 | #if defined(HAVE_DANTE) || defined(HAVE_SOCKS4) |
0bc5b6fb | 756 | /* |
757 | * The following defines map the normal socket operations to SOCKSified | |
758 | * versions coming from the Dante SOCKS package. | |
759 | */ | |
760 | #define accept Raccept | |
761 | #define bind Rbind | |
762 | #define bindresvport Rbindresvport | |
763 | #define connect Rconnect | |
764 | #define gethostbyname Rgethostbyname | |
765 | #define gethostbyname2 Rgethostbyname2 | |
766 | #define getpeername Rgetpeername | |
767 | #define getsockname Rgetsockname | |
768 | #define read Rread | |
769 | #define readv Rreadv | |
770 | #define recv Rrecv | |
771 | #define recvmsg Rrecvmsg | |
772 | #define recvfrom Rrecvfrom | |
773 | #define rresvport Rrresvport | |
774 | #define send Rsend | |
775 | #define sendmsg Rsendmsg | |
776 | #define sendto Rsendto | |
777 | #define write Rwrite | |
778 | #define writev Rwritev | |
779 | int Raccept (int, struct sockaddr *, socklen_t *); | |
780 | int Rbind (int, const struct sockaddr *, socklen_t); | |
781 | int Rbindresvport(int , struct sockaddr_in *); | |
782 | int Rconnect (int, const struct sockaddr *, socklen_t); | |
783 | struct hostent *Rgethostbyname(const char *); | |
784 | struct hostent *Rgethostbyname2(const char *, int); | |
785 | int Rgetpeername (int, struct sockaddr *, socklen_t *); | |
786 | int Rgetsockname (int, struct sockaddr *, socklen_t *); | |
787 | ssize_t Rread(int , void *, size_t ); | |
788 | ssize_t Rreadv(int d, const struct iovec *iov, int iovcnt); | |
789 | ssize_t Rrecv (int, void *, size_t, int); | |
790 | ssize_t Rrecvfrom (int, void *, size_t, int, struct sockaddr *, | |
791 | socklen_t *); | |
792 | ssize_t Rsend (int, const void *, size_t, int); | |
793 | ssize_t Rsendmsg (int, const struct msghdr *, int); | |
794 | ssize_t Rsendto (int, const void *, | |
795 | size_t, int, const struct sockaddr *, socklen_t); | |
796 | ssize_t Rwrite(int , const void *, size_t ); | |
797 | ssize_t Rwritev(int , const struct iovec *, int ); | |
4c40f834 | 798 | #endif /* HAVE_DANTE || HAVE_SOCKS4 */ |
0bc5b6fb | 799 | |
4c40f834 | 800 | #if defined(HAVE_SOCKS5) |
801 | /* | |
802 | * The following defines map the normal socket operations to SOCKSified | |
803 | * versions coming from the SOCKS package. | |
804 | */ | |
805 | #define accept SOCKSaccept | |
806 | #define bind SOCKSbind | |
807 | #define bindresvport SOCKSbindresvport | |
808 | #define connect SOCKSconnect | |
809 | #define gethostbyname SOCKSgethostbyname | |
810 | #define gethostbyname2 SOCKSgethostbyname2 | |
811 | #define getpeername SOCKSgetpeername | |
812 | #define getsockname SOCKSgetsockname | |
813 | #define read SOCKSread | |
814 | #define readv SOCKSreadv | |
815 | #define recv SOCKSrecv | |
816 | #define recvmsg SOCKSrecvmsg | |
817 | #define recvfrom SOCKSrecvfrom | |
818 | #define rresvport SOCKSrresvport | |
819 | #define send SOCKSsend | |
820 | #define sendmsg SOCKSsendmsg | |
821 | #define sendto SOCKSsendto | |
822 | #define write SOCKSwrite | |
823 | #define writev SOCKSwritev | |
824 | int SOCKSaccept (int, struct sockaddr *, socklen_t *); | |
825 | int SOCKSbind (int, const struct sockaddr *, socklen_t); | |
826 | int SOCKSbindresvport(int , struct sockaddr_in *); | |
827 | int SOCKSconnect (int, const struct sockaddr *, socklen_t); | |
828 | struct hostent *SOCKSgethostbyname(const char *); | |
829 | struct hostent *SOCKSgethostbyname2(const char *, int); | |
830 | int SOCKSgetpeername (int, struct sockaddr *, socklen_t *); | |
831 | int SOCKSgetsockname (int, struct sockaddr *, socklen_t *); | |
832 | ssize_t SOCKSread(int , void *, size_t ); | |
833 | ssize_t SOCKSreadv(int d, const struct iovec *iov, int iovcnt); | |
834 | ssize_t SOCKSrecv (int, void *, size_t, int); | |
835 | ssize_t SOCKSrecvfrom (int, void *, size_t, int, struct sockaddr *, | |
836 | socklen_t *); | |
837 | ssize_t SOCKSsend (int, const void *, size_t, int); | |
838 | ssize_t SOCKSsendmsg (int, const struct msghdr *, int); | |
839 | ssize_t SOCKSsendto (int, const void *, | |
840 | size_t, int, const struct sockaddr *, socklen_t); | |
841 | ssize_t SOCKSwrite(int , const void *, size_t ); | |
842 | ssize_t SOCKSwritev(int , const struct iovec *, int ); | |
843 | #endif /* SOCKS5 */ | |
844 | ||
845 | #if defined(DANTE) || defined(SOCKS4) || defined(SOCKS5) | |
846 | #define SOCKS | |
847 | #endif /* defined(DANTE) || defined(SOCKS4) || defined(SOCKS5) */ | |
5260325f | 848 | #endif /* SSH_H */ |