1 /* $NetBSD: misc.h,v 1.8 2015/01/16 20:17:49 christos Exp $ */ 2 /* $OpenBSD: misc.h,v 1.54 2014/07/15 15:54:14 millert Exp $ */ 3 4 /* 5 * Author: Tatu Ylonen <ylo@cs.hut.fi> 6 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 7 * All rights reserved 8 * 9 * As far as I am concerned, the code I have written for this software 10 * can be used freely for any purpose. Any derived versions of this 11 * software must be clearly marked as such, and if the derived work is 12 * incompatible with the protocol description in the RFC file, it must be 13 * called by a name other than "ssh" or "Secure Shell". 14 */ 15 16 #ifndef _MISC_H 17 #define _MISC_H 18 19 /* Data structure for representing a forwarding request. */ 20 struct Forward { 21 char *listen_host; /* Host (address) to listen on. */ 22 int listen_port; /* Port to forward. */ 23 char *listen_path; /* Path to bind domain socket. */ 24 char *connect_host; /* Host to connect. */ 25 int connect_port; /* Port to connect on connect_host. */ 26 char *connect_path; /* Path to connect domain socket. */ 27 int allocated_port; /* Dynamically allocated listen port */ 28 int handle; /* Handle for dynamic listen ports */ 29 }; 30 31 /* Common server and client forwarding options. */ 32 struct ForwardOptions { 33 int gateway_ports; /* Allow remote connects to forwarded ports. */ 34 mode_t streamlocal_bind_mask; /* umask for streamlocal binds */ 35 int streamlocal_bind_unlink; /* unlink socket before bind */ 36 }; 37 38 /* misc.c */ 39 40 char *chop(char *); 41 char *strdelim(char **); 42 int set_nonblock(int); 43 int unset_nonblock(int); 44 void set_nodelay(int); 45 int a2port(const char *); 46 int a2tun(const char *, int *); 47 char *put_host_port(const char *, u_short); 48 char *hpdelim(char **); 49 char *cleanhostname(char *); 50 char *colon(char *); 51 long convtime(const char *); 52 char *tilde_expand_filename(const char *, uid_t); 53 char *percent_expand(const char *, ...) 54 #if __GNUC_PREREQ__(4, 0) 55 __attribute__((__sentinel__)) 56 #endif 57 ; 58 char *tohex(const void *, size_t); 59 void sanitise_stdfd(void); 60 struct timeval; 61 void ms_subtract_diff(struct timeval *, int *); 62 void ms_to_timeval(struct timeval *, int); 63 time_t monotime(void); 64 void lowercase(char *s); 65 int unix_listener(const char *, int, int); 66 67 int bcrypt_pbkdf(const char *, size_t, const u_int8_t *, size_t, 68 u_int8_t *, size_t, unsigned int); 69 70 struct passwd *pwcopy(struct passwd *); 71 const char *ssh_gai_strerror(int); 72 73 typedef struct arglist arglist; 74 struct arglist { 75 char **list; 76 u_int num; 77 u_int nalloc; 78 }; 79 void addargs(arglist *, const char *, ...) 80 __attribute__((format(printf, 2, 3))); 81 void replacearg(arglist *, u_int, const char *, ...) 82 __attribute__((format(printf, 3, 4))); 83 void freeargs(arglist *); 84 85 int tun_open(int, int); 86 87 /* Common definitions for ssh tunnel device forwarding */ 88 #define SSH_TUNMODE_NO 0x00 89 #define SSH_TUNMODE_POINTOPOINT 0x01 90 #define SSH_TUNMODE_ETHERNET 0x02 91 #define SSH_TUNMODE_DEFAULT SSH_TUNMODE_POINTOPOINT 92 #define SSH_TUNMODE_YES (SSH_TUNMODE_POINTOPOINT|SSH_TUNMODE_ETHERNET) 93 94 #define SSH_TUNID_ANY 0x7fffffff 95 #define SSH_TUNID_ERR (SSH_TUNID_ANY - 1) 96 #define SSH_TUNID_MAX (SSH_TUNID_ANY - 2) 97 98 /* Fake port to indicate that host field is really a path. */ 99 #define PORT_STREAMLOCAL -2 100 101 /* Functions to extract or store big-endian words of various sizes */ 102 u_int64_t get_u64(const void *) 103 __attribute__((__bounded__( __minbytes__, 1, 8))); 104 u_int32_t get_u32(const void *) 105 __attribute__((__bounded__( __minbytes__, 1, 4))); 106 u_int16_t get_u16(const void *) 107 __attribute__((__bounded__( __minbytes__, 1, 2))); 108 void put_u64(void *, u_int64_t) 109 __attribute__((__bounded__( __minbytes__, 1, 8))); 110 void put_u32(void *, u_int32_t) 111 __attribute__((__bounded__( __minbytes__, 1, 4))); 112 void put_u16(void *, u_int16_t) 113 __attribute__((__bounded__( __minbytes__, 1, 2))); 114 115 /* Little-endian store/load, used by umac.c */ 116 u_int32_t get_u32_le(const void *) 117 __attribute__((__bounded__(__minbytes__, 1, 4))); 118 void put_u32_le(void *, u_int32_t) 119 __attribute__((__bounded__(__minbytes__, 1, 4))); 120 121 struct bwlimit { 122 size_t buflen; 123 u_int64_t rate, thresh, lamt; 124 struct timeval bwstart, bwend; 125 }; 126 127 void bandwidth_limit_init(struct bwlimit *, u_int64_t, size_t); 128 void bandwidth_limit(struct bwlimit *, size_t); 129 130 int parse_ipqos(const char *); 131 const char *iptos2str(int); 132 void mktemp_proto(char *, size_t); 133 134 /* readpass.c */ 135 136 #define RP_ECHO 0x0001 137 #define RP_ALLOW_STDIN 0x0002 138 #define RP_ALLOW_EOF 0x0004 139 #define RP_USE_ASKPASS 0x0008 140 141 char *read_passphrase(const char *, int); 142 int ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); 143 int read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); 144 145 #endif /* _MISC_H */ 146