Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
Damien Miller | b38eff8 | 2000-04-01 11:09:21 +1000 | [diff] [blame] | 16 | /* RCSID("$Id: ssh.h,v 1.29 2000/04/01 01:09:26 damien Exp $"); */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 17 | |
| 18 | #ifndef SSH_H |
| 19 | #define SSH_H |
| 20 | |
Damien Miller | ab18c41 | 1999-11-11 10:40:23 +1100 | [diff] [blame] | 21 | #include <netinet/in.h> /* For struct sockaddr_in */ |
| 22 | #include <pwd.h> /* For struct pw */ |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 23 | #include <stdarg.h> /* For va_list */ |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 24 | #include <sys/socket.h> /* For struct sockaddr_storage */ |
| 25 | #include "fake-socket.h" /* For struct sockaddr_storage */ |
Damien Miller | 365199d | 1999-12-22 00:12:38 +1100 | [diff] [blame] | 26 | #ifdef HAVE_SYS_SELECT_H |
| 27 | # include <sys/select.h> |
| 28 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 29 | #include "rsa.h" |
| 30 | #include "cipher.h" |
| 31 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 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 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 48 | /* |
| 49 | * Maximum number of RSA authentication identity files that can be specified |
| 50 | * in configuration files or on the command line. |
| 51 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 52 | #define SSH_MAX_IDENTITY_FILES 100 |
| 53 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 54 | /* |
| 55 | * Major protocol version. Different version indicates major incompatiblity |
| 56 | * that prevents communication. |
| 57 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 58 | #define PROTOCOL_MAJOR 1 |
| 59 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 60 | /* |
| 61 | * Minor protocol version. Different version indicates minor incompatibility |
| 62 | * that does not prevent interoperation. |
| 63 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 64 | #define PROTOCOL_MINOR 5 |
| 65 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 66 | /* |
| 67 | * Name for the service. The port named by this service overrides the |
| 68 | * default port if present. |
| 69 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 70 | #define SSH_SERVICE_NAME "ssh" |
| 71 | |
| 72 | #ifndef ETCDIR |
| 73 | #define ETCDIR "/etc" |
| 74 | #endif /* ETCDIR */ |
| 75 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 76 | #ifndef PIDDIR |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 77 | #define PIDDIR "/var/run" |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 78 | #endif /* PIDDIR */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 79 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 80 | /* |
| 81 | * System-wide file containing host keys of known hosts. This file should be |
| 82 | * world-readable. |
| 83 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 84 | #define SSH_SYSTEM_HOSTFILE ETCDIR "/ssh_known_hosts" |
| 85 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 86 | /* |
| 87 | * Of these, ssh_host_key must be readable only by root, whereas ssh_config |
| 88 | * should be world-readable. |
| 89 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 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 | |
Damien Miller | 356a0b0 | 1999-11-08 15:30:59 +1100 | [diff] [blame] | 94 | #ifndef SSH_PROGRAM |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 95 | #define SSH_PROGRAM "/usr/bin/ssh" |
Damien Miller | 356a0b0 | 1999-11-08 15:30:59 +1100 | [diff] [blame] | 96 | #endif /* SSH_PROGRAM */ |
| 97 | |
| 98 | #ifndef LOGIN_PROGRAM |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 99 | #define LOGIN_PROGRAM "/usr/bin/login" |
Damien Miller | 356a0b0 | 1999-11-08 15:30:59 +1100 | [diff] [blame] | 100 | #endif /* LOGIN_PROGRAM */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 101 | |
Damien Miller | c7b38ce | 1999-11-09 10:28:04 +1100 | [diff] [blame] | 102 | #ifndef ASKPASS_PROGRAM |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 103 | #define ASKPASS_PROGRAM "/usr/lib/ssh/ssh-askpass" |
Damien Miller | c7b38ce | 1999-11-09 10:28:04 +1100 | [diff] [blame] | 104 | #endif /* ASKPASS_PROGRAM */ |
| 105 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | a37010e | 1999-10-29 09:18:29 +1000 | [diff] [blame] | 110 | #define SSH_DAEMON_PID_FILE PIDDIR "/sshd.pid" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 111 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 116 | #define SSH_USER_DIR ".ssh" |
| 117 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 123 | #define SSH_USER_HOSTFILE "~/.ssh/known_hosts" |
| 124 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 129 | #define SSH_CLIENT_IDENTITY ".ssh/identity" |
| 130 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 137 | #define SSH_USER_CONFFILE ".ssh/config" |
| 138 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 147 | #define SSH_USER_PERMITTED_KEYS ".ssh/authorized_keys" |
| 148 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 155 | #define SSH_USER_RC ".ssh/rc" |
| 156 | #define SSH_SYSTEM_RC ETCDIR "/sshrc" |
| 157 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 162 | #define SSH_HOSTS_EQUIV ETCDIR "/shosts.equiv" |
| 163 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 164 | /* |
| 165 | * Name of the environment variable containing the pathname of the |
| 166 | * authentication socket. |
| 167 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 168 | #define SSH_AUTHSOCKET_ENV_NAME "SSH_AUTH_SOCK" |
| 169 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 170 | /* |
| 171 | * Name of the environment variable containing the pathname of the |
| 172 | * authentication socket. |
| 173 | */ |
Damien Miller | 3226509 | 1999-11-12 11:33:04 +1100 | [diff] [blame] | 174 | #define SSH_AGENTPID_ENV_NAME "SSH_AGENT_PID" |
Damien Miller | 5eeedae | 1999-10-29 10:21:15 +1000 | [diff] [blame] | 175 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 176 | /* |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 177 | * Default path to ssh-askpass used by ssh-add, |
| 178 | * environment variable for overwriting the default location |
| 179 | */ |
Damien Miller | 3bc14dd | 1999-12-07 14:54:53 +1100 | [diff] [blame] | 180 | #ifndef SSH_ASKPASS_DEFAULT |
| 181 | # define SSH_ASKPASS_DEFAULT "/usr/X11R6/bin/ssh-askpass" |
| 182 | #endif |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 183 | #define SSH_ASKPASS_ENV "SSH_ASKPASS" |
| 184 | |
| 185 | /* |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 189 | #define SSH_KEY_BITS_RESERVED 128 |
| 190 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 191 | /* |
| 192 | * Length of the session key in bytes. (Specified as 256 bits in the |
| 193 | * protocol.) |
| 194 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 195 | #define SSH_SESSION_KEY_LENGTH 32 |
| 196 | |
| 197 | /* Name of Kerberos service for SSH to use. */ |
| 198 | #define KRB4_SERVICE_NAME "rcmd" |
| 199 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 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 |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 208 | #define SSH_AUTH_TIS 5 |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 209 | #define SSH_AUTH_KERBEROS 6 |
| 210 | #define SSH_PASS_KERBEROS_TGT 7 |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 211 | /* 8 to 15 are reserved */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 212 | #define SSH_PASS_AFS_TOKEN 21 |
| 213 | |
| 214 | /* Protocol flags. These are bit masks. */ |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 215 | #define SSH_PROTOFLAG_SCREEN_NUMBER 1 /* X11 forwarding includes screen */ |
| 216 | #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2 /* forwarding opens contain host */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 217 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 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) */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 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) */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 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 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 272 | /*------------ definitions for login.c -------------*/ |
| 273 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 279 | unsigned long |
| 280 | get_last_login_time(uid_t uid, const char *logname, |
| 281 | char *buf, unsigned int bufsize); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 282 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 283 | /* |
| 284 | * Records that the user has logged in. This does many things normally done |
| 285 | * by login(1). |
| 286 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 287 | void |
| 288 | record_login(int pid, const char *ttyname, const char *user, uid_t uid, |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 289 | const char *host, struct sockaddr *addr); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 290 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 291 | /* |
| 292 | * Records that the user has logged out. This does many thigs normally done |
| 293 | * by login(1) or init. |
| 294 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 295 | void record_logout(int pid, const char *ttyname); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 296 | |
| 297 | /*------------ definitions for sshconnect.c ----------*/ |
| 298 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 308 | int |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 309 | ssh_connect(const char *host, struct sockaddr_storage * hostaddr, |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 310 | u_short port, int connection_attempts, |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 311 | int anonymous, uid_t original_real_uid, |
| 312 | const char *proxy_command); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 313 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | 5ce662a | 1999-11-11 17:57:39 +1100 | [diff] [blame] | 322 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 323 | void |
| 324 | ssh_login(int host_key_valid, RSA * host_key, const char *host, |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 325 | struct sockaddr * hostaddr, uid_t original_real_uid); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 326 | |
| 327 | /*------------ Definitions for various authentication methods. -------*/ |
| 328 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 334 | int auth_rhosts(struct passwd * pw, const char *client_user); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 335 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 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 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 340 | int |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 341 | auth_rhosts_rsa(struct passwd * pw, const char *client_user, RSA* client_host_key); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 342 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 343 | /* |
| 344 | * Tries to authenticate the user using password. Returns true if |
| 345 | * authentication succeeds. |
| 346 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 347 | int auth_password(struct passwd * pw, const char *password); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 348 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 349 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 354 | int auth_rsa(struct passwd * pw, BIGNUM * client_n); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 355 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 356 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 360 | int auth_rsa_read_key(char **cpp, unsigned int *bitsp, BIGNUM * e, BIGNUM * n); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 361 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 362 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 366 | char *get_remote_hostname(int socket); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 367 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 368 | /* |
| 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 373 | const char *get_canonical_hostname(void); |
| 374 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 375 | /* |
| 376 | * Returns the remote IP address as an ascii string. The value need not be |
| 377 | * freed by the caller. |
| 378 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 379 | const char *get_remote_ipaddr(void); |
| 380 | |
| 381 | /* Returns the port number of the peer of the socket. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 382 | int get_peer_port(int sock); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 383 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 384 | /* Returns the port number of the remote/local host. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 385 | int get_remote_port(void); |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 386 | int get_local_port(void); |
| 387 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 388 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 389 | /* |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 390 | * 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 Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 394 | int auth_rsa_challenge_dialog(RSA *pk); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 395 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 396 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 401 | char *read_passphrase(const char *prompt, int from_stdin); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 402 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 403 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 409 | int |
| 410 | save_private_key(const char *filename, const char *passphrase, |
| 411 | RSA * private_key, const char *comment); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 412 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 413 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 419 | int |
| 420 | load_public_key(const char *filename, RSA * pub, |
| 421 | char **comment_return); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 422 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 423 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 430 | int |
| 431 | load_private_key(const char *filename, const char *passphrase, |
| 432 | RSA * private_key, char **comment_return); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 433 | |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 434 | /*------------ Definitions for logging. -----------------------*/ |
| 435 | |
| 436 | /* Supported syslog facilities and levels. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 437 | typedef 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 Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 450 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 451 | typedef 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 Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 459 | /* Initializes logging. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 460 | void log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 461 | |
| 462 | /* Logging implementation, depending on server or client */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 463 | void do_log(LogLevel level, const char *fmt, va_list args); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 464 | |
Damien Miller | 6162d12 | 1999-11-21 13:23:52 +1100 | [diff] [blame] | 465 | /* name to facility/level */ |
| 466 | SyslogFacility log_facility_number(char *name); |
| 467 | LogLevel log_level_number(char *name); |
| 468 | |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 469 | /* Output a message to syslog or stderr */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 470 | void fatal(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
| 471 | void error(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
| 472 | void log(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
| 473 | void verbose(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
| 474 | void debug(const char *fmt,...) __attribute__((format(printf, 1, 2))); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 475 | |
| 476 | /* same as fatal() but w/o logging */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 477 | void fatal_cleanup(void); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 478 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 479 | /* |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 484 | void fatal_add_cleanup(void (*proc) (void *context), void *context); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 485 | |
| 486 | /* Removes a cleanup function to be called at fatal(). */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 487 | void fatal_remove_cleanup(void (*proc) (void *context), void *context); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 488 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 489 | /* |
| 490 | * Expands tildes in the file name. Returns data allocated by xmalloc. |
| 491 | * Warning: this calls getpw*. |
| 492 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 493 | char *tilde_expand_filename(const char *filename, uid_t my_uid); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 494 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 495 | /* |
| 496 | * Performs the interactive session. This handles data transmission between |
| 497 | * the client and the program. Note that the notion of stdin, stdout, and |
| 498 | * stderr in this function is sort of reversed: this function writes to stdin |
| 499 | * (of the child program), and reads from stdout and stderr (of the child |
| 500 | * program). |
| 501 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 502 | void server_loop(int pid, int fdin, int fdout, int fderr); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 503 | |
| 504 | /* Client side main loop for the interactive session. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 505 | int client_loop(int have_pty, int escape_char); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 506 | |
| 507 | /* Linked list of custom environment strings (see auth-rsa.c). */ |
| 508 | struct envstring { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 509 | struct envstring *next; |
| 510 | char *s; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 511 | }; |
Damien Miller | 037a0dc | 1999-12-07 15:38:31 +1100 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * Ensure all of data on socket comes through. f==read || f==write |
| 515 | */ |
Damien Miller | 98c7ad6 | 2000-03-09 21:27:49 +1100 | [diff] [blame] | 516 | ssize_t atomicio(ssize_t (*f)(), int fd, void *s, size_t n); |
Damien Miller | 037a0dc | 1999-12-07 15:38:31 +1100 | [diff] [blame] | 517 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 518 | #ifdef KRB4 |
| 519 | #include <krb.h> |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 520 | /* |
| 521 | * Performs Kerberos v4 mutual authentication with the client. This returns 0 |
| 522 | * if the client could not be authenticated, and 1 if authentication was |
| 523 | * successful. This may exit if there is a serious protocol violation. |
| 524 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 525 | int auth_krb4(const char *server_user, KTEXT auth, char **client); |
| 526 | int krb4_init(uid_t uid); |
| 527 | void krb4_cleanup_proc(void *ignore); |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 528 | int auth_krb4_password(struct passwd * pw, const char *password); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 529 | |
| 530 | #ifdef AFS |
| 531 | #include <kafs.h> |
| 532 | |
| 533 | /* Accept passed Kerberos v4 ticket-granting ticket and AFS tokens. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 534 | int auth_kerberos_tgt(struct passwd * pw, const char *string); |
| 535 | int auth_afs_token(struct passwd * pw, const char *token_string); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 536 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 537 | int creds_to_radix(CREDENTIALS * creds, unsigned char *buf); |
| 538 | int radix_to_creds(const char *buf, CREDENTIALS * creds); |
| 539 | #endif /* AFS */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 540 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 541 | #endif /* KRB4 */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 542 | |
| 543 | #ifdef SKEY |
| 544 | #include <skey.h> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 545 | char *skey_fake_keyinfo(char *username); |
Damien Miller | aae6c61 | 1999-12-06 11:47:28 +1100 | [diff] [blame] | 546 | int auth_skey_password(struct passwd * pw, const char *password); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 547 | #endif /* SKEY */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 548 | |
Damien Miller | 34132e5 | 2000-01-14 15:45:46 +1100 | [diff] [blame] | 549 | /* AF_UNSPEC or AF_INET or AF_INET6 */ |
| 550 | extern int IPv4or6; |
| 551 | |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 552 | #ifdef USE_PAM |
| 553 | #include "auth-pam.h" |
| 554 | #endif /* USE_PAM */ |
| 555 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 556 | #endif /* SSH_H */ |