mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
Ensure system identity includes process start time
The polkit access driver will want to use the process start time field. This was already set for network identities, but not for the system identity. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
db7a5688c0
commit
e65667c0c6
@ -35,6 +35,7 @@
|
|||||||
#include "virthread.h"
|
#include "virthread.h"
|
||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
#include "virprocess.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_IDENTITY
|
#define VIR_FROM_THIS VIR_FROM_IDENTITY
|
||||||
|
|
||||||
@ -142,11 +143,20 @@ virIdentityPtr virIdentityGetSystem(void)
|
|||||||
security_context_t con;
|
security_context_t con;
|
||||||
#endif
|
#endif
|
||||||
char *processid = NULL;
|
char *processid = NULL;
|
||||||
|
unsigned long long timestamp;
|
||||||
|
char *processtime = NULL;
|
||||||
|
|
||||||
if (virAsprintf(&processid, "%llu",
|
if (virAsprintf(&processid, "%llu",
|
||||||
(unsigned long long)getpid()) < 0)
|
(unsigned long long)getpid()) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virProcessGetStartTime(getpid(), ×tamp) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (timestamp != 0 &&
|
||||||
|
virAsprintf(&processtime, "%llu", timestamp) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(username = virGetUserName(getuid())))
|
if (!(username = virGetUserName(getuid())))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virAsprintf(&userid, "%d", (int)getuid()) < 0)
|
if (virAsprintf(&userid, "%d", (int)getuid()) < 0)
|
||||||
@ -198,6 +208,11 @@ virIdentityPtr virIdentityGetSystem(void)
|
|||||||
VIR_IDENTITY_ATTR_UNIX_PROCESS_ID,
|
VIR_IDENTITY_ATTR_UNIX_PROCESS_ID,
|
||||||
processid) < 0)
|
processid) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
if (processtime &&
|
||||||
|
virIdentitySetAttr(ret,
|
||||||
|
VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME,
|
||||||
|
processtime) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(username);
|
VIR_FREE(username);
|
||||||
@ -206,6 +221,7 @@ cleanup:
|
|||||||
VIR_FREE(groupid);
|
VIR_FREE(groupid);
|
||||||
VIR_FREE(seccontext);
|
VIR_FREE(seccontext);
|
||||||
VIR_FREE(processid);
|
VIR_FREE(processid);
|
||||||
|
VIR_FREE(processtime);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user