From nobody Wed May 14 01:31:14 2025 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15276276467581005.1565016838298; Tue, 29 May 2018 14:00:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F37AD3001ADE; Tue, 29 May 2018 21:00:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B56885B684; Tue, 29 May 2018 21:00:44 +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 572424CA81; Tue, 29 May 2018 21:00:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4TL0gaX023426 for ; Tue, 29 May 2018 17:00:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14FAF97394; Tue, 29 May 2018 21:00:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DBE290CFA for ; Tue, 29 May 2018 21:00:42 +0000 (UTC) Received: from mail-pl0-f43.google.com (mail-pl0-f43.google.com [209.85.160.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F113D2BCD87 for ; Tue, 29 May 2018 21:00:30 +0000 (UTC) Received: by mail-pl0-f43.google.com with SMTP id i5-v6so9662895plt.2 for ; Tue, 29 May 2018 14:00:30 -0700 (PDT) Received: from centos.localdomain ([49.32.89.162]) by smtp.gmail.com with ESMTPSA id v6-v6sm52176763pfm.120.2018.05.29.14.00.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 14:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=jj9MVbyMp2LEOSSEmNymApLsbpS0+jP9UH2ORhI7zUY=; b=ooBApOBLs4wI+VZNEHupav4KeK9LvMPhDY5gE8qDKv+nba8dsiTLABn1Rpl3O3pshe rVPxlXqOqiHblQ4i3E8BsoPkweqMcSSJ4qWvGMqmPOZIAmc5HJEOWi9T6ICVE2f2gt6m vX7LLGwY9FqOPKRIKX5XH/YPZYrH665EWb2EHBzz5jhBsgP/h8+ny65K0YHLPKk1pfgp LHP1o0gdrQ7SHcJMLzFSSqDxGQ5kJI/Q95dz4S0D64v6Hwb5jChGtd2jHFN8sdz2h3J9 O2EZCJMl7Fqa7fBLn9+9njkV+DVK42M1sN4QNK+6ovKMgDD1Jj60JdNKitcRaoqNxJab xBQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=jj9MVbyMp2LEOSSEmNymApLsbpS0+jP9UH2ORhI7zUY=; b=Cs+5L4MqaxJqBneZrDUZc6ok+OOn0WpLvDnvctAgQF8AMv5c/6JGq3AXSwf4uHFpXt kaLw3O7beikH96uNgh6IA3umUnppUmaVOpfziIlgap66pLL4i2mxVTF6HXPk7coG2d3y b2NKvLWPStTZa8ieui9a3jw3aTSezKPsGJIAb6j7kHYGADKAfavE52GLkffRnyhI/Stz /YCpkgpMhBFsdQi+cV0rzsqFqUz07dNCGmIERSp5AeMOHEYQo3k+w5stXKc007VVM+qn Lvfv+D+ANMb6/GFsja0ZOiF3DWMfEsw0xMGMkh3BUPjOV4U/nk/5rqKVXSV8ObFP4okX Er+Q== X-Gm-Message-State: ALKqPweq78vJ/fHknarzr6TJfDJvtQZDRuwmFgs4proSPbBwN/AGOE9a C8h+Alw82nuxxo8OxaOJErCPEL8o X-Google-Smtp-Source: ADUXVKJZ2BHr9CkkS9G9gfnhV/lf06H46yrtnTemNQn/LwlC8LrAhOby8mF6VkSxVoBuvs63gbjKiA== X-Received: by 2002:a17:902:4301:: with SMTP id i1-v6mr19375pld.280.1527627630259; Tue, 29 May 2018 14:00:30 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Wed, 30 May 2018 02:30:06 +0530 Message-Id: <1527627607-15698-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> References: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 29 May 2018 21:00:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 29 May 2018 21:00:31 +0000 (UTC) for IP:'209.85.160.43' DOMAIN:'mail-pl0-f43.google.com' HELO:'mail-pl0-f43.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.396 (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.160.43 mail-pl0-f43.google.com 209.85.160.43 mail-pl0-f43.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC 3/4] add automatic cleanup support in src/util/virauthconfig.c 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 29 May 2018 21:00:45 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modifiy code to use cleanup macros where required. Signed-off-by: Sukrit Bhatnagar --- src/util/virauthconfig.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 91c9c0c..66f7f7e 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -106,10 +106,9 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *credname, const char **value) { - char *authgroup =3D NULL; - char *credgroup =3D NULL; + VIR_AUTOFREE(char *) authgroup =3D NULL; + VIR_AUTOFREE(char *) credgroup =3D NULL; const char *authcred; - int ret =3D -1; =20 *value =3D NULL; =20 @@ -119,47 +118,38 @@ int virAuthConfigLookup(virAuthConfigPtr auth, hostname =3D "localhost"; =20 if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { VIR_FREE(authgroup); if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0) - goto cleanup; + return -1; } =20 - if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasGroup(auth->keyfile, authgroup)) + return 0; =20 if (!(authcred =3D virKeyFileGetValueString(auth->keyfile, authgroup, = "credentials"))) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing item 'credentials' in group '%s' in '%s'= "), authgroup, auth->path); - goto cleanup; + return -1; } =20 if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, credgroup)) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing group 'credentials-%s' referenced from g= roup '%s' in '%s'"), authcred, authgroup, auth->path); - goto cleanup; + return -1; } =20 - if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) + return 0; =20 *value =3D virKeyFileGetValueString(auth->keyfile, credgroup, credname= ); =20 - ret =3D 0; - - cleanup: - VIR_FREE(authgroup); - VIR_FREE(credgroup); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list