From 76122538b65a809795289a8c74d096e00d542ab3 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 2 Jan 2008 22:48:04 +0000 Subject: [PATCH] Fix crash when no auth callback is provided --- ChangeLog | 5 +++++ src/remote_internal.c | 32 +++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7130ca4b82..1127a513a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jan 2 17:45:53 EST 2008 Daniel P. Berrange + + * src/remote_internal.c: fix policykit auth handling of NULL + callbacks to not crash + Wed Dec 26 06:38:53 CET 2007 Daniel Veillard * src/openvz.c: patch from Mikhail Pokidko to fix the OpenVZ diff --git a/src/remote_internal.c b/src/remote_internal.c index 0c9ec0b34a..a184685982 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -2,7 +2,7 @@ * remote_internal.c: driver to provide access to libvirtd running * on a remote machine * - * Copyright (C) 2007 Red Hat, Inc. + * Copyright (C) 2007-2008 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -3347,24 +3347,26 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open, }; remoteDebug(priv, "Client initialize PolicyKit authentication"); - for (i = 0 ; i < auth->ncredtype ; i++) { - if (auth->credtype[i] == VIR_CRED_EXTERNAL) - allowcb = 1; - } + if (auth && auth->cb) { + /* Check if the neccessary credential type for PolicyKit is supported */ + for (i = 0 ; i < auth->ncredtype ; i++) { + if (auth->credtype[i] == VIR_CRED_EXTERNAL) + allowcb = 1; + } - /* Run the authentication callback */ - if (allowcb) { - if (auth && auth->cb && - (*(auth->cb))(&cred, 1, auth->cbdata) < 0) { - __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE, - VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, - "Failed to collect auth credentials"); - return -1; + if (allowcb) { + /* Run the authentication callback */ + if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { + __virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE, + VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, + "Failed to collect auth credentials"); + return -1; + } } else { - remoteDebug(priv, "No auth callback provided for PolicyKit"); + remoteDebug(priv, "Client auth callback does not support PolicyKit"); } } else { - remoteDebug(priv, "Client auth callback does not support PolicyKit"); + remoteDebug(priv, "No auth callback provided"); } memset (&ret, 0, sizeof ret); -- GitLab