blob: 8bd708150ab39ea68685a3a4a54fda726dee7b01 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 *
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
Damien Miller450a7a12000-03-26 13:04:51 +100016/* RCSID("$Id: ssh.h,v 1.28 2000/03/26 03:04:54 damien Exp $"); */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100017
18#ifndef SSH_H
19#define SSH_H
20
Damien Millerab18c411999-11-11 10:40:23 +110021#include <netinet/in.h> /* For struct sockaddr_in */
22#include <pwd.h> /* For struct pw */
Damien Miller5ce662a1999-11-11 17:57:39 +110023#include <stdarg.h> /* For va_list */
Damien Miller34132e52000-01-14 15:45:46 +110024#include <sys/socket.h> /* For struct sockaddr_storage */
25#include "fake-socket.h" /* For struct sockaddr_storage */
Damien Miller365199d1999-12-22 00:12:38 +110026#ifdef HAVE_SYS_SELECT_H
27# include <sys/select.h>
28#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029#include "rsa.h"
30#include "cipher.h"
31
Damien Miller5428f641999-11-25 11:54:57 +110032/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037#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
Damien Miller5428f641999-11-25 11:54:57 +110048/*
49 * Maximum number of RSA authentication identity files that can be specified
50 * in configuration files or on the command line.
51 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052#define SSH_MAX_IDENTITY_FILES 100
53
Damien Miller5428f641999-11-25 11:54:57 +110054/*
55 * Major protocol version. Different version indicates major incompatiblity
56 * that prevents communication.
57 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100058#define PROTOCOL_MAJOR 1
59
Damien Miller5428f641999-11-25 11:54:57 +110060/*
61 * Minor protocol version. Different version indicates minor incompatibility
62 * that does not prevent interoperation.
63 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100064#define PROTOCOL_MINOR 5
65
Damien Miller5428f641999-11-25 11:54:57 +110066/*
67 * Name for the service. The port named by this service overrides the
68 * default port if present.
69 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100070#define SSH_SERVICE_NAME "ssh"
71
72#ifndef ETCDIR
73#define ETCDIR "/etc"
74#endif /* ETCDIR */
75
Damien Miller95def091999-11-25 00:26:21 +110076#ifndef PIDDIR
Damien Millerd4a8b7e1999-10-27 13:42:43 +100077#define PIDDIR "/var/run"
Damien Miller95def091999-11-25 00:26:21 +110078#endif /* PIDDIR */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100079
Damien Miller5428f641999-11-25 11:54:57 +110080/*
81 * System-wide file containing host keys of known hosts. This file should be
82 * world-readable.
83 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100084#define SSH_SYSTEM_HOSTFILE ETCDIR "/ssh_known_hosts"
85
Damien Miller5428f641999-11-25 11:54:57 +110086/*
87 * Of these, ssh_host_key must be readable only by root, whereas ssh_config
88 * should be world-readable.
89 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090#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
Damien Miller356a0b01999-11-08 15:30:59 +110094#ifndef SSH_PROGRAM
Damien Miller95def091999-11-25 00:26:21 +110095#define SSH_PROGRAM "/usr/bin/ssh"
Damien Miller356a0b01999-11-08 15:30:59 +110096#endif /* SSH_PROGRAM */
97
98#ifndef LOGIN_PROGRAM
Damien Miller95def091999-11-25 00:26:21 +110099#define LOGIN_PROGRAM "/usr/bin/login"
Damien Miller356a0b01999-11-08 15:30:59 +1100100#endif /* LOGIN_PROGRAM */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000101
Damien Millerc7b38ce1999-11-09 10:28:04 +1100102#ifndef ASKPASS_PROGRAM
Damien Miller95def091999-11-25 00:26:21 +1100103#define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass"
Damien Millerc7b38ce1999-11-09 10:28:04 +1100104#endif /* ASKPASS_PROGRAM */
105
Damien Miller5428f641999-11-25 11:54:57 +1100106/*
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 */
Damien Millera37010e1999-10-29 09:18:29 +1000110#define SSH_DAEMON_PID_FILE PIDDIR "/sshd.pid"
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000111
Damien Miller5428f641999-11-25 11:54:57 +1100112/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000116#define SSH_USER_DIR ".ssh"
117
Damien Miller5428f641999-11-25 11:54:57 +1100118/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123#define SSH_USER_HOSTFILE "~/.ssh/known_hosts"
124
Damien Miller5428f641999-11-25 11:54:57 +1100125/*
126 * Name of the default file containing client-side authentication key. This
127 * file should only be readable by the user him/herself.
128 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000129#define SSH_CLIENT_IDENTITY ".ssh/identity"
130
Damien Miller5428f641999-11-25 11:54:57 +1100131/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000137#define SSH_USER_CONFFILE ".ssh/config"
138
Damien Miller5428f641999-11-25 11:54:57 +1100139/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000147#define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys"
148
Damien Miller5428f641999-11-25 11:54:57 +1100149/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000155#define SSH_USER_RC ".ssh/rc"
156#define SSH_SYSTEM_RC ETCDIR "/sshrc"
157
Damien Miller5428f641999-11-25 11:54:57 +1100158/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000162#define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv"
163
Damien Miller5428f641999-11-25 11:54:57 +1100164/*
165 * Name of the environment variable containing the pathname of the
166 * authentication socket.
167 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000168#define SSH_AUTHSOCKET_ENV_NAME "SSH_AUTH_SOCK"
169
Damien Miller5428f641999-11-25 11:54:57 +1100170/*
171 * Name of the environment variable containing the pathname of the
172 * authentication socket.
173 */
Damien Miller32265091999-11-12 11:33:04 +1100174#define SSH_AGENTPID_ENV_NAME "SSH_AGENT_PID"
Damien Miller5eeedae1999-10-29 10:21:15 +1000175
Damien Miller5428f641999-11-25 11:54:57 +1100176/*
Damien Milleraae6c611999-12-06 11:47:28 +1100177 * Default path to ssh-askpass used by ssh-add,
178 * environment variable for overwriting the default location
179 */
Damien Miller3bc14dd1999-12-07 14:54:53 +1100180#ifndef SSH_ASKPASS_DEFAULT
181# define SSH_ASKPASS_DEFAULT "/usr/X11R6/bin/ssh-askpass"
182#endif
Damien Milleraae6c611999-12-06 11:47:28 +1100183#define SSH_ASKPASS_ENV "SSH_ASKPASS"
184
185/*
Damien Miller5428f641999-11-25 11:54:57 +1100186 * 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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000189#define SSH_KEY_BITS_RESERVED 128
190
Damien Miller5428f641999-11-25 11:54:57 +1100191/*
192 * Length of the session key in bytes. (Specified as 256 bits in the
193 * protocol.)
194 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000195#define SSH_SESSION_KEY_LENGTH 32
196
197/* Name of Kerberos service for SSH to use. */
198#define KRB4_SERVICE_NAME "rcmd"
199
Damien Miller5428f641999-11-25 11:54:57 +1100200/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000204#define SSH_AUTH_RHOSTS 1
205#define SSH_AUTH_RSA 2
206#define SSH_AUTH_PASSWORD 3
207#define SSH_AUTH_RHOSTS_RSA 4
Damien Miller95def091999-11-25 00:26:21 +1100208#define SSH_AUTH_TIS 5
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000209#define SSH_AUTH_KERBEROS 6
210#define SSH_PASS_KERBEROS_TGT 7
Damien Miller5428f641999-11-25 11:54:57 +1100211 /* 8 to 15 are reserved */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000212#define SSH_PASS_AFS_TOKEN 21
213
214/* Protocol flags. These are bit masks. */
Damien Miller5428f641999-11-25 11:54:57 +1100215#define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes screen */
216#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain host */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000217
Damien Miller5428f641999-11-25 11:54:57 +1100218/*
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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000225#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) */
Damien Miller95def091999-11-25 00:26:21 +1100264#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) */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000267#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
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000272/*------------ definitions for login.c -------------*/
273
Damien Miller5428f641999-11-25 11:54:57 +1100274/*
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 */
Damien Miller95def091999-11-25 00:26:21 +1100279unsigned long
280get_last_login_time(uid_t uid, const char *logname,
281 char *buf, unsigned int bufsize);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000282
Damien Miller5428f641999-11-25 11:54:57 +1100283/*
284 * Records that the user has logged in. This does many things normally done
285 * by login(1).
286 */
Damien Miller95def091999-11-25 00:26:21 +1100287void
288record_login(int pid, const char *ttyname, const char *user, uid_t uid,
Damien Miller34132e52000-01-14 15:45:46 +1100289 const char *host, struct sockaddr *addr);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000290
Damien Miller5428f641999-11-25 11:54:57 +1100291/*
292 * Records that the user has logged out. This does many thigs normally done
293 * by login(1) or init.
294 */
Damien Miller95def091999-11-25 00:26:21 +1100295void record_logout(int pid, const char *ttyname);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000296
297/*------------ definitions for sshconnect.c ----------*/
298
Damien Miller5428f641999-11-25 11:54:57 +1100299/*
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 */
Damien Miller95def091999-11-25 00:26:21 +1100308int
Damien Miller34132e52000-01-14 15:45:46 +1100309ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
Damien Milleraae6c611999-12-06 11:47:28 +1100310 u_short port, int connection_attempts,
Damien Miller95def091999-11-25 00:26:21 +1100311 int anonymous, uid_t original_real_uid,
312 const char *proxy_command);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000313
Damien Miller5428f641999-11-25 11:54:57 +1100314/*
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 */
Damien Miller5ce662a1999-11-11 17:57:39 +1100322
Damien Miller95def091999-11-25 00:26:21 +1100323void
324ssh_login(int host_key_valid, RSA * host_key, const char *host,
Damien Miller34132e52000-01-14 15:45:46 +1100325 struct sockaddr * hostaddr, uid_t original_real_uid);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000326
327/*------------ Definitions for various authentication methods. -------*/
328
Damien Miller5428f641999-11-25 11:54:57 +1100329/*
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 */
Damien Miller95def091999-11-25 00:26:21 +1100334int auth_rhosts(struct passwd * pw, const char *client_user);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000335
Damien Miller5428f641999-11-25 11:54:57 +1100336/*
337 * Tries to authenticate the user using the .rhosts file and the host using
338 * its host key. Returns true if authentication succeeds.
339 */
Damien Miller95def091999-11-25 00:26:21 +1100340int
Damien Miller450a7a12000-03-26 13:04:51 +1000341auth_rhosts_rsa(struct passwd * pw, const char *client_user, RSA* client_host_key);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000342
Damien Miller5428f641999-11-25 11:54:57 +1100343/*
344 * Tries to authenticate the user using password. Returns true if
345 * authentication succeeds.
346 */
Damien Miller95def091999-11-25 00:26:21 +1100347int auth_password(struct passwd * pw, const char *password);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000348
Damien Miller5428f641999-11-25 11:54:57 +1100349/*
350 * Performs the RSA authentication dialog with the client. This returns 0 if
351 * the client could not be authenticated, and 1 if authentication was
352 * successful. This may exit if there is a serious protocol violation.
353 */
Damien Miller95def091999-11-25 00:26:21 +1100354int auth_rsa(struct passwd * pw, BIGNUM * client_n);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000355
Damien Miller5428f641999-11-25 11:54:57 +1100356/*
357 * Parses an RSA key (number of bits, e, n) from a string. Moves the pointer
358 * over the key. Skips any whitespace at the beginning and at end.
359 */
Damien Miller95def091999-11-25 00:26:21 +1100360int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM * e, BIGNUM * n);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000361
Damien Miller5428f641999-11-25 11:54:57 +1100362/*
363 * Returns the name of the machine at the other end of the socket. The
364 * returned string should be freed by the caller.
365 */
Damien Miller95def091999-11-25 00:26:21 +1100366char *get_remote_hostname(int socket);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000367
Damien Miller5428f641999-11-25 11:54:57 +1100368/*
369 * Return the canonical name of the host in the other side of the current
370 * connection (as returned by packet_get_connection). The host name is
371 * cached, so it is efficient to call this several times.
372 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000373const char *get_canonical_hostname(void);
374
Damien Miller5428f641999-11-25 11:54:57 +1100375/*
376 * Returns the remote IP address as an ascii string. The value need not be
377 * freed by the caller.
378 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000379const char *get_remote_ipaddr(void);
380
381/* Returns the port number of the peer of the socket. */
Damien Miller95def091999-11-25 00:26:21 +1100382int get_peer_port(int sock);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000383
Damien Miller34132e52000-01-14 15:45:46 +1100384/* Returns the port number of the remote/local host. */
Damien Miller95def091999-11-25 00:26:21 +1100385int get_remote_port(void);
Damien Miller34132e52000-01-14 15:45:46 +1100386int get_local_port(void);
387
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000388
Damien Miller5428f641999-11-25 11:54:57 +1100389/*
Damien Miller5428f641999-11-25 11:54:57 +1100390 * Performs the RSA authentication challenge-response dialog with the client,
391 * and returns true (non-zero) if the client gave the correct answer to our
392 * challenge; returns zero if the client gives a wrong answer.
393 */
Damien Miller450a7a12000-03-26 13:04:51 +1000394int auth_rsa_challenge_dialog(RSA *pk);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000395
Damien Miller5428f641999-11-25 11:54:57 +1100396/*
397 * Reads a passphrase from /dev/tty with echo turned off. Returns the
398 * passphrase (allocated with xmalloc). Exits if EOF is encountered. If
399 * from_stdin is true, the passphrase will be read from stdin instead.
400 */
Damien Miller95def091999-11-25 00:26:21 +1100401char *read_passphrase(const char *prompt, int from_stdin);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000402
Damien Miller5428f641999-11-25 11:54:57 +1100403/*
404 * Saves the authentication (private) key in a file, encrypting it with
405 * passphrase. The identification of the file (lowest 64 bits of n) will
406 * precede the key to provide identification of the key without needing a
407 * passphrase.
408 */
Damien Miller95def091999-11-25 00:26:21 +1100409int
410save_private_key(const char *filename, const char *passphrase,
411 RSA * private_key, const char *comment);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000412
Damien Miller5428f641999-11-25 11:54:57 +1100413/*
414 * Loads the public part of the key file (public key and comment). Returns 0
415 * if an error occurred; zero if the public key was successfully read. The
416 * comment of the key is returned in comment_return if it is non-NULL; the
417 * caller must free the value with xfree.
418 */
Damien Miller95def091999-11-25 00:26:21 +1100419int
420load_public_key(const char *filename, RSA * pub,
421 char **comment_return);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000422
Damien Miller5428f641999-11-25 11:54:57 +1100423/*
424 * Loads the private key from the file. Returns 0 if an error is encountered
425 * (file does not exist or is not readable, or passphrase is bad). This
426 * initializes the private key. The comment of the key is returned in
427 * comment_return if it is non-NULL; the caller must free the value with
428 * xfree.
429 */
Damien Miller95def091999-11-25 00:26:21 +1100430int
431load_private_key(const char *filename, const char *passphrase,
432 RSA * private_key, char **comment_return);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000433
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100434/*------------ Definitions for logging. -----------------------*/
435
436/* Supported syslog facilities and levels. */
Damien Miller95def091999-11-25 00:26:21 +1100437typedef enum {
438 SYSLOG_FACILITY_DAEMON,
439 SYSLOG_FACILITY_USER,
440 SYSLOG_FACILITY_AUTH,
441 SYSLOG_FACILITY_LOCAL0,
442 SYSLOG_FACILITY_LOCAL1,
443 SYSLOG_FACILITY_LOCAL2,
444 SYSLOG_FACILITY_LOCAL3,
445 SYSLOG_FACILITY_LOCAL4,
446 SYSLOG_FACILITY_LOCAL5,
447 SYSLOG_FACILITY_LOCAL6,
448 SYSLOG_FACILITY_LOCAL7
449} SyslogFacility;
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100450
Damien Miller95def091999-11-25 00:26:21 +1100451typedef enum {
452 SYSLOG_LEVEL_QUIET,
453 SYSLOG_LEVEL_FATAL,
454 SYSLOG_LEVEL_ERROR,
455 SYSLOG_LEVEL_INFO,
456 SYSLOG_LEVEL_VERBOSE,
457 SYSLOG_LEVEL_DEBUG
458} LogLevel;
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100459/* Initializes logging. */
Damien Miller95def091999-11-25 00:26:21 +1100460void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr);
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100461
462/* Logging implementation, depending on server or client */
Damien Miller95def091999-11-25 00:26:21 +1100463void do_log(LogLevel level, const char *fmt, va_list args);
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100464
Damien Miller6162d121999-11-21 13:23:52 +1100465/* name to facility/level */
466SyslogFacility log_facility_number(char *name);
467LogLevel log_level_number(char *name);
468
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100469/* Output a message to syslog or stderr */
Damien Miller95def091999-11-25 00:26:21 +1100470void fatal(const char *fmt,...) __attribute__((format(printf, 1, 2)));
471void error(const char *fmt,...) __attribute__((format(printf, 1, 2)));
472void log(const char *fmt,...) __attribute__((format(printf, 1, 2)));
473void verbose(const char *fmt,...) __attribute__((format(printf, 1, 2)));
474void debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100475
476/* same as fatal() but w/o logging */
Damien Miller95def091999-11-25 00:26:21 +1100477void fatal_cleanup(void);
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100478
Damien Miller5428f641999-11-25 11:54:57 +1100479/*
480 * Registers a cleanup function to be called by fatal()/fatal_cleanup()
481 * before exiting. It is permissible to call fatal_remove_cleanup for the
482 * function itself from the function.
483 */
Damien Miller95def091999-11-25 00:26:21 +1100484void fatal_add_cleanup(void (*proc) (void *context), void *context);
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100485
486/* Removes a cleanup function to be called at fatal(). */
Damien Miller95def091999-11-25 00:26:21 +1100487void fatal_remove_cleanup(void (*proc) (void *context), void *context);
Damien Miller6d7b2cd1999-11-12 15:19:27 +1100488
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000489/*---------------- definitions for channels ------------------*/
490
491/* Sets specific protocol options. */
Damien Miller95def091999-11-25 00:26:21 +1100492void channel_set_options(int hostname_in_open);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000493
Damien Miller5428f641999-11-25 11:54:57 +1100494/*
495 * Allocate a new channel object and set its type and socket. Remote_name
496 * must have been allocated with xmalloc; this will free it when the channel
497 * is freed.
498 */
Damien Miller95def091999-11-25 00:26:21 +1100499int channel_allocate(int type, int sock, char *remote_name);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000500
501/* Free the channel and close its socket. */
Damien Miller95def091999-11-25 00:26:21 +1100502void channel_free(int channel);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000503
504/* Add any bits relevant to channels in select bitmasks. */
Damien Miller95def091999-11-25 00:26:21 +1100505void channel_prepare_select(fd_set * readset, fd_set * writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000506
Damien Miller5428f641999-11-25 11:54:57 +1100507/*
508 * After select, perform any appropriate operations for channels which have
509 * events pending.
510 */
Damien Miller95def091999-11-25 00:26:21 +1100511void channel_after_select(fd_set * readset, fd_set * writeset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000512
513/* If there is data to send to the connection, send some of it now. */
Damien Miller95def091999-11-25 00:26:21 +1100514void channel_output_poll(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000515
Damien Miller5428f641999-11-25 11:54:57 +1100516/*
517 * This is called when a packet of type CHANNEL_DATA has just been received.
518 * The message type has already been consumed, but channel number and data is
519 * still there.
520 */
Damien Miller95def091999-11-25 00:26:21 +1100521void channel_input_data(int payload_len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000522
523/* Returns true if no channel has too much buffered data. */
Damien Miller95def091999-11-25 00:26:21 +1100524int channel_not_very_much_buffered_data(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000525
526/* This is called after receiving CHANNEL_CLOSE. */
Damien Miller95def091999-11-25 00:26:21 +1100527void channel_input_close(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000528
529/* This is called after receiving CHANNEL_CLOSE_CONFIRMATION. */
Damien Miller95def091999-11-25 00:26:21 +1100530void channel_input_close_confirmation(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000531
532/* This is called after receiving CHANNEL_OPEN_CONFIRMATION. */
Damien Miller95def091999-11-25 00:26:21 +1100533void channel_input_open_confirmation(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000534
535/* This is called after receiving CHANNEL_OPEN_FAILURE from the other side. */
Damien Miller95def091999-11-25 00:26:21 +1100536void channel_input_open_failure(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000537
538/* This closes any sockets that are listening for connections; this removes
539 any unix domain sockets. */
Damien Miller95def091999-11-25 00:26:21 +1100540void channel_stop_listening(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000541
Damien Miller5428f641999-11-25 11:54:57 +1100542/*
543 * Closes the sockets of all channels. This is used to close extra file
544 * descriptors after a fork.
545 */
Damien Miller95def091999-11-25 00:26:21 +1100546void channel_close_all(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000547
548/* Returns the maximum file descriptor number used by the channels. */
Damien Miller95def091999-11-25 00:26:21 +1100549int channel_max_fd(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000550
551/* Returns true if there is still an open channel over the connection. */
Damien Miller95def091999-11-25 00:26:21 +1100552int channel_still_open(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000553
Damien Miller5428f641999-11-25 11:54:57 +1100554/*
555 * Returns a string containing a list of all open channels. The list is
556 * suitable for displaying to the user. It uses crlf instead of newlines.
557 * The caller should free the string with xfree.
558 */
Damien Miller95def091999-11-25 00:26:21 +1100559char *channel_open_message(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000560
Damien Miller5428f641999-11-25 11:54:57 +1100561/*
562 * Initiate forwarding of connections to local port "port" through the secure
563 * channel to host:port from remote side. This never returns if there was an
564 * error.
565 */
Damien Miller95def091999-11-25 00:26:21 +1100566void
Damien Milleraae6c611999-12-06 11:47:28 +1100567channel_request_local_forwarding(u_short port, const char *host,
Damien Millera34a28b1999-12-14 10:47:15 +1100568 u_short remote_port, int gateway_ports);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000569
Damien Miller5428f641999-11-25 11:54:57 +1100570/*
571 * Initiate forwarding of connections to port "port" on remote host through
572 * the secure channel to host:port from local side. This never returns if
573 * there was an error. This registers that open requests for that port are
574 * permitted.
575 */
Damien Miller95def091999-11-25 00:26:21 +1100576void
Damien Milleraae6c611999-12-06 11:47:28 +1100577channel_request_remote_forwarding(u_short port, const char *host,
578 u_short remote_port);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000579
Damien Miller5428f641999-11-25 11:54:57 +1100580/*
581 * Permits opening to any host/port in SSH_MSG_PORT_OPEN. This is usually
582 * called by the server, because the user could connect to any port anyway,
583 * and the server has no way to know but to trust the client anyway.
584 */
Damien Miller95def091999-11-25 00:26:21 +1100585void channel_permit_all_opens(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000586
Damien Miller5428f641999-11-25 11:54:57 +1100587/*
588 * This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates
589 * listening for the port, and sends back a success reply (or disconnect
590 * message if there was an error). This never returns if there was an error.
591 */
Damien Miller95def091999-11-25 00:26:21 +1100592void channel_input_port_forward_request(int is_root);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000593
Damien Miller5428f641999-11-25 11:54:57 +1100594/*
595 * This is called after receiving PORT_OPEN message. This attempts to
596 * connect to the given host:port, and sends back CHANNEL_OPEN_CONFIRMATION
597 * or CHANNEL_OPEN_FAILURE.
598 */
Damien Miller95def091999-11-25 00:26:21 +1100599void channel_input_port_open(int payload_len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000600
Damien Miller5428f641999-11-25 11:54:57 +1100601/*
602 * Creates a port for X11 connections, and starts listening for it. Returns
603 * the display name, or NULL if an error was encountered.
604 */
Damien Miller95def091999-11-25 00:26:21 +1100605char *x11_create_display(int screen);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000606
Damien Miller5428f641999-11-25 11:54:57 +1100607/*
608 * Creates an internet domain socket for listening for X11 connections.
609 * Returns a suitable value for the DISPLAY variable, or NULL if an error
610 * occurs.
611 */
Damien Millera34a28b1999-12-14 10:47:15 +1100612char *x11_create_display_inet(int screen, int x11_display_offset);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000613
Damien Miller5428f641999-11-25 11:54:57 +1100614/*
615 * This is called when SSH_SMSG_X11_OPEN is received. The packet contains
616 * the remote channel number. We should do whatever we want, and respond
617 * with either SSH_MSG_OPEN_CONFIRMATION or SSH_MSG_OPEN_FAILURE.
618 */
Damien Miller95def091999-11-25 00:26:21 +1100619void x11_input_open(int payload_len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000620
Damien Miller5428f641999-11-25 11:54:57 +1100621/*
622 * Requests forwarding of X11 connections. This should be called on the
623 * client only.
624 */
Damien Miller95def091999-11-25 00:26:21 +1100625void x11_request_forwarding(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000626
Damien Miller5428f641999-11-25 11:54:57 +1100627/*
628 * Requests forwarding for X11 connections, with authentication spoofing.
629 * This should be called in the client only.
630 */
Damien Miller95def091999-11-25 00:26:21 +1100631void x11_request_forwarding_with_spoofing(const char *proto, const char *data);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000632
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000633/* Sends a message to the server to request authentication fd forwarding. */
Damien Miller95def091999-11-25 00:26:21 +1100634void auth_request_forwarding(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000635
Damien Miller5428f641999-11-25 11:54:57 +1100636/*
637 * Returns the name of the forwarded authentication socket. Returns NULL if
638 * there is no forwarded authentication socket. The returned value points to
639 * a static buffer.
640 */
Damien Miller95def091999-11-25 00:26:21 +1100641char *auth_get_socket_name(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000642
Damien Miller5428f641999-11-25 11:54:57 +1100643/*
644 * This if called to process SSH_CMSG_AGENT_REQUEST_FORWARDING on the server.
645 * This starts forwarding authentication requests.
646 */
Damien Miller95def091999-11-25 00:26:21 +1100647void auth_input_request_forwarding(struct passwd * pw);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000648
649/* This is called to process an SSH_SMSG_AGENT_OPEN message. */
Damien Miller95def091999-11-25 00:26:21 +1100650void auth_input_open_request(void);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000651
Damien Miller5428f641999-11-25 11:54:57 +1100652/*
653 * Returns true if the given string matches the pattern (which may contain ?
654 * and * as wildcards), and zero if it does not match.
655 */
Damien Miller95def091999-11-25 00:26:21 +1100656int match_pattern(const char *s, const char *pattern);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000657
Damien Miller5428f641999-11-25 11:54:57 +1100658/*
659 * Expands tildes in the file name. Returns data allocated by xmalloc.
660 * Warning: this calls getpw*.
661 */
Damien Miller95def091999-11-25 00:26:21 +1100662char *tilde_expand_filename(const char *filename, uid_t my_uid);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000663
Damien Miller5428f641999-11-25 11:54:57 +1100664/*
665 * Performs the interactive session. This handles data transmission between
666 * the client and the program. Note that the notion of stdin, stdout, and
667 * stderr in this function is sort of reversed: this function writes to stdin
668 * (of the child program), and reads from stdout and stderr (of the child
669 * program).
670 */
Damien Miller95def091999-11-25 00:26:21 +1100671void server_loop(int pid, int fdin, int fdout, int fderr);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000672
673/* Client side main loop for the interactive session. */
Damien Miller95def091999-11-25 00:26:21 +1100674int client_loop(int have_pty, int escape_char);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000675
676/* Linked list of custom environment strings (see auth-rsa.c). */
677struct envstring {
Damien Miller95def091999-11-25 00:26:21 +1100678 struct envstring *next;
679 char *s;
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000680};
Damien Miller037a0dc1999-12-07 15:38:31 +1100681
682/*
683 * Ensure all of data on socket comes through. f==read || f==write
684 */
Damien Miller98c7ad62000-03-09 21:27:49 +1100685ssize_t atomicio(ssize_t (*f)(), int fd, void *s, size_t n);
Damien Miller037a0dc1999-12-07 15:38:31 +1100686
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000687#ifdef KRB4
688#include <krb.h>
Damien Miller5428f641999-11-25 11:54:57 +1100689/*
690 * Performs Kerberos v4 mutual authentication with the client. This returns 0
691 * if the client could not be authenticated, and 1 if authentication was
692 * successful. This may exit if there is a serious protocol violation.
693 */
Damien Miller95def091999-11-25 00:26:21 +1100694int auth_krb4(const char *server_user, KTEXT auth, char **client);
695int krb4_init(uid_t uid);
696void krb4_cleanup_proc(void *ignore);
Damien Milleraae6c611999-12-06 11:47:28 +1100697int auth_krb4_password(struct passwd * pw, const char *password);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000698
699#ifdef AFS
700#include <kafs.h>
701
702/* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */
Damien Miller95def091999-11-25 00:26:21 +1100703int auth_kerberos_tgt(struct passwd * pw, const char *string);
704int auth_afs_token(struct passwd * pw, const char *token_string);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000705
Damien Miller95def091999-11-25 00:26:21 +1100706int creds_to_radix(CREDENTIALS * creds, unsigned char *buf);
707int radix_to_creds(const char *buf, CREDENTIALS * creds);
708#endif /* AFS */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000709
Damien Miller95def091999-11-25 00:26:21 +1100710#endif /* KRB4 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000711
712#ifdef SKEY
713#include <skey.h>
Damien Miller95def091999-11-25 00:26:21 +1100714char *skey_fake_keyinfo(char *username);
Damien Milleraae6c611999-12-06 11:47:28 +1100715int auth_skey_password(struct passwd * pw, const char *password);
Damien Miller95def091999-11-25 00:26:21 +1100716#endif /* SKEY */
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000717
Damien Miller34132e52000-01-14 15:45:46 +1100718/* AF_UNSPEC or AF_INET or AF_INET6 */
719extern int IPv4or6;
720
Damien Millere72b7af1999-12-30 15:08:44 +1100721#ifdef USE_PAM
722#include "auth-pam.h"
723#endif /* USE_PAM */
724
Damien Miller95def091999-11-25 00:26:21 +1100725#endif /* SSH_H */