# SPECIAL: virConnectGetType returns a constant string that must
# not be freed. Therefore, duplicate the string here.
push(@vars_list, "const char *$1");
- push(@ret_list, "/* We have to VIR_STRDUP because remoteDispatchClientRequest will");
+ push(@ret_list, "/* We have to g_strdup because remoteDispatchClientRequest will");
push(@ret_list, " * free this string after it's been serialised. */");
- push(@ret_list, "if (VIR_STRDUP(ret->type, type) < 0)");
- push(@ret_list, " goto cleanup;");
+ push(@ret_list, "ret->type = g_strdup(type);");
} else {
push(@vars_list, "char *$1");
push(@ret_list, "ret->$1 = $1;");
"if (VIR_ALLOC($1_p) < 0)\n" .
" goto cleanup;\n" .
"\n" .
- " if (VIR_STRDUP(*$1_p, $1) < 0)\n".
- " goto cleanup;\n");
+ " *$1_p = g_strdup($1);\n");
$single_ret_var = $1;
$single_ret_by_ref = 0;
if ($single_ret_as_list) {
print " /* This call is caller-frees (although that isn't clear from\n";
print " * the documentation). However xdr_free will free up both the\n";
- print " * names and the list of pointers, so we have to VIR_STRDUP the\n";
+ print " * names and the list of pointers, so we have to g_strdup the\n";
print " * names here. */\n";
print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n";
- print " if (VIR_STRDUP(${single_ret_list_name}[i],\n";
- print " ret.$single_ret_list_name.${single_ret_list_name}_val[i]) < 0) {\n";
- print " size_t j;\n";
- print " for (j = 0; j < i; j++)\n";
- print " VIR_FREE(${single_ret_list_name}[j]);\n";
- print "\n";
- print " goto cleanup;\n";
- print " }\n";
+ print " ${single_ret_list_name}[i] = \n";
+ print " g_strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n";
print " }\n";
print "\n";
} elsif ($modern_ret_as_list) {
client->wakeupSendFD = wakeupFD[1];
wakeupFD[0] = wakeupFD[1] = -1;
- if (VIR_STRDUP(client->hostname, hostname) < 0)
- goto error;
+ client->hostname = g_strdup(hostname);
PROBE(RPC_CLIENT_NEW,
"client=%p sock=%p",
/* Use default paths for known hosts an public keys if not provided */
if (knownHostsPath) {
- if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
- goto cleanup;
+ knownhosts = g_strdup(knownHostsPath);
} else {
confdir = virGetUserConfigDirectory();
if (confdir) {
}
if (privkeyPath) {
- if (VIR_STRDUP(privkey, privkeyPath) < 0)
- goto cleanup;
+ privkey = g_strdup(privkeyPath);
} else {
homedir = virGetUserDirectory();
if (homedir) {
/* Use default paths for known hosts an public keys if not provided */
if (knownHostsPath) {
- if (VIR_STRDUP(knownhosts, knownHostsPath) < 0)
- goto cleanup;
+ knownhosts = g_strdup(knownHostsPath);
} else {
confdir = virGetUserConfigDirectory();
if (confdir) {
}
if (privkeyPath) {
- if (VIR_STRDUP(privkey, privkeyPath) < 0)
- goto cleanup;
+ privkey = g_strdup(privkeyPath);
} else {
homedir = virGetUserDirectory();
if (homedir) {
virObjectLock(sess);
- if (VIR_STRDUP(file, keyfile) < 0 ||
- VIR_STRDUP(pass, password) < 0) {
- ret = -1;
- goto error;
- }
+ file = g_strdup(keyfile);
+ pass = g_strdup(password);
if (!(auth = virNetLibsshSessionAuthMethodNew(sess))) {
ret = -1;
VIR_FREE(sess->channelCommand);
- if (VIR_STRDUP(sess->channelCommand, command) < 0)
- ret = -1;
+ sess->channelCommand = g_strdup(command);
virObjectUnlock(sess);
return ret;
VIR_FREE(sess->hostname);
- if (VIR_STRDUP(sess->hostname, hostname) < 0)
- goto error;
+ sess->hostname = g_strdup(hostname);
/* set the hostname */
if (ssh_options_set(sess->session, SSH_OPTIONS_HOST, sess->hostname) < 0)
goto error;
VIR_FREE(sess->knownHostsFile);
- if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
- goto error;
+ sess->knownHostsFile = g_strdup(hostsfile);
} else {
/* libssh does not support trying no known_host file at all:
* hence use /dev/null here, without storing it as file */
goto error;
}
- if (VIR_STRDUP(sess->username, username) < 0)
- goto error;
+ sess->username = g_strdup(username);
VIR_DEBUG("virNetLibsshSessionPtr: %p, ssh_session: %p",
sess, sess->session);
if (verr) {
rerr->code = verr->code;
rerr->domain = verr->domain;
- if (verr->message && VIR_ALLOC(rerr->message) == 0 &&
- VIR_STRDUP_QUIET(*rerr->message, verr->message) < 0)
- VIR_FREE(rerr->message);
+ if (verr->message && VIR_ALLOC(rerr->message) == 0)
+ *rerr->message = g_strdup(verr->message);
rerr->level = verr->level;
- if (verr->str1 && VIR_ALLOC(rerr->str1) == 0 &&
- VIR_STRDUP_QUIET(*rerr->str1, verr->str1) < 0)
- VIR_FREE(rerr->str1);
- if (verr->str2 && VIR_ALLOC(rerr->str2) == 0 &&
- VIR_STRDUP_QUIET(*rerr->str2, verr->str2) < 0)
- VIR_FREE(rerr->str2);
- if (verr->str3 && VIR_ALLOC(rerr->str3) == 0 &&
- VIR_STRDUP_QUIET(*rerr->str3, verr->str3) < 0)
- VIR_FREE(rerr->str3);
+ if (verr->str1 && VIR_ALLOC(rerr->str1) == 0)
+ *rerr->str1 = g_strdup(verr->str1);
+ if (verr->str2 && VIR_ALLOC(rerr->str2) == 0)
+ *rerr->str2 = g_strdup(verr->str2);
+ if (verr->str3 && VIR_ALLOC(rerr->str3) == 0)
+ *rerr->str3 = g_strdup(verr->str3);
rerr->int1 = verr->int1;
rerr->int2 = verr->int2;
} else {
rerr->code = VIR_ERR_INTERNAL_ERROR;
rerr->domain = VIR_FROM_RPC;
- if (VIR_ALLOC_QUIET(rerr->message) == 0 &&
- VIR_STRDUP_QUIET(*rerr->message,
- _("Library function returned error but did not set virError")) < 0)
- VIR_FREE(rerr->message);
+ if (VIR_ALLOC_QUIET(rerr->message) == 0)
+ *rerr->message = g_strdup(_("Library function returned error but did not set virError"));
rerr->level = VIR_ERR_ERROR;
}
}
srv)))
goto error;
- if (VIR_STRDUP(srv->name, name) < 0)
- goto error;
+ srv->name = g_strdup(name);
srv->next_client_id = next_client_id;
srv->nclients_max = max_clients;
goto cleanup;
}
- if (VIR_STRDUP(*sock_addr, addr) < 0)
- goto cleanup;
+ *sock_addr = g_strdup(addr);
if (!client->identity) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
if (virNetSSHSessionSetChannelCommand(sess, command) != 0)
goto error;
- if (VIR_STRDUP(authMethodsCopy, authMethods) < 0)
- goto error;
+ authMethodsCopy = g_strdup(authMethods);
authMethodNext = authMethodsCopy;
if (virNetLibsshSessionSetChannelCommand(sess, command) != 0)
goto error;
- if (VIR_STRDUP(authMethodsCopy, authMethods) < 0)
- goto error;
+ authMethodsCopy = g_strdup(authMethods);
authMethodNext = authMethodsCopy;
goto cleanup;
}
- if (VIR_STRDUP(*context, seccon) < 0)
- goto cleanup;
+ *context = g_strdup(seccon);
ret = 0;
cleanup:
/* fill data structures for auth callback */
for (i = 0; i < num_prompts; i++) {
char *prompt;
- if (VIR_STRDUP(prompt, prompts[i].text) < 0) {
- priv->authCbErr = VIR_NET_SSH_AUTHCB_OOM;
- goto cleanup;
- }
+ prompt = g_strdup(prompts[i].text);
askcred[i].prompt = prompt;
/* remove colon and trailing spaces from prompts, as default behavior
"ssh", NULL, sess->hostname)))
goto error;
} else {
- if (VIR_STRDUP(user, username) < 0)
- goto error;
+ user = g_strdup(username);
}
virObjectLock(sess);
virObjectLock(sess);
- if (VIR_STRDUP(user, username) < 0)
- goto error;
+ user = g_strdup(username);
if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
goto error;
virObjectLock(sess);
- if (VIR_STRDUP(user, username) < 0 ||
- VIR_STRDUP(file, keyfile) < 0 ||
- VIR_STRDUP(pass, password) < 0)
- goto error;
+ user = g_strdup(username);
+ file = g_strdup(keyfile);
+ pass = g_strdup(password);
if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
goto error;
virObjectLock(sess);
- if (VIR_STRDUP(user, username) < 0)
- goto error;
+ user = g_strdup(username);
if (!(auth = virNetSSHSessionAuthMethodNew(sess)))
goto error;
VIR_FREE(sess->channelCommand);
- if (VIR_STRDUP(sess->channelCommand, command) < 0)
- ret = -1;
+ sess->channelCommand = g_strdup(command);
virObjectUnlock(sess);
return ret;
VIR_FREE(sess->hostname);
- if (VIR_STRDUP(sess->hostname, hostname) < 0)
- goto error;
+ sess->hostname = g_strdup(hostname);
/* load the known hosts file */
if (hostsfile) {
/* set filename only if writing to the known hosts file is requested */
if (!(flags & VIR_NET_SSH_HOSTKEY_FILE_READONLY)) {
VIR_FREE(sess->knownHostsFile);
- if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
- goto error;
+ sess->knownHostsFile = g_strdup(hostsfile);
}
}
if (!(ctxt = virObjectLockableNew(virNetTLSContextClass)))
return NULL;
- if (VIR_STRDUP(ctxt->priority, priority) < 0)
- goto error;
+ ctxt->priority = g_strdup(priority);
err = gnutls_certificate_allocate_credentials(&ctxt->x509cred);
if (err) {
*/
if (!*cacert) {
VIR_DEBUG("Using default TLS CA certificate path");
- if (VIR_STRDUP(*cacert, LIBVIRT_CACERT) < 0)
- goto error;
+ *cacert = g_strdup(LIBVIRT_CACERT);
}
if (!*cacrl) {
VIR_DEBUG("Using default TLS CA revocation list path");
- if (VIR_STRDUP(*cacrl, LIBVIRT_CACRL) < 0)
- goto error;
+ *cacrl = g_strdup(LIBVIRT_CACRL);
}
if (!*key && !*cert) {
VIR_DEBUG("Using default TLS key/certificate path");
- if (VIR_STRDUP(*key, isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY) < 0)
- goto error;
+ *key = g_strdup(isServer ? LIBVIRT_SERVERKEY : LIBVIRT_CLIENTKEY);
- if (VIR_STRDUP(*cert, isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT) < 0)
- goto error;
+ *cert = g_strdup(isServer ? LIBVIRT_SERVERCERT : LIBVIRT_CLIENTCERT);
}
VIR_FREE(user_pki_path);
"[session]", gnutls_strerror(ret));
goto authfail;
}
- if (VIR_STRDUP(sess->x509dname, dname) < 0)
- goto authfail;
+ sess->x509dname = g_strdup(dname);
VIR_DEBUG("Peer DN is %s", dname);
if (virNetTLSContextCheckCertDN(cert, "[session]", sess->hostname, dname,
if (!(sess = virObjectLockableNew(virNetTLSSessionClass)))
return NULL;
- if (VIR_STRDUP(sess->hostname, hostname) < 0)
- goto error;
+ sess->hostname = g_strdup(hostname);
if ((err = gnutls_init(&sess->session,
ctxt->isServer ? GNUTLS_SERVER : GNUTLS_CLIENT)) != 0) {