1323124Sdes/* $OpenBSD: misc.h,v 1.57 2016/07/15 00:24:30 djm Exp $ */ 276259Sgreen 376259Sgreen/* 476259Sgreen * Author: Tatu Ylonen <ylo@cs.hut.fi> 576259Sgreen * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 676259Sgreen * All rights reserved 776259Sgreen * 876259Sgreen * As far as I am concerned, the code I have written for this software 976259Sgreen * can be used freely for any purpose. Any derived versions of this 1076259Sgreen * software must be clearly marked as such, and if the derived work is 1176259Sgreen * incompatible with the protocol description in the RFC file, it must be 1276259Sgreen * called by a name other than "ssh" or "Secure Shell". 1376259Sgreen */ 1476259Sgreen 15162852Sdes#ifndef _MISC_H 16162852Sdes#define _MISC_H 17162852Sdes 18295367Sdes/* Data structure for representing a forwarding request. */ 19295367Sdesstruct Forward { 20295367Sdes char *listen_host; /* Host (address) to listen on. */ 21295367Sdes int listen_port; /* Port to forward. */ 22295367Sdes char *listen_path; /* Path to bind domain socket. */ 23295367Sdes char *connect_host; /* Host to connect. */ 24295367Sdes int connect_port; /* Port to connect on connect_host. */ 25295367Sdes char *connect_path; /* Path to connect domain socket. */ 26295367Sdes int allocated_port; /* Dynamically allocated listen port */ 27295367Sdes int handle; /* Handle for dynamic listen ports */ 28295367Sdes}; 29295367Sdes 30323124Sdesint forward_equals(const struct Forward *, const struct Forward *); 31323124Sdes 32295367Sdes/* Common server and client forwarding options. */ 33295367Sdesstruct ForwardOptions { 34295367Sdes int gateway_ports; /* Allow remote connects to forwarded ports. */ 35295367Sdes mode_t streamlocal_bind_mask; /* umask for streamlocal binds */ 36295367Sdes int streamlocal_bind_unlink; /* unlink socket before bind */ 37295367Sdes}; 38295367Sdes 39137015Sdes/* misc.c */ 40137015Sdes 4192555Sdeschar *chop(char *); 4292555Sdeschar *strdelim(char **); 43137015Sdesint set_nonblock(int); 44137015Sdesint unset_nonblock(int); 4592555Sdesvoid set_nodelay(int); 4692555Sdesint a2port(const char *); 47157016Sdesint a2tun(const char *, int *); 48162852Sdeschar *put_host_port(const char *, u_short); 49146998Sdeschar *hpdelim(char **); 5092555Sdeschar *cleanhostname(char *); 5192555Sdeschar *colon(char *); 52323124Sdesint parse_user_host_port(const char *, char **, char **, int *); 5392555Sdeslong convtime(const char *); 54149749Sdeschar *tilde_expand_filename(const char *, uid_t); 55149749Sdeschar *percent_expand(const char *, ...) __attribute__((__sentinel__)); 56162852Sdeschar *tohex(const void *, size_t); 57157016Sdesvoid sanitise_stdfd(void); 58181111Sdesvoid ms_subtract_diff(struct timeval *, int *); 59181111Sdesvoid ms_to_timeval(struct timeval *, int); 60255767Sdestime_t monotime(void); 61323124Sdesdouble monotime_double(void); 62262566Sdesvoid lowercase(char *s); 63295367Sdesint unix_listener(const char *, int, int); 64262566Sdes 65204917Sdesvoid sock_set_v6only(int); 6676259Sgreen 6792555Sdesstruct passwd *pwcopy(struct passwd *); 68181111Sdesconst char *ssh_gai_strerror(int); 6976259Sgreen 7092555Sdestypedef struct arglist arglist; 7192555Sdesstruct arglist { 7298675Sdes char **list; 73137015Sdes u_int num; 74137015Sdes u_int nalloc; 7592555Sdes}; 76157016Sdesvoid addargs(arglist *, char *, ...) 77157016Sdes __attribute__((format(printf, 2, 3))); 78157016Sdesvoid replacearg(arglist *, u_int, char *, ...) 79157016Sdes __attribute__((format(printf, 3, 4))); 80157016Sdesvoid freeargs(arglist *); 81137015Sdes 82157016Sdesint tun_open(int, int); 83157016Sdes 84157016Sdes/* Common definitions for ssh tunnel device forwarding */ 85157016Sdes#define SSH_TUNMODE_NO 0x00 86157016Sdes#define SSH_TUNMODE_POINTOPOINT 0x01 87157016Sdes#define SSH_TUNMODE_ETHERNET 0x02 88157016Sdes#define SSH_TUNMODE_DEFAULT SSH_TUNMODE_POINTOPOINT 89157016Sdes#define SSH_TUNMODE_YES (SSH_TUNMODE_POINTOPOINT|SSH_TUNMODE_ETHERNET) 90157016Sdes 91157016Sdes#define SSH_TUNID_ANY 0x7fffffff 92157016Sdes#define SSH_TUNID_ERR (SSH_TUNID_ANY - 1) 93157016Sdes#define SSH_TUNID_MAX (SSH_TUNID_ANY - 2) 94162852Sdes 95295367Sdes/* Fake port to indicate that host field is really a path. */ 96295367Sdes#define PORT_STREAMLOCAL -2 97295367Sdes 98162852Sdes/* Functions to extract or store big-endian words of various sizes */ 99162852Sdesu_int64_t get_u64(const void *) 100162852Sdes __attribute__((__bounded__( __minbytes__, 1, 8))); 101162852Sdesu_int32_t get_u32(const void *) 102162852Sdes __attribute__((__bounded__( __minbytes__, 1, 4))); 103162852Sdesu_int16_t get_u16(const void *) 104162852Sdes __attribute__((__bounded__( __minbytes__, 1, 2))); 105162852Sdesvoid put_u64(void *, u_int64_t) 106162852Sdes __attribute__((__bounded__( __minbytes__, 1, 8))); 107162852Sdesvoid put_u32(void *, u_int32_t) 108162852Sdes __attribute__((__bounded__( __minbytes__, 1, 4))); 109162852Sdesvoid put_u16(void *, u_int16_t) 110162852Sdes __attribute__((__bounded__( __minbytes__, 1, 2))); 111162852Sdes 112295367Sdes/* Little-endian store/load, used by umac.c */ 113295367Sdesu_int32_t get_u32_le(const void *) 114295367Sdes __attribute__((__bounded__(__minbytes__, 1, 4))); 115295367Sdesvoid put_u32_le(void *, u_int32_t) 116295367Sdes __attribute__((__bounded__(__minbytes__, 1, 4))); 117295367Sdes 118221420Sdesstruct bwlimit { 119221420Sdes size_t buflen; 120221420Sdes u_int64_t rate, thresh, lamt; 121221420Sdes struct timeval bwstart, bwend; 122221420Sdes}; 123162852Sdes 124221420Sdesvoid bandwidth_limit_init(struct bwlimit *, u_int64_t, size_t); 125221420Sdesvoid bandwidth_limit(struct bwlimit *, size_t); 126221420Sdes 127221420Sdesint parse_ipqos(const char *); 128226046Sdesconst char *iptos2str(int); 129221420Sdesvoid mktemp_proto(char *, size_t); 130221420Sdes 131162852Sdes/* readpass.c */ 132162852Sdes 133162852Sdes#define RP_ECHO 0x0001 134162852Sdes#define RP_ALLOW_STDIN 0x0002 135162852Sdes#define RP_ALLOW_EOF 0x0004 136162852Sdes#define RP_USE_ASKPASS 0x0008 137162852Sdes 138162852Sdeschar *read_passphrase(const char *, int); 139162852Sdesint ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); 140162852Sdesint read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); 141162852Sdes 142162852Sdes#endif /* _MISC_H */ 143