From nobody Sun May 5 12:37:45 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554219479167697.9541365999694; Tue, 2 Apr 2019 08:37:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9176681231; Tue, 2 Apr 2019 15:37:56 +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 9ACE31092000; Tue, 2 Apr 2019 15:37:55 +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 4A58F1803389; Tue, 2 Apr 2019 15:37:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x32Fbm1C009968 for ; Tue, 2 Apr 2019 11:37:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0D0C608BE; Tue, 2 Apr 2019 15:37:48 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2292F608C4; Tue, 2 Apr 2019 15:37:42 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 2 Apr 2019 17:37:40 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH] rpc: Refactor cleanup paths in virNetLibsshAuthenticatePassword 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-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 02 Apr 2019 15:37:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that the memory disposal is handled automatically we can simplify the cleanup paths. In this case it's not as simple as sometimes the value of the called function is returned. While at it fix the initialization value of the returned variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetlibsshsession.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index b9143239b9..9bf25c9caa 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -606,25 +606,22 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionP= tr sess, virNetLibsshAuthMethodPtr priv) { const char *errmsg; - int ret =3D -1; + int rc =3D SSH_AUTH_ERROR; VIR_DEBUG("sess=3D%p", sess); if (priv->password) { /* tunelled password authentication */ - if ((ret =3D ssh_userauth_password(sess->session, NULL, - priv->password)) =3D=3D 0) { - ret =3D SSH_AUTH_SUCCESS; - goto cleanup; - } + if ((rc =3D ssh_userauth_password(sess->session, NULL, + priv->password)) =3D=3D 0) + return SSH_AUTH_SUCCESS; } else { /* password authentication with interactive password request */ if (!sess->cred || !sess->cred->cb) { virReportError(VIR_ERR_LIBSSH, "%s", _("Can't perform authentication: " "Authentication callback not provided")); - ret =3D SSH_AUTH_ERROR; - goto cleanup; + return SSH_AUTH_ERROR; } /* Try the authenticating the set amount of times. The server brea= ks the @@ -634,19 +631,15 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionP= tr sess, if (!(password =3D virAuthGetPasswordPath(sess->authPath, sess= ->cred, "ssh", sess->username, - sess->hostname))) { - ret =3D SSH_AUTH_ERROR; - goto cleanup; - } + sess->hostname))) + return SSH_AUTH_ERROR; /* tunelled password authentication */ - if ((ret =3D ssh_userauth_password(sess->session, NULL, - password)) =3D=3D 0) { - ret =3D SSH_AUTH_SUCCESS; - goto cleanup; - } + if ((rc =3D ssh_userauth_password(sess->session, NULL, + password)) =3D=3D 0) + return SSH_AUTH_SUCCESS; - if (ret !=3D SSH_AUTH_DENIED) + if (rc !=3D SSH_AUTH_DENIED) break; } } @@ -655,9 +648,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr= sess, errmsg =3D ssh_get_error(sess->session); virReportError(VIR_ERR_AUTH_FAILED, _("authentication failed: %s"), errmsg); - - cleanup: - return ret; + return rc; } /* perform keyboard interactive authentication --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list