ERL_NIF_TERM vert_virSecretSetValue(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { VERT_RESOURCE *sp = NULL; ErlNifBinary value = {0}; u_int32_t flags = 0; VERT_GET_RESOURCE(0, sp, VERT_RES_SECRET); VERT_GET_IOLIST(1, value); VERT_GET_UINT(2, flags); VERTERR(virSecretSetValue(sp->res, value.data, value.size, flags) < 0); return atom_ok; }
static bool cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) { virSecretPtr secret; size_t value_size; const char *base64 = NULL; char *value; int res; bool ret = false; if (!(secret = virshCommandOptSecret(ctl, cmd, NULL))) return false; if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0) goto cleanup; if (!base64_decode_alloc(base64, strlen(base64), &value, &value_size)) { vshError(ctl, "%s", _("Invalid base64 data")); goto cleanup; } if (value == NULL) { vshError(ctl, "%s", _("Failed to allocate memory")); goto cleanup; } res = virSecretSetValue(secret, (unsigned char *)value, value_size, 0); memset(value, 0, value_size); VIR_FREE(value); if (res != 0) { vshError(ctl, "%s", _("Failed to set secret value")); goto cleanup; } vshPrintExtra(ctl, "%s", _("Secret value set\n")); ret = true; cleanup: virSecretFree(secret); return ret; }