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