From nobody Wed May 14 01:21:07 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 1528124045200612.4429396399174; Mon, 4 Jun 2018 07:54:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94E1530C98ED; Mon, 4 Jun 2018 14:54:03 +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 25BDE608EF; Mon, 4 Jun 2018 14:54:03 +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 7A85C1800FD8; Mon, 4 Jun 2018 14:54:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w54EacOQ008060 for ; Mon, 4 Jun 2018 10:36:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3D73F2010D5D; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30CB02010D5C for ; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.52]) (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 A8B7729A69 for ; Mon, 4 Jun 2018 14:36:26 +0000 (UTC) Received: by mail-pg0-f52.google.com with SMTP id e11-v6so5341090pgq.0 for ; Mon, 04 Jun 2018 07:36:26 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:25 -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=DKEH/74fDCOTvqcXU0MzDZ5+tFtR/fBCECOLpwBuQP8=; b=RKFtEdwWzMtKNorffYWa8lysFYPNmiv1Ea283m6wyY8AdRfTqJcnmVTRF7EJTssOsf 9KqSYnGFxEcyIbMersUN+fvzD7LLpwIGwzJyCVguU3LZs/vjRrlexUIlVMsUmTTA9ycx o9h2Y8E+ExsiO4rkRJGuuMY28gpQvPLgvd193PrINJjedLfQSmxzTnIzc+6tIbWJ/vYW hjzAYWbCDwiiNb6Aq6HYT65nTJ2EPitnnX83c6Wb+KWUMYemAUIVWd3VhlehyOu7yFdI x9NES3HHqfkrCICFQnAdizdI29mZKXlpeO4CQrKfnzjxfcdGPtdRSPrX/PjPxvyiBA3e RFuA== 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=DKEH/74fDCOTvqcXU0MzDZ5+tFtR/fBCECOLpwBuQP8=; b=jSrdk3M9IJHt2o/JNTpyWAyEF4laxGs1Ut9uuV1Nm6OSGoWpKzT08FCc3qkBgW2Rkw NoKnfKKZKs9D77EB4bFyymGuL9yV8lckWVTPOezmqi16TpIa+TlfJR23y6P9zSyQa24w Yl0/Yd6+FdTMQvICpA2m4qA3qRGbYA0UfrNWa/1bPVohT9PntTglJvx0762etexEzQtt 1Z2UmXf9At5oHwP6Yqtc1V6awQJbnkaWvf42enJ/67TImLfI67fjoHb5vkNAWIG3dKl+ b4Gmz2oeEEL3XCnJJzmWMYR/c9xTnhqp4hctkVpgyalyR7kl4f8AT1fMqcYl7v4Mswqe wgpw== X-Gm-Message-State: ALKqPwcBGnW70X7IW3sa7NwblwFVrmBy1L9HdWysMThn9fy30J5p3R/G dkKE+bg8dUMMyIhHMWDH/u/YkZGv X-Google-Smtp-Source: ADUXVKILsESNd/iddcnr/KDz41cx+jEheRl83Ux1a6OjKLt+N2jsJ+YL4cs+vnHsQgHLU0s2JFi4Eg== X-Received: by 2002:a63:2dc2:: with SMTP id t185-v6mr17815917pgt.204.1528122985768; Mon, 04 Jun 2018 07:36:25 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:01 +0530 Message-Id: <1528013536-22196-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.28]); Mon, 04 Jun 2018 14:36:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 04 Jun 2018 14:36:26 +0000 (UTC) for IP:'74.125.83.52' DOMAIN:'mail-pg0-f52.google.com' HELO:'mail-pg0-f52.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.786 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 74.125.83.52 mail-pg0-f52.google.com 74.125.83.52 mail-pg0-f52.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 03/18] use VIR_AUTOFREE in src/util/virauth.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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 04 Jun 2018 14:54:04 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virauth.c | 60 +++++++++++++++++++-------------------------------= ---- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index adb093e..089a820 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -42,10 +42,9 @@ int virAuthGetConfigFilePathURI(virURIPtr uri, char **path) { - int ret =3D -1; size_t i; const char *authenv =3D virGetEnvBlockSUID("LIBVIRT_AUTH_FILE"); - char *userdir =3D NULL; + VIR_AUTOFREE(char *) userdir =3D NULL; =20 *path =3D NULL; =20 @@ -54,7 +53,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, if (authenv) { VIR_DEBUG("Using path from env '%s'", authenv); if (VIR_STRDUP(*path, authenv) < 0) - goto cleanup; + return -1; return 0; } =20 @@ -64,41 +63,38 @@ virAuthGetConfigFilePathURI(virURIPtr uri, uri->params[i].value) { VIR_DEBUG("Using path from URI '%s'", uri->params[i].value= ); if (VIR_STRDUP(*path, uri->params[i].value) < 0) - goto cleanup; + return -1; return 0; } } } =20 if (!(userdir =3D virGetUserConfigDirectory())) - goto cleanup; + return -1; =20 if (virAsprintf(path, "%s/auth.conf", userdir) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); - if (access(*path, R_OK) =3D=3D 0) - goto done; + if (access(*path, R_OK) =3D=3D 0) { + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); + return 0; + } =20 VIR_FREE(*path); =20 if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); - if (access(*path, R_OK) =3D=3D 0) - goto done; + if (access(*path, R_OK) =3D=3D 0) { + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); + return 0; + } =20 VIR_FREE(*path); =20 - done: - ret =3D 0; - - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); - cleanup: - VIR_FREE(userdir); - - return ret; + return 0; } =20 =20 @@ -156,7 +152,7 @@ virAuthGetUsernamePath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "username", path, &ret= ) < 0) @@ -193,8 +189,6 @@ virAuthGetUsernamePath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -206,18 +200,13 @@ virAuthGetUsername(virConnectPtr conn, const char *defaultUsername, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetUsernamePath(path, auth, servicename, + return virAuthGetUsernamePath(path, auth, servicename, defaultUsername, hostname); - - VIR_FREE(path); - - return ret; } =20 =20 @@ -230,7 +219,7 @@ virAuthGetPasswordPath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "password", path, &ret= ) < 0) @@ -264,8 +253,6 @@ virAuthGetPasswordPath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -277,15 +264,10 @@ virAuthGetPassword(virConnectPtr conn, const char *username, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetPasswordPath(path, auth, servicename, username, host= name); - - VIR_FREE(path); - - return ret; + return virAuthGetPasswordPath(path, auth, servicename, username, hostn= ame); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list