95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
** Default SSH command
*/
#ifdef __MINGW32__
static char zDefaultSshCmd[] = "ssh -T";
#else
static char zDefaultSshCmd[] = "ssh -e none -T";
#endif
/*
** Bring up an SSH link. This involves sending some "echo" commands and
** get back appropriate responses. The point is to move past the MOTD and
** verify that the link is working.
*/
static void transport_ssh_startup(void){
char *zIn; /* An input line received back from remote */
int nWait; /* Number of times waiting for the MOTD */
unsigned iRandom; /* Random probe value */
char zProbe[30]; /* Text of the random probe */
int nProbe; /* Size of probe message */
int nIn; /* Size of input */
static const int nBuf = 10000; /* Size of input buffer */
zIn = fossil_malloc(nBuf);
sqlite3_randomness(sizeof(iRandom), &iRandom);
sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
nProbe = (int)strlen(zProbe);
fprintf(sshOut, "echo %s\n", zProbe);
fflush(sshOut);
if( g.fSshTrace ){
printf("Sent: [echo %s]\n", zProbe);
fflush(stdout);
}
memset(zIn, '*', nProbe);
|
>
>
>
>
>
>
>
>
>
>
>
|
|
<
|
|
<
|
<
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
** Default SSH command
*/
#ifdef __MINGW32__
static char zDefaultSshCmd[] = "ssh -T";
#else
static char zDefaultSshCmd[] = "ssh -e none -T";
#endif
/*
** Generate a random SSH link problem keyword
*/
static int random_probe(char *zProbe, int nProbe){
unsigned r[4];
sqlite3_randomness(sizeof(r), r);
sqlite3_snprintf(nProbe, zProbe, "probe-%08x%08x%08x%08x",
r[0], r[1], r[2], r[3]);
return (int)strlen(zProbe);
}
/*
** Bring up an SSH link. This involves sending some "echo" commands and
** get back appropriate responses. The point is to move past the MOTD and
** verify that the link is working.
*/
static void transport_ssh_startup(void){
char *zIn; /* An input line received back from remote */
int nWait; /* Number of times waiting for the MOTD */
char zProbe[40]; /* Text of the random probe */
int nProbe; /* Size of probe message */
int nIn; /* Size of input */
static const int nBuf = 10000; /* Size of input buffer */
zIn = fossil_malloc(nBuf);
nProbe = random_probe(zProbe, sizeof(zProbe));
fprintf(sshOut, "echo %s\n", zProbe);
fflush(sshOut);
if( g.fSshTrace ){
printf("Sent: [echo %s]\n", zProbe);
fflush(stdout);
}
memset(zIn, '*', nProbe);
|
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
nIn = (int)strlen(zIn);
memcpy(zIn, zIn+(nIn-nProbe), nProbe);
if( g.fSshTrace ){
printf("Fetching more text. Looking for [%s]...\n", zProbe);
fflush(stdout);
}
}
sqlite3_randomness(sizeof(iRandom), &iRandom);
sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom);
fprintf(sshOut, "echo %s\n", zProbe);
fflush(sshOut);
if( g.fSshTrace ){
printf("Sent: [echo %s]\n", zProbe);
fflush(stdout);
}
sshin_read(zIn, nBuf);
|
<
|
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
nIn = (int)strlen(zIn);
memcpy(zIn, zIn+(nIn-nProbe), nProbe);
if( g.fSshTrace ){
printf("Fetching more text. Looking for [%s]...\n", zProbe);
fflush(stdout);
}
}
nProbe = random_probe(zProbe, sizeof(zProbe));
fprintf(sshOut, "echo %s\n", zProbe);
fflush(sshOut);
if( g.fSshTrace ){
printf("Sent: [echo %s]\n", zProbe);
fflush(stdout);
}
sshin_read(zIn, nBuf);
|