- printf("\nEstablishing an SSH connection to the source system...\n\n");
- unlink(socket_path);
- snprintf(cmd, sizeof cmd, "ssh -MNf -S %s %s@%s", socket_path, remote_user, remote_host);
- cmdexit = system(cmd);
- if (cmdexit != 0) {
- printf("\nctdlmigrate was unable to establish an SSH connection to the\n"
- "source system, and cannot continue.\n\n");
- exitcode = cmdexit;
- goto THEEND;
- }
-
- printf("\nTesting a command over the connection...\n\n");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s 'echo Remote commands are executing successfully.'",
- socket_path, remote_user, remote_host);
- cmdexit = system(cmd);
- printf("\n");
- if (cmdexit != 0) {
- printf("Remote commands are not succeeding.\n\n");
- exitcode = cmdexit;
- goto THEEND;
- }
-
- printf("\nLocating the remote 'sendcommand' and Citadel installation...\n");
- snprintf(remote_sendcommand, sizeof remote_sendcommand, "/usr/local/citadel/sendcommand");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s %s NOOP",
- socket_path, remote_user, remote_host, remote_sendcommand);
- cmdexit = system(cmd);
- if (cmdexit != 0) {
- snprintf(remote_sendcommand, sizeof remote_sendcommand, "/usr/sbin/sendcommand");
- snprintf(cmd, sizeof cmd, "ssh -S %s %s@%s %s NOOP",
- socket_path, remote_user, remote_host, remote_sendcommand);
- cmdexit = system(cmd);
+ if (!cmdexit) {
+ printf("\nOK, this side is ready to go. Now we must connect to the source system.\n\n");
+ printf("Enter the host name or IP address of the source system\n"
+ "(example: ctdl.foo.org)\n"
+ "--> ");
+ getz(remote_host);
+
+ while (IsEmptyStr(remote_user)) {
+ printf("\nEnter the name of a user on %s who has full access to Citadel files\n"
+ "(usually root)\n--> ",
+ remote_host);
+ getz(remote_user);
+ }
+
+ printf("\nEstablishing an SSH connection to the source system...\n\n");
+ sprintf(socket_path, "/tmp/ctdlmigrate-socket.%ld.%d", time(NULL), getpid());
+ unlink(socket_path);
+
+ snprintf(cmd, sizeof cmd, "ssh -MNf -S %s -l %s %s", socket_path, remote_user, remote_host);
+ sshpid = fork();
+ if (sshpid < 0) {
+ printf("%s\n", strerror(errno));
+ cmdexit = errno;
+ }
+ else if (sshpid == 0) {
+ execl("/bin/bash", "bash", "-c", cmd, (char *) NULL);
+ exit(1);
+ }
+ else { // Wait for SSH to go into the background
+ waitpid(sshpid, &cmdexit, 0);
+ }