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. *
| 609 | * when we want to rewrite the configuration files describing ACLs and |
| 610 | * in order to show users with ACL LIST. */ |
| 611 | sds 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); |
no test coverage detected