Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcre2 #16

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build-and-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
sudo apt update &&
NEEDRESTART_SUSPEND=1 DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true sudo -E apt -y install
git build-essential cmake gcc linux-headers-`uname -r`
libpcre3-dev libssl-dev liblua5.1-0-dev kmod
libpcre2-dev libssl-dev liblua5.1-0-dev kmod
- name: Check out repository code
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
apt update && apt -y upgrade && apt -y dist-upgrade &&
NEEDRESTART_SUSPEND=1 DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt -y install git build-essential cmake gcc
linux-headers-${{ env.HEADERS_SUFFIX }}
libpcre3-dev libssl-dev liblua5.1-0-dev kmod
libpcre2-dev libssl-dev liblua5.1-0-dev kmod
- name: Get kernel name from headers
run: >
echo KERNEL_NAME=`ls -1 /usr/src/ | grep 'linux-headers.*${{ env.HEADERS_SUFFIX }}' |
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
run: >
apt update && apt -y upgrade && apt -y dist-upgrade &&
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt -y install git build-essential cmake gcc
linux-headers-generic libpcre3-dev libssl-dev liblua5.1-0-dev kmod software-properties-common
linux-headers-generic libpcre2-dev libssl-dev liblua5.1-0-dev kmod software-properties-common
pkexec dbus linux-base &&
add-apt-repository -y ppa:cappelikan/ppa && apt update &&
service dbus start &&
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
steps:
- name: Install build tools
run: >
apk update && apk add --no-cache git cmake make g++ pcre-dev libressl-dev linux-headers libucontext-dev lua5.1-dev
apk update && apk add --no-cache git cmake make g++ pcre2-dev libressl-dev linux-headers libucontext-dev lua5.1-dev
- name: Check out repository code
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:
- name: Install build tools
run: |
emerge -g --autounmask-write sys-kernel/gentoo-kernel-bin || (etc-update --verbose --automode -5 && emerge -g sys-kernel/gentoo-kernel-bin)
emerge -g dev-vcs/git dev-libs/libpcre dev-build/cmake dev-lang/lua:5.1
emerge -g dev-vcs/git dev-libs/libpcre2 dev-build/cmake dev-lang/lua:5.1
- name: Check out repository code
uses: actions/checkout@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
run: >
ssh -i ssh-key -p2222 user@localhost "sudo apt -y install
git build-essential cmake gcc linux-headers-\`uname -r\`
libpcre3-dev libssl-dev liblua5.1-0-dev kmod python3-pip
libpcre2-dev libssl-dev liblua5.1-0-dev kmod python3-pip
libxml2-dev libxslt1-dev zlib1g-dev
iproute2 ppp pppoe isc-dhcp-client timelimit &&
(sudo pip3 install pytest pytest-dependency pytest-order || sudo pip3 install --break-system-packages pytest pytest-dependency pytest-order)"
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
sudo apt update &&
NEEDRESTART_SUSPEND=1 DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true sudo -E apt -y install
git build-essential cmake gcc linux-headers-`uname -r`
libpcre3-dev libssl-dev liblua5.1-0-dev kmod python3-pip
libpcre2-dev libssl-dev liblua5.1-0-dev kmod python3-pip
iproute2 ppp pppoe isc-dhcp-client

- name: Install testing tools (using pip)
Expand Down Expand Up @@ -248,7 +248,7 @@ jobs:
sudo apt update &&
NEEDRESTART_SUSPEND=1 DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true sudo -E apt -y install
git build-essential cmake gcc linux-headers-`uname -r`
libpcre3-dev libssl-dev liblua5.1-0-dev kmod python3-pip
libpcre2-dev libssl-dev liblua5.1-0-dev kmod python3-pip
iproute2 ppp pppoe isc-dhcp-client

- name: Install testing tools (using pip)
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ ENDIF (NOT DEFINED LIB_SUFFIX)
#color console example message(FATAL_ERROR "${Esc}[31m Red Text ${Esc}[m Restore Normal Text")
string(ASCII 27 Esc)

#Check libpcre
find_library(PCRE_LIBRARY pcre
#Check libpcre2
find_library(PCRE2_LIBRARY pcre2-8
HINTS ${CMAKE_SOURCE_DIR}/lib/linux/gcc/${BIT}/lib
PATHS ${CMAKE_SOURCE_DIR}/lib/linux/gcc/${BIT}/lib
)

IF(NOT PCRE_LIBRARY)
message(FATAL_ERROR "${Esc}[31mRequired libpcre not found.\n Install libpcre3-dev and run cmake again${Esc}[m")
ENDIF(NOT PCRE_LIBRARY)
IF(NOT PCRE2_LIBRARY)
message(FATAL_ERROR "${Esc}[31mRequired libpcre not found.\n Install libpcre2-dev and run cmake again${Esc}[m")
ENDIF(NOT PCRE2_LIBRARY)


IF (EXISTS ${CMAKE_HOME_DIRECTORY}/.git AND NOT IGNORE_GIT)
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Requirment
4. cmake-2.6 or later
5. libnl-2.0 or probably later (required for builtin shaper)
6. libcrypto-0.9.8 or probably later (openssl-0.9.8)
7. libpcre
7. libpcre2
8. net-snmp-5.x
9. libssl-0.9.8 or probably later (openssl-0.9.8)

Expand Down
4 changes: 2 additions & 2 deletions accel-pppd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ CHECK_FUNCTION_EXISTS(getcontext HAVE_GETCONTEXT)
CHECK_FUNCTION_EXISTS(setcontext HAVE_SETCONTEXT)

IF (HAVE_GETCONTEXT AND HAVE_SETCONTEXT)
TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre)
TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre2-8)
ELSE (HAVE_GETCONTEXT AND HAVE_SETCONTEXT)
TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre ucontext)
TARGET_LINK_LIBRARIES(accel-pppd triton rt pthread ${crypto_lib} pcre2-8 ucontext)
ENDIF (HAVE_GETCONTEXT AND HAVE_SETCONTEXT)

set_property(TARGET accel-pppd PROPERTY CMAKE_SKIP_BUILD_RPATH FALSE)
Expand Down
64 changes: 13 additions & 51 deletions accel-pppd/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,51 +63,6 @@ void __export cli_register_simple_cmd2(
va_end(ap);
}

void __export cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd)
{
int err;
int erroffset;
const char *errptr;

if (cmd->exec == NULL) {
log_emerg("cli: impossible to register regexp command"
" without an execution callback function\n");
_exit(EXIT_FAILURE);
}
if (cmd->pattern == NULL) {
log_emerg("cli: impossible to register regexp command"
" without pattern\n");
_exit(EXIT_FAILURE);
}
cmd->re = pcre_compile2(cmd->pattern, cmd->options, &err,
&errptr, &erroffset, NULL);
if (!cmd->re) {
log_emerg("cli: failed to compile regexp \"%s\": %s (error %i)"
" at positon %i (unprocessed characters: \"%s\")\n",
cmd->pattern, errptr, err, erroffset,
cmd->pattern + erroffset);
_exit(EXIT_FAILURE);
}

if (cmd->h_pattern) {
cmd->h_re = pcre_compile2(cmd->h_pattern, cmd->h_options, &err,
&errptr, &erroffset, NULL);
if (!cmd->h_re) {
log_emerg("cli: failed to compile help regexp \"%s\":"
" %s (error %i) at position %i (unprocessed"
" characters: \"%s\")\n",
cmd->h_pattern, errptr, err, erroffset,
cmd->h_pattern + erroffset);
_exit(EXIT_FAILURE);
}
} else {
cmd->h_re = NULL;
cmd->h_pattern = NULL;
}

list_add_tail(&cmd->entry, &regexp_cmd_list);
}

int __export cli_send(void *client, const char *data)
{
struct cli_client_t *cln = (struct cli_client_t *)client;
Expand Down Expand Up @@ -189,13 +144,15 @@ static int cli_process_help_cmd(struct cli_client_t *cln)
cmd_found = 1;

list_for_each_entry(recmd, &regexp_cmd_list, entry) {
pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
if (cmd[0] == '\0'
|| pcre_exec(recmd->h_re, NULL, cmd, strlen(cmd),
0, 0, NULL, 0) >= 0) {
|| pcre2_match(recmd->h_re, (PCRE2_SPTR)cmd, strlen(cmd),
0, 0, match_data, NULL) >= 0) {
cmd_found = 1;
if (recmd->help)
recmd->help(cmd, cln);
}
pcre2_match_data_free(match_data);
}

nb_items = split(cmd, items);
Expand Down Expand Up @@ -230,14 +187,19 @@ static int cli_process_regexp_cmd(struct cli_client_t *cln, int *err)
int res;

cmd = skip_space(cmd);
list_for_each_entry(recmd, &regexp_cmd_list, entry)
if (pcre_exec(recmd->re, NULL, cmd, strlen(cmd),
0, 0, NULL, 0) >= 0) {
list_for_each_entry(recmd, &regexp_cmd_list, entry) {
pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
if (pcre2_match(recmd->re, (PCRE2_SPTR)cmd, strlen(cmd),
0, 0, match_data, NULL) >= 0) {
found = 1;
res = recmd->exec(cmd, cln);
if (res != CLI_CMD_OK)
if (res != CLI_CMD_OK) {
pcre2_match_data_free(match_data);
break;
}
}
pcre2_match_data_free(match_data);
}
if (found)
*err = res;

Expand Down
8 changes: 4 additions & 4 deletions accel-pppd/cli/cli.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef __CLI_H
#define __CLI_H

#include <pcre.h>
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>

#include "list.h"

Expand All @@ -23,11 +24,11 @@ struct cli_simple_cmd_t
struct cli_regexp_cmd_t
{
struct list_head entry;
pcre *re;
pcre2_code *re;
const char *pattern;
int options;
int (*exec)(const char *cmd, void *client);
pcre *h_re;
pcre2_code *h_re;
const char *h_pattern;
int h_options;
int (*help)(const char *cmd, void *client);
Expand All @@ -42,7 +43,6 @@ void cli_register_simple_cmd2(
int hdr_len,
...
);
void cli_register_regexp_cmd(struct cli_regexp_cmd_t *cmd);
void cli_show_ses_register(const char *name, const char *desc, void (*print)(struct ap_session *ses, char *buf));

int cli_send(void *client, const char *data);
Expand Down
19 changes: 12 additions & 7 deletions accel-pppd/cli/show_sessions.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
struct column_t *match_key = NULL;
char *match_pattern = NULL;
struct column_t *order_key = NULL;
pcre *re = NULL;
const char *pcre_err;
int pcre_offset;
pcre2_code *re = NULL;
int pcre_err;
PCRE2_SIZE pcre_offset;
struct column_t *column;
struct col_t *col;
struct row_t *row;
Expand Down Expand Up @@ -169,9 +169,11 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
}

if (match_key) {
re = pcre_compile2(match_pattern, 0, NULL, &pcre_err, &pcre_offset, NULL);
re = pcre2_compile((PCRE2_SPTR)match_pattern, PCRE2_ZERO_TERMINATED, 0, &pcre_err, &pcre_offset, NULL);
if (!re) {
cli_sendv(cli, "match: %s at %i\r\n", pcre_err, pcre_offset);
PCRE2_UCHAR err_msg[64];
pcre2_get_error_message(pcre_err, err_msg, sizeof(err_msg));
cli_sendv(cli, "match: %s at %i\r\n", err_msg, (int)pcre_offset);
return CLI_CMD_OK;
}
}
Expand Down Expand Up @@ -262,10 +264,13 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
row = list_entry(t_list.next, typeof(*row), entry);
list_del(&row->entry);
if (match_key) {
if (pcre_exec(re, NULL, row->match_key, strlen(row->match_key), 0, 0, NULL, 0) < 0) {
pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
if (pcre2_match(re, (PCRE2_SPTR)row->match_key, strlen(row->match_key), 0, 0, match_data, NULL) < 0) {
free_row(row);
pcre2_match_data_free(match_data);
continue;
}
pcre2_match_data_free(match_data);
}
if (order_key)
insert_row(&r_list, row);
Expand Down Expand Up @@ -362,7 +367,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
}

if (re)
pcre_free(re);
pcre2_code_free(re);

return CLI_CMD_OK;

Expand Down
20 changes: 13 additions & 7 deletions accel-pppd/cli/std_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
{
struct ap_session *ses;
int hard = 0;
pcre *re;
const char *pcre_err;
int pcre_offset;
pcre2_code *re;
int pcre_err;
PCRE2_SIZE pcre_offset;

if (f_cnt == 5) {
if (!strcmp(f[4], "hard"))
Expand All @@ -135,26 +135,32 @@ static int terminate_exec1(char * const *f, int f_cnt, void *cli)
} else if (f_cnt != 4)
return CLI_CMD_SYNTAX;

re = pcre_compile2(f[3], 0, NULL, &pcre_err, &pcre_offset, NULL);
re = pcre2_compile((PCRE2_SPTR)f[3], PCRE2_ZERO_TERMINATED, 0, &pcre_err, &pcre_offset, NULL);
if (!re) {
cli_sendv(cli, "match: %s at %i\r\n", pcre_err, pcre_offset);
PCRE2_UCHAR err_msg[64];
pcre2_get_error_message(pcre_err, err_msg, sizeof(err_msg));
cli_sendv(cli, "match: %s at %i\r\n", err_msg, (int)pcre_offset);
return CLI_CMD_OK;
}

pthread_rwlock_rdlock(&ses_lock);
list_for_each_entry(ses, &ses_list, entry) {
if (!ses->username)
continue;
if (pcre_exec(re, NULL, ses->username, strlen(ses->username), 0, 0, NULL, 0) < 0)
pcre2_match_data *match_data = pcre2_match_data_create(0, NULL);
if (pcre2_match(re, (PCRE2_SPTR)ses->username, strlen(ses->username), 0, 0, match_data, NULL) < 0) {
pcre2_match_data_free(match_data);
continue;
}
pcre2_match_data_free(match_data);
if (hard)
triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_hard, ses);
else
triton_context_call(ses->ctrl->ctx, (triton_event_func)__terminate_soft, ses);
}
pthread_rwlock_unlock(&ses_lock);

pcre_free(re);
pcre2_code_free(re);

return CLI_CMD_OK;
}
Expand Down
Loading
Loading