[asterisk-commits] oej: branch oej/bufo-manager-contexts r282967 - /team/oej/bufo-manager-contex...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 20 04:35:15 CDT 2010
Author: oej
Date: Fri Aug 20 04:35:12 2010
New Revision: 282967
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=282967
Log:
Adding ability to specify contexts for manager accounts, to limit
the reach of originate actions
Modified:
team/oej/bufo-manager-contexts/main/manager.c
Modified: team/oej/bufo-manager-contexts/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-contexts/main/manager.c?view=diff&rev=282967&r1=282966&r2=282967
==============================================================================
--- team/oej/bufo-manager-contexts/main/manager.c (original)
+++ team/oej/bufo-manager-contexts/main/manager.c Fri Aug 20 04:35:12 2010
@@ -142,6 +142,14 @@
{{ "module", "unload", NULL }},
{{ "restart", "gracefully", NULL }},
};
+
+/*! \brief Structure for simple linked list of available contexts for a manager
+ session */
+struct man_context {
+ char context[AST_MAX_CONTEXT];
+ struct man_context *next;
+};
+
/* In order to understand what the heck is going on with the
* mansession_session and mansession structs, we need to have a bit of a history
@@ -210,6 +218,7 @@
char inbuf[1024];
int inlen;
int send_events;
+ struct man_context *contexts;
int displaysystemname; /*!< Add system name to manager responses and events */
/* Queued events that we've not had the ability to send yet */
struct eventqent *eventq;
@@ -248,6 +257,12 @@
static struct manager_action *first_action;
AST_RWLOCK_DEFINE_STATIC(actionlock);
+
+/* Forward declarations */
+static struct man_context *append_context(struct man_context *con, const char *context);
+static int apply_context(struct man_context *con, const char *context);
+static void free_contexts(struct man_context *con);
+static struct man_context *build_context(const char *context);
/*! \brief Convert authority code to string with serveral options */
static char *authority_to_str(int authority, char *res, int reslen)
@@ -794,6 +809,9 @@
s->eventq = s->eventq->next;
unuse_eventqent(eqe);
}
+ if (s->contexts) {
+ free_contexts(s->contexts);
+ }
free(s);
}
@@ -1005,6 +1023,7 @@
const char *authtype = astman_get_header(m, "AuthType");
const char *key = astman_get_header(m, "Key");
const char *events = astman_get_header(m, "Events");
+ struct man_context *contexts = NULL;
cfg = ast_config_load("manager.conf");
if (!cfg)
@@ -1021,6 +1040,8 @@
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
if (!strcasecmp(v->name, "secret")) {
password = v->value;
+ } else if (!strcasecmp(v->name, "context")) {
+ contexts = append_context(contexts, v->value);
} else if (!strcasecmp(v->name, "displaysystemname")) {
if (ast_true(v->value)) {
if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
@@ -1088,6 +1109,7 @@
}
if (cat) {
ast_copy_string(s->session->username, cat, sizeof(s->session->username));
+ s->session->contexts = contexts;
s->session->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
s->session->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
ast_config_destroy(cfg);
@@ -1922,6 +1944,48 @@
return NULL;
}
+/* Search list of context. Stolen from chan_iax2 */
+static int apply_context(struct man_context *con, const char *context)
+{
+ while(con) {
+ if (!strcmp(con->context, context) || !strcmp(con->context, "*"))
+ return 1;
+ con = con->next;
+ }
+ return 0;
+}
+
+static void free_contexts(struct man_context *con)
+{
+ struct man_context *conl;
+ while(con) {
+ conl = con;
+ con = con->next;
+ free(conl);
+ }
+}
+
+static struct man_context *build_context(const char *context)
+{
+ struct man_context *con;
+
+ if ((con = ast_calloc(1, sizeof(*con))))
+ ast_copy_string(con->context, context, sizeof(con->context));
+
+ return con;
+}
+
+static struct man_context *append_context(struct man_context *con, const char *context)
+{
+ struct man_context *top;
+ if (!con) {
+ return build_context(context);
+ }
+ top = build_context(context);
+ top->next = con;
+ return top;
+}
+
static char mandescr_originate[] =
"Description: Generates an outgoing call to a Extension/Context/Priority or\n"
" Application/Data\n"
@@ -1986,6 +2050,11 @@
astman_send_error(s, m, "Invalid channel");
return 0;
}
+ if (s->session->contexts && ! apply_context(s->session->contexts, context) ) {
+ astman_send_error(s, m, "Illegal context");
+ return 0;
+ }
+
*data++ = '\0';
ast_copy_string(tmp2, callerid, sizeof(tmp2));
ast_callerid_parse(tmp2, &n, &l);
More information about the asterisk-commits
mailing list