static int virStateDriverTabCount = 0;
static int initialized = 0;
-/* If configured with --enable-debug=yes then library calls
- * are printed to stderr for debugging.
- */
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
+
#ifdef ENABLE_DEBUG
-#define DEBUG(fs,...) \
- fprintf (stderr, "libvirt: %s (" fs ")\n", __func__, __VA_ARGS__)
-#define DEBUG0 \
- fprintf (stderr, "libvirt: %s ()\n", __func__)
-#else
-#define DEBUG0
-#define DEBUG(fs,...)
-#endif /* !ENABLE_DEBUG */
+int debugFlag = 0;
+#endif
static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
unsigned int ncred,
int
virInitialize(void)
{
- DEBUG0;
+#ifdef ENABLE_DEBUG
+ char *debugEnv;
+#endif
if (initialized)
return(0);
initialized = 1;
+#ifdef ENABLE_DEBUG
+ debugEnv = getenv("LIBVIRT_DEBUG");
+ if (debugEnv && *debugEnv && *debugEnv != '0')
+ debugFlag = 1;
+#endif
+
+ DEBUG0("register drivers");
+
#if HAVE_WINSOCK2_H
if (winsock_init () == -1) return -1;
#endif
goto failed;
}
-#ifdef ENABLE_DEBUG
- fprintf (stderr,
- "libvirt: do_open: name \"%s\" to URI components:\n"
- " scheme %s\n"
- " opaque %s\n"
- " authority %s\n"
- " server %s\n"
- " user %s\n"
- " port %d\n"
- " path %s\n",
- name,
- uri->scheme, uri->opaque, uri->authority, uri->server,
- uri->user, uri->port, uri->path);
-#endif
+ DEBUG("name \"%s\" to URI components:\n"
+ " scheme %s\n"
+ " opaque %s\n"
+ " authority %s\n"
+ " server %s\n"
+ " user %s\n"
+ " port %d\n"
+ " path %s\n",
+ name,
+ uri->scheme, uri->opaque, uri->authority, uri->server,
+ uri->user, uri->port, uri->path);
ret->name = strdup (name);
if (!ret->name) {
}
for (i = 0; i < virDriverTabCount; i++) {
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: trying driver %d (%s) ...\n",
- i, virDriverTab[i]->name);
-#endif
+ DEBUG("trying driver %d (%s) ...",
+ i, virDriverTab[i]->name);
res = virDriverTab[i]->open (ret, uri, auth, flags);
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: driver %d %s returned %s\n",
- i, virDriverTab[i]->name,
- res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
- (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
- (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
-#endif
+ DEBUG("driver %d %s returned %s",
+ i, virDriverTab[i]->name,
+ res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+ (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+ (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
if (res == VIR_DRV_OPEN_ERROR) goto failed;
else if (res == VIR_DRV_OPEN_SUCCESS) {
ret->driver = virDriverTab[i];
for (i = 0; i < virNetworkDriverTabCount; i++) {
res = virNetworkDriverTab[i]->open (ret, uri, auth, flags);
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "libvirt: do_open: network driver %d %s returned %s\n",
- i, virNetworkDriverTab[i]->name,
- res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
- (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
- (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
-#endif
+ DEBUG("network driver %d %s returned %s",
+ i, virNetworkDriverTab[i]->name,
+ res == VIR_DRV_OPEN_SUCCESS ? "SUCCESS" :
+ (res == VIR_DRV_OPEN_DECLINED ? "DECLINED" :
+ (res == VIR_DRV_OPEN_ERROR ? "ERROR" : "unknown status")));
if (res == VIR_DRV_OPEN_ERROR) {
if (STREQ(virNetworkDriverTab[i]->name, "remote")) {
virLibConnWarning (NULL, VIR_WAR_NO_NETWORK,
#include "remote_internal.h"
#include "remote_protocol.h"
+#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
+#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
+
/* Per-connection private data. */
#define MAGIC 999 /* private_data->magic if OK */
#define DEAD 998 /* private_data->magic if dead/closed */
return 0;
}
-#if HAVE_SASL || HAVE_POLKIT
-static void
-remoteDebug(struct private_data *priv, const char *msg,...)
-{
- va_list args;
- if (priv->debugLog == NULL)
- return;
-
- va_start(args, msg);
- vfprintf(priv->debugLog, msg, args);
- va_end(args);
- fprintf(priv->debugLog, "\n");
-}
-#endif /* HAVE_SASL */
-
-
/**
* remoteFindServerPath:
*
priv->debugLog = stdout;
else
priv->debugLog = stderr;
- }
-#ifdef ENABLE_DEBUG
- else
- fprintf (stderr,
- "remoteOpen: "
- "passing through variable '%s' ('%s') to remote end\n",
- var->name, var->value);
-#endif
+ } else
+ DEBUG("passing through variable '%s' ('%s') to remote end",
+ var->name, var->value);
}
#ifdef HAVE_XMLURI_QUERY_RAW
}
assert (name);
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "remoteOpen: proceeding with name = %s\n", name);
-#endif
+ DEBUG("proceeding with name = %s", name);
/* Connect to the remote service. */
switch (transport) {
return -1;
/* Set the trusted CA cert. */
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "loading CA file %s\n", LIBVIRT_CACERT);
-#endif
+ DEBUG("loading CA file %s", LIBVIRT_CACERT);
err =
gnutls_certificate_set_x509_trust_file (x509_cred, LIBVIRT_CACERT,
GNUTLS_X509_FMT_PEM);
}
/* Set the client certificate and private key. */
-#ifdef ENABLE_DEBUG
- fprintf (stderr, "loading client cert and key from files %s and %s\n",
- LIBVIRT_CLIENTCERT, LIBVIRT_CLIENTKEY);
-#endif
+ DEBUG("loading client cert and key from files %s and %s",
+ LIBVIRT_CLIENTCERT, LIBVIRT_CLIENTKEY);
err =
gnutls_certificate_set_x509_key_file (x509_cred,
LIBVIRT_CLIENTCERT,
/* Verify certificate. */
if (verify_certificate (conn, priv, session) == -1) {
- fprintf (stderr,
- "remote_internal: failed to verify peer's certificate\n");
- if (!no_verify) return NULL;
- }
+ DEBUG0("failed to verify peer's certificate");
+ if (!no_verify) return NULL;
+ }
/* At this point, the server is verifying _our_ certificate, IP address,
* etc. If we make the grade, it will send us a '\1' byte.
int ret = -1;
const char *mechlist;
- remoteDebug(priv, "Client initialize SASL authentication");
+ DEBUG0("Client initialize SASL authentication");
/* Sets up the SASL library as a whole */
err = sasl_client_init(NULL);
if (err != SASL_OK) {
}
ssf *= 8; /* key size is bytes, sasl wants bits */
- remoteDebug(priv, "Setting external SSF %d", ssf);
+ DEBUG("Setting external SSF %d", ssf);
err = sasl_setprop(saslconn, SASL_SSF_EXTERNAL, &ssf);
if (err != SASL_OK) {
__virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
}
restart:
/* Start the auth negotiation on the client end first */
- remoteDebug(priv, "Client start negotiation mechlist '%s'", mechlist);
+ DEBUG("Client start negotiation mechlist '%s'", mechlist);
err = sasl_client_start(saslconn,
mechlist,
&interact,
sargs.data.data_val = (char*)clientout;
sargs.data.data_len = clientoutlen;
sargs.mech = (char*)mech;
- remoteDebug(priv, "Server start negotiation with mech %s. Data %d bytes %p", mech, clientoutlen, clientout);
+ DEBUG("Server start negotiation with mech %s. Data %d bytes %p", mech, clientoutlen, clientout);
/* Now send the initial auth data to the server */
memset (&sret, 0, sizeof sret);
/* NB, distinction of NULL vs "" is *critical* in SASL */
serverin = sret.nil ? NULL : sret.data.data_val;
serverinlen = sret.data.data_len;
- remoteDebug(priv, "Client step result complete: %d. Data %d bytes %p",
- complete, serverinlen, serverin);
+ DEBUG("Client step result complete: %d. Data %d bytes %p",
+ complete, serverinlen, serverin);
/* Loop-the-loop...
* Even if the server has completed, the client must *always* do at least one step
free(serverin);
serverin = NULL;
}
- remoteDebug(priv, "Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
+ DEBUG("Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
/* Previous server call showed completion & we're now locally complete too */
if (complete && err == SASL_OK)
pargs.nil = clientout ? 0 : 1;
pargs.data.data_val = (char*)clientout;
pargs.data.data_len = clientoutlen;
- remoteDebug(priv, "Server step with %d bytes %p", clientoutlen, clientout);
+ DEBUG("Server step with %d bytes %p", clientoutlen, clientout);
memset (&pret, 0, sizeof pret);
if (call (conn, priv, in_open, REMOTE_PROC_AUTH_SASL_STEP,
serverin = pret.nil ? NULL : pret.data.data_val;
serverinlen = pret.data.data_len;
- remoteDebug(priv, "Client step result complete: %d. Data %d bytes %p",
- complete, serverinlen, serverin);
+ DEBUG("Client step result complete: %d. Data %d bytes %p",
+ complete, serverinlen, serverin);
/* This server call shows complete, and earlier client step was OK */
if (complete && err == SASL_OK) {
goto cleanup;
}
ssf = *(const int *)val;
- remoteDebug(priv, "SASL SSF value %d", ssf);
+ DEBUG("SASL SSF value %d", ssf);
if (ssf < 56) { /* 56 == DES level, good for Kerberos */
__virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
}
}
- remoteDebug(priv, "SASL authentication complete");
+ DEBUG0("SASL authentication complete");
priv->saslconn = saslconn;
ret = 0;
NULL,
0,
};
- remoteDebug(priv, "Client initialize PolicyKit authentication");
+ DEBUG0("Client initialize PolicyKit authentication");
if (auth && auth->cb) {
/* Check if the neccessary credential type for PolicyKit is supported */
return -1;
}
} else {
- remoteDebug(priv, "Client auth callback does not support PolicyKit");
+ DEBUG0("Client auth callback does not support PolicyKit");
}
} else {
- remoteDebug(priv, "No auth callback provided");
+ DEBUG0("No auth callback provided");
}
memset (&ret, 0, sizeof ret);
return -1; /* virError already set by call */
}
- remoteDebug(priv, "PolicyKit authentication complete");
+ DEBUG0("PolicyKit authentication complete");
return 0;
}
#endif /* HAVE_POLKIT */