mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
src: add API to determine if current identity is a system identity
This is essentially a way to determine if the current identity is that of another libvirt daemon. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
10689c16d8
commit
11f077e286
@ -2411,6 +2411,7 @@ virIdentityGetUNIXGroupID;
|
||||
virIdentityGetUNIXUserID;
|
||||
virIdentityGetUserName;
|
||||
virIdentityGetX509DName;
|
||||
virIdentityIsCurrentElevated;
|
||||
virIdentityNew;
|
||||
virIdentityNewCopy;
|
||||
virIdentityRestoreHelper;
|
||||
|
@ -366,6 +366,34 @@ virIdentity *virIdentityGetSystem(void)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virIdentityIsCurrentElevated:
|
||||
*
|
||||
* Determine if the current identity has elevated privileges.
|
||||
* This indicates that it was invoked on behalf of the
|
||||
* user by a libvirt daemon.
|
||||
*
|
||||
* Returns: true if elevated
|
||||
*/
|
||||
int virIdentityIsCurrentElevated(void)
|
||||
{
|
||||
g_autoptr(virIdentity) current = virIdentityGetCurrent();
|
||||
const char *currentToken = NULL;
|
||||
int rv;
|
||||
|
||||
if (!current) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("No current identity"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = virIdentityGetSystemToken(current, ¤tToken);
|
||||
if (rv <= 0)
|
||||
return rv;
|
||||
|
||||
return STREQ_NULLABLE(currentToken, systemToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* virIdentityNew:
|
||||
*
|
||||
|
@ -35,6 +35,7 @@ virIdentity *virIdentityElevateCurrent(void);
|
||||
|
||||
void virIdentityRestoreHelper(virIdentity **identptr);
|
||||
|
||||
int virIdentityIsCurrentElevated(void);
|
||||
virIdentity *virIdentityGetSystem(void);
|
||||
|
||||
virIdentity *virIdentityNew(void);
|
||||
|
Loading…
Reference in New Issue
Block a user