+Tue Mar 11 10:45:53 EDT 2008 Daniel P. Berrange <berrange@redhat.com>
+
+ * src/libvirt.c, configure.in: Remove use of polkit-grant since
+ it is fundamentally broken. Only use polkit-auth instead. Keep
+ stdin/out/err open when running polkit-auth.
+
Tue Mar 11 10:21:53 EDT 2008 Daniel P. Berrange <berrange@redhat.com>
* src/virsh.c: Don't force connection to readonly as non-root
CFLAGS="$old_CFLAGS"
LDFLAGS="$old_LDFLAGS"
- AC_PATH_PROG(POLKIT_GRANT, polkit-grant)
- if test "x$POLKIT_GRANT" != "x"; then
- AC_DEFINE_UNQUOTED([POLKIT_GRANT],["$POLKIT_GRANT"],[Location of polkit-grant program])
- fi
AC_PATH_PROG(POLKIT_AUTH, polkit-auth)
if test "x$POLKIT_AUTH" != "x"; then
AC_DEFINE_UNQUOTED([POLKIT_AUTH],["$POLKIT_AUTH"],[Location of polkit-auth program])
#include <sys/stat.h>
#include <unistd.h>
#include <assert.h>
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
#include <libxml/parser.h>
#include <libxml/xpath.h>
int debugFlag = 0;
#endif
+#if defined(POLKIT_AUTH)
+static int virConnectAuthGainPolkit(const char *privilege) {
+ const char *const args[] = {
+ POLKIT_AUTH, "--obtain", privilege, NULL
+ };
+ int childpid, status, ret;
+
+ /* Root has all rights */
+ if (getuid() == 0)
+ return 0;
+
+ if ((childpid = fork()) < 0)
+ return -1;
+
+ if (!childpid) {
+ execvp(args[0], (char **)args);
+ _exit(-1);
+ }
+
+ while ((ret = waitpid(childpid, &status, 0) == -1) && errno == EINTR);
+ if (ret == -1) {
+ return -1;
+ }
+
+ if (!WIFEXITED(status) ||
+ (WEXITSTATUS(status) != 0 && WEXITSTATUS(status) != 1)) {
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
unsigned int ncred,
void *cbdata ATTRIBUTE_UNUSED) {
size_t len;
switch (cred[i].type) {
-#if defined(POLKIT_GRANT) || defined(POLKIT_AUTH)
+#if defined(POLKIT_AUTH)
case VIR_CRED_EXTERNAL: {
int ret;
- const char *const args[] = {
-#if defined(POLKIT_GRANT)
- POLKIT_GRANT, "--gain", cred[i].prompt, NULL
-#else
- POLKIT_AUTH, "--obtain", cred[i].prompt, NULL
-#endif
- };
-
if (STRNEQ(cred[i].challenge, "PolicyKit"))
return -1;
- if (virRun(NULL, (char **) args, &ret) < 0)
- return -1;
- if (!WIFEXITED(ret) ||
- (WEXITSTATUS(ret) != 0 && WEXITSTATUS(ret) != 1))
+ if (virConnectAuthGainPolkit(cred[i].prompt) < 0)
return -1;
+
break;
}
#endif
VIR_CRED_REALM,
VIR_CRED_PASSPHRASE,
VIR_CRED_NOECHOPROMPT,
-#if defined(POLKIT_AUTH) || defined(POLKIT_GRANT)
+#if defined(POLKIT_AUTH)
VIR_CRED_EXTERNAL,
#endif
};