mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
rpc: use virStringSplit instead of strsep
When parsing allowed authentication methods for the native ssh lib transports we used strsep. Since we have virStringSplit helper let's use that one. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
070d6969fe
commit
1a288c7e8a
@ -944,9 +944,8 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
int portN;
|
int portN;
|
||||||
|
|
||||||
char *authMethodNext = NULL;
|
VIR_AUTOSTRINGLIST authMethodList = NULL;
|
||||||
char *authMethodsCopy = NULL;
|
char **authMethodNext;
|
||||||
char *authMethod;
|
|
||||||
|
|
||||||
/* port number will be verified while opening the socket */
|
/* port number will be verified while opening the socket */
|
||||||
if (virStrToLong_i(port, NULL, 10, &portN) < 0) {
|
if (virStrToLong_i(port, NULL, 10, &portN) < 0) {
|
||||||
@ -987,11 +986,12 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
|||||||
if (virNetSSHSessionSetChannelCommand(sess, command) != 0)
|
if (virNetSSHSessionSetChannelCommand(sess, command) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
authMethodsCopy = g_strdup(authMethods);
|
if (!(authMethodList = virStringSplit(authMethods, ",", 0)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
authMethodNext = authMethodsCopy;
|
for (authMethodNext = authMethodList; *authMethodNext; authMethodNext++) {
|
||||||
|
const char *authMethod = *authMethodNext;
|
||||||
|
|
||||||
while ((authMethod = strsep(&authMethodNext, ","))) {
|
|
||||||
if (STRCASEEQ(authMethod, "keyboard-interactive")) {
|
if (STRCASEEQ(authMethod, "keyboard-interactive")) {
|
||||||
ret = virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1);
|
ret = virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1);
|
||||||
} else if (STRCASEEQ(authMethod, "password")) {
|
} else if (STRCASEEQ(authMethod, "password")) {
|
||||||
@ -1028,13 +1028,11 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
|||||||
sock->sshSession = sess;
|
sock->sshSession = sess;
|
||||||
*retsock = sock;
|
*retsock = sock;
|
||||||
|
|
||||||
VIR_FREE(authMethodsCopy);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnref(sock);
|
virObjectUnref(sock);
|
||||||
virObjectUnref(sess);
|
virObjectUnref(sess);
|
||||||
VIR_FREE(authMethodsCopy);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -1079,9 +1077,8 @@ virNetSocketNewConnectLibssh(const char *host,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
int portN;
|
int portN;
|
||||||
|
|
||||||
char *authMethodNext = NULL;
|
VIR_AUTOSTRINGLIST authMethodList = NULL;
|
||||||
char *authMethodsCopy = NULL;
|
char **authMethodNext;
|
||||||
char *authMethod;
|
|
||||||
|
|
||||||
/* port number will be verified while opening the socket */
|
/* port number will be verified while opening the socket */
|
||||||
if (virStrToLong_i(port, NULL, 10, &portN) < 0) {
|
if (virStrToLong_i(port, NULL, 10, &portN) < 0) {
|
||||||
@ -1121,11 +1118,12 @@ virNetSocketNewConnectLibssh(const char *host,
|
|||||||
if (virNetLibsshSessionSetChannelCommand(sess, command) != 0)
|
if (virNetLibsshSessionSetChannelCommand(sess, command) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
authMethodsCopy = g_strdup(authMethods);
|
if (!(authMethodList = virStringSplit(authMethods, ",", 0)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
authMethodNext = authMethodsCopy;
|
for (authMethodNext = authMethodList; *authMethodNext; authMethodNext++) {
|
||||||
|
const char *authMethod = *authMethodNext;
|
||||||
|
|
||||||
while ((authMethod = strsep(&authMethodNext, ","))) {
|
|
||||||
if (STRCASEEQ(authMethod, "keyboard-interactive")) {
|
if (STRCASEEQ(authMethod, "keyboard-interactive")) {
|
||||||
ret = virNetLibsshSessionAuthAddKeyboardAuth(sess, -1);
|
ret = virNetLibsshSessionAuthAddKeyboardAuth(sess, -1);
|
||||||
} else if (STRCASEEQ(authMethod, "password")) {
|
} else if (STRCASEEQ(authMethod, "password")) {
|
||||||
@ -1164,13 +1162,11 @@ virNetSocketNewConnectLibssh(const char *host,
|
|||||||
sock->ownsFd = false;
|
sock->ownsFd = false;
|
||||||
*retsock = sock;
|
*retsock = sock;
|
||||||
|
|
||||||
VIR_FREE(authMethodsCopy);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnref(sock);
|
virObjectUnref(sock);
|
||||||
virObjectUnref(sess);
|
virObjectUnref(sess);
|
||||||
VIR_FREE(authMethodsCopy);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user