Added checks and fixes code style

This commit is contained in:
KLuka 2016-05-06 11:21:14 +02:00
parent e05c6d8178
commit 628d41f32c

View file

@ -124,24 +124,25 @@ void initService(struct Service *service, const char *arg) {
char *sshPort;
check(host = strdup("localhost"));
check(sshPort = strdup("22"));
if ((ptr = strchr(arg, ':')) != NULL) {
ptr = ptr + 1;
if (*ptr) {
char * tmp = strchr(ptr, ':');
if(tmp == NULL)//if the second ":" is not found, keep as host whatever is after first ":"
{
char *tmp = strchr(ptr, ':');
if (tmp == NULL) {
// If the second ":" is not found, keep as host whatever is after first ":".
free(host);
host = strdup(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 ":"
{
check(host = strdup(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);
free(sshPort);
host = malloc(size);
check(host = malloc(size));
memset(host, 0, size);
memcpy(host, ptr , size - 1);
sshPort = strdup (tmp + 1);
memcpy(host, ptr, size - 1);
check(sshPort = strdup(tmp + 1));
}
}
}
@ -166,6 +167,7 @@ void initService(struct Service *service, const char *arg) {
fatal("[config] Invalid port \"%s\" in service definition!", sshPort);
}
}
service->cmdline = stringPrintf(NULL,
"ssh -a -e none -i /dev/null -x -oChallengeResponseAuthentication=no "
"-oCheckHostIP=no -oClearAllForwardings=yes -oCompression=no "