1323134Sdes/* $OpenBSD: misc.h,v 1.61 2016/11/30 00:28:31 dtucker 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 18323134Sdes#include <sys/time.h> 19323134Sdes 20294328Sdes/* Data structure for representing a forwarding request. */ 21294328Sdesstruct Forward { 22294328Sdes char *listen_host; /* Host (address) to listen on. */ 23294328Sdes int listen_port; /* Port to forward. */ 24294328Sdes char *listen_path; /* Path to bind domain socket. */ 25294328Sdes char *connect_host; /* Host to connect. */ 26294328Sdes int connect_port; /* Port to connect on connect_host. */ 27294328Sdes char *connect_path; /* Path to connect domain socket. */ 28294328Sdes int allocated_port; /* Dynamically allocated listen port */ 29294328Sdes int handle; /* Handle for dynamic listen ports */ 30294328Sdes}; 31294328Sdes 32323129Sdesint forward_equals(const struct Forward *, const struct Forward *); 33323134Sdesint bind_permitted(int, uid_t); 34323134Sdesint daemonized(void); 35323129Sdes 36294328Sdes/* Common server and client forwarding options. */ 37294328Sdesstruct ForwardOptions { 38294328Sdes int gateway_ports; /* Allow remote connects to forwarded ports. */ 39294328Sdes mode_t streamlocal_bind_mask; /* umask for streamlocal binds */ 40294328Sdes int streamlocal_bind_unlink; /* unlink socket before bind */ 41294328Sdes}; 42294328Sdes 43137015Sdes/* misc.c */ 44137015Sdes 4592555Sdeschar *chop(char *); 4692555Sdeschar *strdelim(char **); 47137015Sdesint set_nonblock(int); 48137015Sdesint unset_nonblock(int); 4992555Sdesvoid set_nodelay(int); 5092555Sdesint a2port(const char *); 51157016Sdesint a2tun(const char *, int *); 52162852Sdeschar *put_host_port(const char *, u_short); 53146998Sdeschar *hpdelim(char **); 5492555Sdeschar *cleanhostname(char *); 5592555Sdeschar *colon(char *); 56323129Sdesint parse_user_host_port(const char *, char **, char **, int *); 5792555Sdeslong convtime(const char *); 58149749Sdeschar *tilde_expand_filename(const char *, uid_t); 59149749Sdeschar *percent_expand(const char *, ...) __attribute__((__sentinel__)); 60162852Sdeschar *tohex(const void *, size_t); 61157016Sdesvoid sanitise_stdfd(void); 62181111Sdesvoid ms_subtract_diff(struct timeval *, int *); 63181111Sdesvoid ms_to_timeval(struct timeval *, int); 64255767Sdestime_t monotime(void); 65323129Sdesdouble monotime_double(void); 66261320Sdesvoid lowercase(char *s); 67294328Sdesint unix_listener(const char *, int, int); 68261320Sdes 69204917Sdesvoid sock_set_v6only(int); 7076259Sgreen 7192555Sdesstruct passwd *pwcopy(struct passwd *); 72181111Sdesconst char *ssh_gai_strerror(int); 7376259Sgreen 7492555Sdestypedef struct arglist arglist; 7592555Sdesstruct arglist { 7698675Sdes char **list; 77137015Sdes u_int num; 78137015Sdes u_int nalloc; 7992555Sdes}; 80157016Sdesvoid addargs(arglist *, char *, ...) 81157016Sdes __attribute__((format(printf, 2, 3))); 82157016Sdesvoid replacearg(arglist *, u_int, char *, ...) 83157016Sdes __attribute__((format(printf, 3, 4))); 84157016Sdesvoid freeargs(arglist *); 85137015Sdes 86157016Sdesint tun_open(int, int); 87157016Sdes 88157016Sdes/* Common definitions for ssh tunnel device forwarding */ 89157016Sdes#define SSH_TUNMODE_NO 0x00 90157016Sdes#define SSH_TUNMODE_POINTOPOINT 0x01 91157016Sdes#define SSH_TUNMODE_ETHERNET 0x02 92157016Sdes#define SSH_TUNMODE_DEFAULT SSH_TUNMODE_POINTOPOINT 93157016Sdes#define SSH_TUNMODE_YES (SSH_TUNMODE_POINTOPOINT|SSH_TUNMODE_ETHERNET) 94157016Sdes 95157016Sdes#define SSH_TUNID_ANY 0x7fffffff 96157016Sdes#define SSH_TUNID_ERR (SSH_TUNID_ANY - 1) 97157016Sdes#define SSH_TUNID_MAX (SSH_TUNID_ANY - 2) 98162852Sdes 99294328Sdes/* Fake port to indicate that host field is really a path. */ 100294328Sdes#define PORT_STREAMLOCAL -2 101294328Sdes 102162852Sdes/* Functions to extract or store big-endian words of various sizes */ 103162852Sdesu_int64_t get_u64(const void *) 104162852Sdes __attribute__((__bounded__( __minbytes__, 1, 8))); 105162852Sdesu_int32_t get_u32(const void *) 106162852Sdes __attribute__((__bounded__( __minbytes__, 1, 4))); 107162852Sdesu_int16_t get_u16(const void *) 108162852Sdes __attribute__((__bounded__( __minbytes__, 1, 2))); 109162852Sdesvoid put_u64(void *, u_int64_t) 110162852Sdes __attribute__((__bounded__( __minbytes__, 1, 8))); 111162852Sdesvoid put_u32(void *, u_int32_t) 112162852Sdes __attribute__((__bounded__( __minbytes__, 1, 4))); 113162852Sdesvoid put_u16(void *, u_int16_t) 114162852Sdes __attribute__((__bounded__( __minbytes__, 1, 2))); 115162852Sdes 116294328Sdes/* Little-endian store/load, used by umac.c */ 117294328Sdesu_int32_t get_u32_le(const void *) 118294328Sdes __attribute__((__bounded__(__minbytes__, 1, 4))); 119294328Sdesvoid put_u32_le(void *, u_int32_t) 120294328Sdes __attribute__((__bounded__(__minbytes__, 1, 4))); 121294328Sdes 122221420Sdesstruct bwlimit { 123221420Sdes size_t buflen; 124221420Sdes u_int64_t rate, thresh, lamt; 125221420Sdes struct timeval bwstart, bwend; 126221420Sdes}; 127162852Sdes 128221420Sdesvoid bandwidth_limit_init(struct bwlimit *, u_int64_t, size_t); 129221420Sdesvoid bandwidth_limit(struct bwlimit *, size_t); 130221420Sdes 131221420Sdesint parse_ipqos(const char *); 132226046Sdesconst char *iptos2str(int); 133221420Sdesvoid mktemp_proto(char *, size_t); 134221420Sdes 135162852Sdes/* readpass.c */ 136162852Sdes 137162852Sdes#define RP_ECHO 0x0001 138162852Sdes#define RP_ALLOW_STDIN 0x0002 139162852Sdes#define RP_ALLOW_EOF 0x0004 140162852Sdes#define RP_USE_ASKPASS 0x0008 141162852Sdes 142162852Sdeschar *read_passphrase(const char *, int); 143162852Sdesint ask_permission(const char *, ...) __attribute__((format(printf, 1, 2))); 144162852Sdesint read_keyfile_line(FILE *, const char *, char *, size_t, u_long *); 145162852Sdes 146323134Sdes#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) 147323134Sdes#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) 148323134Sdes#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) 149323134Sdes 150162852Sdes#endif /* _MISC_H */ 151