diff options
author | malcolmd <malcolmd@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-07-30 20:27:42 +0000 |
---|---|---|
committer | malcolmd <malcolmd@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-07-30 20:27:42 +0000 |
commit | 27a9d6972dd52d2682f9943513a1dcc91e577761 (patch) | |
tree | 16cc0138e7834d8ce81a4b09fa7d2a81008f7d41 /manager.c | |
parent | cfc0e168ad10ce999ead096fbe6b5d97f5461fb6 (diff) |
Bug # 2170: Add authority_to_str function to let Administrator issue command to find privilege string
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3545 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'manager.c')
-rwxr-xr-x | manager.c | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -103,6 +103,23 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms) return res; } +static char *authority_to_str(int authority, char *res, int reslen) +{ + int running_total = 0, i; + memset(res, 0, reslen); + for (i=0; i<sizeof(perms) / sizeof(perms[0]) - 1; i++) { + if (authority & perms[i].num) { + if (*res) { + strncat(res, ",", (reslen > running_total) ? reslen - running_total : 0); + running_total++; + } + strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total : 0); + running_total += strlen(perms[i].label); + } + } + return res; +} + static char *complete_show_mancmd(char *line, char *word, int pos, int state) { struct manager_action *cur = first_action; @@ -126,6 +143,7 @@ static char *complete_show_mancmd(char *line, char *word, int pos, int state) static int handle_showmancmd(int fd, int argc, char *argv[]) { struct manager_action *cur = first_action; + char authority[80]; int num; if (argc != 4) @@ -134,7 +152,7 @@ static int handle_showmancmd(int fd, int argc, char *argv[]) while (cur) { /* Walk the list of actions */ for (num = 3; num < argc; num++) { if (!strcasecmp(cur->action, argv[num])) { - ast_cli(fd, "Action: %s\nSynopsis: %s\n%s\n", cur->action, cur->synopsis, cur->description ? cur->description : ""); + ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", cur->action, cur->synopsis, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->description ? cur->description : ""); } } cur = cur->next; @@ -147,12 +165,13 @@ static int handle_showmancmd(int fd, int argc, char *argv[]) static int handle_showmancmds(int fd, int argc, char *argv[]) { struct manager_action *cur = first_action; - char *format = " %-15.15s %-45.45s\n"; + char authority[80]; + char *format = " %-15.15s %-10.10s %-45.45s\n"; ast_mutex_lock(&actionlock); - ast_cli(fd, format, "Action", "Synopsis"); + ast_cli(fd, format, "Action", "Privilege", "Synopsis"); while (cur) { /* Walk the list of actions */ - ast_cli(fd, format, cur->action, cur->synopsis); + ast_cli(fd, format, cur->action, authority_to_str(cur->authority, authority, sizeof(authority) -1), cur->synopsis); cur = cur->next; } |