--name=virNetServerProgramFree \
--name=virNetServerServiceFree \
--name=virNetSocketFree \
- --name=virNetSASLContextFree \
- --name=virNetSASLSessionFree \
--name=virNWFilterDefFree \
--name=virNWFilterEntryFree \
--name=virNWFilterHashTableFree \
PROBE(RPC_SERVER_CLIENT_AUTH_FAIL,
"client=%p auth=%d",
client, REMOTE_AUTH_SASL);
- virNetSASLSessionFree(sasl);
+ virObjectUnref(sasl);
virMutexUnlock(&priv->lock);
return -1;
}
"client=%p auth=%d identity=%s",
client, REMOTE_AUTH_SASL, identity);
- virNetSASLSessionFree(priv->sasl);
+ virObjectUnref(priv->sasl);
priv->sasl = NULL;
return 0;
goto error;
error:
- virNetSASLSessionFree(priv->sasl);
+ virObjectUnref(priv->sasl);
priv->sasl = NULL;
virResetLastError();
virReportError(VIR_ERR_AUTH_FAILED, "%s",
goto error;
error:
- virNetSASLSessionFree(priv->sasl);
+ virObjectUnref(priv->sasl);
priv->sasl = NULL;
virResetLastError();
virReportError(VIR_ERR_AUTH_FAILED, "%s",
# virnetsaslcontext.h
-virNetSASLContextCheckIdentity;
-virNetSASLContextFree;
virNetSASLContextNewClient;
-virNetSASLContextNewServer;
-virNetSASLContextRef;
virNetSASLSessionClientStart;
virNetSASLSessionClientStep;
virNetSASLSessionDecode;
virNetSASLSessionEncode;
-virNetSASLSessionExtKeySize;
-virNetSASLSessionFree;
-virNetSASLSessionGetIdentity;
-virNetSASLSessionGetKeySize;
virNetSASLSessionGetMaxBufSize;
-virNetSASLSessionListMechanisms;
virNetSASLSessionNewClient;
-virNetSASLSessionNewServer;
-virNetSASLSessionRef;
-virNetSASLSessionSecProps;
-virNetSASLSessionServerStart;
-virNetSASLSessionServerStep;
# virnetserver.h
virNetServerClientSetDispatcher;
virNetServerClientSetIdentity;
virNetServerClientSetPrivateData;
-virNetServerClientSetSASLSession;
virNetServerClientStartKeepAlive;
virNetServerClientWantClose;
virNetSASLContextCheckIdentity;
virNetSASLContextNewServer;
virNetSASLSessionExtKeySize;
-virNetSASLSessionFree;
virNetSASLSessionGetIdentity;
virNetSASLSessionGetKeySize;
virNetSASLSessionListMechanisms;
remoteAuthInteractStateClear(&state, true);
VIR_FREE(saslcb);
- virNetSASLSessionFree(sasl);
- virNetSASLContextFree(saslCtxt);
+ virObjectUnref(sasl);
+ virObjectUnref(saslCtxt);
return ret;
}
virNetSocketFree(client->sock);
virObjectUnref(client->tls);
#if HAVE_SASL
- virNetSASLSessionFree(client->sasl);
+ virObjectUnref(client->sasl);
#endif
virNetMessageClear(&client->msg);
virObjectUnref(client->tls);
client->tls = NULL;
#if HAVE_SASL
- virNetSASLSessionFree(client->sasl);
+ virObjectUnref(client->sasl);
client->sasl = NULL;
#endif
ka = client->keepalive;
virNetSASLSessionPtr sasl)
{
virNetClientLock(client);
- client->sasl = sasl;
- virNetSASLSessionRef(sasl);
+ client->sasl = virObjectRef(sasl);
virNetSocketSetSASLSession(client->sock, client->sasl);
virNetClientUnlock(client);
}
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetSASLContext {
+ virObject object;
+
virMutex lock;
const char *const*usernameWhitelist;
- int refs;
};
struct _virNetSASLSession {
+ virObject object;
+
virMutex lock;
sasl_conn_t *conn;
- int refs;
size_t maxbufsize;
};
+static virClassPtr virNetSASLContextClass;
+static virClassPtr virNetSASLSessionClass;
+static void virNetSASLContextDispose(void *obj);
+static void virNetSASLSessionDispose(void *obj);
+
+static int virNetSASLContextOnceInit(void)
+{
+ if (!(virNetSASLContextClass = virClassNew("virNetSASLContext",
+ sizeof(virNetSASLContext),
+ virNetSASLContextDispose)))
+ return -1;
+
+ if (!(virNetSASLSessionClass = virClassNew("virNetSASLSession",
+ sizeof(virNetSASLSession),
+ virNetSASLSessionDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virNetSASLContext)
+
+
virNetSASLContextPtr virNetSASLContextNewClient(void)
{
virNetSASLContextPtr ctxt;
int err;
+ if (virNetSASLContextInitialize() < 0)
+ return NULL;
+
err = sasl_client_init(NULL);
if (err != SASL_OK) {
virReportError(VIR_ERR_AUTH_FAILED,
return NULL;
}
- if (VIR_ALLOC(ctxt) < 0) {
- virReportOOMError();
+ if (!(ctxt = virObjectNew(virNetSASLContextClass)))
return NULL;
- }
if (virMutexInit(&ctxt->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
- ctxt->refs = 1;
-
return ctxt;
}
virNetSASLContextPtr ctxt;
int err;
+ if (virNetSASLContextInitialize() < 0)
+ return NULL;
+
err = sasl_server_init(NULL, "libvirt");
if (err != SASL_OK) {
virReportError(VIR_ERR_AUTH_FAILED,
return NULL;
}
- if (VIR_ALLOC(ctxt) < 0) {
- virReportOOMError();
+ if (!(ctxt = virObjectNew(virNetSASLContextClass)))
return NULL;
- }
if (virMutexInit(&ctxt->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
}
ctxt->usernameWhitelist = usernameWhitelist;
- ctxt->refs = 1;
return ctxt;
}
}
-void virNetSASLContextRef(virNetSASLContextPtr ctxt)
-{
- virMutexLock(&ctxt->lock);
- ctxt->refs++;
- virMutexUnlock(&ctxt->lock);
-}
-
-void virNetSASLContextFree(virNetSASLContextPtr ctxt)
+void virNetSASLContextDispose(void *obj)
{
- if (!ctxt)
- return;
-
- virMutexLock(&ctxt->lock);
- ctxt->refs--;
- if (ctxt->refs > 0) {
- virMutexUnlock(&ctxt->lock);
- return;
- }
+ virNetSASLContextPtr ctxt = obj;
- virMutexUnlock(&ctxt->lock);
virMutexDestroy(&ctxt->lock);
- VIR_FREE(ctxt);
}
virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIBUTE_UNUSED,
virNetSASLSessionPtr sasl = NULL;
int err;
- if (VIR_ALLOC(sasl) < 0) {
- virReportOOMError();
- goto cleanup;
- }
+ if (!(sasl = virObjectNew(virNetSASLSessionClass)))
+ return NULL;
if (virMutexInit(&sasl->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
- sasl->refs = 1;
/* Arbitrary size for amount of data we can encode in a single block */
sasl->maxbufsize = 1 << 16;
return sasl;
cleanup:
- virNetSASLSessionFree(sasl);
+ virObjectUnref(sasl);
return NULL;
}
virNetSASLSessionPtr sasl = NULL;
int err;
- if (VIR_ALLOC(sasl) < 0) {
- virReportOOMError();
- goto cleanup;
- }
+ if (!(sasl = virObjectNew(virNetSASLSessionClass)))
+ return NULL;
if (virMutexInit(&sasl->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
- sasl->refs = 1;
/* Arbitrary size for amount of data we can encode in a single block */
sasl->maxbufsize = 1 << 16;
return sasl;
cleanup:
- virNetSASLSessionFree(sasl);
+ virObjectUnref(sasl);
return NULL;
}
-void virNetSASLSessionRef(virNetSASLSessionPtr sasl)
-{
- virMutexLock(&sasl->lock);
- sasl->refs++;
- virMutexUnlock(&sasl->lock);
-}
-
int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
int ssf)
{
return ret;
}
-void virNetSASLSessionFree(virNetSASLSessionPtr sasl)
+void virNetSASLSessionDispose(void *obj)
{
- if (!sasl)
- return;
-
- virMutexLock(&sasl->lock);
- sasl->refs--;
- if (sasl->refs > 0) {
- virMutexUnlock(&sasl->lock);
- return;
- }
+ virNetSASLSessionPtr sasl = obj;
if (sasl->conn)
sasl_dispose(&sasl->conn);
- virMutexUnlock(&sasl->lock);
virMutexDestroy(&sasl->lock);
- VIR_FREE(sasl);
}
# include <sasl/sasl.h>
# include "internal.h"
+# include "virobject.h"
typedef struct _virNetSASLContext virNetSASLContext;
typedef virNetSASLContext *virNetSASLContextPtr;
int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
const char *identity);
-void virNetSASLContextRef(virNetSASLContextPtr sasl);
-void virNetSASLContextFree(virNetSASLContextPtr sasl);
-
virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt,
const char *service,
const char *hostname,
char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl);
-void virNetSASLSessionRef(virNetSASLSessionPtr sasl);
-
int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
int ssf);
const char **output,
size_t *outputlen);
-void virNetSASLSessionFree(virNetSASLSessionPtr sasl);
-
#endif /* __VIR_NET_CLIENT_SASL_CONTEXT_H__ */
* operation do we switch to SASL mode
*/
virNetServerClientLock(client);
- client->sasl = sasl;
- virNetSASLSessionRef(sasl);
+ client->sasl = virObjectRef(sasl);
virNetServerClientUnlock(client);
}
#endif
VIR_FREE(client->identity);
#if HAVE_SASL
- virNetSASLSessionFree(client->sasl);
+ virObjectUnref(client->sasl);
#endif
if (client->sockTimer > 0)
virEventRemoveTimeout(client->sockTimer);
*/
if (client->sasl) {
virNetSocketSetSASLSession(client->sock, client->sasl);
- virNetSASLSessionFree(client->sasl);
+ virObjectUnref(client->sasl);
client->sasl = NULL;
}
#endif
virNetTLSSessionSetIOCallbacks(sock->tlsSession, NULL, NULL, NULL);
virObjectUnref(sock->tlsSession);
#if HAVE_SASL
- virNetSASLSessionFree(sock->saslSession);
+ virObjectUnref(sock->saslSession);
#endif
VIR_FORCE_CLOSE(sock->fd);
virNetSASLSessionPtr sess)
{
virMutexLock(&sock->lock);
- virNetSASLSessionFree(sock->saslSession);
- sock->saslSession = sess;
- virNetSASLSessionRef(sess);
+ virObjectUnref(sock->saslSession);
+ sock->saslSession = virObjectRef(sess);
virMutexUnlock(&sock->lock);
}
#endif