From nobody Sat Feb 7 18:51:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570704895; cv=none; d=zoho.com; s=zohoarc; b=fxUcQvT7u0RCP/d7u/Uh+lgCqNgqj8KveGGgz3gksc+XCfnQzesP47Y1ZDWmhlrq92FkJPcp6WKXsW/mgoz7JgmeE4k0uFHBQj38mRC1orMVSoJ6/SjxwQMhA+O4UkWth5tGB3iZo7tOSM9xU9bbQdiGcHzceo1hQegqGGEPUbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570704895; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l3ALoqWTionoMeRu0Pznj4aa9jD7QhfL9YU7XtypoKg=; b=XGHtDvXXu5A3au/W00xBpRqqfe5sxPlr8EoHSQN55rfAJ0H8wJOclRaOq0A2nsYxrKFO06QcYxt5un+UOHsJcKcCBapaBVTDCTqcwcQT1THG6vpz0QcAAW/hpyXMZ0Rw9v0/wwsARC3fM9nt8nktTWvbV0cY57thQMiLZfDMLxE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570704895776119.36810396679687; Thu, 10 Oct 2019 03:54:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9FA52D6A25; Thu, 10 Oct 2019 10:54:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF2E36017E; Thu, 10 Oct 2019 10:54:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 806D1180BAA7; Thu, 10 Oct 2019 10:54:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9AAsYIs010471 for ; Thu, 10 Oct 2019 06:54:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id C12C55C231; Thu, 10 Oct 2019 10:54:34 +0000 (UTC) Received: from dhcp-16-231.lcy.redhat.com (unknown [10.42.16.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0D7B5C22C; Thu, 10 Oct 2019 10:54:31 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 10 Oct 2019 11:54:07 +0100 Message-Id: <20191010105413.4091-14-berrange@redhat.com> In-Reply-To: <20191010105413.4091-1-berrange@redhat.com> References: <20191010105413.4091-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= Subject: [libvirt] [PATCH v3 13/19] rpc: convert methods using virIdentityPtr to auto free macros X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 10 Oct 2019 10:54:54 +0000 (UTC) Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetserverclient.c | 47 ++++++++++++++-------------------- src/rpc/virnetserverprogram.c | 13 +++------- tests/virnetserverclienttest.c | 3 +-- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 171ee636dd..79287572b6 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -759,13 +759,13 @@ int virNetServerClientGetUNIXIdentity(virNetServerCli= entPtr client, static virIdentityPtr virNetServerClientCreateIdentity(virNetServerClientPtr client) { - char *username =3D NULL; - char *groupname =3D NULL; - char *seccontext =3D NULL; - virIdentityPtr ret =3D NULL; + g_autofree char *username =3D NULL; + g_autofree char *groupname =3D NULL; + g_autofree char *seccontext =3D NULL; + g_autoptr(virIdentity) ret =3D NULL; =20 if (!(ret =3D virIdentityNew())) - goto error; + return NULL; =20 if (client->sock && virNetSocketIsLocal(client->sock)) { gid_t gid; @@ -775,59 +775,50 @@ virNetServerClientCreateIdentity(virNetServerClientPt= r client) if (virNetSocketGetUNIXIdentity(client->sock, &uid, &gid, &pid, ×tamp) < 0) - goto error; + return NULL; =20 if (!(username =3D virGetUserName(uid))) - goto error; + return NULL; if (virIdentitySetUserName(ret, username) < 0) - goto error; + return NULL; if (virIdentitySetUNIXUserID(ret, uid) < 0) - goto error; + return NULL; =20 if (!(groupname =3D virGetGroupName(gid))) - goto error; + return NULL; if (virIdentitySetGroupName(ret, groupname) < 0) - goto error; + return NULL; if (virIdentitySetUNIXGroupID(ret, gid) < 0) - goto error; + return NULL; =20 if (virIdentitySetProcessID(ret, pid) < 0) - goto error; + return NULL; if (virIdentitySetProcessTime(ret, timestamp) < 0) - goto error; + return NULL; } =20 #if WITH_SASL if (client->sasl) { const char *identity =3D virNetSASLSessionGetIdentity(client->sasl= ); if (virIdentitySetSASLUserName(ret, identity) < 0) - goto error; + return NULL; } #endif =20 if (client->tls) { const char *identity =3D virNetTLSSessionGetX509DName(client->tls); if (virIdentitySetX509DName(ret, identity) < 0) - goto error; + return NULL; } =20 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; =20 - error: - virObjectUnref(ret); - ret =3D NULL; - goto cleanup; + return g_steal_pointer(&ret); } =20 =20 diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 7ae1d2e955..cca820ca5a 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -370,13 +370,13 @@ virNetServerProgramDispatchCall(virNetServerProgramPt= r prog, virNetServerClientPtr client, virNetMessagePtr msg) { - char *arg =3D NULL; - char *ret =3D NULL; + g_autofree char *arg =3D NULL; + g_autofree char *ret =3D NULL; int rv =3D -1; virNetServerProgramProcPtr dispatcher; virNetMessageError rerr; size_t i; - virIdentityPtr identity =3D NULL; + g_autoptr(virIdentity) identity =3D NULL; =20 memset(&rerr, 0, sizeof(rerr)); =20 @@ -484,10 +484,7 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr= prog, } =20 xdr_free(dispatcher->ret_filter, ret); - VIR_FREE(arg); - VIR_FREE(ret); =20 - virObjectUnref(identity); /* Put reply on end of tx queue to send out */ return virNetServerClientSendMessage(client, msg); =20 @@ -496,10 +493,6 @@ virNetServerProgramDispatchCall(virNetServerProgramPtr= prog, * RPC error message we can send back to the client */ rv =3D virNetServerProgramSendReplyError(prog, client, msg, &rerr, &ms= g->header); =20 - VIR_FREE(arg); - VIR_FREE(ret); - virObjectUnref(identity); - return rv; } =20 diff --git a/tests/virnetserverclienttest.c b/tests/virnetserverclienttest.c index d094de9840..42393d7dbe 100644 --- a/tests/virnetserverclienttest.c +++ b/tests/virnetserverclienttest.c @@ -51,7 +51,7 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUS= ED) int ret =3D -1; virNetSocketPtr sock =3D NULL; virNetServerClientPtr client =3D NULL; - virIdentityPtr ident =3D NULL; + g_autoptr(virIdentity) ident =3D NULL; const char *gotUsername =3D NULL; uid_t gotUserID; const char *gotGroupname =3D NULL; @@ -141,7 +141,6 @@ static int testIdentity(const void *opaque ATTRIBUTE_UN= USED) if (client) virNetServerClientClose(client); virObjectUnref(client); - virObjectUnref(ident); VIR_FORCE_CLOSE(sv[0]); VIR_FORCE_CLOSE(sv[1]); return ret; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list