Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
LSH
lsh
Commits
cfb2789b
Commit
cfb2789b
authored
Nov 02, 1998
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixes.
Rev: src/server.c:1.18
parent
dfde6c83
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
42 deletions
+90
-42
src/server.c
src/server.c
+90
-42
No files found.
src/server.c
View file @
cfb2789b
...
...
@@ -131,7 +131,7 @@ static struct read_handler *do_line(struct line_handler **h,
verbose
(
"
\n
"
);
/* FIXME: Cleanup properly. */
lsh_free
(
closure
);
lsh_
object_
free
(
closure
);
return
new
;
}
...
...
@@ -142,7 +142,7 @@ static struct read_handler *do_line(struct line_handler **h,
werror
(
"
\n
"
);
/* FIXME: Clean up properly */
lsh_free
(
closure
);
lsh_
object_
free
(
closure
);
*
h
=
0
;
return
0
;
...
...
@@ -219,15 +219,52 @@ struct server_session
{
struct
ssh_channel
super
;
UINT32
max_window
;
/* User information */
struct
unix_user
*
user
;
/* Non-zero if a shell or command has been started. */
int
running
;
/* Child process's stdio */
struct
abstract_write
*
in
;
struct
io_fd
*
out
;
struct
io_fd
*
err
;
};
/* Recieve channel data */
static
int
do_recieve
(
struct
ssh_channel
*
c
,
int
type
,
struct
lsh_string
*
data
)
{
struct
server_session
*
closure
=
(
struct
server_session
*
)
c
;
MDEBUG
(
closure
);
switch
(
type
)
{
case
CHANNEL_DATA
:
return
A_WRITE
(
closure
->
in
,
data
);
case
CHANNEL_STDERR_DATA
:
werror
(
"Ignoring unexpected stderr data.
\n
"
);
lsh_string_free
(
data
);
return
LSH_OK
|
LSH_GOON
;
default:
fatal
(
"Internal error!
\n
"
);
}
}
/* We may send more data */
static
int
do_send
(
struct
ssh_channel
*
c
)
{
struct
server_session
*
closure
=
(
struct
server_session
*
)
c
;
MDEBUG
(
closure
);
closure
->
out
->
on_hold
=
0
;
closure
->
err
->
on_hold
=
0
;
return
LSH_OK
|
LSH_GOON
;
}
struct
ssh_channel
*
make_server_session
(
struct
unix_user
*
user
,
UINT32
max_window
,
struct
alist
*
request_types
)
...
...
@@ -249,6 +286,10 @@ struct ssh_channel *make_server_session(struct unix_user *user,
self
->
running
=
0
;
self
->
in
=
NULL
;
self
->
out
=
NULL
;
self
->
err
=
NULL
;
return
&
self
->
super
;
}
...
...
@@ -380,9 +421,9 @@ static int do_spawn_shell(struct channel_request *c,
struct
shell_request
*
closure
=
(
struct
shell_request
*
)
c
;
struct
server_session
*
session
=
(
struct
server_session
*
)
channel
;
int
in
_fds
[
2
];
int
out
_fds
[
2
];
int
err
_fds
[
2
];
int
in
[
2
];
int
out
[
2
];
int
err
[
2
];
MDEBUG
(
closure
);
MDEBUG
(
channel
);
...
...
@@ -394,14 +435,14 @@ static int do_spawn_shell(struct channel_request *c,
/* Already spawned a shell or command */
goto
fail
;
/* {in
_fds|out_fds|err_fds
}[0] is for reading,
* {in
_fds|out_fds|err_fds
}[1] for writing. */
/* {in
|out|err
}[0] is for reading,
* {in
|out|err
}[1] for writing. */
if
(
make_pipe
(
in
_fds
))
if
(
make_pipe
(
in
))
{
if
(
make_pipe
(
out
_fds
))
if
(
make_pipe
(
out
))
{
if
(
make_pipe
(
err
_fds
))
if
(
make_pipe
(
err
))
{
pid_t
child
;
...
...
@@ -440,31 +481,31 @@ static int do_spawn_shell(struct channel_request *c,
* backend. */
close
(
STDIN_FILENO
);
if
(
dup2
(
in
_fds
[
0
],
STDIN_FILENO
)
<
0
)
if
(
dup2
(
in
[
0
],
STDIN_FILENO
)
<
0
)
{
werror
(
"Can't dup stdin!
\n
"
);
exit
(
EXIT_FAILURE
);
}
close
(
in
_fds
[
0
]);
close
(
in
_fds
[
1
]);
close
(
in
[
0
]);
close
(
in
[
1
]);
close
(
STDOUT_FILENO
);
if
(
dup2
(
out
_fds
[
1
],
STDOUT_FILENO
)
<
0
)
if
(
dup2
(
out
[
1
],
STDOUT_FILENO
)
<
0
)
{
werror
(
"Can't dup stdout!
\n
"
);
exit
(
EXIT_FAILURE
);
}
close
(
out
_fds
[
0
]);
close
(
out
_fds
[
1
]);
close
(
out
[
0
]);
close
(
out
[
1
]);
close
(
STDERR_FILENO
);
if
(
dup2
(
err
_fds
[
1
],
STDERR_FILENO
)
<
0
)
if
(
dup2
(
err
[
1
],
STDERR_FILENO
)
<
0
)
{
/* Can't write any message to stderr. */
exit
(
EXIT_FAILURE
);
}
close
(
err
_fds
[
0
]);
close
(
err
_fds
[
1
]);
close
(
err
[
0
]);
close
(
err
[
1
]);
{
char
*
shell
=
session
->
user
->
shell
->
data
;
...
...
@@ -493,24 +534,31 @@ static int do_spawn_shell(struct channel_request *c,
}
default:
/* Parent */
/* FIXME: Install a calback to catch dying children */
/* FIXME: Install a cal
l
back to catch dying children */
/* Close the child's fd:s */
close
(
in_fds
[
0
]);
close
(
out_fds
[
1
]);
close
(
err_fds
[
2
]);
close
(
in
[
0
]);
close
(
out
[
1
]);
close
(
err
[
2
]);
io_write
(
closure
->
backend
,
in_fds
[
1
],
session
->
in
=
&
io_write
(
closure
->
backend
,
in
[
1
],
SSH_MAX_PACKET
,
/* FIXME: Use a proper close callback */
NULL
);
io_read
(
closure
->
backend
,
out_fds
[
0
],
NULL
)
->
buffer
->
super
;
session
->
out
=
io_read
(
closure
->
backend
,
out
[
0
],
make_channel_read_data
(
channel
),
NULL
);
io_read
(
closure
->
backend
,
err_fds
[
0
],
session
->
err
=
io_read
(
closure
->
backend
,
err
[
0
],
make_channel_read_stderr
(
channel
),
NULL
);
channel
->
recieve
=
do_recieve
;
channel
->
send
=
do_send
;
session
->
running
=
1
;
return
want_reply
?
A_WRITE
(
channel
->
write
,
...
...
@@ -518,14 +566,14 @@ static int do_spawn_shell(struct channel_request *c,
:
LSH_OK
|
LSH_GOON
;
}
close
(
err
_fds
[
0
]);
close
(
err
_fds
[
1
]);
close
(
err
[
0
]);
close
(
err
[
1
]);
}
close
(
out
_fds
[
0
]);
close
(
out
_fds
[
1
]);
close
(
out
[
0
]);
close
(
out
[
1
]);
}
close
(
in
_fds
[
0
]);
close
(
in
_fds
[
1
]);
close
(
in
[
0
]);
close
(
in
[
1
]);
}
fail:
return
want_reply
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment