Fossil

Diff
Login

Differences From Artifact [b88e45d33e]:

To Artifact [f0f2843eb5]:


90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
90
91
92
93
94
95
96




97

98
99
100
101
102
103
104







-
-
-
-
+
-







    got--;
  }
}

/*
** Default SSH command
*/
#ifdef __MINGW32__
static char zDefaultSshCmd[] = "ssh -T";
#else
static char zDefaultSshCmd[] = "ssh -e none -T";
static char zDefaultSshCmd[] = "ssh";
#endif

/*
** Global initialization of the transport layer
*/
void transport_global_startup(void){
  if( g.urlIsSsh ){
    /* Only SSH requires a global initialization.  For SSH we need to create
147
148
149
150
151
152
153










154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164


















165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181




182





183
184
185
186
187
188
189







+
+
+
+
+
+
+
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

















-
-
-
-
+
-
-
-
-
-







    }else{
      zHost = mprintf("%s", g.urlName);
    }
    blob_append(&zCmd, " ", 1);
    shell_escape(&zCmd, zHost);
    fossil_print(" %s\n", zHost);  /* Show the conclusion of the SSH command */
    free(zHost);
     
    /* Append fossil test-http command directly during the invocation of ssh,
    ** to make sure no output from shell or login will pollute the sshIn pipe.
     */
    blob_append(&zCmd, " \"", 2);
    shell_escape(&zCmd, g.urlFossil);
    blob_append(&zCmd, " test-http ", -1);
    shell_escape(&zCmd, g.urlPath);
    blob_append(&zCmd, "\"", 1);
    
    popen2(blob_str(&zCmd), &sshIn, &sshOut, &sshPid);
    if( sshPid==0 ){
      fossil_fatal("cannot start ssh tunnel using [%b]", &zCmd);
    }
    blob_reset(&zCmd);

    /* Send an "echo" command to the other side to make sure that the
    ** connection is up and working.
    */
    zIn = fossil_malloc(16000);
    fprintf(sshOut, "echo toto\n");
    fflush(sshOut);
    usleep(2000000);
    sshin_read(zIn, 16000);
    fossil_print("Second Read: [%s]\n", zIn);
    fprintf(sshOut, "echo test\n");
    fflush(sshOut);
    sshin_read(zIn, 16000);
    if( memcmp(zIn, "test", 4)!=0 ){
      pclose2(sshIn, sshOut, sshPid);
      fossil_fatal("ssh connection failed: [%s]", zIn);
    }
    fossil_free(zIn);
  }
}

/*
** Open a connection to the server.  The server is defined by the following
** global variables:
**
**   g.urlName        Name of the server.  Ex: www.fossil-scm.org
**   g.urlPort        TCP/IP port.  Ex: 80
**   g.urlIsHttps     Use TLS for the connection
**
** Return the number of errors.
*/
int transport_open(void){
  int rc = 0;
  if( transport.isOpen==0 ){
    if( g.urlIsSsh ){
      Blob cmd;
      blob_zero(&cmd);
      shell_escape(&cmd, g.urlFossil);
      blob_append(&cmd, " test-http ", -1);
      transport.isOpen = 1;
      shell_escape(&cmd, g.urlPath);
      /* printf("%s\n", blob_str(&cmd)); fflush(stdout); */
      fprintf(sshOut, "%s\n", blob_str(&cmd));
      fflush(sshOut);
      blob_reset(&cmd);
    }else if( g.urlIsHttps ){
      #ifdef FOSSIL_ENABLE_SSL
      rc = ssl_open();
      if( rc==0 ) transport.isOpen = 1;
      #else
      socket_set_errmsg("HTTPS: Fossil has been compiled without SSL support");
      rc = 1;