MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ACLDescribeUser

Function ACLDescribeUser

app/redis-6.2.6/src/acl.c:611–670  ·  view source on GitHub ↗

This is similar to ACLDescribeUserCommandRules(), however instead of * describing just the user command rules, everything is described: user * flags, keys, passwords and finally the command rules obtained via * the ACLDescribeUserCommandRules() function. This is the function we call * when we want to rewrite the configuration files describing ACLs and * in order to show users with ACL LIST. *

Source from the content-addressed store, hash-verified

609 * when we want to rewrite the configuration files describing ACLs and
610 * in order to show users with ACL LIST. */
611sds ACLDescribeUser(user *u) {
612 sds res = sdsempty();
613
614 /* Flags. */
615 for (int j = 0; ACLUserFlags[j].flag; j++) {
616 /* Skip the allcommands, allkeys and allchannels flags because they'll
617 * be emitted later as +@all, ~* and &*. */
618 if (ACLUserFlags[j].flag == USER_FLAG_ALLKEYS ||
619 ACLUserFlags[j].flag == USER_FLAG_ALLCHANNELS ||
620 ACLUserFlags[j].flag == USER_FLAG_ALLCOMMANDS) continue;
621 if (u->flags & ACLUserFlags[j].flag) {
622 res = sdscat(res,ACLUserFlags[j].name);
623 res = sdscatlen(res," ",1);
624 }
625 }
626
627 /* Passwords. */
628 listIter li;
629 listNode *ln;
630 listRewind(u->passwords,&li);
631 while((ln = listNext(&li))) {
632 sds thispass = listNodeValue(ln);
633 res = sdscatlen(res,"#",1);
634 res = sdscatsds(res,thispass);
635 res = sdscatlen(res," ",1);
636 }
637
638 /* Key patterns. */
639 if (u->flags & USER_FLAG_ALLKEYS) {
640 res = sdscatlen(res,"~* ",3);
641 } else {
642 listRewind(u->patterns,&li);
643 while((ln = listNext(&li))) {
644 sds thispat = listNodeValue(ln);
645 res = sdscatlen(res,"~",1);
646 res = sdscatsds(res,thispat);
647 res = sdscatlen(res," ",1);
648 }
649 }
650
651 /* Pub/sub channel patterns. */
652 if (u->flags & USER_FLAG_ALLCHANNELS) {
653 res = sdscatlen(res,"&* ",3);
654 } else {
655 res = sdscatlen(res,"resetchannels ",14);
656 listRewind(u->channels,&li);
657 while((ln = listNext(&li))) {
658 sds thispat = listNodeValue(ln);
659 res = sdscatlen(res,"&",1);
660 res = sdscatsds(res,thispat);
661 res = sdscatlen(res," ",1);
662 }
663 }
664
665 /* Command rules. */
666 sds rules = ACLDescribeUserCommandRules(u);
667 res = sdscatsds(res,rules);
668 sdsfree(rules);

Callers 3

rewriteConfigUserOptionFunction · 0.85
ACLSaveToFileFunction · 0.85
aclCommandFunction · 0.85

Calls 8

sdsemptyFunction · 0.85
sdscatFunction · 0.85
sdscatlenFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
sdscatsdsFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected