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; char *sshPort;
check(host = strdup("localhost")); check(host = strdup("localhost"));
check(sshPort = strdup("22")); check(sshPort = strdup("22"));
if ((ptr = strchr(arg, ':')) != NULL) { if ((ptr = strchr(arg, ':')) != NULL) {
ptr = ptr + 1; ptr = ptr + 1;
if (*ptr) { if (*ptr) {
char *tmp = strchr(ptr, ':'); char *tmp = strchr(ptr, ':');
if(tmp == NULL)//if the second ":" is not found, keep as host whatever is after first ":" if (tmp == NULL) {
{ // If the second ":" is not found, keep as host whatever is after first ":".
free(host); free(host);
host = strdup(ptr); check(host = strdup(ptr));
} } else {
else // if we find a second ":", keep as a host whatever is in between first ":" and second ":" and as sshPort whatever is after second ":" // 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); int size = (tmp - ptr + 1);
free(host); free(host);
free(sshPort); free(sshPort);
host = malloc(size); check(host = malloc(size));
memset(host, 0, size); memset(host, 0, size);
memcpy(host, ptr, size - 1); memcpy(host, ptr, size - 1);
sshPort = strdup (tmp + 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); 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 "