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;
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;
-
- cleanup:
- VIR_FREE(username);
- VIR_FREE(groupname);
- VIR_FREE(seccontext);
- return ret;
+ return NULL;
- error:
- virObjectUnref(ret);
- ret = NULL;
- goto cleanup;
+ return g_steal_pointer(&ret);
}
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));
}
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);
* 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;
}
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;
if (client)
virNetServerClientClose(client);
virObjectUnref(client);
- virObjectUnref(ident);
VIR_FORCE_CLOSE(sv[0]);
VIR_FORCE_CLOSE(sv[1]);
return ret;