mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
rpc: convert methods using virIdentityPtr to auto free macros
Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
29ef351db6
commit
7c9a1dcba8
@ -759,13 +759,13 @@ int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
|
||||
static virIdentityPtr
|
||||
virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
||||
{
|
||||
char *username = NULL;
|
||||
char *groupname = NULL;
|
||||
char *seccontext = NULL;
|
||||
virIdentityPtr ret = NULL;
|
||||
g_autofree char *username = NULL;
|
||||
g_autofree char *groupname = NULL;
|
||||
g_autofree char *seccontext = NULL;
|
||||
g_autoptr(virIdentity) ret = NULL;
|
||||
|
||||
if (!(ret = virIdentityNew()))
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
if (client->sock && virNetSocketIsLocal(client->sock)) {
|
||||
gid_t gid;
|
||||
@ -775,59 +775,50 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
||||
if (virNetSocketGetUNIXIdentity(client->sock,
|
||||
&uid, &gid, &pid,
|
||||
×tamp) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
if (!(username = virGetUserName(uid)))
|
||||
goto error;
|
||||
return NULL;
|
||||
if (virIdentitySetUserName(ret, username) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
if (virIdentitySetUNIXUserID(ret, uid) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
if (!(groupname = virGetGroupName(gid)))
|
||||
goto error;
|
||||
return NULL;
|
||||
if (virIdentitySetGroupName(ret, groupname) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
if (virIdentitySetUNIXGroupID(ret, gid) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
if (virIdentitySetProcessID(ret, pid) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
if (virIdentitySetProcessTime(ret, timestamp) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if WITH_SASL
|
||||
if (client->sasl) {
|
||||
const char *identity = virNetSASLSessionGetIdentity(client->sasl);
|
||||
if (virIdentitySetSASLUserName(ret, identity) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (client->tls) {
|
||||
const char *identity = virNetTLSSessionGetX509DName(client->tls);
|
||||
if (virIdentitySetX509DName(ret, identity) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (client->sock &&
|
||||
virNetSocketGetSELinuxContext(client->sock, &seccontext) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
if (seccontext &&
|
||||
virIdentitySetSELinuxContext(ret, seccontext) < 0)
|
||||
goto error;
|
||||
return NULL;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(username);
|
||||
VIR_FREE(groupname);
|
||||
VIR_FREE(seccontext);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
virObjectUnref(ret);
|
||||
ret = NULL;
|
||||
goto cleanup;
|
||||
return g_steal_pointer(&ret);
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,13 +370,13 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
||||
virNetServerClientPtr client,
|
||||
virNetMessagePtr msg)
|
||||
{
|
||||
char *arg = NULL;
|
||||
char *ret = NULL;
|
||||
g_autofree char *arg = NULL;
|
||||
g_autofree char *ret = NULL;
|
||||
int rv = -1;
|
||||
virNetServerProgramProcPtr dispatcher;
|
||||
virNetMessageError rerr;
|
||||
size_t i;
|
||||
virIdentityPtr identity = NULL;
|
||||
g_autoptr(virIdentity) identity = NULL;
|
||||
|
||||
memset(&rerr, 0, sizeof(rerr));
|
||||
|
||||
@ -484,10 +484,7 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
||||
}
|
||||
|
||||
xdr_free(dispatcher->ret_filter, ret);
|
||||
VIR_FREE(arg);
|
||||
VIR_FREE(ret);
|
||||
|
||||
virObjectUnref(identity);
|
||||
/* Put reply on end of tx queue to send out */
|
||||
return virNetServerClientSendMessage(client, msg);
|
||||
|
||||
@ -496,10 +493,6 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
||||
* RPC error message we can send back to the client */
|
||||
rv = virNetServerProgramSendReplyError(prog, client, msg, &rerr, &msg->header);
|
||||
|
||||
VIR_FREE(arg);
|
||||
VIR_FREE(ret);
|
||||
virObjectUnref(identity);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
|
||||
int ret = -1;
|
||||
virNetSocketPtr sock = NULL;
|
||||
virNetServerClientPtr client = NULL;
|
||||
virIdentityPtr ident = NULL;
|
||||
g_autoptr(virIdentity) ident = NULL;
|
||||
const char *gotUsername = NULL;
|
||||
uid_t gotUserID;
|
||||
const char *gotGroupname = NULL;
|
||||
@ -141,7 +141,6 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
|
||||
if (client)
|
||||
virNetServerClientClose(client);
|
||||
virObjectUnref(client);
|
||||
virObjectUnref(ident);
|
||||
VIR_FORCE_CLOSE(sv[0]);
|
||||
VIR_FORCE_CLOSE(sv[1]);
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user