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
|
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
|
+
+
-
-
+
+
+
|
/*
** SSH initialization of the transport layer
*/
int transport_ssh_open(void){
/* For SSH we need to create and run SSH fossil http
** to talk to the remote machine.
*/
static int fPrintSshCmd = 1; /* Print SSH command only once */
const char *zSsh; /* The base SSH command */
Blob zCmd; /* The SSH command */
char *zHost; /* The host name to contact */
int n; /* Size of prefix string */
zSsh = db_get("ssh-command", zDefaultSshCmd);
blob_init(&zCmd, zSsh, -1);
if( g.urlPort!=g.urlDfltPort && g.urlPort ){
#ifdef __MINGW32__
blob_appendf(&zCmd, " -P %d", g.urlPort);
#else
blob_appendf(&zCmd, " -p %d", g.urlPort);
#endif
}
if( fPrintSshCmd ){
fossil_force_newline();
fossil_print("%s", blob_str(&zCmd)); /* Show the base of the SSH command */
fossil_force_newline();
fossil_print("%s", blob_str(&zCmd)); /* Show the base of the SSH command */
}
if( g.urlUser && g.urlUser[0] ){
zHost = mprintf("%s@%s", g.urlUser, g.urlName);
#ifdef __MINGW32__
/* Only win32 (and specifically PLINK.EXE) support the -pw option */
if( g.urlPasswd && g.urlPasswd[0] ){
Blob pw;
blob_zero(&pw);
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
+
-
+
+
+
|
blob_append(&zCmd, " fossil", 7);
}
blob_append(&zCmd, " http", 5);
if( g.urlPath && g.urlPath[0] ){
blob_append(&zCmd, " ", 1);
shell_escape(&zCmd, mprintf("%s", g.urlPath));
}
if( fPrintSshCmd ){
fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */
fossil_print("%s\n", blob_str(&zCmd)+n); /* Show tail of SSH command */
fPrintSshCmd = 0;
}
free(zHost);
popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid);
if( sshPid==0 ){
socket_set_errmsg("cannot start ssh tunnel using [%b]", &zCmd);
}
blob_reset(&zCmd);
return sshPid==0;
|