1*ce74bacaSMatthew Dillon /* $OpenBSD: sshconnect.h,v 1.31 2017/09/12 06:32:07 djm Exp $ */ 218de8d7fSPeter Avalos 318de8d7fSPeter Avalos /* 418de8d7fSPeter Avalos * Copyright (c) 2000 Markus Friedl. All rights reserved. 518de8d7fSPeter Avalos * 618de8d7fSPeter Avalos * Redistribution and use in source and binary forms, with or without 718de8d7fSPeter Avalos * modification, are permitted provided that the following conditions 818de8d7fSPeter Avalos * are met: 918de8d7fSPeter Avalos * 1. Redistributions of source code must retain the above copyright 1018de8d7fSPeter Avalos * notice, this list of conditions and the following disclaimer. 1118de8d7fSPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 1218de8d7fSPeter Avalos * notice, this list of conditions and the following disclaimer in the 1318de8d7fSPeter Avalos * documentation and/or other materials provided with the distribution. 1418de8d7fSPeter Avalos * 1518de8d7fSPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1618de8d7fSPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1718de8d7fSPeter Avalos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1818de8d7fSPeter Avalos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1918de8d7fSPeter Avalos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2018de8d7fSPeter Avalos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2118de8d7fSPeter Avalos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2218de8d7fSPeter Avalos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2318de8d7fSPeter Avalos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2418de8d7fSPeter Avalos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2518de8d7fSPeter Avalos */ 2618de8d7fSPeter Avalos 2718de8d7fSPeter Avalos typedef struct Sensitive Sensitive; 2818de8d7fSPeter Avalos struct Sensitive { 29*ce74bacaSMatthew Dillon struct sshkey **keys; 3018de8d7fSPeter Avalos int nkeys; 3118de8d7fSPeter Avalos int external_keysign; 3218de8d7fSPeter Avalos }; 3318de8d7fSPeter Avalos 3436e94dc5SPeter Avalos struct addrinfo; 35*ce74bacaSMatthew Dillon struct ssh; 36*ce74bacaSMatthew Dillon 37*ce74bacaSMatthew Dillon int ssh_connect(struct ssh *, const char *, struct addrinfo *, 38*ce74bacaSMatthew Dillon struct sockaddr_storage *, u_short, int, int, int *, int, int); 399f304aafSPeter Avalos void ssh_kill_proxy_command(void); 4018de8d7fSPeter Avalos 419f304aafSPeter Avalos void ssh_login(Sensitive *, const char *, struct sockaddr *, u_short, 429f304aafSPeter Avalos struct passwd *, int); 4318de8d7fSPeter Avalos 4440c002afSPeter Avalos void ssh_exchange_identification(int); 4540c002afSPeter Avalos 46*ce74bacaSMatthew Dillon int verify_host_key(char *, struct sockaddr *, struct sshkey *); 4718de8d7fSPeter Avalos 489f304aafSPeter Avalos void get_hostfile_hostname_ipaddr(char *, struct sockaddr *, u_short, 499f304aafSPeter Avalos char **, char **); 509f304aafSPeter Avalos 5118de8d7fSPeter Avalos void ssh_kex(char *, struct sockaddr *); 529f304aafSPeter Avalos void ssh_kex2(char *, struct sockaddr *, u_short); 5318de8d7fSPeter Avalos 5418de8d7fSPeter Avalos void ssh_userauth1(const char *, const char *, char *, Sensitive *); 5518de8d7fSPeter Avalos void ssh_userauth2(const char *, const char *, char *, Sensitive *); 5618de8d7fSPeter Avalos 5718de8d7fSPeter Avalos void ssh_put_password(char *); 5818de8d7fSPeter Avalos int ssh_local_cmd(const char *); 5918de8d7fSPeter Avalos 60*ce74bacaSMatthew Dillon void maybe_add_key_to_agent(char *, struct sshkey *, char *, char *); 61e9778795SPeter Avalos 6218de8d7fSPeter Avalos /* 6318de8d7fSPeter Avalos * Macros to raise/lower permissions. 6418de8d7fSPeter Avalos */ 6518de8d7fSPeter Avalos #define PRIV_START do { \ 6618de8d7fSPeter Avalos int save_errno = errno; \ 6718de8d7fSPeter Avalos if (seteuid(original_effective_uid) != 0) \ 6818de8d7fSPeter Avalos fatal("PRIV_START: seteuid: %s", \ 6918de8d7fSPeter Avalos strerror(errno)); \ 7018de8d7fSPeter Avalos errno = save_errno; \ 7118de8d7fSPeter Avalos } while (0) 7218de8d7fSPeter Avalos 7318de8d7fSPeter Avalos #define PRIV_END do { \ 7418de8d7fSPeter Avalos int save_errno = errno; \ 7518de8d7fSPeter Avalos if (seteuid(original_real_uid) != 0) \ 7618de8d7fSPeter Avalos fatal("PRIV_END: seteuid: %s", \ 7718de8d7fSPeter Avalos strerror(errno)); \ 7818de8d7fSPeter Avalos errno = save_errno; \ 7918de8d7fSPeter Avalos } while (0) 80