diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 02ac4e9352a033ee6c2d20871c10276d5862ce58..d648ed3982ed8c0af40697cfe03f594d93d40fe6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1401,11 +1401,29 @@ virHostdevUpdateDomainActiveDevices; # util/viridentity.h virIdentityGetAttr; virIdentityGetCurrent; +virIdentityGetSASLUserName; +virIdentityGetSELinuxContext; virIdentityGetSystem; +virIdentityGetUNIXGroupID; +virIdentityGetUNIXGroupName; +virIdentityGetUNIXProcessID; +virIdentityGetUNIXProcessTime; +virIdentityGetUNIXUserID; +virIdentityGetUNIXUserName; +virIdentityGetX509DName; virIdentityIsEqual; virIdentityNew; virIdentitySetAttr; virIdentitySetCurrent; +virIdentitySetSASLUserName; +virIdentitySetSELinuxContext; +virIdentitySetUNIXGroupID; +virIdentitySetUNIXGroupName; +virIdentitySetUNIXProcessID; +virIdentitySetUNIXProcessTime; +virIdentitySetUNIXUserID; +virIdentitySetUNIXUserName; +virIdentitySetX509DName; # util/virinitctl.h diff --git a/src/util/viridentity.c b/src/util/viridentity.c index a997385cf267879c977078db7dde953b92c42b03..68ccab9ace60772d2f14a8920f3bcb1b1aa1fc77 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -352,3 +352,244 @@ bool virIdentityIsEqual(virIdentityPtr identA, cleanup: return ret; } + + +int virIdentityGetUNIXUserName(virIdentityPtr ident, + const char **username) +{ + return virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_USER_NAME, + username); +} + + +int virIdentityGetUNIXUserID(virIdentityPtr ident, + uid_t *uid) +{ + int val; + const char *userid; + + *uid = -1; + if (virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_USER_ID, + &userid) < 0) + return -1; + + if (!userid) + return -1; + + if (virStrToLong_i(userid, NULL, 10, &val) < 0) + return -1; + + *uid = (uid_t)val; + + return 0; +} + +int virIdentityGetUNIXGroupName(virIdentityPtr ident, + const char **groupname) +{ + return virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_GROUP_NAME, + groupname); +} + + +int virIdentityGetUNIXGroupID(virIdentityPtr ident, + gid_t *gid) +{ + int val; + const char *groupid; + + *gid = -1; + if (virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_GROUP_ID, + &groupid) < 0) + return -1; + + if (!groupid) + return -1; + + if (virStrToLong_i(groupid, NULL, 10, &val) < 0) + return -1; + + *gid = (gid_t)val; + + return 0; +} + + +int virIdentityGetUNIXProcessID(virIdentityPtr ident, + pid_t *pid) +{ + unsigned long long val; + const char *processid; + + *pid = 0; + if (virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_PROCESS_ID, + &processid) < 0) + return -1; + + if (!processid) + return -1; + + if (virStrToLong_ull(processid, NULL, 10, &val) < 0) + return -1; + + *pid = (pid_t)val; + + return 0; +} + + +int virIdentityGetUNIXProcessTime(virIdentityPtr ident, + unsigned long long *timestamp) +{ + const char *processtime; + if (virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME, + &processtime) < 0) + return -1; + + if (!processtime) + return -1; + + if (virStrToLong_ull(processtime, NULL, 10, timestamp) < 0) + return -1; + + return 0; +} + + +int virIdentityGetSASLUserName(virIdentityPtr ident, + const char **username) +{ + return virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_SASL_USER_NAME, + username); +} + + +int virIdentityGetX509DName(virIdentityPtr ident, + const char **dname) +{ + return virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME, + dname); +} + + +int virIdentityGetSELinuxContext(virIdentityPtr ident, + const char **context) +{ + return virIdentityGetAttr(ident, + VIR_IDENTITY_ATTR_SELINUX_CONTEXT, + context); +} + + +int virIdentitySetUNIXUserName(virIdentityPtr ident, + const char *username) +{ + return virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_USER_NAME, + username); +} + + +int virIdentitySetUNIXUserID(virIdentityPtr ident, + uid_t uid) +{ + char *val; + int ret; + if (virAsprintf(&val, "%d", (int)uid) < 0) + return -1; + ret = virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_USER_ID, + val); + VIR_FREE(val); + return ret; +} + + +int virIdentitySetUNIXGroupName(virIdentityPtr ident, + const char *groupname) +{ + return virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_GROUP_NAME, + groupname); +} + + +int virIdentitySetUNIXGroupID(virIdentityPtr ident, + gid_t gid) +{ + char *val; + int ret; + if (virAsprintf(&val, "%d", (int)gid) < 0) + return -1; + ret = virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_GROUP_ID, + val); + VIR_FREE(val); + return ret; +} + + +int virIdentitySetUNIXProcessID(virIdentityPtr ident, + pid_t pid) +{ + char *val; + int ret; + if (virAsprintf(&val, "%llu", (unsigned long long)pid) < 0) + return -1; + ret = virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_PROCESS_ID, + val); + VIR_FREE(val); + return ret; +} + + +int virIdentitySetUNIXProcessTime(virIdentityPtr ident, + unsigned long long timestamp) +{ + char *val; + int ret; + if (virAsprintf(&val, "%llu", timestamp) < 0) + return -1; + ret = virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME, + val); + VIR_FREE(val); + return ret; +} + + + +int virIdentitySetSASLUserName(virIdentityPtr ident, + const char *username) +{ + return virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_SASL_USER_NAME, + username); +} + + +int virIdentitySetX509DName(virIdentityPtr ident, + const char *dname) +{ + return virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME, + dname); +} + + +int virIdentitySetSELinuxContext(virIdentityPtr ident, + const char *context) +{ + return virIdentitySetAttr(ident, + VIR_IDENTITY_ATTR_SELINUX_CONTEXT, + context); +} diff --git a/src/util/viridentity.h b/src/util/viridentity.h index a240c2da0543684259819aa8db4c5285b16537de..63aa63d573cafc00b76ba23a4e4526f3b1807d12 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -65,4 +65,44 @@ bool virIdentityIsEqual(virIdentityPtr identA, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +int virIdentityGetUNIXUserName(virIdentityPtr ident, + const char **username); +int virIdentityGetUNIXUserID(virIdentityPtr ident, + uid_t *uid); +int virIdentityGetUNIXGroupName(virIdentityPtr ident, + const char **groupname); +int virIdentityGetUNIXGroupID(virIdentityPtr ident, + gid_t *gid); +int virIdentityGetUNIXProcessID(virIdentityPtr ident, + pid_t *pid); +int virIdentityGetUNIXProcessTime(virIdentityPtr ident, + unsigned long long *timestamp); +int virIdentityGetSASLUserName(virIdentityPtr ident, + const char **username); +int virIdentityGetX509DName(virIdentityPtr ident, + const char **dname); +int virIdentityGetSELinuxContext(virIdentityPtr ident, + const char **context); + + +int virIdentitySetUNIXUserName(virIdentityPtr ident, + const char *username); +int virIdentitySetUNIXUserID(virIdentityPtr ident, + uid_t uid); +int virIdentitySetUNIXGroupName(virIdentityPtr ident, + const char *groupname); +int virIdentitySetUNIXGroupID(virIdentityPtr ident, + gid_t gid); +int virIdentitySetUNIXProcessID(virIdentityPtr ident, + pid_t pid); +int virIdentitySetUNIXProcessTime(virIdentityPtr ident, + unsigned long long timestamp); +int virIdentitySetSASLUserName(virIdentityPtr ident, + const char *username); +int virIdentitySetX509DName(virIdentityPtr ident, + const char *dname); +int virIdentitySetSELinuxContext(virIdentityPtr ident, + const char *context); + + #endif /* __VIR_IDENTITY_H__ */