[asterisk-commits] russell: branch 1.2-netsec r93669 - in /branches/1.2-netsec: ./ channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Dec 18 12:34:29 CST 2007
Author: russell
Date: Tue Dec 18 12:34:29 2007
New Revision: 93669
URL: http://svn.digium.com/view/asterisk?view=rev&rev=93669
Log:
sync with 1.2
Modified:
branches/1.2-netsec/ (props changed)
branches/1.2-netsec/channels/chan_iax2.c
branches/1.2-netsec/channels/chan_sip.c
Propchange: branches/1.2-netsec/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Dec 18 12:34:29 2007
@@ -1,1 +1,1 @@
-/branches/1.2:1-90174
+/branches/1.2:1-93668
Modified: branches/1.2-netsec/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.2-netsec/channels/chan_iax2.c?view=diff&rev=93669&r1=93668&r2=93669
==============================================================================
--- branches/1.2-netsec/channels/chan_iax2.c (original)
+++ branches/1.2-netsec/channels/chan_iax2.c Tue Dec 18 12:34:29 2007
@@ -2625,11 +2625,13 @@
struct iax2_peer *peer=NULL;
time_t regseconds, nowtime;
int dynamic=0;
-
- if (peername)
- var = ast_load_realtime("iaxpeers", "name", peername, NULL);
- else {
- char iabuf[INET_ADDRSTRLEN];
+ char iabuf[INET_ADDRSTRLEN];
+
+ if (peername) {
+ var = ast_load_realtime("iaxpeers", "name", peername, "host", "dynamic", NULL);
+ if (!var)
+ var = ast_load_realtime("iaxpeers", "name", peername, "host", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
+ } else {
char porta[25];
ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
sprintf(porta, "%d", ntohs(sin->sin_port));
@@ -2641,6 +2643,29 @@
if (!strcasecmp(tmp->name, "name"))
peername = tmp->value;
tmp = tmp->next;
+ }
+ }
+ }
+ if (!var) { /* Last ditch effort */
+ var = ast_load_realtime("iaxpeers", "name", peername, NULL);
+ /*!\note
+ * If this one loaded something, then we need to ensure that the host
+ * field matched. The only reason why we can't have this as a criteria
+ * is because we only have the IP address and the host field might be
+ * set as a name (and the reverse PTR might not match).
+ */
+ if (var) {
+ for (tmp = var; tmp; tmp = tmp->next) {
+ if (!strcasecmp(tmp->name, "host")) {
+ struct in_addr sin2 = { 0, };
+ struct ast_dnsmgr_entry *dnsmgr = NULL;
+ if ((ast_dnsmgr_lookup(tmp->value, &sin2, &dnsmgr) < 0) || (memcmp(&sin2, &sin->sin_addr, sizeof(sin2)) != 0)) {
+ /* No match */
+ ast_variables_destroy(var);
+ var = NULL;
+ }
+ break;
+ }
}
}
}
@@ -2720,13 +2745,46 @@
return peer;
}
-static struct iax2_user *realtime_user(const char *username)
+static struct iax2_user *realtime_user(const char *username, struct sockaddr_in *sin)
{
struct ast_variable *var;
struct ast_variable *tmp;
struct iax2_user *user=NULL;
-
- var = ast_load_realtime("iaxusers", "name", username, NULL);
+ char iabuf[INET_ADDRSTRLEN];
+
+ var = ast_load_realtime("iaxusers", "name", username, "host", "dynamic", NULL);
+ if (!var && sin)
+ var = ast_load_realtime("iaxusers", "name", username, "host", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr));
+ if (!var && sin) {
+ char porta[6];
+ snprintf(porta, sizeof(porta), "%d", ntohs(sin->sin_port));
+ var = ast_load_realtime("iaxusers", "name", username, "ipaddr", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), "port", porta, NULL);
+ if (!var)
+ var = ast_load_realtime("iaxusers", "ipaddr", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), "port", porta, NULL);
+ }
+ if (!var) { /* Last ditch effort */
+ var = ast_load_realtime("iaxusers", "name", username, NULL);
+ /*!\note
+ * If this one loaded something, then we need to ensure that the host
+ * field matched. The only reason why we can't have this as a criteria
+ * is because we only have the IP address and the host field might be
+ * set as a name (and the reverse PTR might not match).
+ */
+ if (var) {
+ for (tmp = var; tmp; tmp = tmp->next) {
+ if (!strcasecmp(tmp->name, "host")) {
+ struct in_addr sin2 = { 0, };
+ struct ast_dnsmgr_entry *dnsmgr = NULL;
+ if ((ast_dnsmgr_lookup(tmp->value, &sin2, &dnsmgr) < 0) || (memcmp(&sin2, &sin->sin_addr, sizeof(sin2)) != 0)) {
+ /* No match */
+ ast_variables_destroy(var);
+ var = NULL;
+ }
+ break;
+ }
+ }
+ }
+ }
if (!var)
return NULL;
@@ -4878,7 +4936,7 @@
ast_mutex_unlock(&userl.lock);
user = best;
if (!user && !ast_strlen_zero(iaxs[callno]->username)) {
- user = realtime_user(iaxs[callno]->username);
+ user = realtime_user(iaxs[callno]->username, sin);
if (user && !ast_strlen_zero(iaxs[callno]->context) && /* No context specified */
!apply_context(user->contexts, iaxs[callno]->context)) { /* Context is permitted */
destroy_user(user);
Modified: branches/1.2-netsec/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.2-netsec/channels/chan_sip.c?view=diff&rev=93669&r1=93668&r2=93669
==============================================================================
--- branches/1.2-netsec/channels/chan_sip.c (original)
+++ branches/1.2-netsec/channels/chan_sip.c Tue Dec 18 12:34:29 2007
@@ -81,6 +81,7 @@
#include "asterisk/dnsmgr.h"
#include "asterisk/devicestate.h"
#include "asterisk/linkedlists.h"
+#include "asterisk/dnsmgr.h"
#ifdef OSP_SUPPORT
#include "asterisk/astosp.h"
@@ -1725,9 +1726,35 @@
char iabuf[80];
/* First check on peer name */
- if (newpeername)
- var = ast_load_realtime("sippeers", "name", peername, NULL);
- else if (sin) { /* Then check on IP address */
+ if (newpeername) {
+ var = ast_load_realtime("sippeers", "name", newpeername, "host", "dynamic", NULL);
+ if (!var && sin) {
+ var = ast_load_realtime("sippeers", "name", newpeername, "host", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), NULL);
+ if (!var) {
+ var = ast_load_realtime("sippeers", "name", newpeername, NULL);
+ /*!\note
+ * If this one loaded something, then we need to ensure that the host
+ * field matched. The only reason why we can't have this as a criteria
+ * is because we only have the IP address and the host field might be
+ * set as a name (and the reverse PTR might not match).
+ */
+ if (var) {
+ for (tmp = var; tmp; tmp = tmp->next) {
+ if (!strcasecmp(var->name, "host")) {
+ struct in_addr sin2 = { 0, };
+ struct ast_dnsmgr_entry *dnsmgr = NULL;
+ if ((ast_dnsmgr_lookup(tmp->value, &sin2, &dnsmgr) < 0) || (memcmp(&sin2, &sin->sin_addr, sizeof(sin2)) != 0)) {
+ /* No match */
+ ast_variables_destroy(var);
+ var = NULL;
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ } else if (sin) { /* Then check on IP address */
ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
var = ast_load_realtime("sippeers", "host", iabuf, NULL); /* First check for fixed IP hosts */
if (!var)
More information about the asterisk-commits
mailing list