<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16160] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16160">16160</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2010-01-05 13:47:49 -0600 (Tue, 05 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>add userauth <user>@<domain>:<pass> to event_socket to auth against user directory uses esl-password esl-allowed-api esl-allowed-events and esl-allowed-log to control resource access</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodevent_handlersmod_event_socketmod_event_socketc">freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c</a></li>
<li><a href="#freeswitchtrunksrcmodxml_intmod_xml_rpcmod_xml_rpcc">freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodevent_handlersmod_event_socketmod_event_socketc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (16159 => 16160)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c        2010-01-05 19:08:40 UTC (rev 16159)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c        2010-01-05 19:47:49 UTC (rev 16160)
</span><span class="lines">@@ -54,6 +54,9 @@
</span><span class="cx">         LFLAG_HANDLE_DISCO = (1 << 11),
</span><span class="cx">         LFLAG_CONNECTED = (1 << 12),
</span><span class="cx">         LFLAG_RESUME = (1 << 13),
</span><ins>+        LFLAG_AUTH_EVENTS = (1 << 14),
+        LFLAG_ALL_EVENTS_AUTHED = (1 << 15),
+        LFLAG_ALLOW_LOG = (1 << 16)
</ins><span class="cx"> } event_flag_t;
</span><span class="cx">
</span><span class="cx"> typedef enum {
</span><span class="lines">@@ -73,7 +76,10 @@
</span><span class="cx">         switch_log_level_t level;
</span><span class="cx">         char *ebuf;
</span><span class="cx">         uint8_t event_list[SWITCH_EVENT_ALL + 1];
</span><ins>+        uint8_t allowed_event_list[SWITCH_EVENT_ALL + 1];
</ins><span class="cx">         switch_hash_t *event_hash;
</span><ins>+        switch_hash_t *allowed_event_hash;
+        switch_hash_t *allowed_api_hash;
</ins><span class="cx">         switch_thread_rwlock_t *rwlock;
</span><span class="cx">         switch_core_session_t *session;
</span><span class="cx">         int lost_events;
</span><span class="lines">@@ -211,6 +217,15 @@
</span><span class="cx">         flush_listener(*listener, SWITCH_TRUE, SWITCH_TRUE);
</span><span class="cx">         switch_core_hash_destroy(&l->event_hash);
</span><span class="cx">
</span><ins>+        if (l->allowed_event_hash) {
+ switch_core_hash_destroy(&l->allowed_event_hash);
+ }
+
+        if (l->allowed_api_hash) {
+ switch_core_hash_destroy(&l->allowed_api_hash);
+ }
+
+
</ins><span class="cx">         switch_mutex_lock(l->filter_mutex);
</span><span class="cx">         if (l->filters) {
</span><span class="cx">                 switch_event_destroy(&l->filters);
</span><span class="lines">@@ -429,6 +444,7 @@
</span><span class="cx">         listener->pool = switch_core_session_get_pool(session);
</span><span class="cx">         listener->format = EVENT_FORMAT_PLAIN;
</span><span class="cx">         listener->session = session;
</span><ins>+        switch_set_flag(listener, LFLAG_ALLOW_LOG);
</ins><span class="cx">
</span><span class="cx">         switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
</span><span class="cx">         switch_mutex_init(&listener->filter_mutex, SWITCH_MUTEX_NESTED, listener->pool);
</span><span class="lines">@@ -753,6 +769,7 @@
</span><span class="cx">                 switch_core_hash_init(&listener->event_hash, listener->pool);
</span><span class="cx">                 switch_set_flag(listener, LFLAG_AUTHED);
</span><span class="cx">                 switch_set_flag(listener, LFLAG_STATEFUL);
</span><ins>+                switch_set_flag(listener, LFLAG_ALLOW_LOG);
</ins><span class="cx">                 switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener->pool);
</span><span class="cx">                 switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener->pool);
</span><span class="cx">
</span><span class="lines">@@ -1390,6 +1407,60 @@
</span><span class="cx">         return NULL;
</span><span class="cx">
</span><span class="cx"> }
</span><ins>+
+static switch_bool_t auth_api_command(listener_t *listener, const char *api_cmd, const char *arg)
+{
+        const char *check_cmd = api_cmd;
+        char *sneaky_commands[] = { "bgapi", "sched_api", "eval", "expand", NULL };
+        int x = 0;
+        char *dup_arg = NULL;
+        char *next = NULL;
+        switch_bool_t ok = SWITCH_TRUE;
+
+ top:
+
+        if (!switch_core_hash_find(listener->allowed_api_hash, check_cmd)) {
+                ok = SWITCH_FALSE;
+                goto end;
+        }
+        
+        while(check_cmd) {
+                for (x = 0; sneaky_commands[x]; x++) {
+                        if (!strcasecmp(sneaky_commands[x], check_cmd)) {
+                                if (check_cmd == api_cmd) {
+                                        if (arg) {
+                                                dup_arg = strdup(arg);
+                                                check_cmd = dup_arg;
+                                                if ((next = strchr(check_cmd, ' '))) {
+                                                        *next++ = '\0';
+                                                }
+                                        } else {
+                                                break;
+                                        }
+                                } else {
+                                        if (next) {
+                                                check_cmd = next;
+                                        } else {
+                                                check_cmd = dup_arg;
+                                        }
+                                        
+                                        if ((next = strchr(check_cmd, ' '))) {
+                                                *next++ = '\0';
+                                        }
+                                }
+                                goto top;
+                        }
+                }
+                break;
+        }
+
+ end:
+
+        switch_safe_free(dup_arg);
+        return ok;
+        
+}
+
</ins><span class="cx"> static switch_status_t parse_command(listener_t *listener, switch_event_t **event, char *reply, uint32_t reply_len)
</span><span class="cx"> {
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -1405,7 +1476,7 @@
</span><span class="cx">                 cmd = reload_cheat;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (!strncasecmp(cmd, "exit", 4)) {
</del><ins>+        if (!strncasecmp(cmd, "exit", 4) || !strncasecmp(cmd, "...", 3)) {
</ins><span class="cx">                 switch_clear_flag_locked(listener, LFLAG_RUNNING);
</span><span class="cx">                 switch_snprintf(reply, reply_len, "+OK bye");
</span><span class="cx">                 goto done;
</span><span class="lines">@@ -1429,6 +1500,196 @@
</span><span class="cx">                         goto done;
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                if (!strncasecmp(cmd, "userauth ", 9)) {
+                        const char *passwd;
+                        const char *allowed_api;
+                        const char *allowed_events;
+                        switch_event_t *params;
+                        char *user, *domain_name, *pass;
+                        switch_xml_t x_domain = NULL, x_domain_root, x_user = NULL, x_params, x_param, x_group = NULL;
+                        int authed = 0;
+                        char *edup = NULL;
+                        char event_reply[512] = "Allowed-Events: all\n";
+                        char api_reply[512] = "Allowed-API: all\n";
+                        char log_reply[512] = "";
+                        int allowed_log = 1;
+                        
+
+                        switch_clear_flag(listener, LFLAG_ALLOW_LOG);
+
+                        strip_cr(cmd);
+
+                        user = cmd + 9;
+
+                        if ((pass = strchr(user, ':'))) {
+                                *pass++ = '\0';
+                        }
+
+                        if ((domain_name = strchr(user, '@'))) {
+                                *domain_name++ = '\0';
+                        }
+
+                        if (zstr(user) || zstr(domain_name)) {
+                                switch_snprintf(reply, reply_len, "-ERR invalid");
+                                switch_clear_flag_locked(listener, LFLAG_RUNNING);
+                                goto done;
+                        }
+
+
+                        passwd = NULL;
+                        allowed_events = NULL;
+                        allowed_api = NULL;
+                        
+                        params = NULL;
+                        x_domain_root = NULL;
+                        
+
+                        switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
+                        switch_assert(params);
+                        switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "event_socket_auth");
+
+                        if (switch_xml_locate_user("id", user, domain_name, NULL, &x_domain_root, &x_domain, &x_user, &x_group, params) == SWITCH_STATUS_SUCCESS) {
+                                switch_xml_t list[3];
+                                int x = 0;
+
+                                list[0] = x_domain;
+                                list[1] = x_group;
+                                list[2] = x_user;
+
+                                for (x = 0 ; x < 3; x++) {
+                                        if ((x_params = switch_xml_child(list[x], "params"))) {
+                                                for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
+                                                        const char *var = switch_xml_attr_soft(x_param, "name");
+                                                        const char *val = switch_xml_attr_soft(x_param, "value");
+
+                                                        if (!strcasecmp(var, "esl-password")) {
+                                                                passwd = val;
+                                                        } else if (!strcasecmp(var, "esl-allowed-log")) {
+                                                                allowed_log = switch_true(val);
+                                                        } else if (!strcasecmp(var, "esl-allowed-events")) {
+                                                                allowed_events = val;
+                                                        } else if (!strcasecmp(var, "esl-allowed-api")) {
+                                                                allowed_api = val;
+                                                        }
+                                                }
+                                        }
+                                }
+                        } else {
+                                authed = 0;
+                                goto bot;
+                        }
+                        
+                        if (!zstr(passwd) && !zstr(pass) && !strcmp(passwd, pass)) {
+                                authed = 1;
+                                
+                                if (allowed_events) {
+                                        char delim = ',';
+                                        char *cur, *next;
+                                        int count = 0, custom = 0, key_count = 0;
+
+                                        switch_set_flag(listener, LFLAG_AUTH_EVENTS);
+
+                                        switch_snprintf(event_reply, sizeof(event_reply), "Allowed-Events: %s\n", allowed_events);
+
+                                        switch_core_hash_init(&listener->allowed_event_hash, listener->pool);
+                                        
+                                        edup = strdup(allowed_events);
+                                        cur = edup;
+
+                                        if (strchr(edup, ' ')) {
+                                                delim = ' ';
+                                        }
+                                        
+                                        for (cur = edup; cur; count++) {
+                                                switch_event_types_t type;
+                                                
+                                                if ((next = strchr(cur, delim))) {
+                                                        *next++ = '\0';
+                                                }
+                                                
+                                                if (custom) {
+                                                        switch_core_hash_insert(listener->allowed_event_hash, cur, MARKER);
+                                                } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
+                                                        key_count++;
+                                                        if (type == SWITCH_EVENT_ALL) {
+                                                                uint32_t x = 0;
+                                                                switch_set_flag(listener, LFLAG_ALL_EVENTS_AUTHED);
+                                                                for (x = 0; x < SWITCH_EVENT_ALL; x++) {
+                                                                        listener->allowed_event_list[x] = 1;
+                                                                }
+                                                        }
+                                                        if (type <= SWITCH_EVENT_ALL) {
+                                                                listener->allowed_event_list[type] = 1;
+                                                        }
+                                                        if (type == SWITCH_EVENT_CUSTOM) {
+                                                                custom++;
+                                                        }
+                                                }
+                                                
+                                                cur = next;
+                                        }
+                
+                                        switch_safe_free(edup);
+                                }
+
+                                switch_snprintf(log_reply, sizeof(log_reply), "Allowed-LOG: %s\n", allowed_log ? "true" : "false");
+
+                                if (allowed_log) {
+                                        switch_set_flag(listener, LFLAG_ALLOW_LOG);
+                                }
+
+                                if (allowed_api) {
+                                        char delim = ',';
+                                        char *cur, *next;
+                                        int count = 0;
+
+                                        switch_snprintf(api_reply, sizeof(api_reply), "Allowed-API: %s\n", allowed_api);
+
+                                        switch_core_hash_init(&listener->allowed_api_hash, listener->pool);
+                                        
+                                        edup = strdup(allowed_api);
+                                        cur = edup;
+
+                                        if (strchr(edup, ' ')) {
+                                                delim = ' ';
+                                        }
+                                        
+                                        for (cur = edup; cur; count++) {
+                                                if ((next = strchr(cur, delim))) {
+                                                        *next++ = '\0';
+                                                }
+
+                                                switch_core_hash_insert(listener->allowed_api_hash, cur, MARKER);
+
+                                                cur = next;
+                                        }
+                
+                                        switch_safe_free(edup);
+                                }
+
+                        }
+
+                        
+                bot:
+
+                        if (params) {
+                                switch_event_destroy(&params);
+                        }
+                        
+                        if (authed) {
+                                switch_set_flag_locked(listener, LFLAG_AUTHED);
+                                switch_snprintf(reply, reply_len, "~Reply-Text: +OK accepted\n%s%s%s\n", event_reply, api_reply, log_reply);
+                        } else {
+                                switch_snprintf(reply, reply_len, "-ERR invalid");
+                                switch_clear_flag_locked(listener, LFLAG_RUNNING);
+                        }
+                        
+                        if (x_domain_root) {
+                                switch_xml_free(x_domain_root);
+                        }                        
+
+                }
+
</ins><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -1737,6 +1998,15 @@
</span><span class="cx">                         *arg++ = '\0';
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                if (listener->allowed_api_hash) {
+                        if (!auth_api_command(listener, api_cmd, arg)) {
+                                switch_snprintf(reply, reply_len, "-ERR permission denied");
+                                status = SWITCH_STATUS_SUCCESS;
+                                goto done;
+                        }
+                }
+                
+
</ins><span class="cx">                 acs.listener = listener;
</span><span class="cx">                 acs.api_cmd = api_cmd;
</span><span class="cx">                 acs.arg = arg;
</span><span class="lines">@@ -1763,6 +2033,14 @@
</span><span class="cx">                         *arg++ = '\0';
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                if (listener->allowed_api_hash) {
+                        if (!auth_api_command(listener, api_cmd, arg)) {
+                                switch_snprintf(reply, reply_len, "-ERR permission denied");
+                                status = SWITCH_STATUS_SUCCESS;
+                                goto done;
+                        }
+                }
+
</ins><span class="cx">                 switch_core_new_memory_pool(&pool);
</span><span class="cx">                 acs = switch_core_alloc(pool, sizeof(*acs));
</span><span class="cx">                 switch_assert(acs);
</span><span class="lines">@@ -1804,6 +2082,11 @@
</span><span class="cx">                 char *level_s;
</span><span class="cx">                 switch_log_level_t ltype = SWITCH_LOG_DEBUG;
</span><span class="cx">
</span><ins>+                if (!switch_test_flag(listener, LFLAG_ALLOW_LOG)) {
+                        switch_snprintf(reply, reply_len, "-ERR permission denied");
+                        goto done;
+                }
+
</ins><span class="cx">                 //pull off the first newline/carriage return
</span><span class="cx">                 strip_cr(cmd);
</span><span class="cx">
</span><span class="lines">@@ -1874,10 +2157,22 @@
</span><span class="cx">                                                 goto end;
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><del>-
</del><ins>+                                
+                                
</ins><span class="cx">                                 if (custom) {
</span><del>-                                        switch_core_hash_insert(listener->event_hash, cur, MARKER);
</del><ins>+                                        if (listener->allowed_event_hash && switch_core_hash_find(listener->allowed_event_hash, cur)) {
+                                                switch_core_hash_insert(listener->event_hash, cur, MARKER);
+                                        } else {
+                                                switch_snprintf(reply, reply_len, "-ERR permission denied");
+                                                goto done;
+                                        }
</ins><span class="cx">                                 } else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
</span><ins>+                                        if (switch_test_flag(listener, LFLAG_AUTH_EVENTS) && !listener->allowed_event_list[type] &&
+                                                !switch_test_flag(listener, LFLAG_ALL_EVENTS_AUTHED)) {
+                                                switch_snprintf(reply, reply_len, "-ERR permission denied");
+                                                goto done;
+                                        }
+
</ins><span class="cx">                                         key_count++;
</span><span class="cx">                                         if (type == SWITCH_EVENT_ALL) {
</span><span class="cx">                                                 uint32_t x = 0;
</span><span class="lines">@@ -2199,6 +2494,14 @@
</span><span class="cx">
</span><span class="cx">         switch_core_hash_destroy(&listener->event_hash);
</span><span class="cx">
</span><ins>+        if (listener->allowed_event_hash) {
+                switch_core_hash_destroy(&listener->allowed_event_hash);
+        }
+
+        if (listener->allowed_api_hash) {
+                switch_core_hash_destroy(&listener->allowed_api_hash);
+        }
+
</ins><span class="cx">         if (listener->session) {
</span><span class="cx">                 switch_channel_clear_flag(switch_core_session_get_channel(listener->session), CF_CONTROLLED);
</span><span class="cx">                 switch_clear_flag_locked(listener, LFLAG_SESSION);
</span><span class="lines">@@ -2376,6 +2679,8 @@
</span><span class="cx">                 listener_pool = NULL;
</span><span class="cx">                 listener->format = EVENT_FORMAT_PLAIN;
</span><span class="cx">                 switch_set_flag(listener, LFLAG_FULL);
</span><ins>+                switch_set_flag(listener, LFLAG_ALLOW_LOG);
+
</ins><span class="cx">                 switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool);
</span><span class="cx">                 switch_mutex_init(&listener->filter_mutex, SWITCH_MUTEX_NESTED, listener->pool);
</span><span class="cx">
</span></span></pre></div>
<a id="freeswitchtrunksrcmodxml_intmod_xml_rpcmod_xml_rpcc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c (16159 => 16160)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c        2010-01-05 19:08:40 UTC (rev 16159)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c        2010-01-05 19:47:49 UTC (rev 16160)
</span><span class="lines">@@ -227,19 +227,20 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (x_domain_root) {
-                switch_xml_free(x_domain_root);
-        }
-
</del><span class="cx">         if (ppasswd)
</span><del>-                *ppasswd = passwd;
</del><ins>+                *ppasswd = strdup(passwd);
</ins><span class="cx">         if (pvm_passwd)
</span><del>-                *pvm_passwd = vm_passwd;
</del><ins>+                *pvm_passwd = strdup(vm_passwd);
</ins><span class="cx">         if (palias)
</span><del>-                *palias = alias;
</del><ins>+                *palias = strdup(alias);
</ins><span class="cx">         if (pallowed_commands)
</span><del>-                *pallowed_commands = allowed_commands;
</del><ins>+                *pallowed_commands = strdup(allowed_commands);
+        
</ins><span class="cx">
</span><ins>+        if (x_domain_root) {
+                switch_xml_free(x_domain_root);
+        }
+
</ins><span class="cx">         return TRUE;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -293,7 +294,7 @@
</span><span class="cx">         if (!allowed_commands)
</span><span class="cx">                 return FALSE;
</span><span class="cx">
</span><del>-        dup = strdup (allowed_commands);
</del><ins>+        dup = allowed_commands;
</ins><span class="cx">         argc = switch_separate_string (dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
</span><span class="cx">
</span><span class="cx">         for (i = 0; i < argc; i++) {
</span><span class="lines">@@ -319,7 +320,8 @@
</span><span class="cx">         const char *box = NULL;
</span><span class="cx">         int at = 0;
</span><span class="cx">         char *dp;
</span><del>-
</del><ins>+        abyss_bool rval = FALSE;
+        
</ins><span class="cx">         p = RequestHeaderValue(r, "authorization");
</span><span class="cx">
</span><span class="cx">         if (p) {
</span><span class="lines">@@ -445,18 +447,25 @@
</span><span class="cx">
</span><span class="cx">                                 ResponseAddField(r, "freeswitch-user", (box ? box : user));
</span><span class="cx">                                 ResponseAddField(r, "freeswitch-domain", domain_name);
</span><del>-
-                                return TRUE;
</del><ins>+                                rval = TRUE;
+                                goto done;
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>- fail:
</del><ins>+ fail:
</ins><span class="cx">
</span><span class="cx">         switch_snprintf(z, sizeof(z), "Basic realm=\"%s\"", domain_name ? domain_name : globals.realm);
</span><span class="cx">         ResponseAddField(r, "WWW-Authenticate", z);
</span><span class="cx">         ResponseStatus(r, 401);
</span><del>-        return FALSE;
</del><ins>+
+ done:
+
+        switch_safe_free(mypass1);
+        switch_safe_free(mypass2);
+        switch_safe_free(box);
+        
+        return rval;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> abyss_bool auth_hook(TSession * r)
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>