---
src/libvirt.c | 365 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 365 insertions(+), 0 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 22bc34c..4beb822 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8660,3 +8660,368 @@ error:
virSetConnError(conn);
return -1;
}
+
+/**
+ * virSecretAllocateID:
+ * @conn: virConnect connection
+ *
+ * Allocates a secret ID (a printable string) without associating a secret
+ * value with the ID.
+ *
+ * Returns the secret ID on success, or NULL on failure. The caller must
+ * free() the secret ID.
+ */
+char *
+virSecretAllocateID(virConnectPtr conn)
+{
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return NULL;
+ }
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->allocateID !=
NULL) {
+ char *ret;
+
+ ret = conn->secretDriver->allocateID(conn);
+ if (ret == NULL)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return NULL;
+}
+
+/**
+ * virSecretSetXML:
+ * @conn: virConnect connection
+ * @secret_id: A secret ID
+ * @xml: XML containing attributes of the secret.
+ *
+ * Replaces all attributes of the secret specified by secret_id by attributes
+ * specified in xml (any attributes not specified in xml are
+ * discarded). Allocates secret_id if it was not previously allocated.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int
+virSecretSetXML(virConnectPtr conn, const char *secret_id, const char *xml)
+{
+ VIR_DEBUG("conn=%p, secret_id=%s, xml=%s", conn, secret_id, xml);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ if (secret_id == NULL || xml == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->setXML !=
NULL) {
+ int ret;
+
+ ret = conn->secretDriver->setXML(conn, secret_id, xml);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return -1;
+}
+
+/**
+ * virSecretGetXML:
+ * @conn: virConnect connection
+ * @secret_id: A secret ID
+ *
+ * Fetches an XML document describing attributes of the secret.
+ *
+ * Returns the XML document on success, NULL on failure. The caller must
+ * free() the XML.
+ */
+char *
+virSecretGetXML(virConnectPtr conn, const char *secret_id)
+{
+ VIR_DEBUG("conn=%p, secret_id=%s", conn, secret_id);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return NULL;
+ }
+ if (secret_id == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->getXML !=
NULL) {
+ char *ret;
+
+ ret = conn->secretDriver->getXML(conn, secret_id);
+ if (ret == NULL)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return NULL;
+}
+
+/**
+ * virSecretSetValue:
+ * @conn: virConnect connection
+ * @secret_id: A secret ID
+ * @secret: The secret
+ * @secret_size: Size of the secret
+ *
+ * Associates a secret value with secret_id. Allocates secret_id if it was
+ * not previously allocated.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int
+virSecretSetValue(virConnectPtr conn, const char *secret_id, const void *secret,
+ size_t secret_size)
+{
+ VIR_DEBUG("conn=%p, secret_id=%s, secret=%p, secret_size=%zu", conn,
+ secret_id, secret, secret_size);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ if (secret_id == NULL || secret == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->setValue !=
NULL) {
+ int ret;
+
+ ret = conn->secretDriver->setValue(conn, secret_id, secret,
+ secret_size);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return -1;
+}
+
+/**
+ * virSecretGetValue:
+ * @conn: virConnect connection
+ * @secret_id: A secret ID
+ * @secret_size: Place for storing size of the secret
+ *
+ * Fetches the secret value associated with secret_id.
+ *
+ * Returns the secret value on success, NULL on failure. The caller must
+ * free() the secret value.
+ */
+void *
+virSecretGetValue(virConnectPtr conn, const char *secret_id,
+ size_t *secret_size)
+{
+ VIR_DEBUG("conn=%p, secret_id=%s, secret_size=%p", conn, secret_id,
+ secret_size);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return NULL;
+ }
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ if (secret_id == NULL || secret_size == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->getValue !=
NULL) {
+ void *ret;
+
+ ret = conn->secretDriver->getValue(conn, secret_id, secret_size, false);
+ if (ret == NULL)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return NULL;
+}
+
+/**
+ * virSecretDelete:
+ * @conn: virConnect connection
+ * @secret_id: A secret ID
+ *
+ * Deletes the secret with secret_id (including the secret value and all
+ * attributes).
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int
+virSecretDelete(virConnectPtr conn, const char *secret_id)
+{
+ VIR_DEBUG("conn=%p, secret_id=%s", conn, secret_id);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ if (secret_id == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->delete !=
NULL) {
+ int ret;
+
+ ret = conn->secretDriver->delete(conn, secret_id);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return -1;
+}
+
+/**
+ * virSecretNumOfSecrets:
+ * @conn: virConnect connection
+ *
+ * Fetch number of currently defined secret IDs.
+ *
+ * Returns the number currently defined secret IDs.
+ */
+int
+virSecretNumOfSecrets(virConnectPtr conn)
+{
+ VIR_DEBUG("conn=%p", conn);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+
+ if (conn->secretDriver != NULL &&
+ conn->secretDriver->numOfSecrets != NULL) {
+ int ret;
+
+ ret = conn->secretDriver->numOfSecrets(conn);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return -1;
+}
+
+/**
+ * virSecretListSecrets:
+ * @conn: virConnect connection
+ * @ids: Pointer to an array to store the IDs
+ * @maxids: size of the array.
+ *
+ * List the defined secret IDs, store pointers to names in ids.
+ *
+ * Returns the number of IDs provided in the array, or -1 on failure.
+ */
+int
+virSecretListSecrets(virConnectPtr conn, char **ids, int maxids)
+{
+ VIR_DEBUG("conn=%p, ids=%p, maxids=%d", conn, ids, maxids);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return -1;
+ }
+ if (ids == NULL || maxids < 0) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->secretDriver != NULL && conn->secretDriver->listSecrets !=
NULL) {
+ int ret;
+
+ ret = conn->secretDriver->listSecrets(conn, ids, maxids);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return -1;
+}
--
1.6.2.5