summaryrefslogtreecommitdiff
path: root/ssh.h
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
committerDamien Miller <djm@mindrot.org>1999-11-25 00:26:21 +1100
commit95def09838fc61b37b6ea7cd5c234a465b4b129b (patch)
tree042744f76f40a326b873cb1c3690a6d7d966bc3e /ssh.h
parent4d2f15f895f4c795afc008aeff3fd2ceffbc44f4 (diff)
- Merged very large OpenBSD source code reformat
- OpenBSD CVS updates - [channels.c cipher.c compat.c log-client.c scp.c serverloop.c] [ssh.h sshd.8 sshd.c] syslog changes: * Unified Logmessage for all auth-types, for success and for failed * Standard connections get only ONE line in the LOG when level==LOG: Auth-attempts are logged only, if authentication is: a) successfull or b) with passwd or c) we had more than AUTH_FAIL_LOG failues * many log() became verbose() * old behaviour with level=VERBOSE - [readconf.c readconf.h ssh.1 ssh.h sshconnect.c sshd.c] tranfer s/key challenge/response data in SSH_SMSG_AUTH_TIS_CHALLENGE messages. allows use of s/key in windows (ttssh, securecrt) and ssh-1.2.27 clients without 'ssh -v', ok: niels@ - [sshd.8] -V, for fallback to openssh in SSH2 compatibility mode - [sshd.c] fix sigchld race; cjc5@po.cwru.edu
Diffstat (limited to 'ssh.h')
-rw-r--r--ssh.h351
1 files changed, 182 insertions, 169 deletions
diff --git a/ssh.h b/ssh.h
index 90668286b..f8426bfbb 100644
--- a/ssh.h
+++ b/ssh.h
@@ -1,19 +1,19 @@
1/* 1/*
2 2 *
3ssh.h 3 * ssh.h
4 4 *
5Author: Tatu Ylonen <ylo@cs.hut.fi> 5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 6 *
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved 8 * All rights reserved
9 9 *
10Created: Fri Mar 17 17:09:37 1995 ylo 10 * Created: Fri Mar 17 17:09:37 1995 ylo
11 11 *
12Generic header file for ssh. 12 * Generic header file for ssh.
13 13 *
14*/ 14 */
15 15
16/* RCSID("$Id: ssh.h,v 1.14 1999/11/21 02:23:53 damien Exp $"); */ 16/* RCSID("$Id: ssh.h,v 1.15 1999/11/24 13:26:23 damien Exp $"); */
17 17
18#ifndef SSH_H 18#ifndef SSH_H
19#define SSH_H 19#define SSH_H
@@ -25,7 +25,7 @@ Generic header file for ssh.
25#include "rsa.h" 25#include "rsa.h"
26#include "cipher.h" 26#include "cipher.h"
27 27
28/* The default cipher used if IDEA is not supported by the remote host. 28/* The default cipher used if IDEA is not supported by the remote host.
29 It is recommended that this be one of the mandatory ciphers (DES, 3DES), 29 It is recommended that this be one of the mandatory ciphers (DES, 3DES),
30 though that is not required. */ 30 though that is not required. */
31#define SSH_FALLBACK_CIPHER SSH_CIPHER_3DES 31#define SSH_FALLBACK_CIPHER SSH_CIPHER_3DES
@@ -59,7 +59,9 @@ Generic header file for ssh.
59#define ETCDIR "/etc" 59#define ETCDIR "/etc"
60#endif /* ETCDIR */ 60#endif /* ETCDIR */
61 61
62#ifndef PIDDIR
62#define PIDDIR "/var/run" 63#define PIDDIR "/var/run"
64#endif /* PIDDIR */
63 65
64/* System-wide file containing host keys of known hosts. This file should be 66/* System-wide file containing host keys of known hosts. This file should be
65 world-readable. */ 67 world-readable. */
@@ -76,15 +78,15 @@ only by root, whereas ssh_config should be world-readable. */
76#define HOST_CONFIG_FILE ETCDIR "/ssh_config" 78#define HOST_CONFIG_FILE ETCDIR "/ssh_config"
77 79
78#ifndef SSH_PROGRAM 80#ifndef SSH_PROGRAM
79#define SSH_PROGRAM "/usr/bin/ssh" 81#define SSH_PROGRAM "/usr/bin/ssh"
80#endif /* SSH_PROGRAM */ 82#endif /* SSH_PROGRAM */
81 83
82#ifndef LOGIN_PROGRAM 84#ifndef LOGIN_PROGRAM
83#define LOGIN_PROGRAM "/usr/bin/login" 85#define LOGIN_PROGRAM "/usr/bin/login"
84#endif /* LOGIN_PROGRAM */ 86#endif /* LOGIN_PROGRAM */
85 87
86#ifndef ASKPASS_PROGRAM 88#ifndef ASKPASS_PROGRAM
87#define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass" 89#define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass"
88#endif /* ASKPASS_PROGRAM */ 90#endif /* ASKPASS_PROGRAM */
89 91
90/* The process id of the daemon listening for connections is saved 92/* The process id of the daemon listening for connections is saved
@@ -100,7 +102,7 @@ only by root, whereas ssh_config should be world-readable. */
100 not contain anything particularly secret. */ 102 not contain anything particularly secret. */
101#define SSH_USER_HOSTFILE "~/.ssh/known_hosts" 103#define SSH_USER_HOSTFILE "~/.ssh/known_hosts"
102 104
103/* Name of the default file containing client-side authentication key. 105/* Name of the default file containing client-side authentication key.
104 This file should only be readable by the user him/herself. */ 106 This file should only be readable by the user him/herself. */
105#define SSH_CLIENT_IDENTITY ".ssh/identity" 107#define SSH_CLIENT_IDENTITY ".ssh/identity"
106 108
@@ -116,7 +118,7 @@ only by root, whereas ssh_config should be world-readable. */
116 readable by anyone but the user him/herself, but does not contain 118 readable by anyone but the user him/herself, but does not contain
117 anything particularly secret. If the user\'s home directory resides 119 anything particularly secret. If the user\'s home directory resides
118 on an NFS volume where root is mapped to nobody, this may need to be 120 on an NFS volume where root is mapped to nobody, this may need to be
119 world-readable. (This file is read by the daemon which is running as 121 world-readable. (This file is read by the daemon which is running as
120 root.) */ 122 root.) */
121#define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys" 123#define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys"
122 124
@@ -130,7 +132,7 @@ only by root, whereas ssh_config should be world-readable. */
130/* Ssh-only version of /etc/hosts.equiv. */ 132/* Ssh-only version of /etc/hosts.equiv. */
131#define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv" 133#define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv"
132 134
133/* Additionally, the daemon may use ~/.rhosts and /etc/hosts.equiv if 135/* Additionally, the daemon may use ~/.rhosts and /etc/hosts.equiv if
134 rhosts authentication is enabled. */ 136 rhosts authentication is enabled. */
135 137
136/* Name of the environment variable containing the pathname of the 138/* Name of the environment variable containing the pathname of the
@@ -145,7 +147,7 @@ only by root, whereas ssh_config should be world-readable. */
145 many bits. This is to make double encryption with rsaref work. */ 147 many bits. This is to make double encryption with rsaref work. */
146#define SSH_KEY_BITS_RESERVED 128 148#define SSH_KEY_BITS_RESERVED 128
147 149
148/* Length of the session key in bytes. (Specified as 256 bits in the 150/* Length of the session key in bytes. (Specified as 256 bits in the
149 protocol.) */ 151 protocol.) */
150#define SSH_SESSION_KEY_LENGTH 32 152#define SSH_SESSION_KEY_LENGTH 32
151 153
@@ -158,21 +160,23 @@ only by root, whereas ssh_config should be world-readable. */
158#define SSH_AUTH_RSA 2 160#define SSH_AUTH_RSA 2
159#define SSH_AUTH_PASSWORD 3 161#define SSH_AUTH_PASSWORD 3
160#define SSH_AUTH_RHOSTS_RSA 4 162#define SSH_AUTH_RHOSTS_RSA 4
161 /* 5 is TIS */ 163#define SSH_AUTH_TIS 5
162#define SSH_AUTH_KERBEROS 6 164#define SSH_AUTH_KERBEROS 6
163#define SSH_PASS_KERBEROS_TGT 7 165#define SSH_PASS_KERBEROS_TGT 7
164 /* 8 to 15 are reserved */ 166 /* 8 to 15 are reserved */
165#define SSH_PASS_AFS_TOKEN 21 167#define SSH_PASS_AFS_TOKEN 21
166 168
167/* Protocol flags. These are bit masks. */ 169/* Protocol flags. These are bit masks. */
168#define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes screen */ 170#define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes
169#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain host */ 171 * screen */
172#define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain
173 * host */
170 174
171/* Definition of message types. New values can be added, but old values 175/* Definition of message types. New values can be added, but old values
172 should not be removed or without careful consideration of the consequences 176 should not be removed or without careful consideration of the consequences
173 for compatibility. The maximum value is 254; value 255 is reserved 177 for compatibility. The maximum value is 254; value 255 is reserved
174 for future extension. */ 178 for future extension. */
175/* Message name */ /* msg code */ /* arguments */ 179 /* Message name *//* msg code *//* arguments */
176#define SSH_MSG_NONE 0 /* no message */ 180#define SSH_MSG_NONE 0 /* no message */
177#define SSH_MSG_DISCONNECT 1 /* cause (string) */ 181#define SSH_MSG_DISCONNECT 1 /* cause (string) */
178#define SSH_SMSG_PUBLIC_KEY 2 /* ck,msk,srvk,hostk */ 182#define SSH_SMSG_PUBLIC_KEY 2 /* ck,msk,srvk,hostk */
@@ -212,10 +216,9 @@ only by root, whereas ssh_config should be world-readable. */
212#define SSH_MSG_DEBUG 36 /* string */ 216#define SSH_MSG_DEBUG 36 /* string */
213#define SSH_CMSG_REQUEST_COMPRESSION 37 /* level 1-9 (int) */ 217#define SSH_CMSG_REQUEST_COMPRESSION 37 /* level 1-9 (int) */
214#define SSH_CMSG_MAX_PACKET_SIZE 38 /* size 4k-1024k (int) */ 218#define SSH_CMSG_MAX_PACKET_SIZE 38 /* size 4k-1024k (int) */
215#define SSH_CMSG_AUTH_TIS 39 /* this is proto-1.5, but we ignore TIS */ 219#define SSH_CMSG_AUTH_TIS 39 /* we use this for s/key */
216#define SSH_SMSG_AUTH_TIS_CHALLENGE 40 220#define SSH_SMSG_AUTH_TIS_CHALLENGE 40 /* challenge (string) */
217#define SSH_CMSG_AUTH_TIS_RESPONSE 41 221#define SSH_CMSG_AUTH_TIS_RESPONSE 41 /* response (string) */
218
219#define SSH_CMSG_AUTH_KERBEROS 42 /* (KTEXT) */ 222#define SSH_CMSG_AUTH_KERBEROS 42 /* (KTEXT) */
220#define SSH_SMSG_AUTH_KERBEROS_RESPONSE 43 /* (KTEXT) */ 223#define SSH_SMSG_AUTH_KERBEROS_RESPONSE 43 /* (KTEXT) */
221#define SSH_CMSG_HAVE_KERBEROS_TGT 44 /* credentials (s) */ 224#define SSH_CMSG_HAVE_KERBEROS_TGT 44 /* credentials (s) */
@@ -223,74 +226,79 @@ only by root, whereas ssh_config should be world-readable. */
223 226
224/*------------ definitions for login.c -------------*/ 227/*------------ definitions for login.c -------------*/
225 228
226/* Returns the time when the user last logged in. Returns 0 if the 229/* Returns the time when the user last logged in. Returns 0 if the
227 information is not available. This must be called before record_login. 230 information is not available. This must be called before record_login.
228 The host from which the user logged in is stored in buf. */ 231 The host from which the user logged in is stored in buf. */
229unsigned long get_last_login_time(uid_t uid, const char *logname, 232unsigned long
230 char *buf, unsigned int bufsize); 233get_last_login_time(uid_t uid, const char *logname,
234 char *buf, unsigned int bufsize);
231 235
232/* Records that the user has logged in. This does many things normally 236/* Records that the user has logged in. This does many things normally
233 done by login(1). */ 237 done by login(1). */
234void record_login(int pid, const char *ttyname, const char *user, uid_t uid, 238void
235 const char *host, struct sockaddr_in *addr); 239record_login(int pid, const char *ttyname, const char *user, uid_t uid,
240 const char *host, struct sockaddr_in * addr);
236 241
237/* Records that the user has logged out. This does many thigs normally 242/* Records that the user has logged out. This does many thigs normally
238 done by login(1) or init. */ 243 done by login(1) or init. */
239void record_logout(int pid, const char *ttyname); 244void record_logout(int pid, const char *ttyname);
240 245
241/*------------ definitions for sshconnect.c ----------*/ 246/*------------ definitions for sshconnect.c ----------*/
242 247
243/* Opens a TCP/IP connection to the remote server on the given host. If 248/* Opens a TCP/IP connection to the remote server on the given host. If
244 port is 0, the default port will be used. If anonymous is zero, 249 port is 0, the default port will be used. If anonymous is zero,
245 a privileged port will be allocated to make the connection. 250 a privileged port will be allocated to make the connection.
246 This requires super-user privileges if anonymous is false. 251 This requires super-user privileges if anonymous is false.
247 Connection_attempts specifies the maximum number of tries, one per 252 Connection_attempts specifies the maximum number of tries, one per
248 second. This returns true on success, and zero on failure. If the 253 second. This returns true on success, and zero on failure. If the
249 connection is successful, this calls packet_set_connection for the 254 connection is successful, this calls packet_set_connection for the
250 connection. */ 255 connection. */
251int ssh_connect(const char *host, struct sockaddr_in *hostaddr, 256int
252 int port, int connection_attempts, 257ssh_connect(const char *host, struct sockaddr_in * hostaddr,
253 int anonymous, uid_t original_real_uid, 258 int port, int connection_attempts,
254 const char *proxy_command); 259 int anonymous, uid_t original_real_uid,
260 const char *proxy_command);
255 261
256/* Starts a dialog with the server, and authenticates the current user on the 262/* Starts a dialog with the server, and authenticates the current user on the
257 server. This does not need any extra privileges. The basic connection 263 server. This does not need any extra privileges. The basic connection
258 to the server must already have been established before this is called. 264 to the server must already have been established before this is called.
259 If login fails, this function prints an error and never returns. 265 If login fails, this function prints an error and never returns.
260 This initializes the random state, and leaves it initialized (it will also 266 This initializes the random state, and leaves it initialized (it will also
261 have references from the packet module). */ 267 have references from the packet module). */
262 268
263void ssh_login(int host_key_valid, RSA *host_key, const char *host, 269void
264 struct sockaddr_in *hostaddr, uid_t original_real_uid); 270ssh_login(int host_key_valid, RSA * host_key, const char *host,
271 struct sockaddr_in * hostaddr, uid_t original_real_uid);
265 272
266/*------------ Definitions for various authentication methods. -------*/ 273/*------------ Definitions for various authentication methods. -------*/
267 274
268/* Tries to authenticate the user using the .rhosts file. Returns true if 275/* Tries to authenticate the user using the .rhosts file. Returns true if
269 authentication succeeds. If ignore_rhosts is non-zero, this will not 276 authentication succeeds. If ignore_rhosts is non-zero, this will not
270 consider .rhosts and .shosts (/etc/hosts.equiv will still be used). */ 277 consider .rhosts and .shosts (/etc/hosts.equiv will still be used). */
271int auth_rhosts(struct passwd *pw, const char *client_user); 278int auth_rhosts(struct passwd * pw, const char *client_user);
272 279
273/* Tries to authenticate the user using the .rhosts file and the host using 280/* Tries to authenticate the user using the .rhosts file and the host using
274 its host key. Returns true if authentication succeeds. */ 281 its host key. Returns true if authentication succeeds. */
275int auth_rhosts_rsa(struct passwd *pw, const char *client_user, 282int
276 BIGNUM *client_host_key_e, BIGNUM *client_host_key_n); 283auth_rhosts_rsa(struct passwd * pw, const char *client_user,
284 BIGNUM * client_host_key_e, BIGNUM * client_host_key_n);
277 285
278/* Tries to authenticate the user using password. Returns true if 286/* Tries to authenticate the user using password. Returns true if
279 authentication succeeds. */ 287 authentication succeeds. */
280int auth_password(struct passwd *pw, const char *password); 288int auth_password(struct passwd * pw, const char *password);
281 289
282/* Performs the RSA authentication dialog with the client. This returns 290/* Performs the RSA authentication dialog with the client. This returns
283 0 if the client could not be authenticated, and 1 if authentication was 291 0 if the client could not be authenticated, and 1 if authentication was
284 successful. This may exit if there is a serious protocol violation. */ 292 successful. This may exit if there is a serious protocol violation. */
285int auth_rsa(struct passwd *pw, BIGNUM *client_n); 293int auth_rsa(struct passwd * pw, BIGNUM * client_n);
286 294
287/* Parses an RSA key (number of bits, e, n) from a string. Moves the pointer 295/* Parses an RSA key (number of bits, e, n) from a string. Moves the pointer
288 over the key. Skips any whitespace at the beginning and at end. */ 296 over the key. Skips any whitespace at the beginning and at end. */
289int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM *e, BIGNUM *n); 297int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM * e, BIGNUM * n);
290 298
291/* Returns the name of the machine at the other end of the socket. The 299/* Returns the name of the machine at the other end of the socket. The
292 returned string should be freed by the caller. */ 300 returned string should be freed by the caller. */
293char *get_remote_hostname(int socket); 301char *get_remote_hostname(int socket);
294 302
295/* Return the canonical name of the host in the other side of the current 303/* Return the canonical name of the host in the other side of the current
296 connection (as returned by packet_get_connection). The host name is 304 connection (as returned by packet_get_connection). The host name is
@@ -302,296 +310,301 @@ const char *get_canonical_hostname(void);
302const char *get_remote_ipaddr(void); 310const char *get_remote_ipaddr(void);
303 311
304/* Returns the port number of the peer of the socket. */ 312/* Returns the port number of the peer of the socket. */
305int get_peer_port(int sock); 313int get_peer_port(int sock);
306 314
307/* Returns the port number of the remote host. */ 315/* Returns the port number of the remote host. */
308int get_remote_port(void); 316int get_remote_port(void);
309 317
310/* Tries to match the host name (which must be in all lowercase) against the 318/* Tries to match the host name (which must be in all lowercase) against the
311 comma-separated sequence of subpatterns (each possibly preceded by ! to 319 comma-separated sequence of subpatterns (each possibly preceded by ! to
312 indicate negation). Returns true if there is a positive match; zero 320 indicate negation). Returns true if there is a positive match; zero
313 otherwise. */ 321 otherwise. */
314int match_hostname(const char *host, const char *pattern, unsigned int len); 322int match_hostname(const char *host, const char *pattern, unsigned int len);
315 323
316/* Checks whether the given host is already in the list of our known hosts. 324/* Checks whether the given host is already in the list of our known hosts.
317 Returns HOST_OK if the host is known and has the specified key, 325 Returns HOST_OK if the host is known and has the specified key,
318 HOST_NEW if the host is not known, and HOST_CHANGED if the host is known 326 HOST_NEW if the host is not known, and HOST_CHANGED if the host is known
319 but used to have a different host key. The host must be in all lowercase. */ 327 but used to have a different host key. The host must be in all lowercase. */
320typedef enum { HOST_OK, HOST_NEW, HOST_CHANGED } HostStatus; 328typedef enum {
321HostStatus check_host_in_hostfile(const char *filename, const char *host, 329 HOST_OK, HOST_NEW, HOST_CHANGED
322 BIGNUM *e, BIGNUM *n, BIGNUM *ke, BIGNUM *kn); 330} HostStatus;
331HostStatus
332check_host_in_hostfile(const char *filename, const char *host,
333 BIGNUM * e, BIGNUM * n, BIGNUM * ke, BIGNUM * kn);
323 334
324/* Appends an entry to the host file. Returns false if the entry 335/* Appends an entry to the host file. Returns false if the entry
325 could not be appended. */ 336 could not be appended. */
326int add_host_to_hostfile(const char *filename, const char *host, 337int
327 BIGNUM *e, BIGNUM *n); 338add_host_to_hostfile(const char *filename, const char *host,
339 BIGNUM * e, BIGNUM * n);
328 340
329/* Performs the RSA authentication challenge-response dialog with the client, 341/* Performs the RSA authentication challenge-response dialog with the client,
330 and returns true (non-zero) if the client gave the correct answer to 342 and returns true (non-zero) if the client gave the correct answer to
331 our challenge; returns zero if the client gives a wrong answer. */ 343 our challenge; returns zero if the client gives a wrong answer. */
332int auth_rsa_challenge_dialog(BIGNUM *e, BIGNUM *n); 344int auth_rsa_challenge_dialog(BIGNUM * e, BIGNUM * n);
333 345
334/* Reads a passphrase from /dev/tty with echo turned off. Returns the 346/* Reads a passphrase from /dev/tty with echo turned off. Returns the
335 passphrase (allocated with xmalloc). Exits if EOF is encountered. 347 passphrase (allocated with xmalloc). Exits if EOF is encountered.
336 If from_stdin is true, the passphrase will be read from stdin instead. */ 348 If from_stdin is true, the passphrase will be read from stdin instead. */
337char *read_passphrase(const char *prompt, int from_stdin); 349char *read_passphrase(const char *prompt, int from_stdin);
338 350
339/* Saves the authentication (private) key in a file, encrypting it with 351/* Saves the authentication (private) key in a file, encrypting it with
340 passphrase. The identification of the file (lowest 64 bits of n) 352 passphrase. The identification of the file (lowest 64 bits of n)
341 will precede the key to provide identification of the key without 353 will precede the key to provide identification of the key without
342 needing a passphrase. */ 354 needing a passphrase. */
343int save_private_key(const char *filename, const char *passphrase, 355int
344 RSA *private_key, const char *comment); 356save_private_key(const char *filename, const char *passphrase,
357 RSA * private_key, const char *comment);
345 358
346/* Loads the public part of the key file (public key and comment). 359/* Loads the public part of the key file (public key and comment).
347 Returns 0 if an error occurred; zero if the public key was successfully 360 Returns 0 if an error occurred; zero if the public key was successfully
348 read. The comment of the key is returned in comment_return if it is 361 read. The comment of the key is returned in comment_return if it is
349 non-NULL; the caller must free the value with xfree. */ 362 non-NULL; the caller must free the value with xfree. */
350int load_public_key(const char *filename, RSA *pub, 363int
351 char **comment_return); 364load_public_key(const char *filename, RSA * pub,
365 char **comment_return);
352 366
353/* Loads the private key from the file. Returns 0 if an error is encountered 367/* Loads the private key from the file. Returns 0 if an error is encountered
354 (file does not exist or is not readable, or passphrase is bad). 368 (file does not exist or is not readable, or passphrase is bad).
355 This initializes the private key. The comment of the key is returned 369 This initializes the private key. The comment of the key is returned
356 in comment_return if it is non-NULL; the caller must free the value 370 in comment_return if it is non-NULL; the caller must free the value
357 with xfree. */ 371 with xfree. */
358int load_private_key(const char *filename, const char *passphrase, 372int
359 RSA *private_key, char **comment_return); 373load_private_key(const char *filename, const char *passphrase,
374 RSA * private_key, char **comment_return);
360 375
361/*------------ Definitions for logging. -----------------------*/ 376/*------------ Definitions for logging. -----------------------*/
362 377
363/* Supported syslog facilities and levels. */ 378/* Supported syslog facilities and levels. */
364typedef enum 379typedef enum {
365{ 380 SYSLOG_FACILITY_DAEMON,
366 SYSLOG_FACILITY_DAEMON, 381 SYSLOG_FACILITY_USER,
367 SYSLOG_FACILITY_USER, 382 SYSLOG_FACILITY_AUTH,
368 SYSLOG_FACILITY_AUTH, 383 SYSLOG_FACILITY_LOCAL0,
369 SYSLOG_FACILITY_LOCAL0, 384 SYSLOG_FACILITY_LOCAL1,
370 SYSLOG_FACILITY_LOCAL1, 385 SYSLOG_FACILITY_LOCAL2,
371 SYSLOG_FACILITY_LOCAL2, 386 SYSLOG_FACILITY_LOCAL3,
372 SYSLOG_FACILITY_LOCAL3, 387 SYSLOG_FACILITY_LOCAL4,
373 SYSLOG_FACILITY_LOCAL4, 388 SYSLOG_FACILITY_LOCAL5,
374 SYSLOG_FACILITY_LOCAL5, 389 SYSLOG_FACILITY_LOCAL6,
375 SYSLOG_FACILITY_LOCAL6, 390 SYSLOG_FACILITY_LOCAL7
376 SYSLOG_FACILITY_LOCAL7 391} SyslogFacility;
377} SyslogFacility; 392
378 393typedef enum {
379typedef enum 394 SYSLOG_LEVEL_QUIET,
380{ 395 SYSLOG_LEVEL_FATAL,
381 SYSLOG_LEVEL_QUIET, 396 SYSLOG_LEVEL_ERROR,
382 SYSLOG_LEVEL_FATAL, 397 SYSLOG_LEVEL_INFO,
383 SYSLOG_LEVEL_ERROR, 398 SYSLOG_LEVEL_VERBOSE,
384 SYSLOG_LEVEL_INFO, 399 SYSLOG_LEVEL_DEBUG
385 SYSLOG_LEVEL_CHAT, 400} LogLevel;
386 SYSLOG_LEVEL_DEBUG
387} LogLevel;
388
389/* Initializes logging. */ 401/* Initializes logging. */
390void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr); 402void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr);
391 403
392/* Logging implementation, depending on server or client */ 404/* Logging implementation, depending on server or client */
393void do_log(LogLevel level, const char *fmt, va_list args); 405void do_log(LogLevel level, const char *fmt, va_list args);
394 406
395/* name to facility/level */ 407/* name to facility/level */
396SyslogFacility log_facility_number(char *name); 408SyslogFacility log_facility_number(char *name);
397LogLevel log_level_number(char *name); 409LogLevel log_level_number(char *name);
398 410
399/* Output a message to syslog or stderr */ 411/* Output a message to syslog or stderr */
400void fatal(const char *fmt, ...); 412void fatal(const char *fmt,...) __attribute__((format(printf, 1, 2)));
401void error(const char *fmt, ...); 413void error(const char *fmt,...) __attribute__((format(printf, 1, 2)));
402void log(const char *fmt, ...); 414void log(const char *fmt,...) __attribute__((format(printf, 1, 2)));
403void chat(const char *fmt, ...); 415void verbose(const char *fmt,...) __attribute__((format(printf, 1, 2)));
404void debug(const char *fmt, ...); 416void debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
405 417
406/* same as fatal() but w/o logging */ 418/* same as fatal() but w/o logging */
407void fatal_cleanup(void); 419void fatal_cleanup(void);
408 420
409/* Registers a cleanup function to be called by fatal()/fatal_cleanup() before exiting. 421/* Registers a cleanup function to be called by fatal()/fatal_cleanup() before exiting.
410 It is permissible to call fatal_remove_cleanup for the function itself 422 It is permissible to call fatal_remove_cleanup for the function itself
411 from the function. */ 423 from the function. */
412void fatal_add_cleanup(void (*proc)(void *context), void *context); 424void fatal_add_cleanup(void (*proc) (void *context), void *context);
413 425
414/* Removes a cleanup function to be called at fatal(). */ 426/* Removes a cleanup function to be called at fatal(). */
415void fatal_remove_cleanup(void (*proc)(void *context), void *context); 427void fatal_remove_cleanup(void (*proc) (void *context), void *context);
416 428
417/*---------------- definitions for channels ------------------*/ 429/*---------------- definitions for channels ------------------*/
418 430
419/* Sets specific protocol options. */ 431/* Sets specific protocol options. */
420void channel_set_options(int hostname_in_open); 432void channel_set_options(int hostname_in_open);
421 433
422/* Allocate a new channel object and set its type and socket. Remote_name 434/* Allocate a new channel object and set its type and socket. Remote_name
423 must have been allocated with xmalloc; this will free it when the channel 435 must have been allocated with xmalloc; this will free it when the channel
424 is freed. */ 436 is freed. */
425int channel_allocate(int type, int sock, char *remote_name); 437int channel_allocate(int type, int sock, char *remote_name);
426 438
427/* Free the channel and close its socket. */ 439/* Free the channel and close its socket. */
428void channel_free(int channel); 440void channel_free(int channel);
429 441
430/* Add any bits relevant to channels in select bitmasks. */ 442/* Add any bits relevant to channels in select bitmasks. */
431void channel_prepare_select(fd_set *readset, fd_set *writeset); 443void channel_prepare_select(fd_set * readset, fd_set * writeset);
432 444
433/* After select, perform any appropriate operations for channels which 445/* After select, perform any appropriate operations for channels which
434 have events pending. */ 446 have events pending. */
435void channel_after_select(fd_set *readset, fd_set *writeset); 447void channel_after_select(fd_set * readset, fd_set * writeset);
436 448
437/* If there is data to send to the connection, send some of it now. */ 449/* If there is data to send to the connection, send some of it now. */
438void channel_output_poll(void); 450void channel_output_poll(void);
439 451
440/* This is called when a packet of type CHANNEL_DATA has just been received. 452/* This is called when a packet of type CHANNEL_DATA has just been received.
441 The message type has already been consumed, but channel number and data 453 The message type has already been consumed, but channel number and data
442 is still there. */ 454 is still there. */
443void channel_input_data(int payload_len); 455void channel_input_data(int payload_len);
444 456
445/* Returns true if no channel has too much buffered data. */ 457/* Returns true if no channel has too much buffered data. */
446int channel_not_very_much_buffered_data(void); 458int channel_not_very_much_buffered_data(void);
447 459
448/* This is called after receiving CHANNEL_CLOSE. */ 460/* This is called after receiving CHANNEL_CLOSE. */
449void channel_input_close(void); 461void channel_input_close(void);
450 462
451/* This is called after receiving CHANNEL_CLOSE_CONFIRMATION. */ 463/* This is called after receiving CHANNEL_CLOSE_CONFIRMATION. */
452void channel_input_close_confirmation(void); 464void channel_input_close_confirmation(void);
453 465
454/* This is called after receiving CHANNEL_OPEN_CONFIRMATION. */ 466/* This is called after receiving CHANNEL_OPEN_CONFIRMATION. */
455void channel_input_open_confirmation(void); 467void channel_input_open_confirmation(void);
456 468
457/* This is called after receiving CHANNEL_OPEN_FAILURE from the other side. */ 469/* This is called after receiving CHANNEL_OPEN_FAILURE from the other side. */
458void channel_input_open_failure(void); 470void channel_input_open_failure(void);
459 471
460/* This closes any sockets that are listening for connections; this removes 472/* This closes any sockets that are listening for connections; this removes
461 any unix domain sockets. */ 473 any unix domain sockets. */
462void channel_stop_listening(void); 474void channel_stop_listening(void);
463 475
464/* Closes the sockets of all channels. This is used to close extra file 476/* Closes the sockets of all channels. This is used to close extra file
465 descriptors after a fork. */ 477 descriptors after a fork. */
466void channel_close_all(void); 478void channel_close_all(void);
467 479
468/* Returns the maximum file descriptor number used by the channels. */ 480/* Returns the maximum file descriptor number used by the channels. */
469int channel_max_fd(void); 481int channel_max_fd(void);
470 482
471/* Returns true if there is still an open channel over the connection. */ 483/* Returns true if there is still an open channel over the connection. */
472int channel_still_open(void); 484int channel_still_open(void);
473 485
474/* Returns a string containing a list of all open channels. The list is 486/* Returns a string containing a list of all open channels. The list is
475 suitable for displaying to the user. It uses crlf instead of newlines. 487 suitable for displaying to the user. It uses crlf instead of newlines.
476 The caller should free the string with xfree. */ 488 The caller should free the string with xfree. */
477char *channel_open_message(void); 489char *channel_open_message(void);
478 490
479/* Initiate forwarding of connections to local port "port" through the secure 491/* Initiate forwarding of connections to local port "port" through the secure
480 channel to host:port from remote side. This never returns if there 492 channel to host:port from remote side. This never returns if there
481 was an error. */ 493 was an error. */
482void channel_request_local_forwarding(int port, const char *host, 494void
483 int remote_port); 495channel_request_local_forwarding(int port, const char *host,
496 int remote_port);
484 497
485/* Initiate forwarding of connections to port "port" on remote host through 498/* Initiate forwarding of connections to port "port" on remote host through
486 the secure channel to host:port from local side. This never returns 499 the secure channel to host:port from local side. This never returns
487 if there was an error. This registers that open requests for that 500 if there was an error. This registers that open requests for that
488 port are permitted. */ 501 port are permitted. */
489void channel_request_remote_forwarding(int port, const char *host, 502void
490 int remote_port); 503channel_request_remote_forwarding(int port, const char *host,
504 int remote_port);
491 505
492/* Permits opening to any host/port in SSH_MSG_PORT_OPEN. This is usually 506/* Permits opening to any host/port in SSH_MSG_PORT_OPEN. This is usually
493 called by the server, because the user could connect to any port anyway, 507 called by the server, because the user could connect to any port anyway,
494 and the server has no way to know but to trust the client anyway. */ 508 and the server has no way to know but to trust the client anyway. */
495void channel_permit_all_opens(void); 509void channel_permit_all_opens(void);
496 510
497/* This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates 511/* This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates
498 listening for the port, and sends back a success reply (or disconnect 512 listening for the port, and sends back a success reply (or disconnect
499 message if there was an error). This never returns if there was an 513 message if there was an error). This never returns if there was an
500 error. */ 514 error. */
501void channel_input_port_forward_request(int is_root); 515void channel_input_port_forward_request(int is_root);
502 516
503/* This is called after receiving PORT_OPEN message. This attempts to connect 517/* This is called after receiving PORT_OPEN message. This attempts to connect
504 to the given host:port, and sends back CHANNEL_OPEN_CONFIRMATION or 518 to the given host:port, and sends back CHANNEL_OPEN_CONFIRMATION or
505 CHANNEL_OPEN_FAILURE. */ 519 CHANNEL_OPEN_FAILURE. */
506void channel_input_port_open(int payload_len); 520void channel_input_port_open(int payload_len);
507 521
508/* Creates a port for X11 connections, and starts listening for it. 522/* Creates a port for X11 connections, and starts listening for it.
509 Returns the display name, or NULL if an error was encountered. */ 523 Returns the display name, or NULL if an error was encountered. */
510char *x11_create_display(int screen); 524char *x11_create_display(int screen);
511 525
512/* Creates an internet domain socket for listening for X11 connections. 526/* Creates an internet domain socket for listening for X11 connections.
513 Returns a suitable value for the DISPLAY variable, or NULL if an error 527 Returns a suitable value for the DISPLAY variable, or NULL if an error
514 occurs. */ 528 occurs. */
515char *x11_create_display_inet(int screen); 529char *x11_create_display_inet(int screen);
516 530
517/* This is called when SSH_SMSG_X11_OPEN is received. The packet contains 531/* This is called when SSH_SMSG_X11_OPEN is received. The packet contains
518 the remote channel number. We should do whatever we want, and respond 532 the remote channel number. We should do whatever we want, and respond
519 with either SSH_MSG_OPEN_CONFIRMATION or SSH_MSG_OPEN_FAILURE. */ 533 with either SSH_MSG_OPEN_CONFIRMATION or SSH_MSG_OPEN_FAILURE. */
520void x11_input_open(int payload_len); 534void x11_input_open(int payload_len);
521 535
522/* Requests forwarding of X11 connections. This should be called on the 536/* Requests forwarding of X11 connections. This should be called on the
523 client only. */ 537 client only. */
524void x11_request_forwarding(void); 538void x11_request_forwarding(void);
525 539
526/* Requests forwarding for X11 connections, with authentication spoofing. 540/* Requests forwarding for X11 connections, with authentication spoofing.
527 This should be called in the client only. */ 541 This should be called in the client only. */
528void x11_request_forwarding_with_spoofing(const char *proto, const char *data); 542void x11_request_forwarding_with_spoofing(const char *proto, const char *data);
529 543
530/* Sends a message to the server to request authentication fd forwarding. */ 544/* Sends a message to the server to request authentication fd forwarding. */
531void auth_request_forwarding(void); 545void auth_request_forwarding(void);
532 546
533/* Returns the name of the forwarded authentication socket. Returns NULL 547/* Returns the name of the forwarded authentication socket. Returns NULL
534 if there is no forwarded authentication socket. The returned value points 548 if there is no forwarded authentication socket. The returned value points
535 to a static buffer. */ 549 to a static buffer. */
536char *auth_get_socket_name(void); 550char *auth_get_socket_name(void);
537 551
538/* This if called to process SSH_CMSG_AGENT_REQUEST_FORWARDING on the server. 552/* This if called to process SSH_CMSG_AGENT_REQUEST_FORWARDING on the server.
539 This starts forwarding authentication requests. */ 553 This starts forwarding authentication requests. */
540void auth_input_request_forwarding(struct passwd *pw); 554void auth_input_request_forwarding(struct passwd * pw);
541 555
542/* This is called to process an SSH_SMSG_AGENT_OPEN message. */ 556/* This is called to process an SSH_SMSG_AGENT_OPEN message. */
543void auth_input_open_request(void); 557void auth_input_open_request(void);
544 558
545/* Returns true if the given string matches the pattern (which may contain 559/* Returns true if the given string matches the pattern (which may contain
546 ? and * as wildcards), and zero if it does not match. */ 560 ? and * as wildcards), and zero if it does not match. */
547int match_pattern(const char *s, const char *pattern); 561int match_pattern(const char *s, const char *pattern);
548 562
549/* Expands tildes in the file name. Returns data allocated by xmalloc. 563/* Expands tildes in the file name. Returns data allocated by xmalloc.
550 Warning: this calls getpw*. */ 564 Warning: this calls getpw*. */
551char *tilde_expand_filename(const char *filename, uid_t my_uid); 565char *tilde_expand_filename(const char *filename, uid_t my_uid);
552 566
553/* Performs the interactive session. This handles data transmission between 567/* Performs the interactive session. This handles data transmission between
554 the client and the program. Note that the notion of stdin, stdout, and 568 the client and the program. Note that the notion of stdin, stdout, and
555 stderr in this function is sort of reversed: this function writes to 569 stderr in this function is sort of reversed: this function writes to
556 stdin (of the child program), and reads from stdout and stderr (of the 570 stdin (of the child program), and reads from stdout and stderr (of the
557 child program). */ 571 child program). */
558void server_loop(int pid, int fdin, int fdout, int fderr); 572void server_loop(int pid, int fdin, int fdout, int fderr);
559 573
560/* Client side main loop for the interactive session. */ 574/* Client side main loop for the interactive session. */
561int client_loop(int have_pty, int escape_char); 575int client_loop(int have_pty, int escape_char);
562 576
563/* Linked list of custom environment strings (see auth-rsa.c). */ 577/* Linked list of custom environment strings (see auth-rsa.c). */
564struct envstring { 578struct envstring {
565 struct envstring *next; 579 struct envstring *next;
566 char *s; 580 char *s;
567}; 581};
568
569#ifdef KRB4 582#ifdef KRB4
570#include <krb.h> 583#include <krb.h>
571 584
572/* Performs Kerberos v4 mutual authentication with the client. This returns 585/* Performs Kerberos v4 mutual authentication with the client. This returns
573 0 if the client could not be authenticated, and 1 if authentication was 586 0 if the client could not be authenticated, and 1 if authentication was
574 successful. This may exit if there is a serious protocol violation. */ 587 successful. This may exit if there is a serious protocol violation. */
575int auth_krb4(const char *server_user, KTEXT auth, char **client); 588int auth_krb4(const char *server_user, KTEXT auth, char **client);
576int krb4_init(uid_t uid); 589int krb4_init(uid_t uid);
577void krb4_cleanup_proc(void *ignore); 590void krb4_cleanup_proc(void *ignore);
578 591
579#ifdef AFS 592#ifdef AFS
580#include <kafs.h> 593#include <kafs.h>
581 594
582/* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */ 595/* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */
583int auth_kerberos_tgt(struct passwd *pw, const char *string); 596int auth_kerberos_tgt(struct passwd * pw, const char *string);
584int auth_afs_token(struct passwd *pw, const char *token_string); 597int auth_afs_token(struct passwd * pw, const char *token_string);
585 598
586int creds_to_radix(CREDENTIALS *creds, unsigned char *buf); 599int creds_to_radix(CREDENTIALS * creds, unsigned char *buf);
587int radix_to_creds(const char *buf, CREDENTIALS *creds); 600int radix_to_creds(const char *buf, CREDENTIALS * creds);
588#endif /* AFS */ 601#endif /* AFS */
589 602
590#endif /* KRB4 */ 603#endif /* KRB4 */
591 604
592#ifdef SKEY 605#ifdef SKEY
593#include <skey.h> 606#include <skey.h>
594char *skey_fake_keyinfo(char *username); 607char *skey_fake_keyinfo(char *username);
595#endif /* SKEY */ 608#endif /* SKEY */
596 609
597#endif /* SSH_H */ 610#endif /* SSH_H */