security: update user and group parsing in security_dac.c

The functions virGetUserID and virGetGroupID are now able to parse
user/group names and IDs in a similar way to coreutils' chown. So, user
and group parsing in security_dac can be simplified.
This commit is contained in:
Marcelo Cerri 2012-10-08 17:37:02 -03:00 committed by Eric Blake
parent 0b237296ef
commit 7c035625f8
1 changed files with 8 additions and 37 deletions

View File

@ -69,8 +69,8 @@ static
int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
{ {
int rc = -1; int rc = -1;
unsigned int theuid; uid_t theuid;
unsigned int thegid; gid_t thegid;
char *tmp_label = NULL; char *tmp_label = NULL;
char *sep = NULL; char *sep = NULL;
char *owner = NULL; char *owner = NULL;
@ -94,41 +94,12 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
owner = tmp_label; owner = tmp_label;
group = sep + 1; group = sep + 1;
/* Parse owner */ /* Parse owner and group, error message is defined by
if (*owner == '+') { * virGetUserID or virGetGroupID.
if (virStrToLong_ui(++owner, NULL, 10, &theuid) < 0) { */
virReportError(VIR_ERR_INVALID_ARG, if (virGetUserID(owner, &theuid) < 0 ||
_("Invalid uid \"%s\" in DAC label \"%s\""), virGetGroupID(group, &thegid) < 0)
owner, label); goto cleanup;
goto cleanup;
}
} else {
if (virGetUserID(owner, &theuid) < 0 &&
virStrToLong_ui(owner, NULL, 10, &theuid) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid owner \"%s\" in DAC label \"%s\""),
owner, label);
goto cleanup;
}
}
/* Parse group */
if (*group == '+') {
if (virStrToLong_ui(++group, NULL, 10, &thegid) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid gid \"%s\" in DAC label \"%s\""),
group, label);
goto cleanup;
}
} else {
if (virGetGroupID(group, &thegid) < 0 &&
virStrToLong_ui(group, NULL, 10, &thegid) < 0) {
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid group \"%s\" in DAC label \"%s\""),
group, label);
goto cleanup;
}
}
if (uidPtr) if (uidPtr)
*uidPtr = theuid; *uidPtr = theuid;