pax_global_header 0000666 0000000 0000000 00000000064 14765004441 0014517 g ustar 00root root 0000000 0000000 52 comment=a76940445a8c45867b956c0a789cddc4287dc210
pg-gvm-22.6.8/ 0000775 0000000 0000000 00000000000 14765004441 0013013 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/.docker/ 0000775 0000000 0000000 00000000000 14765004441 0014340 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/.docker/entrypoint.sh 0000664 0000000 0000000 00000002003 14765004441 0017102 0 ustar 00root root 0000000 0000000 #!/bin/sh
# Copyright (C) 2022 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#!/bin/bash
chown -R postgres:postgres /var/lib/postgresql
chown -R postgres:postgres /var/run/postgresql
chown -R postgres:postgres /var/log/postgresql
chown -R postgres:postgres /etc/postgresql
chmod 0755 /var/lib/postgresql
chmod 0750 /var/lib/postgresql/13/main || true
exec gosu postgres "$@"
pg-gvm-22.6.8/.docker/prod.Dockerfile 0000664 0000000 0000000 00000003237 14765004441 0017302 0 ustar 00root root 0000000 0000000 ARG GVM_LIBS_VERSION=oldstable
FROM greenbone/gvm-libs:${GVM_LIBS_VERSION} AS builder
# This will make apt-get install without question
ARG DEBIAN_FRONTEND=noninteractive
# Install Debian core dependencies required for building gvm with PostgreSQL
# support and not yet installed as dependencies of gvm-libs-core
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
pkg-config \
libglib2.0-dev \
libgnutls28-dev \
postgresql-server-dev-13 \
pkg-config \
libical-dev && \
rm -rf /var/lib/apt/lists/*
COPY . /source
WORKDIR /source
# clone and install pg-gvm
RUN mkdir /build && \
mkdir /install && \
cd /build && \
cmake -DCMAKE_BUILD_TYPE=Release /source && \
make DESTDIR=/install install
FROM greenbone/gvm-libs:${GVM_LIBS_VERSION}
COPY --from=builder /install/ /
COPY .docker/start-postgresql.sh /usr/local/bin/start-postgresql
COPY .docker/entrypoint.sh /usr/local/bin/entrypoint
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libgpgme11 \
libical3 \
libpq5 \
gosu \
postgresql-13 \
postgresql-client-13 \
postgresql-client-common && \
rm -rf /var/lib/apt/lists/*
WORKDIR /home/postgres
RUN usermod -u 104 postgres && groupmod -g 106 postgres && \
chown -R postgres:postgres /var/lib/postgresql && \
chown -R postgres:postgres /var/run/postgresql && \
chown -R postgres:postgres /var/log/postgresql && \
chown -R postgres:postgres /etc/postgresql && \
chmod 755 /usr/local/bin/start-postgresql /usr/local/bin/entrypoint
ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
CMD ["/usr/local/bin/start-postgresql"]
pg-gvm-22.6.8/.docker/start-postgresql.sh 0000664 0000000 0000000 00000005371 14765004441 0020240 0 ustar 00root root 0000000 0000000 #!/bin/sh
[ -z "$POSTGRES_USER" ] && POSTGRES_USER="gvmd"
[ -z "$POSTGRES_DATA" ] && POSTGRES_DATA="/var/lib/postgresql"
[ -z "$POSTGRES_HOST_AUTH_METHOD" ] && POSTGRES_HOST_AUTH_METHOD="md5"
[ -z "$POSTGRES_VERSION" ] && POSTGRES_VERSION=13
POSTGRES_DB=gvmd
POSTGRES_HBA_CONF="/etc/postgresql/$POSTGRES_VERSION/main/pg_hba.conf"
rm -f "$POSTGRES_DATA/started"
# allow access via unix domain socket unauthenticated
echo "local all all trust" > $POSTGRES_HBA_CONF
if [ "$POSTGRES_HOST_AUTH_METHOD" = "trust" ]; then
echo "# warning trust is enabled for all connections"
echo "# see https://www.postgresql.org/docs/$POSTGRES_VERSION/auth-trust.html"
fi
echo "host all all all $POSTGRES_HOST_AUTH_METHOD" >> $POSTGRES_HBA_CONF
pg_ctlcluster -o "-k /tmp" -o "-c listen_addresses=''" $POSTGRES_VERSION main start
USER_EXISTS="$(echo "SELECT 1 FROM pg_roles WHERE rolname = '$POSTGRES_USER'" | psql --host=/tmp -d postgres --tuples-only)"
if [ -z "$USER_EXISTS" ]; then
createuser --host=/tmp -DRS "$POSTGRES_USER"
fi
if [ -n "$POSTGRES_PASSWORD" ]; then
echo "ALTER ROLE $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD';" | \
psql --host=/tmp -d postgres
fi
DB_EXISTS="$(echo "SELECT 1 FROM pg_database WHERE datname = '$POSTGRES_DB';" | psql --host=/tmp -d postgres --tuples-only)"
if [ -z "$DB_EXISTS" ]; then
createdb --host=/tmp -O "$POSTGRES_DB" "$POSTGRES_USER"
fi;
DBA_EXISTS="$(echo "SELECT 1 FROM pg_roles WHERE rolname = 'dba';" | psql --host=/tmp -d $POSTGRES_DB --tuples-only)"
if [ -z "$DBA_EXISTS" ]; then
psql --host=/tmp -d $POSTGRES_DB -c "create role dba with superuser noinherit;"
psql --host=/tmp -d $POSTGRES_DB -c "grant dba to $POSTGRES_USER;"
fi
UUID_OSSP_EXTENSION_EXISTS="$(echo "SELECT 1 FROM pg_extension WHERE extname = 'uuid-ossp';" | psql --host=/tmp -d $POSTGRES_DB --tuples-only)"
if [ -z "$UUID_OSSP_EXTENSION_EXISTS" ]; then
psql --host=/tmp -d $POSTGRES_DB -c 'create extension "uuid-ossp";'
fi
PGCRYPTO_EXTENSION_EXISTS="$(echo "SELECT 1 FROM pg_extension WHERE extname = 'pgcrypto';" | psql --host=/tmp -d $POSTGRES_DB --tuples-only)"
if [ -z "$PGCRYPTO_EXTENSION_EXISTS" ]; then
psql --host=/tmp -d $POSTGRES_DB -c 'create extension "pgcrypto";'
fi
PG_GVM_EXTENSION_EXISTS="$(echo "SELECT 1 FROM pg_extension WHERE extname = 'pg-gvm';" | psql --host=/tmp -d $POSTGRES_DB --tuples-only)"
if [ -z "$PG_GVM_EXTENSION_EXISTS" ]; then
psql --host=/tmp -d $POSTGRES_DB -c 'create extension "pg-gvm";'
fi
pg_ctlcluster --foreground $POSTGRES_VERSION main stop
# Touch file, signaling startup is done
touch "$POSTGRES_DATA/started"
pg_ctlcluster -o "-c listen_addresses='*'" --foreground $POSTGRES_VERSION main start
at_exit() {
rm -f "$POSTGRES_DATA/started" && echo "Deleted verification file."
}
trap at_exit EXIT
pg-gvm-22.6.8/.dockerignore 0000664 0000000 0000000 00000000033 14765004441 0015463 0 ustar 00root root 0000000 0000000 .git
.github
.vscode
build
pg-gvm-22.6.8/.github/ 0000775 0000000 0000000 00000000000 14765004441 0014353 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/.github/CODEOWNERS 0000664 0000000 0000000 00000000246 14765004441 0015750 0 ustar 00root root 0000000 0000000 # default reviewers
* @greenbone/gea
# dev ops
.github/ @greenbone/devops @greenbone/gea
.docker/ @greenbone/devops @greenbone/gea
pg-gvm-22.6.8/.github/dependabot.yml 0000664 0000000 0000000 00000000272 14765004441 0017204 0 ustar 00root root 0000000 0000000 version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
github-actions:
patterns:
- "*"
pg-gvm-22.6.8/.github/workflows/ 0000775 0000000 0000000 00000000000 14765004441 0016410 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/.github/workflows/auto-merge.yml 0000664 0000000 0000000 00000000335 14765004441 0021201 0 ustar 00root root 0000000 0000000 name: Auto-merge squash
on: pull_request_target
permissions:
contents: write
pull-requests: write
jobs:
auto-merge:
uses: greenbone/workflows/.github/workflows/auto-merge.yml@main
secrets: inherit
pg-gvm-22.6.8/.github/workflows/changelog.yml 0000664 0000000 0000000 00000001477 14765004441 0021073 0 ustar 00root root 0000000 0000000 name: Show changelog since last release
on:
workflow_dispatch:
jobs:
changelog:
name: Show changelog since last release
runs-on: 'ubuntu-latest'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for conventional commits and getting all git tags
persist-credentials: false
- name: Install git-cliff
uses: greenbone/actions/uv@v3
with:
install: git-cliff
- name: Determine changelog
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
run: |
git-cliff -v --strip header --unreleased -o /tmp/changelog.md
- name: Show changelog
run: |
cat /tmp/changelog.md
cat /tmp/changelog.md >> $GITHUB_STEP_SUMMARY
pg-gvm-22.6.8/.github/workflows/ci-c.yml 0000664 0000000 0000000 00000002720 14765004441 0017747 0 ustar 00root root 0000000 0000000 name: Build and test C
on:
push:
branches: [ main, stable ]
pull_request:
branches: [ main, stable ]
jobs:
build_and_test_debug:
name: Build and test
runs-on: ubuntu-latest
container: greenbone/gvm-libs:oldstable
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install build dependencies
run: .github/workflows/install-build-dependencies.sh
- name: Set up database
run: |
su postgres -c " \
/etc/init.d/postgresql start && \
createuser -DRS root && \
createdb -O root gvmd && \
psql -d gvmd -c 'create role dba with superuser noinherit; grant dba to root;' && \
psql -d gvmd -c 'create extension \"uuid-ossp\"; create extension \"pgcrypto\"; create extension "pgtap";' && \
/etc/init.d/postgresql stop \
"
- name: Build and install extension
run: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make install
- name: Start PostgreSQL server
run: su postgres -c "pg_ctlcluster 13 main start"
- name: Add "/usr/local/lib" as ld directory
run: echo "/usr/local/lib" >> /etc/ld.so.conf.d/gvm.conf && ldconfig
- name: Add pg-gvm extension
run: psql -d gvmd -c 'SET ROLE dba; CREATE EXTENSION "pg-gvm";'
- name: Create gvmd tables
run: psql -d gvmd < gvmd-tables.sql
- name: Run tests
run: pg_prove -d gvmd tests/*.sql
pg-gvm-22.6.8/.github/workflows/codeql-analysis-c.yml 0000664 0000000 0000000 00000002130 14765004441 0022437 0 ustar 00root root 0000000 0000000 name: "CodeQL"
on:
push:
branches: [ main, stable ]
pull_request:
branches: [ main, stable ]
paths-ignore:
- '**/*.md'
- '**/*.txt'
schedule:
- cron: '30 5 * * 0' # 5:30h on Sundays
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
container: greenbone/gvm-libs:oldstable
strategy:
fail-fast: false
matrix:
language: [ 'c' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install build dependencies
run: .github/workflows/install-build-dependencies.sh
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# build between init and analyze ...
- name: Configure and Compile pg-gvm
run: |
mkdir build && cd build/ && cmake \
-DCMAKE_BUILD_TYPE=Release .. && make install
working-directory: ${{ github.WORKSPACE }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
pg-gvm-22.6.8/.github/workflows/container.yml 0000664 0000000 0000000 00000005132 14765004441 0021116 0 ustar 00root root 0000000 0000000 name: Container Image Builds
on:
push:
branches:
- main
tags: ["v*"]
pull_request:
branches:
- main
workflow_dispatch:
jobs:
images:
name: Build and upload container images
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: greenbone/actions/is-latest-tag@v3
id: latest
- name: Setup container meta information
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}
labels: |
org.opencontainers.image.vendor=Greenbone
org.opencontainers.image.base.name=debian/stable-slim
flavor: latest=false # no latest container tag for git tags
tags: |
# use version, major.minor and major for tags
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# use edge for default branch
type=edge
# set label for non-published pull request builds
type=ref,event=pr
# when a new git tag is created set stable and a latest tags
type=raw,value=latest,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
type=raw,value=stable,enable=${{ steps.latest.outputs.is-latest-tag == 'true' }}
- name: Set container build options
id: container-opts
run: |
if [[ "${{ github.ref_type }}" = 'tag' ]]; then
echo "gvm-libs-version=oldstable" >> $GITHUB_OUTPUT
else
echo "gvm-libs-version=oldstable-edge" >> $GITHUB_OUTPUT
fi
- name: Login to Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Container image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' && (github.ref_type == 'tag' || github.ref_name == 'main') }}
build-args: |
GVM_LIBS_VERSION=${{ steps.container-opts.outputs.gvm-libs-version }}
file: .docker/prod.Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
pg-gvm-22.6.8/.github/workflows/conventional-commits.yml 0000664 0000000 0000000 00000000463 14765004441 0023306 0 ustar 00root root 0000000 0000000 name: Conventional Commits
on:
pull_request_target:
permissions:
pull-requests: write
contents: read
jobs:
conventional-commits:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Report Conventional Commits
uses: greenbone/actions/conventional-commits@v3
pg-gvm-22.6.8/.github/workflows/dependency-review.yml 0000664 0000000 0000000 00000000345 14765004441 0022552 0 ustar 00root root 0000000 0000000 name: 'Dependency Review'
on: [pull_request]
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Dependency Review'
uses: greenbone/actions/dependency-review@v3
pg-gvm-22.6.8/.github/workflows/install-build-dependencies.sh 0000775 0000000 0000000 00000001672 14765004441 0024144 0 ustar 00root root 0000000 0000000 #!/bin/sh
# Copyright (C) 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#!/bin/bash
apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
cmake \
libglib2.0-dev \
postgresql-server-dev-13 \
pkg-config \
libical-dev \
pgtap && \
rm -rf /var/lib/apt/lists/*
pg-gvm-22.6.8/.github/workflows/push.yaml 0000664 0000000 0000000 00000001422 14765004441 0020252 0 ustar 00root root 0000000 0000000 name: Build and Push to Greenbone Registry
on:
push:
branches: [ main ]
tags: ["v*"]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
ref-name:
type: string
description: "The ref to build a container image from. For example a tag v23.0.0."
required: true
jobs:
push:
name: Build and push to self-hosted harbor
uses: greenbone/workflows/.github/workflows/container-build-push-2nd-gen.yml@main
with:
image-labels: |
org.opencontainers.image.vendor=Greenbone
org.opencontainers.image.documentation=https://greenbone.github.io/docs/
org.opencontainers.image.base.name=debian:stable-slim
image-url: community/pg-gvm
ref-name: ${{ inputs.ref-name }}
secrets: inherit
pg-gvm-22.6.8/.github/workflows/release.yml 0000664 0000000 0000000 00000007637 14765004441 0020570 0 ustar 00root root 0000000 0000000 name: Release pg-gvm
on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
release-type:
type: choice
description: What kind of release do you want to do?
options:
- patch
- minor
- major
release-version:
type: string
description: Set an explicit version, that will overwrite release-type. Fails if version is not compliant.
jobs:
build-and-release:
name: Create a new release
# If the event is a workflow_dispatch or on of the labels 'pre release',
# 'patch release', 'minor release' or 'major release' is set and PR is
# closed because of a merge
# NOTE: priority of set labels will be alpha > release-candidate > patch > minor > major,
# so if 'major' and 'patch' labels are set, it will create a patch release.
if: |
( github.event_name == 'workflow_dispatch') || (
( contains(github.event.pull_request.labels.*.name, 'alpha release') ||
contains(github.event.pull_request.labels.*.name, 'rc release') ||
contains(github.event.pull_request.labels.*.name, 'patch release') ||
contains(github.event.pull_request.labels.*.name, 'minor release') ||
contains(github.event.pull_request.labels.*.name, 'major release')) &&
github.event.pull_request.merged == true )
runs-on: "ubuntu-latest"
steps:
- name: Selecting the Release type
id: release-type
uses: greenbone/actions/release-type@v3
with:
release-type-input: ${{ inputs.release-type }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for conventional commits and getting all git tags
persist-credentials: false
ref: ${{ steps.release-type.outputs.release-ref }}
- name: Determine release version
id: release-version
uses: greenbone/actions/release-version@v3
with:
release-type: ${{ steps.release-type.outputs.release-type }}
release-version: ${{ inputs.release-version }}
versioning-scheme: "semver"
- name: Show versions
run: |
echo "Current release: ${{ steps.release-version.outputs.last-release-version}}"
echo "Next release: ${{ steps.release-version.outputs.release-version}}"
- name: Check for SQL migration script
run: |
found=$(find ./sql/update -name "*--${{ steps.release-version.outputs.release-version-major }}.${{ steps.release-version.outputs.release-version-minor }}.sql" | wc -l)
if [ $found -eq 0 ]; then
echo "::error ::Missing SQL migration file in ./sql/update for ${{ steps.release-version.outputs.release-version-major }}.${{ steps.release-version.outputs.release-version-minor }} release"
exit 1
fi
- name: Install git-cliff
uses: greenbone/actions/uv@v3
with:
install: git-cliff
- name: Determine changelog
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
run: |
git-cliff -v --strip header -o /tmp/changelog.md --unreleased --tag ${{ steps.release-version.outputs.release-version }} ${{ steps.release-version.outputs.last-release-version }}..HEAD
- name: Release with release action
id: release
uses: greenbone/actions/release@v3
with:
github-user: ${{ secrets.GREENBONE_BOT }}
github-user-mail: ${{ secrets.GREENBONE_BOT_MAIL }}
github-user-token: ${{ secrets.GREENBONE_BOT_TOKEN }}
gpg-key: ${{ secrets.GPG_KEY }}
gpg-fingerprint: ${{ secrets.GPG_FINGERPRINT }}
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
release-version: ${{ steps.release-version.outputs.release-version }}
changelog: /tmp/changelog.md
ref: ${{ steps.release-type.outputs.release-ref }}
versioning-scheme: "semver"
pg-gvm-22.6.8/.github/workflows/sbom-upload.yml 0000664 0000000 0000000 00000000415 14765004441 0021355 0 ustar 00root root 0000000 0000000 name: SBOM upload
on:
workflow_dispatch:
push:
branches: ["main"]
jobs:
SBOM-upload:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: 'SBOM upload'
uses: greenbone/actions/sbom-upload@v3
pg-gvm-22.6.8/.mergify.yml 0000664 0000000 0000000 00000002177 14765004441 0015265 0 ustar 00root root 0000000 0000000 pull_request_rules:
- name: backport main patches to stable branch
conditions:
- base=main
- label=backport-to-stable
actions:
backport:
branches:
- stable
- name: backport main patches to oldstable branch
conditions:
- base=main
- label=backport-to-oldstable
actions:
backport:
branches:
- oldstable
- name: backport stable patches to main branch
conditions:
- base=stable
- label=backport-to-main
actions:
backport:
branches:
- main
- name: backport stable patches to oldstable branch
conditions:
- base=stable
- label=backport-to-oldstable
actions:
backport:
branches:
- oldstable
- name: backport oldstable patches to main branch
conditions:
- base=oldstable
- label=backport-to-main
actions:
backport:
branches:
- main
- name: backport oldstable patches to stable branch
conditions:
- base=oldstable
- label=backport-to-stable
actions:
backport:
branches:
- stable
pg-gvm-22.6.8/CMakeLists.txt 0000664 0000000 0000000 00000020047 14765004441 0015556 0 ustar 00root root 0000000 0000000 # Copyright (C) 2020-2021 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
cmake_minimum_required(VERSION 3.0)
message ("-- Configuring PostgreSQL extension for GVMd functions...")
project(pg-gvm
VERSION 22.6.8
LANGUAGES C)
# List all sourcefiles
set(SRCS
src/regexp.c
src/ical.c
src/ical_utils.c
src/hosts.c
src/array.c)
# List all sql input files
set(SQL
sql/regexp.in.sql
sql/hosts.in.sql
sql/ical.in.sql)
message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")
configure_file (VERSION.in VERSION)
if (POLICY CMP0005)
cmake_policy (SET CMP0005 NEW)
endif (POLICY CMP0005)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include (FindPkgConfig)
# Check if libical is installed
pkg_check_modules (LIBICAL REQUIRED libical>=1.00)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.42)
pkg_check_modules (LIBGVM_BASE REQUIRED libgvm_base>=22.6)
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Debug)
endif (NOT CMAKE_BUILD_TYPE)
OPTION (ENABLE_COVERAGE "Enable support for coverage analysis" OFF)
OPTION (DEBUG_FUNCTION_NAMES "Print function names on entry and exit" OFF)
## Retrieve git revision (at configure time)
include (GetGit)
if (NOT CMAKE_BUILD_TYPE MATCHES "Release")
if (EXISTS "${CMAKE_SOURCE_DIR}/.git/")
if (GIT_FOUND)
Git_GET_REVISION(${CMAKE_SOURCE_DIR} ProjectRevision)
set (GIT_REVISION "~git-${ProjectRevision}")
else (GIT_FOUND)
set (GIT_REVISION "~git")
endif (GIT_FOUND)
endif (EXISTS "${CMAKE_SOURCE_DIR}/.git/")
endif (NOT CMAKE_BUILD_TYPE MATCHES "Release")
# Set dev version if this is a development version and not a full release,
# unset (put value 0 or delete line) before a full release and reset after.
set (PROJECT_DEV_VERSION 0)
# If PROJECT_DEV_VERSION is set, the version string will be set to:
# "major.minor.patch~dev${PROJECT_DEV_VERSION}${GIT_REVISION}"
# If PROJECT_DEV_VERSION is NOT set, the version string will be set to:
# "major.minor.patch${GIT_REVISION}"
# For CMAKE_BUILD_TYPE "Release" the git revision will be empty.
if (PROJECT_DEV_VERSION)
set (PROJECT_VERSION_SUFFIX "~dev${PROJECT_DEV_VERSION}")
endif (PROJECT_DEV_VERSION)
set (PROJECT_VERSION_STRING
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}${PROJECT_VERSION_SUFFIX}${GIT_REVISION}")
# All versions with this API are compatible
# If an sql update is required the minor version MUST be increased
set (PROJECT_API_VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}")
# Check if pg_config is available
find_program(PGCONFIG pg_config)
if (NOT PGCONFIG)
message(FATAL_ERROR "Could not find pg_config")
endif ()
execute_process(COMMAND ${PGCONFIG} --version OUTPUT_VARIABLE PGVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT "${PGVERSION}" MATCHES "${PG_REQUIRED_VERSION}")
message(FATAL_ERROR "Wrong PostgreSQL version: found ${PGVERSION}, required ${PG_REQUIRED_VERSION}")
endif ()
# Retrieve postgres include directories
execute_process(COMMAND ${PGCONFIG} --includedir --includedir-server OUTPUT_VARIABLE PostgreSQL_ACTUAL_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
find_package (PostgreSQL REQUIRED)
if (NOT PostgreSQL_FOUND)
message (SEND_ERROR "The PostgreSQL library is required.")
endif (NOT PostgreSQL_FOUND)
string (REGEX MATCH "^[ \t]*\([0-9]+\)\\.\([0-9]+\)\(.*\)" TEMP ${PostgreSQL_VERSION_STRING})
if (NOT CMAKE_MATCH_1)
message (SEND_ERROR "Error matching PostgreSQL version.")
elseif ((CMAKE_MATCH_1 EQUAL 9 AND CMAKE_MATCH_2 LESS 6)
OR (CMAKE_MATCH_1 LESS 9))
message (SEND_ERROR "PostgreSQL version >= 9.6 is required")
message (STATUS "PostgreSQL version ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}${CMAKE_MATCH_3}")
endif (NOT CMAKE_MATCH_1)
# Set include directories
include_directories(${PostgreSQL_ACTUAL_INCLUDE_DIR} ${GLIB_INCLUDE_DIRS} ${LIBGVM_BASE_INCLUDE_DIRS})
include_directories("include")
link_libraries(${LIBICAL_LIBRARIES} ${LIBGVM_BASE_LDFLAGS})
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
# Set control file for postgres extension definition
set(CONTROLIN "control.in")
set(CONTROLOUT "pg-gvm.control")
# Set SQL output file using the version to match postgres conventions
set(SQLOUT "pg-gvm--${PROJECT_API_VERSION}.sql")
# Determine the postgres lib dirs
execute_process(COMMAND ${PGCONFIG} --sharedir OUTPUT_VARIABLE PostgreSQL_SHARE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PGCONFIG} --pkglibdir OUTPUT_VARIABLE PostgreSQL_EXTLIB_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
# Custom targets to build SQL and control files
add_custom_target(sqlscript ALL DEPENDS ${CMAKE_BINARY_DIR}/${SQLOUT})
add_custom_target(control ALL DEPENDS ${CMAKE_BINARY_DIR}/${CONTROLOUT})
## CPack configuration
set (CPACK_CMAKE_GENERATOR "Unix Makefiles")
set (CPACK_GENERATOR "TGZ")
set (CPACK_INSTALL_CMAKE_PROJECTS ".;gvm;ALL;/")
set (CPACK_MODULE_PATH "")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set (CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md")
set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_SOURCE_TOPLEVEL_TAG "")
set (CPACK_SYSTEM_NAME "")
set (CPACK_TOPLEVEL_TAG "")
set (CPACK_PACKAGE_VERSION "${PROJECT_VERSION_STRING}${PROJECT_VERSION_GIT}")
set (CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_PACKAGE_VENDOR "Greenbone AG")
set (CPACK_SOURCE_IGNORE_FILES
"${CMAKE_BINARY_DIR}"
"/.git/"
"swp$"
)
# Define the library
add_library (${CMAKE_PROJECT_NAME} MODULE ${SRCS})
# Prepare control file
configure_file (${CONTROLIN} ${CONTROLOUT})
# Prepare SQL file
add_custom_command(
OUTPUT ${SQLOUT}
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/sqlin
COMMAND cp ${SQL} ${CMAKE_BINARY_DIR}/sqlin/
COMMAND cd ${CMAKE_BINARY_DIR}/sqlin/ && find -type f | xargs cat > ${CMAKE_BINARY_DIR}/${SQLOUT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${SQL})
# Define install targets
if (CMAKE_INSTALL_DEV_PREFIX)
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION "${CMAKE_INSTALL_DEV_PREFIX}/lib/postgresql")
configure_file("${CMAKE_SOURCE_DIR}/pg-gvm-make-dev-links.in" "${CMAKE_BINARY_DIR}/pg-gvm-make-dev-links" @ONLY)
install(
FILES "${CMAKE_BINARY_DIR}/pg-gvm-make-dev-links"
DESTINATION "${CMAKE_INSTALL_DEV_PREFIX}/sbin"
PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES "${CMAKE_BINARY_DIR}/${CONTROLOUT}" DESTINATION "${CMAKE_INSTALL_DEV_PREFIX}/share/postgresql/extension")
install(FILES "${CMAKE_BINARY_DIR}/${SQLOUT}" DESTINATION "${CMAKE_INSTALL_DEV_PREFIX}/share/postgresql/extension")
file(GLOB SQL_UPDATE_FILES ${CMAKE_SOURCE_DIR}/sql/update/*.sql)
install(FILES ${SQL_UPDATE_FILES} DESTINATION "${CMAKE_INSTALL_DEV_PREFIX}/share/postgresql/extension")
message(NOTICE "${CMAKE_PROJECT_NAME} installed with prefix. Run ${CMAKE_INSTALL_DEV_PREFIX}/sbin/pg-gvm-make-dev-links as root to create symlinks to this installation.")
else (CMAKE_INSTALL_DEV_PREFIX)
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION "${PostgreSQL_EXTLIB_DIR}")
install(FILES "${CMAKE_BINARY_DIR}/${CONTROLOUT}" DESTINATION "${PostgreSQL_SHARE_DIR}/extension")
install(FILES "${CMAKE_BINARY_DIR}/${SQLOUT}" DESTINATION "${PostgreSQL_SHARE_DIR}/extension")
file(GLOB SQL_UPDATE_FILES ${CMAKE_SOURCE_DIR}/sql/update/*.sql)
install(FILES ${SQL_UPDATE_FILES} DESTINATION "${PostgreSQL_SHARE_DIR}/extension")
endif (CMAKE_INSTALL_DEV_PREFIX)
pg-gvm-22.6.8/LICENSE 0000664 0000000 0000000 00000104505 14765004441 0014025 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
pg-gvm-22.6.8/README.md 0000664 0000000 0000000 00000003173 14765004441 0014276 0 ustar 00root root 0000000 0000000 
# Greenbone Library for PostgreSQL utility functions
This library contains PostgreSQL utility functions. For example to compute host
and ical information within SQL statements.
# Build and Installation
## Prerequisites
* GCC
* cmake >= 3.0
* pkg-config
* libical >= 1.0.0
* glib >= 2.42
* PostgreSQL dev >= 9.6
* libgvm-base >= 20.8
Install these packages using (on Debian GNU/Linux bookworm 12):
```sh
apt-get install gcc cmake pkg-config libical-dev libglib2.0-dev postgresql-server-dev-15
```
and build the gvm-libs as described in the [README](https://github.com/greenbone/gvm-libs).
## Configure and Build
This extension can be configured, built and installed with the following commands:
```sh
cmake .
make && make install
```
## Use the extension
To use the extension in a database create the extension using
```sh
CREATE EXTENSION "pg-gvm";
```
## Test the extension
The tests are based on pgTAP, a unit test tool for PostgreSQL Databases.
### Setup for tests
Install pgTAP cloning the [repository](https://github.com/theory/pgtap.git)
and follow the instructions in the [setup documentation](https://pgtap.org/documentation.html#installation)
### Integration
To use pgTAP in a database use
```sh
CREATE EXTENSION IF NOT EXISTS pgtap;
```
as postgres user.
To check if the extension exists use
```sh
\dx
```
### Running the tests
The tests are located in the ```tests``` folder of this repository.
As postgres user run (replace MY_DATABASE with the real name of the database)
```sh
pg_prove -d MY_DATABASE tests/*.sql
```
pg-gvm-22.6.8/VERSION.in 0000664 0000000 0000000 00000000031 14765004441 0014462 0 ustar 00root root 0000000 0000000 @PROJECT_VERSION_STRING@
pg-gvm-22.6.8/cliff.toml 0000664 0000000 0000000 00000007032 14765004441 0014775 0 ustar 00root root 0000000 0000000 [changelog]
# template for the changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{% if version -%}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
## [Unreleased]
{% endif -%}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
{% if commit.remote.username %} by [@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }}){%- endif -%}
{% if commit.remote.pr_number %} in \
[#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
{% elif commit.id %} in \
[{{ commit.id | truncate(length=7, end="") }}]({{ self::remote_url() }}/commit/{{ commit.id }})\
{%- endif -%}
{% endfor %}
{% endfor -%}
"""
# template for the changelog footer
footer = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{% for release in releases %}
{% if release.version -%}
{% if release.previous.version -%}
[{{ release.version | trim_start_matches(pat="v") }}]: \
{{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }}
{% endif -%}
{% else -%}
[unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD
{% endif -%}
{%- endfor -%}
"""
# remove the leading and trailing whitespace from the templates
trim = true
[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not following the conventional commits format
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
# remove issue numbers from commits
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^[a|A]dd", group = ":sparkles: Added" },
{ message = "^[c|C]hange", group = ":construction_worker: Changed" },
{ message = "^[f|F]ix", group = ":bug: Bug Fixes" },
{ message = "^[r|R]emove", group = ":fire: Removed" },
{ message = "^[d|D]rop", group = ":fire: Removed" },
{ message = "^[d|D]oc", group = ":books: Documentation" },
{ message = "^[t|T]est", group = ":white_check_mark: Testing" },
{ message = "^[c|C]hore", group = ":wrench: Miscellaneous" },
{ message = "^[c|C]i", group = "️:wrench: Miscellaneous" },
{ message = "^[m|M]isc", group = ":wrench: Miscellaneous" },
{ message = "^[d|D]eps", group = ":ship: Dependencies" },
]
# filter out the commits that are not matched by commit parsers
filter_commits = true
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
pg-gvm-22.6.8/cmake/ 0000775 0000000 0000000 00000000000 14765004441 0014073 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/cmake/FindPackageHandleStandardArgs.cmake 0000664 0000000 0000000 00000043514 14765004441 0022652 0 ustar 00root root 0000000 0000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPackageHandleStandardArgs
-----------------------------
This module provides a function intended to be used in :ref:`Find Modules`
implementing :command:`find_package()` calls. It handles the
``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``.
It also sets the ``_FOUND`` variable. The package is
considered found if all variables listed contain valid results, e.g.
valid filepaths.
.. command:: find_package_handle_standard_args
There are two signatures::
find_package_handle_standard_args(
(DEFAULT_MSG|)
...
)
find_package_handle_standard_args(
[FOUND_VAR ]
[REQUIRED_VARS ...]
[VERSION_VAR ]
[HANDLE_COMPONENTS]
[CONFIG_MODE]
[NAME_MISMATCHED]
[REASON_FAILURE_MESSAGE ]
[FAIL_MESSAGE ]
)
The ``_FOUND`` variable will be set to ``TRUE`` if all
the variables ``...`` are valid and any optional
constraints are satisfied, and ``FALSE`` otherwise. A success or
failure message may be displayed based on the results and on
whether the ``REQUIRED`` and/or ``QUIET`` option was given to
the :command:`find_package` call.
The options are:
``(DEFAULT_MSG|)``
In the simple signature this specifies the failure message.
Use ``DEFAULT_MSG`` to ask for a default message to be computed
(recommended). Not valid in the full signature.
``FOUND_VAR ``
Obsolete. Specifies either ``_FOUND`` or
``_FOUND`` as the result variable. This exists only
for compatibility with older versions of CMake and is now ignored.
Result variables of both names are always set for compatibility.
``REQUIRED_VARS ...``
Specify the variables which are required for this package.
These may be named in the generated failure message asking the
user to set the missing variable values. Therefore these should
typically be cache entries such as ``FOO_LIBRARY`` and not output
variables like ``FOO_LIBRARIES``. This option is mandatory if
``HANDLE_COMPONENTS`` is not specified.
``VERSION_VAR ``
Specify the name of a variable that holds the version of the package
that has been found. This version will be checked against the
(potentially) specified required version given to the
:command:`find_package` call, including its ``EXACT`` option.
The default messages include information about the required
version and the version which has been actually found, both
if the version is ok or not.
``HANDLE_COMPONENTS``
Enable handling of package components. In this case, the command
will report which components have been found and which are missing,
and the ``_FOUND`` variable will be set to ``FALSE``
if any of the required components (i.e. not the ones listed after
the ``OPTIONAL_COMPONENTS`` option of :command:`find_package`) are
missing.
``CONFIG_MODE``
Specify that the calling find module is a wrapper around a
call to ``find_package( NO_MODULE)``. This implies
a ``VERSION_VAR`` value of ``_VERSION``. The command
will automatically check whether the package configuration file
was found.
``REASON_FAILURE_MESSAGE ``
Specify a custom message of the reason for the failure which will be
appended to the default generated message.
``FAIL_MESSAGE ``
Specify a custom failure message instead of using the default
generated message. Not recommended.
``NAME_MISMATCHED``
Indicate that the ```` does not match
``${CMAKE_FIND_PACKAGE_NAME}``. This is usually a mistake and raises a
warning, but it may be intentional for usage of the command for components
of a larger package.
Example for the simple signature:
.. code-block:: cmake
find_package_handle_standard_args(LibXml2 DEFAULT_MSG
LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
The ``LibXml2`` package is considered to be found if both
``LIBXML2_LIBRARY`` and ``LIBXML2_INCLUDE_DIR`` are valid.
Then also ``LibXml2_FOUND`` is set to ``TRUE``. If it is not found
and ``REQUIRED`` was used, it fails with a
:command:`message(FATAL_ERROR)`, independent whether ``QUIET`` was
used or not. If it is found, success will be reported, including
the content of the first ````. On repeated CMake runs,
the same message will not be printed again.
.. note::
If ```` does not match ``CMAKE_FIND_PACKAGE_NAME`` for the
calling module, a warning that there is a mismatch is given. The
``FPHSA_NAME_MISMATCHED`` variable may be set to bypass the warning if using
the old signature and the ``NAME_MISMATCHED`` argument using the new
signature. To avoid forcing the caller to require newer versions of CMake for
usage, the variable's value will be used if defined when the
``NAME_MISMATCHED`` argument is not passed for the new signature (but using
both is an error)..
Example for the full signature:
.. code-block:: cmake
find_package_handle_standard_args(LibArchive
REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
VERSION_VAR LibArchive_VERSION)
In this case, the ``LibArchive`` package is considered to be found if
both ``LibArchive_LIBRARY`` and ``LibArchive_INCLUDE_DIR`` are valid.
Also the version of ``LibArchive`` will be checked by using the version
contained in ``LibArchive_VERSION``. Since no ``FAIL_MESSAGE`` is given,
the default messages will be printed.
Another example for the full signature:
.. code-block:: cmake
find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4)
find_package_handle_standard_args(Automoc4 CONFIG_MODE)
In this case, a ``FindAutmoc4.cmake`` module wraps a call to
``find_package(Automoc4 NO_MODULE)`` and adds an additional search
directory for ``automoc4``. Then the call to
``find_package_handle_standard_args`` produces a proper success/failure
message.
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
# internal helper macro
macro(_FPHSA_FAILURE_MESSAGE _msg)
set (__msg "${_msg}")
if (FPHSA_REASON_FAILURE_MESSAGE)
string(APPEND __msg "\n Reason given by package: ${FPHSA_REASON_FAILURE_MESSAGE}\n")
endif()
if (${_NAME}_FIND_REQUIRED)
message(FATAL_ERROR "${__msg}")
else ()
if (NOT ${_NAME}_FIND_QUIETLY)
message(STATUS "${__msg}")
endif ()
endif ()
endmacro()
# internal helper macro to generate the failure message when used in CONFIG_MODE:
macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE)
# _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found:
if(${_NAME}_CONFIG)
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing:${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})")
else()
# If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version.
# List them all in the error message:
if(${_NAME}_CONSIDERED_CONFIGS)
set(configsText "")
list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount)
math(EXPR configsCount "${configsCount} - 1")
foreach(currentConfigIndex RANGE ${configsCount})
list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename)
list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version)
string(APPEND configsText "\n ${filename} (version ${version})")
endforeach()
if (${_NAME}_NOT_FOUND_MESSAGE)
if (FPHSA_REASON_FAILURE_MESSAGE)
string(PREPEND FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}\n ")
else()
set(FPHSA_REASON_FAILURE_MESSAGE "${${_NAME}_NOT_FOUND_MESSAGE}")
endif()
else()
string(APPEND configsText "\n")
endif()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:${configsText}")
else()
# Simple case: No Config-file was found at all:
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}")
endif()
endif()
endmacro()
function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
# Set up the arguments for `cmake_parse_arguments`.
set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED)
set(oneValueArgs FAIL_MESSAGE REASON_FAILURE_MESSAGE VERSION_VAR FOUND_VAR)
set(multiValueArgs REQUIRED_VARS)
# Check whether we are in 'simple' or 'extended' mode:
set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
unset(FPHSA_NAME_MISMATCHED_override)
if (DEFINED FPHSA_NAME_MISMATCHED)
# If the variable NAME_MISMATCHED variable is set, error if it is passed as
# an argument. The former is for old signatures, the latter is for new
# signatures.
list(FIND ARGN "NAME_MISMATCHED" name_mismatched_idx)
if (NOT name_mismatched_idx EQUAL "-1")
message(FATAL_ERROR
"The `NAME_MISMATCHED` argument may only be specified by the argument or "
"the variable, not both.")
endif ()
# But use the variable if it is not an argument to avoid forcing minimum
# CMake version bumps for calling modules.
set(FPHSA_NAME_MISMATCHED_override "${FPHSA_NAME_MISMATCHED}")
endif ()
if(${INDEX} EQUAL -1)
set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG})
set(FPHSA_REQUIRED_VARS ${ARGN})
set(FPHSA_VERSION_VAR)
else()
cmake_parse_arguments(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
if(FPHSA_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"")
endif()
if(NOT FPHSA_FAIL_MESSAGE)
set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
endif()
# In config-mode, we rely on the variable _CONFIG, which is set by find_package()
# when it successfully found the config-file, including version checking:
if(FPHSA_CONFIG_MODE)
list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG)
list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS)
set(FPHSA_VERSION_VAR ${_NAME}_VERSION)
endif()
if(NOT FPHSA_REQUIRED_VARS AND NOT FPHSA_HANDLE_COMPONENTS)
message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()")
endif()
endif()
if (DEFINED FPHSA_NAME_MISMATCHED_override)
set(FPHSA_NAME_MISMATCHED "${FPHSA_NAME_MISMATCHED_override}")
endif ()
if (DEFINED CMAKE_FIND_PACKAGE_NAME
AND NOT FPHSA_NAME_MISMATCHED
AND NOT _NAME STREQUAL CMAKE_FIND_PACKAGE_NAME)
message(AUTHOR_WARNING
"The package name passed to `find_package_handle_standard_args` "
"(${_NAME}) does not match the name of the calling package "
"(${CMAKE_FIND_PACKAGE_NAME}). This can lead to problems in calling "
"code that expects `find_package` result variables (e.g., `_FOUND`) "
"to follow a certain pattern.")
endif ()
# now that we collected all arguments, process them
if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG")
set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
endif()
if (FPHSA_REQUIRED_VARS)
list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR)
endif()
string(TOUPPER ${_NAME} _NAME_UPPER)
string(TOLOWER ${_NAME} _NAME_LOWER)
if(FPHSA_FOUND_VAR)
set(_FOUND_VAR_UPPER ${_NAME_UPPER}_FOUND)
set(_FOUND_VAR_MIXED ${_NAME}_FOUND)
if(FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_MIXED OR FPHSA_FOUND_VAR STREQUAL _FOUND_VAR_UPPER)
set(_FOUND_VAR ${FPHSA_FOUND_VAR})
else()
message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_FOUND_VAR_MIXED}\" and \"${_FOUND_VAR_UPPER}\" are valid names.")
endif()
else()
set(_FOUND_VAR ${_NAME_UPPER}_FOUND)
endif()
# collect all variables which were not found, so they can be printed, so the
# user knows better what went wrong (#6375)
set(MISSING_VARS "")
set(DETAILS "")
# check if all passed variables are valid
set(FPHSA_FOUND_${_NAME} TRUE)
foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS})
if(NOT ${_CURRENT_VAR})
set(FPHSA_FOUND_${_NAME} FALSE)
string(APPEND MISSING_VARS " ${_CURRENT_VAR}")
else()
string(APPEND DETAILS "[${${_CURRENT_VAR}}]")
endif()
endforeach()
if(FPHSA_FOUND_${_NAME})
set(${_NAME}_FOUND TRUE)
set(${_NAME_UPPER}_FOUND TRUE)
else()
set(${_NAME}_FOUND FALSE)
set(${_NAME_UPPER}_FOUND FALSE)
endif()
# component handling
unset(FOUND_COMPONENTS_MSG)
unset(MISSING_COMPONENTS_MSG)
if(FPHSA_HANDLE_COMPONENTS)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(${_NAME}_${comp}_FOUND)
if(NOT DEFINED FOUND_COMPONENTS_MSG)
set(FOUND_COMPONENTS_MSG "found components:")
endif()
string(APPEND FOUND_COMPONENTS_MSG " ${comp}")
else()
if(NOT DEFINED MISSING_COMPONENTS_MSG)
set(MISSING_COMPONENTS_MSG "missing components:")
endif()
string(APPEND MISSING_COMPONENTS_MSG " ${comp}")
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
string(APPEND MISSING_VARS " ${comp}")
endif()
endif()
endforeach()
set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}")
string(APPEND DETAILS "[c${COMPONENT_MSG}]")
endif()
# version handling:
set(VERSION_MSG "")
set(VERSION_OK TRUE)
# check with DEFINED here as the requested or found version may be "0"
if (DEFINED ${_NAME}_FIND_VERSION)
if(DEFINED ${FPHSA_VERSION_VAR})
set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}})
if(${_NAME}_FIND_VERSION_EXACT) # exact version required
# count the dots in the version string
string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${_FOUND_VERSION}")
# add one dot because there is one dot more than there are components
string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS)
if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT)
# Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT
# is at most 4 here. Therefore a simple lookup table is used.
if (${_NAME}_FIND_VERSION_COUNT EQUAL 1)
set(_VERSION_REGEX "[^.]*")
elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2)
set(_VERSION_REGEX "[^.]*\\.[^.]*")
elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3)
set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*")
else ()
set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
endif ()
string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${_FOUND_VERSION}")
unset(_VERSION_REGEX)
if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD)
set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")")
endif ()
unset(_VERSION_HEAD)
else ()
if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _FOUND_VERSION)
set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")")
endif ()
endif ()
unset(_VERSION_DOTS)
else() # minimum version specified:
if (${_NAME}_FIND_VERSION VERSION_GREATER _FOUND_VERSION)
set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
set(VERSION_MSG "(found suitable version \"${_FOUND_VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")")
endif ()
endif()
else()
# if the package was not found, but a version was given, add that to the output:
if(${_NAME}_FIND_VERSION_EXACT)
set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")")
else()
set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")")
endif()
endif()
else ()
# Check with DEFINED as the found version may be 0.
if(DEFINED ${FPHSA_VERSION_VAR})
set(VERSION_MSG "(found version \"${${FPHSA_VERSION_VAR}}\")")
endif()
endif ()
if(VERSION_OK)
string(APPEND DETAILS "[v${${FPHSA_VERSION_VAR}}(${${_NAME}_FIND_VERSION})]")
else()
set(${_NAME}_FOUND FALSE)
endif()
# print the result:
if (${_NAME}_FOUND)
FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}")
else ()
if(FPHSA_CONFIG_MODE)
_FPHSA_HANDLE_FAILURE_CONFIG_MODE()
else()
if(NOT VERSION_OK)
set(RESULT_MSG)
if (_FIRST_REQUIRED_VAR)
string (APPEND RESULT_MSG "found ${${_FIRST_REQUIRED_VAR}}")
endif()
if (COMPONENT_MSG)
if (RESULT_MSG)
string (APPEND RESULT_MSG ", ")
endif()
string (APPEND RESULT_MSG "${FOUND_COMPONENTS_MSG}")
endif()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (${RESULT_MSG})")
else()
_FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing:${MISSING_VARS}) ${VERSION_MSG}")
endif()
endif()
endif ()
set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
endfunction()
pg-gvm-22.6.8/cmake/FindPackageMessage.cmake 0000664 0000000 0000000 00000003257 14765004441 0020545 0 ustar 00root root 0000000 0000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPackageMessage
------------------
.. code-block:: cmake
find_package_message( "message for user" "find result details")
This function is intended to be used in FindXXX.cmake modules files.
It will print a message once for each unique find result. This is
useful for telling the user where a package was found. The first
argument specifies the name (XXX) of the package. The second argument
specifies the message to display. The third argument lists details
about the find result so that if they change the message will be
displayed again. The macro also obeys the QUIET argument to the
find_package command.
Example:
.. code-block:: cmake
if(X11_FOUND)
find_package_message(X11 "Found X11: ${X11_X11_LIB}"
"[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
else()
...
endif()
#]=======================================================================]
function(find_package_message pkg msg details)
# Avoid printing a message repeatedly for the same find result.
if(NOT ${pkg}_FIND_QUIETLY)
string(REPLACE "\n" "" details "${details}")
set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg})
if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}")
# The message has not yet been printed.
message(STATUS "${msg}")
# Save the find details in the cache to avoid printing the same
# message again.
set("${DETAILS_VAR}" "${details}"
CACHE INTERNAL "Details about finding ${pkg}")
endif()
endif()
endfunction()
pg-gvm-22.6.8/cmake/FindPostgreSQL.cmake 0000664 0000000 0000000 00000027071 14765004441 0017710 0 ustar 00root root 0000000 0000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPostgreSQL
--------------
Find the PostgreSQL installation.
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``PostgreSQL::PostgreSQL``
if PostgreSQL has been found.
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``PostgreSQL_FOUND``
True if PostgreSQL is found.
``PostgreSQL_LIBRARIES``
the PostgreSQL libraries needed for linking
``PostgreSQL_INCLUDE_DIRS``
the directories of the PostgreSQL headers
``PostgreSQL_LIBRARY_DIRS``
the link directories for PostgreSQL libraries
``PostgreSQL_VERSION_STRING``
the version of PostgreSQL found
#]=======================================================================]
# ----------------------------------------------------------------------------
# History:
# This module is derived from the module originally found in the VTK source tree.
#
# ----------------------------------------------------------------------------
# Note:
# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
# version number of the implementation of PostgreSQL.
# In Windows the default installation of PostgreSQL uses that as part of the path.
# E.g C:\Program Files\PostgreSQL\8.4.
# Currently, the following version numbers are known to this module:
# "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
#
# To use this variable just do something like this:
# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
# This will mean that the versions you set here will be found first in the order
# specified before the default ones are searched.
#
# ----------------------------------------------------------------------------
# You may need to manually set:
# PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are.
# PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are.
# If FindPostgreSQL.cmake cannot find the include files or the library files.
#
# ----------------------------------------------------------------------------
# The following variables are set if PostgreSQL is found:
# PostgreSQL_FOUND - Set to true when PostgreSQL is found.
# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL
# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
# PostgreSQL_LIBRARIES - The PostgreSQL libraries.
#
# The ``PostgreSQL::PostgreSQL`` imported target is also created.
#
# ----------------------------------------------------------------------------
# If you have installed PostgreSQL in a non-standard location.
# (Please note that in the following comments, it is assumed that
# points to the root directory of the include directory of PostgreSQL.)
# Then you have three options.
# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to /include and
# PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
# 2) Use CMAKE_INCLUDE_PATH to set a path to /PostgreSQL<-version>. This will allow find_path()
# to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/include")
# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
# installed PostgreSQL, e.g. .
#
# ----------------------------------------------------------------------------
set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include")
set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}")
set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.")
set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}")
set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4")
set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS}
"17" "16" "15" "14" "13" "12" "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
# Define additional search paths for root directories.
set( PostgreSQL_ROOT_DIRECTORIES
ENV PostgreSQL_ROOT
${PostgreSQL_ROOT}
)
foreach(suffix ${PostgreSQL_KNOWN_VERSIONS})
if(WIN32)
list(APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES
"PostgreSQL/${suffix}/lib")
list(APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES
"PostgreSQL/${suffix}/include")
list(APPEND PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES
"PostgreSQL/${suffix}/include/server")
endif()
if(UNIX)
list(APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES
"postgresql${suffix}"
"pgsql-${suffix}/lib")
list(APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES
"postgresql${suffix}"
"postgresql/${suffix}"
"pgsql-${suffix}/include")
list(APPEND PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES
"postgresql${suffix}/server"
"postgresql/${suffix}/server"
"pgsql-${suffix}/include/server")
endif()
endforeach()
#
# Look for an installation.
#
find_path(PostgreSQL_INCLUDE_DIR
NAMES libpq-fe.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
pgsql
postgresql
include
${PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES}
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
postgresql
pgsql/server
postgresql/server
include/server
${PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES}
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)
# The PostgreSQL library.
set (PostgreSQL_LIBRARY_TO_FIND pq)
# Setting some more prefixes for the library
set (PostgreSQL_LIB_PREFIX "")
if ( WIN32 )
set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
set (PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
endif()
function(__postgresql_find_library _name)
find_library(${_name}
NAMES ${ARGN}
PATHS
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
lib
${PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES}
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_LIBRARY_DIR_MESSAGE}"
)
endfunction()
# For compatibility with versions prior to this multi-config search, honor
# any PostgreSQL_LIBRARY that is already specified and skip the search.
if(PostgreSQL_LIBRARY)
set(PostgreSQL_LIBRARIES "${PostgreSQL_LIBRARY}")
get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY}" PATH)
else()
__postgresql_find_library(PostgreSQL_LIBRARY_RELEASE ${PostgreSQL_LIBRARY_TO_FIND})
__postgresql_find_library(PostgreSQL_LIBRARY_DEBUG ${PostgreSQL_LIBRARY_TO_FIND}d)
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(PostgreSQL)
mark_as_advanced(PostgreSQL_LIBRARY_RELEASE PostgreSQL_LIBRARY_DEBUG)
if(PostgreSQL_LIBRARY_RELEASE)
get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY_RELEASE}" PATH)
elseif(PostgreSQL_LIBRARY_DEBUG)
get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY_DEBUG}" PATH)
else()
set(PostgreSQL_LIBRARY_DIR "")
endif()
endif()
if (PostgreSQL_INCLUDE_DIR)
# Some platforms include multiple pg_config.hs for multi-lib configurations
# This is a temporary workaround. A better solution would be to compile
# a dummy c file and extract the value of the symbol.
file(GLOB _PG_CONFIG_HEADERS "${PostgreSQL_INCLUDE_DIR}/pg_config*.h")
foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS})
if(EXISTS "${_PG_CONFIG_HEADER}")
file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str
REGEX "^#define[\t ]+PG_VERSION_NUM[\t ]+.*")
if(pgsql_version_str)
string(REGEX REPLACE "^#define[\t ]+PG_VERSION_NUM[\t ]+([0-9]*).*"
"\\1" _PostgreSQL_VERSION_NUM "${pgsql_version_str}")
break()
endif()
endif()
endforeach()
if (_PostgreSQL_VERSION_NUM)
# 9.x and older encoding
if (_PostgreSQL_VERSION_NUM LESS 100000)
math(EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000")
math(EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000 / 100")
math(EXPR _PostgreSQL_patch_version "${_PostgreSQL_VERSION_NUM} % 100")
set(PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}.${_PostgreSQL_patch_version}")
unset(_PostgreSQL_major_version)
unset(_PostgreSQL_minor_version)
unset(_PostgreSQL_patch_version)
else ()
math(EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000")
math(EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000")
set(PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}")
unset(_PostgreSQL_major_version)
unset(_PostgreSQL_minor_version)
endif ()
else ()
foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS})
if(EXISTS "${_PG_CONFIG_HEADER}")
file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str
REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"")
if(pgsql_version_str)
string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*"
"\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}")
break()
endif()
endif()
endforeach()
endif ()
unset(_PostgreSQL_VERSION_NUM)
unset(pgsql_version_str)
endif()
# Did we find anything?
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(PostgreSQL
REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR
VERSION_VAR PostgreSQL_VERSION_STRING)
set(PostgreSQL_FOUND ${POSTGRESQL_FOUND})
function(__postgresql_import_library _target _var _config)
if(_config)
set(_config_suffix "_${_config}")
else()
set(_config_suffix "")
endif()
set(_lib "${${_var}${_config_suffix}}")
if(EXISTS "${_lib}")
if(_config)
set_property(TARGET ${_target} APPEND PROPERTY
IMPORTED_CONFIGURATIONS ${_config})
endif()
set_target_properties(${_target} PROPERTIES
IMPORTED_LOCATION${_config_suffix} "${_lib}")
endif()
endfunction()
# Now try to get the include and library path.
if(PostgreSQL_FOUND)
if (NOT TARGET PostgreSQL::PostgreSQL)
add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED)
set_target_properties(PostgreSQL::PostgreSQL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR};${PostgreSQL_TYPE_INCLUDE_DIR}")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "RELEASE")
__postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "DEBUG")
endif ()
set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
endif()
mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR)
pg-gvm-22.6.8/cmake/GetGit.cmake 0000664 0000000 0000000 00000003641 14765004441 0016264 0 ustar 00root root 0000000 0000000 # Copyright (C) 2018 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
# This script attempts to determine the Git commit ID and writes or updates
# a "gitrevision.h" file if successful.
find_package (Git)
macro (Git_GET_REVISION dir variable)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${dir}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${dir}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
string (REPLACE "/" "_" GIT_BRANCH ${GIT_BRANCH})
set (${variable} "${GIT_COMMIT_HASH}-${GIT_BRANCH}")
endmacro (Git_GET_REVISION)
if (EXISTS "${SOURCE_DIR}/.git/")
if (GIT_EXECUTABLE)
Git_GET_REVISION (${SOURCE_DIR} GIT_REVISION)
endif (GIT_EXECUTABLE)
endif (EXISTS "${SOURCE_DIR}/.git/")
if (GIT_REVISION)
file (WRITE gitrevision.h.in "#define GVMD_GIT_REVISION \"${GIT_REVISION}\"\n")
execute_process (COMMAND ${CMAKE_COMMAND} -E copy_if_different
gitrevision.h.in gitrevision.h)
file (REMOVE gitrevision.h.in)
endif (GIT_REVISION)
pg-gvm-22.6.8/cmake/SelectLibraryConfigurations.cmake 0000664 0000000 0000000 00000006332 14765004441 0022560 0 ustar 00root root 0000000 0000000 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
SelectLibraryConfigurations
---------------------------
.. code-block:: cmake
select_library_configurations(basename)
This macro takes a library base name as an argument, and will choose
good values for the variables
::
basename_LIBRARY
basename_LIBRARIES
basename_LIBRARY_DEBUG
basename_LIBRARY_RELEASE
depending on what has been found and set.
If only ``basename_LIBRARY_RELEASE`` is defined, ``basename_LIBRARY`` will
be set to the release value, and ``basename_LIBRARY_DEBUG`` will be set
to ``basename_LIBRARY_DEBUG-NOTFOUND``. If only ``basename_LIBRARY_DEBUG``
is defined, then ``basename_LIBRARY`` will take the debug value, and
``basename_LIBRARY_RELEASE`` will be set to ``basename_LIBRARY_RELEASE-NOTFOUND``.
If the generator supports configuration types, then ``basename_LIBRARY``
and ``basename_LIBRARIES`` will be set with debug and optimized flags
specifying the library to be used for the given configuration. If no
build type has been set or the generator in use does not support
configuration types, then ``basename_LIBRARY`` and ``basename_LIBRARIES``
will take only the release value, or the debug value if the release one
is not set.
#]=======================================================================]
# This macro was adapted from the FindQt4 CMake module and is maintained by Will
# Dicharry .
macro(select_library_configurations basename)
if(NOT ${basename}_LIBRARY_RELEASE)
set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
endif()
if(NOT ${basename}_LIBRARY_DEBUG)
set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
endif()
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
# if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
# single-config generators, set optimized and debug libraries
set( ${basename}_LIBRARY "" )
foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
endforeach()
foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
list( APPEND ${basename}_LIBRARY debug "${_libname}" )
endforeach()
elseif( ${basename}_LIBRARY_RELEASE )
set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
elseif( ${basename}_LIBRARY_DEBUG )
set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
else()
set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
endif()
set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
if( ${basename}_LIBRARY )
set( ${basename}_FOUND TRUE )
endif()
mark_as_advanced( ${basename}_LIBRARY_RELEASE
${basename}_LIBRARY_DEBUG
)
endmacro()
pg-gvm-22.6.8/control.in 0000664 0000000 0000000 00000000175 14765004441 0015026 0 ustar 00root root 0000000 0000000 comment = 'Functions for GVMd'
default_version = '@PROJECT_API_VERSION@'
module_pathname = '$libdir/lib@CMAKE_PROJECT_NAME@'
pg-gvm-22.6.8/gvmd-tables.sql 0000664 0000000 0000000 00000000425 14765004441 0015742 0 ustar 00root root 0000000 0000000 --
-- Create tables required for testing the extension, normally created by gvmd.
--
CREATE TABLE IF NOT EXISTS meta
(id SERIAL PRIMARY KEY,
name text UNIQUE NOT NULL,
value text);
INSERT INTO meta(name, value)
VALUES ('max_hosts', 1024)
ON CONFLICT DO NOTHING;
pg-gvm-22.6.8/include/ 0000775 0000000 0000000 00000000000 14765004441 0014436 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/include/array.h 0000664 0000000 0000000 00000002035 14765004441 0015725 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file array.h
* @brief Headers for array_x memory management
*/
#ifndef _GVMD_ARRAY_X_H
#define _GVMD_ARRAY_X_H
typedef struct array_x
{
void **data;
int len;
int cap;
} array_x;
array_x *new_array_x(void);
void free_array_x(array_x *arr);
int append_x(array_x *arr, void *datum);
#endif
pg-gvm-22.6.8/include/hosts.h 0000664 0000000 0000000 00000001762 14765004441 0015755 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2014-2020 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/**
* @file hosts.h
* @brief Utility functions for host operations.
*/
#ifndef _GVMD_HOSTS_X
#define _GVMD_HOSTS_X
int
manage_count_hosts_max (const char *, const char *, int);
int
hosts_str_contains (const char *, const char *, int);
#endif pg-gvm-22.6.8/include/ical_utils.h 0000664 0000000 0000000 00000002274 14765004441 0016744 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020-2022 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file ical_utils.h
* @brief Headers for ical functions
*/
#ifndef _GVMD_MANAGE_UTILS_X_H
#define _GVMD_MANAGE_UTILS_X_H
#include
#include
icaltimezone *
icalendar_timezone_from_string_x (const char *);
time_t
icalendar_next_time_from_string_x (const char *, time_t, const char *, int);
time_t
icalendar_next_time_from_vcalendar_x (icalcomponent *, time_t, const char *,
int);
#endif
pg-gvm-22.6.8/pg-gvm-make-dev-links.in 0000775 0000000 0000000 00000003305 14765004441 0017351 0 ustar 00root root 0000000 0000000 #!/bin/sh
# Copyright (C) 2021-2022 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Helper script to create symlinks for development setups of pg-gvm
#
PREFIX_SHARE_DIR="@CMAKE_INSTALL_DEV_PREFIX@/share/postgresql"
PREFIX_EXTLIB_DIR="@CMAKE_INSTALL_DEV_PREFIX@/lib/postgresql"
REAL_SHARE_DIR="@PostgreSQL_SHARE_DIR@"
REAL_EXTLIB_DIR="@PostgreSQL_EXTLIB_DIR@"
LIB_PREFIX="@CMAKE_SHARED_MODULE_PREFIX@"
LIB_SUFFIX="@CMAKE_SHARED_MODULE_SUFFIX@"
LIB_FILE_NAME="${LIB_PREFIX}@CMAKE_PROJECT_NAME@${LIB_SUFFIX}"
CONTROLOUT="@CONTROLOUT@"
SQLOUT="@SQLOUT@"
echo "Creating links:"
echo " $REAL_SHARE_DIR/extension/$CONTROLOUT"
ln -s "$PREFIX_SHARE_DIR/extension/$CONTROLOUT" \
"$REAL_SHARE_DIR/extension/$CONTROLOUT"
for update_file in $(ls -1 $PREFIX_SHARE_DIR/extension/*.sql);
do
update_basename=$(basename "$update_file")
echo " $REAL_SHARE_DIR/extension/$update_basename"
ln -s "$update_file" "$REAL_SHARE_DIR/extension/$update_basename"
done
echo " $REAL_EXTLIB_DIR/$LIB_FILE_NAME"
ln -s "$PREFIX_EXTLIB_DIR/$LIB_FILE_NAME" \
"$REAL_EXTLIB_DIR/$LIB_FILE_NAME"
pg-gvm-22.6.8/sql/ 0000775 0000000 0000000 00000000000 14765004441 0013612 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/sql/hosts.in.sql 0000664 0000000 0000000 00000002005 14765004441 0016075 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
CREATE OR REPLACE FUNCTION hosts_contains (text, text)
RETURNS boolean
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_hosts_contains$$;
CREATE OR REPLACE FUNCTION max_hosts (text, text)
RETURNS integer
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_max_hosts$$;
pg-gvm-22.6.8/sql/ical.in.sql 0000664 0000000 0000000 00000002055 14765004441 0015652 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020-2022 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
CREATE OR REPLACE FUNCTION next_time_ical (text, bigint, text)
RETURNS integer
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_next_time_ical$$;
CREATE OR REPLACE FUNCTION next_time_ical (text, bigint, text, integer)
RETURNS integer
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_next_time_ical$$;
pg-gvm-22.6.8/sql/regexp.in.sql 0000664 0000000 0000000 00000001553 14765004441 0016236 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2021 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
CREATE OR REPLACE FUNCTION regexp (text, text)
RETURNS boolean
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_regexp$$;
pg-gvm-22.6.8/sql/update/ 0000775 0000000 0000000 00000000000 14765004441 0015074 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/sql/update/pg-gvm--1.0--1.1.sql 0000664 0000000 0000000 00000002235 14765004441 0017737 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2022 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
CREATE OR REPLACE FUNCTION next_time_ical (text, bigint, text)
RETURNS integer
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_next_time_ical$$;
CREATE OR REPLACE FUNCTION next_time_ical (text, bigint, text, integer)
RETURNS integer
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$sql_next_time_ical$$;
DROP FUNCTION IF EXISTS next_time_ical (text, text);
DROP FUNCTION IF EXISTS next_time_ical (text, text, integer); pg-gvm-22.6.8/sql/update/pg-gvm--1.1--22.4.0.sql 0000664 0000000 0000000 00000000213 14765004441 0020156 0 ustar 00root root 0000000 0000000 /* SPDX-FileCopyrightText: 2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-- Empty update. Nothing has changed.
pg-gvm-22.6.8/sql/update/pg-gvm--22.4.0--22.5.sql 0000664 0000000 0000000 00000000213 14765004441 0020245 0 ustar 00root root 0000000 0000000 /* SPDX-FileCopyrightText: 2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-- Empty update. Nothing has changed.
pg-gvm-22.6.8/sql/update/pg-gvm--22.5--22.6.sql 0000664 0000000 0000000 00000000213 14765004441 0020111 0 ustar 00root root 0000000 0000000 /* SPDX-FileCopyrightText: 2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-- Empty update. Nothing has changed.
pg-gvm-22.6.8/src/ 0000775 0000000 0000000 00000000000 14765004441 0013602 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/src/array.c 0000664 0000000 0000000 00000004520 14765004441 0015065 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file array.c
* @brief Memory management for arrays based on postgres functions
*
* Functions to have transaction safe memory allocation using palloc0 and pfree.
*/
#include "array.h"
#include "postgres.h"
/**
* @brief Allocate memory for new array_x
*
* @return The new array_x
*/
array_x
*new_array_x(void)
{
array_x *arr;
if ((arr = (array_x*)palloc0(sizeof(array_x))) == NULL)
return NULL;
if ((arr->data = (void**)palloc0(sizeof(void*) * 10)) == NULL)
{
pfree(arr);
return NULL;
}
arr->cap = 10;
arr->len = 0;
return arr;
}
/**
* @brief Free the memory of a previously created array_x
*
* @param[in] arr The array
*/
void
free_array_x(array_x *arr)
{
if (arr != NULL)
{
if (arr->data != NULL)
{
int i;
for (i = 0; i < arr->len; i++)
{
if (arr->data[i] != NULL)
{
pfree(arr->data[i]);
arr->data[i] = NULL;
}
}
pfree(arr->data);
arr->data = NULL;
}
pfree(arr);
}
}
/**
* @brief Append a new item to an existing array
*
* @param[in] arr The Array
* @param[in] datum The new item
*
* @return 1 if item appended, else 0
*/
int
append_x(array_x *arr, void *datum)
{
if (arr->len == arr->cap)
{
int new_size = arr->cap*2;
void **ndata = (void**)repalloc(arr->data, new_size*sizeof(void*));
if (ndata == NULL)
return 0;
memset(&arr->data[arr->len], 0, sizeof(void*)*arr->len);
}
arr->data[arr->len++] = datum;
return 1;
}
pg-gvm-22.6.8/src/hosts.c 0000664 0000000 0000000 00000013511 14765004441 0015107 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file hosts.c
*
* @brief This file defines functions that are available via the PostgreSQL
* @brief extension
*/
#include "hosts.h"
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
#include "glib.h"
#include
/**
* @brief Create a string from a portion of text.
*
* @param[in] text_arg Text.
* @param[in] length Length to create.
*
* @return Freshly allocated string.
*/
static char *
textndup (text *text_arg, int length)
{
char *ret;
ret = palloc (length + 1);
memcpy (ret, VARDATA (text_arg), length);
ret[length] = 0;
return ret;
}
/**
* @brief Get the maximum number of hosts.
*
* @return The maximum number of hosts.
*/
static int
get_max_hosts_x ()
{
int ret;
int max_hosts = 4095;
SPI_connect ();
ret = SPI_exec ("SELECT coalesce ((SELECT value FROM meta"
" WHERE name = 'max_hosts'),"
" '4095');", /* Same as MANAGE_MAX_HOSTS. */
1); /* Max 1 row returned. */
if (SPI_processed > 0 && ret > 0 && SPI_tuptable != NULL)
{
char *cell;
cell = SPI_getvalue (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
elog (DEBUG1, "cell: %s", cell);
if (cell)
max_hosts = atoi (cell);
}
elog (DEBUG1, "done");
SPI_finish ();
return max_hosts;
}
/**
* @brief Define function for Postgres.
*/
PG_FUNCTION_INFO_V1 (sql_max_hosts);
/**
* @brief Return number of hosts.
*
* This is a callback for a SQL function of two arguments.
*
* @return Postgres Datum.
*/
Datum
sql_max_hosts (PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL (0))
PG_RETURN_INT32 (0);
else
{
text *hosts_arg;
char *hosts, *exclude;
int ret, max_hosts;
hosts_arg = PG_GETARG_TEXT_P (0);
hosts = textndup (hosts_arg, VARSIZE (hosts_arg) - VARHDRSZ);
if (PG_ARGISNULL (1))
{
exclude = palloc (1);
exclude[0] = 0;
}
else
{
text *exclude_arg;
exclude_arg = PG_GETARG_TEXT_P (1);
exclude = textndup (exclude_arg, VARSIZE (exclude_arg) - VARHDRSZ);
}
max_hosts = get_max_hosts_x ();
ret = manage_count_hosts_max (hosts, exclude, max_hosts);
pfree (hosts);
pfree (exclude);
PG_RETURN_INT32 (ret);
}
}
/**
* @brief Define function for Postgres.
*/
PG_FUNCTION_INFO_V1 (sql_hosts_contains);
/**
* @brief Return if argument 1 matches regular expression in argument 2.
*
* This is a callback for a SQL function of two arguments.
*
* @return Postgres Datum.
*/
Datum
sql_hosts_contains (PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL (0) || PG_ARGISNULL (1))
PG_RETURN_BOOL (0);
else
{
text *hosts_arg, *find_host_arg;
char *hosts, *find_host;
int max_hosts, ret;
hosts_arg = PG_GETARG_TEXT_P(0);
hosts = textndup (hosts_arg, VARSIZE (hosts_arg) - VARHDRSZ);
find_host_arg = PG_GETARG_TEXT_P(1);
find_host = textndup (find_host_arg, VARSIZE (find_host_arg) - VARHDRSZ);
max_hosts = get_max_hosts_x ();
if (hosts_str_contains ((gchar *) hosts, (gchar *) find_host,
max_hosts))
ret = 1;
else
ret = 0;
pfree (hosts);
pfree (find_host);
PG_RETURN_BOOL (ret);
}
}
/**
* @brief Return number of hosts described by a hosts string.
*
* @param[in] given_hosts String describing hosts.
* @param[in] exclude_hosts String describing hosts excluded from given set.
* @param[in] max_hosts Max hosts.
*
* @return Number of hosts, or -1 on error.
*/
int
manage_count_hosts_max (const char *given_hosts, const char *exclude_hosts,
int max_hosts)
{
int count;
gvm_hosts_t *hosts;
hosts = gvm_hosts_new_with_max (given_hosts, max_hosts);
if (hosts == NULL)
return -1;
if (exclude_hosts)
{
if (gvm_hosts_exclude_with_max (hosts,
exclude_hosts,
max_hosts)
< 0)
return -1;
}
count = gvm_hosts_count (hosts);
gvm_hosts_free (hosts);
return count;
}
/**
* @brief Returns whether a host has an equal host in a hosts string.
*
* For example, 192.168.10.1 has an equal in a hosts string
* "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't.
*
* @param[in] hosts_str Hosts string to check.
* @param[in] find_host_str The host to find.
* @param[in] max_hosts Maximum number of hosts allowed in hosts_str.
*
* @return 1 if host has equal in hosts_str, 0 otherwise.
*/
int
hosts_str_contains (const char* hosts_str, const char* find_host_str,
int max_hosts)
{
gvm_hosts_t *hosts, *find_hosts;
hosts = gvm_hosts_new_with_max (hosts_str, max_hosts);
find_hosts = gvm_hosts_new_with_max (find_host_str, 1);
if (hosts == NULL || find_hosts == NULL || find_hosts->count != 1)
{
gvm_hosts_free (hosts);
gvm_hosts_free (find_hosts);
return 0;
}
int ret = gvm_host_in_hosts (find_hosts->hosts[0], NULL, hosts);
gvm_hosts_free (hosts);
gvm_hosts_free (find_hosts);
return ret;
} pg-gvm-22.6.8/src/ical.c 0000664 0000000 0000000 00000005232 14765004441 0014660 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2020-2022 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file ical.c
*
* @brief This file defines functions that are available via the PostgreSQL
* @brief extension
*/
#include "ical_utils.h"
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
/**
* @brief Create a string from a portion of text.
*
* @param[in] text_arg Text.
* @param[in] length Length to create.
*
* @return Freshly allocated string.
*/
static char *
textndup (text *text_arg, int length)
{
char *ret;
ret = palloc (length + 1);
memcpy (ret, VARDATA (text_arg), length);
ret[length] = 0;
return ret;
}
/**
* @brief Define function for Postgres.
*/
PG_FUNCTION_INFO_V1 (sql_next_time_ical);
/**
* @brief Get the next time given schedule times.
*
* This is a callback for a SQL function of one to three arguments.
*
* @return Postgres Datum.
*/
Datum
sql_next_time_ical (PG_FUNCTION_ARGS)
{
char *ical_string, *zone;
int64 reference_time;
int periods_offset;
int32 ret;
if (PG_NARGS() < 1 || PG_ARGISNULL (0))
{
PG_RETURN_NULL ();
}
else
{
text* ical_string_arg;
ical_string_arg = PG_GETARG_TEXT_P (0);
ical_string = textndup (ical_string_arg,
VARSIZE (ical_string_arg) - VARHDRSZ);
}
if (PG_NARGS() < 2 || PG_ARGISNULL (1))
reference_time = 0;
else
reference_time = PG_GETARG_INT64 (1);
if (PG_NARGS() < 3 || PG_ARGISNULL (2))
zone = NULL;
else
{
text* timezone_arg;
timezone_arg = PG_GETARG_TEXT_P (2);
zone = textndup (timezone_arg, VARSIZE (timezone_arg) - VARHDRSZ);
}
if (PG_NARGS() < 4)
periods_offset = 0;
else
periods_offset = PG_GETARG_INT32 (3);
ret = icalendar_next_time_from_string_x (ical_string, reference_time, zone,
periods_offset);
if (ical_string)
pfree (ical_string);
if (zone)
pfree (zone);
PG_RETURN_INT32 (ret);
}
pg-gvm-22.6.8/src/ical_utils.c 0000664 0000000 0000000 00000033272 14765004441 0016105 0 ustar 00root root 0000000 0000000
/* Copyright (C) 2020-2022 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file ical_utils.c
* @brief Implements ical functions for the GVM PostgreSQL Extension.
*/
#include
#include "ical_utils.h"
#include "array.h"
#include "postgres.h"
/**
* @brief Collect the times of EXDATE or RDATE properties from an VEVENT.
* The returned GPtrArray will contain pointers to icaltimetype structs, which
* will be freed with g_ptr_array_free.
*
* @param[in] vevent The VEVENT component to collect times.
* @param[in] type The property to get the times from.
*
* @return GPtrArray with pointers to collected times or NULL on error.
*/
static array_x*
icalendar_times_from_vevent_x (icalcomponent *vevent, icalproperty_kind type)
{
array_x* times;
icalproperty *date_prop;
if (icalcomponent_isa (vevent) != ICAL_VEVENT_COMPONENT
|| (type != ICAL_EXDATE_PROPERTY && type != ICAL_RDATE_PROPERTY))
return NULL;
times = new_array_x ();
if (times == NULL)
{
return NULL;
}
date_prop = icalcomponent_get_first_property (vevent, type);
while (date_prop)
{
icaltimetype *time;
time = (icaltimetype*)palloc0 (sizeof (icaltimetype));
if (time == NULL)
{
return NULL;
}
if (type == ICAL_EXDATE_PROPERTY)
{
*time = icalproperty_get_exdate (date_prop);
}
else if (type == ICAL_RDATE_PROPERTY)
{
struct icaldatetimeperiodtype datetimeperiod;
datetimeperiod = icalproperty_get_rdate (date_prop);
// Assume periods have been converted to date or datetime
*time = datetimeperiod.time;
}
if (append_x(times, time) != 1)
{
return NULL;
}
date_prop = icalcomponent_get_next_property (vevent, type);
}
return times;
}
/**
* @brief Get the next or previous time from a list of RDATEs.
*
* @param[in] rdates The list of RDATEs.
* @param[in] tz The icaltimezone to use.
* @param[in] ref_time_ical The reference time (usually the current time).
* @param[in] periods_offset 0 for next, -1 for previous from/before reference.
*
* @return The next or previous time as time_t.
*/
static time_t
icalendar_next_time_from_rdates_x (array_x *rdates,
icaltimetype ref_time_ical,
icaltimezone *tz,
int periods_offset)
{
int index;
time_t ref_time, closest_time;
int old_diff;
closest_time = 0;
ref_time = icaltime_as_timet_with_zone (ref_time_ical, tz);
if (periods_offset < 0)
old_diff = INT_MIN;
else
old_diff = INT_MAX;
for (index = 0; index < rdates->len; index++)
{
icaltimetype *iter_time_ical;
time_t iter_time;
int time_diff;
iter_time_ical = (icaltimetype*)rdates->data[index];
iter_time = icaltime_as_timet_with_zone (*iter_time_ical, tz);
time_diff = iter_time - ref_time;
// Cases: previous (offset -1): latest before reference
// next (offset 0): earliest after reference
if ((periods_offset == -1 && time_diff < 0 && time_diff > old_diff)
|| (periods_offset == 0 && time_diff >= 0 && time_diff < old_diff))
{
closest_time = iter_time;
old_diff = time_diff;
}
}
return closest_time;
}
/**
* @brief Tests if an icaltimetype matches one in a GPtrArray.
* When an icaltimetype is a date, only the date must match, otherwise both
* date and time must match.
*
* @param[in] time The icaltimetype to try to find a match of.
* @param[in] times_array Array of pointers to check for a matching time.
*
* @return Whether a match was found.
*/
static int
icalendar_time_matches_array_x (icaltimetype time, array_x *times_array)
{
int found = 0;
int index;
if (times_array == NULL)
return 0;
for (index = 0;
found == 0 && index < times_array->len;
index++)
{
int compare_result;
icaltimetype *array_time = (icaltimetype*)times_array->data[index];
if (array_time->is_date)
compare_result = icaltime_compare_date_only (time, *array_time);
else
compare_result = icaltime_compare (time, *array_time);
if (compare_result == 0)
found = 1;
}
return found;
}
/**
* @brief Calculate the next time of a recurrence
*
* @param[in] recurrence The recurrence rule to evaluate.
* @param[in] dtstart The start time of the recurrence.
* @param[in] reference_time The reference time (usually the current time).
* @param[in] tz The icaltimezone to use.
* @param[in] exdates GList of EXDATE dates or datetimes to skip.
* @param[in] rdates GList of RDATE datetimes to include.
* @param[in] periods_offset 0 for next, -1 for previous from/before reference.
*
* @return The next time.
*/
static time_t
icalendar_next_time_from_recurrence_x (struct icalrecurrencetype recurrence,
icaltimetype dtstart,
icaltimetype reference_time,
icaltimezone *tz,
array_x *exdates,
array_x *rdates,
int periods_offset)
{
icalrecur_iterator *recur_iter;
icaltimetype recur_time, prev_time, next_time;
time_t rdates_time;
// Start iterating over rule-based times
recur_iter = icalrecur_iterator_new (recurrence, dtstart);
recur_time = icalrecur_iterator_next (recur_iter);
if (icaltime_is_null_time (recur_time))
{
// Use DTSTART if there are no recurrence rule times
if (icaltime_compare (dtstart, reference_time) < 0)
{
prev_time = dtstart;
next_time = icaltime_null_time ();
}
else
{
prev_time = icaltime_null_time ();
next_time = dtstart;
}
}
else
{
/* Handle rule-based recurrence times:
* Get the first rule-based recurrence time, skipping ahead in case
* DTSTART is excluded by EXDATEs. */
while (icaltime_is_null_time (recur_time) == 0
&& icalendar_time_matches_array_x (recur_time, exdates))
{
recur_time = icalrecur_iterator_next (recur_iter);
}
// Set the first recur_time as either the previous or next time.
if (icaltime_compare (recur_time, reference_time) < 0)
{
prev_time = recur_time;
}
else
{
prev_time = icaltime_null_time ();
}
/* Iterate over rule-based recurrences up to first time after
* reference time */
while (icaltime_is_null_time (recur_time) == 0
&& icaltime_compare (recur_time, reference_time) <= 0)
{
if (icalendar_time_matches_array_x (recur_time, exdates) == 0)
prev_time = recur_time;
recur_time = icalrecur_iterator_next (recur_iter);
}
// Skip further ahead if last recurrence time is in EXDATEs
while (icaltime_is_null_time (recur_time) == 0
&& icalendar_time_matches_array_x (recur_time, exdates))
{
recur_time = icalrecur_iterator_next (recur_iter);
}
// Select last recur_time as the next_time
next_time = recur_time;
}
// Get time from RDATEs
rdates_time = icalendar_next_time_from_rdates_x (rdates, reference_time, tz,
periods_offset);
// Select appropriate time as the RRULE time, compare it to the RDATEs time
// and return the appropriate time.
if (periods_offset == -1)
{
time_t rrule_time;
rrule_time = icaltime_as_timet_with_zone (prev_time, tz);
if (rdates_time == 0 || rrule_time - rdates_time > 0)
return rrule_time;
else
return rdates_time;
}
else
{
time_t rrule_time;
rrule_time = icaltime_as_timet_with_zone (next_time, tz);
if (rdates_time == 0 || rrule_time - rdates_time < 0)
return rrule_time;
else
return rdates_time;
}
}
/**
* @brief Try to get a built-in libical timezone from a tzid or city name.
*
* @param[in] tzid The tzid or Olson city name.
*
* @return The built-in timezone if found, else NULL.
*/
icaltimezone*
icalendar_timezone_from_string_x (const char *tzid)
{
if (tzid)
{
icaltimezone *tz;
tz = icaltimezone_get_builtin_timezone_from_tzid (tzid);
if (tz == NULL)
tz = icaltimezone_get_builtin_timezone (tzid);
return tz;
}
return NULL;
}
/**
* @brief Get the next or previous due time from a VCALENDAR component.
* The VCALENDAR must have simplified with icalendar_from_string for this to
* work reliably.
* The reference time is usually the current time.
*
* @param[in] vcalendar The VCALENDAR component to get the time from.
* @param[in] reference_time The reference time for calculating the next time.
* @param[in] default_tzid Timezone id to use if none is set in the iCal.
* @param[in] periods_offset 0 for next, -1 for previous from/before now.
*
* @return The next or previous time as a time_t.
*/
time_t
icalendar_next_time_from_vcalendar_x (icalcomponent *vcalendar,
time_t reference_time,
const char *default_tzid,
int periods_offset)
{
time_t now;
icalcomponent *vevent;
icaltimetype dtstart, dtstart_with_tz, ical_reference_time;
icaltimezone *tz;
icalproperty *rrule_prop;
struct icalrecurrencetype recurrence;
array_x *exdates, *rdates;
time_t next_time = 0;
// Only offsets -1 and 0 will work properly
if (periods_offset < -1 || periods_offset > 0)
return 0;
// Component must be a VCALENDAR
if (vcalendar == NULL
|| icalcomponent_isa (vcalendar) != ICAL_VCALENDAR_COMPONENT)
return 0;
// Process only the first VEVENT
// Others should be removed by icalendar_from_string
vevent = icalcomponent_get_first_component (vcalendar,
ICAL_VEVENT_COMPONENT);
if (vevent == NULL)
return 0;
// Get start time and timezone
dtstart = icalcomponent_get_dtstart (vevent);
if (icaltime_is_null_time (dtstart))
return 0;
tz = (icaltimezone*) icaltime_get_timezone (dtstart);
if (tz == NULL)
{
tz = icalendar_timezone_from_string_x (default_tzid);
if (tz == NULL)
tz = icaltimezone_get_utc_timezone ();
}
dtstart_with_tz = dtstart;
// Set timezone in case the original DTSTART did not have any set.
icaltime_set_timezone (&dtstart_with_tz, tz);
// Get current time
ical_reference_time = icaltime_from_timet_with_zone (reference_time, 0, tz);
// Set timezone explicitly because icaltime_current_time_with_zone doesn't.
icaltime_set_timezone (&ical_reference_time, tz);
if (ical_reference_time.zone == NULL)
{
ical_reference_time.zone = tz;
}
// Get EXDATEs and RDATEs
exdates = icalendar_times_from_vevent_x (vevent, ICAL_EXDATE_PROPERTY);
rdates = icalendar_times_from_vevent_x (vevent, ICAL_RDATE_PROPERTY);
// Try to get the recurrence from the RRULE property
rrule_prop = icalcomponent_get_first_property (vevent, ICAL_RRULE_PROPERTY);
if (rrule_prop)
recurrence = icalproperty_get_rrule (rrule_prop);
else
icalrecurrencetype_clear (&recurrence);
// Calculate next time.
next_time = icalendar_next_time_from_recurrence_x (recurrence,
dtstart_with_tz,
ical_reference_time, tz,
exdates, rdates,
periods_offset);
// Cleanup
free_array_x (exdates);
free_array_x (rdates);
return next_time;
}
/**
* @brief Get the next or previous due time from a VCALENDAR string.
* The string must be a VCALENDAR simplified with icalendar_from_string for
* this to work reliably.
* The reference time is usually the current time.
*
* @param[in] ical_string The VCALENDAR string to get the time from.
* @param[in] reference_time The reference time for calculating the next time.
* @param[in] default_tzid Timezone id to use if none is set in the iCal.
* @param[in] periods_offset 0 for next, -1 for previous from/before now.
*
* @return The next or previous time as a time_t.
*/
time_t
icalendar_next_time_from_string_x (const char *ical_string,
time_t reference_time,
const char *default_tzid,
int periods_offset)
{
time_t next_time;
icalcomponent *ical_parsed;
ical_parsed = icalcomponent_new_from_string (ical_string);
next_time = icalendar_next_time_from_vcalendar_x (ical_parsed,
reference_time,
default_tzid,
periods_offset);
icalcomponent_free (ical_parsed);
return next_time;
}
pg-gvm-22.6.8/src/regexp.c 0000664 0000000 0000000 00000004216 14765004441 0015243 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2021 Greenbone AG
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file regexp.c
*
* @brief This file defines functions that are available via the PostgreSQL
* @brief extension
*/
#include "glib.h"
#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"
/**
* @brief Create a string from a portion of text.
*
* @param[in] text_arg Text.
* @param[in] length Length to create.
*
* @return Freshly allocated string.
*/
static char *
textndup (text *text_arg, int length)
{
char *ret;
ret = palloc (length + 1);
memcpy (ret, VARDATA (text_arg), length);
ret[length] = 0;
return ret;
}
/**
* @brief Define function for Postgres.
*/
PG_FUNCTION_INFO_V1 (sql_regexp);
/**
* @brief Return if argument 1 matches regular expression in argument 2.
*
* This is a callback for a SQL function of two arguments.
*
* @return Postgres Datum.
*/
Datum
sql_regexp (PG_FUNCTION_ARGS)
{
if (PG_ARGISNULL (0) || PG_ARGISNULL (1))
PG_RETURN_BOOL (0);
else
{
text *string_arg, *regexp_arg;
char *string, *regexp;
int ret;
regexp_arg = PG_GETARG_TEXT_P(1);
regexp = textndup (regexp_arg, VARSIZE (regexp_arg) - VARHDRSZ);
string_arg = PG_GETARG_TEXT_P(0);
string = textndup (string_arg, VARSIZE (string_arg) - VARHDRSZ);
if (g_regex_match_simple ((gchar *) regexp, (gchar *) string, 0, 0))
ret = 1;
else
ret = 0;
pfree (string);
pfree (regexp);
PG_RETURN_BOOL (ret);
}
}
pg-gvm-22.6.8/tests/ 0000775 0000000 0000000 00000000000 14765004441 0014155 5 ustar 00root root 0000000 0000000 pg-gvm-22.6.8/tests/hosts_contains.sql 0000664 0000000 0000000 00000001112 14765004441 0017727 0 ustar 00root root 0000000 0000000 -- Start transaction and plan the tests.
BEGIN;
-- IMPORTANT! See https://pgtap.org/documentation.html#iloveitwhenaplancomestogether
SELECT plan(3);
-- Run the tests.
-- Test with empty input
SELECT is(hosts_contains('',''), false, 'Empty input should return false.');
SELECT is(hosts_contains('192.168.123.1-192.168.123.20, 192.168.123.30', '192.168.123.10'), true, 'Should return true');
SELECT is(hosts_contains('192.168.123.1-192.168.123.20, 192.168.123.30', '192.168.10.20'), false, 'Should return false');
-- Finish the tests and clean up.
SELECT * FROM finish();
ROLLBACK;
pg-gvm-22.6.8/tests/max_hosts.sql 0000664 0000000 0000000 00000000773 14765004441 0016712 0 ustar 00root root 0000000 0000000 -- Start transaction and plan the tests.
BEGIN;
-- IMPORTANT! See https://pgtap.org/documentation.html#iloveitwhenaplancomestogether
SELECT plan(2);
-- Run the tests.
-- Test with empty input
SELECT is(max_hosts('192.168.123.1-192.168.123.20, 192.168.123.30-192.168.123.34', ''), 25, 'Value should be 25');
SELECT is(max_hosts('192.168.123.1-192.168.123.20, 192.168.123.30-192.168.123.34', '192.168.123.10'), 24, 'Value should be 24');
-- Finish the tests and clean up.
SELECT * FROM finish();
ROLLBACK;
pg-gvm-22.6.8/tests/next_time_ical.sql 0000664 0000000 0000000 00000012243 14765004441 0017664 0 ustar 00root root 0000000 0000000 -- Start transaction and plan the tests.
BEGIN;
-- IMPORTANT! See https://pgtap.org/documentation.html#iloveitwhenaplancomestogether
SELECT plan(10);
-- Function to calculate the test timestamps based on current time
-- PostgreSQL internal date-time functions.
CREATE OR REPLACE FUNCTION next_test_time (integer, timestamp with time zone)
RETURNS integer AS $$
DECLARE
current_year integer;
current_month integer;
next_time timestamp with time zone;
BEGIN
current_year = EXTRACT (year FROM $2);
current_month = EXTRACT (month FROM $2);
-- First guess based on month
IF current_month <= 5 THEN
next_time
= make_timestamptz(current_year, 5, 21, 3, 7, 0, 'Europe/Berlin');
ELSE
next_time
= make_timestamptz(current_year, 11, 21, 3, 7, 0, 'Europe/Berlin');
END IF;
-- If 03:07:00 on the 21st has already passed in May / November,
-- add 6 months.
IF $2 > next_time THEN
next_time
= (next_time AT TIME ZONE 'Europe/Berlin' + interval '6 months')
AT TIME ZONE 'Europe/Berlin';
END IF;
-- Apply offset
next_time
= (next_time AT TIME ZONE 'Europe/Berlin' + ($1 * interval '6 months'))
AT TIME ZONE 'Europe/Berlin';
RETURN extract (EPOCH FROM (next_time AT TIME ZONE 'UTC'));
END;
$$ LANGUAGE plpgsql;
--
-- Test the date test model function
--
-- 2020-02-02T12:00:00 CET -> 2020-05-21T03:07:00 CEST
SELECT is (next_test_time (0, to_timestamp (1580641200)), 1590023220);
-- 2020-05-21T03:00:00 CEST -> 2020-05-21T03:07:00 CEST
SELECT is (next_test_time (0, to_timestamp (1590022800)), 1590023220);
-- 2020-05-21T03:10:00 CEST -> 2020-11-21T03:07:00 CET
SELECT is (next_test_time (0, to_timestamp (1590023400)), 1605924420);
-- 2020-08-21T00:00:00 CEST -> 2020-11-21T03:07:00 CET
SELECT is (next_test_time (0, to_timestamp (1597960800)), 1605924420);
-- 2020-11-21T03:00:00 CET -> 2020-11-21T03:07:00 CET
SELECT is (next_test_time (0, to_timestamp (1605924000)), 1605924420);
-- 2020-11-21T03:10:00 CET -> 2021-05-21T03:07:00 CEST
SELECT is (next_test_time (0, to_timestamp (1605924600)), 1621559220);
-- 2020-12-12T11:11:11 CET -> 2021-05-21T03:07:00 CEST
SELECT is (next_test_time (0, to_timestamp (1607767871)), 1621559220);
--
-- Run the tests for the actual iCalendar function.
--
-- Test without offset parameter
SELECT is (next_time_ical('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager
20.8+alpha~git-053b4bcb-timezone-ical//EN
BEGIN:VTIMEZONE
TZID:/freeassociation.sourceforge.net/Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZNAME:CEST
DTSTART:19810329T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
DTSTART:19961025T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin:
20100521T030700
DURATION:PT0S
RRULE:FREQ=MONTHLY;INTERVAL=6;BYMONTHDAY=21
UID:8c022087-e10a-462e-a1af-65559601a0db
DTSTAMP:20200615T161125Z
END:VEVENT
END:VCALENDAR', EXTRACT (EPOCH from now())::bigint, 'Europe/Berlin'),
next_test_time (0, now ()),
'Calculation was wrong');
-- Test with offset parameter set to 0
SELECT is (next_time_ical('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager
20.8+alpha~git-053b4bcb-timezone-ical//EN
BEGIN:VTIMEZONE
TZID:/freeassociation.sourceforge.net/Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZNAME:CEST
DTSTART:19810329T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
DTSTART:19961025T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin:
20100521T030700
DURATION:PT0S
RRULE:FREQ=MONTHLY;INTERVAL=6;BYMONTHDAY=21
UID:8c022087-e10a-462e-a1af-65559601a0db
DTSTAMP:20200615T161125Z
END:VEVENT
END:VCALENDAR', EXTRACT (EPOCH from now())::bigint, 'Europe/Berlin', 0),
next_test_time (0, now ()),
'Calculation was wrong');
-- Test with offset parameter set to -1
SELECT is (next_time_ical('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager
20.8+alpha~git-053b4bcb-timezone-ical//EN
BEGIN:VTIMEZONE
TZID:/freeassociation.sourceforge.net/Europe/Berlin
X-LIC-LOCATION:Europe/Berlin
BEGIN:DAYLIGHT
TZNAME:CEST
DTSTART:19810329T020000
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
DTSTART:19961025T030000
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin:
20100521T030700
DURATION:PT0S
RRULE:FREQ=MONTHLY;INTERVAL=6;BYMONTHDAY=21
UID:8c022087-e10a-462e-a1af-65559601a0db
DTSTAMP:20200615T161125Z
END:VEVENT
END:VCALENDAR', EXTRACT (EPOCH from now())::bigint, 'Europe/Berlin', -1),
next_test_time (-1, now ()),
'Calculation was wrong');
-- Finish the tests and clean up.
SELECT * FROM finish();
DROP FUNCTION next_test_time (integer, timestamp with time zone);
ROLLBACK;
pg-gvm-22.6.8/tests/regexp.sql 0000664 0000000 0000000 00000000705 14765004441 0016172 0 ustar 00root root 0000000 0000000 -- Start transaction and plan the tests.
BEGIN;
-- IMPORTANT! See https://pgtap.org/documentation.html#iloveitwhenaplancomestogether
SELECT plan(3);
-- Run the tests.
SELECT ok(regexp ('abc', '^[a-z]+$'), 'Should match!');
SELECT is(regexp ('123', '^[a-z]+$'), false, 'Should not match');
SELECT is(regexp ('123', '^[a-z+$'), false, 'Should return false because regex is invalid');
-- Finish the tests and clean up.
SELECT * FROM finish();
ROLLBACK;