CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/libssh/ssh_server_fork.patch
Views: 11766
1
diff --git a/examples/ssh_server_fork.c b/examples/ssh_server_fork.c
2
index 217c5298..20008c76 100644
3
--- a/examples/ssh_server_fork.c
4
+++ b/examples/ssh_server_fork.c
5
@@ -235,8 +235,6 @@ struct channel_data_struct {
6
struct session_data_struct {
7
/* Pointer to the channel the session will allocate. */
8
ssh_channel channel;
9
- int auth_attempts;
10
- int authenticated;
11
};
12
13
static int data_function(ssh_session session, ssh_channel channel, void *data,
14
@@ -406,8 +404,8 @@ static int shell_request(ssh_session session, ssh_channel channel,
15
if (cdata->pty_master != -1 && cdata->pty_slave != -1) {
16
return exec_pty("-l", NULL, cdata);
17
}
18
- /* Client requested a shell without a pty, let's pretend we allow that */
19
- return SSH_OK;
20
+
21
+ return exec_nopty("/bin/sh -l", cdata);
22
}
23
24
static int subsystem_request(ssh_session session, ssh_channel channel,
25
@@ -421,16 +419,13 @@ static int subsystem_request(ssh_session session, ssh_channel channel,
26
27
static int auth_password(ssh_session session, const char *user,
28
const char *pass, void *userdata) {
29
- struct session_data_struct *sdata = (struct session_data_struct *) userdata;
30
-
31
(void) session;
32
+ (void) userdata;
33
34
if (strcmp(user, USER) == 0 && strcmp(pass, PASS) == 0) {
35
- sdata->authenticated = 1;
36
return SSH_AUTH_SUCCESS;
37
}
38
39
- sdata->auth_attempts++;
40
return SSH_AUTH_DENIED;
41
}
42
43
@@ -496,9 +491,7 @@ static void handle_session(ssh_event event, ssh_session session) {
44
45
/* Our struct holding information about the session. */
46
struct session_data_struct sdata = {
47
- .channel = NULL,
48
- .auth_attempts = 0,
49
- .authenticated = 0
50
+ .channel = NULL
51
};
52
53
struct ssh_channel_callbacks_struct channel_cb = {
54
@@ -530,19 +523,11 @@ static void handle_session(ssh_event event, ssh_session session) {
55
ssh_set_auth_methods(session, SSH_AUTH_METHOD_PASSWORD);
56
ssh_event_add_session(event, session);
57
58
- n = 0;
59
- while (sdata.authenticated == 0 || sdata.channel == NULL) {
60
- /* If the user has used up all attempts, or if he hasn't been able to
61
- * authenticate in 10 seconds (n * 100ms), disconnect. */
62
- if (sdata.auth_attempts >= 3 || n >= 100) {
63
- return;
64
- }
65
-
66
+ while (sdata.channel == NULL) {
67
if (ssh_event_dopoll(event, 100) == SSH_ERROR) {
68
fprintf(stderr, "%s\n", ssh_get_error(session));
69
return;
70
}
71
- n++;
72
}
73
74
ssh_set_channel_callbacks(sdata.channel, &channel_cb);
75
76