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
|
static virIdentityPtr
|
||||||
virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
char *username = NULL;
|
g_autofree char *username = NULL;
|
||||||
char *groupname = NULL;
|
g_autofree char *groupname = NULL;
|
||||||
char *seccontext = NULL;
|
g_autofree char *seccontext = NULL;
|
||||||
virIdentityPtr ret = NULL;
|
g_autoptr(virIdentity) ret = NULL;
|
||||||
|
|
||||||
if (!(ret = virIdentityNew()))
|
if (!(ret = virIdentityNew()))
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (client->sock && virNetSocketIsLocal(client->sock)) {
|
if (client->sock && virNetSocketIsLocal(client->sock)) {
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
@ -775,59 +775,50 @@ virNetServerClientCreateIdentity(virNetServerClientPtr client)
|
|||||||
if (virNetSocketGetUNIXIdentity(client->sock,
|
if (virNetSocketGetUNIXIdentity(client->sock,
|
||||||
&uid, &gid, &pid,
|
&uid, &gid, &pid,
|
||||||
×tamp) < 0)
|
×tamp) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (!(username = virGetUserName(uid)))
|
if (!(username = virGetUserName(uid)))
|
||||||
goto error;
|
return NULL;
|
||||||
if (virIdentitySetUserName(ret, username) < 0)
|
if (virIdentitySetUserName(ret, username) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
if (virIdentitySetUNIXUserID(ret, uid) < 0)
|
if (virIdentitySetUNIXUserID(ret, uid) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (!(groupname = virGetGroupName(gid)))
|
if (!(groupname = virGetGroupName(gid)))
|
||||||
goto error;
|
return NULL;
|
||||||
if (virIdentitySetGroupName(ret, groupname) < 0)
|
if (virIdentitySetGroupName(ret, groupname) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
if (virIdentitySetUNIXGroupID(ret, gid) < 0)
|
if (virIdentitySetUNIXGroupID(ret, gid) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virIdentitySetProcessID(ret, pid) < 0)
|
if (virIdentitySetProcessID(ret, pid) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
if (virIdentitySetProcessTime(ret, timestamp) < 0)
|
if (virIdentitySetProcessTime(ret, timestamp) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_SASL
|
#if WITH_SASL
|
||||||
if (client->sasl) {
|
if (client->sasl) {
|
||||||
const char *identity = virNetSASLSessionGetIdentity(client->sasl);
|
const char *identity = virNetSASLSessionGetIdentity(client->sasl);
|
||||||
if (virIdentitySetSASLUserName(ret, identity) < 0)
|
if (virIdentitySetSASLUserName(ret, identity) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (client->tls) {
|
if (client->tls) {
|
||||||
const char *identity = virNetTLSSessionGetX509DName(client->tls);
|
const char *identity = virNetTLSSessionGetX509DName(client->tls);
|
||||||
if (virIdentitySetX509DName(ret, identity) < 0)
|
if (virIdentitySetX509DName(ret, identity) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->sock &&
|
if (client->sock &&
|
||||||
virNetSocketGetSELinuxContext(client->sock, &seccontext) < 0)
|
virNetSocketGetSELinuxContext(client->sock, &seccontext) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
if (seccontext &&
|
if (seccontext &&
|
||||||
virIdentitySetSELinuxContext(ret, seccontext) < 0)
|
virIdentitySetSELinuxContext(ret, seccontext) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
cleanup:
|
return g_steal_pointer(&ret);
|
||||||
VIR_FREE(username);
|
|
||||||
VIR_FREE(groupname);
|
|
||||||
VIR_FREE(seccontext);
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virObjectUnref(ret);
|
|
||||||
ret = NULL;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,13 +370,13 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
|||||||
virNetServerClientPtr client,
|
virNetServerClientPtr client,
|
||||||
virNetMessagePtr msg)
|
virNetMessagePtr msg)
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
g_autofree char *arg = NULL;
|
||||||
char *ret = NULL;
|
g_autofree char *ret = NULL;
|
||||||
int rv = -1;
|
int rv = -1;
|
||||||
virNetServerProgramProcPtr dispatcher;
|
virNetServerProgramProcPtr dispatcher;
|
||||||
virNetMessageError rerr;
|
virNetMessageError rerr;
|
||||||
size_t i;
|
size_t i;
|
||||||
virIdentityPtr identity = NULL;
|
g_autoptr(virIdentity) identity = NULL;
|
||||||
|
|
||||||
memset(&rerr, 0, sizeof(rerr));
|
memset(&rerr, 0, sizeof(rerr));
|
||||||
|
|
||||||
@ -484,10 +484,7 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
xdr_free(dispatcher->ret_filter, ret);
|
xdr_free(dispatcher->ret_filter, ret);
|
||||||
VIR_FREE(arg);
|
|
||||||
VIR_FREE(ret);
|
|
||||||
|
|
||||||
virObjectUnref(identity);
|
|
||||||
/* Put reply on end of tx queue to send out */
|
/* Put reply on end of tx queue to send out */
|
||||||
return virNetServerClientSendMessage(client, msg);
|
return virNetServerClientSendMessage(client, msg);
|
||||||
|
|
||||||
@ -496,10 +493,6 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr prog,
|
|||||||
* RPC error message we can send back to the client */
|
* RPC error message we can send back to the client */
|
||||||
rv = virNetServerProgramSendReplyError(prog, client, msg, &rerr, &msg->header);
|
rv = virNetServerProgramSendReplyError(prog, client, msg, &rerr, &msg->header);
|
||||||
|
|
||||||
VIR_FREE(arg);
|
|
||||||
VIR_FREE(ret);
|
|
||||||
virObjectUnref(identity);
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetSocketPtr sock = NULL;
|
virNetSocketPtr sock = NULL;
|
||||||
virNetServerClientPtr client = NULL;
|
virNetServerClientPtr client = NULL;
|
||||||
virIdentityPtr ident = NULL;
|
g_autoptr(virIdentity) ident = NULL;
|
||||||
const char *gotUsername = NULL;
|
const char *gotUsername = NULL;
|
||||||
uid_t gotUserID;
|
uid_t gotUserID;
|
||||||
const char *gotGroupname = NULL;
|
const char *gotGroupname = NULL;
|
||||||
@ -141,7 +141,6 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
|
|||||||
if (client)
|
if (client)
|
||||||
virNetServerClientClose(client);
|
virNetServerClientClose(client);
|
||||||
virObjectUnref(client);
|
virObjectUnref(client);
|
||||||
virObjectUnref(ident);
|
|
||||||
VIR_FORCE_CLOSE(sv[0]);
|
VIR_FORCE_CLOSE(sv[0]);
|
||||||
VIR_FORCE_CLOSE(sv[1]);
|
VIR_FORCE_CLOSE(sv[1]);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user