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