| | @@ -183,13 +183,24 @@ |
| 183 | 183 | ** and run an SSH command to talk to the remote machine. |
| 184 | 184 | */ |
| 185 | 185 | const char *zSsh; /* The base SSH command */ |
| 186 | 186 | Blob zCmd; /* The SSH command */ |
| 187 | 187 | char *zHost; /* The host name to contact */ |
| 188 | + char *zPath; /* The path to the remote file for SSH */ |
| 189 | + char *zfCmd; /* The path to remote fossil for SSH */ |
| 188 | 190 | int n; /* Size of prefix string */ |
| 189 | 191 | |
| 190 | 192 | zSsh = db_get("ssh-command", zDefaultSshCmd); |
| 193 | + if( g.fSshRemoteCmd && g.fSshRemoteCmd[0] ){ |
| 194 | + zfCmd = g.fSshRemoteCmd; |
| 195 | + db_set("last-ssh-remote-cmd", zfCmd, 0); |
| 196 | + }else{ |
| 197 | + zfCmd = db_get("last-ssh-remote-cmd", 0); |
| 198 | + if( zfCmd==0 ){ |
| 199 | + zfCmd = "fossil"; |
| 200 | + } |
| 201 | + } |
| 191 | 202 | blob_init(&zCmd, zSsh, -1); |
| 192 | 203 | if( g.urlPort!=g.urlDfltPort ){ |
| 193 | 204 | #ifdef __MINGW32__ |
| 194 | 205 | blob_appendf(&zCmd, " -P %d", g.urlPort); |
| 195 | 206 | #else |
| | @@ -223,34 +234,24 @@ |
| 223 | 234 | zHost = mprintf("%s", g.urlName); |
| 224 | 235 | } |
| 225 | 236 | n = blob_size(&zCmd); |
| 226 | 237 | blob_append(&zCmd, " ", 1); |
| 227 | 238 | shell_escape(&zCmd, zHost); |
| 228 | | - if( g.urlShell ){ |
| 229 | | - blob_appendf(&zCmd, " %s", g.urlShell); |
| 230 | | - }else{ |
| 231 | | -#if defined(FOSSIL_ENABLE_SSH_FAR_SIDE) |
| 232 | | - /* The following works. But only if the fossil on the remote side |
| 233 | | - ** is recent enough to support the test-ssh-far-side command. That |
| 234 | | - ** command was added on 2013-02-06. We will leave this turned off |
| 235 | | - ** until most fossil servers have upgraded to that version or a later |
| 236 | | - ** version. The sync will still work as long as the shell on the far |
| 237 | | - ** side is bash and not tcsh. And if the default far side shell is |
| 238 | | - ** tcsh, then the shell=/bin/bash query parameter can be used as a |
| 239 | | - ** work-around. Enable this code after about a year... |
| 240 | | - */ |
| 241 | | - blob_appendf(&zCmd, " exec %s test-ssh-far-side", g.urlFossil); |
| 242 | | -#endif |
| 239 | + blob_append(&zCmd, " ", 1); |
| 240 | + shell_escape(&zCmd, zfCmd); |
| 241 | + blob_append(&zCmd, " http ", 6); |
| 242 | + if( g.urlPath && g.urlPath[0] ){ |
| 243 | + zPath = mprintf("%s", g.urlPath); |
| 244 | + shell_escape(&zCmd, zPath); |
| 243 | 245 | } |
| 244 | 246 | fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */ |
| 245 | 247 | free(zHost); |
| 246 | 248 | popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid); |
| 247 | 249 | if( sshPid==0 ){ |
| 248 | 250 | fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd); |
| 249 | 251 | } |
| 250 | 252 | blob_reset(&zCmd); |
| 251 | | - transport_ssh_startup(); |
| 252 | 253 | } |
| 253 | 254 | } |
| 254 | 255 | |
| 255 | 256 | /* |
| 256 | 257 | ** COMMAND: test-ssh-far-side |
| | @@ -288,19 +289,11 @@ |
| 288 | 289 | */ |
| 289 | 290 | int transport_open(void){ |
| 290 | 291 | int rc = 0; |
| 291 | 292 | if( transport.isOpen==0 ){ |
| 292 | 293 | if( g.urlIsSsh ){ |
| 293 | | - Blob cmd; |
| 294 | | - blob_zero(&cmd); |
| 295 | | - shell_escape(&cmd, g.urlFossil); |
| 296 | | - blob_append(&cmd, " test-http ", -1); |
| 297 | | - shell_escape(&cmd, g.urlPath); |
| 298 | | - fprintf(sshOut, "%s || true\n", blob_str(&cmd)); |
| 299 | | - fflush(sshOut); |
| 300 | | - if( g.fSshTrace ) printf("Sent: [%s]\n", blob_str(&cmd)); |
| 301 | | - blob_reset(&cmd); |
| 294 | + /* no-op now */ |
| 302 | 295 | }else if( g.urlIsHttps ){ |
| 303 | 296 | #ifdef FOSSIL_ENABLE_SSL |
| 304 | 297 | rc = ssl_open(); |
| 305 | 298 | if( rc==0 ) transport.isOpen = 1; |
| 306 | 299 | #else |
| | @@ -582,19 +575,23 @@ |
| 582 | 575 | if( g.fSshTrace ) printf("Got line: [%s]\n", &transport.pBuf[iStart]); |
| 583 | 576 | return &transport.pBuf[iStart]; |
| 584 | 577 | } |
| 585 | 578 | |
| 586 | 579 | void transport_global_shutdown(void){ |
| 587 | | - if( g.urlIsSsh && sshPid ){ |
| 588 | | - /*printf("Closing SSH tunnel: ");*/ |
| 589 | | - fflush(stdout); |
| 590 | | - pclose2(sshIn, sshOut, sshPid); |
| 591 | | - sshPid = 0; |
| 592 | | - } |
| 580 | + transport_global_ssh_shutdown(); |
| 593 | 581 | if( g.urlIsHttps ){ |
| 594 | 582 | #ifdef FOSSIL_ENABLE_SSL |
| 595 | 583 | ssl_global_shutdown(); |
| 596 | 584 | #endif |
| 597 | 585 | }else{ |
| 598 | 586 | socket_global_shutdown(); |
| 599 | 587 | } |
| 600 | 588 | } |
| 589 | + |
| 590 | +void transport_global_ssh_shutdown(void){ |
| 591 | + if( g.urlIsSsh && sshPid ){ |
| 592 | + /*printf("Closing SSH tunnel: ");*/ |
| 593 | + fflush(stdout); |
| 594 | + pclose2(sshIn, sshOut, sshPid); |
| 595 | + sshPid = 0; |
| 596 | + } |
| 597 | +} |
| 601 | 598 | |