exception.h 5.76 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* exception.h
 *
 * $Id$ */

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Möller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef LSH_EXCEPTION_H_INCLUDED
#define LSH_EXCEPTION_H_INCLUDED

#include "lsh.h"

Niels Möller's avatar
Niels Möller committed
29
#define GABA_DECLARE
Niels Möller's avatar
Niels Möller committed
30
#include "exception.h.x"
Niels Möller's avatar
Niels Möller committed
31
#undef GABA_DECLARE
Niels Möller's avatar
Niels Möller committed
32
33
34
35
36
37

/* GABA:
   (class
     (name exception)
     (vars
       (type . UINT32)
Niels Möller's avatar
Niels Möller committed
38
       (msg . "const char *")))
Niels Möller's avatar
Niels Möller committed
39
40
*/

Niels Möller's avatar
Niels Möller committed
41
42
43
#define STATIC_EXCEPTION(type, name) \
{ STATIC_HEADER, (type), (name) }

Niels Möller's avatar
Niels Möller committed
44
45
46
47
/* GABA:
   (class
     (name exception_handler)
     (vars
Niels Möller's avatar
Niels Möller committed
48
       (raise method void "const struct exception *")
49
50
51
52
       (parent object exception_handler)

       ; Provide some context for debugging unhandled exceptions
       (context . "const char *")))
Niels Möller's avatar
Niels Möller committed
53
54
*/

55
void exception_raise(struct exception_handler *e,
56
57
		     const struct exception *h,
		     const char *context);
58
59

#if DEBUG_TRACE
60
#  define EXCEPTION_RAISE(h, e) exception_raise((h), (e), HANDLER_CONTEXT)
61
62
63
#else /* !DEBUG_TRACE */
#  define EXCEPTION_RAISE(h, e)  ((h)->raise((h), (e)))
#endif /* !DEBUG_TRACE */
Niels Möller's avatar
Niels Möller committed
64

Niels Möller's avatar
Niels Möller committed
65
66
67
68
/* NOTE: This is pretty useless, as it requires that the parent be
 * static as well. Used only for the default_exception_handler and
 * ignore_exception_handler, and perhaps some others with NULL parent.
 * */
Niels Möller's avatar
Niels Möller committed
69
#define STATIC_EXCEPTION_HANDLER(r, p) \
70
71
{ STATIC_HEADER, (r), (p), __FILE__ ":" STRING_LINE ": Static" }

Niels Möller's avatar
Niels Möller committed
72

73
74
#define HANDLER_CONTEXT   (__FILE__ ":" STRING_LINE ": " FUNCTION_NAME)

Niels Möller's avatar
Niels Möller committed
75
76
77
78
79
80
81

/* Exception types. */

/* Used in places where no real exception is defined yet.
 * Never handled. */
#define EXC_DUMMY 0

Niels Möller's avatar
Niels Möller committed
82
83
84
/* FIXME: This is an inappropriate name, as this exception type is
 * used for all events that should result in a disconnect message. */

Niels Möller's avatar
Niels Möller committed
85
86
87
88
89
/* Protocol errors */
#define EXC_PROTOCOL 0x1000

/* IO related errors */
#define EXC_IO 0x2000
90
#define EXC_IO_CONNECT 0x2001
Niels Möller's avatar
Niels Möller committed
91
#define EXC_IO_BLOCKING_WRITE 0x2003
Niels Möller's avatar
Niels Möller committed
92
93
#define EXC_IO_READ 0x2004
#define EXC_IO_WRITE 0x2005
Niels Möller's avatar
Niels Möller committed
94
#define EXC_IO_OPEN_WRITE 0x2006
Balázs Scheidler's avatar
Balázs Scheidler committed
95
96
#define EXC_IO_OPEN_READ 0x2007
#define EXC_IO_LISTEN 0x2008
97
#define EXC_IO_CLOSE 0x2009
Niels Möller's avatar
Niels Möller committed
98
99
100
101
102

/* Authorization errors */
#define EXC_AUTH 0x4000
#define EXC_USERAUTH 0x4001

Niels Möller's avatar
Niels Möller committed
103
104
105
/* Implies an exception struct with a reply packet in it. */
#define EXC_USERAUTH_SPECIAL 0x4002

Niels Möller's avatar
Niels Möller committed
106
107
108
109
110
111
112
113
/* Services */
#define EXC_SERVICE 0x8000
#define EXC_GLOBAL_REQUEST 0x8001
#define EXC_CHANNEL_REQUEST 0x8002

/* Use subtypes for the different error codes? */
#define EXC_CHANNEL_OPEN 0x8003

Niels Möller's avatar
Niels Möller committed
114
115
/* Closing down things */
#define EXC_FINISH 0x10000
Niels Möller's avatar
Niels Möller committed
116

Niels Möller's avatar
Niels Möller committed
117
118
/* Close a channel */
#define EXC_FINISH_CHANNEL 0x10001
Niels Möller's avatar
Niels Möller committed
119

Niels Möller's avatar
Niels Möller committed
120
121
122
/* Stop reading on some fd */
#define EXC_FINISH_READ 0x10002

Niels Möller's avatar
Niels Möller committed
123
124
125
126
127
128
129
/* Close the connection immediately */
#define EXC_FINISH_IO 0x10003

/* Put the connection into pending-close mode,
 * i.e. don't open any new channels, and close it
 * as soon as all channels are gone. */
#define EXC_FINISH_PENDING 0x10004
Niels Möller's avatar
Niels Möller committed
130

131
132
133
134
135
136
137
138
/* DNS errors */
#define EXC_RESOLVE 0x20001

/* SEXP parse errors */
#define EXC_SEXP 0x40000
#define EXC_SEXP_SYNTAX 0x40001
#define EXC_SEXP_EOF 0x40002

139
140
141
142
143
/* SPKI errors */
#define EXC_SPKI 0x80000
/* Unexpected or unsupported expression type */
#define EXC_SPKI_TYPE 0x80001

144
145
146
147
148
149
150
151
/* Pausing, used to temporarily stop reading packets on a connection. */
#define EXC_PAUSE 0x100000

#define EXC_PAUSE_READ 0x100001
#define EXC_PAUSE_START_READ 0x100002
#define EXC_PAUSE_CONNECTION 0x100003
#define EXC_PAUSE_START_CONNECTION 0x100004

152
/* Application specific exceptions */
153
#define EXC_APP 0x200000
154

155
156
#define EXC_ALL (~0)

Niels Möller's avatar
Niels Möller committed
157
extern struct exception_handler default_exception_handler;
158
extern struct exception_handler ignore_exception_handler;
Niels Möller's avatar
Niels Möller committed
159
160
extern struct exception dummy_exception;

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* GABA:
   (class
     (name report_exception_info)
     (vars
       (mask . UINT32)
       (value . UINT32)
       (prefix . "const char *")))
*/

struct report_exception_info *
make_report_exception_info(UINT32 mask, UINT32 value,
			   const char *prefix);

#define STATIC_REPORT_EXCEPTION_INFO(m, v, p) \
{ STATIC_HEADER, m, v, p }

177
struct exception_handler *
178
make_report_exception_handler(struct report_exception_info *info,
179
180
			      struct exception_handler *parent,
			      const char *context);
Niels Möller's avatar
Niels Möller committed
181
182

struct exception *
Niels Möller's avatar
Niels Möller committed
183
make_simple_exception(UINT32 type, const char *msg);
Niels Möller's avatar
Niels Möller committed
184

Niels Möller's avatar
Niels Möller committed
185
186
187
188
/* Create a simple exception handler, with no internal state */
struct exception_handler *
make_exception_handler(void (*raise)(struct exception_handler *s,
				     const struct exception *x),
189
190
		       struct exception_handler *parent,
		       const char *context);
Niels Möller's avatar
Niels Möller committed
191

Niels Möller's avatar
Niels Möller committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* A protocol exception, that normally terminates the connection */
/* GABA:
   (class
     (name protocol_exception)
     (super exception)
     (vars
       ;; A reason code that can be passed in a SSH_MSG_DISCONNECT message.
       ;; Zero means terminate the connection without sending such a message.
       (reason . UINT32)))
*/


/* If msg is NULL, it is derived from the reason value */
struct exception *
make_protocol_exception(UINT32 reason, const char *msg);

#define STATIC_PROTOCOL_EXCEPTION(reason, msg) \
{ { STATIC_HEADER, EXC_PROTOCOL, (msg) }, (reason) }

211
212
213
214
#define PROTOCOL_ERROR(e, msg) \
EXCEPTION_RAISE((e), \
  make_protocol_exception(SSH_DISCONNECT_PROTOCOL_ERROR, (msg)))

Niels Möller's avatar
Niels Möller committed
215
#endif /* LSH_EXCEPTION_H_INCLUDED */