Skip to content
Snippets Groups Projects
Commit ddcb5ea3 authored by Lukasz Kotasa's avatar Lukasz Kotasa
Browse files

Revert "Disable registrar account after failing to register for several times in a row, REF 16825"

This reverts commit bcd55530.
parent 2bd65a09
No related branches found
No related tags found
1 merge request!346Revert "Disable registrar account after failing to register for several times in a row, REF 16825"
...@@ -21,10 +21,6 @@ include $(ASTTOPDIR)/Makefile.moddir_rules ...@@ -21,10 +21,6 @@ include $(ASTTOPDIR)/Makefile.moddir_rules
LIBS += ../main/dt_logger.o LIBS += ../main/dt_logger.o
ifneq ($(DATAMODEL_UCI_PATH),)
_ASTCFLAGS += -DUCI_CONFIG_DIR=\"$(DATAMODEL_UCI_PATH)\"
endif
ifneq ($(findstring $(OSARCH), mingw32 cygwin ),) ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
# cygwin has some dependencies among res_ things. # cygwin has some dependencies among res_ things.
# We use order-only dependencies, and then add the libraries as required. # We use order-only dependencies, and then add the libraries as required.
...@@ -34,7 +30,6 @@ endif ...@@ -34,7 +30,6 @@ endif
res_pjsip_pubsub.so: LIBS+=-lubus -lubox -lpicoevent res_pjsip_pubsub.so: LIBS+=-lubus -lubox -lpicoevent
res_pjsip_outbound_registration.so: LIBS+=-lubus -lubox -lpicoevent res_pjsip_outbound_registration.so: LIBS+=-lubus -lubox -lpicoevent
res_pjsip.so: LIBS+=-luci
res_config_ldap.o: _ASTCFLAGS+=-DLDAP_DEPRECATED res_config_ldap.o: _ASTCFLAGS+=-DLDAP_DEPRECATED
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "asterisk.h" #include "asterisk.h"
#include <pjsip.h> #include <pjsip.h>
#include <uci.h>
#include "asterisk/res_pjsip.h" #include "asterisk/res_pjsip.h"
#include "asterisk/acl.h" #include "asterisk/acl.h"
...@@ -28,11 +27,6 @@ ...@@ -28,11 +27,6 @@
#include "asterisk/threadpool.h" #include "asterisk/threadpool.h"
#include "asterisk/res_pjsip_cli.h" #include "asterisk/res_pjsip_cli.h"
#ifndef UCI_CONFIG_DIR
#define UCI_CONFIG_DIR "/etc/config/"
#endif
static const char uciStrConfig[] = "asterisk";
static int distribute(void *data); static int distribute(void *data);
static pj_bool_t distributor(pjsip_rx_data *rdata); static pj_bool_t distributor(pjsip_rx_data *rdata);
static pj_status_t record_serializer(pjsip_tx_data *tdata); static pj_status_t record_serializer(pjsip_tx_data *tdata);
...@@ -883,77 +877,6 @@ static int apply_endpoint_contact_acl(pjsip_rx_data *rdata, struct ast_sip_endpo ...@@ -883,77 +877,6 @@ static int apply_endpoint_contact_acl(pjsip_rx_data *rdata, struct ast_sip_endpo
return forbidden; return forbidden;
} }
static void disable_registrar_uci(char* registrar)
{
struct uci_context *context = NULL;
struct uci_package *package = NULL;
struct uci_section *section = NULL;
struct uci_element *element = NULL;
struct uci_ptr ptr = {0};
char option_enable[32];
const char *ext_number = NULL, *ext_provider = NULL;
int res;
FILE *fp = NULL;
char file_name[32] = "";
char package_path[32];
context = uci_alloc_context();
if (!context) {
ast_log(LOG_ERROR, "failed to alloc context %s\n");
return;
}
uci_set_confdir(context, UCI_CONFIG_DIR);
snprintf(package_path, sizeof(package_path), "%s%s", UCI_CONFIG_DIR, uciStrConfig);
res = uci_load(context, package_path, &package);
if (res != 0 || !package) {
ast_log(LOG_ERROR, "failed to load load uci, conf dir: %s, conf file: %s\n", UCI_CONFIG_DIR, uciStrConfig);
} else {
uci_foreach_element(&package->sections, element) {
section = uci_to_section(element);
if (strcasecmp(section->type, "extension") == 0) {
ext_number = uci_lookup_option_string(context, section, "extension_number");
if (ext_number && strcasecmp(ext_number, registrar) == 0) {
ext_provider = uci_lookup_option_string(context, section, "provider");
if (ext_provider) {
snprintf(option_enable, sizeof(option_enable), "asterisk.%s.enable", ext_provider);
if (uci_lookup_ptr(context, &ptr, option_enable, true)) {
ast_log(LOG_ERROR, "Failed to find section %s\n", option_enable);
} else {
ptr.value = "2";
if (uci_set(context, &ptr) != UCI_OK) {
ast_log(LOG_ERROR, "Failed to uci_set, package: %s\n", ptr.package);
} else {
if (uci_commit(context, &ptr.p, true) != UCI_OK) {
ast_log(LOG_ERROR, "Failed to uci_commit\n");
} else {
snprintf(file_name, sizeof(file_name), "/tmp/registrar.%s", ext_provider);
break;
}
}
}
}
}
}
}
}
// Free the memory
if (package)
uci_unload(context, package);
if (context)
uci_free_context(context);
// create /tmp/registrar.ext_provider file and reload asterisk
// reload will trigger config_asterisk.sh re-run
if (file_name[0] != '\0') {
fp = fopen(file_name, "w");
if (fp) {
fclose(fp);
}
system("systemctl reload asterisk");
}
}
static pj_bool_t authenticate(pjsip_rx_data *rdata) static pj_bool_t authenticate(pjsip_rx_data *rdata)
{ {
RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_pjsip_rdata_get_endpoint(rdata), ao2_cleanup); RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_pjsip_rdata_get_endpoint(rdata), ao2_cleanup);
...@@ -968,7 +891,6 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata) ...@@ -968,7 +891,6 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata)
if (ast_sip_requires_authentication(endpoint, rdata)) { if (ast_sip_requires_authentication(endpoint, rdata)) {
pjsip_tx_data *tdata; pjsip_tx_data *tdata;
struct unidentified_request *unid; struct unidentified_request *unid;
char client[24] = {0};
pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 401, NULL, &tdata); pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 401, NULL, &tdata);
switch (ast_sip_check_authentication(endpoint, rdata, tdata)) { switch (ast_sip_check_authentication(endpoint, rdata, tdata)) {
...@@ -991,6 +913,7 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata) ...@@ -991,6 +913,7 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata)
case AST_SIP_AUTHENTICATION_FAILED: case AST_SIP_AUTHENTICATION_FAILED:
pjsip_tx_data_dec_ref(tdata); // dec_ref for tdata with 401 pjsip_tx_data_dec_ref(tdata); // dec_ref for tdata with 401
pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, &tdata); // create tdata with 403 pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, &tdata); // create tdata with 403
if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) { if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) {
pjsip_tx_data_dec_ref(tdata); pjsip_tx_data_dec_ref(tdata);
} }
...@@ -1000,14 +923,9 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata) ...@@ -1000,14 +923,9 @@ static pj_bool_t authenticate(pjsip_rx_data *rdata)
pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
if (contact_hdr && contact_hdr->uri) { if (contact_hdr && contact_hdr->uri) {
pjsip_sip_uri *client_uri = pjsip_uri_get_uri(contact_hdr->uri); pjsip_sip_uri *client_uri = pjsip_uri_get_uri(contact_hdr->uri);
/* IPX101 and disable registrar */ /* IPX101 */
if (client_uri) { if (client_uri) {
ast_log_dt(LOG_EVENT_CODE_IPX101, (int) client_uri->user.slen, client_uri->user.ptr, 403, (int) client_uri->host.slen, client_uri->host.ptr); ast_log_dt(LOG_EVENT_CODE_IPX101, (int) client_uri->user.slen, client_uri->user.ptr, 403, (int) client_uri->host.slen, client_uri->host.ptr);
ast_copy_pj_str(client, &client_uri->user, sizeof(client));
if (client[0] != '\0') {
disable_registrar_uci(client);
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment