mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-18 11:50:57 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3555ac775 | |||
| 22a822e259 | |||
| eeaddab5b0 | |||
| e6b8985090 | |||
| b3cf8df094 | |||
| 806bf69eae | |||
| 4a433ae438 | |||
| cc147e7cae | |||
| c5953d152b | |||
| 7b697a5e97 | |||
| 4a23ca80f2 | |||
| 2066113885 | |||
| 9fba1e1967 | |||
| fda32b6105 | |||
| f491714658 | |||
| 72f53966fc | |||
| be73ecbf9c | |||
|
|
4b6bca7b0d | ||
|
|
0a153bfdb4 | ||
|
|
ad8681f0d1 |
33
.woodpecker/build.yaml
Normal file
33
.woodpecker/build.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
matrix:
|
||||
platform:
|
||||
- linux/amd64
|
||||
|
||||
labels:
|
||||
platform: ${platform}
|
||||
|
||||
steps:
|
||||
build-berkeley:
|
||||
when:
|
||||
event: [push]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev db db-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure build
|
||||
- ninja -C build
|
||||
- rm -f test.db
|
||||
- build/dbtool -d test.db -i -k "test" -v "blah blah blah"
|
||||
- build/dbtool -d test.db -D | grep blah
|
||||
|
||||
build-gdbm:
|
||||
when:
|
||||
event: [push]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure build
|
||||
- ninja -C build
|
||||
- rm -f test.db
|
||||
- build/dbtool -d test.db -i -k "test" -v "blah blah blah"
|
||||
- build/dbtool -d test.db -D | grep blah
|
||||
54
.woodpecker/release.sh
Executable file
54
.woodpecker/release.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is my own simple codeberg generic releaser. It takes to
|
||||
# binaries to be uploaded as arguments and takes every other args from
|
||||
# env. Works on tags or normal commits (push), tags must start with v.
|
||||
|
||||
|
||||
set -e
|
||||
|
||||
die() {
|
||||
echo $*
|
||||
exit 1
|
||||
}
|
||||
|
||||
if test -z "$DEPLOY_TOKEN"; then
|
||||
die "token DEPLOY_TOKEN not set"
|
||||
fi
|
||||
|
||||
git fetch --all
|
||||
|
||||
# determine current tag or commit hash
|
||||
version="$CI_COMMIT_TAG"
|
||||
previous=""
|
||||
log=""
|
||||
if test -z "$version"; then
|
||||
version="${CI_COMMIT_SHA:0:6}"
|
||||
log=$(git log -1 --oneline)
|
||||
else
|
||||
previous=$(git tag -l | grep -E "^v" | tac | grep -A1 "$version" | tail -1)
|
||||
log=$(git log -1 --oneline "${previous}..${version}" | sed 's|^|- |g')
|
||||
fi
|
||||
|
||||
# release body
|
||||
printf "# Changes\n\n %s\n" "$log" > body.txt
|
||||
|
||||
# create the release
|
||||
https --ignore-stdin --check-status -b -A bearer -a "$DEPLOY_TOKEN" POST \
|
||||
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases" \
|
||||
tag_name="$version" name="Release $version" body=@body.txt > release.json
|
||||
|
||||
# we need the id to upload files
|
||||
ID=$(jq -r .id < release.json)
|
||||
|
||||
if test -z "$ID"; then
|
||||
cat release.json
|
||||
die "failed to create release"
|
||||
fi
|
||||
|
||||
# actually upload
|
||||
for file in "$@"; do
|
||||
https --ignore-stdin --check-status -A bearer -a "$DEPLOY_TOKEN" -f POST \
|
||||
"https://codeberg.org/api/v1/repos/${CI_REPO_OWNER}/${CI_REPO_NAME}/releases/$ID/assets" \
|
||||
"name=${file}-${version}" "attachment@${file}"
|
||||
done
|
||||
29
.woodpecker/release.yaml
Normal file
29
.woodpecker/release.yaml
Normal file
@@ -0,0 +1,29 @@
|
||||
# build release
|
||||
|
||||
labels:
|
||||
platform: linux/amd64
|
||||
|
||||
steps:
|
||||
compile:
|
||||
when:
|
||||
event: [manual]
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash build-base words-en gdb perl pcre2 pcre2-dev gdbm gdbm-dev pkgconfig meson ninja
|
||||
- meson setup --reconfigure --prefer-static build
|
||||
- ninja -C build
|
||||
- file build/dbtool
|
||||
- mv build/dbtool dbtool-linux-amd64
|
||||
|
||||
release:
|
||||
image: alpine:latest
|
||||
when:
|
||||
event: [manual]
|
||||
environment:
|
||||
DEPLOY_TOKEN:
|
||||
from_secret: DEPLOY_TOKEN
|
||||
commands:
|
||||
- apk update
|
||||
- apk add --no-cache bash httpie jq git
|
||||
- .woodpecker/release.sh dbtool-linux-amd64
|
||||
@@ -1,3 +1,9 @@
|
||||
1.9.1:
|
||||
- fixed messed up configure flags, backward, be compatible again
|
||||
- fixed berkeley m4 makro, again
|
||||
- removed bashisms in samples
|
||||
- applied patch of freebsd port
|
||||
|
||||
1.9:
|
||||
- rewrote configure, it better finds berkeley
|
||||
db or gdbm.
|
||||
|
||||
5
README
5
README
@@ -20,9 +20,12 @@ And the berkeley library at: http://www.sleepycat.com.
|
||||
|
||||
|
||||
|
||||
Installation
|
||||
Installation from source
|
||||
============================================================
|
||||
|
||||
If you build directly from the git repo, you'll need to generate the
|
||||
configure script first with 'autogen.sh'.
|
||||
|
||||
For installation run:
|
||||
|
||||
% ./configure
|
||||
|
||||
25
cipher.cc
25
cipher.cc
@@ -79,18 +79,22 @@ string cipher::encrypt(const string& source) {
|
||||
rijn.init(Rijndael::CBC, Rijndael::Encrypt, key, Rijndael::Key32Bytes);
|
||||
|
||||
/* encrypt the source */
|
||||
unsigned char output[size + 16];
|
||||
unsigned char *output = (unsigned char *)malloc(size + 16);
|
||||
int res = rijn.padEncrypt(plainText, (int)size, output);
|
||||
|
||||
/* convert the result back to char[] */
|
||||
char outText[res];
|
||||
char *outText = (char *)malloc(res);
|
||||
for(int y=0; y<(res); y++) {
|
||||
outText[y] = output[y];
|
||||
}
|
||||
|
||||
free(output);
|
||||
|
||||
/* return the crypted string */
|
||||
if (res >= 0) {
|
||||
return string(outText, res);
|
||||
if(res >= 0) {
|
||||
string text = string(outText, res);
|
||||
free(outText);
|
||||
return text;
|
||||
}
|
||||
else {
|
||||
cerr << "Failed to encrypt: " << error(res) << "!" << endl;
|
||||
@@ -113,18 +117,23 @@ string cipher::decrypt(const string& source) {
|
||||
rijn.init(Rijndael::CBC, Rijndael::Decrypt, key, Rijndael::Key32Bytes);
|
||||
|
||||
/* decrypt the source */
|
||||
unsigned char output[size];
|
||||
unsigned char *output = (unsigned char *)malloc(size);
|
||||
int res = rijn.padDecrypt(cryptedText, (int)size, output);
|
||||
|
||||
/* convert the result back to char[] */
|
||||
char outText[res];
|
||||
char *outText = (char *)malloc(res);
|
||||
for(int y=0; y<(res); y++) {
|
||||
outText[y] = output[y];
|
||||
}
|
||||
|
||||
free(output);
|
||||
|
||||
/* return the decrypted string */
|
||||
if (res >= 0)
|
||||
return string(outText, res);
|
||||
if (res >= 0) {
|
||||
string text = string(outText, res);
|
||||
free(outText);
|
||||
return text;
|
||||
}
|
||||
else {
|
||||
cerr << "Failed to decrypt: " << error(res) << " (passphrase invalid?) !" << endl;
|
||||
exit(1);
|
||||
|
||||
@@ -75,11 +75,11 @@ AC_DEFUN([AX_BERKELEY_DB_CXX],
|
||||
AC_MSG_CHECKING([for Berkeley DB (C++)])
|
||||
else
|
||||
minvermajor=`echo $minversion | cut -d. -f1`
|
||||
minverminor=`echo $minversion | cut -d. -f2`
|
||||
minverpatch=`echo $minversion | cut -d. -f3`
|
||||
minvermajor=${minvermajor:-0}
|
||||
minverminor=${minverminor:-0}
|
||||
minverpatch=${minverpatch:-0}
|
||||
minverminor=`echo $minversion | cut -d. -f2 -s`
|
||||
minverpatch=`echo $minversion | cut -d. -f3 -s`
|
||||
if test -z "$minvermajor"; then minvermajor=0; fi
|
||||
if test -z "$minverminor"; then minverminor=0; fi
|
||||
if test -z "$minverpatch"; then minverpatch=0; fi
|
||||
AC_MSG_CHECKING([for Berkeley DB (C++) >= $minvermajor.$minverminor.$minverpatch])
|
||||
fi
|
||||
|
||||
@@ -95,12 +95,12 @@ AC_DEFUN([AX_BERKELEY_DB_CXX],
|
||||
for version in "${major}.${minor}" "${major}${minor}"; do
|
||||
|
||||
try_libs="-ldb_cxx-${version}%-ldb-${version} -ldb${version}_cxx%-ldb${version}"
|
||||
try_headers="db$version/db_cxx.h db`echo $version | sed -e 's,\..*,,g'`/db_cxx.h"
|
||||
|
||||
try_headers="db${major}.${minor}/db_cxx.h db${major}${minor}/db_cxx.h db${major}/db_cxx.h"
|
||||
for db_cxx_hdr in $try_headers ; do
|
||||
for db_cxx_lib in $try_libs; do
|
||||
db_cxx_lib="$libdbdir `echo "$db_cxx_lib" | sed 's/%/ /g'`"
|
||||
LIBS="$old_LIBS $db_cxx_lib"
|
||||
#echo "Trying <$db_cxx_lib> <$db_cxx_hdr>"
|
||||
if test -z $DB_CXX_HEADER ; then
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
|
||||
35
configure.ac
35
configure.ac
@@ -2,7 +2,7 @@
|
||||
|
||||
AC_PREREQ(2.61)
|
||||
|
||||
define([dbtoolversion], esyscmd([sh -c "cat VERSION|head -1"]))
|
||||
define([dbtoolversion], esyscmd([sh -c "cat VERSION"]))dnl
|
||||
|
||||
# what we are compiling
|
||||
AC_INIT([dbtool], [dbtoolversion], [tlinden@cpan.org])
|
||||
@@ -104,8 +104,31 @@ PCRE="no"
|
||||
|
||||
|
||||
# configure args
|
||||
AC_ARG_WITH([berkeley],
|
||||
[AS_HELP_STRING([--with-berkeley],
|
||||
[Use berkeley library ])])
|
||||
|
||||
if test "x$with_berkeley" = "xno"; then
|
||||
BERKELEY=no
|
||||
GDBM=yes
|
||||
elif test "x$with_berkeley" = "xyes"; then
|
||||
BERKELEY=yes
|
||||
GDBM=no
|
||||
fi
|
||||
|
||||
|
||||
AC_ARG_WITH([gdbm],
|
||||
[AS_HELP_STRING([--with-gdbm=DIR],
|
||||
[AS_HELP_STRING([--with-gdbm],
|
||||
[Use GNU gdbm library ])])
|
||||
|
||||
if test "x$with_gdbm" = "xno"; then
|
||||
GDBM=no
|
||||
elif test "x$with_gdbm" = "xyes"; then
|
||||
GDBM=yes
|
||||
fi
|
||||
|
||||
AC_ARG_WITH([gdbm-dir],
|
||||
[AS_HELP_STRING([--with-gdbm-dir=DIR],
|
||||
[Use GNU gdbm library in DIR])],
|
||||
[
|
||||
AC_MSG_CHECKING([checking $with_gdbm_dir/include/gdbm.h presence])
|
||||
@@ -114,14 +137,16 @@ AC_ARG_WITH([gdbm],
|
||||
CFLAGS="$CXXFLAGS"
|
||||
LDFLAGS="-L$with_gdbm_dir/lib $LDFLAGS"
|
||||
LIBS="-lgdbm"
|
||||
GDBM=yes
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
GDBM=no
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
])
|
||||
|
||||
AC_ARG_WITH([pcre],
|
||||
[AS_HELP_STRING([--with-pcre=DIR],
|
||||
AC_ARG_WITH([pcre-dir],
|
||||
[AS_HELP_STRING([--with-pcre-dir=DIR],
|
||||
[Use GNU pcre library in DIR])],
|
||||
[
|
||||
AC_MSG_CHECKING([checking $with_pcre_dir/include/pcre.h presence])
|
||||
@@ -186,7 +211,7 @@ if test "$GDBM" = "no"; then
|
||||
export LDFLAGS
|
||||
export LIBS
|
||||
export CXXFLAGS
|
||||
AX_BERKELEY_DB_CXX([4.0.0],[
|
||||
AX_BERKELEY_DB_CXX([4],[
|
||||
LDFLAGS="$DB_CXX_LIBS $LDFLAGS"
|
||||
BERKELEY="yes"
|
||||
],[BERKELEY="no"])
|
||||
|
||||
@@ -77,7 +77,7 @@ int main(int argc, char *argv[]) {
|
||||
engine.dump();
|
||||
break;
|
||||
case 'I':
|
||||
engine.from_stdin();
|
||||
engine.from_input();
|
||||
break;
|
||||
case 's':
|
||||
/* select */
|
||||
@@ -127,7 +127,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
string readpass() {
|
||||
char *pass;
|
||||
char *envpass;
|
||||
envpass = getenv(PW_VARNAME);
|
||||
if(envpass != NULL) {
|
||||
@@ -136,7 +135,7 @@ string readpass() {
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_GETPASS
|
||||
pass = getpass("passphrase: ");
|
||||
char *pass = getpass("passphrase: ");
|
||||
string password = pass;
|
||||
free(pass);
|
||||
#else
|
||||
|
||||
@@ -139,7 +139,7 @@ or the parameter of B<-F>.
|
||||
=head1 EXPRESSIONS
|
||||
|
||||
Regular expressions are provided using the B<PCRE Library>. It supports most of
|
||||
the features which perl provides. See the section <EFBFBD>DIFFERENCES FROM PERL<EFBFBD> in the PCRE
|
||||
the features which perl provides. See the section "DIFFERENCES FROM PERL" in the PCRE
|
||||
manpage. You can also take a look to the perl regular expression man page with
|
||||
the following command:
|
||||
|
||||
@@ -247,7 +247,7 @@ and it's attributes.
|
||||
|
||||
=head1 REPORTING BUGS
|
||||
|
||||
Report bugs on L<https://github.com/tlinden/dbtool/issues> or mail to <tlinden@cpan.org>.
|
||||
Report bugs on L<https://codeberg.org/scip/dbtool/issues> or mail to <tlinden@cpan.org>.
|
||||
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
754
engine.cc
754
engine.cc
@@ -45,8 +45,6 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "dbtool.h"
|
||||
#include "engine.h"
|
||||
#include "platform.h"
|
||||
@@ -88,12 +86,12 @@ void Engine::init() {
|
||||
#else
|
||||
|
||||
db = gdbm_open(
|
||||
(char *)config.filename.c_str(),
|
||||
BLOCKSIZE,
|
||||
mode,
|
||||
FILEMODE,
|
||||
0
|
||||
);
|
||||
(char *)config.filename.c_str(),
|
||||
BLOCKSIZE,
|
||||
mode,
|
||||
FILEMODE,
|
||||
0
|
||||
);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@@ -104,12 +102,12 @@ void Engine::init() {
|
||||
}
|
||||
#else
|
||||
db = gdbm_open(
|
||||
(char *)config.filename.c_str(),
|
||||
BLOCKSIZE,
|
||||
mode,
|
||||
FILEMODE,
|
||||
0
|
||||
);
|
||||
(char *)config.filename.c_str(),
|
||||
BLOCKSIZE,
|
||||
mode,
|
||||
FILEMODE,
|
||||
0
|
||||
);
|
||||
#endif
|
||||
}
|
||||
#ifndef HAVE_BERKELEY
|
||||
@@ -150,10 +148,10 @@ void Engine::dump() {
|
||||
string K((char *)key.get_data(), key.get_size());
|
||||
string V((char *)data.get_data(), data.get_size());
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(V) << config.separator << K << endl;
|
||||
cout << decode(V) << config.separator << K << endl;
|
||||
}
|
||||
else {
|
||||
cout << K << config.separator << decode(V) << endl;
|
||||
cout << K << config.separator << decode(V) << endl;
|
||||
}
|
||||
}
|
||||
dbcp->close();
|
||||
@@ -173,7 +171,7 @@ void Engine::dump() {
|
||||
string V(value.dptr, value.dsize);
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(V) << config.separator << K << endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << K << config.separator << decode(V) << endl;
|
||||
}
|
||||
@@ -184,31 +182,43 @@ void Engine::dump() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* search for regexp given in config.key
|
||||
*/
|
||||
void Engine::regexp() {
|
||||
init();
|
||||
int num;
|
||||
pcre *p_pcre;
|
||||
pcre_extra *p_pcre_extra;
|
||||
char *err_str;
|
||||
int sub_len = 9;
|
||||
int *sub_vec;
|
||||
int erroffset;
|
||||
p_pcre_extra = NULL;
|
||||
p_pcre = pcre_compile((char *)config.key.c_str(), 0,
|
||||
(const char **)(&err_str), &erroffset, NULL);
|
||||
int errnumber;
|
||||
PCRE2_SIZE erroffset;
|
||||
pcre2_match_data *match_data;
|
||||
|
||||
pcre2_code *p_pcre = pcre2_compile(
|
||||
(PCRE2_SPTR)config.key.c_str(), /* the pattern */
|
||||
PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
|
||||
0, /* default options */
|
||||
&errnumber, /* for error number */
|
||||
&erroffset, /* for error offset */
|
||||
NULL); /* use default compile context */
|
||||
|
||||
if (p_pcre == NULL) {
|
||||
PCRE2_UCHAR buffer[256];
|
||||
pcre2_get_error_message(errnumber, buffer, sizeof(buffer));
|
||||
cerr << "PCRE2 compilation failed at offset: " << erroffset << " with: " << buffer << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
match_data = pcre2_match_data_create_from_pattern(p_pcre, NULL);
|
||||
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbc *dbcp;
|
||||
db->cursor(NULL, &dbcp, 0);
|
||||
Dbt key;
|
||||
Dbt data;
|
||||
while (dbcp->get(&key, &data, DB_NEXT) == 0) {
|
||||
string K((char *)key.get_data(), key.get_size());
|
||||
string V((char *)data.get_data(), data.get_size());
|
||||
Dbc *dbcp;
|
||||
db->cursor(NULL, &dbcp, 0);
|
||||
Dbt key;
|
||||
Dbt data;
|
||||
while (dbcp->get(&key, &data, DB_NEXT) == 0) {
|
||||
string K((char *)key.get_data(), key.get_size());
|
||||
string V((char *)data.get_data(), data.get_size());
|
||||
#else
|
||||
datum key;
|
||||
datum value;
|
||||
@@ -218,23 +228,24 @@ void Engine::regexp() {
|
||||
string K(key.dptr, key.dsize);
|
||||
string V(value.dptr, value.dsize);
|
||||
#endif
|
||||
|
||||
sub_vec = new int(sub_len);
|
||||
num = pcre_exec(p_pcre, p_pcre_extra, (char *)K.c_str(),
|
||||
(int)K.length(), 0, 0, (int *)sub_vec, sub_len);
|
||||
num = pcre2_match(p_pcre, (PCRE2_SPTR)K.c_str(), (PCRE2_SIZE)K.length(), 0, 0, match_data, NULL);
|
||||
|
||||
if(num == 1){
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(V);
|
||||
if(config.with == 1) {
|
||||
cout << config.separator << K;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else {
|
||||
if(config.with == 1) {
|
||||
cout << K << config.separator;
|
||||
}
|
||||
cout << decode(V) << endl;
|
||||
}
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(V);
|
||||
if(config.with == 1) {
|
||||
cout << config.separator << K;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else {
|
||||
if(config.with == 1) {
|
||||
cout << K << config.separator;
|
||||
}
|
||||
cout << decode(V) << endl;
|
||||
}
|
||||
}
|
||||
K = "";
|
||||
V = "";
|
||||
@@ -243,365 +254,392 @@ void Engine::regexp() {
|
||||
key = gdbm_nextkey(db,key);
|
||||
#endif
|
||||
}
|
||||
pcre_free(p_pcre);
|
||||
|
||||
pcre2_match_data_free(match_data);
|
||||
pcre2_code_free(p_pcre);
|
||||
|
||||
#ifdef HAVE_BERKELEY
|
||||
dbcp->close();
|
||||
db->close(0);
|
||||
#else
|
||||
gdbm_close(db);
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Insert data into the db
|
||||
*/
|
||||
void Engine::from_stdin() {
|
||||
init();
|
||||
/*
|
||||
* Insert data into the db
|
||||
*/
|
||||
void Engine::from_input() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
int err;
|
||||
#else
|
||||
int ret;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
FILE *stream;
|
||||
stream = fdopen(0, "r");
|
||||
char c;
|
||||
string mode = "key";
|
||||
string key = "";
|
||||
string value = "";
|
||||
string line = "";
|
||||
FILE *stream;
|
||||
stream = fdopen(0, "r");
|
||||
char c;
|
||||
string mode = "key";
|
||||
string key = "";
|
||||
string value = "";
|
||||
string line = "";
|
||||
|
||||
int num;
|
||||
|
||||
int errnumber;
|
||||
PCRE2_SIZE erroffset;
|
||||
pcre2_match_data *match_data;
|
||||
PCRE2_SIZE *ovector;
|
||||
|
||||
pcre2_code *p_pcre = pcre2_compile(
|
||||
(PCRE2_SPTR)config.token.c_str(),
|
||||
PCRE2_ZERO_TERMINATED,
|
||||
0,
|
||||
&errnumber,
|
||||
&erroffset,
|
||||
NULL);
|
||||
|
||||
if (p_pcre == NULL) {
|
||||
PCRE2_UCHAR buffer[256];
|
||||
pcre2_get_error_message(errnumber, buffer, sizeof(buffer));
|
||||
cerr << "PCRE2 compilation failed at offset: " << erroffset << " with: " << buffer << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
match_data = pcre2_match_data_create_from_pattern(p_pcre, NULL);
|
||||
|
||||
int num, match;
|
||||
pcre *p_pcre;
|
||||
pcre_extra *p_pcre_extra;
|
||||
char *err_str;
|
||||
int sub_len = 9;
|
||||
int *sub_vec;
|
||||
char *v1;
|
||||
char *v2;
|
||||
int erroffset;
|
||||
p_pcre_extra = NULL;
|
||||
p_pcre = pcre_compile((char *)config.token.c_str(), 0,
|
||||
(const char **)(&err_str), &erroffset, NULL);
|
||||
while((c = fgetc(stream)) != EOF) {
|
||||
if(c == '\n') {
|
||||
// record end
|
||||
mode = "key";
|
||||
if(config.token != "") {
|
||||
v1 = new char[line.length()];
|
||||
v2 = new char[line.length()];
|
||||
sub_vec = new int[sub_len];
|
||||
num = pcre_exec(p_pcre, p_pcre_extra, (char *)line.c_str(),
|
||||
(int)line.length(), 0, 0, (int *)sub_vec, sub_len);
|
||||
if(num < 0)
|
||||
cerr << "Token \"" << config.token << "\" did not match on \"" << line << "\"!\n";
|
||||
else if(num == 1)
|
||||
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
||||
else {
|
||||
match = pcre_copy_substring((char *)line.c_str(), sub_vec, num, 1, v1, line.length());
|
||||
match = pcre_copy_substring((char *)line.c_str(), sub_vec, num, 2, v2, line.length());
|
||||
if(config.reverse) {
|
||||
value = v1;
|
||||
key = v2;
|
||||
}
|
||||
else {
|
||||
value = v2;
|
||||
key = v1;
|
||||
}
|
||||
}
|
||||
delete(sub_vec);
|
||||
pcre_free((void *)v1);
|
||||
pcre_free((void *)v2);
|
||||
line = "";
|
||||
}
|
||||
value = encode(value);
|
||||
if(c == '\n') {
|
||||
// record end
|
||||
mode = "key";
|
||||
if(config.token != "") {
|
||||
//char **subs = new char*[2];
|
||||
char *subs[2];
|
||||
|
||||
num = pcre2_match(p_pcre, (PCRE2_SPTR)line.c_str(), (PCRE2_SIZE)line.length(), 0, 0, match_data, NULL);
|
||||
|
||||
if(num < 0)
|
||||
cerr << "Token \"" << config.token << "\" did not match on \"" << line << "\"!\n";
|
||||
else if(num == 1)
|
||||
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
||||
else {
|
||||
ovector = pcre2_get_ovector_pointer(match_data);
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
char * substring_start = const_cast<char*>(line.c_str()) + ovector[2*i];
|
||||
|
||||
if (i == 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
subs[i] = substring_start;
|
||||
}
|
||||
|
||||
free(ovector);
|
||||
|
||||
if(config.reverse) {
|
||||
value = subs[0];
|
||||
key = subs[1];
|
||||
}
|
||||
else {
|
||||
value = subs[1];
|
||||
key = subs[0];
|
||||
}
|
||||
}
|
||||
|
||||
//delete(subs);
|
||||
|
||||
|
||||
line = "";
|
||||
}
|
||||
value = encode(value);
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt d_key((char *)key.c_str(), key.length());
|
||||
Dbt d_value((char *)value.c_str(), value.length());
|
||||
Dbt d_key((char *)key.c_str(), key.length());
|
||||
Dbt d_value((char *)value.c_str(), value.length());
|
||||
#else
|
||||
datum d_key = {(char *)key.c_str(), key.length()};
|
||||
datum d_value = {(char *)value.c_str(), value.length()};
|
||||
datum d_key = {(char *)key.c_str(), key.length()};
|
||||
datum d_value = {(char *)value.c_str(), value.length()};
|
||||
#endif
|
||||
if(config.force == 1) {
|
||||
if(config.force == 1) {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(0, &d_key, &d_value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
if((err = db->put(0, &d_key, &d_value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, d_key, d_value, GDBM_REPLACE);
|
||||
ret = gdbm_store(db, d_key, d_value, GDBM_REPLACE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(NULL, &d_key, &d_value, DB_NOOVERWRITE)) != 0) {
|
||||
if(err == DB_KEYEXIST) {
|
||||
cerr << "Key " + config.key + " already exists" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if((err = db->put(NULL, &d_key, &d_value, DB_NOOVERWRITE)) != 0) {
|
||||
if(err == DB_KEYEXIST) {
|
||||
cerr << "Key " + config.key + " already exists" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, d_key, d_value, GDBM_INSERT);
|
||||
ret = gdbm_store(db, d_key, d_value, GDBM_INSERT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifndef HAVE_BERKELEY
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
key = "";
|
||||
value = "";
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
key = "";
|
||||
value = "";
|
||||
continue;
|
||||
}
|
||||
else if(c == config.separator && mode != "value" && config.token == "") {
|
||||
// key ready, the following stuff is the data!
|
||||
mode = "value";
|
||||
continue;
|
||||
}
|
||||
if(config.token != "") {
|
||||
/* we have a split token */
|
||||
line += char(c);
|
||||
}
|
||||
else {
|
||||
if(mode == "key")
|
||||
key += char(c);
|
||||
else
|
||||
value += char(c);
|
||||
}
|
||||
}
|
||||
pcre_free(p_pcre);
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
#else
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Insert data into the db
|
||||
*/
|
||||
void Engine::insert() {
|
||||
init();
|
||||
string __value;
|
||||
__value = encode(config.value);
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
char *k;
|
||||
char *v;
|
||||
k = (char *)config.key.c_str();
|
||||
v = (char *)__value.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value(v, strlen(v));
|
||||
#else
|
||||
int ret;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
datum value = {(char *)__value.c_str(), __value.length()};
|
||||
#endif
|
||||
|
||||
if(config.force == 1) {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(0, &key, &value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(NULL, &key, &value, DB_NOOVERWRITE)) != 0) {
|
||||
if(err == DB_KEYEXIST) {
|
||||
cerr << "Key " + config.key + " already exists" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
else if(c == config.separator && mode != "value" && config.token == "") {
|
||||
// key ready, the following stuff is the data!
|
||||
mode = "value";
|
||||
continue;
|
||||
}
|
||||
if(config.token != "") {
|
||||
/* we have a split token */
|
||||
line += char(c);
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
if(mode == "key")
|
||||
key += char(c);
|
||||
else
|
||||
value += char(c);
|
||||
}
|
||||
}
|
||||
|
||||
pcre2_match_data_free(match_data);
|
||||
pcre2_code_free(p_pcre);
|
||||
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_INSERT);
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Insert data into the db
|
||||
*/
|
||||
void Engine::insert() {
|
||||
init();
|
||||
string __value;
|
||||
__value = encode(config.value);
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
int err;
|
||||
char *k;
|
||||
char *v;
|
||||
k = (char *)config.key.c_str();
|
||||
v = (char *)__value.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value(v, strlen(v));
|
||||
#else
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
}
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* update a database
|
||||
*/
|
||||
void Engine::update() {
|
||||
init();
|
||||
string __value;
|
||||
__value = encode(config.value);
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
char *k;
|
||||
char *v;
|
||||
k = (char *)config.key.c_str();
|
||||
v = (char *)__value.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value(v, strlen(v));
|
||||
#else
|
||||
int ret;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
datum value = {(char *)__value.c_str(), __value.length()};
|
||||
int ret;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
datum value = {(char *)__value.c_str(), __value.length()};
|
||||
#endif
|
||||
|
||||
if(config.force == 1) {
|
||||
if(config.force == 1) {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(0, &key, &value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt val;
|
||||
err = db->get(0, &key, &val, 0);
|
||||
if(err == 0) {
|
||||
/* key exists, do the update */
|
||||
if((err = db->put(0, &key, &value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
#endif
|
||||
}
|
||||
else if(err == DB_NOTFOUND) {
|
||||
cerr << "Key " << config.key << " does not exist\n";
|
||||
else {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(NULL, &key, &value, DB_NOOVERWRITE)) != 0) {
|
||||
if(err == DB_KEYEXIST) {
|
||||
cerr << "Key " + config.key + " already exists" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_INSERT);
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
#else
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
}
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* update a database
|
||||
*/
|
||||
void Engine::update() {
|
||||
init();
|
||||
string __value;
|
||||
__value = encode(config.value);
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
char *k;
|
||||
char *v;
|
||||
k = (char *)config.key.c_str();
|
||||
v = (char *)__value.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value(v, strlen(v));
|
||||
#else
|
||||
int ret;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
datum value = {(char *)__value.c_str(), __value.length()};
|
||||
#endif
|
||||
|
||||
if(config.force == 1) {
|
||||
#ifdef HAVE_BERKELEY
|
||||
if((err = db->put(0, &key, &value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt val;
|
||||
err = db->get(0, &key, &val, 0);
|
||||
if(err == 0) {
|
||||
/* key exists, do the update */
|
||||
if((err = db->put(0, &key, &value, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else if(err == DB_NOTFOUND) {
|
||||
cerr << "Key " << config.key << " does not exist\n";
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
ret = gdbm_exists(db, key);
|
||||
if(ret) {
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
}
|
||||
else {
|
||||
cerr << "Key " << config.key << " does not exist\n";
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
#else
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
}
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* remove an entry
|
||||
*/
|
||||
void Engine::remove() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt key((char *)config.key.c_str(), config.key.length() + 1);
|
||||
int ret;
|
||||
if((ret = db->del(NULL, &key, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(ret) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
db->close(0);
|
||||
#else
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
int ret;
|
||||
if((ret = gdbm_delete(db, key)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(ret) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* search for specific data
|
||||
*/
|
||||
void Engine::select() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
char *k;
|
||||
k = (char *)config.key.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value;
|
||||
err = db->get(0, &key, &value, 0);
|
||||
if(err == 0) {
|
||||
string gotvalue((char *)value.get_data(), value.get_size());
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(gotvalue);
|
||||
if(config.with == 1) {
|
||||
cout << config.separator << config.key;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else {
|
||||
if(config.with == 1) {
|
||||
cout << config.key << config.separator;
|
||||
}
|
||||
cout << decode(gotvalue) << endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
db->close(0);
|
||||
#else
|
||||
ret = gdbm_exists(db, key);
|
||||
if(ret) {
|
||||
ret = gdbm_store(db, key, value, GDBM_REPLACE);
|
||||
}
|
||||
else {
|
||||
cerr << "Key " << config.key << " does not exist\n";
|
||||
exit(1);
|
||||
}
|
||||
datum content;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
content = gdbm_fetch(db, key);
|
||||
string V(content.dptr, content.dsize);
|
||||
if(config.with == 1)
|
||||
cout << config.key << config.separator;
|
||||
cout << decode(V) << endl;
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_BERKELEY
|
||||
db->close(0);
|
||||
#else
|
||||
if(ret != 0) {
|
||||
cerr << pkg << ": " << gdbm_strerror(gdbm_errno) << endl;
|
||||
exit(1);
|
||||
}
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* remove an entry
|
||||
*/
|
||||
void Engine::remove() {
|
||||
init();
|
||||
int ret;
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt key((char *)config.key.c_str(), config.key.length() + 1);
|
||||
if((ret = db->del(NULL, &key, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(ret) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
db->close(0);
|
||||
#else
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
ret = gdbm_delete(db, key);
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* search for specific data
|
||||
*/
|
||||
void Engine::select() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
int err;
|
||||
char *k;
|
||||
k = (char *)config.key.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
Dbt value;
|
||||
err = db->get(0, &key, &value, 0);
|
||||
if(err == 0) {
|
||||
string gotvalue((char *)value.get_data(), value.get_size());
|
||||
if(config.reverse == 1) {
|
||||
cout << decode(gotvalue);
|
||||
if(config.with == 1) {
|
||||
cout << config.separator << config.key;
|
||||
}
|
||||
cout << endl;
|
||||
string Engine::encode(const string& data) {
|
||||
if(config.encrypted) {
|
||||
return rijn.encrypt(data);
|
||||
}
|
||||
else {
|
||||
if(config.with == 1) {
|
||||
cout << config.key << config.separator;
|
||||
}
|
||||
cout << decode(gotvalue) << endl;
|
||||
else
|
||||
return data;
|
||||
}
|
||||
|
||||
string Engine::decode(const string& data) {
|
||||
if(config.encrypted) {
|
||||
return rijn.decrypt(data);
|
||||
}
|
||||
else
|
||||
return data;
|
||||
}
|
||||
else {
|
||||
cerr << "Database error" << "(" << strerror(err) << ")" << endl;
|
||||
exit(1);
|
||||
}
|
||||
db->close(0);
|
||||
#else
|
||||
datum content;
|
||||
datum key = {(char *)config.key.c_str(), config.key.length()};
|
||||
content = gdbm_fetch(db, key);
|
||||
string V(content.dptr, content.dsize);
|
||||
if(config.with == 1)
|
||||
cout << config.key << config.separator;
|
||||
cout << decode(V) << endl;
|
||||
gdbm_close(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
string Engine::encode(const string& data) {
|
||||
if(config.encrypted) {
|
||||
return rijn.encrypt(data);
|
||||
}
|
||||
else
|
||||
return data;
|
||||
}
|
||||
|
||||
string Engine::decode(const string& data) {
|
||||
if(config.encrypted) {
|
||||
return rijn.decrypt(data);
|
||||
}
|
||||
else
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
8
engine.h
8
engine.h
@@ -58,9 +58,10 @@
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include "platform.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pcre.h>
|
||||
#include <pcre2.h>
|
||||
}
|
||||
|
||||
#ifdef HAVE_BERKELEY
|
||||
@@ -74,8 +75,7 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
#include DB_CXX_HEADER
|
||||
#include <db_cxx.h>
|
||||
|
||||
#else
|
||||
|
||||
@@ -117,7 +117,7 @@ class Engine {
|
||||
void update();
|
||||
void remove();
|
||||
void select();
|
||||
void from_stdin();
|
||||
void from_input();
|
||||
void dump();
|
||||
void regexp();
|
||||
};
|
||||
|
||||
120
meson.build
Normal file
120
meson.build
Normal file
@@ -0,0 +1,120 @@
|
||||
project(
|
||||
'dbtool',
|
||||
'cpp',
|
||||
license: 'GPL',
|
||||
version: '1.9.1',
|
||||
meson_version: '>=1.3',
|
||||
default_options: [
|
||||
'warning_level=2',
|
||||
'werror=true',
|
||||
],
|
||||
)
|
||||
|
||||
add_project_arguments(
|
||||
[
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-unused-result',
|
||||
'-Wno-missing-braces',
|
||||
'-Wno-format-zero-length',
|
||||
'-Wvla',
|
||||
'-Wno-sign-compare',
|
||||
'-Wno-narrowing'
|
||||
],
|
||||
language: 'cpp',
|
||||
)
|
||||
|
||||
|
||||
cpp = meson.get_compiler('cpp')
|
||||
conf = configuration_data()
|
||||
dbtool_inc = include_directories('.')
|
||||
|
||||
if host_machine.system().startswith('freebsd')
|
||||
dbtool_inc = include_directories('.', '/usr/local/include')
|
||||
add_project_link_arguments('LDFLAGS=/usr/local/lib')
|
||||
endif
|
||||
|
||||
|
||||
# check for funcs.
|
||||
foreach func : ['getopt', 'fdopen', 'fgetc', 'getenv', 'getpass']
|
||||
conf.set('HAVE_'+func.to_upper(), cpp.has_function(func, prefix : '#include <unistd.h>\n#include <stdio.h>\n#include <stdlib.h>'))
|
||||
endforeach
|
||||
|
||||
|
||||
|
||||
# check for libraries with CMAKE or pkg-config
|
||||
pcre2 = dependency('libpcre2-8')
|
||||
|
||||
|
||||
# manually check for libraries
|
||||
lib_berkeley = cpp.find_library('db_cxx', required: false,
|
||||
dirs : ['/usr', '/usr/local'])
|
||||
inc_berkeley = include_directories('/usr', '/usr/local')
|
||||
|
||||
lib_gdbm = cpp.find_library('gdbm', required: false,
|
||||
dirs : ['/usr', '/usr/local'])
|
||||
inc_gdbm = include_directories('/usr', '/usr/local')
|
||||
|
||||
|
||||
if not lib_gdbm.found() and not lib_berkeley.found()
|
||||
error('neither GDBM nor BerkeleyDB are installed')
|
||||
endif
|
||||
|
||||
# check commandline options
|
||||
prefix = get_option('prefix')
|
||||
|
||||
if get_option('buildtype') == 'debug'
|
||||
conf.set('DEBUG', '1')
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# setup conf map
|
||||
version = '@0@'.format(meson.project_version())
|
||||
|
||||
conf.set('HAVE_LIBPCRE', pcre2.found())
|
||||
conf.set('HAVE_BERKELEY', lib_berkeley.found())
|
||||
conf.set('HAVE_GDBM', lib_gdbm.found())
|
||||
conf.set('prefix', prefix)
|
||||
conf.set('VERSION', version)
|
||||
|
||||
|
||||
# write out the config header
|
||||
m = configure_file(
|
||||
input : 'platform.h.in',
|
||||
output : 'platform.h',
|
||||
configuration : conf,
|
||||
)
|
||||
|
||||
|
||||
# code
|
||||
dbtool_sources = files(
|
||||
'cipher.cc',
|
||||
'config.cc',
|
||||
'dbtool.cc',
|
||||
'digest.cc',
|
||||
'engine.cc',
|
||||
'rijndael.cc'
|
||||
)
|
||||
|
||||
# add dependencies, manual libs are added directly below
|
||||
dbtool_deps = [
|
||||
pcre2
|
||||
]
|
||||
|
||||
|
||||
executable(
|
||||
'dbtool',
|
||||
[dbtool_sources],
|
||||
include_directories: [dbtool_inc, inc_berkeley, inc_gdbm],
|
||||
dependencies: [dbtool_deps, lib_berkeley, lib_gdbm],
|
||||
install: true
|
||||
)
|
||||
|
||||
# build manual page
|
||||
pod2man = find_program('pod2man', native: true)
|
||||
if pod2man.found()
|
||||
res = run_command(pod2man.full_path(), 'dbtool.pod', 'dbtool.1', check:true)
|
||||
if res.returncode() == 0
|
||||
install_man('dbtool.1')
|
||||
endif
|
||||
endif
|
||||
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
@@ -0,0 +1 @@
|
||||
# custom build options
|
||||
@@ -1,92 +1,19 @@
|
||||
/* platform.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* "Berkeley DB C++ Header File" */
|
||||
#undef DB_CXX_HEADER
|
||||
#mesondefine HAVE_BERKELEY
|
||||
#mesondefine HAVE_GDBM
|
||||
#mesondefine HAVE_LIBPCRE
|
||||
#mesondefine HAVE_GETPASS
|
||||
#mesondefine HAVE_GETOPT
|
||||
#mesondefine HAVE_FDOPEN
|
||||
#mesondefine HAVE_FGETC
|
||||
#mesondefine HAVE_GETENV
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `fdopen' function. */
|
||||
#undef HAVE_FDOPEN
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#define PACKAGE "dbtool"
|
||||
|
||||
/* Define to 1 if you have the `fgetc' function. */
|
||||
#undef HAVE_FGETC
|
||||
|
||||
/* Define to 1 if you have the `getenv' function. */
|
||||
#undef HAVE_GETENV
|
||||
|
||||
/* Define to 1 if you have the `getopt' function. */
|
||||
#undef HAVE_GETOPT
|
||||
|
||||
/* Define to 1 if you have the `getpass' function. */
|
||||
#undef HAVE_GETPASS
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `gdbm' library (-lgdbm). */
|
||||
#undef HAVE_LIBGDBM
|
||||
|
||||
/* Define to 1 if you have the `pcre' library (-lpcre). */
|
||||
#undef HAVE_LIBPCRE
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#undef HAVE_STDIO_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
#define VERSION "@VERSION@"
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
3
platform.sh
Executable file
3
platform.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "$@"> platform.h
|
||||
@@ -1108,7 +1108,7 @@ int Rijndael::blockEncrypt(const UINT8 *input,int inputLen,UINT8 *outBuffer)
|
||||
iv[3][0] = (iv[3][0] << 1) | (iv[3][1] >> 7);
|
||||
iv[3][1] = (iv[3][1] << 1) | (iv[3][2] >> 7);
|
||||
iv[3][2] = (iv[3][2] << 1) | (iv[3][3] >> 7);
|
||||
iv[3][3] = (iv[3][3] << 1) | (outBuffer[k/8] >> (7-(k&7))) & 1;
|
||||
iv[3][3] = (iv[3][3] << 1) | ((outBuffer[k/8] >> (7-(k&7))) & 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1262,7 +1262,7 @@ int Rijndael::blockDecrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer)
|
||||
iv[3][0] = (iv[3][0] << 1) | (iv[3][1] >> 7);
|
||||
iv[3][1] = (iv[3][1] << 1) | (iv[3][2] >> 7);
|
||||
iv[3][2] = (iv[3][2] << 1) | (iv[3][3] >> 7);
|
||||
iv[3][3] = (iv[3][3] << 1) | (input[k/8] >> (7-(k&7))) & 1;
|
||||
iv[3][3] = (iv[3][3] << 1) | ((input[k/8] >> (7-(k&7))) & 1);
|
||||
outBuffer[k/8] ^= (block[0] & 0x80) >> (k & 7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ db=~/.accdb
|
||||
#
|
||||
# check if dbtool version is 1.4 or higher
|
||||
version=`dbtool -V 2>&1 | sed 's/[a-zA-Z .]*//g'`
|
||||
if [ "x$version" != "x" ]; then
|
||||
let res="$version < 14"
|
||||
if [ "x$res" = "x1" ]; then
|
||||
if test -n "$version"; then
|
||||
if test $version -lt 14; then
|
||||
echo "This version of dbtool does not support encryption!"
|
||||
exit 1
|
||||
fi
|
||||
@@ -36,7 +35,7 @@ fi
|
||||
echo -n "Enter passphrase: "
|
||||
read PW
|
||||
|
||||
if [ "x$PW" = "x" ]; then
|
||||
if test -z "$PW"; then
|
||||
echo "empty passphrase!"
|
||||
exit -1
|
||||
fi
|
||||
@@ -65,7 +64,8 @@ while :
|
||||
do
|
||||
read command
|
||||
|
||||
if [ "x$command" = "xL" -o "x$command" = "xl" ]; then
|
||||
case $command in
|
||||
l|L)
|
||||
echo
|
||||
if [ -e $db ]; then
|
||||
#
|
||||
@@ -73,7 +73,7 @@ do
|
||||
# separator for better formatting with sed :-)
|
||||
dbtool -d $db -p -D -F "<22>" | sed 's/<2F>/ => /'
|
||||
fi
|
||||
elif [ "x$command" = "xN" -o "x$command" = "xn" ]; then
|
||||
n|N)
|
||||
echo
|
||||
echo -n "Enter entry name: "
|
||||
read name
|
||||
@@ -91,18 +91,18 @@ do
|
||||
| dbtool -p -i -f -d $db -F "|"
|
||||
echo "entry $name inserted."
|
||||
fi
|
||||
elif [ "x$command" = "xS" -o "x$command" = "xs" ]; then
|
||||
s|S)
|
||||
echo -n "Enter search string: "
|
||||
read string
|
||||
#
|
||||
# search for the given key
|
||||
dbtool -p -d $db -s -k $string
|
||||
elif [ "x$command" = "xQ" -o "x$command" = "xq" ]; then
|
||||
q|Q)
|
||||
echo
|
||||
echo "Thanks for the fish."
|
||||
echo
|
||||
exit 0
|
||||
fi
|
||||
esac
|
||||
|
||||
menu
|
||||
done
|
||||
|
||||
@@ -11,14 +11,11 @@
|
||||
# compliant regular expression.
|
||||
#
|
||||
|
||||
dbtool="/usr/bin/dbtool";
|
||||
find="/usr/bin/find";
|
||||
db="/var/local/locate.db";
|
||||
sort="/bin/sort";
|
||||
regex=$1;
|
||||
db="/var/db/locate.db"
|
||||
regex=$1
|
||||
|
||||
if [ "x$regex" != "x" ]; then
|
||||
$dbtool -d $db -S -k $regex -w -R;
|
||||
if test -n "$regex"; then
|
||||
dbtool -d $db -S -k $regex -w -R
|
||||
else
|
||||
echo "Usage: locate <expression>";
|
||||
echo "Usage: locate <expression>"
|
||||
fi
|
||||
|
||||
@@ -9,11 +9,7 @@
|
||||
# to search for a certain string.
|
||||
#
|
||||
|
||||
dbtool="/usr/bin/dbtool";
|
||||
find="/usr/bin/find";
|
||||
db="/var/local/locate.db";
|
||||
egrep="/bin/egrep";
|
||||
cp="/bin/cp"
|
||||
db="/var/db/locate.db";
|
||||
|
||||
$cp /dev/null $db;
|
||||
$find / -ls | $egrep -v "^\/proc|dev|tmp" | $dbtool -d $db -i -f -R -t "^(.+?) (\/.*)$";
|
||||
echo -n > $db
|
||||
find / -ls | egrep -v "^\/proc|dev|tmp" | dbtool -d $db -i -f -R -t "^(.+?) (\/.*)$";
|
||||
|
||||
Reference in New Issue
Block a user