# util/viridentity.h
-virIdentityGetAttr;
virIdentityGetCurrent;
virIdentityGetGroupName;
virIdentityGetProcessID;
virIdentityGetX509DName;
virIdentityIsEqual;
virIdentityNew;
-virIdentitySetAttr;
virIdentitySetCurrent;
virIdentitySetGroupName;
virIdentitySetProcessID;
VIR_LOG_INIT("util.identity");
+typedef enum {
+ VIR_IDENTITY_ATTR_USER_NAME,
+ VIR_IDENTITY_ATTR_UNIX_USER_ID,
+ VIR_IDENTITY_ATTR_GROUP_NAME,
+ VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
+ VIR_IDENTITY_ATTR_PROCESS_ID,
+ VIR_IDENTITY_ATTR_PROCESS_TIME,
+ VIR_IDENTITY_ATTR_SASL_USER_NAME,
+ VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME,
+ VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
+
+ VIR_IDENTITY_ATTR_LAST,
+} virIdentityAttrType;
+
struct _virIdentity {
virObject parent;
*
* Returns: 0 on success, or -1 on error
*/
-int virIdentitySetAttr(virIdentityPtr ident,
- unsigned int attr,
- const char *value)
+static int
+virIdentitySetAttr(virIdentityPtr ident,
+ unsigned int attr,
+ const char *value)
{
int ret = -1;
VIR_DEBUG("ident=%p attribute=%u value=%s", ident, attr, value);
*
* Returns 0 on success, -1 on error
*/
-int virIdentityGetAttr(virIdentityPtr ident,
- unsigned int attr,
- const char **value)
+static int
+virIdentityGetAttr(virIdentityPtr ident,
+ unsigned int attr,
+ const char **value)
{
VIR_DEBUG("ident=%p attribute=%d value=%p", ident, attr, value);
typedef struct _virIdentity virIdentity;
typedef virIdentity *virIdentityPtr;
-typedef enum {
- VIR_IDENTITY_ATTR_USER_NAME,
- VIR_IDENTITY_ATTR_UNIX_USER_ID,
- VIR_IDENTITY_ATTR_GROUP_NAME,
- VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
- VIR_IDENTITY_ATTR_PROCESS_ID,
- VIR_IDENTITY_ATTR_PROCESS_TIME,
- VIR_IDENTITY_ATTR_SASL_USER_NAME,
- VIR_IDENTITY_ATTR_X509_DISTINGUISHED_NAME,
- VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
-
- VIR_IDENTITY_ATTR_LAST,
-} virIdentityAttrType;
-
virIdentityPtr virIdentityGetCurrent(void);
int virIdentitySetCurrent(virIdentityPtr ident);
virIdentityPtr virIdentityNew(void);
-int virIdentitySetAttr(virIdentityPtr ident,
- unsigned int attr,
- const char *value)
- ATTRIBUTE_NONNULL(1)
- ATTRIBUTE_NONNULL(3);
-
-int virIdentityGetAttr(virIdentityPtr ident,
- unsigned int attr,
- const char **value)
- ATTRIBUTE_NONNULL(1)
- ATTRIBUTE_NONNULL(3);
bool virIdentityIsEqual(virIdentityPtr identA,
virIdentityPtr identB)
if (!(ident = virIdentityNew()))
goto cleanup;
- if (virIdentitySetAttr(ident,
- VIR_IDENTITY_ATTR_USER_NAME,
- "fred") < 0)
+ if (virIdentitySetUserName(ident, "fred") < 0)
goto cleanup;
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_USER_NAME,
- &val) < 0)
+ if (virIdentityGetUserName(ident, &val) < 0)
goto cleanup;
if (STRNEQ_NULLABLE(val, "fred")) {
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_GROUP_NAME,
- &val) < 0)
+ if (virIdentityGetGroupName(ident, &val) < 0)
goto cleanup;
if (val != NULL) {
goto cleanup;
}
- if (virIdentitySetAttr(ident,
- VIR_IDENTITY_ATTR_USER_NAME,
- "joe") != -1) {
+ if (virIdentitySetUserName(ident, "joe") >= 0) {
VIR_DEBUG("Unexpectedly overwrote attribute");
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_USER_NAME,
- &val) < 0)
+ if (virIdentityGetUserName(ident, &val) < 0)
goto cleanup;
if (STRNEQ_NULLABLE(val, "fred")) {
goto cleanup;
}
- if (virIdentitySetAttr(identa,
- VIR_IDENTITY_ATTR_USER_NAME,
- "fred") < 0)
+ if (virIdentitySetUserName(identa, "fred") < 0)
goto cleanup;
if (virIdentityIsEqual(identa, identb)) {
goto cleanup;
}
- if (virIdentitySetAttr(identb,
- VIR_IDENTITY_ATTR_USER_NAME,
- "fred") < 0)
+ if (virIdentitySetUserName(identb, "fred") < 0)
goto cleanup;
if (!virIdentityIsEqual(identa, identb)) {
goto cleanup;
}
- if (virIdentitySetAttr(identa,
- VIR_IDENTITY_ATTR_GROUP_NAME,
- "flintstone") < 0)
+ if (virIdentitySetGroupName(identa, "flintstone") < 0)
goto cleanup;
- if (virIdentitySetAttr(identb,
- VIR_IDENTITY_ATTR_GROUP_NAME,
- "flintstone") < 0)
+ if (virIdentitySetGroupName(identb, "flintstone") < 0)
goto cleanup;
if (!virIdentityIsEqual(identa, identb)) {
goto cleanup;
}
- if (virIdentitySetAttr(identb,
- VIR_IDENTITY_ATTR_SASL_USER_NAME,
- "fred@FLINTSTONE.COM") < 0)
+ if (virIdentitySetSASLUserName(identb, "fred@FLINTSTONE.COM") < 0)
goto cleanup;
if (virIdentityIsEqual(identa, identb)) {
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
- &val) < 0)
+ if (virIdentityGetSELinuxContext(ident, &val) < 0)
goto cleanup;
if (STRNEQ_NULLABLE(val, context)) {
virNetServerClientPtr client = NULL;
virIdentityPtr ident = NULL;
const char *gotUsername = NULL;
- const char *gotUserID = NULL;
+ uid_t gotUserID;
const char *gotGroupname = NULL;
- const char *gotGroupID = NULL;
+ gid_t gotGroupID;
const char *gotSELinuxContext = NULL;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) < 0) {
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_USER_NAME,
- &gotUsername) < 0) {
+ if (virIdentityGetUserName(ident, &gotUsername) < 0) {
fprintf(stderr, "Missing username in identity\n");
goto cleanup;
}
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_UNIX_USER_ID,
- &gotUserID) < 0) {
+ if (virIdentityGetUNIXUserID(ident, &gotUserID) < 0) {
fprintf(stderr, "Missing user ID in identity\n");
goto cleanup;
}
- if (STRNEQ_NULLABLE("666", gotUserID)) {
- fprintf(stderr, "Want username '666' got '%s'\n",
- NULLSTR(gotUserID));
+ if (666 != gotUserID) {
+ fprintf(stderr, "Want username '666' got '%llu'\n",
+ (unsigned long long)gotUserID);
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_GROUP_NAME,
- &gotGroupname) < 0) {
+ if (virIdentityGetGroupName(ident, &gotGroupname) < 0) {
fprintf(stderr, "Missing groupname in identity\n");
goto cleanup;
}
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_UNIX_GROUP_ID,
- &gotGroupID) < 0) {
+ if (virIdentityGetUNIXGroupID(ident, &gotGroupID) < 0) {
fprintf(stderr, "Missing group ID in identity\n");
goto cleanup;
}
- if (STRNEQ_NULLABLE("7337", gotGroupID)) {
- fprintf(stderr, "Want groupname '7337' got '%s'\n",
- NULLSTR(gotGroupID));
+ if (7337 != gotGroupID) {
+ fprintf(stderr, "Want groupname '7337' got '%llu'\n",
+ (unsigned long long)gotGroupID);
goto cleanup;
}
- if (virIdentityGetAttr(ident,
- VIR_IDENTITY_ATTR_SELINUX_CONTEXT,
- &gotSELinuxContext) < 0) {
+ if (virIdentityGetSELinuxContext(ident, &gotSELinuxContext) < 0) {
fprintf(stderr, "Missing SELinux context in identity\n");
goto cleanup;
}