White space tweaks and skip categories already applied
This commit is contained in:
parent
411bcf1a41
commit
d310beb417
15
src/acl.c
15
src/acl.c
@ -488,6 +488,12 @@ sds ACLDescribeUserCommandRules(user *u) {
|
|||||||
* already applied. */
|
* already applied. */
|
||||||
user tu = {0};
|
user tu = {0};
|
||||||
user *tempuser = &tu;
|
user *tempuser = &tu;
|
||||||
|
|
||||||
|
/* Keep track of the categories that have been applied, to prevent
|
||||||
|
* applying them twice. */
|
||||||
|
char applied[sizeof(ACLCommandCategories)/sizeof(ACLCommandCategories[0])];
|
||||||
|
memset(applied, 0, sizeof(applied));
|
||||||
|
|
||||||
memcpy(tempuser->allowed_commands,
|
memcpy(tempuser->allowed_commands,
|
||||||
u->allowed_commands,
|
u->allowed_commands,
|
||||||
sizeof(u->allowed_commands));
|
sizeof(u->allowed_commands));
|
||||||
@ -495,9 +501,10 @@ sds ACLDescribeUserCommandRules(user *u) {
|
|||||||
int best = -1;
|
int best = -1;
|
||||||
unsigned long mindiff = INT_MAX, maxsame = 0;
|
unsigned long mindiff = INT_MAX, maxsame = 0;
|
||||||
for (int j = 0; ACLCommandCategories[j].flag != 0; j++) {
|
for (int j = 0; ACLCommandCategories[j].flag != 0; j++) {
|
||||||
|
if (applied[j]) continue;
|
||||||
|
|
||||||
unsigned long on, off, diff, same;
|
unsigned long on, off, diff, same;
|
||||||
ACLCountCategoryBitsForUser(tempuser,&on,&off,ACLCommandCategories[j].name);
|
ACLCountCategoryBitsForUser(tempuser,&on,&off,ACLCommandCategories[j].name);
|
||||||
|
|
||||||
/* Check if the current category is the best this loop:
|
/* Check if the current category is the best this loop:
|
||||||
* * It has more commands in common with the user than commands
|
* * It has more commands in common with the user than commands
|
||||||
* that are different.
|
* that are different.
|
||||||
@ -509,7 +516,8 @@ sds ACLDescribeUserCommandRules(user *u) {
|
|||||||
diff = additive ? off : on;
|
diff = additive ? off : on;
|
||||||
same = additive ? on : off;
|
same = additive ? on : off;
|
||||||
if (same > diff &&
|
if (same > diff &&
|
||||||
((diff < mindiff) || (diff == mindiff && same > maxsame))) {
|
((diff < mindiff) || (diff == mindiff && same > maxsame)))
|
||||||
|
{
|
||||||
best = j;
|
best = j;
|
||||||
mindiff = diff;
|
mindiff = diff;
|
||||||
maxsame = same;
|
maxsame = same;
|
||||||
@ -531,8 +539,9 @@ sds ACLDescribeUserCommandRules(user *u) {
|
|||||||
rules = sdscatlen(rules," ",1);
|
rules = sdscatlen(rules," ",1);
|
||||||
sdsfree(op);
|
sdsfree(op);
|
||||||
sdsfree(invop);
|
sdsfree(invop);
|
||||||
}
|
|
||||||
|
|
||||||
|
applied[best] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Fix the final ACLs with single commands differences. */
|
/* Fix the final ACLs with single commands differences. */
|
||||||
dictIterator *di = dictGetIterator(server.orig_commands);
|
dictIterator *di = dictGetIterator(server.orig_commands);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user