MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ACLAddAllowedSubcommand

Function ACLAddAllowedSubcommand

src/acl.cpp:721–748  ·  view source on GitHub ↗

Add a subcommand to the list of subcommands for the user 'u' and * the command id specified. */

Source from the content-addressed store, hash-verified

719/* Add a subcommand to the list of subcommands for the user 'u' and
720 * the command id specified. */
721void ACLAddAllowedSubcommand(user *u, unsigned long id, const char *sub) {
722 /* If this is the first subcommand to be configured for
723 * this user, we have to allocate the subcommands array. */
724 if (u->allowed_subcommands == NULL) {
725 u->allowed_subcommands = (sds**)zcalloc(USER_COMMAND_BITS_COUNT *
726 sizeof(sds*), MALLOC_LOCAL);
727 }
728
729 /* We also need to enlarge the allocation pointing to the
730 * null terminated SDS array, to make space for this one.
731 * To start check the current size, and while we are here
732 * make sure the subcommand is not already specified inside. */
733 long items = 0;
734 if (u->allowed_subcommands[id]) {
735 while(u->allowed_subcommands[id][items]) {
736 /* If it's already here do not add it again. */
737 if (!strcasecmp(u->allowed_subcommands[id][items],sub)) return;
738 items++;
739 }
740 }
741
742 /* Now we can make space for the new item (and the null term). */
743 items += 2;
744 u->allowed_subcommands[id] = (sds*)zrealloc(u->allowed_subcommands[id],
745 sizeof(sds)*items, MALLOC_LOCAL);
746 u->allowed_subcommands[id][items-2] = sdsnew(sub);
747 u->allowed_subcommands[id][items-1] = NULL;
748}
749
750/* Set user properties according to the string "op". The following
751 * is a description of what different strings will do:

Callers 2

ACLCopyUserFunction · 0.85
ACLSetUserFunction · 0.85

Calls 3

zcallocFunction · 0.85
zreallocFunction · 0.85
sdsnewFunction · 0.85

Tested by

no test coverage detected