client.h 5.38 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
/* client.h
 *
3
 */
4
5
6

/* lsh, an implementation of the ssh protocol
 *
7
 * Copyright (C) 1998, 1999, 2000, 2001 Niels Möller
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * 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
J.H.M. Dassen's avatar
J.H.M. Dassen committed
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Niels Möller's avatar
Niels Möller committed
22
23
24
25
26
 */

#ifndef LSH_CLIENT_H_INCLUDED
#define LSH_CLIENT_H_INCLUDED

27
#include "channel_commands.h"
Niels Möller's avatar
Niels Möller committed
28
#include "io.h"
Niels Möller's avatar
Niels Möller committed
29
#include "keyexchange.h"
Niels Möller's avatar
Niels Möller committed
30

31
32
33
#define GABA_DECLARE
#include "client.h.x"
#undef GABA_DECLARE
Niels Möller's avatar
Niels Möller committed
34

35
36
37
/* The argp option group for actions. */
#define CLIENT_ARGP_ACTION_GROUP 100
#define CLIENT_ARGP_MODIFIER_GROUP 200
38

Niels Möller's avatar
Niels Möller committed
39
struct packet_handler *
40
make_accept_service_handler(uint32_t service,
41
			    struct command_continuation *c);
42

43
44
45
46
47
/* GABA:
   (class
     (name request_service)
     (super command)
     (vars
Niels Möller's avatar
Niels Möller committed
48
       (service . int)))
49
50
51
52
53
54
55
*/

void
do_request_service(struct command *s,
		   struct lsh_object *x,
		   struct command_continuation *c,
		   struct exception_handler *e);
56

57
58
59
60
#define STATIC_REQUEST_SERVICE(service) \
{ STATIC_COMMAND(do_request_service), service } 

struct command *make_request_service(int service);
61

62
63
64
65
66
67
68
69
/* GABA:
   (class
     (name escape_callback)
     (super lsh_callback)
     (vars
       (help . "const char *")))
*/

Niels Möller's avatar
Niels Möller committed
70
71
72
73
74
75
76
77
/* FIXME: Use const? */

#define DEFINE_ESCAPE(name, help) \
static void do_##name(struct lsh_callback *self); \
struct escape_callback \
name = { { STATIC_HEADER, do_##name }, help }; \
static void do_##name(struct lsh_callback *self UNUSED)

78
79
80
81
/* GABA:
   (class
     (name escape_info)
     (vars
82
       (escape . uint8_t)
83
       ; Handlers, indexed by character.
84
       (dispatch array (object escape_callback) "0x100")))
85
86
*/

87
struct escape_info *make_escape_info(uint8_t escape);
88
89
90
struct abstract_write *
make_handle_escape(struct escape_info *info, struct abstract_write *next);

91
92
93
struct channel_request *make_handle_exit_status(int *exit_code);
struct channel_request *make_handle_exit_signal(int *exit_code);

Niels Möller's avatar
Niels Möller committed
94
struct command *make_open_session_command(struct ssh_channel *session);
95

96
97

extern struct channel_request_command request_shell;
98
99
#define REQUEST_SHELL (&request_shell.super.super)

100
extern struct command client_io;
101
#define CLIENT_START_IO (&client_io.super)
102

103
104
105
106
struct ssh_channel *
make_client_session_channel(struct lsh_fd *in,
			    struct lsh_fd *out,
			    struct lsh_fd *err,
Niels Möller's avatar
Niels Möller committed
107
			    struct escape_info *escape,
108
			    uint32_t initial_window,
109
			    int *exit_status);
Niels Möller's avatar
Niels Möller committed
110

111
112
struct command *
make_exec_request(struct lsh_string *command);
113

114
115
116
struct command *
make_pty_request(struct interact *tty);

117
118
119
struct command *
make_subsystem_request(struct lsh_string *subsystem);

120
extern struct channel_open channel_open_x11;
121
122

struct command *
123
124
make_forward_x11(const char *display_string,
		 struct randomness *random);
125
126
127
128

struct client_x11_display *
make_client_x11_display(const char *display, struct lsh_string *fake);

129
130
131
132
/* GABA:
   (class
     (name client_options)
     (vars
133
       ;; Used only by lsh, NULL for lshg.
134
       (random object randomness)
135

136
137
       (tty object interact)

Niels Möller's avatar
Niels Möller committed
138
139
140
       ; -1 means default.
       (escape . int)
       
141
142
143
144
145
146
       ; For i/o exceptions 
       (handler object exception_handler)

       (exit_code . "int *")

       (not . int)
147
148
       (port . "const char *")
       (target . "const char *")
149
150
151
152
153
154
155
156

       (local_user . "char *")
       (user . "char *")

       (with_remote_peers . int)
       
       ; -1 means default behaviour
       (with_pty . int)
157
158

       (with_x11 . int)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
       
       ; Session modifiers
       (stdin_file . "const char *")
       (stdout_file . "const char *")
       (stderr_file . "const char *")

       ; fork() extra processes for handling stdio file-descriptors,
       ; to avoid setting them in non-blocking mode.
       (stdin_fork . int)
       (stdout_fork . int)
       (stderr_fork . int)

       ; True if the process's stdin or pty (respectively) has been used. 
       (used_stdin . int)
       (used_pty . int)
174
175
       (used_x11 . int)
       
176
177
178
       ; True if the client should detach when a session closes (useful for gateways)
       (detach_end . int)

179
180
181
       ; Inhibit actions, used to not create actions from environment parsing.
       (inhibit_actions . int)

182
       (start_shell . int)
Niels Möller's avatar
Niels Möller committed
183
       (remote_forward . int)
184
185
186
187
188
       (actions struct object_queue)))
*/

void
init_client_options(struct client_options *options,
189
		    struct randomness *random,
190
191
192
193
194
195
196
197
		    struct exception_handler *handler,
		    int *exit_code);

struct command *
client_add_action(struct client_options *options,
		  struct command *action);
int
client_parse_forward_arg(char *arg,
198
			 uint32_t *listen_port,
199
200
			 struct address_info **target);

201
202
extern struct command client_options2actions;
#define OPTIONS2ACTIONS (&client_options2actions.super)
203
204
205

extern const struct argp client_argp;

206
207
208
209
210
211
212
213

void
envp_parse(const struct argp *argp,
           const char** envp,
           const char* name,
           unsigned flags,
           void *input);

Niels Möller's avatar
Niels Möller committed
214
#endif /* LSH_CLIENT_H_INCLUDED */