rpc: Use g_strdup_printf() instead of virAsprintf()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-10-22 15:26:14 +02:00
parent 2b41a017ab
commit c684b3c7e8
5 changed files with 28 additions and 70 deletions

View File

@ -343,8 +343,7 @@ virNetClientCheckKeyExists(const char *homedir,
{
char *path;
if (virAsprintf(&path, "%s/.ssh/%s", homedir, name) < 0)
return -1;
path = g_strdup_printf("%s/.ssh/%s", homedir, name);
if (!(virFileExists(path))) {
VIR_FREE(path);
@ -565,10 +564,8 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
knownhosts = g_strdup(knownHostsPath);
} else {
confdir = virGetUserConfigDirectory();
if (confdir) {
if (virAsprintf(&knownhosts, "%s/known_hosts", confdir) < 0)
goto cleanup;
}
if (confdir)
knownhosts = g_strdup_printf("%s/known_hosts", confdir);
}
if (privkeyPath) {
@ -602,16 +599,10 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
if (!(nc = virBufferContentAndReset(&buf)))
goto no_memory;
if (virAsprintf(&command,
"sh -c "
"'if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;"
"else "
"ARG=;"
"fi;"
"'%s' $ARG -U %s'",
nc, nc, socketPath) < 0)
goto cleanup;
command = g_strdup_printf("sh -c "
"'if '%s' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;" "else " "ARG=;" "fi;" "'%s' $ARG -U %s'", nc, nc,
socketPath);
if (virNetSocketNewConnectLibssh(host, port,
family,

View File

@ -341,15 +341,8 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess)
if (!keyhashstr)
return -1;
if (virAsprintf(&tmp,
_("Accept SSH host key with hash '%s' for "
"host '%s:%d' (%s/%s)?"),
keyhashstr,
sess->hostname, sess->port,
"y", "n") < 0) {
ssh_string_free_char(keyhashstr);
return -1;
}
tmp = g_strdup_printf(_("Accept SSH host key with hash '%s' for " "host '%s:%d' (%s/%s)?"),
keyhashstr, sess->hostname, sess->port, "y", "n");
askKey.prompt = tmp;
if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) {
@ -530,10 +523,7 @@ virNetLibsshAuthenticatePrivkey(virNetLibsshSessionPtr sess,
VIR_DEBUG("sess=%p", sess);
if (virAsprintf(&tmp, "%s.pub", priv->filename) < 0) {
err = SSH_AUTH_ERROR;
goto error;
}
tmp = g_strdup_printf("%s.pub", priv->filename);
/* try to open the public part of the private key */
ret = ssh_pki_import_pubkey_file(tmp, &public_key);

View File

@ -698,8 +698,7 @@ int virNetSocketNewConnectUNIX(const char *path,
goto cleanup;
}
if (virAsprintf(&lockpath, "%s/%s.lock", rundir, binname) < 0)
goto cleanup;
lockpath = g_strdup_printf("%s/%s.lock", rundir, binname);
if ((lockfd = open(lockpath, O_RDWR | O_CREAT, 0600)) < 0 ||
virSetCloseExec(lockfd) < 0) {

View File

@ -362,15 +362,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
keyhashstr = virBufferContentAndReset(&buff);
askKey.type = VIR_CRED_ECHOPROMPT;
if (virAsprintf((char **)&askKey.prompt,
_("Accept SSH host key with hash '%s' for "
"host '%s:%d' (%s/%s)?"),
keyhashstr,
sess->hostname, sess->port,
"y", "n") < 0) {
VIR_FREE(keyhashstr);
return -1;
}
askKey.prompt = g_strdup_printf(_("Accept SSH host key with hash '%s' for " "host '%s:%d' (%s/%s)?"),
keyhashstr, sess->hostname, sess->port, "y", "n");
if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) {
virReportError(VIR_ERR_SSH, "%s",
@ -628,10 +621,8 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
return -1;
}
if (virAsprintf((char **)&retr_passphrase.prompt,
_("Passphrase for key '%s'"),
priv->filename) < 0)
return -1;
retr_passphrase.prompt = g_strdup_printf(_("Passphrase for key '%s'"),
priv->filename);
if (sess->cred->cb(&retr_passphrase, 1, sess->cred->cbdata)) {
virReportError(VIR_ERR_SSH, "%s",

View File

@ -796,19 +796,13 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
*/
if (pkipath) {
VIR_DEBUG("Told to use TLS credentials in %s", pkipath);
if ((virAsprintf(cacert, "%s/%s", pkipath,
"cacert.pem")) < 0)
goto error;
if ((virAsprintf(cacrl, "%s/%s", pkipath,
"cacrl.pem")) < 0)
goto error;
if ((virAsprintf(key, "%s/%s", pkipath,
isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
goto error;
*cacert = g_strdup_printf("%s/%s", pkipath, "cacert.pem");
*cacrl = g_strdup_printf("%s/%s", pkipath, "cacrl.pem");
*key = g_strdup_printf("%s/%s", pkipath,
isServer ? "serverkey.pem" : "clientkey.pem");
if ((virAsprintf(cert, "%s/%s", pkipath,
isServer ? "servercert.pem" : "clientcert.pem")) < 0)
goto error;
*cert = g_strdup_printf("%s/%s", pkipath,
isServer ? "servercert.pem" : "clientcert.pem");
} else if (tryUserPkiPath) {
/* Check to see if $HOME/.pki contains at least one of the
* files and if so, use that
@ -818,26 +812,19 @@ static int virNetTLSContextLocateCredentials(const char *pkipath,
if (!userdir)
goto error;
if (virAsprintf(&user_pki_path, "%s/.pki/libvirt", userdir) < 0)
goto error;
user_pki_path = g_strdup_printf("%s/.pki/libvirt", userdir);
VIR_DEBUG("Trying to find TLS user credentials in %s", user_pki_path);
if ((virAsprintf(cacert, "%s/%s", user_pki_path,
"cacert.pem")) < 0)
goto error;
*cacert = g_strdup_printf("%s/%s", user_pki_path, "cacert.pem");
if ((virAsprintf(cacrl, "%s/%s", user_pki_path,
"cacrl.pem")) < 0)
goto error;
*cacrl = g_strdup_printf("%s/%s", user_pki_path, "cacrl.pem");
if ((virAsprintf(key, "%s/%s", user_pki_path,
isServer ? "serverkey.pem" : "clientkey.pem")) < 0)
goto error;
*key = g_strdup_printf("%s/%s", user_pki_path,
isServer ? "serverkey.pem" : "clientkey.pem");
if ((virAsprintf(cert, "%s/%s", user_pki_path,
isServer ? "servercert.pem" : "clientcert.pem")) < 0)
goto error;
*cert = g_strdup_printf("%s/%s", user_pki_path,
isServer ? "servercert.pem" : "clientcert.pem");
/*
* If some of the files can't be found, fallback