Fossil SCM
Further attempts to help the "ssh" sync protocol move past noisy motd comments and other extraneous login text, synchronize with the remote end, and start exchanging messages successfully.
Commit
4473a27f3b6e049e3c162e440e0e4c87daf9570c
Parent
8c7faee6c5fac25…
1 file changed
+12
-5
+12
-5
| --- src/http_transport.c | ||
| +++ src/http_transport.c | ||
| @@ -110,10 +110,12 @@ | ||
| 110 | 110 | */ |
| 111 | 111 | const char *zSsh; /* The base SSH command */ |
| 112 | 112 | Blob zCmd; /* The SSH command */ |
| 113 | 113 | char *zHost; /* The host name to contact */ |
| 114 | 114 | char *zIn; /* An input line received back from remote */ |
| 115 | + unsigned iRandom; | |
| 116 | + char zProbe[30]; | |
| 115 | 117 | |
| 116 | 118 | zSsh = db_get("ssh-command", zDefaultSshCmd); |
| 117 | 119 | blob_init(&zCmd, zSsh, -1); |
| 118 | 120 | if( g.urlPort!=g.urlDfltPort ){ |
| 119 | 121 | #ifdef __MINGW32__ |
| @@ -155,18 +157,23 @@ | ||
| 155 | 157 | if( sshPid==0 ){ |
| 156 | 158 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| 157 | 159 | } |
| 158 | 160 | blob_reset(&zCmd); |
| 159 | 161 | |
| 160 | - /* Send an "echo" command to the other side to make sure that the | |
| 162 | + /* Send a couple of "echo" command to the other side to make sure that the | |
| 161 | 163 | ** connection is up and working. |
| 162 | 164 | */ |
| 163 | - fprintf(sshOut, "echo test\n"); | |
| 165 | + fprintf(sshOut, "echo test1\n"); | |
| 166 | + fflush(sshOut); | |
| 167 | + zIn = fossil_malloc(50000); | |
| 168 | + sshin_read(zIn, 50000); | |
| 169 | + sqlite3_randomness(sizeof(iRandom), &iRandom); | |
| 170 | + sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom); | |
| 171 | + fprintf(sshOut, "echo %s\n", zProbe); | |
| 164 | 172 | fflush(sshOut); |
| 165 | - zIn = fossil_malloc(16000); | |
| 166 | - sshin_read(zIn, 16000); | |
| 167 | - if( memcmp(zIn, "test", 4)!=0 ){ | |
| 173 | + sshin_read(zIn, 500); | |
| 174 | + if( memcmp(zIn, zProbe, 14)!=0 ){ | |
| 168 | 175 | pclose2(sshIn, sshOut, sshPid); |
| 169 | 176 | fossil_fatal("ssh connection failed: [%s]", zIn); |
| 170 | 177 | } |
| 171 | 178 | fossil_free(zIn); |
| 172 | 179 | } |
| 173 | 180 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -110,10 +110,12 @@ | |
| 110 | */ |
| 111 | const char *zSsh; /* The base SSH command */ |
| 112 | Blob zCmd; /* The SSH command */ |
| 113 | char *zHost; /* The host name to contact */ |
| 114 | char *zIn; /* An input line received back from remote */ |
| 115 | |
| 116 | zSsh = db_get("ssh-command", zDefaultSshCmd); |
| 117 | blob_init(&zCmd, zSsh, -1); |
| 118 | if( g.urlPort!=g.urlDfltPort ){ |
| 119 | #ifdef __MINGW32__ |
| @@ -155,18 +157,23 @@ | |
| 155 | if( sshPid==0 ){ |
| 156 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| 157 | } |
| 158 | blob_reset(&zCmd); |
| 159 | |
| 160 | /* Send an "echo" command to the other side to make sure that the |
| 161 | ** connection is up and working. |
| 162 | */ |
| 163 | fprintf(sshOut, "echo test\n"); |
| 164 | fflush(sshOut); |
| 165 | zIn = fossil_malloc(16000); |
| 166 | sshin_read(zIn, 16000); |
| 167 | if( memcmp(zIn, "test", 4)!=0 ){ |
| 168 | pclose2(sshIn, sshOut, sshPid); |
| 169 | fossil_fatal("ssh connection failed: [%s]", zIn); |
| 170 | } |
| 171 | fossil_free(zIn); |
| 172 | } |
| 173 |
| --- src/http_transport.c | |
| +++ src/http_transport.c | |
| @@ -110,10 +110,12 @@ | |
| 110 | */ |
| 111 | const char *zSsh; /* The base SSH command */ |
| 112 | Blob zCmd; /* The SSH command */ |
| 113 | char *zHost; /* The host name to contact */ |
| 114 | char *zIn; /* An input line received back from remote */ |
| 115 | unsigned iRandom; |
| 116 | char zProbe[30]; |
| 117 | |
| 118 | zSsh = db_get("ssh-command", zDefaultSshCmd); |
| 119 | blob_init(&zCmd, zSsh, -1); |
| 120 | if( g.urlPort!=g.urlDfltPort ){ |
| 121 | #ifdef __MINGW32__ |
| @@ -155,18 +157,23 @@ | |
| 157 | if( sshPid==0 ){ |
| 158 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| 159 | } |
| 160 | blob_reset(&zCmd); |
| 161 | |
| 162 | /* Send a couple of "echo" command to the other side to make sure that the |
| 163 | ** connection is up and working. |
| 164 | */ |
| 165 | fprintf(sshOut, "echo test1\n"); |
| 166 | fflush(sshOut); |
| 167 | zIn = fossil_malloc(50000); |
| 168 | sshin_read(zIn, 50000); |
| 169 | sqlite3_randomness(sizeof(iRandom), &iRandom); |
| 170 | sqlite3_snprintf(sizeof(zProbe), zProbe, "probe-%08x", iRandom); |
| 171 | fprintf(sshOut, "echo %s\n", zProbe); |
| 172 | fflush(sshOut); |
| 173 | sshin_read(zIn, 500); |
| 174 | if( memcmp(zIn, zProbe, 14)!=0 ){ |
| 175 | pclose2(sshIn, sshOut, sshPid); |
| 176 | fossil_fatal("ssh connection failed: [%s]", zIn); |
| 177 | } |
| 178 | fossil_free(zIn); |
| 179 | } |
| 180 |