Add support for using ShellInABox with a custom SSH port

This commit is contained in:
Alexandru Bogdan Stefan 2016-04-21 19:14:50 +03:00
parent 048cecd2e7
commit d34d5db9d9

View file

@ -121,18 +121,27 @@ void initService(struct Service *service, const char *arg) {
service->group = NULL; service->group = NULL;
check(service->cwd = strdup("/")); check(service->cwd = strdup("/"));
char *host; char *host;
char *sshPort;
check(host = strdup("localhost")); check(host = strdup("localhost"));
check(sshPort = strdup("22"));
if ((ptr = strchr(arg, ':')) != NULL) { if ((ptr = strchr(arg, ':')) != NULL) {
check(ptr = strdup(ptr + 1)); ptr = ptr + 1;
char *end;
if ((end = strchr(ptr, ':')) != NULL) {
*end = '\000';
}
if (*ptr) { if (*ptr) {
char * tmp = strchr(ptr, ':');
if(tmp == NULL)//if the second ":" is not found, keep as host whatever is after first ":"
{
free(host); free(host);
host = ptr; host = strdup(ptr);
} else { }
free(ptr); else // if we find a second ":", keep as a host whatever is in between first ":" and second ":" and as sshPort whatever is after second ":"
{
int size = (tmp - ptr + 1);
free(host);
host = malloc(size);
memset(host, 0, size);
memcpy(host, ptr , size-1);
sshPort = strdup (tmp + 1);
}
} }
} }
@ -148,6 +157,14 @@ void initService(struct Service *service, const char *arg) {
} }
} }
// Don't allow manipulation of the SSH command line through "creative" use
// of the port.
for (char *h = sshPort; *h; h++) {
char ch = *h;
if (!(ch >= '0' && ch <= '9')) {
fatal("[config] Invalid port \"%s\" in service definition!", sshPort);
}
}
service->cmdline = stringPrintf(NULL, service->cmdline = stringPrintf(NULL,
"ssh -a -e none -i /dev/null -x -oChallengeResponseAuthentication=no " "ssh -a -e none -i /dev/null -x -oChallengeResponseAuthentication=no "
"-oCheckHostIP=no -oClearAllForwardings=yes -oCompression=no " "-oCheckHostIP=no -oClearAllForwardings=yes -oCompression=no "
@ -162,8 +179,9 @@ void initService(struct Service *service, const char *arg) {
// feature, we cannot be sure that it is available on the // feature, we cannot be sure that it is available on the
// target server. Removing it for the sake of Centos. // target server. Removing it for the sake of Centos.
// "-oVisualHostKey=no" // "-oVisualHostKey=no"
" -oLogLevel=FATAL %%s@%s", host); " -oLogLevel=FATAL -p%s %%s@%s",sshPort, host);
free(host); free(host);
free(sshPort);
} else { } else {
service->useLogin = 0; service->useLogin = 0;