switch PCREPlugin to PCRE2

This commit is contained in:
Vladimir Dubrovin 2026-04-02 17:55:10 +03:00
parent 5d3d56dae1
commit 5fd5eb55c6
10 changed files with 209 additions and 62 deletions

View File

@ -25,7 +25,7 @@ jobs:
# run: ./configure # run: ./configure
- name: Linux libraries - name: Linux libraries
if: ${{ startsWith(matrix.target, 'ubuntu') }} if: ${{ startsWith(matrix.target, 'ubuntu') }}
run: sudo apt install libssl-dev libpam-dev libpcre3 libpcre3-dev run: sudo apt install libssl-dev libpam-dev libpcre2-dev
- name: make Ubuntu - name: make Ubuntu
if: ${{ startsWith(matrix.target, 'ubuntu') }} if: ${{ startsWith(matrix.target, 'ubuntu') }}
run: make -f Makefile.Linux run: make -f Makefile.Linux
@ -40,7 +40,7 @@ jobs:
run: make -f Makefile.Linux clean run: make -f Makefile.Linux clean
- name: Mac libraries - name: Mac libraries
if: ${{ startsWith(matrix.target, 'macos') }} if: ${{ startsWith(matrix.target, 'macos') }}
run: brew install pcre run: brew install pcre2
- name: make MacOS - name: make MacOS
if: ${{ startsWith(matrix.target, 'macos') }} if: ${{ startsWith(matrix.target, 'macos') }}
run: make -f Makefile.FreeBSD run: make -f Makefile.FreeBSD

View File

@ -27,7 +27,7 @@
FROM gcc AS buildenv FROM gcc AS buildenv
COPY . 3proxy COPY . 3proxy
RUN cd 3proxy &&\ RUN cd 3proxy &&\
apt update && apt install libssl-dev libpam-dev libpcre3 libpcre3-dev &&\ apt update && apt install libssl-dev libpam-dev libpcre2-dev &&\
make -f Makefile.Linux &&\ make -f Makefile.Linux &&\
strip bin/3proxy &&\ strip bin/3proxy &&\
strip bin/StringsPlugin.ld.so &&\ strip bin/StringsPlugin.ld.so &&\

View File

@ -39,7 +39,7 @@ PAM_CHECK = $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0
ifeq ($(PAM_CHECK), true) ifeq ($(PAM_CHECK), true)
PLUGINS += PamAuth PLUGINS += PamAuth
endif endif
PCRE_CHECK = $(shell echo "\#include <pcre.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false) PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true) ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin PLUGINS += PCREPlugin
endif endif

View File

@ -41,7 +41,7 @@ ifeq ($(OPENSSL_CHECK), true)
LIBS += -l crypto -l ssl LIBS += -l crypto -l ssl
PLUGINS += SSLPlugin PLUGINS += SSLPlugin
endif endif
PCRE_CHECK = $(shell echo "\#include <pcre.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false) PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true) ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin PLUGINS += PCREPlugin
endif endif

View File

@ -41,7 +41,7 @@ ifeq ($(OPENSSL_CHECK), true)
LIBS += -l crypto -l ssl LIBS += -l crypto -l ssl
PLUGINS += SSLPlugin PLUGINS += SSLPlugin
endif endif
PCRE_CHECK = $(shell echo "\#include <pcre.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false) PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true) ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin PLUGINS += PCREPlugin
endif endif

View File

@ -43,7 +43,7 @@ PAM_CHECK = $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0
ifeq ($(PAM_CHECK), true) ifeq ($(PAM_CHECK), true)
PLUGINS += PamAuth PLUGINS += PamAuth
endif endif
PCRE_CHECK = $(shell echo "\#include <pcre.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false) PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n\#include <pcre2.h>\\n int main(){return 0;}" | tr -d \\\\ | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true) ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin PLUGINS += PCREPlugin
endif endif

View File

@ -40,7 +40,7 @@ ifeq ($(OPENSSL_CHECK), true)
LIBS += -l crypto -l ssl LIBS += -l crypto -l ssl
PLUGINS += SSLPlugin PLUGINS += SSLPlugin
endif endif
PCRE_CHECK = $(shell echo "#include <pcre.h>\\n int main(){return 0;}" | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false) PCRE_CHECK = $(shell echo "#define PCRE2_CODE_UNIT_WIDTH 8\\n#include <pcre2.h>\\n int main(){return 0;}" | cc -x c $(CFLAGS) $(LDFLAGS) -l pcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
ifeq ($(PCRE_CHECK), true) ifeq ($(PCRE_CHECK), true)
PLUGINS += PCREPlugin PLUGINS += PCREPlugin
endif endif

2
README
View File

@ -141,7 +141,7 @@ make
+ All access control entries now support weekday and time limitations + All access control entries now support weekday and time limitations
+ Hostnames and * templates are supported instead of IP address + Hostnames and * templates are supported instead of IP address
5. Extensions 5. Extensions
+ Regular expression filtering (with PCRE) via PCREPlugin + Regular expression filtering (with PCRE2) via PCREPlugin
+ Authentication with Windows username/password (cleartext only) + Authentication with Windows username/password (cleartext only)
+ SSL/TLS decryptions with certificate spoofing + SSL/TLS decryptions with certificate spoofing
+ Transparent redirection support for Linux and *BSD + Transparent redirection support for Linux and *BSD

View File

@ -1,4 +1,4 @@
all: $(BUILDDIR)PCREPlugin$(DLSUFFICS) all: $(BUILDDIR)PCREPlugin$(DLSUFFICS)
$(BUILDDIR)PCREPlugin$(DLSUFFICS): pcre_plugin$(OBJSUFFICS) $(BUILDDIR)PCREPlugin$(DLSUFFICS): pcre_plugin$(OBJSUFFICS)
$(LN) $(LNOUT)../../$(BUILDDIR)PCREPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) pcre_plugin$(OBJSUFFICS) $(LIBSPREFIX)pcre$(LIBSSUFFIX) $(LN) $(LNOUT)../../$(BUILDDIR)PCREPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) pcre_plugin$(OBJSUFFICS) $(LIBSPREFIX)pcre2-8$(LIBSSUFFIX)

View File

@ -7,7 +7,8 @@
#include "../../structures.h" #include "../../structures.h"
#include <string.h> #include <string.h>
#include <pcre.h> #define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -34,46 +35,76 @@ static struct filter pcre_first_filter = {
static struct filter *pcre_last_filter; static struct filter *pcre_last_filter;
static int pcre_loaded = 0; static int pcre_loaded = 0;
static int pcre_options = 0; static uint32_t pcre_options = 0;
static struct pcreopt { static struct pcreopt {
char * name; char * name;
int value; uint32_t value;
} pcreopts[]= { } pcreopts[]= {
{"PCRE_CASELESS", PCRE_CASELESS}, {"PCRE2_ALLOW_EMPTY_CLASS", PCRE2_ALLOW_EMPTY_CLASS},
{"PCRE_MULTILINE", PCRE_MULTILINE}, {"PCRE2_ALT_BSUX", PCRE2_ALT_BSUX},
{"PCRE_DOTALL", PCRE_DOTALL}, {"PCRE2_AUTO_CALLOUT", PCRE2_AUTO_CALLOUT},
{"PCRE_EXTENDED", PCRE_EXTENDED}, {"PCRE2_CASELESS", PCRE2_CASELESS},
{"PCRE_ANCHORED", PCRE_ANCHORED}, {"PCRE2_DOLLAR_ENDONLY", PCRE2_DOLLAR_ENDONLY},
{"PCRE_DOLLAR_ENDONLY", PCRE_DOLLAR_ENDONLY}, {"PCRE2_DOTALL", PCRE2_DOTALL},
{"PCRE_EXTRA", PCRE_EXTRA}, {"PCRE2_DUPNAMES", PCRE2_DUPNAMES},
{"PCRE_NOTBOL", PCRE_NOTBOL}, {"PCRE2_EXTENDED", PCRE2_EXTENDED},
{"PCRE_NOTEOL", PCRE_NOTEOL}, {"PCRE2_FIRSTLINE", PCRE2_FIRSTLINE},
{"PCRE_UNGREEDY", PCRE_UNGREEDY}, {"PCRE2_MATCH_UNSET_BACKREF", PCRE2_MATCH_UNSET_BACKREF},
{"PCRE_NOTEMPTY", PCRE_NOTEMPTY}, {"PCRE2_MULTILINE", PCRE2_MULTILINE},
{"PCRE_UTF8", PCRE_UTF8}, {"PCRE2_NEVER_UCP", PCRE2_NEVER_UCP},
{"PCRE_NO_AUTO_CAPTURE", PCRE_NO_AUTO_CAPTURE}, {"PCRE2_NEVER_UTF", PCRE2_NEVER_UTF},
{"PCRE_NO_UTF8_CHECK", PCRE_NO_UTF8_CHECK}, {"PCRE2_NO_AUTO_CAPTURE", PCRE2_NO_AUTO_CAPTURE},
{"PCRE_AUTO_CALLOUT", PCRE_AUTO_CALLOUT}, {"PCRE2_NO_AUTO_POSSESS", PCRE2_NO_AUTO_POSSESS},
{"PCRE_PARTIAL", PCRE_PARTIAL}, {"PCRE2_NO_DOTSTAR_ANCHOR", PCRE2_NO_DOTSTAR_ANCHOR},
{"PCRE_DFA_SHORTEST", PCRE_DFA_SHORTEST}, {"PCRE2_NO_START_OPTIMIZE", PCRE2_NO_START_OPTIMIZE},
{"PCRE_DFA_RESTART", PCRE_DFA_RESTART}, {"PCRE2_UCP", PCRE2_UCP},
{"PCRE_FIRSTLINE", PCRE_FIRSTLINE}, {"PCRE2_UNGREEDY", PCRE2_UNGREEDY},
{"PCRE_DUPNAMES", PCRE_DUPNAMES}, {"PCRE2_UTF", PCRE2_UTF},
{"PCRE_NEWLINE_CR", PCRE_NEWLINE_CR}, {"PCRE2_NEVER_BACKSLASH_C", PCRE2_NEVER_BACKSLASH_C},
{"PCRE_NEWLINE_LF", PCRE_NEWLINE_LF}, {"PCRE2_ALT_CIRCUMFLEX", PCRE2_ALT_CIRCUMFLEX},
{"PCRE_NEWLINE_CRLF", PCRE_NEWLINE_CRLF}, {"PCRE2_ALT_VERBNAMES", PCRE2_ALT_VERBNAMES},
{"PCRE_NEWLINE_ANY", PCRE_NEWLINE_ANY}, {"PCRE2_USE_OFFSET_LIMIT", PCRE2_USE_OFFSET_LIMIT},
{"PCRE_NEWLINE_ANYCRLF", PCRE_NEWLINE_ANYCRLF}, {"PCRE2_EXTENDED_MORE", PCRE2_EXTENDED_MORE},
{"PCRE_BSR_ANYCRLF", PCRE_BSR_ANYCRLF}, {"PCRE2_LITERAL", PCRE2_LITERAL},
{"PCRE_BSR_UNICODE", PCRE_BSR_UNICODE}, {"PCRE2_MATCH_INVALID_UTF", PCRE2_MATCH_INVALID_UTF},
{"PCRE_CASELESS", PCRE2_CASELESS},
{"PCRE_MULTILINE", PCRE2_MULTILINE},
{"PCRE_DOTALL", PCRE2_DOTALL},
{"PCRE_EXTENDED", PCRE2_EXTENDED},
{"PCRE_ANCHORED", PCRE2_ANCHORED},
{"PCRE_DOLLAR_ENDONLY", PCRE2_DOLLAR_ENDONLY},
{"PCRE_EXTRA", PCRE2_EXTENDED_MORE},
{"PCRE_NOTBOL", PCRE2_NOTBOL},
{"PCRE_NOTEOL", PCRE2_NOTEOL},
{"PCRE_UNGREEDY", PCRE2_UNGREEDY},
{"PCRE_NOTEMPTY", PCRE2_NOTEMPTY},
{"PCRE_UTF8", PCRE2_UTF},
{"PCRE_NO_AUTO_CAPTURE", PCRE2_NO_AUTO_CAPTURE},
{"PCRE_NO_UTF8_CHECK", PCRE2_MATCH_INVALID_UTF},
{"PCRE_AUTO_CALLOUT", PCRE2_AUTO_CALLOUT},
{"PCRE_PARTIAL", PCRE2_PARTIAL_SOFT},
{"PCRE_DFA_SHORTEST", PCRE2_DFA_SHORTEST},
{"PCRE_DFA_RESTART", PCRE2_DFA_RESTART},
{"PCRE_FIRSTLINE", PCRE2_FIRSTLINE},
{"PCRE_DUPNAMES", PCRE2_DUPNAMES},
{"PCRE_NEWLINE_CR", PCRE2_NEWLINE_CR},
{"PCRE_NEWLINE_LF", PCRE2_NEWLINE_LF},
{"PCRE_NEWLINE_CRLF", PCRE2_NEWLINE_CRLF},
{"PCRE_NEWLINE_ANY", PCRE2_NEWLINE_ANY},
{"PCRE_NEWLINE_ANYCRLF", PCRE2_NEWLINE_ANYCRLF},
{"PCRE_BSR_ANYCRLF", PCRE2_BSR_ANYCRLF},
{"PCRE_BSR_UNICODE", PCRE2_BSR_UNICODE},
{NULL, 0} {NULL, 0}
}; };
struct pcre_filter_data { struct pcre_filter_data {
int users; int users;
pcre * re; pcre2_code * re;
pcre2_match_data * match_data;
int action; int action;
char * replace; char * replace;
struct ace *acl; struct ace *acl;
@ -83,7 +114,8 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){
pthread_mutex_lock(&pcre_mutex); pthread_mutex_lock(&pcre_mutex);
pcrefd->users--; pcrefd->users--;
if(!pcrefd->users){ if(!pcrefd->users){
if(pcrefd->re) pl->freefunc(pcrefd->re); if(pcrefd->match_data) pcre2_match_data_free(pcrefd->match_data);
if(pcrefd->re) pcre2_code_free(pcrefd->re);
if(pcrefd->acl) pl->freeacl(pcrefd->acl); if(pcrefd->acl) pl->freeacl(pcrefd->acl);
if(pcrefd->replace) pl->freefunc(pcrefd->replace); if(pcrefd->replace) pl->freefunc(pcrefd->replace);
pl->freefunc(pcrefd); pl->freefunc(pcrefd);
@ -123,7 +155,7 @@ static FILTER_ACTION pcre_filter_client(void *fo, struct clientparam * param, vo
} }
static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){
int ovector[48]; PCRE2_SIZE *ovector;
int count = 0; int count = 0;
struct ace *acl; struct ace *acl;
int match = 0; int match = 0;
@ -143,8 +175,9 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
if(!pcrefd->re) return pcrefd->action; if(!pcrefd->re) return pcrefd->action;
for(; offset < *length_p; nreplaces++){ for(; offset < *length_p; nreplaces++){
count = pcre_exec(pcrefd->re, NULL, (char *)*buf_p, *length_p, offset, 0, ovector, 48); count = pcre2_match(pcrefd->re, (PCRE2_SPTR)*buf_p, *length_p, offset, 0, pcrefd->match_data, NULL);
if(count <= 0) break; if(count <= 0) break;
ovector = pcre2_get_ovector_pointer(pcrefd->match_data);
if(!(replace = pcrefd->replace) || param->nooverwritefilter) return pcrefd->action; if(!(replace = pcrefd->replace) || param->nooverwritefilter) return pcrefd->action;
replen = *length_p - ovector[1]; replen = *length_p - ovector[1];
@ -220,10 +253,11 @@ static void pcre_filter_close(void *fo){
static int h_pcre(int argc, unsigned char **argv){ static int h_pcre(int argc, unsigned char **argv){
int action = 0; int action = 0;
pcre *re = NULL; pcre2_code *re = NULL;
pcre2_match_data *match_data = NULL;
struct ace *acl; struct ace *acl;
int offset = 4; int errcode;
const char * errptr; PCRE2_SIZE erroffset;
struct pcre_filter_data *flt; struct pcre_filter_data *flt;
struct filter *newf; struct filter *newf;
char *replace = NULL; char *replace = NULL;
@ -235,7 +269,6 @@ static int h_pcre(int argc, unsigned char **argv){
else return 1; else return 1;
if(!strncmp((char *)argv[0], "pcre_rewrite", 12)) { if(!strncmp((char *)argv[0], "pcre_rewrite", 12)) {
int i,j; int i,j;
offset = 5;
replace = pl->strdupfunc((char *)argv[4]); replace = pl->strdupfunc((char *)argv[4]);
if(!replace) return 9; if(!replace) return 9;
for(i=0, j=0; replace[i]; i++, j++){ for(i=0, j=0; replace[i]; i++, j++){
@ -264,22 +297,30 @@ static int h_pcre(int argc, unsigned char **argv){
} }
replace[j] = 0; replace[j] = 0;
} }
if(!(acl = pl->make_ace(argc - offset, argv + offset))) return 2; if(!(acl = pl->make_ace(argc - 4, argv + 4))) return 2;
acl->nolog = (strstr((char *)argv[2],"log") == 0); acl->nolog = (strstr((char *)argv[2],"log") == 0);
if(*argv[3] && !(*argv[3] == '*' && !argv[3][1]) ){ if(*argv[3] && !(*argv[3] == '*' && !argv[3][1]) ){
re = pcre_compile((char *)argv[3], pcre_options, &errptr, &offset, NULL); re = pcre2_compile((PCRE2_SPTR)argv[3], PCRE2_ZERO_TERMINATED, pcre_options, &errcode, &erroffset, NULL);
if(!re) { if(!re) {
pl->freefunc(acl); pl->freefunc(acl);
if(replace) pl->freefunc(replace); if(replace) pl->freefunc(replace);
return 3; return 3;
} }
match_data = pcre2_match_data_create_from_pattern(re, NULL);
if(!match_data) {
pcre2_code_free(re);
pl->freefunc(acl);
if(replace) pl->freefunc(replace);
return 4;
}
} }
flt = pl->mallocfunc(sizeof(struct pcre_filter_data)); flt = pl->mallocfunc(sizeof(struct pcre_filter_data));
newf = pl->mallocfunc(sizeof(struct filter)); newf = pl->mallocfunc(sizeof(struct filter));
if(!flt || !newf) { if(!flt || !newf) {
if(match_data) pcre2_match_data_free(match_data);
if(re) pcre2_code_free(re);
pl->freefunc(acl); pl->freefunc(acl);
pl->freefunc(re);
if(replace) pl->freefunc(replace); if(replace) pl->freefunc(replace);
if(flt) pl->freefunc(flt); if(flt) pl->freefunc(flt);
return 4; return 4;
@ -288,6 +329,114 @@ static int h_pcre(int argc, unsigned char **argv){
memset(newf, 0, sizeof(struct filter)); memset(newf, 0, sizeof(struct filter));
flt->action = action; flt->action = action;
flt->re = re; flt->re = re;
flt->match_data = match_data;
flt->acl = acl;
flt->replace = replace;
flt->users = 1;
newf->instance = "pcre";
newf->data = flt;
newf->filter_open = pcre_filter_open;
newf->filter_client = pcre_filter_client;
if(strstr((char *)argv[1], "request"))newf->filter_request = pcre_filter_buffer;
if(strstr((char *)argv[1], "cliheader"))newf->filter_header_cli = pcre_filter_buffer;
if(strstr((char *)argv[1], "clidata"))newf->filter_data_cli = pcre_filter_buffer;
if(strstr((char *)argv[1], "srvheader"))newf->filter_header_srv = pcre_filter_buffer;
if(strstr((char *)argv[1], "srvdata"))newf->filter_data_srv = pcre_filter_buffer;
newf->filter_clear = pcre_filter_clear;
newf->filter_close = pcre_filter_close;
if(!pcre_last_filter){
newf->next = pcre_first_filter.next;
pcre_first_filter.next=newf;
}
else {
newf->next = pcre_last_filter->next;
pcre_last_filter->next = newf;
}
pcre_last_filter=newf;
return 0;
}
static int h_pcre_rewrite(int argc, unsigned char **argv){
int action = 0;
pcre2_code *re = NULL;
pcre2_match_data *match_data = NULL;
struct ace *acl;
int errcode;
PCRE2_SIZE erroffset;
struct pcre_filter_data *flt;
struct filter *newf;
char *replace = NULL;
if(!strncmp((char *)argv[2], "allow",5)) action = PASS;
else if(!strncmp((char *)argv[2], "deny",4)) action = REJECT;
else if(!strncmp((char *)argv[2], "remove",6)) action = REMOVE;
else if(!strncmp((char *)argv[2], "dunno",5)) action = CONTINUE;
else return 1;
{
int i,j;
replace = pl->strdupfunc((char *)argv[4]);
if(!replace) return 9;
for(i=0, j=0; replace[i]; i++, j++){
if(replace[i] == '\\'){
switch(replace[i+1]){
case 'r':
i++;
replace[j] = '\r';
break;
case 'n':
i++;
replace[j] = '\n';
break;
case '0':
i++;
replace[j] = 0;
break;
case '\\':
i++;
default:
replace[j] = '\\';
break;
}
}
else replace[j] = replace[i];
}
replace[j] = 0;
}
if(!(acl = pl->make_ace(argc - 5, argv + 5))) return 2;
acl->nolog = (strstr((char *)argv[2],"log") == 0);
if(*argv[3] && !(*argv[3] == '*' && !argv[3][1]) ){
re = pcre2_compile((PCRE2_SPTR)argv[3], PCRE2_ZERO_TERMINATED, pcre_options, &errcode, &erroffset, NULL);
if(!re) {
pl->freefunc(acl);
if(replace) pl->freefunc(replace);
return 3;
}
match_data = pcre2_match_data_create_from_pattern(re, NULL);
if(!match_data) {
pcre2_code_free(re);
pl->freefunc(acl);
if(replace) pl->freefunc(replace);
return 4;
}
}
flt = pl->mallocfunc(sizeof(struct pcre_filter_data));
newf = pl->mallocfunc(sizeof(struct filter));
if(!flt || !newf) {
if(match_data) pcre2_match_data_free(match_data);
if(re) pcre2_code_free(re);
pl->freefunc(acl);
if(replace) pl->freefunc(replace);
if(flt) pl->freefunc(flt);
return 4;
}
memset(flt, 0, sizeof(struct pcre_filter_data));
memset(newf, 0, sizeof(struct filter));
flt->action = action;
flt->re = re;
flt->match_data = match_data;
flt->acl = acl; flt->acl = acl;
flt->replace = replace; flt->replace = replace;
flt->users = 1; flt->users = 1;
@ -342,14 +491,14 @@ static int h_pcre_options(int argc, unsigned char **argv){
static struct commands pcre_commandhandlers[] = { static struct commands pcre_commandhandlers[] = {
{pcre_commandhandlers+1, "pcre", h_pcre, 4, 0}, {pcre_commandhandlers+1, "pcre", h_pcre, 4, 0},
{pcre_commandhandlers+2, "pcre_rewrite", h_pcre, 5, 0}, {pcre_commandhandlers+2, "pcre_rewrite", h_pcre_rewrite, 5, 0},
{pcre_commandhandlers+3, "pcre_extend", h_pcre_extend, 2, 0}, {pcre_commandhandlers+3, "pcre_extend", h_pcre_extend, 2, 0},
{NULL, "pcre_options", h_pcre_options, 2, 0} {NULL, "pcre_options", h_pcre_options, 2, 0}
}; };
static struct symbol regexp_symbols[] = { static struct symbol regexp_symbols[] = {
{regexp_symbols+1, "pcre_compile", (void*) pcre_compile}, {regexp_symbols+1, "pcre2_compile", (void*) pcre2_compile},
{regexp_symbols+2, "pcre_exec", (void*) pcre_exec}, {regexp_symbols+2, "pcre2_match", (void*) pcre2_match},
{NULL, "pcre_options", (void *)&pcre_options}, {NULL, "pcre_options", (void *)&pcre_options},
}; };
@ -366,8 +515,6 @@ PLUGINAPI int PLUGINCALL pcre_plugin (struct pluginlink * pluginlink,
pl = pluginlink; pl = pluginlink;
pcre_options = 0; pcre_options = 0;
if(!pcre_loaded){ if(!pcre_loaded){
pcre_malloc = pl->mallocfunc;
pcre_free = pl->freefunc;
pcre_loaded = 1; pcre_loaded = 1;
pthread_mutex_init(&pcre_mutex, NULL); pthread_mutex_init(&pcre_mutex, NULL);
regexp_symbols[2].next = pl->symbols.next; regexp_symbols[2].next = pl->symbols.next;