xref: /netbsd-src/crypto/external/bsd/openssh/dist/misc.h (revision 5101d403135608e4343a9f7948cea8b048c93bfb)
1 /*	$NetBSD: misc.h,v 1.10 2016/08/02 13:45:12 christos Exp $	*/
2 /* $OpenBSD: misc.h,v 1.57 2016/07/15 00:24:30 djm 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 int forward_equals(const struct Forward *, const struct Forward *);
32 
33 /* Common server and client forwarding options. */
34 struct ForwardOptions {
35 	int	 gateway_ports; /* Allow remote connects to forwarded ports. */
36 	mode_t	 streamlocal_bind_mask; /* umask for streamlocal binds */
37 	int	 streamlocal_bind_unlink; /* unlink socket before bind */
38 };
39 
40 /* misc.c */
41 
42 char	*chop(char *);
43 char	*strdelim(char **);
44 int	 set_nonblock(int);
45 int	 unset_nonblock(int);
46 void	 set_nodelay(int);
47 int	 a2port(const char *);
48 int	 a2tun(const char *, int *);
49 char	*put_host_port(const char *, u_short);
50 char	*hpdelim(char **);
51 char	*cleanhostname(char *);
52 char	*colon(char *);
53 int	 parse_user_host_port(const char *, char **, char **, int *);
54 long	 convtime(const char *);
55 char	*tilde_expand_filename(const char *, uid_t);
56 char	*percent_expand(const char *, ...)
57 #if __GNUC_PREREQ__(4, 0)
58     __attribute__((__sentinel__))
59 #endif
60     ;
61 char	*tohex(const void *, size_t);
62 void	 sanitise_stdfd(void);
63 struct timeval;
64 void	 ms_subtract_diff(struct timeval *, int *);
65 void	 ms_to_timeval(struct timeval *, int);
66 time_t	 monotime(void);
67 double	 monotime_double(void);
68 void	 lowercase(char *s);
69 int	 unix_listener(const char *, int, int);
70 
71 int	bcrypt_pbkdf(const char *, size_t, const u_int8_t *, size_t,
72     u_int8_t *, size_t, unsigned int);
73 
74 struct passwd *pwcopy(struct passwd *);
75 const char *ssh_gai_strerror(int);
76 
77 typedef struct arglist arglist;
78 struct arglist {
79 	char    **list;
80 	u_int   num;
81 	u_int   nalloc;
82 };
83 void	 addargs(arglist *, const char *, ...)
84 	     __attribute__((format(printf, 2, 3)));
85 void	 replacearg(arglist *, u_int, const char *, ...)
86 	     __attribute__((format(printf, 3, 4)));
87 void	 freeargs(arglist *);
88 
89 int	 tun_open(int, int);
90 
91 /* Common definitions for ssh tunnel device forwarding */
92 #define SSH_TUNMODE_NO		0x00
93 #define SSH_TUNMODE_POINTOPOINT	0x01
94 #define SSH_TUNMODE_ETHERNET	0x02
95 #define SSH_TUNMODE_DEFAULT	SSH_TUNMODE_POINTOPOINT
96 #define SSH_TUNMODE_YES		(SSH_TUNMODE_POINTOPOINT|SSH_TUNMODE_ETHERNET)
97 
98 #define SSH_TUNID_ANY		0x7fffffff
99 #define SSH_TUNID_ERR		(SSH_TUNID_ANY - 1)
100 #define SSH_TUNID_MAX		(SSH_TUNID_ANY - 2)
101 
102 /* Fake port to indicate that host field is really a path. */
103 #define PORT_STREAMLOCAL	-2
104 
105 /* Functions to extract or store big-endian words of various sizes */
106 u_int64_t	get_u64(const void *)
107     __attribute__((__bounded__( __minbytes__, 1, 8)));
108 u_int32_t	get_u32(const void *)
109     __attribute__((__bounded__( __minbytes__, 1, 4)));
110 u_int16_t	get_u16(const void *)
111     __attribute__((__bounded__( __minbytes__, 1, 2)));
112 void		put_u64(void *, u_int64_t)
113     __attribute__((__bounded__( __minbytes__, 1, 8)));
114 void		put_u32(void *, u_int32_t)
115     __attribute__((__bounded__( __minbytes__, 1, 4)));
116 void		put_u16(void *, u_int16_t)
117     __attribute__((__bounded__( __minbytes__, 1, 2)));
118 
119 /* Little-endian store/load, used by umac.c */
120 u_int32_t	get_u32_le(const void *)
121     __attribute__((__bounded__(__minbytes__, 1, 4)));
122 void		put_u32_le(void *, u_int32_t)
123     __attribute__((__bounded__(__minbytes__, 1, 4)));
124 
125 struct bwlimit {
126 	size_t buflen;
127 	u_int64_t rate, thresh, lamt;
128 	struct timeval bwstart, bwend;
129 };
130 
131 void bandwidth_limit_init(struct bwlimit *, u_int64_t, size_t);
132 void bandwidth_limit(struct bwlimit *, size_t);
133 
134 int parse_ipqos(const char *);
135 const char *iptos2str(int);
136 void mktemp_proto(char *, size_t);
137 
138 /* readpass.c */
139 
140 #define RP_ECHO			0x0001
141 #define RP_ALLOW_STDIN		0x0002
142 #define RP_ALLOW_EOF		0x0004
143 #define RP_USE_ASKPASS		0x0008
144 
145 char	*read_passphrase(const char *, int);
146 int	 ask_permission(const char *, ...) __attribute__((format(printf, 1, 2)));
147 int	 read_keyfile_line(FILE *, const char *, char *, size_t, u_long *);
148 
149 #endif /* _MISC_H */
150