util: allow identity to be imported/exported as typed parameters

Add ability to import/export all the parameters associated with an
identity, so that they can be exposed via the public API.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-07-26 16:36:29 +01:00
parent b1aa312185
commit 4471003836
3 changed files with 66 additions and 0 deletions

View File

@ -2144,6 +2144,7 @@ virHostGetBootTime;
# util/viridentity.h # util/viridentity.h
virIdentityGetCurrent; virIdentityGetCurrent;
virIdentityGetGroupName; virIdentityGetGroupName;
virIdentityGetParameters;
virIdentityGetProcessID; virIdentityGetProcessID;
virIdentityGetProcessTime; virIdentityGetProcessTime;
virIdentityGetSASLUserName; virIdentityGetSASLUserName;
@ -2156,6 +2157,7 @@ virIdentityGetX509DName;
virIdentityNew; virIdentityNew;
virIdentitySetCurrent; virIdentitySetCurrent;
virIdentitySetGroupName; virIdentitySetGroupName;
virIdentitySetParameters;
virIdentitySetProcessID; virIdentitySetProcessID;
virIdentitySetProcessTime; virIdentitySetProcessTime;
virIdentitySetSASLUserName; virIdentitySetSASLUserName;

View File

@ -36,6 +36,7 @@
#include "virutil.h" #include "virutil.h"
#include "virstring.h" #include "virstring.h"
#include "virprocess.h" #include "virprocess.h"
#include "virtypedparam.h"
#define VIR_FROM_THIS VIR_FROM_IDENTITY #define VIR_FROM_THIS VIR_FROM_IDENTITY
@ -545,3 +546,58 @@ int virIdentitySetSELinuxContext(virIdentityPtr ident,
VIR_CONNECT_IDENTITY_SELINUX_CONTEXT, VIR_CONNECT_IDENTITY_SELINUX_CONTEXT,
context); context);
} }
int virIdentitySetParameters(virIdentityPtr ident,
virTypedParameterPtr params,
int nparams)
{
if (virTypedParamsValidate(params, nparams,
VIR_CONNECT_IDENTITY_USER_NAME,
VIR_TYPED_PARAM_STRING,
VIR_CONNECT_IDENTITY_UNIX_USER_ID,
VIR_TYPED_PARAM_ULLONG,
VIR_CONNECT_IDENTITY_GROUP_NAME,
VIR_TYPED_PARAM_STRING,
VIR_CONNECT_IDENTITY_UNIX_GROUP_ID,
VIR_TYPED_PARAM_ULLONG,
VIR_CONNECT_IDENTITY_PROCESS_ID,
VIR_TYPED_PARAM_LLONG,
VIR_CONNECT_IDENTITY_PROCESS_TIME,
VIR_TYPED_PARAM_ULLONG,
VIR_CONNECT_IDENTITY_SASL_USER_NAME,
VIR_TYPED_PARAM_STRING,
VIR_CONNECT_IDENTITY_X509_DISTINGUISHED_NAME,
VIR_TYPED_PARAM_STRING,
VIR_CONNECT_IDENTITY_SELINUX_CONTEXT,
VIR_TYPED_PARAM_STRING,
NULL) < 0)
return -1;
virTypedParamsFree(ident->params, ident->nparams);
ident->params = NULL;
ident->nparams = 0;
ident->maxparams = 0;
if (virTypedParamsCopy(&ident->params, params, nparams) < 0)
return -1;
ident->nparams = nparams;
ident->maxparams = nparams;
return 0;
}
int virIdentityGetParameters(virIdentityPtr ident,
virTypedParameterPtr *params,
int *nparams)
{
*params = NULL;
*nparams = 0;
if (virTypedParamsCopy(params, ident->params, ident->nparams) < 0)
return -1;
*nparams = ident->nparams;
return 0;
}

View File

@ -71,3 +71,11 @@ int virIdentitySetX509DName(virIdentityPtr ident,
const char *dname); const char *dname);
int virIdentitySetSELinuxContext(virIdentityPtr ident, int virIdentitySetSELinuxContext(virIdentityPtr ident,
const char *context); const char *context);
int virIdentitySetParameters(virIdentityPtr ident,
virTypedParameterPtr params,
int nparams);
int virIdentityGetParameters(virIdentityPtr ident,
virTypedParameterPtr *params,
int *nparams);