pax_global_header00006660000000000000000000000064147065171070014522gustar00rootroot0000000000000052 comment=01f160c1515e22d0495998a02bf63850b848fdc5 snoopy-snoopy-2.5.2/000077500000000000000000000000001470651710700144045ustar00rootroot00000000000000snoopy-snoopy-2.5.2/.github/000077500000000000000000000000001470651710700157445ustar00rootroot00000000000000snoopy-snoopy-2.5.2/.github/CODEOWNERS000066400000000000000000000000211470651710700173300ustar00rootroot00000000000000* @bostjan snoopy-snoopy-2.5.2/.github/CONTRIBUTING.md000066400000000000000000000125001470651710700201730ustar00rootroot00000000000000# Contributing to Snoopy development New ideas are welcome. Most of change requests so far were about additional log data or filtering capabilities, therefore most of development/changes is expected in that area. Initial information about Snoopy hacking is available here: [doc/HACKING-OVERVIEW.md](../doc/HACKING-OVERVIEW.md) ## Table of Contents * [Git branches - persistent](#git-branches---persistent) * [Git branch naming for pull requests](#git-branch-naming-for-pull-requests) * [Creating feature documentation](#creating-feature-documentation) * [Creating a pull request](#creating-a-pull-request) ## Git branches - persistent The following git branches are always available in main Snoopy repository: - `master`: contains latest Snoopy development efforts. All new features should be based on this branch. - `install`: branch dedicated to Snoopy automated install procedure. When you use it, install-snoopy.sh script is downloaded from this branch. - `coverity_scan`: when Coverity analysis of a build is required, it is performed using this branch. Usually it lazily follows master branch. Coverity has a limited build submission frequency, thus a dedicated branch has been created to trigger analysis on as-needed basis. - `legacy`: orphaned branch, which contains imported Snoopy releases from 1.00 to 1.6.1 + changes to bring it in sync with initial commit from master branch. This is a lousy attempt to recreate lost SVN history (commits 1-31). Present for historical completeness only. ## Git branch naming for pull requests The following branch-naming patterns are intended for branches whose sole purpose of existence is pull request submission. These branches should have concise naming. Main reason for this is clean git history. When one-line-per- commit history view shows "Merge branch 'contributor/master'" our dear history viewer has no idea what is going on there. But, if instead of that, the first line of that commit message is "Merge branch 'bugfix/invalid-data-from-ttyname'" then a single glance is enough to understand the big picture. Thus pull requests should only be made for concise-named branches that follow these patterns: - bugfix/*: pull request branch, contains one bugfix, - documentation/*: pull request branch, contains documentation work, - enhancement/*: pull request branch, contains one enhancement (not a new feature, but improvement nonetheless) - feature/*: pull request branch, contains a new feature, - refactoring/*: pull request branch, contains code refactoring, ### On what branch should you base your contribution to Snoopy? **As a general rule, base your contribution on the `master` branch.** Non-exception: - you have developed a new feature and would like it to land in the next bugfix release: **do not bother**. Bugfix releases are bugfix releases, they are not intended to introduce new features. Base your work on **master** branch. If you somehow manage to convince maintainer(s) that your feature should land in next bugfix release anyway, maintainer will do the integration. ## Creating feature documentation Here is a brief description of Snoopy documentation structure in the [doc/](../doc) directory: - [doc/INSTALL.md](../doc/INSTALL.md): detailed installation instructions; - [doc/FAQ.md](../doc/FAQ.md): location of answers to frequently asked questions; - `doc/DATA-SOURCES.md`: general, data-sources-specific information; - `doc/DATA-SOURCE_complex_data_source_name.md`: documentation for advanced and configurable data source called "complex_data_source_name", which has its code located in `src/datasource/complex_data_source_name.c`; (also, do not include "_name" suffix in data source's name:); - `doc/FILTERING.md`: filtering-specific information; - `doc/FILTER_complex_filter_name.md`: documentation for advanced filter called "complex_filter_name", which has its code located in src/filter/complex_filter_name.c; - `doc/HACKING-*.md`: location of documentation useful to Snoopy developers and contributors; ## Creating a pull request Commits: - Commits should follow the KISS principle: do one thing, and do it well (keep it simple, stupid). - Commit messages should be easily readable, imperative style ("Fix memory leak in...", not "FixES mem...") Branching and PR branch naming: - Branch your contribution branch from Snoopy's `master` branch; - Consult the sections about branch naming above; - Branch name example #1: `feature/my-shiny-new-snoopy-feature-title` for new features; - branch name example #2: `bugfix/my-totally-non-hackish-workaround` for bugfixes; Pull requests: - Do not create pull requests for merging your master branch - see PR branch naming section above; - One pull request should contain one logical change only (one bugfix or one feature at a time); - If you have developed multiple features and/or bugfixes, create separate branches for each one of them, and request merges for each branch; - Snoopy uses Travis-CI for testing builds. When you submit a pull request, wait for Travis-CI to finish the build and see if everything went smoothly. - The cleaner you code/change/changeset is, the faster it will be merged. - Coverity scan is run on an as-needed basis, but keep in mind that you might be "called to court" ;) That is it. Your pull requests are welcome! ;) snoopy-snoopy-2.5.2/.github/FUNDING.yml000066400000000000000000000000501470651710700175540ustar00rootroot00000000000000custom: ['https://flattr.com/@bostjan'] snoopy-snoopy-2.5.2/.github/ISSUE_TEMPLATE/000077500000000000000000000000001470651710700201275ustar00rootroot00000000000000snoopy-snoopy-2.5.2/.github/ISSUE_TEMPLATE/bug-report.md000066400000000000000000000031061470651710700225370ustar00rootroot00000000000000--- name: Bug report about: Have you found a bug in Snoopy? Report it via this template. title: '' labels: 'Type: Bug' assignees: '' --- ## Checklist before starting to submit this bug report I confirm that: - [X] I am submitting a bug report! :) - [ ] I have tested this with the [latest stable Snoopy version](https://github.com/a2o/snoopy/releases/latest) (or the latest master build). - [ ] I have checked the [FAQ](https://github.com/a2o/snoopy/blob/master/doc/FAQ.md). - [ ] I have read Snoopy's documentation [here](https://github.com/a2o/snoopy/blob/master/README.md) and [here](https://github.com/a2o/snoopy/tree/master/doc). - [ ] I have searched [Snoopy issues](https://github.com/a2o/snoopy/issues?q=is%3Aissue) for an existing issue that matches my problem, and found none. ## Bug description `` `` `<...OR REMOVE THE SECTION ALTOGETHER IF ALREADY DESCRIBED ADEQUATELY IN THE "Expected result"/"Actual result" SECTIONS BELOW.>` ## Bug reproduction steps To avoid describing the environment "manually", I am providing a [Docker-based issue demo](../blob/master/doc/DOCKER-BASED-ISSUE-DEMO.md). My `Dockerfile` content: ``` ``` My `docker run ...` command that goes along with my `Dockerfile` to start the container: ``` ``` My additional command to run inside the container to triggre the bug (remove this section if not needed): ``` ``` ## Expected result `` ## Actual result `` snoopy-snoopy-2.5.2/.github/ISSUE_TEMPLATE/enhancement-idea.md000066400000000000000000000002741470651710700236410ustar00rootroot00000000000000--- name: Enhancement idea about: Suggest a new feature for Snoopy title: '' labels: 'Type: Enhancement' assignees: '' --- snoopy-snoopy-2.5.2/.github/ISSUE_TEMPLATE/support-request.md000066400000000000000000000031271470651710700236560ustar00rootroot00000000000000--- name: Support request about: Abandon all hope ye who enter here... ;) title: '' labels: 'Type: Support Request' assignees: '' --- ## Checklist before starting to submit this support request I confirm that: - [X] I am requesting support! :) - [ ] I have tested this with the [latest stable Snoopy version](https://github.com/a2o/snoopy/releases/latest) (or the latest master build). - [ ] I have checked the [FAQ](https://github.com/a2o/snoopy/blob/master/doc/FAQ.md). - [ ] I have read Snoopy's documentation [here](https://github.com/a2o/snoopy/blob/master/README.md) and [here](https://github.com/a2o/snoopy/tree/master/doc). - [ ] I have searched [Snoopy issues](https://github.com/a2o/snoopy/issues?q=is%3Aissue) for an existing issue that matches my problem, and found none. ## Issue description `` `` `<...OR REMOVE THE SECTION ALTOGETHER IF ALREADY DESCRIBED ADEQUATELY IN THE "Expected result"/"Actual result" SECTIONS BELOW.>` ## Issue reproduction steps To avoid describing the environment "manually", I am providing a [Docker-based issue demo](../blob/master/doc/DOCKER-BASED-ISSUE-DEMO.md). My `Dockerfile` content: ``` ``` My `docker run ...` command that goes along with my `Dockerfile` to start the container: ``` ``` My additional command to run inside the container to triggre the issue (remove this section if not needed): ``` ``` ## Expected result `` ## Actual result `` snoopy-snoopy-2.5.2/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000034561470651710700215550ustar00rootroot00000000000000Checklists for Pull requests ---------------------------- About pull request itself: - [X] I am submitting a pull request! :) - [ ] My submission does one logical thing only (one bugfix, one new feature). If I will want to supply multiple logical changes, I will submit multiple pull requests. - [ ] I have read and understood the [CONTRIBUTING guide](https://github.com/a2o/snoopy/blob/master/.github/CONTRIBUTING.md) Code quality: (not applicable for non-code fixes) - [ ] My submission is passing the test suite run (./configure --enable-everything && make tests) - test suite reports zero unexpected failures. Commits: - [ ] My commits are logical, easily readable, and with concise comments. - [ ] My commits follow the KISS principle: do one thing, and do it well. Licensing: - [ ] I am the author of this submission or I have been authorized by the submission copyright holder to issue this pull request. By issuing this pull request the copyright holder agrees that their contribution is included in Snoopy and released under the current Snoopy license (currently GPLv2). Branching: - [ ] My submission is based on `master` branch. - [ ] My submission is compatible with the latest `master` branch (no conflicts, I did a rebase if it was necessary). - [ ] The name of the branch I want to merge upstream is not `master`. - [ ] My branch name is `feature/my-shiny-new-snoopy-feature-title` (for new features). - [ ] My branch name is `bugfix/my-totally-non-hackish-workaround` (for bugfixes). - [ ] My branch name is `doc/what-i-did-to-documentation` (for documentation updates). Continuous integration: - [ ] Once I submit this pull request, I will wait for a CI report (normally done in a few minutes) and fix any issues CI points out. Pull request description ------------------------ snoopy-snoopy-2.5.2/.github/SECURITY.md000066400000000000000000000007451470651710700175430ustar00rootroot00000000000000# Security Policy ## Supported Versions Only the latest stable Snoopy release is supported. Bugfixes will not be backported to older releases. The latest Snoopy version can be found: - In the [main README.md](https://github.com/a2o/snoopy) file, or - In the [releases](https://github.com/a2o/snoopy/releases) section. ## Reporting a Vulnerability Report a security-related issue like any other issue, in Snoopy's [issue tracker](https://github.com/a2o/snoopy/issues), as a `Bug`. snoopy-snoopy-2.5.2/.github/workflows/000077500000000000000000000000001470651710700200015ustar00rootroot00000000000000snoopy-snoopy-2.5.2/.github/workflows/build-qa-arch-matrix.yml000066400000000000000000000054171470651710700244460ustar00rootroot00000000000000name: Build QA - Arch Matrix on: workflow_dispatch: pull_request: branches: - master paths: - '**' - '!.github/**' - '.github/workflows/build-qa-arch-matrix.yml' - '!.gitignore' - '!ChangeLog' - '!COPYING' - '!configure.scan' - '!dev-tools/**' - 'dev-tools/install-dev-software.sh' - 'dev-tools/libexec/get-release-*.sh' - '!doc/**' - '!etc/**' - '!install/**' - '!lib/*/IMPORT.defs' - '!lib/*/LICENSE' - '!README.md' push: branches: - master - force-github-action-run tags: - '*' paths: - '**' - '!.github/**' - '.github/workflows/build-qa-arch-matrix.yml' - '!.gitignore' - '!ChangeLog' - '!COPYING' - '!configure.scan' - '!dev-tools/**' - 'dev-tools/install-dev-software.sh' - 'dev-tools/libexec/get-release-*.sh' - '!doc/**' - '!etc/**' - '!install/**' - '!lib/*/IMPORT.defs' - '!lib/*/LICENSE' - '!README.md' jobs: build-qa-arch-matrix: ### Define the matrix of architectures/platforms to run on # strategy: matrix: include: - arch: linux/386 libdir: /lib/i386-linux-gnu - arch: linux/amd64 libdir: /lib/x86_64-linux-gnu ### Define the environment to run in # name: Build on ${{matrix.arch}} runs-on: ubuntu-20.04 container: image: debian:bullseye options: --platform ${{ matrix.arch }} ### ### Steps to run ### steps: ### Fetch the code # # We're using @v1 here to support execution on 32-bit systems # - uses: actions/checkout@v1 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 # (In this particular instance, git is not installed yet at this point.) # (The repo "clone" here is that actions/checkout@v1 magic that kinda looks like a git clone.) # (This command has been moved further down to where git is actually available [more or less accidentally, tbh].) #- run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Make sure we're running on the right platform # - run: ls -lad ${{ matrix.libdir }} ### Build # - run: ./dev-tools/install-dev-software.sh # Work around the fix for CVE-2022-24765 # (Should be done higher up, but see higher up for why it is down here.) - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make -j4 - run: make -j4 check - run: cat tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-config-matrix-large.yml000066400000000000000000000044361470651710700260660ustar00rootroot00000000000000name: Build QA - Config Matrix (Large) on: workflow_dispatch: push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-config-matrix-large: name: "Build with flags: '${{matrix.configure_flags}}'" runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c ### Define the list of configure flag combinations to test out # strategy: matrix: configure_flags: # Predefined configure flag combinations - "" #- "--enable-everything" ### This one already runs in the "OS Matrix" workflow - "--enable-everything --disable-thread-safety" - "--enable-everything --disable-config-file" - "--disable-everything" # Random configure flag combinations - "random-01" - "random-02" - "random-03" - "random-04" - "random-05" - "random-06" - "random-07" - "random-08" - "random-09" - "random-10" - "random-11" - "random-12" - "random-13" - "random-14" - "random-15" - "random-16" ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal ${{matrix.configure_flags}} if: ${{ ! startsWith(matrix.configure_flags, 'random') }} - run: ./configure --enable-option-checking=fatal `./dev-tools/libexec/get-random-configure-flags.sh` if: ${{ startsWith(matrix.configure_flags, 'random') }} - run: make -j4 - run: make -j4 check - run: cat tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-config-matrix-small.yml000066400000000000000000000037301470651710700261000ustar00rootroot00000000000000name: Build QA - Config Matrix (Small) on: workflow_dispatch: pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-config-matrix-small: name: "Build with flags: '${{matrix.configure_flags}}'" runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c ### Define the list of configure flag combinations to test out # strategy: matrix: configure_flags: # Predefined configure flag combinations - "" #- "--enable-everything" ### This one already runs in the "OS Matrix" workflow - "--enable-everything --disable-thread-safety" - "--enable-everything --disable-config-file" - "--disable-everything" # Random configure flag combinations - "random-01" - "random-02" - "random-03" ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal ${{matrix.configure_flags}} if: ${{ ! startsWith(matrix.configure_flags, 'random') }} - run: ./configure --enable-option-checking=fatal `./dev-tools/libexec/get-random-configure-flags.sh` if: ${{ startsWith(matrix.configure_flags, 'random') }} - run: make -j4 - run: make -j4 check - run: cat tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-os-matrix-large.yml000066400000000000000000000037431470651710700252420ustar00rootroot00000000000000name: Build QA - OS Matrix (Large) on: workflow_dispatch: push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-os-matrix-large: name: Build on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: - ciready/alpine:3.14-ci-c - ciready/alpine:3.15-ci-c - ciready/alpine:3.16-ci-c - ciready/archlinux:base-devel-ci-c - ciready/almalinux:8-ci-c - ciready/almalinux:9-ci-c - ciready/centos:stream-9-ci-c - ciready/debian:buster-ci-c - ciready/debian:bullseye-ci-c - ciready/debian:bookworm-ci-c - ciready/debian:sid-ci-c - ciready/opensuse:leap-15.4-ci-c - ciready/opensuse:leap-15.5-ci-c - ciready/opensuse:tumbleweed-latest-ci-c - ciready/ubuntu:20.04-ci-c - ciready/ubuntu:22.04-ci-c - ciready/ubuntu:24.04-ci-c - ciready/ubuntu:rolling-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make -j4 - run: make -j4 check - run: cat tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-os-matrix-small.yml000066400000000000000000000031521470651710700252520ustar00rootroot00000000000000name: Build QA - OS Matrix (Small) on: workflow_dispatch: pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-os-matrix-small: name: Build on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: - ciready/alpine:3.16-ci-c - ciready/archlinux:base-devel-ci-c - ciready/almalinux:9-ci-c - ciready/centos:stream-9-ci-c - ciready/debian:bookworm-ci-c - ciready/debian:sid-ci-c - ciready/opensuse:leap-15.4-ci-c - ciready/ubuntu:24.04-ci-c - ciready/ubuntu:rolling-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make -j4 - run: make -j4 check - run: cat tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-out-of-tree-build.yml000066400000000000000000000032041470651710700254620ustar00rootroot00000000000000name: Build QA - Out-of-tree build on: workflow_dispatch: pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-out-of-tree-build: name: Out-of-tree build runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: mkdir -p tmp/build1 - run: cd tmp/build1 && ../../configure --enable-option-checking=fatal --enable-everything - run: cd tmp/build1 && make -j4 - run: cd tmp/build1 && make -j4 check - run: cat tmp/build1/tests/*/test-suite.log if: failure() snoopy-snoopy-2.5.2/.github/workflows/build-qa-verify-make-targets-prefix.yml000066400000000000000000000030741470651710700274050ustar00rootroot00000000000000name: Build QA - Verify make targets prefix on: workflow_dispatch: pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: build-qa-verify-make-targets-prefix: name: Verify make targets prefix runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Build # - run: ./dev-tools/install-dev-software.sh - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make -j4 ### Verify # - run: ./dev-tools/libexec/verify-make-targets-prefix.sh snoopy-snoopy-2.5.2/.github/workflows/code-qa-autoscan.yml000066400000000000000000000031751470651710700236560ustar00rootroot00000000000000name: Code QA - Autoscan on: workflow_dispatch: push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'packaging/**' - 'doc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'packaging/**' - 'doc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: code-qa-autoscan: name: Scan for configure.ac changes runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install build environment tools # - run: ./dev-tools/install-dev-software.sh ### Run autoscan # - name: Run autoscan, check for changes run: | cp configure.scan configure.scan.GIT ./dev-tools/autoscan.sh diff -u configure.scan.GIT configure.scan ### If changes are detected, show this help hint # - name: "Failed? Here's what you should do to fix the issue:" if: failure() run: | echo -e "Check the autoscan-related section in this document:\n\n https://github.com/a2o/snoopy/blob/master/doc/HACKING-QA.md#autoscan\n\n" snoopy-snoopy-2.5.2/.github/workflows/code-qa-codeql.yml000066400000000000000000000031501470651710700233010ustar00rootroot00000000000000name: "Code QA - CodeQL" on: workflow_dispatch: push: branches: - master tags: - '*' # paths-ignore: # Intentionally commented out, as CodeQL does not run for a PR, if it didn't run for PR's base commit # - '.github/**' # - '.gitignore' # - 'ChangeLog' # - 'COPYING' # - 'configure.scan' # - 'packaging/**' # - 'dev-tools/**' ## - '!dev-tools/libexec/get-release-*.sh' # - 'doc/**' # - 'etc/**' # - 'install/**' # - 'lib/*/IMPORT.defs' # - 'lib/*/LICENSE' # - 'README.md' pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' # - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: analyze: name: Analyze runs-on: ubuntu-20.04 steps: - name: Checkout repository uses: actions/checkout@v2 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Initialize the CodeQL tools for scanning # - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: cpp ### Build # - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make -j4 ### Run the scan # - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 snoopy-snoopy-2.5.2/.github/workflows/code-qa-coverity.yml000066400000000000000000000050761470651710700237070ustar00rootroot00000000000000name: Code QA - Coverity on: workflow_dispatch: push: branches: - coverity-scan tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' # - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: code-qa-coverity: name: Static code analysis runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install build environment tools # - run: ./dev-tools/install-dev-software.sh ### Download and install coverity # - name: Download the Coverity Build Tool run: | wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$COVERITY_SCAN_TOKEN&project=a2o%2Fsnoopy" -O cov-analysis-linux64.tar.gz mkdir cov-analysis-linux64 tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64 working-directory: /opt env: COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} ### Configure # - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything ### Build with cov-build # - name: Build with cov-build run: | export PATH=/opt/cov-analysis-linux64/bin:$PATH cov-build \ --dir cov-int \ make ### Submit to Coverity Scan # - name: Submit the result to Coverity Scan run: | RELEASE_TAG=`./dev-tools/libexec/get-release-tag.sh` tar -czf cov-int.tar.gz cov-int curl \ --form project=a2o%2Fsnoopy \ --form token=$COVERITY_SCAN_TOKEN \ --form email=$COVERITY_SCAN_EMAIL \ --form version=$RELEASE_TAG \ --form description=$RELEASE_TAG \ --form file=@cov-int.tar.gz \ https://scan.coverity.com/builds?project=a2o%2Fsnoopy echo "Submission tag: $RELEASE_TAG" env: COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} COVERITY_SCAN_EMAIL: ${{ secrets.COVERITY_SCAN_EMAIL }} snoopy-snoopy-2.5.2/.github/workflows/code-qa-sonarcloud.yml000066400000000000000000000207451470651710700242140ustar00rootroot00000000000000name: Code QA - SonarCloud on: workflow_dispatch: push: branches: - master - sonarcloud-scan tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' # - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' pull_request_target: types: - labeled - opened - synchronize branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' # - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: code-qa-sonarcloud: name: Static code analysis submission runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c # For PRs, start the execution only when a specific label is added if: | ( (github.event_name == 'workflow_dispatch') || (github.event_name == 'push') || ( (github.event_name == 'pull_request_target') && ( ((github.event.pull_request.action == 'labeled') && contains(github.event.pull_request.labels.*.name, '/ci run additional tests')) || (github.actor == 'bostjan') ) ) ) steps: - name: Check the SONAR_TOKEN value shell: bash run: | if [[ "$SONAR_TOKEN" == "" ]]; then echo "ERROR: SONAR_TOKEN environmental variable not set or empty." echo "ERROR: If you're running this workflow locally with 'act', add the '--secret-file=...', like this" echo "ERROR:" echo "ERROR: act -j code-qa-sonarcloud --secret-file=dev-tools/submit-to-sonarcloud.conf" echo "ERROR:" exit 1 fi env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} ### Fetch the code # - name: Checkout branch ${{ github.ref }} uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis if: | ( (github.event_name == 'workflow_dispatch') || (github.event_name == 'push') ) # In the PR-related operation mode, unlike regular github's CI workflows (where # the workflow operates on a (preview) merge commit (as if PR was merged into the base # branch already), we're operating on PR's HEAD (last commit of the PR) itself here. - name: Checkout (preview) merge commit for PR ${{ github.event.pull_request.number }} uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis repository: ${{github.event.pull_request.head.repo.full_name}} ref: ${{github.event.pull_request.head.ref}} if: ${{ github.event_name == 'pull_request_target' }} # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install build environment tools + unzip # - run: ./dev-tools/install-dev-software.sh - run: DEBIAN_FRONTEND=noninteractive apt-get install -y unzip ### Bootstrap & configure the code # - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything --enable-code-coverage ### Install SonarCloud build & scan tools # - name: Install SonarCloud build wrapper run: | wget https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip unzip build-wrapper-linux-x86.zip working-directory: /opt ### Build with SonarCloud wrapper # - name: Build with SonarCloud build wrapper run: | /opt/build-wrapper-linux-x86/build-wrapper-linux-x86-64 \ --out-dir ../snoopy-sonarcloud-build-wrapper-output \ make -j4 ### Generate coverage info # # No need to run `make check`, as the test suite is started by # the `coverage` target in Makefile. # - name: Run tests and generate coverage information run: make coverage ### Install SonarCloud scanner # # The installation of the scanner is deferred to this point for security reasons, # as the build is done on a PR code that can easily mess with the scanner # installation to reveal the tokens. # - name: Install SonarClound scanner run: | rm -rf sonar-scanner* # Temporarily disabling using the latest SonarScanner version (5.0.0.2966), # as it is producing the following error: # java.io.IOException: Cannot run program ".../.scannerwork/.sonartmp/5786710878849275698/subprocess" (in directory "..."): error=13, Permission denied # #LATEST_SONAR_SCANNER_VERSION=`wget -q -O - --header "Accept: application/vnd.github.v3+json" https://api.github.com/repos/SonarSource/sonar-scanner-cli/releases/latest | grep '"tag_name"' | head -n1 | cut -d '"' -f4` # # Replacing it with this static definition for now: LATEST_SONAR_SCANNER_VERSION="6.1.0.4477" echo "Got the latest Sonar Scanner version: $LATEST_SONAR_SCANNER_VERSION" LATEST_SONAR_SCANNER_ZIP="sonar-scanner-cli-$LATEST_SONAR_SCANNER_VERSION-linux-x64.zip" LATEST_SONAR_SCANNER_DIR="sonar-scanner-$LATEST_SONAR_SCANNER_VERSION-linux-x64" wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$LATEST_SONAR_SCANNER_ZIP unzip $LATEST_SONAR_SCANNER_ZIP ln -s $LATEST_SONAR_SCANNER_DIR/bin/sonar-scanner /opt/sonar-scanner working-directory: /opt ### Trigger the SonarCloudscan and submission # - name: Scan and submit to SonarCloud - on push run: | CURRENT_BRANCH_NAME=`git branch --show-current` SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh` /opt/sonar-scanner \ -Dsonar.organization=a2o \ -Dsonar.projectKey=snoopy \ -Dsonar.sources=. \ -Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \ -Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \ -Dsonar.branch.name=$CURRENT_BRANCH_NAME \ -Dsonar.projectVersion=$SONARCLOUD_TAG \ -Dsonar.cfamily.build-wrapper-output=../snoopy-sonarcloud-build-wrapper-output \ -Dsonar.cfamily.gcov.reportsPath=. \ -Dsonar.host.url=https://sonarcloud.io echo "Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} if: ${{ github.event_name == 'push' }} - name: Scan and submit to SonarCloud - on PR run: | CURRENT_BRANCH_NAME=`git branch --show-current` SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh` /opt/sonar-scanner \ -Dsonar.organization=a2o \ -Dsonar.projectKey=snoopy \ -Dsonar.sources=. \ -Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \ -Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \ -Dsonar.pullrequest.provider=github \ -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \ -Dsonar.pullrequest.branch=${{github.event.pull_request.head.repo.owner.login}}:$PR_HEAD_REF \ -Dsonar.pullrequest.github.repository=${{ github.event.pull_request.base.repo.full_name }} \ -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} \ -Dsonar.cfamily.build-wrapper-output=../snoopy-sonarcloud-build-wrapper-output \ -Dsonar.cfamily.gcov.reportsPath=. \ -Dsonar.host.url=https://sonarcloud.io echo "Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)" env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} if: ${{ github.event_name == 'pull_request_target' }} snoopy-snoopy-2.5.2/.github/workflows/code-qa-valgrind.yml000066400000000000000000000031501470651710700236400ustar00rootroot00000000000000name: Code QA - Valgrind on: workflow_dispatch: push: branches: - master tags: - '*' paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' pull_request: branches: - master paths-ignore: - '.github/**' - '.gitignore' - 'ChangeLog' - 'COPYING' - 'configure.scan' - 'packaging/**' - 'dev-tools/**' - '!dev-tools/libexec/get-release-*.sh' - 'doc/**' - 'etc/**' - 'install/**' - 'lib/*/IMPORT.defs' - 'lib/*/LICENSE' - 'README.md' jobs: code-qa-valgrind: name: Check for memory and fd leaks runs-on: ubuntu-20.04 container: ciready/ubuntu:20.04-ci-c steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install build environment tools + valgrind # - run: ./dev-tools/install-dev-software.sh - run: DEBIAN_FRONTEND=noninteractive apt-get install -y valgrind ### Build # - run: ./bootstrap.sh - run: ./configure --enable-option-checking=fatal --enable-everything - run: make ### Run the valgrind verification # - run: make valgrind snoopy-snoopy-2.5.2/.github/workflows/install-qa-installfile.yml000066400000000000000000000026731470651710700251050ustar00rootroot00000000000000name: Install QA - install-snoopy.sh on: workflow_dispatch: push: branches: - master - install paths: - 'install/install-snoopy.sh' pull_request: branches: - master - install paths: - 'install/install-snoopy.sh' jobs: install-qa-test-installfile: name: Test install-snoopy.sh ${{matrix.install_mode}} runs-on: ubuntu-20.04 container: ubuntu:20.04 strategy: matrix: install_mode: - stable - git-master - download ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install # - run: ./install/install-snoopy.sh ${{matrix.install_mode}} ### Verify Snoopy operation (or successful download) # - name: Verify Snoopy operation run: | touch /var/log/snoopy.log echo "output = file:/var/log/snoopy.log" >> /etc/snoopy.ini /bin/echo "Snoopy is alive and well" cat /var/log/snoopy.log | grep -v ': grep' | grep "Snoopy is alive and well" if: ${{ matrix.install_mode != 'download' }} - name: Verify Snoopy download run: ls -la snoopy-*.tar.gz if: ${{ matrix.install_mode == 'download' }} snoopy-snoopy-2.5.2/.github/workflows/install-qa-os-matrix.yml000066400000000000000000000042311470651710700245120ustar00rootroot00000000000000name: Install QA - OS Matrix on: workflow_dispatch: push: branches: - install tags: - '*' paths: - 'install/install-snoopy.sh' pull_request: branches: - master paths: - 'install/install-snoopy.sh' jobs: install-qa-os-matrix: name: Install on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: #FIXME uncomment once Snoopy 2.5.0 containing Alpine-/musl-related fixes is released # - alpine:3.14 # - alpine:3.15 # - alpine:3.16 - archlinux:base-devel - almalinux/8-base:latest - almalinux/9-base:latest - quay.io/centos/centos:stream9 - debian:buster - debian:bullseye - debian:bookworm - debian:sid - opensuse/leap:15.4 - opensuse/leap:15.5 - opensuse/tumbleweed:latest - ubuntu:20.04 - ubuntu:22.04 - ubuntu:24.04 - ubuntu:rolling ### ### Steps to run ### steps: ### Install requirements for the subsequent checkout action # # Alpine - run: apk add bash if: ${{ startsWith(matrix.container, 'alpine:') }} # SUSE / OpenSUSE - run: zypper -n install gzip tar if: ${{ startsWith(matrix.container, 'opensuse/') }} ### Fetch the code # - uses: actions/checkout@v2 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install # - run: ./install/install-snoopy.sh stable ### Report debugging info on failure # - run: cat install-snoopy.log if: failure() ### Verify Snoopy operation # - name: Verify Snoopy operation run: | touch /var/log/snoopy.log echo "output = file:/var/log/snoopy.log" >> /etc/snoopy.ini /bin/echo "Snoopy is alive and well" cat /var/log/snoopy.log | grep -v ': grep' | grep "Snoopy is alive and well" snoopy-snoopy-2.5.2/.github/workflows/install-qa-readme.yml000066400000000000000000000024121470651710700240230ustar00rootroot00000000000000name: Install QA - README.md on: workflow_dispatch: push: branches: - master paths: - 'README.md' pull_request: branches: - master paths: - 'README.md' jobs: install-qa-test-readme-steps: name: Test install steps from README.md runs-on: ubuntu-20.04 container: ubuntu:20.04 ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install tools required to download and run the script # - run: | DEBIAN_FRONTEND=noninteractive apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get install -y wget ### Install # - run: ./dev-tools/libexec/extract-and-run-install-steps-from-readme.sh ### Verify Snoopy operation # - name: Verify Snoopy operation run: | touch /var/log/snoopy.log echo "output = file:/var/log/snoopy.log" >> /etc/snoopy.ini /bin/echo "Snoopy is alive and well" cat /var/log/snoopy.log | grep -v ': grep' | grep "Snoopy is alive and well" snoopy-snoopy-2.5.2/.github/workflows/packaging-qa-os-matrix-large.yml000066400000000000000000000041541470651710700260640ustar00rootroot00000000000000name: Packaging QA - OS Matrix (Large) on: workflow_dispatch: push: branches: - master tags: - '*' paths: - '**' - '!.github/**' - '.github/workflows/packaging-qa-os-matrix-large.yml' - '!.gitignore' - '!ChangeLog' - '!COPYING' - '!configure.scan' - '!dev-tools/**' - 'dev-tools/_bootstrap.sh' - 'dev-tools/build-native-package.sh' - 'dev-tools/clean-git-repository.sh' - 'dev-tools/libexec/get-release-*.sh' - '!doc/**' - '!etc/**' - '!install/**' - '!lib/*/IMPORT.defs' - '!lib/*/LICENSE' - '!README.md' jobs: packaging-qa-os-matrix-large: name: Build on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: - ciready/archlinux:base-devel-ci-c - ciready/almalinux:8-ci-c - ciready/almalinux:9-ci-c - ciready/centos:stream-9-ci-c - ciready/debian:buster-ci-c - ciready/debian:bullseye-ci-c - ciready/debian:bookworm-ci-c - ciready/opensuse:leap-15.4-ci-c - ciready/opensuse:leap-15.5-ci-c - ciready/ubuntu:20.04-ci-c - ciready/ubuntu:22.04-ci-c - ciready/ubuntu:24.04-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install required tools # - run: ./dev-tools/install-dev-software.sh - run: ./dev-tools/install-packaging-software.sh ### Archlinux "workaround" # - name: "WORKAROUND: Make makepkg run as roon on Arch Linux" run: | sed -i 's/EUID == 0/EUID == 1987/' /usr/sbin/makepkg if: ${{ startsWith(matrix.container, 'ciready/archlinux:') }} ### Build # - run: ./dev-tools/build-native-package.sh snoopy-snoopy-2.5.2/.github/workflows/packaging-qa-os-matrix-small.yml000066400000000000000000000033641470651710700261040ustar00rootroot00000000000000name: Packaging QA - OS Matrix (Small) on: workflow_dispatch: pull_request: branches: - master paths: - '**' - '!.github/**' - '.github/workflows/packaging-qa-os-matrix-small.yml' - '!.gitignore' - '!ChangeLog' - '!COPYING' - '!configure.scan' - '!dev-tools/**' - 'dev-tools/_bootstrap.sh' - 'dev-tools/build-native-package.sh' - 'dev-tools/clean-git-repository.sh' - 'dev-tools/libexec/get-release-*.sh' - '!doc/**' - '!etc/**' - '!install/**' - '!lib/*/IMPORT.defs' - '!lib/*/LICENSE' - '!README.md' jobs: packaging-qa-os-matrix-small: name: Build on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: - ciready/archlinux:base-devel-ci-c - ciready/centos:stream-9-ci-c - ciready/ubuntu:24.04-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install required tools # - run: ./dev-tools/install-dev-software.sh - run: ./dev-tools/install-packaging-software.sh ### Archlinux "workaround" # - name: "WORKAROUND: Make makepkg run as roon on Arch Linux" run: | sed -i 's/EUID == 0/EUID == 1987/' /usr/sbin/makepkg if: ${{ startsWith(matrix.container, 'ciready/archlinux:') }} ### Build # - run: ./dev-tools/build-native-package.sh snoopy-snoopy-2.5.2/.github/workflows/publish-native-packages.yml000066400000000000000000000056051470651710700252400ustar00rootroot00000000000000name: Publish native packages on: workflow_dispatch: push: # Before being able to run the workflow manually, it needs to run at least # once via a push event. branches: - force-github-action-run # For now, do not run automatically on tags. # We are currently executing this workflow manually, via "gh workflow run". #tags: # - 'snoopy-*.*.*' jobs: publish-native-packages: name: Publish for ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: max-parallel: 1 matrix: container: - ciready/archlinux:base-devel-ci-c - ciready/almalinux:8-ci-c - ciready/almalinux:9-ci-c - ciready/centos:stream-9-ci-c - ciready/debian:buster-ci-c - ciready/debian:bullseye-ci-c - ciready/debian:bookworm-ci-c - ciready/opensuse:leap-15.4-ci-c - ciready/opensuse:leap-15.5-ci-c - ciready/ubuntu:20.04-ci-c - ciready/ubuntu:22.04-ci-c - ciready/ubuntu:24.04-ci-c ### ### Steps to run ### steps: ### Fetch the code # - uses: actions/checkout@v2 with: fetch-depth: 0 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install required tools # - run: ./dev-tools/install-dev-software.sh - run: ./dev-tools/install-packaging-software.sh ### Archlinux "workaround" # - name: "WORKAROUND: Make makepkg run as roon on Arch Linux" run: | sed -i 's/EUID == 0/EUID == 1987/' /usr/sbin/makepkg if: ${{ startsWith(matrix.container, 'ciready/archlinux:') }} ### Set up authentication and signing keys # - name: "Setup SSH key for managing git@github.com:a2o/snoopy-packages repository" env: SSH_PRIVKEY_TO_SNOOPY_PACKAGES_REPO: ${{ secrets.SSH_PRIVKEY_TO_SNOOPY_PACKAGES_REPO }} run: | mkdir -p /root/.ssh echo "$SSH_PRIVKEY_TO_SNOOPY_PACKAGES_REPO" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa ssh-keyscan -H github.com >> /root/.ssh/known_hosts - name: "Setup repository signing GPG key" env: GPG_PRIVKEY_SNOOPY_PACKAGES: ${{ secrets.GPG_PRIVKEY_SNOOPY_PACKAGES }} run: | echo "$GPG_PRIVKEY_SNOOPY_PACKAGES" | gpg --import - name: "Setup git commit settings" run: | git config --global user.email "publish-native-packages.workflow@snoopy.a2o.github.com" git config --global user.name "Publish native packages workflow @ github.com:a2o/snoopy" ### Build & publish # - run: ./dev-tools/build-native-package.sh - run: ./dev-tools/publish-native-package.sh snoopy-snoopy-2.5.2/.github/workflows/release-qa-os-matrix-install-from-repo.yml000066400000000000000000000126461470651710700300450ustar00rootroot00000000000000name: Release QA - OS Matrix - Install from repo on: workflow_dispatch: inputs: gitCheckoutRef: description: 'Git reference to checkout (defaults to the chosen branch or tag above when left empty)' required: false default: '' expectedSnoopyPackageVersion: description: 'Version of a Snoopy package (without the release number) to expect (gets latest Snoopy version tag from git when not given)' required: false default: '' # Commented out, as we can't do this automatically with the git push tag # release: # types: [published] # push: # branches: # - release-qa-os-matrix-install-from-repo # - introduce-distro-packaging jobs: release-qa-os-matrix-install-from-repo: name: Install on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: - archlinux:base-devel - almalinux/8-base:latest - almalinux/9-base:latest - quay.io/centos/centos:stream9 - debian:buster - debian:bullseye - debian:bookworm - opensuse/leap:15.4 - opensuse/leap:15.5 - ubuntu:20.04 - ubuntu:22.04 - ubuntu:24.04 ### ### Steps to run ### steps: ### Install prerequisites # # Arch - run: | pacman-key --init pacman -Syu --noconfirm git curl tar gzip if: ${{ startsWith(matrix.container, 'archlinux:') }} # CentOS - run: yum install -y --allowerasing git curl tar gzip if: ${{ startsWith(matrix.container, 'almalinux/') || startsWith(matrix.container, 'quay.io/centos/centos:') }} # Debian / Ubuntu # ('dpkg-dev' is here to provide 'dpkg-architecture' command) # ('debconf-utils' is here to provide 'debconf-set-selections' command) - run: | DEBIAN_FRONTEND=noninteractive apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get install -y git curl tar gzip dpkg-dev debconf-utils echo "snoopy snoopy/install-ld-preload boolean true" | debconf-set-selections if: ${{ startsWith(matrix.container, 'ubuntu:') || startsWith(matrix.container, 'debian:') }} # OpenSUSE - run: zypper -n install git curl tar gzip if: ${{ startsWith(matrix.container, 'opensuse/') }} ### Fetch the code # # This one is only needed to get that `extract-...` script. # NOTICE: For SUSE, make sure to install tar+gzip before running this action # - uses: actions/checkout@v2 with: # This awkward "ref" expression is a workaround to get a semblance # of an "if" statement into the workflow definition. ref: ${{ (github.event.inputs.gitCheckoutRef == '') && github.ref || github.event.inputs.gitCheckoutRef }} # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install the package (& verify the installed version) # - name: Extract and run the installation steps shell: bash run: | MATRIX_CONTAINER='${{ matrix.container }}' ARG_EXPECTED_SNOOPY_PACKAGE_VERSION='${{ github.event.inputs.expectedSnoopyPackageVersion }}' CMD_FLAG_CHECK_LIBRARY_VERSION="" CMD_FLAG_CHECK_PACKAGE_VERSION="" if [ "$ARG_EXPECTED_SNOOPY_PACKAGE_VERSION" == "" ]; then CMD_FLAG_CHECK_LIBRARY_VERSION="-c" CMD_FLAG_CHECK_PACKAGE_VERSION="-p" else CMD_FLAG_CHECK_LIBRARY_VERSION="-C $ARG_EXPECTED_SNOOPY_PACKAGE_VERSION" # CMD_FLAG_CHECK_PACKAGE_VERSION="-P $ARG_EXPECTED_SNOOPY_PACKAGE_VERSION" CMD_FLAG_CHECK_PACKAGE_VERSION="-p" # This one uses the value of -C, but changes it into a package tag fi if [ "$ARG_EXPECTED_SNOOPY_PACKAGE_VERSION" != "" ]; then SNOOPY_VERSION="$ARG_EXPECTED_SNOOPY_PACKAGE_VERSION" else SNOOPY_VERSION=`./dev-tools/libexec/get-release-version.sh -m git` fi if [[ $SNOOPY_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then CMD_FLAG_CHANNEL_TESTING="" else CMD_FLAG_CHANNEL_TESTING="-t" fi # Arch repos have some symlinks that raw.githubusercontent.com does not handle properly, # making package installation fail with some gpg signature issue (in reality, 404 or invalid content). if [[ $MATRIX_CONTAINER =~ ^archlinux ]]; then CMD_FLAG_RAW_GITHUBUSERCONTENT="" else CMD_FLAG_RAW_GITHUBUSERCONTENT="-r" fi ./dev-tools/libexec/extract-native-package-install-steps.sh \ -a \ -e \ $CMD_FLAG_RAW_GITHUBUSERCONTENT \ $CMD_FLAG_CHECK_LIBRARY_VERSION \ $CMD_FLAG_CHECK_PACKAGE_VERSION \ $CMD_FLAG_CHANNEL_TESTING ### Verify Snoopy operation # - name: Verify Snoopy operation run: | touch /var/log/snoopy.log echo "output = file:/var/log/snoopy.log" >> /etc/snoopy.ini /bin/echo "Snoopy is alive and well" cat /var/log/snoopy.log | grep -v ': grep' | grep "Snoopy is alive and well" snoopy-snoopy-2.5.2/.github/workflows/release-qa-os-matrix-install-from-source.yml000066400000000000000000000053771470651710700304030ustar00rootroot00000000000000name: Release QA - OS Matrix - Install from source on: workflow_dispatch: release: types: [published] push: branches: - add-release-qa-os-matrix-install-from-source jobs: release-qa-os-matrix-install-from-source: name: Install on ${{matrix.container}} runs-on: ubuntu-20.04 ### Define the list of container images # container: ${{ matrix.container }} strategy: matrix: container: # - alpine:3.14 # - alpine:3.15 # - alpine:3.16 - archlinux:base-devel - almalinux/8-base:latest - almalinux/9-base:latest - quay.io/centos/centos:stream9 - debian:buster - debian:bullseye - debian:bookworm - debian:sid - opensuse/leap:15.4 - opensuse/leap:15.5 - opensuse/tumbleweed:latest - ubuntu:20.04 - ubuntu:22.04 - ubuntu:24.04 - ubuntu:rolling ### ### Steps to run ### steps: ### Install prerequisites # # Alpine - run: apk add wget tar gzip bash if: ${{ startsWith(matrix.container, 'alpine:') }} # Arch - run: pacman -Syu --noconfirm wget tar gzip if: ${{ startsWith(matrix.container, 'archlinux:') }} # CentOS - run: yum install -y wget tar gzip if: ${{ startsWith(matrix.container, 'almalinux/') || startsWith(matrix.container, 'quay.io/centos/centos:') }} # Debian / Ubuntu - run: | DEBIAN_FRONTEND=noninteractive apt-get update -y DEBIAN_FRONTEND=noninteractive apt-get install -y wget tar gzip if: ${{ startsWith(matrix.container, 'ubuntu:') || startsWith(matrix.container, 'debian:') }} # OpenSUSE - run: zypper -n install wget tar gzip if: ${{ startsWith(matrix.container, 'opensuse/') }} ### Fetch the code # # This one is only needed to get that `extract-...` script. # NOTICE: For SUSE, make sure to install tar+gzip before running this action # - uses: actions/checkout@v2 # Work around the fix for CVE-2022-24765 - run: git config --global --add safe.directory $GITHUB_WORKSPACE || true ### Install # # The '-r' switch ensures README.md content is pulled from https://github.com/a2o/snoopy # - run: ./dev-tools/libexec/extract-and-run-install-steps-from-readme.sh -r ### Verify Snoopy operation # - name: Verify Snoopy operation run: | touch /var/log/snoopy.log echo "output = file:/var/log/snoopy.log" >> /etc/snoopy.ini /bin/echo "Snoopy is alive and well" cat /var/log/snoopy.log | grep -v ': grep' | grep "Snoopy is alive and well" snoopy-snoopy-2.5.2/.gitignore000066400000000000000000000036361470651710700164040ustar00rootroot00000000000000### Files produced by autotools # Makefile.in /aclocal.m4 /autom4te.cache /autoscan.log /build/aux/ar-lib /build/aux/compile /build/aux/config.guess /build/aux/config.sub /build/aux/depcomp /build/aux/install-sh /build/aux/ltmain.sh /build/aux/missing /build/aux/test-driver /build/m4/libtool.m4 /build/m4/lt*.m4 /configure /configure~ /config.cache /config.h /config.log /config.status /config.h.in /config.h.in~ /stamp-h? ### Temporary files creating during ./bootstrap.sh run # /configure.tmp ### Files produced by ./configure # Makefile /libtool /tests/_bootstrap-paths.sh # Temporary files created during ./configure run /conf*/ /confdefs.h /conftest /conftest.c /conftest.cpp /conftest.err /libtoolT ### Files produced by build process # .dirstamp *.a *.o *.la *.lo *.loT .deps/ .libs/ /a.out /src/cli/snoopyctl /src/libsnoopy.so /tests/bin/snoopy-test /tests/bin/spaceparent /tests/bin/space parent /etc/snoopy.ini ### Files produced by the test suite # /tests/*.log /tests/*/*.log /tests/*.trs /tests/*/*.trs ### Files produced by the tests' code coverage analysis # *.gcda *.gcno *.gcov ### Code analysis configuration and output files # # Notes: # - cov-int*: Can't rename this one, or else Coverity build analysis fails once the build tarball is uploaded. # /cov-int* /dev-tools/submit-to-coverity.conf /dev-tools/submit-to-sonarcloud.conf /.scannerwork/ /sonar-cfamily.reproducer /sonarcloud-build-wrapper-output ### Files produced by the releasing process # /snoopy-*.tar.* ### Files produced by the native packaging process # # Arch /PKGBUILD /snoopy-*.pkg.tar.zst # Debian /debian /packaging/deb/changelog /packaging/deb/.debhelper/ /packaging/deb/autoreconf.after /packaging/deb/autoreconf.before /packaging/deb/debhelper-build-stamp /packaging/deb/snoopy.debhelper.log /packaging/deb/snoopy/ #../snoopy_*_*.buildinfo #../snoopy_*_*.changes #../snoopy_*_*.deb #../snoopy-dbgsym_*_*.ddeb # RPM /packaging/rpmbuild snoopy-snoopy-2.5.2/COPYING000066400000000000000000000432541470651710700154470ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) 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 this service 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 make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the 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 a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 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. 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 convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision 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, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This 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. snoopy-snoopy-2.5.2/ChangeLog000066400000000000000000000725611470651710700161710ustar00rootroot00000000000000------------------------------------------------------------------------------- Snoopy Command Logger ChangeLog ------------------------------------------------------------------------------- 2024-10-24 - Version 2.5.2 -------------------------- New features: ============= o Add Ubuntu 24.04 support (GH #275). o Add OpenSUSE 15.5 support (GH #262). o Configurable max log message length (GH #264). Ref: https://github.com/a2o/snoopy/issue/254 Ref: https://github.com/a2o/snoopy/pull/264 Deprecations: ============= o Remove Ubuntu 18.04 support (GH #261). o Remove OpenSUSE 15.3 support (GH #262). o Remove CentOS Stream 8 support (GH #272, #278). Bugfixes: ========= o Fix datasource argument handling in output specification Ref: https://github.com/a2o/snoopy/pull/274 o Fix incorrectly placed free() call in `systemd_unit_name` datasource Ref: https://github.com/a2o/snoopy/pull/264 2022-09-28 - Version 2.5.1 -------------------------- Bugfixes: ========= o Bugfix (GH #246, #247): Fix build issues on 32-bit architectures. (Thanks Marcos Fouces (@MarcosFouces @ GitHub) for the report & testing on Debian build infrastructure.) 2022-09-04 - Version 2.5.0 -------------------------- New features: ============= o Binary packages are now being provided for major Linux distributions: - Ubuntu 18.04, 20.04 and 22.04 - openSUSE 15.3 and 15.4 - Debian Buster, Bullseye and Bookworm - CentOS Stream 8 and Stream 9 - AlmaLinux OS 8 and 9 - Arch Linux Ref: https://github.com/a2o/snoopy/pull/236 o Thread safety is now enabled by default. It can still be disabled at build time via the `--disable-thread-safety` flag. Ref: https://github.com/a2o/snoopy/pull/166 o A command line utility for managing Snoopy (called `snoopyctl`) has been introduced. Ref: https://github.com/a2o/snoopy/pull/187 o Support for setting syslog ident string to Systemd's unit name has been added. Ref: https://github.com/a2o/snoopy/pull/228 o A new datasource called `systemd_unit_name` has been added. Ref: https://github.com/a2o/snoopy/pull/228 o A new datasource called `cgroup` has been added, to facilitate the Ref: https://github.com/a2o/snoopy/pull/228 o A new datasource called `ipaddr` has been added. It reads the IP address information from the system `utmp` file. Ref: https://github.com/a2o/snoopy/pull/235 o The `file` output can now accept date format as part of a target filename. Ref: https://github.com/a2o/snoopy/pull/235 o Building against musl libc is now supported. Ref: https://github.com/a2o/snoopy/pull/244 Bugfixes: ========= o Fix incorrect `./configure --help` hints. Ref: https://github.com/a2o/snoopy/issues/209 o Add missing `findutils` package to our installer (for openSUSE) Ref: https://github.com/a2o/snoopy/pull/206 o Switch Snoopy installer from using GitHub API to simply parse the raw README.md file to get the latest Snoopy version, to avoid hitting GitHup API's rate limits. Ref: https://github.com/a2o/snoopy/issues/213 Changes: ======== o Required `autoconf` version been updated, from 2.63 to 2.69. Ref: https://github.com/a2o/snoopy/pull/219 o Further thread safety fixes (`strerror` -> `strerror_r`). Ref: https://github.com/a2o/snoopy/issues/82 o Upgrade included INI parser release from r42 to r55. Ref: https://github.com/a2o/snoopy/pull/221 o Hide all .so symbols by default, only expose the ones that are needed (by the .so preloading, and by the `snoopyctl`). Ref: https://github.com/a2o/snoopy/pull/230 o Stop using external linked list implementation. Ref: https://github.com/a2o/snoopy/pull/230 o Tests: Refactor all helper binaries into a single `snoopy-test` binary and its subcommands. Ref: https://github.com/a2o/snoopy/pull/187 o Simplify the implementation of datasource `cmdline`, as it has been a source of many issues (either reported by users, or uncovered via CI). Ref: https://github.com/a2o/snoopy/pull/234 o CI: Stop using/supporting openSUSE 15.1 and 15.2 o CI: Add openSUSE 15.4 to CI o CI: Deprecate Ubuntu 16.04 from our CI environment o CI: Switch from CentOS to AlmaLinxu for RHEL-related CI jobs o CI: Add support for CentOS Stream o CI: Reintroduce Arch Linux testing o CI: Increased SonarCloud test coverage to above 80% o CI: Add Debian Bookworm to testing matrices o Fix all outstanding Coverity and SonarCloud issues 2021-10-17 - Version 2.4.15 --------------------------- o Bugfix (GH #201): Work around DirectAdmin's non-conventional execve() call (null argv). (Thanks to Yavuz Aydin (@yavuzaydin @ GitHub) for reporting this issue and for providing access to a reproduction environment to aid the investigation.) 2021-04-20 - Version 2.4.14 --------------------------- o Bugfix (GH #198): Prevent overflow in the `cmdline` datasource. (Thanks to Ken TSUKAHARA (@ken3 @ GitHub) for finding, reporting and fixing this.) 2021-04-14 - Version 2.4.13 --------------------------- o Enhancement (GH #194, #195): Datasource `datetime` now support custom date and time formatting, with %-based conversion specifications - strftime()'s manual page contains all the details. (Thanks to @ky4k0b (@GitHub) for suggesting this.) 2021-02-09 - Version 2.4.12 --------------------------- o Bugfix (GH #191, #192): Fix incorrect handling of sysconf(_SC_ARG_MAX)'s return value in cmdline datasource. (Thanks to Marco Stagno (@MarcoStagno @ GitHub) for reporting this.) 2021-02-02 - Version 2.4.11 --------------------------- o Enhancement (GH #179): Introduction of SonarCloud static analysis pointed out many potential issues and other code smells, all fixed now (details are available in the repo history). o Enhancement (GH #176): Add installation support for Arch Linux and OpenSUSE. o Enhancement (GH #175): Remove installation dependency on the `which` program. Additionally, remove configure dependency on `socat` and `ps` programs. Additionally, add a script to quickly install all development-related programs on mainstream Linux distributions. o Bugfix (GH #184): Fix out-of-source builds (+ a verificaton job has been added to CI so we don't break that aspect inadvertently again). o Bugfix (GH #184): Fix incorrect handling of comments when reading /etc/hosts file by the `domain` data source. o Bugfix (GH #174): Fix invalid memory access that could only be encountered by running a test suite. Regular Snoopy operation was unaffected by this. 2020-11-30 - Version 2.4.10 --------------------------- o Bugfix (GH #119, #168) - IMPORTANT: Fix symbol leaks. Now all symbols that are present in the Snoopy's shared .so library and declared as global have `snoopy_` prefix. Previous versions of Snoopy were more likely to clash with other libraries' exported sybols, causing unexpected program behavior. (Thanks to @jibriss for reporting this.) o Bugfix (GH #145, #170): Make exclude_spawns_of inspect PID 1 too. This enables the filter to work correctly inside Docker containers where PID 1 is normally not an init process. (Thanks to @alex-ren for reporting this.) o Bugfix (GH #117, #118, #169): Fix handling of program names with spaces in `exclude_spawns_of` filter. (Thanks to @joaquimds for reporting this and to @akwizgran for a PR.) o Bugfix (GH #160, #163): Allow double quotes and backslashes in message format defined via `./configure --with-message-format="..."` (Thanks to Pascal Trouvin (@ptrouvin @ GH) for the inital PR.) o Bugfix: Fix build tooling to enable successful builds from git on Debian systems. o Enhancement (GH #113, #164): Store the ./configure command used to build the Snoopy and provide access to the data via the snoopy_configure_command data source. o Enhancement (GH #171): Migrate from Travis-CI to GitHub Actions, for simpler and faster access to PR test results. 2020-11-13 - Version 2.4.9 -------------------------- o Bugfix (#161 @ GitHub): Fixed regressions introduced by upgrading inih library in PR #143: - Removing surrounding single quotes from ini values stopped working; - The ini line length limit was reduced back down to 199 bytes. Additionally, line length limit was raised to 1023 bytes. (Thanks to @arstercz @ GitHub for pointing this out.) o Bugfix (#152 @ GitHub): Fix datasource_login test to work inside Docker container. (Thanks John-Mark Allen (@jmaargh @ GitHub) for the PR.) 2020-10-04 - Version 2.4.8 -------------------------- o Bugfix (#157 @ GitHub): Make Snoopy build with GCC 10.x. (Thanks Marcos Fouces (@MarcosFouces @ GitHub) for the report.) o Bugfix (#151 @ GitHub): Fix incorrect comparison in cmdline.c. (Thanks Mark Garrett (@gcsgithub @ GitHub) for the PR.) 2020-10-04 - Version 2.4.7 -------------------------- o Enhancement (#125 @ GitHub): Permit longer message_format in the .ini file. (Thanks Miguel Scapolla (@migueloangelo @ GitHub) for the PR.) o Bugfix (#126 @ GitHub): Fix datasource_rpname.c to correctly handle test suite running from tmux. (Thanks Lukas Schwaighofer (@lukas227 @ GitHub) for the PR.) o Bugfix (#122 @ GitHub): Fix build on GCC 7.x. (Thanks Alexander F Rødseth (@xyproto @ GitHub) for the PR.) o Change: Adjust unknown TTY handling (generates a nicer text now). o Enhancement (#142, #143 @ GitHub): Fix issues reported by GCC 8.x (mainly by upgrading the .ini parsing library). (Thanks @PaulCombal for reporting this.) o Change: Adjust unknown TTY handling (generates a nicer text now). o Bugfix (#146 @ GitHub): Fix the main deployment method, by moving all release packages to GitHub. 2016-08-14 - Version 2.4.6 -------------------------- o Bugfix (#106 @ GitHub): fix segmentation faults of Network Manager on CentOS 7 when using DHCP address configuration. (thanks tkimball83, p64 @ GitHub for reporting it, and jmtysonjr @ GitHub for verifying the bugfix) o Internal: replace ini parsing library iniparser with inih (triggered by #106 @ Github) 2016-03-05 - Version 2.4.5 -------------------------- o Bugfix (#102 @ GitHub): fix broken validation of --with-syslog-facility configure argument for LOCALx values. Build test updated to prevent regressions. (reported by lhmerino @ GitHub) o Bugfix: filter/only_tty: treat errors as if command does not have a tty associated with it o Bugfix: filter/only_tty: treat errors as if command does not have a tty associated with it o Tests: fix timestamp provider (ms) range test condition (bugfix found at user alasdairdc @ GitHub). o Install (#90 @ GitHub): Add support for installing local Snoopy packages with install script. (Suggested by PSKyne@Github) o Install (#90 @ GitHub): install-snoopy.sh now has a download-only mode. (Suggested by PSKyne@github) o Install: Reenabled 'make check' in install-snoopy.sh. The test that was was causing the most grief was datasource_domain test, which is disabled now. o Install (#98 @ GitHub): Add support for bootstrapping git builds on older OS releases (i.e. CentOS 6). Package builds are not affected by this. This is now done automatically by bootstrap.sh script. o Infrastructure (#94 @ GitHub): Migrated Travis-CI to container-based builds. Builds are not much faster, but their startup is indeed speedier. o Infrastructure: Added 16 builds to Travis-CI which use random selection of ./configure flags. This should ensure valid builds with all possible (valid) ./configure flag selections. o Refactoring: move src/libsnoopy.c/.h contents to more appropriate location: src/eventsource/execve_wrapper.c/.h 2015-08-28 - Version 2.4.4 -------------------------- o Thread safety: all remaining strtok() function calls were replaced with their thread-safe counterparts - strtok_r(). o Thread safety: all localtime() function calls were replaced with their thread-safe counterparts - localtime_r(). o Thread safety: all ttyname() functions were replaced with their thread-safe counterparts - ttyname_r(). o Thread safety info: the remaining non-thread-safe functions that are used are: - getenv() - strerror() getenv() does not have any thread-safe counterpart, so it was left as it was. If anyone uses threaded programs that do lots of execv() calls, then these programs should modify environment and execute programs in mutexed manner. strerror() is used in lib/liblcthw as define, therefore an easy fix is not possible. This doubly linked list implementation needs a general overhaul anyway. o RH packaging bugfix: do not fail the installation if directory already exists. (Brendan Germain - bcg62@github) o Feature: added new filter only_tty. Logs only commands associated with a TTY. (Jack DeLoach - urq@github) o Bugfix (#92 @ GitHub): fix false warning about open file descriptors when running valgrind. 2015-06-18 - Version 2.4.3 -------------------------- o Build bugfix: include forgotten files in distribution package (version detection script, some test files, etc). 2015-06-18 - Version 2.4.2 -------------------------- o Version skipped. 2015-06-18 - Version 2.4.1 -------------------------- o Bugfix: tests/datasource/snoopy_version was failing because regex was untested on full-release (non-development/preview) versions. Fixed. 2015-06-18 - Version 2.4.0 -------------------------- o Change: configuration file (snoopy.ini) support is now enabled by default. o Change: filtering support is now enabled by default. o Change: Removal of deprecated feature: removed ./configure flag --enable-root-only. An error message will be emitted by ./configure if this deprecated flag is encountered. General filtering should be used instead, like this: --enable-filtering --with-filter-chain="only_uid:0". o Enhancement: EXPERIMENTAL support for thread-safety added. o Feature: added new datasource snoopy_threads, that returns count of threads that Snoopy is currently configured for. o Feature: added new dummy data source: snoopy_literal. Returns its own argument. o Feature: added new data source: tid (Thread ID). o Feature: added new data source: tid_kernel (Thread ID, as retured by Linux kernel). o Feature: syslog ident string is now configurable, via ./configure line or via snoopy.ini. o Feature: added two new data sources: hostname and domain. o Feature: added a new output: devnull - writes to /dev/null black hole. o Feature: added a new output: devtty - writes to /dev/tty directly. o Feature: added two new outputs: stderr and stdout. o Feature: added new data source: snoopy_literal (dummy) o Feature: Full test suite is now implemented. It contains unit tests for every datasource, filter and all outputs that can actually be tested (testing syslog output provider is a bit inconvenient, for example). Additionally there are combined tests that check Snoopy functionality as a whole, as much as this can be done. Config file parsing is tested too. This test suite is now used at the following occasions: - when installing Snoopy via install-snoopy.sh script, - when submitting contribution pull request on GitHub, - when creating release package. o Bugfixes: see git history for details. o Internal feature: created generic argument parser. It should be used by all subcomponents that require CSV argument parsing. o Internal enhancement: iniparser upgraded to version 4.0. Also migrated to git submodule. o Internal enhancement: iniparser migrated to nested autotools subpackage. o Internal refactoring: make all arguments (that are applicable to be changed) to datasources, filters and outputs, constant string pointers. o Build bugfix: actually halt if some required header file, function or library is missing. Before this fix it only displayed "checking for X... no" error message and the process went on (not for all resources, but for many). o Build refactoring: do not build development tools by default o Build refactoring: now supports --enable-everything configuration flag. o Build refactoring: optimize configuration process, output relevant settings for review. o Build refactoring: optimized configure.ac to use way less code than before. This was achieved by abstracting common stuff into special macros stored in build/snoopy.m4. o Build refactoring: switched to non-verbose build output by default. Use 'make V=1' to revert to the old (verbose) behaviour. o Build refactoring: enabled -std=c99 and -pedantic build flags, to catch even more potential errors. o Release process: all release packages are now checked with CI provided by Travis-CI.org. o Release process: all release packages are now checked with Coverity Scan. o Release process: all release packages are now checked with "make distcheck" make target, to ensure proper builds. o Contribution process: all pull requests are automatically checked by Travis-CI. 2015-05-28 - Version 2.3.2 -------------------------- o Bugfix (#73 @ GitHub): fixed installation problem on systems that do not set executable flag for shared library files. (reported by Evgenii Terechkov - evgkrsk @ GitHub) 2015-05-24 - Version 2.3.1 -------------------------- o Bugfix (#68 @ GitHub): fixed build failure on SLES - mismatching prototype in error.c/.h (reported by GitHub user @tparkercbn). 2015-05-11 - Version 2.3.0 -------------------------- o Feature: new data source: datetime (returns current date and time in ISO8601 format). o Feature (#54 @ GitHub): new data sources: timestamp, timestamp_ms and timestamp_us o Feature (#55 @ GitHub): file output is now configurable with ./configure flag --with-default-output=OUTPUT_SPEC. o Feature (#53 @ GitHub): file output provider implemented. Snoopy is now capable of logging directly to file, if filesystem permissions do not prevent it. o Bugfixes: resolved all nine Coverity bugs (#80899-#80909), covering various resource leaks, unchecked string writes etc. o Bugfixes: resolved six additional coverity bugs (82437-82442) o Refactoring build process: config file comments now reflect which data sources, filters and outputs are available in given Snoopy installation/ package/build. o Refactoring build process: all data sources, filters and outputs can now be enabled/disabled individually by ./configure flags. This should make Snoopy less vulnerable if securing installation by reducing attack surface is desired. Each group (data sources, filters and outputs) can also be disabled with a single --enable-all-* ./configure flag. o Refactoring build process: removed all stale files which are copied/symlinked by autoreconf; updated makefiles to enable building outside of source tree; renamed some outputs to maintain naming consistency; reduced complexity and size of configure.ac by abstracting certain functionality into dedicated macros; moved as many build-time files as possible from root into build/aux/ directory; o Enhancement: specify in debian build recipe that libsnoopy package is to supersed old 'snoopy' package. (Contributed by Frederic Mora) o Refactoring: do not include filtering code if filtering is not enabled on ./configure line. o Refactoring #50 (GitHub): change ./configure flag --enable-filter to --enable-filtering, to prepare Snoopy for future changes (per-datasource, per-filter and per-output configure flags). o Bug #49 (GitHub): reset configuration values back to their corresponding defaults when running final cleanup. This prevents buffer overflows on next Snoopy invocations when config file is not found anymore. o Enhancement #48: do not include code for config file in the final library when config file is not enabled at all (via ./configure argument). o Feature #45: new filter that excludes Snoopy log entries from certain processes. (Code contributed by Frederic Mora) o Bug #44 / Enhancement #42: upgraded iniparser compotent to latest git version, the one that was included before was causing problems in threaded environments (java). o Refactoring #41: change term "input provider" to "data source", to more accurately reflect what is actually going on in that part of code. o Enhancement #42: upgraded included iniparser component to latest git version. This hopefully resolves issues with threaded processes. o Repository refactoring: removed all files that are created/copied by autotools suite, and added them to gitignore. o Include documentation in release packages from now on. 2015-04-27 - Version 2.2.8 --------------------------- o Bugfix #39: prevent double freeing of message_format and filter_chain variables when snoopy.ini suddenly disappears from filesystem. (reported by Ariel Zach) o Bugfix #39-2: Fix invalid parsing in rpname input provider - check the line that is read from /proc/PID/status and verify that it is non-empty and that it actually contains colon character before attempting to parse it. (reported and initial fix authored by Ariel Zach) o Bugfix #46: prevent bufffer overflow in cmdline input provider (reported by Ariel Zach) o Bugfix and refactoring: rpname input provider was leaking some memory, and it was made more logically structured (variables and if conditions were changed to more logical and coherent naming, to align it better with the rest of Snoopy code). o Bugfix #47: Bugfix #39 inadvertently introduced a doublefree bug when filter chain was specified in snoopy.ini. (reported by Ariel Zach) 2015-03-26 - Version 2.2.7 --------------------------- o Feature: added new input provider %{rpname} - gets root process name (submitted by Ariel Zach) 2015-03-06 - Version 2.2.6 --------------------------- o Feature: added new input provider %{env_all} - logs whole environment o Feature: added new input provider %{pid} - provides process id o Feature: added new input provider %{ppid} - provides parent process id o Bugfix: Fixed improper return value checking in all input providers that work with literal usernames and groups. This was causing shutdown hangs on RH/CentOS 7 systems that use systemd, with additional special conitions: - compiled-in message_format must have included these input providers, - when only configured in snoopy.ini, they did not trigger this bug. 2015-03-04 - Version 2.2.5 --------------------------- o Bugfix: devlog output provider was not resetting configuration to original values after it called socket output provider as its subroutine. o Bugfix: added support for 'make install DESTDIR=...' in etc/Makefile.am o Bugfix: fixed installation of snoopy.ini in nonexistent directory 2015-01-27 - Version 2.2.4 --------------------------- o Bugfix: devlog output was not implemented properly, it was missing log facility and log level specification. This resulted in Snoopy output appearing on user's console, as everything was treated with EMERG severity. On CentOS/RH messages of this severity are forwarded to console by default. o Bugfix: Install configuration file with .NEW suffix, and warn the user. 2015-01-27 - Version 2.2.3 --------------------------- o Bugfix: fixed compilation issues on pre 2.09 glibc platforms (SOCK_NONBLOCK, SOCK_CLOEXEC missing) 2015-01-20 - Version 2.2.2 --------------------------- o Bugfix: fixed compilation issues on pre 2.12 glibc platforms (getsid) 2015-01-11 - Version 2.2.1 --------------------------- o Feature: added support for configurable output selection o Feature: added dummy input provider: snoopy_version o Bugfix: changed default output provider from syslog to devlog (non-blocking socket as workaround for systemd's buffered/blocking /dev/log socket) 2015-01-11 - Version 2.2.0 --------------------------- o Never released. 2014-11-08 - Version 2.1.0 --------------------------- o Enhancement: strict checking of ./configure --with-syslog-* values o Enhancement: enabled configuration of syslog facility and level from configuration file 2014-11-07 - Version 2.0.1 --------------------------- o Bugfix: fixed uninitialized pointer in filter/exclude_uid.c and only_uid.c o Enhancement: prefix all iniparser errors with "SNOOPY " prefix, so it is evident where errors are coming from o Bugfix: changed --with-config-file to --enable-config-file. Having two ways to specify where configuration file exists is redundant and confusing. 2014-11-05 - Version 2.0.0 --------------------------- o Feature: Added support for custom message format specification at configuration time o Feature: New input providers: - egroup (thanks Sébastien Gross) - env (thanks Taylor Kimball) - eusername (thanks Sébastien Gross) - group (thanks Sébastien Gross) - login (thanks Sébastien Gross) - username (thanks Sébastien Gross) - tty_uid (thanks Tony Malkowski) - tty_username o Feature: Implemented internal filtering, with the following filters available: - exclude_uid - only_root - only_uid o Feature: Added optional support for INI configuration file o Feature: Added envp data to intputdatastorage if execve() is used. Prepared for future inputs to consume it. o Feature: Created snoopy-enable and snoopy-disable system scripts. o Distro packaging: added debian/ubuntu packaging data (by Sebastien Gross) o Distro packaging: added rhel/centos package spec file (by Jeremy Brown) o Refactoring: Separated data gathering into separate functions, to be used at will - now they are called "input providers" o Refactoring: Removed external filtering, to be replaced with internal filtering capability in the making o Refactoring: Removed logging exclusion via prefix, was created for exclusion of logging of external filter commands o Refactoring: switched to autotools completely o Refactoring: all builds now use -Wall and -Werror o Refactoring: removed --enable-cwd-logging (superseded by message formatting options and input provider) o Refactoring: Snoopy library is now called libsnoopy.so instead of snoopy.so, to conform to autotools syntax o Refactoring: ./configure: removed many bugs, added proper syntax and error messages to help user decide what she wants o Refactoring: added 'proper' (unified) error handling o Refactoring: moved input testing to separate executable, which does not get installed, but is only intended for development/debugging o Refactoring: created proper initialization/shutdown methods o Documentation: added into about writing new input providers o Bugfix: fixed compilation failure on debian in inputs/cwd.c (thanks Sébastien Gross) o Bugfix: missing snoopy.ini in distribution tarball (thanks Jeremy Brown) o Bugfix: When uninstalling, also disable Snoopy (remove from /etc/ld.so.preload). 2013-04-06 - Version 1.9.0 --------------------------- o Bugfix: fixed bug with unclosed /dev/log descriptor which caused hangs o Feature: System-dependent exec() argument length support added (thanks Jeff Schroeder) o Refactoring: README updated with Markdown format, for nicer display at github 2013-02-03 - Version 1.8.1 --------------------------- o Bugfix: enable.sh was not /bin/sh compliant, fixed (thanks "phe") 2011-03-06 - Version 1.8.0 --------------------------- o Feature: syslog facility is now configurable o Feature: syslog level is now configurable o Feature: external filter support available o Feature: single path prefix filtering available 2010-10-10 - Version 1.7.10 --------------------------- o Fixed bug with long command lines (thanks Luis Fernando Muñoz Mejías) 2010-10-10 - Version 1.7.6 --------------------------- o Quick fix of buggy patch applied in previous release 2010-10-10 - Version 1.7.5 --------------------------- o Build for 64bit machines and destdir support for RPMs (Aldemira) o Fixed 1-byte memory leak introduced in previous release 2010-09-24 - Version 1.7.2 --------------------------- o Logs current tty (initial patch provided by Aldemira user on SourceForge) 2010-02-11 - Version 1.6.1 --------------------------- o Logs current working directory 2010-02-09 - Version 1.6.0 --------------------------- o Uses autotools now o Changed installation procedure o Rewritten logging function to avoid memory leaks o No more segfaults on 64bit platforms o Program name and argument lengths limited to 4096 bytes o Many thanks to otheus for supplying a patch on SourceForge one and a half years ago, it helped tremendously. 2010-02-09 - Version 1.5.0 --------------------------- o Updated to compile and work without segfaults on 32bit and 64bit platforms o Project maintenance taken over by Bostjan Skufca Sun December 10 - Version 1.3 ------------------------------ o Altered logging mechanism for performance o Added new way of logging (can choose) o Added an integrity check (optional) Wed October 25 - Version 1.2a ----------------------------- o ROOT_ONLY behavior now works again, thanks to adrian.head@bytecomm.com.au for notifying us! Thu October 10 - Version 1.2 ----------------------------- o Fixed small bug with rather adverse side effects. Thu August 17 - Version 1.1 ---------------------------- o Added support for execv(). Although execv() calls execve() [as described in the man page], execv() calls don't seem to log. They now do. Will investigate this issue a bit further. o Made logging code modular, as to accommodate for the extra overload that execv() brought. Thu August 3 - Version 1.00 ---------------------------- o Cleaned up the codebase a bit o Added the output of username and sid (PID of the login shell) to the logged output o Fixed install.sh to be compatible with older (v1.0) bash shells snoopy-snoopy-2.5.2/Makefile.am000066400000000000000000000065051470651710700164460ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Local configuration changes # AUTOMAKE_OPTIONS = foreign subdir-objects ACLOCAL_AMFLAGS = -I build/m4 ### Subdir processing order # # Process etc/ before other subdirs # # If Snoopy has config file enabled, then there is a small time frame # between installation of library and subsequent installation of # initial configuration file where ini parsing library emits an error about # configuration file not being found. Therefore we first install # configuration file and only then the Snoopy library itself. # # Also, lib/ must be processed before src/, as ini parsing library is needed # there if config file is enabled. # SUBDIRS = if CONFIGFILE_ENABLED SUBDIRS += etc endif SUBDIRS += lib SUBDIRS += src SUBDIRS += doc SUBDIRS += tests ### Additional files to distribute in distribution package # EXTRA_DIST = \ dev-tools/libexec/get-release-version.sh \ README.md ### Make check aliases # checks: check test: check tests: check ### Enable/disable targets # enable: install $(sbindir)/snoopyctl enable # We need to run a local instance of `snoopyctl`, as `make uninstall` first # removes the installed `snoopyctl` instance before running the `uninstall-local` target. disable: ./src/cli/snoopyctl disable # Disable it if we are uninstalling it, to avoid error messages # about missing library that should be preloaded. uninstall-local: disable ### Clean these files additionally # # Clean release files clean-local-this-dir: rm -f config.h.in~ ; \ rm -f config.log ; \ rm -f configure~ ; \ rm -rf snoopy-[0-9].[0-9].* ; \ rm -f snoopy-*.tar.gz* ; \ rm -f snoopy-latest-*.txt ; \ rm -rf cov-int* ; \ rm -rf sonarcloud-build-wrapper-output ; \ rm -rf sonar-cfamily.reproducer ; \ rm -rf .scannerwork ; \ rm -rf packaging/deb/.debhelper ; \ rm -f packaging/deb/autoreconf.after ; \ rm -f packaging/deb/autoreconf.before ; \ rm -f packaging/deb/debhelper-build-stamp ; \ rm -f packaging/deb/files ; \ rm -f packaging/deb/snoopy.debhelper.log ; \ rm -f packaging/deb/snoopy.postrm.debhelper ; \ rm -f packaging/deb/snoopy.substvars ; \ rm -rf packaging/deb/snoopy ; \ rm -f ../snoopy_*_*.buildinfo ; \ rm -f ../snoopy_*_*.changes ; \ rm -f ../snoopy_*_*.deb ; \ rm -f ../snoopy-dbgsym_*_*.ddeb ; \ rm -rf packaging/rpmbuild ; \ rm -f snoopy-*.pkg.tar.zst ; \ true # Clean all files that were generated by bootstrap.sh, autoscan, packaging etc. # (anything that is not in git repository must go away) gitclean: maintainer-clean rm -f aclocal.m4 ; \ rm -fr autom4te.cache ; \ rm -f autoscan.log ; \ rm -fr build/aux/ ; \ rm -fr build/m4/ ; \ rm -f config.h.in ; \ rm -f configure ; \ rm -f debian ; \ rm -f packaging/deb/changelog ; \ rm -f PKGBUILD ; \ true ### Maintainer targets # # # Bootstrap: simplify maintainer's life # .PHONY: bootstrap bootstrap: maintainer-clean ./bootstrap.sh # # # Valgrind: run valgrind # .PHONY: valgrind valgrind: all valgrind -v \ --error-exitcode=1 \ --track-fds=yes \ --smc-check=all \ --leak-check=full \ --undef-value-errors=yes \ --track-origins=yes \ ./tests/bin/snoopy-test run everything ; ### Code coverage # if CODE_COVERAGE_ENABLED coverage-report: ./dev-tools/libexec/generate-gcov-reports.sh coverage: coverage-clean check coverage-report endif snoopy-snoopy-2.5.2/README.md000066400000000000000000000247631470651710700156770ustar00rootroot00000000000000# Snoopy Command Logger ## Table of contents * [What is Snoopy?](#what-is-snoopy) * [News](#news) * [Latest version](#latest-version) * [Installation](#installation) * [Output](#output) * [Configuration](#configuration) * [FAQ - Frequently asked questions](#faq-frequently-asked-questions) * [Security disclaimer](#security-disclaimer) * [Contributing to Snoopy development](#contributing-to-snoopy-development) * [Getting support](#getting-support) * [License](#license) * [Online resources](#online-resources) * [Credits](#credits) ## What is Snoopy? Snoopy is a small library that logs all program executions on your Linux/BSD system. [Developer documentation](doc/HACKING-INTERNALS.md) outlines how it actually does that (a fairly technical read). And don't miss the [security disclaimer](#security-disclaimer) about it. ## News | Date | What? | Details | | ------------ | ------------------------- | --------- | | 2024-10-24 | Snoopy 2.5.2 released. | Bugfix release + created Ubuntu 24.04 packaging. | | 2022-09-28 | Snoopy 2.5.1 released. | Bugfix release - fixed 32-bit builds. | | 2022-08-19 | Snoopy 2.5.0 released. | Thread safety by default & binary distribution packages are finally here! :) | Consult [ChangeLog](ChangeLog) for more information. ## Latest version | Latest release | Version | Status | Download location | | -------------- | -------- | ------ | ----------------- | | Stable | 2.5.2 | [![Build QA - OS Matrix (Large) / stable](https://github.com/a2o/snoopy/workflows/Build%20QA%20-%20OS%20Matrix%20(Large)/badge.svg?branch=snoopy-2.5.2)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Build+QA+-+OS+Matrix%20(Large)%22+branch%3Asnoopy-%2A)
[![Build QA - Config Matrix (Large) / stable](https://github.com/a2o/snoopy/workflows/Build%20QA%20-%20Config%20Matrix%20(Large)/badge.svg?branch=snoopy-2.5.2)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Build+QA+-+Config+Matrix+%28Large%29%22+branch%3Asnoopy-%2A)
[![Code QA - Autoscan / stable](https://github.com/a2o/snoopy/workflows/Code%20QA%20-%20Autoscan/badge.svg?branch=snoopy-2.5.2)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Code+QA+-+Autoscan%22+branch%3Asnoopy-%2A)
[![Code QA - Valgrind / stable](https://github.com/a2o/snoopy/workflows/Code%20QA%20-%20Valgrind/badge.svg?branch=snoopy-2.5.2)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Code+QA+-+Valgrind%22+branch%3Asnoopy-%2A) | All release packages can be found over there :point_right: in the [Releases](https://github.com/a2o/snoopy/releases) section. | | Development | `master` | [![Build QA - OS Matrix (Large) / master](https://github.com/a2o/snoopy/workflows/Build%20QA%20-%20OS%20Matrix%20(Large)/badge.svg?branch=master)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Build+QA+-+OS+Matrix+%28Large%29%22+branch%3Amaster)
[![Build QA - Config Matrix / master](https://github.com/a2o/snoopy/workflows/Build%20QA%20-%20Config%20Matrix%20(Large)/badge.svg?branch=master)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Build+QA+-+Config+Matrix+%28Large%29%22+branch%3Amaster)
[![Code QA - Autoscan / master](https://github.com/a2o/snoopy/workflows/Code%20QA%20-%20Autoscan/badge.svg?branch=master)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Code+QA+-+Autoscan%22+branch%3Amaster)
[![Code QA - Valgrind / master](https://github.com/a2o/snoopy/workflows/Code%20QA%20-%20Valgrind/badge.svg?branch=master)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Code+QA+-+Valgrind%22+branch%3Amaster)
[![Coverity Scan](https://scan.coverity.com/projects/4973/badge.svg?flat=1)](https://scan.coverity.com/projects/4973)
SonarCloud:
[![SonarCloud - Bugs](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=bugs)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Code Smells](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=code_smells)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Coverage](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=coverage)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=alert_status)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Security Rating](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=security_rating)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=sqale_index)](https://sonarcloud.io/dashboard?id=snoopy)
[![SonarCloud - Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=snoopy&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=snoopy) | `git clone git@github.com:a2o/snoopy` | ## Installation [![Install QA - README.md / master](https://github.com/a2o/snoopy/workflows/Install%20QA%20-%20README.md/badge.svg?branch=master)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Install+QA+-+README.md%22+branch%3Amaster) [![Install QA - install-snoopy.sh / install](https://github.com/a2o/snoopy/workflows/Install%20QA%20-%20install-snoopy.sh/badge.svg?branch=install)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Install+QA+-+install-snoopy.sh%22+branch%3Ainstall) [![Install QA - OS Matrix - Install from git](https://github.com/a2o/snoopy/workflows/Install%20QA%20-%20OS%20Matrix/badge.svg?branch=install)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Install+QA+-+OS+Matrix%22+branch%3Ainstall) [![Release QA - OS Matrix - Install from source](https://github.com/a2o/snoopy/workflows/Release%20QA%20-%20OS%20Matrix%20-%20Install%20from%20source/badge.svg)](https://github.com/a2o/snoopy/actions?query=workflow%3A%22Release+QA+-+OS+Matrix+-+Install+from+source%22) Starting with version 2.5.0, repositories with binary packages are provided for major Linux distributions. Here is a [guide to installing Snoopy from package repositories](doc/install-from-repo.md). *WARNING:* If you've installed Snoopy from source (i.e. using the `install-snoopy.sh` script method below) before, it's best to remove it before installing it from a package repository. [This guide](doc/install-from-source.md) contains steps to remove "manually" installed Snoopy from your system. Alternatively, the original method of installing Snoopy from source is still available: ```shell wget -O install-snoopy.sh https://github.com/a2o/snoopy/raw/install/install/install-snoopy.sh && chmod 755 install-snoopy.sh && sudo ./install-snoopy.sh stable ``` More information is available in the [doc/INSTALL.md](doc/INSTALL.md) document. ## Output This is what typical Snoopy output looks like: 2015-02-11T19:05:10+00:00 labrat-1 snoopy[896]: [uid:0 sid:11679 tty:/dev/pts/2 cwd:/root filename:/usr/bin/cat]: cat /etc/fstab.BAK 2015-02-11T19:05:15+00:00 labrat-1 snoopy[896]: [uid:0 sid:11679 tty:/dev/pts/2 cwd:/root filename:/usr/bin/rm]: rm -f /etc/fstab.BAK 2015-02-11T19:05:19+00:00 labrat-1 snoopy[896]: [uid:0 sid:11679 tty:/dev/pts/2 cwd:/root filename:/usr/bin/tail]: tail -f /var/log/messages These are default output locations on various Linux distributions: | Distribution | Snoopy output location | Notes | | ------------ | ---------------------- |---------------------------------- | | CentOS | `/var/log/secure` | | | Debian | `/var/log/auth.log` | | | Ubuntu | `/var/log/auth.log` | | | (others) | `/var/log/messages` | (potentially, could be elsewhere) | For actual output format and destination, check your Snoopy and syslog configuration. ## Configuration If the configuration file support is available in your Snoopy build (it probably is), Snoopy can be reconfigured on-the-fly. The configuration file is (most likely, but depending on the build) located at `/etc/snoopy.ini`. Supported configuration directives are explained in the [default configuration file](etc/snoopy.ini.in). ## FAQ - Frequently asked questions Frequently asked questions and answers are collected in the [doc/FAQ.md](https://github.com/a2o/snoopy/blob/master/doc/FAQ.md) file in this repository. ## Security disclaimer **WARNING: Snoopy is not a reliable auditing solution.** Rogue users can easily manipulate environment to avoid their actions being logged by Snoopy. Consult [this FAQ entry](https://github.com/a2o/snoopy/blob/master/doc/FAQ.md#5-i-see-no-snoopy-output-after-initial-user-login) for more information. ## Contributing to Snoopy development Consult the following documents for information related to Snoopy development: - [CONTRIBUTING.md](.github/CONTRIBUTING.md) - [HACKING-OVERVIEW.md](doc/HACKING-OVERVIEW.md) - [HACKING-INTERNALS.md](doc/HACKING-INTERNALS.md) - [HACKING-QA.md](doc/HACKING-QA.md) (Autoscan, Travis-CI and Valgrind-related sections) ## Getting support Information is available in a [dedicated document about getting support](https://github.com/a2o/snoopy/blob/master/doc/GETTING-SUPPORT.md). ## License Snoopy is released under [GNU General Public License version 2](https://github.com/a2o/snoopy/blob/master/COPYING). ## Online resources Snoopy development is located at the following URI: - https://github.com/a2o/snoopy/ Additional git repository mirrors (read-only) are available here: - https://gitlab.com/a2o/snoopy/ - https://bitbucket.org/snoopylogger/snoopy/ ## Credits Snoopy Command Logger was originally created and maintained by: - Marius Aamodt Eriksen - Mike Baker Contribution acknowledgements are available at the following locations: - In the [ChangeLog](ChangeLog), - In [pull requests](https://github.com/a2o/snoopy/pulls), - In [git history](https://github.com/a2o/snoopy/commits/master). Snoopy is currently maintained by [Bostjan Skufca Jese](https://github.com/bostjan). snoopy-snoopy-2.5.2/bootstrap.sh000077500000000000000000000020571470651710700167640ustar00rootroot00000000000000#!/bin/bash ### Shell setup # # Treat all errors as fatal and trace the progress # set -e set -u ### Check if autoconf is present on the system # if ! command -v autoreconf > /dev/null; then echo "ERROR: Program 'autoreconf' not found. Consider running './dev-tools/install-dev-software.sh' to correct this." exit 1 fi ### Check autotools version # RES=`autoreconf --version | head -n1 | cut -d' ' -f4 | sed -e 's/\.//'` if [ "$RES" -lt "268" ]; then echo "ERROR: Your autotools version is too old. At least version 2.68 is required." exit 1 fi ### Clear cache # if [ -d autom4te.cache ]; then rm -rf autom4te.cache fi ### Bug in aclocal: manually create m4 directory if it does not exist # if [ ! -d build/m4 ]; then mkdir -p build/m4 fi ### Signal process start # echo "###" echo "### Starting AutoTools run:" echo "###" echo ### Run autotools # autoreconf -i -v ### Signal success and exit # echo echo "###" echo "### AutoTools run was completed successfully." echo "### You should run ./configure now." echo "###" echo snoopy-snoopy-2.5.2/build/000077500000000000000000000000001470651710700155035ustar00rootroot00000000000000snoopy-snoopy-2.5.2/build/Makefile.am.common000066400000000000000000000021611470651710700210260ustar00rootroot00000000000000### Autoconf defaults # MAINTAINERCLEANFILES = Makefile.in ### Automake defaults # # Notes: # -I$(top_srcdir)/src is here for #include "snoopy.h" (or similar) to work everywhere # -I$(top_srcdir) is here for #include "lib/*/src/*.h" to work everywhere (additionally, this also makes references "src/*/*.h" work too) # AM_CFLAGS = -Wall -Werror -Wextra -Wno-unused-parameter -std=c99 -Wpedantic -fvisibility=hidden -I$(top_srcdir)/src -I$(top_srcdir) ### Distclean .dep files # # It has been discovered that running `make distclean` in Snoopy's release tarball # leaves empty .dep directories lying around. # distclean-local: rm -rf .deps ### Additional `make clean` tasks # # Cleans the coverage files generated by the build process coverage-notes-clean: rm -f *.gcno ; # Clean the coverage files generated by `make check` and `make coverage` coverage-clean: rm -f *.gcda ; rm -f *.gcov ; # Common tasks for clean-local clean-local-common: rm -f .dirstamp ; # This one is to be overriden where required clean-local-this-dir: clean-local: coverage-clean coverage-notes-clean clean-local-common clean-local-this-dir snoopy-snoopy-2.5.2/build/snoopy.m4000066400000000000000000000333421470651710700173010ustar00rootroot00000000000000# # SNOOPY COMMAND LOGGER # # File: snoopy.m4 # # Copyright (c) 2015 Bostjan Skufca # # 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ### ### PROGRAM CHECK Macros ### # # GENERAL ENTITY: ./configure output # # Args: # 1: program name to check, exact case # 2: variable to define, usually upper case (is prefixed with SNOOPY_PROG_ and suffixed with _FOUND) # 3: additional info if program is not found # AC_DEFUN([SNOOPY_PROG_REQUIRE], [ AC_CHECK_PROG(SNOOPY_PROG_$2_FOUND, $1, yes) if test x"$SNOOPY_PROG_$2_FOUND" != x"yes" ; then AC_MSG_ERROR([Program "$1" not found: $3]) fi ]) AC_DEFUN([SNOOPY_PROG_SUGGEST], [ AC_CHECK_PROG(SNOOPY_PROG_$2_FOUND, $1, yes) if test x"$SNOOPY_PROG_$2_FOUND" != x"yes" ; then AC_MSG_WARN([Program "$1" not found: $3]) fi ]) ### ### EVERYTHING default value ### # # Defines a variable based on if --enable/--disable-everything was specified, # and if not, the default value provided. # # Set default value # # Args: # 1: valuevariable to check # AC_DEFUN([SNOOPY_CONFIGURE_ENABLE_EVERYTHING_SET], [ if test "x$1" == "xyes"; then everything_enabled="yes" elif test "x$1" == "xno"; then everything_enabled="no" elif test "x$1" == "xunspecified"; then everything_enabled="unspecified" else AC_MSG_ERROR([--enable-everything does not take an argument. Got: $enableval]) fi ]) # Get default value # # Args: # 1: variable name to define # 2: default value, if no --enable/--disable-everything is specified. # AC_DEFUN([SNOOPY_CONFIGURE_ENABLE_EVERYTHING_GET], [ if test "x$everything_enabled" == "xyes"; then $1="yes" elif test "x$everything_enabled" == "xno"; then $1="no" else $1="$2" fi ]) ### ### ENABLE GENERIC ### # # Defines a variable based on if --enable/--disable-everything was specified, # and if not, the default value provided. # # ENABLE GENERIC: Set values if SPECIFIED (as ./configure argument) # # Args: # 1: configure flag, without --enable/--disable prefix # 2: variable name, including "_enabled" suffix # 3: enableval value # 4: additional help content, if invalid value is provided # AC_DEFUN([SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED], [ if test "x$3" == "xyes"; then $2="yes" elif test "x$3" == "xno"; then $2="no" else AC_MSG_ERROR([--enable/--disable-$1 does not take an argument. $4 Got: $enableval]) fi ]) # ENABLE GENERIC: Set values if *UN*SPECIFIED (as ./configure argument) # # Args: # 1: configure flag, without --enable/--disable prefix # 2: variable name, including "_enabled" suffix # 3: parent default value, used if specified # 3: default value, used if parent default value is unspecified # # AC_DEFUN([SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED], [ if test "x$3" == "xyes"; then $2="yes" elif test "x$3" == "xno"; then $2="no" else $2="$4" fi ]) # ENABLE GENERIC: Final macro # # Args: # 1: configure flag, without --enable/--disable prefix # 2: variable name, including "_enabled" suffix # 3: default value # # AC_DEFUN([SNOOPY_CONFIGURE_ENABLE_GENERIC_EVALUATE], [ AS_IF([test "x$1" = "xyes"], [ AC_DEFINE(SNOOPY_CONF_$2, 1, [$3]) ]) AM_CONDITIONAL([$2], [test "x$1" == "xyes"]) AC_MSG_NOTICE([Snoopy $3 enabled: $1]) ]) ### ### GENERAL ENTITY macros ### # # GENERAL ENTITY: ./configure output # # Args: # 1: entity type (lower case) # 2: entity type (upper case) # 3: entity id # 4: "yes" if enabled, "no" if disabled, anything else is displayed literally # AC_DEFUN([SNOOPY_CONFIGURE_ENTITY_MSG], [ AS_IF( [test "x" == "x"], [ dotLine=".................................................."; whatString="Snoopy $1 enabled: $3 "; whatStringPadded="$whatString${dotLine:${#whatString}}"; if test "x$4" == "xyes"; then AC_MSG_NOTICE([$whatStringPadded YES]) elif test "x$4" == "xno"; then AC_MSG_NOTICE([$whatStringPadded no]) else AC_MSG_NOTICE([$whatStringPadded $4]) fi ] ) ]) ### ### DATASOURCE Macros ### # # DATASOURCE: ./configure output AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_MSG], [ # Do not put newline between last angled and regular closing brace, # it gets picked up as part of argument. SNOOPY_CONFIGURE_ENTITY_MSG([datasource], [DATASOURCE], [$1], [$2]) ]) # DATASOURCE: actual macro # # Args: # 1: Datasource name # 2: Datasource description # 3: Default setting (either "enabled" or "disabled") # 4: Action that opposes the arg #3 ("disable" or "enable") # 5: Same as #4, but with capitalized first letter # 6: Optional variables to set # AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_ENABLEDISABLE], [ AC_ARG_ENABLE(datasource-$1, [AS_HELP_STRING( [--$4-datasource-$1], [$5 datasource "$1". This datasource provides $2. [default=$3]] )], [ if test "x$enableval" == "xyes"; then enable_datasource_explicit_$1="yes" enable_datasource_$1="yes" elif test "x$enableval" == "xno" ; then enable_datasource_explicit_$1="no" enable_datasource_$1="no" else AC_MSG_ERROR([--$4-datasource-$1 does not take any arguments, got: $enableval]) fi ], [ enable_datasource_explicit_$1="undef" if test "x$enable_all_datasources" == "xyes"; then enable_datasource_$1="yes" elif test "x$enable_all_datasources" == "xno" ; then enable_datasource_$1="no" else if test "x$enable_everything" == "xyes"; then enable_datasource_$1="yes" elif test "x$enable_everything" == "xno" ; then enable_datasource_$1="no" else if test "x$3" == "xenabled"; then enable_datasource_$1="yes" else enable_datasource_$1="no" fi fi fi ] ) AS_IF([test "x$enable_datasource_$1" = "xyes"], [ AC_DEFINE(SNOOPY_CONF_DATASOURCE_ENABLED_$1, 1, [Is datasource "$1" available?]) ]) AM_CONDITIONAL([DATASOURCE_ENABLED_$1], [test "x$enable_datasource_$1" == "xyes"]) AC_SUBST([enable_datasource_$1]) # Define (optional) additional variables AM_CONDITIONAL([DATASOURCE_$6], [test "x$6" != "x"]) SNOOPY_CONFIGURE_DATASOURCE_MSG([$1], [$enable_datasource_$1]) ]) # DATASOURCE: alias macros AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_ENABLE], [SNOOPY_CONFIGURE_DATASOURCE_ENABLEDISABLE([$1], [$2], [enabled], [disable], [Disable], [$3])]) AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_DISABLE], [SNOOPY_CONFIGURE_DATASOURCE_ENABLEDISABLE([$1], [$2], [disabled], [enable], [Enable], [$3])]) # DATASOURCE: force certain datasource to be enabled AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_FORCE], [ AC_DEFINE(SNOOPY_CONF_DATASOURCE_ENABLED_$1, 1, [Is datasource "$1" available? Forced "Yes".]) AM_CONDITIONAL([DATASOURCE_ENABLED_$1], [test "x" == "x"]) AC_SUBST([enable_datasource_$1], [yes]) SNOOPY_CONFIGURE_DATASOURCE_MSG([$1], [YES (forced)]) ]) # DATASOURCE: force certain datasource to be disabled AC_DEFUN([SNOOPY_CONFIGURE_DATASOURCE_FORCEDISABLE], [ AM_CONDITIONAL([DATASOURCE_ENABLED_$1], [test "x" == "y"]) AC_SUBST([enable_datasource_$1], [no]) SNOOPY_CONFIGURE_DATASOURCE_MSG([$1], [no (forced)]) ]) ### ### FILTER Macros ### # # FILTER: ./configure output AC_DEFUN([SNOOPY_CONFIGURE_FILTER_MSG], [ # Do not put newline between last angled and regular closing brace, # it gets picked up as part of argument. SNOOPY_CONFIGURE_ENTITY_MSG([filter], [FILTER], [$1], [$2]) ]) # FILTER: actual macro # # Args: # 1: Filter name # 2: Filter description # 3: Default setting (either "enabled" or "disabled") # 4: Action that opposes the arg #3 ("disable" or "enable") # 5: Same as #4, but with capitalized first letter # AC_DEFUN([SNOOPY_CONFIGURE_FILTER_ENABLEDISABLE], [ AC_ARG_ENABLE(filter-$1, [AS_HELP_STRING( [--$4-filter-$1], [$5 filter "$1". $2 [default=$3]] )], [ if test "x$enableval" == "xyes"; then enable_filter_$1=yes elif test "x$enableval" == "xno" ; then enable_filter_$1=no else AC_MSG_ERROR([--$4-filter-$1 does not take any arguments, got: $enableval]) fi ], [ if test "x$enable_all_filters" == "xyes"; then enable_filter_$1="yes" elif test "x$enable_all_filters" == "xno" ; then enable_filter_$1="no" else if test "x$enable_filtering" == "xyes"; then enable_filter_$1="yes" elif test "x$enable_filtering" == "xno" ; then enable_filter_$1="no" else if test "x$everything_enabled" == "xyes"; then enable_filter_$1="yes" elif test "x$everything_enabled" == "xno" ; then enable_filter_$1="no" else if test "x$3" == "xenabled"; then enable_filter_$1="yes" else enable_filter_$1="no" fi fi fi fi ] ) AS_IF([test "x$enable_filter_$1" = "xyes"], [ AC_DEFINE(SNOOPY_CONF_FILTER_ENABLED_$1, 1, [Is filter "$1" available?]) ]) AM_CONDITIONAL([FILTER_ENABLED_$1], [test "x$enable_filter_$1" == "xyes"]) AC_SUBST([enable_filter_$1]) SNOOPY_CONFIGURE_FILTER_MSG([$1], [$enable_filter_$1]) ]) # FILTER: alias macros AC_DEFUN([SNOOPY_CONFIGURE_FILTER_ENABLE], [SNOOPY_CONFIGURE_FILTER_ENABLEDISABLE([$1], [$2], [enabled], [disable], [Disable])]) AC_DEFUN([SNOOPY_CONFIGURE_FILTER_DISABLE], [SNOOPY_CONFIGURE_FILTER_ENABLEDISABLE([$1], [$2], [disabled], [enable], [Enable] )]) # FILTER: force certain filter to be enabled AC_DEFUN([SNOOPY_CONFIGURE_FILTER_FORCE], [ AC_DEFINE(SNOOPY_CONF_FILTER_ENABLED_$1, 1, [Is filter "$1" available? Forced "Yes".]) AM_CONDITIONAL([FILTER_ENABLED_$1], [test "x" == "x"]) AC_SUBST([enable_filter_$1], [yes]) SNOOPY_CONFIGURE_FILTER_MSG([$1], [YES (forced)]) ]) ### ### OUTPUT Macros ### # # OUTPUT: ./configure output AC_DEFUN([SNOOPY_CONFIGURE_OUTPUT_MSG], [ # Do not put newline between last angled and regular closing brace, # it gets picked up as part of argument. SNOOPY_CONFIGURE_ENTITY_MSG([output], [OUTPUT], [$1], [$2]) ]) # OUTPUT: actual macro # # Args: # 1: Output name # 2: Output description # 3: Default setting (either "enabled" or "disabled") # 4: Action that opposes the arg #3 ("disable" or "enable") # 5: Same as #4, but with capitalized first letter # AC_DEFUN([SNOOPY_CONFIGURE_OUTPUT_ENABLEDISABLE], [ AC_ARG_ENABLE(output-$1, [AS_HELP_STRING( [--$4-output-$1], [$5 output "$1". $2 [default=$3]] )], [ if test "x$enableval" == "xyes"; then enable_output_$1=yes elif test "x$enableval" == "xno" ; then enable_output_$1=no else AC_MSG_ERROR([--$4-output-$1 does not take any arguments, got: $enableval]) fi ], [ if test "x$enable_all_outputs" == "xyes"; then enable_output_$1="yes" elif test "x$enable_all_outputs" == "xno" ; then enable_output_$1="no" else if test "x$enable_everything" == "xyes"; then enable_output_$1="yes" elif test "x$enable_everything" == "xno" ; then enable_output_$1="no" else if test "x$3" == "xenabled"; then enable_output_$1="yes" else enable_output_$1="no" fi fi fi ] ) AS_IF([test "x$enable_output_$1" = "xyes"], [ AC_DEFINE(SNOOPY_CONF_OUTPUT_ENABLED_$1, 1, [Is output "$1" available?]) ]) AM_CONDITIONAL([OUTPUT_ENABLED_$1], [test "x$enable_output_$1" == "xyes"]) AC_SUBST([enable_output_$1]) SNOOPY_CONFIGURE_OUTPUT_MSG([$1], [$enable_output_$1]) ]) # OUTPUT: alias macros AC_DEFUN([SNOOPY_CONFIGURE_OUTPUT_ENABLE], [SNOOPY_CONFIGURE_OUTPUT_ENABLEDISABLE([$1], [$2], [enabled], [disable], [Disable])]) AC_DEFUN([SNOOPY_CONFIGURE_OUTPUT_DISABLE], [SNOOPY_CONFIGURE_OUTPUT_ENABLEDISABLE([$1], [$2], [disabled], [enable], [Enable] )]) # OUTPUT: force certain output to be enabled AC_DEFUN([SNOOPY_CONFIGURE_OUTPUT_FORCE], [ AC_DEFINE(SNOOPY_CONF_OUTPUT_ENABLED_$1, 1, [Is output "$1" available? Forced "Yes".]) AM_CONDITIONAL([OUTPUT_ENABLED_$1], [test "x" == "x"]) AC_SUBST([enable_output_$1], [yes]) SNOOPY_CONFIGURE_OUTPUT_MSG([$1], [YES (forced)]) ]) snoopy-snoopy-2.5.2/configure.ac000066400000000000000000001156461470651710700167070ustar00rootroot00000000000000### ### Snoopy configure.ac ### ### Initialize autotools # AC_PREREQ([2.69]) # If you are running older OS and trying to build Snoopy from git, # ./bootstrap.sh will change the line below from script-based version # determination of Snoopy version to fixed string. DO NOT COMMIT THIS CHANGE! # Pull requests with this change will be rejected. # Correct line content that follows is: # # m4_esyscmd_s(echo $(./dev-tools/libexec/get-release-version.sh)), # # PS: Since the upgrade to autoconf 2.69, AC_INIT definition can no longer span multiple lines. # AC_INIT([Snoopy Command Logger],[m4_esyscmd_s(echo $(./dev-tools/libexec/get-release-version.sh))],[https://github.com/a2o/snoopy/issues/],[snoopy],[https://github.com/a2o/snoopy/]) ### Configure autotools # AC_CONFIG_SRCDIR([src/entrypoint/execve-wrapper.c]) # Check if we are in correct directory tree AC_CONFIG_AUX_DIR([build/aux]) AC_CONFIG_MACRO_DIRS([build/m4]) m4_include([build/snoopy.m4]) AM_INIT_AUTOMAKE([1.11 gnu silent-rules subdir-objects -Wall -Werror]) ### Silent make output # # Use it by default, but use version here that is backwards-compatible. # Must be used after AM_INIT_AUTOMAKE #AM_SILENT_RULES([yes]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) dnl Option AM_PROG_AR dnl dnl Required for building Snoopy from git on Ubuntu (which is what is mainly dnl used for development). dnl dnl Some older platforms do not provide this macro, and there might be some dnl packaging issues (see issue #38 on GitHub), that is why we're including dnl it conditionally here. dnl dnl This option must appear before LT_INIT. dnl m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) dnl Enable libtool LT_INIT([disable-static]) dnl Checks for programs. dnl dnl WARNING: Do not run autoscan over a non-gitclean-ed directory! dnl dnl If you run autoscan over a dirty directory, it adds the following macros dnl that are actually not required: dnl - AC_PROG_CPP dnl - AC_PROG_CXX dnl - AC_PROG_LN_S dnl - AC_PROG_RANLIB dnl AC_PROG_AWK AC_PROG_CC AC_PROG_GREP AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_MKDIR_P AC_PROG_SED LT_PATH_NM ### Check for programs required for TEST suite # SNOOPY_PROG_REQUIRE([dirname], [DIRNAME], [Needed for "make check" test suite.]) SNOOPY_PROG_REQUIRE([gcov], [GCOV], [Needed for "make coverage" build target.]) SNOOPY_PROG_REQUIRE([readlink], [READLINK], [Needed for "make check" test suite.]) SNOOPY_PROG_SUGGEST([socat], [SOCAT], [Needed for "make check" test suite.]) SNOOPY_PROG_SUGGEST([ps], [PS], [Needed for "make check" test suite.]) SNOOPY_PROG_REQUIRE([wc], [WC], [Needed for "make check" test suite.]) dnl Checks for libraries. AC_CHECK_LIB([dl], [dlsym], [], [ AC_MSG_ERROR([A library is missing. Unable to continue.]) ]) dnl Checks for header files. AC_CHECK_HEADERS([ \ arpa/inet.h \ ctype.h \ dlfcn.h \ errno.h \ fcntl.h \ features.h \ grp.h \ limits.h \ pwd.h \ stdio.h \ stddef.h \ stdlib.h \ string.h \ syslog.h \ sys/socket.h \ sys/stat.h \ sys/syscall.h \ sys/time.h \ sys/types.h \ sys/un.h \ time.h \ unistd.h \ utmp.h \ ], [], [ AC_MSG_ERROR([A header file is missing. Unable to continue.]) ]) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_SSIZE_T AC_TYPE_UID_T dnl Checks for library functions. AC_FUNC_FORK AC_FUNC_MALLOC AC_FUNC_STRERROR_R AC_CHECK_FUNCS([ \ getcwd \ gethostname \ getsid \ gettimeofday \ localtime_r \ socket \ strchr \ strdup \ strerror \ strndup \ strrchr \ strstr \ ], [], [ AC_MSG_ERROR([A function is missing. Unable to continue.]) ]) HOST_SUPPORTS_DATASOURCE_ipaddr="true" AC_CHECK_FUNCS([ \ getutline_r \ utmpname \ ], [], [ AC_MSG_WARN([Function missing, cannot enable datasource ipaddr.]) HOST_SUPPORTS_DATASOURCE_ipaddr="false" ]) dnl Substitute these variables when creating (Make)files below - GENERIC AC_SUBST([PREFIX]) AC_SUBST([SYSCONFDIR]) dnl Substitute these variables when creating (Make)files below - CUSTOM dnl $libdir contains '${exec_prefix}' if not specified as ./configure --libdir=... dnl ${exec_prefix} contains 'NONE' if not specified as ./configure --exec-prefix=... SNOOPY_LIBDIR="`eval echo ${libdir} | sed -e s@^NONE@$prefix@ | sed -e s@^NONE@/usr/local@`" AC_SUBST([SNOOPY_LIBDIR]) ### Generate these header files # AC_CONFIG_HEADERS([config.h]) ### Generate these (Make)files # AC_CONFIG_FILES([Makefile doc/Makefile etc/Makefile etc/snoopy.ini lib/Makefile lib/inih/Makefile lib/inih/src/Makefile src/Makefile src/action/Makefile src/cli/Makefile src/datasource/Makefile src/entrypoint/Makefile src/filter/Makefile src/output/Makefile src/util/Makefile tests/Makefile tests/bin/Makefile tests/cli/Makefile tests/combined/Makefile tests/configfile/Makefile tests/datasource/Makefile tests/filter/Makefile tests/general/Makefile tests/message/Makefile tests/output/Makefile tests/threads/Makefile tests/unit/Makefile ]) AC_CONFIG_FILES([tests/_bootstrap-paths.sh], [chmod +x tests/_bootstrap-paths.sh]) dnl ============================================================================ dnl ======= Determine target locations ========================================= dnl ============================================================================ if test "x$prefix" = "xNONE" ; then PREFIX="/usr/local" else PREFIX="$prefix" fi if test "x$exec_prefix" = "xNONE" ; then EXEC_PREFIX="$PREFIX" else EXEC_PREFIX="$exec_prefix" fi if test "x$sysconfdir" = "x\${prefix}/etc" ; then SYSCONFDIR="$PREFIX/etc" else SYSCONFDIR="$sysconfdir" fi if test "x$libdir" = "x\${exec_prefix}/lib" ; then LIBDIR="$EXEC_PREFIX/lib" else LIBDIR="$libdir" fi if test "x$sbindir" = "x\${exec_prefix}/sbin" ; then SBINDIR="$EXEC_PREFIX/sbin" else SBINDIR="$sbindir" fi dnl ============================================================================ dnl ======= START CONFIGURATION SUMMARY OUTPUT ================================= dnl ============================================================================ AC_MSG_NOTICE([======================================================================]) AC_MSG_NOTICE([Snoopy version: AC_PACKAGE_VERSION]) AC_DEFINE_UNQUOTED(SNOOPY_CONFIGURE_COMMAND, "./configure $(echo $ac_configure_args | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')", [Configure command that was used to build Snoopy]) AC_MSG_NOTICE([Snoopy build configuration command: ./configure $ac_configure_args]) AC_MSG_NOTICE([-]) # ============================================================================ # ======= ENABLE EVERYTHING ================================================== # ============================================================================ AC_ARG_ENABLE(everything, [AS_HELP_STRING( [--enable-everything], [enable/disable all Snoopy features with one argument. Mainly useful for testing Snoopy builds. Individual features can still be enabled/disabled. [default=depends]] )], [ SNOOPY_CONFIGURE_ENABLE_EVERYTHING_SET([$enableval])], # Specified on command line SNOOPY_CONFIGURE_ENABLE_EVERYTHING_SET([unspecified]) # Not specified on command line ) AS_IF([test "x$enable_everything" = "xyes"], [AC_MSG_NOTICE([Snoopy all features enabled/disabled: yes - enabled])], [ AS_IF([test "x$enable_everything" = "xno"], [AC_MSG_NOTICE([Snoopy all features enabled/disabled: yes - disabled])], [AC_MSG_NOTICE([Snoopy all features enabled/disabled: no - using defaults])] ) ] ) # ============================================================================ # ========= TARGET PATHS ===================================================== # ============================================================================ AC_MSG_NOTICE([Snoopy library directory: $LIBDIR]) AC_MSG_NOTICE([Snoopy CLI tool directory: $SBINDIR]) AC_DEFINE_UNQUOTED(SNOOPY_CONF_LIBDIR, "$LIBDIR", [Target installation directory for .so library]) AC_DEFINE_UNQUOTED(SNOOPY_CONF_SBINDIR, "$SBINDIR", [Target installation directory for the CLI tool]) dnl ============================================================================ dnl ======= ENABLE CONFIG FILE ================================================= dnl ============================================================================ AC_ARG_ENABLE(config-file, [AS_HELP_STRING( [--disable-config-file], [disable INI configuration file parsing. If enabled, then path is SYSCONFDIR/snoopy.ini [default=enabled] [default location=SYSCONFDIR/snoopy.ini]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [config-file], [configfile_enabled], [$enableval], [Use --sysconfdir to set config file path.]), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([config-file], [configfile_enabled], [$enable_everything], [yes]) ) AC_MSG_NOTICE([Snoopy config file enabled: $configfile_enabled]) AS_IF([test "x$configfile_enabled" == "xyes"], [ configfile_path="$SYSCONFDIR/snoopy.ini" AC_DEFINE_UNQUOTED(SNOOPY_CONF_CONFIGFILE_ENABLED, 1, [Is config file parsing enabled?]) AC_DEFINE_UNQUOTED(SNOOPY_CONF_CONFIGFILE_PATH, "$configfile_path", [INI configuration file path to use]) AC_DEFINE_UNQUOTED(SNOOPY_CONF_SYSCONFDIR, "$SYSCONFDIR", [Target installation directory for the configuration file]) AC_MSG_NOTICE([Snoopy config file path: $configfile_path]) ]) AM_CONDITIONAL([CONFIGFILE_ENABLED], [test "x$configfile_enabled" == "xyes"]) dnl ============================================================================ dnl ======= ENABLE ERROR LOGGING =============================================== dnl ============================================================================ AC_ARG_ENABLE(error-logging, [AS_HELP_STRING( [--enable-error-logging], [enable error logging through configured output - use only if you are developing Snoopy or having problems configuring it [default=disabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [error-logging], [enable_error_logging], [$enableval], []), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([error-logging], [enable_error_logging], [$enable_everything], [no]) ) AS_IF([test "x$enable_error_logging" = "xyes"], [ AC_DEFINE_UNQUOTED(SNOOPY_CONF_ERROR_LOGGING_ENABLED, 1, [Enable error logging]) ]) AC_MSG_NOTICE([Snoopy error logging enabled: $enable_error_logging]) dnl ============================================================================ dnl ======= ENABLE THREAD SAFETY =============================================== dnl ============================================================================ AC_ARG_ENABLE(thread-safety, [AS_HELP_STRING( [--disable-thread-safety], [Disable parts of code that ensure safe multi-threaded operation [default=enabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [thread_safety], [thread_safety_enabled], [$enableval], []), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([thread_safety], [thread_safety_enabled], [$enable_everything], [yes]) ) SNOOPY_CONFIGURE_ENABLE_GENERIC_EVALUATE([$thread_safety_enabled], [THREAD_SAFETY_ENABLED], [thread safety]) dnl ============================================================================ dnl ============================================================================ dnl ======= START section: DATASOURCES & MESSAGE FORMAT ======================== dnl ============================================================================ dnl ============================================================================ AC_MSG_NOTICE([-]) # ============================================================================== # ======= Enable/disable all data sources at once ============================== # ============================================================================== AC_ARG_ENABLE(all-datasources, [AS_HELP_STRING( [--disable-all-datasources], [disables all data sources at once. Use --enable-datasource-NAME to reenable individual data sources. [default=enabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [all-datasources], [enable_all_datasources], [$enableval], [Use --enable/--disable-datasource-NAME to reenable/disable individual data sources.]), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([all-datasources], [enable_all_datasources], [$enable_everything], [unspecified]) ) # ============================================================================== # ======= START section: ENABLE INDIVIDUAL DATA SOURCES ======================== # ============================================================================== SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [cgroup], [cgroup information]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [cmdline], [full command line including arguments]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [cwd], [current working directory]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [datetime], [current date and time, supports strftime-based formatting argument, defaults to ISO 8601 format]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [domain], [domain of this system]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [egid], [effective GID]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [egroup], [effective literal group name]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [env], [particular environment variable]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [env_all], [all environment variables]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [euid], [effective UID]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [eusername], [effective literal username]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [filename], [full filename of process being executed]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [gid], [GID of process performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [group], [literal group name of process performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [hostname], [hostname of this system]) if test x"$HOST_SUPPORTS_DATASOURCE_ipaddr" = xfalse ; then SNOOPY_CONFIGURE_DATASOURCE_FORCEDISABLE( [ipaddr], [IP address of a connected terminal]) else SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [ipaddr], [IP address of a connected terminal]) fi SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [login], [login username of user doing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [pid], [PID of process performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [ppid], [parent PID of process performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [rpname], [real parent name found up the process tree]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [sid], [session leader PID]) SNOOPY_CONFIGURE_DATASOURCE_FORCE( [snoopy_configure_command], [returns the ./configure command that was used to build Snoopy]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [snoopy_literal], [dummy data source - only returns what it receives as argument]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [snoopy_threads], [number of threads that Snoopy currently is initialized for]) SNOOPY_CONFIGURE_DATASOURCE_FORCE( [snoopy_version], [installed Snoopy version]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [systemd_unit_name], [SystemD unit name, as found in /proc/self/cgroup file under the name=systemd cgroup]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [tid], [Thread ID of process performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [tid_kernel], [Thread ID of process performing the execution, as retured by kernel via syscall]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [timestamp], [current Unix timestamp]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [timestamp_ms], [millisecond part of current Unix timestamp]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [timestamp_us], [microsecond part of current Unix timestamp]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [tty], [path to TTY performing the execution]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [tty_uid], [UID of TTY performing the execution], [INCLUDE_tty__common]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [tty_username], [literal username of TTY performing the execution], [INCLUDE_tty__common]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [uid], [numeric UID that executed the process]) SNOOPY_CONFIGURE_DATASOURCE_ENABLE( [username], [literal username of UID that executed the process]) # ============================================================================== # ======= END section: ENABLE INDIVIDUAL DATA SOURCES ========================== # ============================================================================== dnl ============================================================================ dnl ======= DEFAULT MESSAGE FORMAT ============================================= dnl ============================================================================ AC_ARG_WITH(message-format, [AS_HELP_STRING( [--with-message-format=FORMAT], [format to use to log messages with. For default value and available options, see comments in etc/snoopy.ini for format specification.] )], [ if test "x$withval" = "x" -o "x$withval" = "xyes"; then AC_MSG_ERROR([--with-message-format requires an appropriate value (message format specification). See etc/snoopy.ini for syntax. To use default log message format, remove this argument from ./configure line.]) elif test "x$withval" = "xno"; then AC_MSG_ERROR([using --without-message-format is not supported, log message format is required, or omit this argument altogether to enable default log message format.]) else with_message_format="$withval" fi ], [with_message_format="@<:@uid:%{uid} sid:%{sid} tty:%{tty} cwd:%{cwd} filename:%{filename}@:>@: %{cmdline}"] ) AC_DEFINE_UNQUOTED(SNOOPY_CONF_MESSAGE_FORMAT, "$(echo $with_message_format | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')", [Custom message format to use]) AC_SUBST([SNOOPY_CONF_MESSAGE_FORMAT], [$with_message_format]) AC_MSG_NOTICE([Snoopy default message format: "$with_message_format"]) dnl ============================================================================ dnl ============================================================================ dnl ======= END section: DATASOURCES & MESSAGE FORMAT ========================== dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= START section: FILTERING =========================================== dnl ============================================================================ dnl ============================================================================ AC_MSG_NOTICE([-]) dnl ============================================================================ dnl ======= DEPRECATED FILTER: root-only ======================================= dnl ============================================================================ AC_ARG_ENABLE(root-only, [AS_HELP_STRING( [--enable-root-only], [DEPRECATED. Use --enable-filtering --with-filter-chain="only_uid:0" instead.] )], [ AC_MSG_ERROR([Use of --enable-root-only is DEPRECATED. Use --enable-filtering --with-filter-chain="only_uid:0" instead.]) ] ) dnl ============================================================================ dnl ======= ENABLE FILTERING =================================================== dnl ============================================================================ AC_ARG_ENABLE(filtering, [AS_HELP_STRING( [--disable-filtering], [disable general message filtering [default=enabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [filtering], [enable_filtering], [$enableval], []), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([filtering], [enable_filtering], [$enable_everything], [yes]) ) SNOOPY_CONFIGURE_ENABLE_GENERIC_EVALUATE([$enable_filtering], [FILTERING_ENABLED], [filtering subsystem]) # ============================================================================== # ======= Enable/disable all filters at once =================================== # ============================================================================== AC_ARG_ENABLE(all-filters, [AS_HELP_STRING( [--disable-all-filters], [disables all filters at once. This does not disable filtering in general. It only causes that none of filters is going to be built unless explicitly enabling it by specifying --enable-filter-NAME at ./confgure time. [default=enabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [all-filters], [enable_all_filters], [$enableval], []), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([all-filters], [enable_all_filters], [$enable_filtering], [yes]) ) # ============================================================================== # ======= START section: ENABLE INDIVIDUAL FILTERS ============================= # ============================================================================== SNOOPY_CONFIGURE_FILTER_ENABLE( [exclude_spawns_of], [Drops messages that originate for specified process trees.]) SNOOPY_CONFIGURE_FILTER_ENABLE( [exclude_uid], [Drops messages that match given UIDs.]) SNOOPY_CONFIGURE_FILTER_ENABLE( [only_root], [Passes only messages generated by root.]) SNOOPY_CONFIGURE_FILTER_ENABLE( [only_tty], [Passes only messages that do not originate from processes associated with a TTY - daemons, basically.]) SNOOPY_CONFIGURE_FILTER_ENABLE( [only_uid], [Passes only messages that match given UIDs.]) # ============================================================================== # ======= END section: ENABLE INDIVIDUAL FILTERS =============================== # ============================================================================== dnl ============================================================================ dnl ======= WITH FILTER CHAIN ================================================== dnl ============================================================================ AC_ARG_WITH(filter-chain, [AS_HELP_STRING( [--with-filter-chain=CHAINSPEC], [default filter chain to use. See src/snoopy.h and src/filter/ for available filters [default=empty]] )], [ if test "x$withval" = "x" -o "x$withval" = "xno"; then # We allow it here, as it might be desired to not have any # filter chain configured by default, but will be configured # later, using configuration file. # Allowed: empty, no with_filter_chain="" elif test "x$withval" = "xyes"; then # This must be an error. AC_MSG_ERROR([--with-filter-chain requires an appropriate value (filter chain specification), even empty string will do (--with-filter-chain=""). To disable filtering by default, use --without-filter-chain. Filter chain can later be specified and consequentially enabled by using configuration file. For this to work, configuration file (--with-config-file) and general filtering (--enable-filter) must be enabled.]) else with_filter_chain="$withval" fi ], [with_filter_chain=""] ) AC_DEFINE_UNQUOTED(SNOOPY_CONF_FILTER_CHAIN, "$with_filter_chain", [Filter chain to use]) AC_MSG_NOTICE([Snoopy default filter chain: ${with_filter_chain:-(none)}]) dnl ============================================================================ dnl ============================================================================ dnl ======= END section: FILTERING ============================================= dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= START section: OUTPUTS ============================================= dnl ============================================================================ dnl ============================================================================ AC_MSG_NOTICE([-]) # ============================================================================== # ======= Enable/disable all outputs at once =================================== # ============================================================================== AC_ARG_ENABLE(all-outputs, [AS_HELP_STRING( [--disable-all-outputs], [disables all outputs at once. Use --enable-output-NAME to reenable individual output. [default=enabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [all-outputs], [enable_all_outputs], [$enableval], [Use --enable/--disable-output-NAME to reenable/disable individual data sources.]), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([all-outputs], [enable_all_outputs], [$enable_everything], [unspecified]) ) # ============================================================================== # ======= START section: ENABLE INDIVIDUAL OUTPUTS ============================= # ============================================================================== SNOOPY_CONFIGURE_OUTPUT_ENABLE( [devlog], [This is the default output. Writes to /dev/log in a non-blocking manner.]) SNOOPY_CONFIGURE_OUTPUT_ENABLE( [devnull], [This output is a black hole - messages are discarded.]) SNOOPY_CONFIGURE_OUTPUT_ENABLE( [devtty], [Writes to /dev/tty which will send the output to the current console.]) SNOOPY_CONFIGURE_OUTPUT_FORCE( [file], [Writes directly to a file. NOTICE: If applicable, make sure the file has proper permissions set for non-root users too.]) SNOOPY_CONFIGURE_OUTPUT_FORCE( [socket], [Writes to a socket.]) SNOOPY_CONFIGURE_OUTPUT_ENABLE( [stderr], [Writes to stderr.]) SNOOPY_CONFIGURE_OUTPUT_ENABLE( [stdout], [Writes to stdout.]) SNOOPY_CONFIGURE_OUTPUT_DISABLE( [syslog], [WARNING: This output is causing system hangs with SystemD. Do not use it unless you are absolutely certain you know better. Similar to devlog output, but blocking.]) # ============================================================================== # ======= END section: ENABLE INDIVIDUAL OUTPUTS =============================== # ============================================================================== dnl ============================================================================ AC_ARG_WITH(default-output, [AS_HELP_STRING( [--with-default-output=OUTPUT_SPEC], [default output to use. See snoopy.ini or src/output/* for available values. [default=devlog]] )], [ if test "x$withval" = "x" -o "x$withval" = "xyes"; then # Enabled, but without explicit value AC_MSG_ERROR([--with-default-output requires an appropriate value]) elif test "x$withval" = "xno"; then # Explicitly disabled: --without-... AC_MSG_ERROR([using --without-default-output is not supported, as it makes no sense. Either define it explicitly, or, to use the default value, remove this argument from ./configure line.]) else # Enabled with explicit value definition default_output_val="$withval" # Separate output from argument if echo "$default_output_val" | grep ':' > /dev/null ; then default_output=`echo "$default_output_val" | cut -d: -f1` default_output_arg=`echo "$default_output_val" | cut -d: -f2-` else default_output="$default_output_val" default_output_arg="" fi # Strip "output" suffix if exists if ! echo "$default_output" | grep 'output$' > /dev/null ; then default_output=`echo "$default_output" | sed -e 's/output$//'` fi # Check if given output exist if test ! -f src/output/${default_output}output.c ; then AC_MSG_ERROR([--with-default-output value provided is invalid, output does not exist: $default_output]) fi fi ], # Not specified on ./configure line, decided in snoopy.h [ default_output="" default_output_arg="" ] ) AS_IF([test "x$default_output" != "x"], [ AC_DEFINE_UNQUOTED(SNOOPY_CONF_OUTPUT_DEFAULT, ["$default_output"], [Default output provider]) AC_DEFINE_UNQUOTED(SNOOPY_CONF_OUTPUT_DEFAULT_ARG, ["$default_output_arg"], [Default output arguments]) ]) AC_MSG_NOTICE([Snoopy default output: ${default_output:-default (system dependent)}]) AC_MSG_NOTICE([Snoopy default output argument: ${default_output_arg:-(none)}]) dnl ============================================================================ dnl ============================================================================ dnl ======= END section: OUTPUTS =============================================== dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= START section: SYSLOG ============================================== dnl ============================================================================ dnl ============================================================================ AC_MSG_NOTICE([-]) dnl ============================================================================ AC_ARG_WITH(syslog-facility, [AS_HELP_STRING( [--with-syslog-facility=FACILITY], [syslog facility to use when logging. Check 'man 3 syslog' or 'man openlog' for supported values [default=LOG_AUTHPRIV]] )], [ if test "x$withval" = "x" -o "x$withval" = "xyes"; then # Enabled, but without explicit value AC_MSG_ERROR([--with-syslog-facility requires an appropriate LOG_* value]) elif test "x$withval" = "xno"; then # Explicitly disabled: --without-... AC_MSG_ERROR([using --without-syslog-facility is not supported, syslog log facility is required. Either define it explicitly, or, to use the default value, remove this argument from ./configure line.]) else # Enabled with explicit value definition with_syslog_facility_val="$withval" # Check for value correctness syslog_facility_short=`echo "$with_syslog_facility_val" | awk '{print toupper($0)}' | sed -e 's/^LOG_//' | grep -E '^(AUTH|AUTHPRIV|CRON|DAEMON|FTP|KERN|LOCAL(0|1|2|3|4|5|6|7)|LPR|MAIL|NEWS|SYSLOG|USER|UUCP)$'` if test "x$syslog_facility_short" = "x"; then AC_MSG_ERROR([--with-syslog-facility value provided is invalid: $with_syslog_facility_val]) fi # Prefix value with LOG_ syslog_facility="LOG_$syslog_facility_short" fi ], # Not specified on ./configure line [syslog_facility="LOG_AUTHPRIV"] ) AC_DEFINE_UNQUOTED(SNOOPY_CONF_SYSLOG_FACILITY, [$syslog_facility], [Syslog facility to use by default]) AC_MSG_NOTICE([Snoopy default syslog facility: $syslog_facility]) dnl ============================================================================ AC_ARG_WITH(syslog-level, [AS_HELP_STRING( [--with-syslog-level=LEVEL], [syslog level to use when logging. Check 'man 3 syslog' or 'man openlog' for supported values [default=LOG_INFO]] )], [ if test "x$withval" = "x" -o "x$withval" = "xyes"; then # Enabled, but without explicit value AC_MSG_ERROR([--with-syslog-level requires an appropriate LOG_* value]) elif test "x$withval" = "xno"; then # Explicitly disabled: --without-... AC_MSG_ERROR([using --without-syslog-level is not supported, syslog log level is required. Either define it explicitly, or, to use the default value, remove this argument from ./configure line.]) else # Enabled with explicit value definition with_syslog_level_val="$withval" # Check for value correctness syslog_level_short=`echo "$with_syslog_level_val" | awk '{print toupper($0)}' | sed -e 's/^LOG_//' | grep -E '^(EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG)$'` if test "x$syslog_level_short" = "x"; then AC_MSG_ERROR([--with-syslog-level value provided is invalid: $with_syslog_level_val]) fi # Prefix value with LOG_ syslog_level="LOG_$syslog_level_short" fi ], # Not specified on command line [syslog_level="LOG_INFO"] ) AC_DEFINE_UNQUOTED(SNOOPY_CONF_SYSLOG_LEVEL, [$syslog_level], [Syslog level to use by default]) AC_MSG_NOTICE([Snoopy default syslog level: $syslog_level]) dnl ============================================================================ AC_ARG_WITH(syslog-ident, [AS_HELP_STRING( [--with-syslog-ident=STRING], [syslog identity to use when logging. [default=snoopy]] )], [ if test "x$withval" = "x" -o "x$withval" = "xyes"; then # Enabled, but without explicit value AC_MSG_ERROR([--with-syslog-ident requires a value]) elif test "x$withval" = "xno"; then # Explicitly disabled: --without-... AC_MSG_ERROR([using --without-syslog-ident is not supported, syslog ident is required. Either define it explicitly, or, to use the default value, remove this argument from ./configure line.]) else # Enabled with explicit value definition syslog_ident="$withval" fi ], # Not specified on command line [syslog_ident="snoopy"] ) AC_DEFINE_UNQUOTED(SNOOPY_CONF_SYSLOG_IDENT_FORMAT, ["$syslog_ident"], [Syslog ident to use by default]) AC_MSG_NOTICE([Snoopy default syslog ident: "$syslog_ident"]) dnl ============================================================================ dnl ============================================================================ dnl ======= END section: SYSLOG ================================================ dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= START section: DEVELOPMENT ========================================= dnl ============================================================================ dnl ============================================================================ AC_MSG_NOTICE([-]) dnl ============================================================================ dnl ======= ENABLE TEST COVERAGE BUILD ========================================= dnl ============================================================================ AC_ARG_ENABLE(code-coverage, [AS_HELP_STRING( [--enable-code-coverage], [Embed code coverage instrumentation into Snoopy [default=disabled]] )], SNOOPY_CONFIGURE_ENABLE_GENERIC_SPECIFIED( [code_coverage], [code_coverage_enabled], [$enableval], []), SNOOPY_CONFIGURE_ENABLE_GENERIC_UNSPECIFIED([code_coverage], [code_coverage_enabled], [no], []) ) SNOOPY_CONFIGURE_ENABLE_GENERIC_EVALUATE([$code_coverage_enabled], [CODE_COVERAGE_ENABLED], [code coverage]) AS_IF([test "x$code_coverage_enabled" = "xyes"], [ # Disable optimization, add code coverage-related build and linking flags changequote({,}) CFLAGS=`echo $CFLAGS | sed 's/-O[1-9s]/-O0/g'` CXXFLAGS=`echo $CXXFLAGS | sed 's/-O[1-9s]/-O0/g'` CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" CXXFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" LDFLAGS="$LDFLAGS -lgcov --coverage" changequote([,]) ]) dnl ============================================================================ dnl ============================================================================ dnl ======= END section: DEVELOPMENT =========================================== dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= END CONFIGURATION SUMMARY OUTPUT =================================== dnl ============================================================================ AC_MSG_NOTICE([======================================================================]) dnl ============================================================================ dnl ============================================================================ dnl ======= START: Check for config-dependent things =========================== dnl ============================================================================ dnl ============================================================================ ### Datasource snoopy_threads # # Bail out if this datasource is explicitly enabled, but thread_safety is not # AS_IF([test "x$enable_datasource_explicit_snoopy_threads" = "xyes" -a "x$thread_safety_enabled" = "xno"], [ AC_MSG_ERROR([For datasource snoopy_threads to be enabled, thread safety must be enabled too. Unable to continue.]) ]) ### Datasource systemd_unit_name requires datasource cgroup # AS_IF([test "x$enable_datasource_systemd_unit_name" = "xyes" -a "x$enable_datasource_cgroup" = "xno"], [ AC_MSG_ERROR([For datasource systemd_unit_name to be enabled, datasource cgroup must be enabled too. Unable to continue.]) ]) ### Datasource tid - check for pthread library # AS_IF([test "x$enable_datasource_tid" = "xyes"], [ AC_CHECK_HEADER([pthread.h], [], [ AC_MSG_ERROR([A header file is missing. Unable to continue.]) ]) AC_CHECK_LIB([pthread], [pthread_self], [], [ AC_MSG_ERROR([A library is missing. Unable to continue. (Needed by "tid" datasource.)]) ]) ]) dnl ============================================================================ dnl ============================================================================ dnl ======= END: Check for config-dependent things ============================= dnl ============================================================================ dnl ============================================================================ dnl ============================================================================ dnl ======= Final output ======================================================= dnl ============================================================================ AC_OUTPUT snoopy-snoopy-2.5.2/configure.scan000066400000000000000000000036541470651710700172430ustar00rootroot00000000000000# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) # AC_CONFIG_SRCDIR commented out by dev-tools/autoscan.sh AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_AWK AC_PROG_CC AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET # Checks for libraries. # FIXME: Replace `main' with a function in `-lpthread': AC_CHECK_LIB([pthread], [main]) # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h stddef.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h utmp.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_PID_T AC_TYPE_SIZE_T AC_TYPE_SSIZE_T AC_TYPE_UID_T # Checks for library functions. AC_FUNC_FORK AC_FUNC_MALLOC AC_FUNC_STRERROR_R AC_FUNC_STRNLEN AC_CHECK_FUNCS([getcwd gethostname gettimeofday localtime_r socket strchr strdup strerror strndup strrchr strstr utmpname]) AC_CONFIG_FILES([Makefile doc/Makefile etc/Makefile lib/Makefile lib/inih/Makefile lib/inih/src/Makefile src/Makefile src/action/Makefile src/cli/Makefile src/datasource/Makefile src/entrypoint/Makefile src/filter/Makefile src/output/Makefile src/util/Makefile tests/Makefile tests/bin/Makefile tests/cli/Makefile tests/combined/Makefile tests/configfile/Makefile tests/datasource/Makefile tests/filter/Makefile tests/general/Makefile tests/message/Makefile tests/output/Makefile tests/threads/Makefile tests/unit/Makefile]) AC_OUTPUT snoopy-snoopy-2.5.2/dev-tools/000077500000000000000000000000001470651710700163205ustar00rootroot00000000000000snoopy-snoopy-2.5.2/dev-tools/_bootstrap.sh000066400000000000000000000126671470651710700210440ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and error handler # set -e set -u set -o pipefail ### Fatal error handler # _fatalError() { ERR_FILE="$0" ERR_MSG="$1" ERR_LINE="${2:--}" echo "[$ERR_FILE:$ERR_LINE] ERROR: $ERR_MSG" 1>&2 exit 1 } ### Message output handlers # _echo() { echo "[$0] $1" } _debug() { echo "[$0] [DEBUG] $1" } ### Public release version/tag verifier # # This check (in contrast to the one below) is more strict, and controls what # format of public release versioning do we actually allow in the current # releasing process implementation. For now, only these two options: # - X.Y.Z # - X.Y.ZrcN # _isPublicReleaseTagFormatValid() { RELEASE_TAG_TO_VERIFY="$1" if [[ $RELEASE_TAG_TO_VERIFY =~ ^snoopy-[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$ ]]; then true else false fi } _isPublicReleaseVersionFormatValid() { RELEASE_VERSION_TO_VERIFY="$1" if [[ $RELEASE_VERSION_TO_VERIFY =~ ^[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$ ]]; then true else false fi } ### Determine if release is considered stable or not # # RC and git-based releases are not considered stable. # _doesReleaseTagDenoteStableRelease() { RELEASE_TAG_TO_VERIFY="$1" if [[ $RELEASE_TAG_TO_VERIFY =~ ^snoopy-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then true else false fi } _doesReleaseVersionDenoteStableRelease() { RELEASE_VERSION_TO_VERIFY="$1" if [[ $RELEASE_VERSION_TO_VERIFY =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then true else false fi } ### Determine if release is considered public or not # # Stable and RC releases are considered public. Implications (as of this writing) # are that such releases are subject to more consistency scrutiny. # # Git-based preview releases (with -X-gXXXXXXX version suffix) are not considered # a public repease, even if their packages land in the `testing` channel. # _doesReleaseTagDenotePublicRelease() { RELEASE_TAG_TO_VERIFY="$1" if [[ $RELEASE_TAG_TO_VERIFY =~ ^snoopy-[0-9]+\.[0-9]+\.[0-9]+(-?rc\.?[0-9]+)?$ ]]; then true else false fi } _doesReleaseVersionDenotePublicRelease() { RELEASE_VERSION_TO_VERIFY="$1" if [[ $RELEASE_VERSION_TO_VERIFY =~ ^[0-9]+\.[0-9]+\.[0-9]+(-?rc\.?[0-9]+)?$ ]]; then true else false fi } ### Determine packaging channel from tag/version # # Usage: # PACKAGING_CHANNEL="" # _getPackagingChannelFromVersion "$MY_SNOOPY_VERSION" # if [ "$PACKAGING_CHANNEL" == "stable" ]; then # ... # if # _getPackagingChannelFromTag() { RELEASE_TAG_TO_VERIFY="$1" PACKAGING_CHANNEL="" if [[ $RELEASE_TAG_TO_VERIFY =~ ^snoopy-[0-9]+\.[0-9]+\.[0-9]+$ ]]; then PACKAGING_CHANNEL="stable" else PACKAGING_CHANNEL="testing" fi } _getPackagingChannelFromVersion() { RELEASE_VERSION_TO_VERIFY="$1" PACKAGING_CHANNEL="" if [[ $RELEASE_VERSION_TO_VERIFY =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then PACKAGING_CHANNEL="stable" else PACKAGING_CHANNEL="testing" fi } _detectOperatingSystem() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/_bootstrap.sh # - dev-tools/install-dev-software.sh # - dev-tools/install-packaging-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID set to "" # - Global variable OS_VERSION set to "" # - Global variable OS_VERSION_CODENAME set to "" # # Sets: # - Global variable OS_ID # - Global variable OS_VERSION (potentially not applicable on rolling releases) # - Global variable OS_VERSION_CODENAME (if applicable) # # How to use this method in a script: # OS_ID="" # OS_VERSION="" # OS_VERSION_CODENAME="" # _detectOperatingSystem # echo "id:$OS_ID" # echo "version=$OS_VERSION" # echo "version_codename=$OS_VERSION_CODENAME" # # Returns: # - (nothing) OS_ID="" OS_VERSION="" OS_VERSION_CODENAME="" . /etc/os-release OS_ID="$ID" OS_VERSION="${VERSION_ID:-}" OS_VERSION_CODENAME="${VERSION_CODENAME:-}" if [ "$OS_ID" == "" ]; then _debug "/etc/os-release content:" cat /etc/os-release _fatalError "Unable to detect your OS via /etc/os-release." fi # Debian testing/Sid quirk if [[ "$OS_ID" == "debian" ]] && [[ "$OS_VERSION_CODENAME" == "" ]]; then OS_VERSION_CODENAME=`apt-cache policy | grep http://deb.debian.org/debian -A1 | tail -n1 | grep -Eo 'n=[a-z]+' | sed -e 's/^n=//'` # Needed by extract-native-package-install-steps.sh if [ "$OS_VERSION_CODENAME" == "bookworm" ]; then OS_VERSION="12" fi fi # Almalinux contains minor version in VERSION_ID, let's remove it if [[ "$OS_ID" == "almalinux" ]] && [[ $OS_VERSION =~ \. ]]; then OS_VERSION=`echo "$OS_VERSION" | cut -d. -f1` fi # Arch quirk if [[ "$OS_ID" == "arch" ]] && [[ "$OS_VERSION" == "TEMPLATE_VERSION_ID" ]]; then OS_VERSION="" OS_VERSION_CODENAME="" fi } _isGitStatusIgnoredClean() { RES=`git status --ignored --short | grep -c '^!!'` || true if [ "$RES" -le "2" ]; then return 0 else return 1 fi } ### Check the runtime environment # if [ "${BOOTSTRAP_GIT_REPO_REQUIRED:-true}" != "false" ]; then if [ ! -d .git ]; then _fatalError "This script must be run from the root of the git repository" fi fi snoopy-snoopy-2.5.2/dev-tools/autoscan.sh000077500000000000000000000012101470651710700204660ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/_bootstrap.sh ### Run autoscan # autoscan ### Fix the autoscan's output # # AC_CONFIG_SRCDIR is somewhat randomly set to the first encountered file in the source tree. # # Enountered so far: # - lib/inih/src/ini.h (long time default) # - lib/inih/src/ini.c (encountered in 2023 on Ubuntu 20.04) # - tests/bin/action-run-filter.c (encountered in GitHub's Actions) # # Let's just stop this nonsense and fix the output manually. # sed -i 's%^AC_CONFIG_SRCDIR.\+%# AC_CONFIG_SRCDIR commented out by dev-tools/autoscan.sh%' configure.scan snoopy-snoopy-2.5.2/dev-tools/build-native-package.sh000077500000000000000000000227411470651710700226410ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/_bootstrap.sh ### Define the help method # _showHelp() { cat < '~rc' transformation causes the dpkg/dnf/yum to install the final # release, once it is available, over the installed release candidates. # # On arch, the tilde character is not treated as above. However, i.e. version 1.0.0rc # is considered lower than 1.0.0, so we remove the potential dash in front of rc. # case "$OS_ID" in arch) # For pacman, 1.0.0rc1 < 1.0.0 PKG_SNOOPY_VERSION=`echo "$SNOOPY_RELEASE_VERSION" | sed -e 's/-rc/rc/' | sed -e 's/-/_/g'` PKG_RELEASE_NUMBER="$ARG_PKG_RELEASE_NUMBER" ARCHITECTURE=`uname -m` PKG_VERS_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}" PKG_FULL_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}-${ARCHITECTURE}" PKG_FILE_NAME="snoopy-${PKG_FULL_TAG}.pkg.tar.zst" PKG_FILE_PATH="${PKG_FILE_NAME}" ;; debian|ubuntu) # For dpkg/apt, 1.0.0~rc1 < 1.0.0 PKG_SNOOPY_VERSION=`echo "$SNOOPY_RELEASE_VERSION" | sed -e 's/-\?rc/~rc/'` PKG_RELEASE_NUMBER="$ARG_PKG_RELEASE_NUMBER" PKG_RELEASE_DIST="${OS_VERSION_CODENAME}" PKG_RELEASE_TAG="${PKG_RELEASE_NUMBER}~${PKG_RELEASE_DIST}" ARCHITECTURE=`dpkg-architecture -q DEB_BUILD_ARCH` PKG_VERS_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}~${PKG_RELEASE_DIST}" PKG_FULL_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}~${PKG_RELEASE_DIST}_${ARCHITECTURE}" PKG_FILE_NAME="snoopy_${PKG_FULL_TAG}.deb" PKG_FILE_PATH="../${PKG_FILE_NAME}" ;; rhel|fedora|centos|almalinux) # For rpm/yum/dnf, 1.0.0~rc1 < 1.0.0 PKG_SNOOPY_VERSION=`echo "$SNOOPY_RELEASE_VERSION" | sed -e 's/-\?rc/~rc/' | sed -e 's/-/_/g'` PKG_RELEASE_NUMBER="$ARG_PKG_RELEASE_NUMBER" PKG_RELEASE_DIST=`rpm --eval '%{?dist}' | sed -e 's/^[.]//'` if [ "$PKG_RELEASE_DIST" == "" ]; then _fatalError "Unable to determine target distribution tag" fi PKG_RELEASE_TAG="${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}" ARCHITECTURE=`rpm --eval '%{_arch}'` PKG_VERS_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}" PKG_FULL_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}.${ARCHITECTURE}" PKG_FILE_NAME="snoopy-${PKG_FULL_TAG}.rpm" PKG_FILE_PATH="packaging/rpmbuild/RPMS/$ARCHITECTURE/${PKG_FILE_NAME}" ;; sles|opensuse-leap|opensuse-tumbleweed) # For rpm/zypper, 1.0.0~rc1 < 1.0.0 PKG_SNOOPY_VERSION=`echo "$SNOOPY_RELEASE_VERSION" | sed -e 's/-\?rc/~rc/' | sed -e 's/-/_/g'` PKG_RELEASE_NUMBER="$ARG_PKG_RELEASE_NUMBER" case "$OS_VERSION" in "15.4") PKG_RELEASE_DIST="bp154" ;; "15.5") PKG_RELEASE_DIST="bp155" ;; *) _fatalError "Unsuppoterd SUSE version: $OS_VERSION" ;; esac PKG_RELEASE_TAG="${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}" ARCHITECTURE=`rpm --eval '%{_arch}'` PKG_VERS_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}" PKG_FULL_TAG="${PKG_SNOOPY_VERSION}-${PKG_RELEASE_NUMBER}.${PKG_RELEASE_DIST}.${ARCHITECTURE}" PKG_FILE_NAME="snoopy-${PKG_FULL_TAG}.rpm" PKG_FILE_PATH="packaging/rpmbuild/RPMS/$ARCHITECTURE/${PKG_FILE_NAME}" ;; *) _fatalError "Unsupported OS: '$OS_ID'. Install Snoopy from source instead." ;; esac ### Special "show" run modes # if [ "$ARG_RUN_MODE" == "only-show-file-name" ]; then echo "$PKG_FILE_NAME" exit fi if [ "$ARG_RUN_MODE" == "only-show-file-path" ]; then echo "$PKG_FILE_PATH" exit fi if [ "$ARG_RUN_MODE" == "only-show-package-version" ]; then echo "$PKG_VERS_TAG" exit fi ### Show info in the default "build" run mode # _echo "Snoopy code version: $SNOOPY_RELEASE_VERSION" _echo "Target package full tag: $PKG_FULL_TAG" _echo "Target package file name: $PKG_FILE_NAME" _echo "Target package file path: $PKG_FILE_PATH" ### Verify version consistency for public releases # if _doesReleaseTagDenotePublicRelease "$SNOOPY_RELEASE_TAG" ; then _echo "This is a public rc/stable build, running version consistency checks..." ./dev-tools/libexec/verify-last-version-everywhere.sh "$SNOOPY_RELEASE_VERSION" else _echo "This is NOT a public rc/stable build, thus skipping version consistency checks." fi ### Does the target release package already exist? # if [ -e $PKG_FILE_PATH ]; then _fatalError "Release package file already exists: $PKG_FILE_PATH (Hint: 'rm -f $PKG_FILE_PATH' or 'make clean')" fi ### Clean the environment if necessary # ./dev-tools/clean-git-repository.sh ### Run the build environment bootstrap # ./bootstrap.sh ### Build the package # case "$OS_ID" in arch) # Make gitclean removes this one, so let's (re?)create it rm -f PKGBUILD ln -s packaging/arch/PKGBUILD # Pull in some settings as environment variables source packaging/arch/env # Build the package makepkg --holdver # Cleanup git checkout packaging/arch/PKGBUILD rm -rf pkg/ ;; debian|ubuntu) # Symlink the debian/ directory first rm -f debian ln -s packaging/deb debian # Generate "proper" packaging/deb/changelog content # # Why such a convoluted approach? # # Well, we can't do that with ./configure that translates # `changelog.in` template to `changelog`, as dpkg-buildpackage first # cleans the directory, making subsequent step fail due to a missing # `changelog` file. cat packaging/deb/changelog.TEMPLATE \ | sed -e "s/DEB_PACKAGE_VERSION/$PKG_VERS_TAG/" \ > packaging/deb/changelog # Build the package dpkg-buildpackage --build=binary --no-sign # Remove the temporary changelog file rm -f packaging/deb/changelog # Cleanup rm -rf packaging/deb/.debhelper/ rm -f packaging/deb/autoreconf.after rm -f packaging/deb/autoreconf.before rm -f packaging/deb/debhelper-build-stamp rm -f packaging/deb/files rm -f packaging/deb/snoopy.debhelper.log rm -f packaging/deb/snoopy.postrm.debhelper rm -f packaging/deb/snoopy.substvars rm -rf packaging/deb/snoopy/ rm -f debian ;; rhel|fedora|centos|almalinux|\ sles|opensuse-leap|opensuse-tumbleweed) rpmbuild \ --define "snoopy_rpm_package_version ${PKG_SNOOPY_VERSION}" \ --define "snoopy_rpm_release_tag ${PKG_RELEASE_TAG}" \ --define "_topdir $PWD/packaging/rpmbuild" \ --define '_configure ../../../configure' \ -bb packaging/rpm/snoopy.spec ;; *) _fatalError "Unsupported OS: '$OS_ID'. Install Snoopy from source instead." ;; esac ### Check if target file has indeed been built # if [ ! -e $PKG_FILE_PATH ]; then _fatalError "Package build complete, but expected package file not found: $PKG_FILE_PATH" fi ### Report success # _echo "" _echo "SUCCESS: Build complete." _echo "SUCCESS: Package file path: $PKG_FILE_PATH" _echo "" snoopy-snoopy-2.5.2/dev-tools/build-release-package.sh000077500000000000000000000037771470651710700230030ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/_bootstrap.sh ### Check the runtime environment # if [ ! -d .git ]; then _fatalError "This script must be run from the root of the git repository" fi ### Get the release tag # RELEASE_TAG=`./dev-tools/libexec/get-release-tag.sh` if [ "$RELEASE_TAG" == "" ]; then _fatalError "Unable to determine release tag, got: '$RELEASE_TAG'" fi ### Check if release tag is properly formatted # if [[ ! "$RELEASE_TAG" =~ ^snoopy- ]]; then _fatalError "Release tag is not properly formatted - snoopy-* format is required" fi RELEASE_VERSION=`echo "$RELEASE_TAG" | sed -e 's/snoopy-//'` _echo "Determined release tag: $RELEASE_TAG" _echo "Determined release version: $RELEASE_VERSION" ### Verify version consistency for public releases # RELEASE_IS_PUBLIC="false" if _doesReleaseTagDenotePublicRelease "$RELEASE_TAG" ; then _echo "This is a stable/rc build, running version consistency checks..." ./dev-tools/libexec/verify-last-version-everywhere.sh "$RELEASE_VERSION" RELEASE_IS_PUBLIC="true" else _echo "This is NOT a stable/rc build, thus skipping version consistency checks." fi ### Does the target release package already exist? # RELEASE_PACKAGE_FILE="snoopy-$RELEASE_VERSION.tar.gz" if [ -e $RELEASE_PACKAGE_FILE ]; then _fatalError "Release package file already exists: $RELEASE_PACKAGE_FILE" fi ### Clean up the git repo first # ./dev-tools/clean-git-repository.sh ### Create the release package # ./bootstrap.sh ./configure --enable-everything make clean make distcheck ### Report success # _echo "" _echo "SUCCESS: Build complete." _echo "SUCCESS: Result: $RELEASE_PACKAGE_FILE" _echo "" ### Suggest next step(s) # if [ "$RELEASE_IS_PUBLIC" == "true" ]; then _echo " Next step: ========== 5. Publish the release: ./dev-tools/publish-release.sh " else _echo " Next step: ========== This is not a public release, thus not showing the publishing next step(s). " fi snoopy-snoopy-2.5.2/dev-tools/clean-git-repository.sh000077500000000000000000000043551470651710700227460ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/_bootstrap.sh ### Define the help method # _showHelp() { cat < /dev/null; then _fatalError "Git commit with message'$COMMIT_MESSAGE' already exists" $LINENO fi ### Check git history for the existence of a tag # if git tag | egrep "^$RELEASE_TAG\$" > /dev/null; then _fatalError "Git tag '$RELEASE_TAG' already exists" $LINENO fi ### Verify last version information # if ! ./dev-tools/libexec/verify-last-version-everywhere.sh "$RELEASE_VERSION"; then _fatalError "Last version information is not consistent everywhere: $RELEASE_VERSION" $LINENO fi _echo "Last release version information is consistent everywhere." ### Verify if ChangeLog and README.md changes are not yet committed # if ! git status | grep 'modified:' | grep 'ChangeLog$' > /dev/null; then _fatalError "Release-related ChangeLog changes must not yet be committed - they must a part of the release commit" $LINENO fi if ! git status | grep 'modified:' | grep 'README.md$' > /dev/null; then _fatalError "Release-related README.md changes must not yet be committed - they must a part of the release commit" $LINENO fi ### Create a git commit and tag # # - Pre-format the commit message # - Open the editor for any additional tweaking # - If the commit is successful, tag the commit # git add ChangeLog git add README.md git commit -m "Release $RELEASE_VERSION # # # If you want to terminate the commit+tag process here, # comment out all the lines above and save. # This will result in the 'Aborting commit due to empty commit message' error. # # # " -e -s -v git tag "$RELEASE_TAG" ### Report success # _echo "" _echo "SUCCESS: Commit and tag for version $RELEASE_VERSION created (locally)." _echo "" ### Suggest next step(s) # _echo " Next step: ========== 4. Build the release package: ./dev-tools/build-release-package.sh " snoopy-snoopy-2.5.2/dev-tools/import-external-lib.sh000077500000000000000000000132101470651710700225520ustar00rootroot00000000000000#!/bin/bash #!/bin/bash ### How does this script operate? # # Script's expectations: # - A directory that contains IMPORT.defs, where the import definitions are stored # - Access to the referenced git repository URL (via internet, or otherwise) # # Script's arguments: # - Path to the directory containing the external library to import/update # # Steps that this script performs: # - Reads the external library import definitions (from the IMPORT.defs file) # - Clones the library's git repo to a temporary location # - Executes the import routine # - Applies patches, if any are found in the patches/ directory inside target directory # - In the IMPORT.defs: updates the git reference that was used for the import ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/_bootstrap.sh ### Define the help method # _showHelp() { cat < /dev/null; then ALL_REQUIRED_PROGRAMS_PRESENT="false" _echo "The following program is missing: $REQUIRED_PROGRAM" fi done if [ "$ALL_REQUIRED_PROGRAMS_PRESENT" == "true" ]; then true else false fi } _detectOperatingSystem() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID set to "" # - Global variable OS_VERSION set to "" # # Sets: # - Global variable OS_ID # - Global variable OS_VERSION # # Returns: # - (nothing) OS_ID="" OS_VERSION="" . /etc/os-release OS_ID="$ID" OS_VERSION="${VERSION_ID:-}" # Debian Sid quirk if [[ $OS_ID == "debian" ]] && [[ "$OS_VERSION" == "" ]]; then OS_VERSION="sid" fi } _installPackages() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID # - Global variable OS_VERSION # - Global variable PACKAGE_NAMES_ALPINE # - Global variable PACKAGE_NAMES_ARCH # - Global variable PACKAGE_NAMES_DEBIAN # - Global variable PACKAGE_NAMES_REDHAT # - Global variable PACKAGE_NAMES_SUSE # # Sets: # - (nothing) # # Returns: # - false on error USE_SUDO="sudo -n" MY_UID=`id -u` if [ "$MY_UID" == "0" ]; then USE_SUDO="" fi case "$OS_ID" in alpine) $USE_SUDO apk add $PACKAGE_NAMES_ALPINE ;; arch) $USE_SUDO sudo pacman -Syu --noconfirm $PACKAGE_NAMES_ARCH ;; debian|ubuntu) DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get update -y DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get install -y $PACKAGE_NAMES_DEBIAN ;; rhel|centos|almalinux) $USE_SUDO yum install -y --allowerasing $PACKAGE_NAMES_REDHAT ;; sles|opensuse-leap|opensuse-tumbleweed) $USE_SUDO zypper -n install $PACKAGE_NAMES_SUSE ;; *) _fatalError "Unknown OS: '$OS_ID'. Install the following programs manually: $PACKAGE_NAMES_DEBIAN" ;; esac } ### Check programs presence # if _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then _echo "All required programs are already installed, nice." exit fi # Now run the OS detection # OS_ID="" OS_VERSION="" _detectOperatingSystem if [ "$OS_ID" == "" ]; then _fatalError "Unable to detect your OS via /etc/os-release. Install the following programs manually: $PROGRAM_NAMES" fi ### Now install the packages # _installPackages ### Recheck # if ! _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then _fatalError "Even after installation, at least some of the required programs are still not available. Seems like a bug in this script." else _echo "All required programs are now installed." fi snoopy-snoopy-2.5.2/dev-tools/install-packaging-software.sh000077500000000000000000000062341470651710700241040ustar00rootroot00000000000000#!/bin/bash ### How does this script operate? # # Script's expectations: # - To be run on one of the supported OSes # # Script's arguments: # - (none) # # Steps that this script performs: # - Verifies the presence of required binaries # - If all are present, exit # - Detect the OS, bail out if unknown/unsupported # - Use the OS-specific package installation method to intall all required packages # ### Shell configuration and script bootstrap # set -e set -u set -o pipefail BOOTSTRAP_GIT_REPO_REQUIRED="false" . `dirname $0`/_bootstrap.sh ### Definitions # PACKAGE_NAMES_ARCH="pacman openssh" PACKAGE_NAMES_DEBIAN="debhelper apt-utils gnupg" PACKAGE_NAMES_REDHAT="rpm-build createrepo rpm-sign gnupg2" PACKAGE_NAMES_SUSE="rpm-build createrepo_c gpg2" ### Software check & install functions # # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # _detectOperatingSystem() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID set to "" # - Global variable OS_VERSION set to "" # # Sets: # - Global variable OS_ID # - Global variable OS_VERSION # # Returns: # - (nothing) OS_ID="" OS_VERSION="" . /etc/os-release OS_ID="$ID" OS_VERSION="${VERSION_ID:-}" # Debian Sid quirk if [[ $OS_ID == "debian" ]] && [[ "$OS_VERSION" == "" ]]; then OS_VERSION="sid" fi } _installPackages() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID # - Global variable OS_VERSION # - Global variable PACKAGE_NAMES_ARCH # - Global variable PACKAGE_NAMES_DEBIAN # - Global variable PACKAGE_NAMES_REDHAT # - Global variable PACKAGE_NAMES_SUSE # # Sets: # - (nothing) # # Returns: # - false on error USE_SUDO="sudo -n" MY_UID=`id -u` if [ "$MY_UID" == "0" ]; then USE_SUDO="" fi case "$OS_ID" in arch) $USE_SUDO sudo pacman -Syu --noconfirm $PACKAGE_NAMES_ARCH ;; debian|ubuntu) DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get update -y DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get install -y $PACKAGE_NAMES_DEBIAN ;; rhel|centos|almalinux) $USE_SUDO yum install -y --allowerasing $PACKAGE_NAMES_REDHAT ;; sles|opensuse-leap|opensuse-tumbleweed) $USE_SUDO zypper -n install $PACKAGE_NAMES_SUSE ;; *) _fatalError "Unknown OS: '$OS_ID'. Install the following programs manually: $PACKAGE_NAMES_DEBIAN" ;; esac } # Now run the OS detection # OS_ID="" OS_VERSION="" _detectOperatingSystem if [ "$OS_ID" == "" ]; then _fatalError "Unable to detect your OS via /etc/os-release. Install the following programs manually: $PROGRAM_NAMES" fi ### Now install the packages # _installPackages snoopy-snoopy-2.5.2/dev-tools/libexec/000077500000000000000000000000001470651710700177335ustar00rootroot00000000000000snoopy-snoopy-2.5.2/dev-tools/libexec/extract-and-run-install-steps-from-readme.sh000077500000000000000000000021211470651710700302760ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u set -o pipefail MYDIR=`dirname $0` ### Local or remote operation? # README_LOCATION="local" if [ "${1:-}" == "-r" ]; then README_LOCATION="remote" fi ### Extract the install steps # INSTALL_STEPS="" if [ "$README_LOCATION" == "remote" ]; then SNOOPY_README_URL="https://raw.githubusercontent.com/a2o/snoopy/master/README.md" echo "Extracting steps from remore README.md at $SNOOPY_README_URL..." INSTALL_STEPS=`wget -O - $SNOOPY_README_URL | grep -E '## Installation' -A25 | grep -E '^\`\`\`shell$' -A15 | grep -E '^\`\`\`$' -B10 | grep -Ev '^\`\`\`' | sed -e 's/sudo //'` else echo "Extracting steps from local README.md..." INSTALL_STEPS=`cat $MYDIR/../../README.md | grep -E '## Installation' -A25 | grep -E '^\`\`\`shell$' -A15 | grep -E '^\`\`\`$' -B10 | grep -Ev '^\`\`\`' | sed -e 's/sudo //'` echo fi echo "Extracted install steps ('sudo' was removed, not needed for CI):" echo "========================" echo "$INSTALL_STEPS" echo "========================" ### Run the install steps # eval $INSTALL_STEPS snoopy-snoopy-2.5.2/dev-tools/libexec/extract-native-package-install-steps.sh000077500000000000000000000176521470651710700274340ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/../_bootstrap.sh ### Define the help method # _showHelp() { cat < /dev/null ; then _fatalError "Unable to find package installation steps for string '$SEARCH_STRING' in file $SEARCH_FILE." fi INSTALL_STEPS=`cat $SEARCH_FILE | grep -F "$SEARCH_STRING" -A20 | sed -e '1,/^\`\`\`shell$/d' | sed -e '/^\`\`\`$/,$d' | sed -e 's/^sudo //'` if [ "$INSTALL_STEPS" == "" ]; then _fatalError "Unable to extract package installation steps for search key '$SEARCH_KEY' from file $SEARCH_FILE." fi ### Adjust if requested # if [ "$REPO_URL_SWITCH_TO_RAW" == "true" ]; then _echo "NOTICE: Switching repository URLs from GitHub Pages to raw.githubusercontent..." INSTALL_STEPS=`echo "$INSTALL_STEPS" | sed -e 's#https://a2o.github.io/snoopy-packages/repo/#https://raw.githubusercontent.com/a2o/snoopy-packages/master/repo/#g'` fi if [ "$REPO_CHANNEL_SWITCH_TO_TESTING" == "true" ]; then _echo "NOTICE: Switching instructions from 'stable' to 'testing'..." INSTALL_STEPS=`echo "$INSTALL_STEPS" | sed -e 's/stable/testing/g'` fi ### Adjust to non-interactive # if [ "$ADJUST_COMMANDS_TO_NON_INTERACTIVE" == "true" ]; then _echo "NOTICE: Adjusting steps to non-interactive mode..." INSTALL_STEPS=`echo "$INSTALL_STEPS" \ | sed -e 's/^apt install snoopy/DEBIAN_FRONTEND=noninteractive apt install -y snoopy/' \ | sed -e 's/^pacman -Sy snoopy/pacman -Sy --noconfirm snoopy/' \ | sed -e 's/^yum install snoopy/yum install -y snoopy/' \ | sed -e 's/^zypper install snoopy/zypper -n install snoopy/'` fi ### Show extracted steps # echo "Extracted package installation steps ('sudo' was removed, not needed for CI):" echo "=============================================================================" echo "$INSTALL_STEPS" echo "=============================================================================" ### Run the install steps if requested # if [ "$MODE" == "extract-and-execute" ]; then _echo "Executing extracted install steps:" eval "$INSTALL_STEPS" fi ### Run the Snoopy library version check # if [ "$CHECK_INSTALLED_SNOOPY_LIBRARY_VERSION" != "" ]; then INSTALLED_SNOOPY_LIBRARY_VERSION=`snoopyctl version | grep '^Snoopy library version:' | awk '{print $4}'` if [ "$CHECK_INSTALLED_SNOOPY_LIBRARY_VERSION" != "$INSTALLED_SNOOPY_LIBRARY_VERSION" ]; then _fatalError "Installed Snoopy library version is not the same as expected (expected=$CHECK_INSTALLED_SNOOPY_LIBRARY_VERSION, installed=$INSTALLED_SNOOPY_LIBRARY_VERSION)" fi fi ### FUNCTION: Get installed package's version # # Usage: # INSTALLED_PACKAGE_VERSION="" # _getInstalledPackageVersion "your-package-name-here" # _getInstalledPackageVersion() { PACKAGE_NAME="$1" OS_ID="" _detectOperatingSystem INSTALLED_PACKAGE_VERSION="" case "$OS_ID" in arch) INSTALLED_PACKAGE_VERSION=`pacman -Q "$PACKAGE_NAME" | awk '{print $2}'` ;; debian|ubuntu) INSTALLED_PACKAGE_VERSION=`dpkg-query --showformat='${Version}' --show "$PACKAGE_NAME"` ;; rhel|fedora|centos|almalinux|\ sles|opensuse-leap|opensuse-tumbleweed) INSTALLED_PACKAGE_VERSION=`rpm -q "$PACKAGE_NAME" --qf '%{VERSION}-%{RELEASE}'` ;; *) _fatalError "Unsupported OS: '$OS_ID'. Install Snoopy from source instead." ;; esac } ### Run the Snoopy package version check # if [ "$CHECK_INSTALLED_SNOOPY_PACKAGE_VERSION" != "" ]; then INSTALLED_PACKAGE_VERSION="" _getInstalledPackageVersion "snoopy" if [ "$CHECK_INSTALLED_SNOOPY_PACKAGE_VERSION" != "$INSTALLED_PACKAGE_VERSION" ]; then _fatalError "Installed Snoopy package version is not the same as expected (expected=$CHECK_INSTALLED_SNOOPY_PACKAGE_VERSION, installed=$INSTALLED_PACKAGE_VERSION)" fi fi snoopy-snoopy-2.5.2/dev-tools/libexec/generate-gcov-reports.sh000077500000000000000000000013731470651710700245200ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/../_bootstrap.sh ### Generate reports # for CFILE in `find . -name '*.c' | sort`; do CDIR=`dirname "$CFILE"` CFILENAME=`basename $CFILE` CFILENAME_NOEXT=`echo "$CFILENAME" | sed -e 's/\.c$//'` if [ -f $CDIR/$CFILENAME_NOEXT.gcno ]; then GCNO_FILE="$CFILENAME_NOEXT.gcno" elif [ -f $CDIR/.libs/$CFILENAME_NOEXT.gcno ]; then GCNO_FILE=".libs/$CFILENAME_NOEXT.gcno" else echo "ERROR: Cannot locate .gcno file for $CFILE ($CDIR, $CFILENAME, $CFILENAME_NOEXT), exiting." exit 1 fi echo "Generating coverage analysis for $CFILE (from $GCNO_FILE)..." ( cd $CDIR && gcov $GCNO_FILE ) done snoopy-snoopy-2.5.2/dev-tools/libexec/get-random-configure-flags.sh000077500000000000000000000125361470651710700254070ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u MYDIR=`dirname $0` ### Collect all ./configure settings # # Ignore the following switches: # --only-root (deprecated), # --enable-dev-tools (not needed), # --output-file (always needed) # --output-socket (always needed) # OTHERS=" everything config-file error-logging thread-safety all-datasources all-outputs filtering all-filters " DATASOURCES=`cat $MYDIR/../../configure.ac | grep SNOOPY_CONFIGURE_DATASOURCE_ | cut -d'[' -f2 | cut -d']' -f1 | sed -e 's/^/datasource-/' | grep -Ev '^datasource-snoopy_(configure_command|version)$'` FILTERS=`cat $MYDIR/../../configure.ac | grep SNOOPY_CONFIGURE_FILTER_ | cut -d'[' -f2 | cut -d']' -f1 | sed -e 's/^/filter-/'` OUTPUTS=`cat $MYDIR/../../configure.ac | grep SNOOPY_CONFIGURE_OUTPUT_ | cut -d'[' -f2 | cut -d']' -f1 | sed -e 's/^/output-/' | grep -Ev '^output-(file|socket)$'` ALL_CONFIGURE_OPTS="$OTHERS $DATASOURCES $FILTERS $OUTPUTS" # Make associative array for this declare -A ALL_CONFIG_OPTS_ASSOC for OPT in $ALL_CONFIGURE_OPTS; do ALL_CONFIG_OPTS_ASSOC[$OPT]="unspecified" done ### Select random set of options # for OPT in "${!ALL_CONFIG_OPTS_ASSOC[@]}"; do RN=$[ RANDOM % 3 ] case $RN in 0) ALL_CONFIG_OPTS_ASSOC[$OPT]="enable" ;; 1) ALL_CONFIG_OPTS_ASSOC[$OPT]="disable" ;; 2) ALL_CONFIG_OPTS_ASSOC[$OPT]="unspecified" ;; esac done ### Adjust selections # # Thread safety needs to be enabled for this datasource # if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-snoopy_threads"]}" == "enable" ]; then ALL_CONFIG_OPTS_ASSOC["thread-safety"]="enable" fi if [[ "${ALL_CONFIG_OPTS_ASSOC["everything"]}" == "enable" ]] || [[ "${ALL_CONFIG_OPTS_ASSOC["all-datasources"]}" == "enable" ]]; then if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-snoopy_threads"]}" != "disable" ]; then ALL_CONFIG_OPTS_ASSOC["thread-safety"]="enable" fi fi if [[ "${ALL_CONFIG_OPTS_ASSOC["everything"]}" == "unspecified" ]] && [[ "${ALL_CONFIG_OPTS_ASSOC["all-datasources"]}" == "unspecified" ]]; then if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-snoopy_threads"]}" != "disable" ]; then ALL_CONFIG_OPTS_ASSOC["thread-safety"]="enable" fi fi # Datasource `cgroup` is needed by `systemd_unit_name` # if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-systemd_unit_name"]}" == "enable" ]; then ALL_CONFIG_OPTS_ASSOC["datasource-cgroup"]="enable" fi if [[ "${ALL_CONFIG_OPTS_ASSOC["everything"]}" == "enable" ]] || [[ "${ALL_CONFIG_OPTS_ASSOC["all-datasources"]}" == "enable" ]]; then if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-systemd_unit_name"]}" != "disable" ]; then ALL_CONFIG_OPTS_ASSOC["datasource-cgroup"]="enable" fi fi if [[ "${ALL_CONFIG_OPTS_ASSOC["everything"]}" == "unspecified" ]] && [[ "${ALL_CONFIG_OPTS_ASSOC["all-datasources"]}" == "unspecified" ]]; then if [ "${ALL_CONFIG_OPTS_ASSOC["datasource-systemd_unit_name"]}" != "disable" ]; then ALL_CONFIG_OPTS_ASSOC["datasource-cgroup"]="enable" fi fi ### Build output # SELECTED_OPTS="" for OPT in "${!ALL_CONFIG_OPTS_ASSOC[@]}"; do case ${ALL_CONFIG_OPTS_ASSOC[$OPT]} in enable) SELECTED_OPTS="$SELECTED_OPTS --enable-$OPT" ;; disable) SELECTED_OPTS="$SELECTED_OPTS --disable-$OPT" ;; esac done ### Add --with-syslog-facility flag by chance - manual for now # RN=$[ RANDOM % 2 ] case $RN in 0) # Skip ;; 1) SYSLOG_FACILITIES=( "AUTH" "AUTHPRIV" "CRON" "DAEMON" "FTP" "KERN" "LOCAL0" "LOCAL1" "LOCAL2" "LOCAL3" "LOCAL4" "LOCAL5" "LOCAL6" "LOCAL7" "LPR" "MAIL" "NEWS" "SYSLOG" "USER" "UUCP" ) SELECTED_SYSLOG_FACILITY=${SYSLOG_FACILITIES[$RANDOM % ${#SYSLOG_FACILITIES[@]} ]} # Also decide if we prefix it with LOG_ or not RN=$[ RANDOM % 2 ] case $RN in 0) PREFIX="LOG_" ;; 1) PREFIX="" ;; esac SELECTED_OPTS="$SELECTED_OPTS --with-syslog-facility=${PREFIX}${SELECTED_SYSLOG_FACILITY}" ;; esac ### Add --with-syslog-level flag by chance - manual for now # RN=$[ RANDOM % 2 ] case $RN in 0) # Skip ;; 1) SYSLOG_LEVELS=( "EMERG" "ALERT" "CRIT" "ERR" "WARNING" "NOTICE" "INFO" "DEBUG" ) SELECTED_SYSLOG_LEVEL=${SYSLOG_LEVELS[$RANDOM % ${#SYSLOG_LEVELS[@]} ]} # Also decide if we prefix it with LOG_ or not RN=$[ RANDOM % 2 ] case $RN in 0) PREFIX="LOG_" ;; 1) PREFIX="" ;; esac SELECTED_OPTS="$SELECTED_OPTS --with-syslog-level=${PREFIX}${SELECTED_SYSLOG_LEVEL}" ;; esac ### Add --with-syslog-ident flag by chance - manual for now # RN=$[ RANDOM % 2 ] case $RN in 0) # Skip ;; 1) SELECTED_OPTS="$SELECTED_OPTS --with-syslog-ident=FAKERANDOMSTRINGTODO" ;; esac ### Final output # echo $SELECTED_OPTS snoopy-snoopy-2.5.2/dev-tools/libexec/get-release-tag.sh000077500000000000000000000020231470651710700232350ustar00rootroot00000000000000#!/bin/bash ### Description # # Return the git tag representing the state of the working directory. # # Expected output variants: # - snoopy-2.3.1 # - snoopy-2.3.1-dirty # - snoopy-2.3.1-146-COMMITID # - snoopy-2.3.1-146-COMMITID-dirty # # The "-dirty" suffix is added whenever there are uncommitted changes in the # working directory. # # The "-xxx-COMMITID" part is added whenever the currently checked out commit # does not have an associated git tag. "xxx" represents the number of commits # since the latest tag. "COMMITID" is a hash representing the current commit. ### Shell configuration and error handler # set -e set -u _fatalError() { MSG="$1" echo "ERROR($0): $MSG" 1>&2 exit 1 } ### Check the runtime environment # if [ ! -d .git ]; then _fatalError "This script must be run from the root of the git repository" fi ### Generate the data # SNOOPY_RELEASE_VERSION=`./dev-tools/libexec/get-release-version.sh ${@:-}` SNOOPY_RELEASE_TAG="snoopy-$SNOOPY_RELEASE_VERSION" echo "$SNOOPY_RELEASE_TAG" snoopy-snoopy-2.5.2/dev-tools/libexec/get-release-version.sh000077500000000000000000000113041470651710700241510ustar00rootroot00000000000000#!/bin/bash ### Description # # Return the version representing the state of the working directory. # # Expected output variants: # - 2.3.1 # - 2.3.1-dirty # - 2.3.1-146-COMMITID # - 2.3.1-146-COMMITID-dirty # # The "-dirty" suffix is added whenever there are uncommitted changes in the # working directory. # # The "-xxx-COMMITID" part is added whenever the currently checked out commit # does not have an associated git tag. "xxx" represents the number of commits # since the latest tag. "COMMITID" is a hash representing the current commit. ### Shell configuration and error handler # set -e set -u _fatalError() { MSG="$1" echo "ERROR($0): $MSG" 1>&2 exit 1 } ### Check the runtime environment # if [ ! -d dev-tools ]; then _fatalError "This script must be run from the root of either git repository or uncompressed distribution package directory" fi ### Define the help method # _showHelp() { cat <&2 IGNORE_DIRTY=true fi ### Check arguments # case $MODE in 'autoreconf') ;; 'git') ;; 'changelog') ;; *) _fatalError "Invalid run mode: '$MODE'. Only 'git', 'changelog' or 'autoreconf' (default) options are supported." ;; esac #### First get current commit ## #CURRENT_COMMIT_HASH=`git rev-parse HEAD` # # # #### Check if current commit has corresponding tag ## #if git show-ref --tags | grep "^$CURRENT_COMMIT_HASH refs/tags" > /dev/null; then # CURRENT_TAG=`git show-ref --tags | grep "^$CURRENT_COMMIT_HASH refs/tags" | awk '{print $2}' | sed -e 's#^refs/tags##'` # CURRENT_PACKAGE_VERSION=`echo "$CURRENT_TAG" | sed -e 's/snoopy-//'` # # ### Is tree dirty? # # # if git describe --tags --dirty | grep -- '-dirty$' > /dev/null; then # CURRENT_PACKAGE_VERSION="${CURRENT_PACKAGE_VERSION}-dirty" # fi #else # # Here '-dirty' gets appended automatically # CURRENT_PACKAGE_VERSION=`git describe --tags --dirty` #fi ### Get current Snoopy version from git, if applicable # # Used for building from git, and for making RC packages # if [ "$MODE" == "autoreconf" -o "$MODE" == "git" ]; then if [ -d .git ]; then if [ "$IGNORE_DIRTY" == "true" ]; then SNOOPY_RELEASE_VERSION=`git describe --tags --always | sed -e 's/^snoopy-//'` else SNOOPY_RELEASE_VERSION=`git describe --tags --always --dirty | sed -e 's/^snoopy-//'` fi echo $SNOOPY_RELEASE_VERSION exit 0 fi fi ### Otherwise get it from ChangeLog # # Used only if ./bootstrap.sh is run from distribution package, not from git # if [ "$MODE" == "autoreconf" -o "$MODE" == "changelog" ]; then if [ -f ChangeLog ]; then SNOOPY_RELEASE_VERSION=`cat ChangeLog | grep -E '^[-0-9]+ - Version [0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$' | head -n1 | awk '{print $4}'` echo $SNOOPY_RELEASE_VERSION exit 0 fi fi ### Signal error # _fatalError "Unable to determine Snoopy version (mode=$MODE)" snoopy-snoopy-2.5.2/dev-tools/libexec/get-sonarcloud-tag.sh000077500000000000000000000025101470651710700237670ustar00rootroot00000000000000#!/bin/bash ### Description # # Return the git tag representing the state of the working directory. # # Expected output variants: # - snoopy-2.3.1 # - snoopy-2.3.1-dirty/branch-name # - snoopy-2.3.1-146-COMMITID/branch-name # - snoopy-2.3.1-146-COMMITID-dirty/branch-name # # The "-dirty" suffix is added whenever there are uncommitted changes in the # working directory. # # The "-xxx-COMMITID" part is added whenever the currently checked out commit # does not have an associated git tag. "xxx" represents the number of commits # since the latest tag. "COMMITID" is a hash representing the current commit. ### Shell configuration and error handler # set -e set -u _fatalError() { MSG="$1" echo "ERROR($0): $MSG" 1>&2 exit 1 } ### Check the runtime environment # if [ ! -d .git ]; then _fatalError "This script must be run from the root of the git repository" fi ### Generate the data # SNOOPY_RELEASE_VERSION=`./dev-tools/libexec/get-release-version.sh ${@:-}` SNOOPY_RELEASE_TAG="snoopy-$SNOOPY_RELEASE_VERSION" ### Add branch info for SonarCloud tags, if applicable # SONARCLOUD_TAG="$SNOOPY_RELEASE_TAG" if ! [[ $SONARCLOUD_TAG =~ ^snoopy-[0-9]+.[0-9]+.[0-9]+(rc[0-9]+)?$ ]]; then CURRENT_BRANCH=`git branch --show-current` SONARCLOUD_TAG="$SONARCLOUD_TAG/$CURRENT_BRANCH" fi echo "$SONARCLOUD_TAG" snoopy-snoopy-2.5.2/dev-tools/libexec/verify-last-version-everywhere.sh000077500000000000000000000017771470651710700264210ustar00rootroot00000000000000#!/bin/bash ### How does this script operate? # # Script's expectations: # - TODO # # Script's arguments: # - Release version to verify # # Steps that this script performs: # - Takes the release version as an argument # - Inspects ChangeLog # - Makes sure that the top-most listed release is the one we're verifying for ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/../_bootstrap.sh ### Get the release version from arguments # RELEASE_VERSION="${1:-}" if [ "$RELEASE_VERSION" == "" ]; then _fatalError "Release version argument not provided. Usage: $0 x.y.z" fi ### Verify release version syntax # if ! _isPublicReleaseVersionFormatValid "$RELEASE_VERSION"; then _fatalError "Invalid public release version syntax: $RELEASE_VERSION" $LINENO fi ### Check everywhere for last version consistency # ./dev-tools/libexec/verify-last-version-in-readme.sh "$RELEASE_VERSION" ./dev-tools/libexec/verify-last-version-in-changelog.sh "$RELEASE_VERSION" ### All good # true snoopy-snoopy-2.5.2/dev-tools/libexec/verify-last-version-in-changelog.sh000077500000000000000000000024201470651710700265510ustar00rootroot00000000000000#!/bin/bash ### How does this script operate? # # Script's expectations: # - TODO # # Script's arguments: # - Release version to verify # # Steps that this script performs: # - Takes the release version as an argument # - Inspects ChangeLog # - Makes sure that the top-most listed release is the one we're verifying for ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/../_bootstrap.sh ### Get the release version from arguments # RELEASE_VERSION="${1:-}" if [ "$RELEASE_VERSION" == "" ]; then _fatalError "Release version argument not provided. Usage: $0 x.y.z" $LINENO fi ### Verify release version syntax # if ! _isPublicReleaseVersionFormatValid "$RELEASE_VERSION"; then _fatalError "Invalid public release version syntax: $RELEASE_VERSION" $LINENO fi ### Get latest release version from ChangeLog and verify it # LAST_VERSION_IN_CHANGELOG=`cat ChangeLog | grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2} - Version [0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?$' | head -n1 | awk '{print $4}'` if [ "$LAST_VERSION_IN_CHANGELOG" != "$RELEASE_VERSION" ]; then _fatalError "Last version listed in ChangeLog is $LAST_VERSION_IN_CHANGELOG, not $RELEASE_VERSION" $LINENO fi ### All good # #_echo "Last version listed in ChangeLog: $LAST_VERSION_IN_CHANGELOG" true snoopy-snoopy-2.5.2/dev-tools/libexec/verify-last-version-in-readme.sh000077500000000000000000000041751470651710700260700ustar00rootroot00000000000000#!/bin/bash ### How does this script operate? # # Script's expectations: # - TODO # # Script's arguments: # - Release version to verify # # Steps that this script performs: # - Takes the release version as an argument # - Inspects ChangeLog # - Makes sure that the top-most listed release is the one we're verifying for ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/../_bootstrap.sh ### Get the release version from arguments # RELEASE_VERSION="${1:-}" if [ "$RELEASE_VERSION" == "" ]; then _fatalError "Release version argument not provided. Usage: $0 x.y.z" fi ### Verify release version syntax # if ! _isPublicReleaseVersionFormatValid "$RELEASE_VERSION"; then _fatalError "Invalid public release version syntax: $RELEASE_VERSION" $LINENO fi ### Check the `News` section of README.md # if ! cat README.md | grep -E '^## News$' -A10 | grep -E '^[|] [0-9]{4}-[0-9]{2}-[0-9]{2}' | grep -E "Snoopy $RELEASE_VERSION released[!.]" > /dev/null; then _fatalError "Version $RELEASE_VERSION not mentioned in the 'News' section of the README.md" $LINENO fi ### Check the `Latest version` section of README.md # if [[ $RELEASE_VERSION =~ rc ]]; then TABLE_ROW_FIRST_CELL_CONTENT="Preview" else TABLE_ROW_FIRST_CELL_CONTENT="Stable" fi if ! cat README.md | grep -E '^## Latest version$' -A10 | grep -E "^[|] +$TABLE_ROW_FIRST_CELL_CONTENT +" | grep -E "[|] +$RELEASE_VERSION +[|]" > /dev/null; then _fatalError "Version $RELEASE_VERSION not mentioned in the 'Latest version' section of the README.md (in the line denoting '$TABLE_ROW_FIRST_CELL_CONTENT' version)" $LINENO fi RES=`cat README.md | grep -E '^## Latest version$' -A10 | grep -E "^[|] +$TABLE_ROW_FIRST_CELL_CONTENT +" | grep -E "[|] +$RELEASE_VERSION +[|]" | tr ' ' '\n' | grep -Eo "snoopy-[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?" | sed -e 's/^snoopy-//' | grep -Ev "^$RELEASE_VERSION\$" | grep -c . || true` if [ "$RES" != "0" ]; then _fatalError "Another version besides $RELEASE_VERSION is mentioned in the 'Latest version' section of the README.md (in the line denoting '$TABLE_ROW_FIRST_CELL_CONTENT' version)" $LINENO fi ### All good # true snoopy-snoopy-2.5.2/dev-tools/libexec/verify-make-targets-prefix.sh000077500000000000000000000007631470651710700254610ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/../_bootstrap.sh ### Generate reports # RES=`make -p | grep -Eo '^[a-z][^:]+\.lo:' | grep -E '^libsnoopy' -c || true` if [ "$RES" -ne "0" ]; then make -p | grep -Eo '^[a-z][^:]+\.lo:' | grep -E '^libsnoopy' _fatalError "Some *.lo make targets contain 'libsnoopy...' prefix (listed above)." $LINENO fi ### All good # _echo "All relevant make targets do not contain 'libsnoopy...' prefix, good." snoopy-snoopy-2.5.2/dev-tools/publish-native-package.sh000077500000000000000000000216021470651710700232030ustar00rootroot00000000000000#!/bin/bash ### Shell configuration and script bootstrap # set -e set -u set -o pipefail . `dirname $0`/_bootstrap.sh ### Define the help method # _showHelp() { cat < dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/binary-amd64/Packages gzip -f -k dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/binary-amd64/Packages # Contents-amd64 apt-ftparchive contents pool/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL > dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/Contents-amd64 gzip -f -k dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/Contents-amd64 # Release #1 apt-ftparchive release dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/binary-amd64 > dists/$OS_VERSION_CODENAME/$PACKAGING_CHANNEL/binary-amd64/Release # Release #2 # NOTICE: Options must be specified without surrounding spaces around the '=' character. # NOTICE: All possible PACKAGING_CHANNEL values must appear in the 'Components' value. apt-ftparchive release \ -o="APT::FTPArchive::Release::Origin=https://a2o.github.io/snoopy-packages/" \ -o="APT::FTPArchive::Release::Suite=snoopy-upstream" \ -o="APT::FTPArchive::Release::Codename=$OS_VERSION_CODENAME" \ -o="APT::FTPArchive::Release::Components=stable testing" \ -o="APT::FTPArchive::Release::Label=Snoopy Command Logger - Upstream APT repository" \ -o="APT::FTPArchive::Release::Architectures=amd64" \ dists/$OS_VERSION_CODENAME \ > dists/$OS_VERSION_CODENAME/Release # Sign gpg -a --yes --detach-sign --local-user snoopy-packages@a2o.github.com --output dists/$OS_VERSION_CODENAME/Release.gpg dists/$OS_VERSION_CODENAME/Release gpg -a --yes --detach-sign --local-user snoopy-packages@a2o.github.com --clearsign --output dists/$OS_VERSION_CODENAME/InRelease dists/$OS_VERSION_CODENAME/Release ) # Git commit && push ( cd $APT_REPO_DIR git add . git commit -m "Release new $PACKAGING_CHANNEL package for $OS_ID/$OS_VERSION_CODENAME: $PKG_FILE_NAME" git push ) ;; rhel|fedora|centos|almalinux|\ sles|opensuse-leap|opensuse-tumbleweed) YUM_REPO_DIR="snoopy-packages/repo/$OS_ID/$OS_VERSION/$PACKAGING_CHANNEL" YUM_REPO_PACKAGES_DIR="$YUM_REPO_DIR/Packages" DEST_FILE_PATH="$YUM_REPO_PACKAGES_DIR/$PKG_FILE_NAME" # Copy the package into the repo _copyPkgToTargetRepo "$PKG_FILE_PATH" "$DEST_FILE_PATH" "$ARG_OVERWRITE_TARGET_PKG" # Sign the package rpmsign --addsign --key-id=snoopy-packages@a2o.github.com $DEST_FILE_PATH # Update YUM repo index files ( cd $YUM_REPO_DIR # Generate all metadata files if [ "$ARG_OVERWRITE_TARGET_PKG" == "true" ]; then createrepo . else createrepo --update . fi # Sign the repo gpg -a --yes --detach-sign --local-user snoopy-packages@a2o.github.com repodata/repomd.xml ) # Git commit && push ( cd $YUM_REPO_DIR git add . git commit -m "Release new $PACKAGING_CHANNEL package for $OS_ID/$OS_VERSION: $PKG_FILE_NAME" git push ) ;; *) _fatalError "Unsupported OS: '$OS_ID'. Install Snoopy from source instead." ;; esac ### Remove the packages repo clone # rm -rf snoopy-packages ### Report success # _echo "" _echo "SUCCESS: Native package publishing complete." _echo "SUCCESS: Published at: $DEST_FILE_PATH" _echo "" snoopy-snoopy-2.5.2/dev-tools/publish-release.sh000077500000000000000000000303041470651710700217430ustar00rootroot00000000000000#!/bin/bash ### How does this script operate? # # Script's expectations: # - # - Executed from the root of the Snoopy's git repository working directory # - Release commit already present and tagged in the repo # - Release commit/tag checked out in the current working directory # - Release package(s) already present in the directory (created via ./dev-tools/build-package-*.sh scripts) # # Script's arguments: # - Release tag to publish (must match currently checked out commit) # # Steps that this script performs: # - Verifies the release commit+tag presence in local repo and being checked out # - Determines the remote to use (from a current branch), overridable # - Push release commit + tag to remote # - Creates a release via GitHub API # - Pushes package file(s) to the release via GitHub API ### Shell configuration and script bootstrap # set -e set -u . `dirname $0`/_bootstrap.sh ### Configuration defaults # SNOOPY_UPSTREAM_GIT_REPO_REGEX="(git@github.com:|https://github.com/)a2o/snoopy(\.git)?(/)?" ### Define the help method # _showHelp() { cat < /dev/null; then _fatalError "Git tag '$RELEASE_TAG' not found on the current git branch." $LINENO fi # Commit message if ! git log --pretty="%h %d %s" | grep -E "(\(|, )tag: $RELEASE_TAG(\)|, )" | grep -E "\) Release $RELEASE_VERSION\$" > /dev/null; then _fatalError "Git tag '$RELEASE_TAG' does not seem to be representing a release commit." $LINENO fi RELEASE_COMMIT_ID=`git log --format="%h" $RELEASE_TAG | head -n1` || true # WhyTF is this "|| true" needed here?!? _echo "Release tag and commit ($RELEASE_COMMIT_ID) seem to be in order locally." ### Check if the release commit and tag already exists in remote, else push them # # Fetch _echo "Fetching from remote '$GIT_REMOTE_NAME'..." git fetch $GIT_REMOTE_NAME # Commit GIT_PUSH_COMMITS="false" if git branch -r --contains $RELEASE_COMMIT_ID | grep -E "$GIT_REMOTE_NAME/$CURRENT_GIT_BRANCH\$" > /dev/null; then _echo "Remote branch $GIT_REMOTE_NAME/$CURRENT_GIT_BRANCH already contains commit $RELEASE_COMMIT_ID, push will be skipped." else _echo "Will push commits from local branch '$CURRENT_GIT_BRANCH' to remote '$GIT_REMOTE_NAME'." GIT_PUSH_COMMITS="true" fi # Tag GIT_PUSH_TAG="false" if git ls-remote --tags origin | grep -E "refs/tags/$RELEASE_TAG\$" > /dev/null; then # Check if the remote tag corresponds to our commit ID if ! git ls-remote --tags origin | grep -E "^$RELEASE_COMMIT_ID.+refs/tags/$RELEASE_TAG\$" > /dev/null; then _fatalError "Git tag '$RELEASE_TAG' already exists in the remote '$GIT_REMOTE_NAME', but it does not represent the release commit $RELEASE_COMMIT_ID." $LINENO fi _echo "Remote '$GIT_REMOTE_NAME' already contains tag $RELEASE_TAG, push will be skipped." else _echo "Will push tag '$RELEASE_TAG' to remote '$GIT_REMOTE_NAME'." GIT_PUSH_TAG="true" fi ### Check the presence of the to-be-published packages # RELEASE_PACKAGE_TARGZ="$RELEASE_TAG.tar.gz" if [ ! -f $RELEASE_PACKAGE_TARGZ ]; then _fatalError "Unable to find local package to release: $RELEASE_PACKAGE_TARGZ" $LINENO fi ### Check if access to GitHub API is working (via the "gh" CLI tool) # if ! command -v gh > /dev/null; then _fatalError "Unable to GitHub CLI tool called 'gh'." $LINENO fi if ! gh release list -R $GIT_REMOTE_GITHUB_ID > /dev/null; then _fatalError "GitHub CLI access is not working. Run 'gh release list -R $GIT_REMOTE_GITHUB_ID' to see the actual error." $LINENO fi RES=`gh release list -R $GIT_REMOTE_GITHUB_ID | grep -P "^$RELEASE_TAG[ \t]+(Latest[ \t]+)?$RELEASE_TAG" -c` || true if [ "$RES" != "0" ]; then _fatalError "Release $RELEASE_TAG already exists in the $GIT_REMOTE_GITHUB_ID git repository." $LINENO fi _echo "GitHub API access works, and release $RELEASE_TAG does not exist yet in $GIT_REMOTE_GITHUB_ID repo, good." ### Is this a stable or a preview (RC) release? # RELEASE_IS_STABLE="false" GH_PREVIEW_RELEASE_FLAG="--prerelease" if _doesReleaseTagDenoteStableRelease "$RELEASE_TAG"; then RELEASE_IS_STABLE="true" GH_PREVIEW_RELEASE_FLAG="" fi ### Sanity check complete, double check the intent # _echo "All checks successful, starting the releasing process." _echo "Target remote name: $GIT_REMOTE_NAME" _echo "Target remote URL: $GIT_REMOTE_URL" _echo "Target remote GitHub id: $GIT_REMOTE_GITHUB_ID" _echo "Release tag: $RELEASE_TAG" _echo "Stable release? $RELEASE_IS_STABLE" if [ "$CONFIRMED_VIA_CLI" != "true" ]; then _echo "Are you sure you want to proceed?" INPUT="" while [ "$INPUT" != "yes" ]; do _echo "(Enter 'yes' or rerun the command with the '-y' flag) " read INPUT done fi ### Push git content # if [ "$GIT_PUSH_COMMITS" == "true" ]; then _echo "Pushing commits from local branch '$CURRENT_GIT_BRANCH' to remote '$GIT_REMOTE_NAME':" git push _echo "Commits pushed." fi if [ "$GIT_PUSH_TAG" == "true" ]; then _echo "Pushing tag '$RELEASE_TAG' to remote '$GIT_REMOTE_NAME'..." git push $GIT_REMOTE_NAME $RELEASE_TAG _echo "Tags pushed." fi ### Create a release # _echo "Creating a release:" gh release create \ -R $GIT_REMOTE_GITHUB_ID \ -n "" \ -t "$RELEASE_TAG" \ $GH_PREVIEW_RELEASE_FLAG \ "$RELEASE_TAG" \ $RELEASE_PACKAGE_TARGZ ### Report success # _echo "" _echo "SUCCESS: Snoopy version $RELEASE_VERSION released." _echo "SUCCESS: The new release is available at:" _echo "SUCCESS:" _echo "SUCCESS: https://github.com/$GIT_REMOTE_GITHUB_ID/releases/tag/$RELEASE_TAG" _echo "" ### Suggest next step(s) # _echo " Next steps: =========== 6. Go to GitHub and close the corresponding milestone: https://github.com/a2o/snoopy/milestones 7. Go to Snoopy's [Actions](https://github.com/a2o/snoopy/actions) tab on GitHub and monitor the workflows related to the new release: https://github.com/a2o/snoopy/actions?query=branch%3A$RELEASE_TAG 8. Trigger the native packaging build jobs: gh workflow run -R a2o/snoopy publish-native-packages.yml --ref=$RELEASE_TAG 9. Monitor the native packaging build jobs: https://github.com/a2o/snoopy/actions/workflows/publish-native-packages.yml?query=branch%3A$RELEASE_TAG 10. Trigger the native package installation verification jobs: gh workflow run -R a2o/snoopy release-qa-os-matrix-install-from-repo.yml --ref=$RELEASE_TAG 11. Monitor the native package installation verification jobs: https://github.com/a2o/snoopy/actions/workflows/release-qa-os-matrix-install-from-repo.yml?query=branch%3A$RELEASE_TAG 12. All done. " snoopy-snoopy-2.5.2/dev-tools/submit-to-coverity.conf.SAMPLE000066400000000000000000000001751470651710700237370ustar00rootroot00000000000000COVERITY_EMAIL=`git config user.email` COVERITY_TOKEN="" COVERITY_BUILD_VERSION=`./dev-tools/libexec/get-release-version.sh` snoopy-snoopy-2.5.2/dev-tools/submit-to-coverity.sh000077500000000000000000000055271470651710700224550ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u set -o pipefail ### Settings # COVERITY_SETTINGS_FILE="./dev-tools/submit-to-coverity.conf" BUILD_DIR="cov-int" # Can't change the name of this one, or else Coverity build analysis fails once the build tarball is uploaded BUILD_FILE_PREFIX="cov-int" ### Help function # displayHelp() { cat < /dev/null; then echo echo "ERROR: Unable to find cov-build." echo echo "export PATH=/path/to/cov-analysis-linux64-a.b.c/bin:\$PATH" echo exit 1 fi if ! command -v curl > /dev/null; then echo echo "ERROR: Unable to find CURL. Please install it and rerun the process." echo exit 1 fi ### Display stuff # cat < /dev/null; then echo "ERROR: Unable to find 'build-wrapper-linux-x86-64'." exit 1 fi if ! command -v sonar-scanner > /dev/null; then echo "ERROR: Unable to find 'sonar-scanner'." exit 1 fi ### Configure # # Clean ./dev-tools/clean-git-repository.sh # Configure ./bootstrap.sh ./configure --enable-everything --enable-code-coverage ### Build with SonarCloud wrapper # build-wrapper-linux-x86-64 \ --out-dir $BUILD_WRAPPER_OUTPUT_DIR \ make ### Generate coverage info # # No need to run `make check`, as the test suite is started by # the `coverage` target in Makefile. # make coverage ### Analyze and submit # CURRENT_BRANCH_NAME=`git branch --show-current` SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh` sonar-scanner \ -Dsonar.organization=a2o \ -Dsonar.projectKey=snoopy \ -Dsonar.sources=. \ -Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \ -Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \ -Dsonar.branch.name=$CURRENT_BRANCH_NAME \ -Dsonar.projectVersion=$SONARCLOUD_TAG \ -Dsonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUTPUT_DIR \ -Dsonar.cfamily.gcov.reportsPath=. \ -Dsonar.host.url=https://sonarcloud.io echo "INFO: Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)" snoopy-snoopy-2.5.2/dev-tools/test-build-matrix.sh000077500000000000000000000037331470651710700222430ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u set -o pipefail ### Which configurations are we testing # CONFIGURE_ARGS_MATRIX=( '--enable-output-devlog' # This is a normal build - we must not have "" so we imitate it with something that is always enabled '--enable-everything' '--enable-everything --disable-config-file' '--enable-everything --disable-filtering' '--enable-everything --disable-config-file --disable-filtering' '--enable-everything --disable-thread-safety' '--disable-everything' '--disable-everything --enable-config-file' '--disable-everything --enable-config-file --enable-output-file' '--disable-everything --enable-filtering' '--disable-everything --enable-filtering --enable-datasource-uid' '--disable-everything --enable-config-file --enable-filtering' '--disable-everything --enable-thread-safety' ) ### Display stuff # echo -e "\n\n\n" cat < /etc/ld.so.preload ``` ## Verification This is an example verification process (again, tested on Ubuntu 20.04) for making sure that both Snoopy instances work as expected. v1. Enable installation of packages built for the 32-bit architecture: ``` dpkg --add-architecture i386 ``` v2. Install a 32-bit version of `zsh`: ``` apt-get update apt-get install zsh:i386 ``` v3. Get into the 32-bit `zsh`: ``` zsh ``` v4. Run a unique command to see if 32-bit logging works: ``` tail -f /var/log/auth.log -n14 ``` v5. And sure enough, in the output of the last command, the expected `-n14` (generated by the 32-bit Snoopy instance) appears in the very last line. Earlier log entries (ending with the `filename:/usr/bin/zsh]: zsh` entry) were produced by the 64-bit Snoopy instance: ``` t-snoopy-2004-multiarch# tail -f /var/log/auth.log -n14 Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14408]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/bin/chown]: chown --reference=/etc/shells /etc/shells.tmp Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14409]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/bin/mv]: mv /etc/shells.tmp /etc/shells Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14410]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/bin/ln]: ln -s /bin/zsh /usr/bin/zsh Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14411]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/usr/bin/dpkg-maintscript-helper]: dpkg-maintscript-helper symlink_to_dir /usr/share/doc/zsh zsh-common 5.0.7-3 -- configure Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14412]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/usr/bin/basename]: basename /usr/bin/dpkg-maintscript-helper Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14413]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/usr/bin/dpkg]: dpkg --validate-version -- 5.0.7-3 Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14415]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/sbin/ldconfig]: ldconfig Nov 26 19:40:35 t-snoopy-2004-multiarch snoopy[14415]: [uid:0 sid:14352 tty:/dev/pts/5 cwd:/ filename:/sbin/ldconfig.real]: /sbin/ldconfig.real Nov 26 19:40:36 t-snoopy-2004-multiarch snoopy[14421]: [uid:0 sid:278 tty:/dev/pts/4 cwd:/tmp filename:/usr/lib/ubuntu-advantage/apt-esm-hook]: /usr/lib/ubuntu-advantage/apt-esm-hook post-invoke-success Nov 26 19:40:42 t-snoopy-2004-multiarch snoopy[14422]: [uid:0 sid:278 tty:/dev/pts/4 cwd:/snoopy-2.4.15 filename:/usr/bin/zsh]: zsh Nov 26 19:40:42 t-snoopy-2004-multiarch snoopy[14423]: [uid:0 sid:278 tty:/dev/pts/4 cwd:/snoopy-2.4.15 filename:/usr/bin/getent]: getent group root Nov 26 19:40:42 t-snoopy-2004-multiarch snoopy[14442]: [uid:0 sid:278 tty:/dev/pts/4 cwd:/snoopy-2.4.15 filename:/bin/mv]: mv -f /root/.zcompdump.t-snoopy-2004-multiarch.14422 /root/.zcompdump Nov 26 19:40:57 t-snoopy-2004-multiarch snoopy[14445]: [uid:0 sid:278 tty:(none) cwd:/snoopy-2.4.15 filename:/usr/bin/tail]: tail --version Nov 26 19:41:09 t-snoopy-2004-multiarch snoopy[14446]: [uid:0 sid:278 tty:/dev/pts/4 cwd:/snoopy-2.4.15 filename:/usr/bin/tail]: tail -f /var/log/auth.log -n14 ^C t-snoopy-2004-multiarch# ``` ## Notes * In the example above, both Snoopy instances (the 64-bit one residing in `/usr/lib/x86_64-linux-gnu`, and the 32-bit one in `/usr/lib/i386-linux-gnu`) will use the same `/etc/snoopy.ini` configuration file. * The absence of full path to `libsnoopy.so` in `/etc/ld.so.preload` will make the linker choose the correct version, depending on the architecture for which the executed program was built. * Alternatively (tested on Ubuntu 20.04), specifying full path in `/etc/ld.so.preload` as `/usr/$LIB/libsnoopy.so` will yield the same result, as `$LIB` is expanded to `lib/x86_64-linux-gnu` or `lib/i386-linux-gnu`. * In the past, apparently `$LIB` used to expand to one of `lib64`/`lib32`/`lib` (depending on the actual libc implementation/configuration, [multilib](https://de.wikipedia.org/wiki/Multilib)). This is apparently not the case anymore (as of 2021). * Some systems may support `LD_PRELOAD_32` and `LD_PRELOAD_64` environmental variables to load appropriate variations of architecture-dependent shared libraries. snoopy-snoopy-2.5.2/doc/INSTALL.md000066400000000000000000000024541470651710700166060ustar00rootroot00000000000000# Installation instructions - Snoopy Command Logger There are five main options for installing Snoopy: 1. *From your Linux distribution repositories:* Your distribition maintainers may already have packaged Snoopy for you. Simply try the install command (i.e. `apt install snoopy` on Ubuntu) and keep your fingers crossed. Package may be named slightly differently, though, like `libsnoopy`. 2. *From upstream package repositories:* Snoopy maintainers provide binary package repositories for certain Linux distributions. Here is [a guide for installing Snoopy from upstream package repositories](install-from-repo.md). 3. *Automated build from release tarballs:* An install script is provided that builds and installs Snoopy from source. Here is [a guide for building from source](install-from-source.md). 3. *Manual build from release tarballs:* Build and install directly from released sources on your own. The same [guide for building from source](install-from-source.md) contains relevant information. 4. *Manual build from git repository:* This method is essentially almost the same as installing (manually) from release tarballs. Therefore, [the guide for building from source](install-from-source.md) also contains bits related to building directly from a git repository clone. snoopy-snoopy-2.5.2/doc/Makefile.am000066400000000000000000000003541470651710700172070ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Include documentation in final release package # EXTRA_DIST = \ CONTRIBUTING.md \ FAQ.md \ FILTER_exclude_spawns_of.md \ INSTALL.md snoopy-snoopy-2.5.2/doc/RELEASING-HOWTO.md000066400000000000000000000060711470651710700177060ustar00rootroot00000000000000# Releasing guide - Snoopy Command Logger ## Changing the release process / Editing this document This document contains the overall releasing process description, but hints for what to do after each step are scattered around the related scripts in the [dev-tools/](../dev-tools/) directory, to speed up the process. Therefore, when changing the release process and documenting the changes in this file, replicate the changes into the `Next step(s):` sections at the end of each releasing-related script in the [dev-tools/](../dev-tools/) directory. ## (Before the release) QA Run through the Quality Assurance-related steps in the [HACKING-QA.md](HACKING-QA.md) document and work out any kinks that get pointed out. ## (Before the release) Assumptions The following assumptions are, well, assumed, by the releasing scripts: - `master` branch is used for releasing. - All the code that is to be released is already merged into the `master` branch. - The final release-related updates to `ChangeLog` and `README.md` files are already present in the local files, **but not yet committed**. - The release commit does not yet exist. - The release tag does not yet exist. - The release does not exist yet on GitHub. ## Steps to release Snoopy 0. If it makes sense, drop a note to Marcos Fouces and mention the RC tag to test, and he'll upload it to the Debian Sid CI as an experimental release. This way, the new Snoopy code can be built and tested on [a lot of different architectures](https://buildd.debian.org/status/package.php?p=snoopy&suite=sid). https://buildd.debian.org/status/package.php?p=snoopy&suite=sid 1. Edit the `ChangeLog` file, update the upcoming release version and date: edit ChangeLog 2. Edit the `README.md` file, update: - The latest shown release version - The latest release version in URLs right next to the edit above - Add the latest release to the `News` section: edit README.md 3. Create a commit and tag: ./dev-tools/create-release-commit-and-tag.sh 4. Build the release package: ./dev-tools/build-release-package.sh 5. Publish the release: ./dev-tools/publish-release.sh 6. Go to GitHub and close the corresponding milestone: https://github.com/a2o/snoopy/milestones 7. Go to Snoopy's [Actions](https://github.com/a2o/snoopy/actions) tab on GitHub and monitor the workflows related to the new release: https://github.com/a2o/snoopy/actions?query=branch%3A$RELEASE_TAG 8. Trigger the native packaging build jobs: gh workflow run -R a2o/snoopy publish-native-packages.yml --ref=$RELEASE_TAG 9. Monitor the native packaging build jobs: https://github.com/a2o/snoopy/actions/workflows/publish-native-packages.yml?query=branch%3A$RELEASE_TAG 10. Trigger the native package installation verification jobs: gh workflow run -R a2o/snoopy release-qa-os-matrix-install-from-repo.yml --ref=$RELEASE_TAG 11. Monitor the native package installation verification jobs: https://github.com/a2o/snoopy/actions/workflows/release-qa-os-matrix-install-from-repo.yml?query=branch%3A$RELEASE_TAG 12. All done. snoopy-snoopy-2.5.2/doc/install-from-repo.md000066400000000000000000000143651470651710700210560ustar00rootroot00000000000000# Installing from upstream package repository - Snoopy Command Logger Supported distributions: * [AlmaLinux OS](#almalinux-os) * [Arch Linux](#arch-linux) * [CentOS](#centos) * [Debian](#debian) * [openSUSE Leap](#opensuse-leap) * [Ubuntu](#ubuntu) Supported architectures: * x86_64 (amd64) Prerequisites: * Installed package: `curl` Release channels: * stable * [testing](#repositories-with-non-stable-builds-testing) ## AlmaLinux OS List of supported AlmaLinux OS versions is [here](https://github.com/a2o/snoopy-packages/tree/master/repo/almalinux). AlmaLinux 9 [search-key:almalinux-9]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && echo "[snoopy-stable] name=Snoopy Upstream Stable Repository baseurl=https://a2o.github.io/snoopy-packages/repo/almalinux/9/stable/ enabled=1 gpgcheck=1 " > /etc/yum.repos.d/snoopy-stable.repo && yum install snoopy ``` AlmaLinux 8 [search-key:almalinux-8]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && echo "[snoopy-stable] name=Snoopy Upstream Stable Repository baseurl=https://a2o.github.io/snoopy-packages/repo/almalinux/8/stable/ enabled=1 gpgcheck=1 " > /etc/yum.repos.d/snoopy-stable.repo && yum install snoopy ``` ## Arch Linux NOTICE: Trusted keys must be already initialized (hint: `pacman-key --init`). Arch Linux rolling-release [search-key:arch]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && pacman-key --add snoopy-packages-key.pub && pacman-key --lsign-key snoopy-packages@a2o.github.com && echo " [snoopy-stable] Server = https://a2o.github.io/snoopy-packages/repo/arch/stable/ " >> /etc/pacman.conf && pacman -Sy snoopy ``` ## CentOS List of supported CentOS versions is [here](https://github.com/a2o/snoopy-packages/tree/master/repo/centos). CentOS 9 Stream [search-key:centos-9]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && echo "[snoopy-stable] name=Snoopy Upstream Stable Repository baseurl=https://a2o.github.io/snoopy-packages/repo/centos/9/stable/ enabled=1 gpgcheck=1 " > /etc/yum.repos.d/snoopy-stable.repo && yum install snoopy ``` CentOS 8 Stream [search-key:centos-8]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && echo "[snoopy-stable] name=Snoopy Upstream Stable Repository baseurl=https://a2o.github.io/snoopy-packages/repo/centos/8/stable/ enabled=1 gpgcheck=1 " > /etc/yum.repos.d/snoopy-stable.repo && yum install snoopy ``` ## Debian List of supported Debian versions is [here](https://github.com/a2o/snoopy-packages/tree/master/repo/debian/dists). Debian 12 (Bookworm) [search-key:debian-12]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/debian bookworm stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` Debian 11 (Bullseye) [search-key:debian-11]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/debian bullseye stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` Debian 10 (Buster) [search-key:debian-10]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/debian buster stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` ## openSUSE Leap List of supported openSUSE Leap versions [here](https://github.com/a2o/snoopy-packages/tree/master/repo/opensuse-leap). openSUSE Leap 15.5 [search-key:opensuse-leap-15.5]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && zypper addrepo -n "Snoopy Upstream Stable Repository" -g -e https://a2o.github.io/snoopy-packages/repo/opensuse-leap/15.5/stable/ snoopy-stable && zypper install snoopy ``` openSUSE Leap 15.4 [search-key:opensuse-leap-15.4]: ```shell curl -o snoopy-packages-key.pub https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub && rpm --import snoopy-packages-key.pub && zypper addrepo -n "Snoopy Upstream Stable Repository" -g -e https://a2o.github.io/snoopy-packages/repo/opensuse-leap/15.4/stable/ snoopy-stable && zypper install snoopy ``` ## Ubuntu Packages are provided for active Ubuntu LTS versions only. List of supported Ubuntu LTS versions is [here](https://github.com/a2o/snoopy-packages/tree/master/repo/ubuntu/dists). Ubuntu 24.04 LTS (Noble Numbat) [search-key:ubuntu-24.04]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/ubuntu noble stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` Ubuntu 22.04 LTS (Jammy Jellyfish) [search-key:ubuntu-22.04]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/ubuntu jammy stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` Ubuntu 20.04 LTS (Focal Fossa) [search-key:ubuntu-20.04]: ```shell curl https://a2o.github.io/snoopy-packages/snoopy-packages-key.pub | apt-key add - && echo "deb https://a2o.github.io/snoopy-packages/repo/ubuntu focal stable" > /etc/apt/sources.list.d/snoopy-stable.list && apt update && apt install snoopy ``` ## Respositories with non-stable builds - testing Instructions above contain steps to install **stable** Snoopy releases only. Sometimes, non-stable Snoopy packages are released too, but not through the stable repositories. To install a **testing** Snoopy version, add a _testing_ repository: - Use the same steps as above, but - In all steps, replace the word `stable` with `testing`, i.e.: - `https://a2o.github.io/snoopy-packages/repo/ubuntu jammy stable` becomes - `https://a2o.github.io/snoopy-packages/repo/ubuntu jammy testing` snoopy-snoopy-2.5.2/doc/install-from-source.md000066400000000000000000000172171470651710700214100ustar00rootroot00000000000000# Installing from source - Snoopy Command Logger * Building and installing: * [Automated installation procedure](#automated-installation-procedure) * [Building from source](#building-from-source) * [Distribution-native packages](#distribution-native-packages) (and [how to build them](#building-a-distribution-native-package)) * [Multiarch systems](#multiarch-systems) * Configuration: * [Important build configuration flags](#important-build-configuration-flags) * [/etc/snoopy.ini](#etcsnoopyini) * Enabling: * [Enable for a specific command](#enable-for-a-specific-command) * [Enable system-wide](#enable-system-wide) * [Under the hood](#under-the-hood) * Removing: * [What gets installed](#what-gets-installed) * [How to disable Snoopy](#how-to-disable-snoopy) ## Automated installation procedure (This is the preferred installation method.) To start the automated installation procedure of the latest **stable** version of Snoopy, run this command: ``` wget -q -O install-snoopy.sh https://github.com/a2o/snoopy/raw/install/install/install-snoopy.sh && chmod 755 install-snoopy.sh && ./install-snoopy.sh stable ``` To use the automated installation procedure for installing the latest **development** version of Snoopy, simply modify the `./install-snoopy.sh` command above by replacing the `stable` argument with `git-master`. ## Building from source Download the Snoopy source tarball (you can find the releases [here](https://github.com/a2o/snoopy/releases)): ``` wget https://github.com/a2o/snoopy/releases/download/snoopy-2.4.15/snoopy-2.4.15.tar.gz tar -xzf snoopy-2.4.15.tar.gz cd snoopy-2.4.15 ``` Alternatively, clone the latest Snoopy git repository from GitHub: ``` git clone https://github.com/a2o/snoopy snoopy cd snoopy # Run the ./bootstrap.sh script to generate the ./configure script ./bootstrap.sh ``` Configure the build: ``` ./configure [OPTIONS] ``` For information about available build configuration options, consult the section below listing [the most important build configuration flags](#important-build-configuration-flags) or run the `./configure --help` to list all available flags. Build it: ``` make ``` Optionally run the test suite: ``` make tests ``` Install it: ``` make install ``` At this point, Snoopy is **installed but not yet enabled**. What is missing is (optionally) [adjusting the snoopy.ini configuration file](#etcsnoopyini) and [enabling Snoopy for a specific command](#enable-for-a-specific-command) or [enabling Snoopy system-wide](#enable-system-wide). ## Distribution-native packages Providing distribution-specific instructions on how to install packages is out of the scope of this manual. However, installing a distribution-native Snoopy package should look something like this: ``` apt install snoopy # Debian / Ubuntu yum install snoopy # RHEL / CentOS zypper install snoopy # SLES / OpenSUSE ``` #### Building a distribution-native package **Disclaimer:** * There are distribution-native Snoopy packages in the wild, created by distribution package maintainers. * Efforts of distribution package maintainers and efforts of Snoopy core developers are (mostly) independent of each other (as of late 2021). That said, some distribution package maintainers (and other interested individuals) have contributed their work to the Snoopy upstream repository (this repository). Their contributions are collected in the [contrib/](../contrib/) directory: * Debian/Ubuntu, in `contrib/debian/` * RHEL/CentOS/Fedora, in `contrib/rhel/` * SLES/OpenSUSE, in `contrib/sles/` ## Multiarch systems Snoopy does not natively support installation on systems that concurrently support multiple architectures. However, [doc/INSTALL-MULTIARCH.md](INSTALL-MULTIARCH.md) guide contains an example multiarch installation. ## Important build configuration flags | Flag | Meaning | |------------------------|---------| | --disable-config-file | Disable `snoopy.ini` support (default: enabled) | | --with-message-format | Modify the built-in default log message format. Useful when config file support is disabled. | | --with-default-output | Modify the built-in default output target. Useful when config file support is disabled. | | --enable-thread-safety | Enable per-thread data structures (experimental, default: disableD) | | --prefix | Overall installation target directory prefix (default: `/usr/local`) | | --libdir | Target `libsnoopy.so` installation directory (default: `PREFIX/lib`) | | --sysconfdir | Target `snoopy.ini` installation directory (default: `PREFIX/etc`) | Run the `./configure --help` command to get a list of all available build flags. ## /etc/snoopy.ini When Snoopy has been built with a configuration file support (which is enabled by default), then Snoopy runtime configuration is picked up from the `/etc/snoopy.ini` file (or `PREFIX/etc/snoopy.ini` or `SYSCONFDIR/snoopy.ini`, depending on your build flags). All supported runtime configuration directives are listed and described in the default [snoopy.ini](../etc/snoopy.ini.in) configuration file. Configuration changes are picked up instantly, as Snoopy re-reads its configuration file on each invocation. ## Enable for a specific command When only a certain application should be monitored for its execution of external programs, the `LD_PRELOAD` environment variable can be used: ``` LD_PRELOAD="/usr/local/lib/libsnoopy.so" bash ``` The new `bash` shell instance will log any executed command. Exiting this `bash` will stop the logging. ## Enable system-wide There are two ways to enable Snoopy. The first one is to use a `snoopyctl` CLI utility that is installed by the `make install` step above: ``` snoopyctl enable ``` Alternatively, when Snoopy has been built from source, the following `make` command can be used from within the source directory: ``` makectl enable ``` A system reboot is usually necessary to make all programs pick up the newly installed Snoopy. #### Under the hood `snoopyctl enable` or `make enable` command creates an entry in the `/etc/ld.so.preload` file. This entry causes the [dynamic linker](https://man7.org/linux/man-pages/man8/ld.so.8.html) to preload the Snoopy shared library, which interposes Snoopy between the `execv()`/`execve()` function calls of a program and the real `execv()`/`execve()` implementations in the libc library. When `execv()`/`execve()` is called, the interposed Snoopy code is responsible for creating a log entry for a command that is to be executed, and then the execution is forwarded to the real `execv()`/`execve()` libc functions to do the actual program invocation. ## What gets installed Commands `make install` and `make enable`/`snoopyctl enable` perform the following changes on the system: | File | Location | Change | |------------------|----------------------|--------| | `libsnoopy.so*` | `/usr/local/lib/`* | File installed | | `snoopyctl` | `/usr/local/sbin/`* | File installed | | `snoopy.ini` | `/etc/`* | File installed | | `ld.so.preload` | `/etc/ld.so.preload` | Entry added | *Locations of these files may vary, depending on your [build configuration flags](#important-build-configuration-flags). ## How to disable Snoopy The simplest way to disable Snoopy is to use the script installed for this purpose: ``` snoopyctl disable ``` Once disabled, a system reboot may be necessary to force a reload of all the running programs. #### How to disable Snoopy manually To manually disable Snoopy, remove any references to `libsnoopy.so` from the `/etc/ld.so.preload` file. Additionally, unset any environment variable that references Snoopy (`LD_PRELOAD`, `LD_PRELOAD_32`, and `LD_PRELOAD_64`). Reboot. snoopy-snoopy-2.5.2/etc/000077500000000000000000000000001470651710700151575ustar00rootroot00000000000000snoopy-snoopy-2.5.2/etc/Makefile.am000066400000000000000000000033331470651710700172150ustar00rootroot00000000000000include $(top_srcdir)/build/Makefile.am.common AUTOMAKE_OPTIONS = foreign subdir-objects ACLOCAL_AMFLAGS = -I build/m4 if CONFIGFILE_ENABLED install-exec-local: if [ ! -f $(DESTDIR)$(sysconfdir)/snoopy.ini ]; then \ echo ; \ echo "Installing configuration file: $(DESTDIR)$(sysconfdir)/snoopy.ini" ; \ echo ; \ if [ ! -e $(DESTDIR)$(sysconfdir) ]; then \ install -d $(DESTDIR)$(sysconfdir) ; \ fi ; \ install -m 644 snoopy.ini $(DESTDIR)$(sysconfdir)/snoopy.ini ; \ else \ if diff -u snoopy.ini $(DESTDIR)$(sysconfdir)/snoopy.ini; then \ echo ; \ echo "No changes to configuration file are required: $(DESTDIR)$(sysconfdir)/snoopy.ini" ; \ echo ; \ else \ install -m 644 snoopy.ini $(DESTDIR)$(sysconfdir)/snoopy.ini.NEW ; \ echo ; \ echo "Existing config file: $(DESTDIR)$(sysconfdir)/snoopy.ini" ; \ echo " New config file: $(DESTDIR)$(sysconfdir)/snoopy.ini.NEW" ; \ echo ; \ echo "WARNING: CONFIGURATION FILE CHANGES NEED MANUAL REVIEW" ; \ echo ; \ fi ; \ fi ; \ if [ -f $(DESTDIR)$(sysconfdir)/snoopy.ini ]; then \ if [ -x $(DESTDIR)$(sysconfdir)/snoopy.ini ]; then \ chmod 644 $(DESTDIR)$(sysconfdir)/snoopy.ini ; \ fi ; \ fi ; \ if [ -f $(DESTDIR)$(sysconfdir)/snoopy.ini.NEW ]; then \ if [ -x $(DESTDIR)$(sysconfdir)/snoopy.ini.NEW ]; then \ chmod 644 $(DESTDIR)$(sysconfdir)/snoopy.ini.NEW ; \ fi ; \ fi ; uninstall-local: if [ -f $(DESTDIR)$(sysconfdir)/snoopy.ini ]; then \ echo ; \ echo "Removing configuration file: $(DESTDIR)$(sysconfdir)/snoopy.ini" ; \ echo ; \ rm -f $(DESTDIR)$(sysconfdir)/snoopy.ini ; \ fi ; endif snoopy-snoopy-2.5.2/etc/snoopy.ini.in000066400000000000000000000255551470651710700176300ustar00rootroot00000000000000;;; REQUIRED Section ; [snoopy] ;;; Log Message Format specification ; ; May consist of: ; - arbitrary text, which is copied to log message as-is, ; - calls to data sources without arguments: %{datasourcename} ; - calls to data sources with argument : %{datasourcename:arg1} ; - calls to data sources with arguments: %{datasourcename:arg1,arg2} <--- if data source supports it ; ; List of available data sources: ; - %{cgroup:PATTERN} ; (available=@enable_datasource_cgroup@) Control group information. PATTERN can be either a number (hierarchy id) or a string (controller name) ; - %{cmdline} ; (available=@enable_datasource_cmdline@) Full command line, with arguments ; - %{cwd} ; (available=@enable_datasource_cwd@) Current working directory ; - %{datetime:fmt} ; (available=@enable_datasource_datetime@) Date and time. The format argument is optional, supports strftime() syntax (%-based conversion specifications, google for "man strftime()") and defaults to ISO 8601 format. ; - %{domain} ; (available=@enable_datasource_domain@) Domain of current system ; - %{egid} ; (available=@enable_datasource_egid@) Effective gid that executed the command ; - %{egroup} ; (available=@enable_datasource_egroup@) Effective group name that executed the command ; - %{env:VAR} ; (available=@enable_datasource_env@) Environmental variable named 'VAR' ; - %{env_all} ; (available=@enable_datasource_env_all@) All environmental varibles, comma separated ; - %{euid} ; (available=@enable_datasource_euid@) Effective uid that executed the command ; - %{eusername} ; (available=@enable_datasource_eusername@) Effective username that executed the command ; - %{filename} ; (available=@enable_datasource_filename@) Full path to executable ; - %{gid} ; (available=@enable_datasource_gid@) Group id that executed the command ; - %{group} ; (available=@enable_datasource_group@) Group name that executed the command ; - %{hostname} ; (available=@enable_datasource_hostname@) Hostname of current system ; - %{ipaddr} ; (available=@enable_datasource_ipaddr@) IP address of a connected terminal ; - %{login} ; (available=@enable_datasource_login@) Login name (tries getlogin_r() first, then SUDO_USER env variabe, and LOGNAME env as last resort) ; - %{pid} ; (available=@enable_datasource_pid@) ID of process that executed the command ; - %{ppid} ; (available=@enable_datasource_ppid@) Parent process ID of process that executed the command ; - %{rpname} ; (available=@enable_datasource_rpname@) Root process name of process that executed the command ; - %{sid} ; (available=@enable_datasource_sid@) Process id of session group process leader ; - %{snoopy_configure_command} ; (available=@enable_datasource_snoopy_configure_command@) The ./configure command that was used to build Snoopy ; - %{snoopy_threads} ; (available=@enable_datasource_snoopy_threads@) Number of threads that Snoopy currently is configured for ; - %{snoopy_version} ; (available=@enable_datasource_snoopy_version@) Snoopy version ; - %{snoopy_literal:arg} ; (available=@enable_datasource_snoopy_literal@) Dummy data source, only returns its argument literally ; - %{systemd_unit_name} ; (available=@enable_datasource_systemd_unit_name@) SystemD unit name, as read from /proc/PID/cgroup (from line that starts with "1:name=systemd:...") ; - %{tid} ; (available=@enable_datasource_tid@) Thread ID of process that executed the command ; - %{tid_kernel} ; (available=@enable_datasource_tid_kernel@) Thread ID of process that executed the command, as returned by Linux kernel ; - %{timestamp} ; (available=@enable_datasource_timestamp@) Current Unix timestamp ; - %{timestamp_ms} ; (available=@enable_datasource_timestamp_ms@) Millisecond part of current Unix timestamp ; - %{timestamp_us} ; (available=@enable_datasource_timestamp_us@) Microsecond part of current Unix timestamp ; - %{tty} ; (available=@enable_datasource_tty@) Which TTY the command was run on ; - %{tty_uid} ; (available=@enable_datasource_tty_uid@) TTY uid ; - %{tty_username} ; (available=@enable_datasource_tty_username@) TTY username ; - %{uid} ; (available=@enable_datasource_uid@) User id that executed the command ; - %{username} ; (available=@enable_datasource_username@) Username that executed the command ; ; Availability (yes/no): ; This flag signifies whether this build of Snoopy has particular data source ; built-in or not. If particular data source is not available and its use is ; desired, then Snoopy must be rebuilt with flags that enable given data ; source. ; ; Default value: ; "@SNOOPY_CONF_MESSAGE_FORMAT@" ; ; Examples: ;message_format = "useless static log entry that gets logged on every program execution" ;message_format = "uid=%{uid}" ; <--- this would only log uids who execute programs, nothing else; ;message_format = "uid=%{uid} tty=%{tty} cmdline=%{cmdline}" ; <--- logs uid + tty + command that is executed ;;; Filter Chain specification ; ; Must comply with the following rules: ; - one or more filters may be specified, separated by semicolon, ; - each filter may contain argument that follows the colon, ; - filter may accept multiple arguments, separated by comma, ; - filter chain must not contain any spaces (allowed in filter arguments, but generally discouraged). ; ; List of available filters: ; - exclude_spawns_of ; (available=@enable_filter_exclude_spawns_of@) Exclude log entries that occur in specified process trees ; - exclude_uid ; (available=@enable_filter_exclude_uid@) Exclude these UIDs from logging ; - only_root ; (available=@enable_filter_only_root@) Only log root commands ; - only_tty ; (available=@enable_filter_only_tty@) Only log commands associated with a TTY ; - only_uid ; (available=@enable_filter_only_uid@) Only log commands executed by these UIDs ; ; Availability (yes/no): ; This flag signifies whether this build of Snoopy has particular filter ; built-in or not. If particular filter is not available and its use is ; desired, then Snoopy must be rebuilt with flags that enable given filter. ; ; Sample definitions with explanations: ; - filter_chain = "exclude_uid:0" # Log all commands, except the ones executed by root ; - filter_chain = "exclude_uid:1,2,3" # Log all commands, except those executed by users with UIDs 1, 2 and 3 ; - filter_chain = "only_uid:0" # Log only root commands ; - filter_chain = "exclude_spawns_of:cron,my_daemon" # Do not log commands spawned by cron or my_daemon ; - filter_chain = "filter1:arg11;filter2:arg21,arg22;filter3:arg31,32,33" ; ; Default value: ; "" (empty string) ; ; Examples: ;filter_chain = "" ;filter_chain = "only_uid:0" ;filter_chain = "only_uid:10000,10001,10002" ;filter_chain = "exclude_uid:0" ;;; Output ; ; Where messages get sent to ; ; List of available outputs: ; - devlog ; (available=@enable_output_devlog@) Default, writes directly to /dev/log. ; - devnull ; (available=@enable_output_devnull@) Black hole. ; - devtty ; (available=@enable_output_devtty@) Write to current tty via /dev/tty. ; - file ; (available=@enable_output_file@) Write directly to file. (NOTICE: Make sure file has proper permissions set for non-root users.) ; - socket ; (available=@enable_output_socket@) Built-in output. As argument it requires an absolute path of socket to write to. ; - stderr ; (available=@enable_output_stderr@) Write to STDERR. Mainly useful for debugging purposes. ; - stdout ; (available=@enable_output_stdout@) Write to STDOUT. Mainly useful for debugging purposes. ; - syslog ; (available=@enable_output_syslog@) Previuosly-default (WARNING: DO NOT USE syslog OUTPUT WITH systemd - IT WILL HANG YOUR SYSTEM ON BOOT) ; ; Availability (yes/no): ; This flag signifies whether this build of Snoopy has particular output ; built-in or not. If particular output is not available and its use is ; desired, then Snoopy must be rebuilt with flags that enable given output. ; ; List of outputs pending implementation (patches welcome!): ; - console ; TODO ; - journald ; TODO ; ; Default value: ; devlog ; (previously 'syslog' was default value, but due to systemd issues default was changed) ; (to raw device writing as syslogd blocks syslog() calls if journald is not running) ; ; Example: ;output = devtty ;output = devlog ;output = file:/var/log/snoopy.log ;output = file:/var/log/snoopy.log-%{datetime:%Y-%m-%d} ;output = file:/var/log/snoopy.log-%{username} ;output = file:/home/%{username}/snoopy.log ; If "/home/%{username}" directory does not exist, Snoopy will _not_ create it. ;output = socket:/var/run/socket-for-snoopy.sock ;;; Error Logging ; ; Whether to log error messages or not. ; This should generally be disabled, as it may generate lots of error logs. ; ; The most appropriate usage of this parameter is when: ; - you are developing new data source ; - you are trying to configure message format and are having problems with it ; ; Default value: ; no (unless changed by ./configure --enable-error-logging to yes) ; ; Example: ;error_logging = yes ;;; Syslog Facility ; ; What syslog facility to use. Can be prefixed with 'LOG_'. ; ; Possible values: ; One of AUTH|AUTHPRIV|CRON|DAEMON|FTP|KERN|LOCAL[0-7]|LPR|MAIL|NEWS|SYSLOG|USER|UUCP ; ; Default value: ; LOG_AUTHPRIV (unless changed by ./configure --with-syslog-facility=FACILITY) ; ; Example: ;syslog_facility = LOG_AUTHPRIV ;;; Syslog Ident ; ; What syslog ident (program name) to use. ; ; Possible values: ; Any non-spaced string. Using data sources is supported. ; ; Default value: ; "snoopy" (unless changed by ./configure --with-syslog-ident="other") ; ; Examples: ;syslog_ident = "my-ident-string" ;syslog_ident = "%{username}" ;syslog_ident = "%{systemd_unit_name}" ;;; Syslog Level ; ; What syslog level to use. Can be prefixed with 'LOG_'. ; ; Possible values: ; One of EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG ; ; Default value: ; LOG_INFO (unless changed by ./configure --with-syslog-level=LEVEL) ; ; Example: ;syslog_level = LOG_INFO ;;; Maximum individual data source's message length ; ; The length limit of a message emitted by an individual data source. ; WARNING: Memmory of this size is allocated on every Snoopy invocation. ; Increasing this setting beyond reasonable limits may impact your system's stability. ; ; Possible values: ; Between 255 and 1048575 ; ; Default value: ; 2047 ; ; Example: ;datasource_message_max_length = 2047 ;;; Maximum formatted log message length ; ; The length limit of a final formatted log message. ; WARNING: Memmory of this size is allocated on every Snoopy invocation. ; Increasing this setting beyond reasonable limits may impact your system's stability. ; ; Possible values: ; Between 255 and 1048575 ; ; Default value: ; 16383 ; ; Example: ;log_message_max_length = 16383 snoopy-snoopy-2.5.2/install/000077500000000000000000000000001470651710700160525ustar00rootroot00000000000000snoopy-snoopy-2.5.2/install/install-snoopy.sh000077500000000000000000000412431470651710700214100ustar00rootroot00000000000000#!/bin/bash ### Shell configuration # set -e set -u set -o pipefail ### Configuration # SNOOPY_GIT_ORIGIN_URI="https://github.com/a2o/snoopy.git" SNOOPY_PACKAGE_DOWNLOAD_URI_PREFIX="https://github.com/a2o/snoopy/releases/download" SNOOPY_INSTALL_LOGFILE="`pwd`/install-snoopy.log" SNOOPY_TRAVIS_BUILD=${SNOOPY_TRAVIS_BUILD:-false} ### Helper functions # function _snoopy_install_showHelp() { echo "Possible installation arguments/modes:" echo "- 'stable' ; installs latest stable version" echo "- 'preview' ; installs latest preview version (defaults to git-master most of the time)" echo "- 'X.Y.Z' ; installs specific version from release package" echo "- 'git-REF' ; install directly from git, where REF is either:" echo " - branch name," echo " - tag," echo " - commit SHA hash." echo "- 'path/to/snoopy-X.Y.Z.tar.gz' ; installs specific pre-downloaded Snoopy release package" echo "- 'download' ; only downloads latest Snoopy release package" } _echo() { echo "SNOOPY_INSTALL: ${1:-}" } _fatalError() { ERR_FILE="$0" ERR_MSG="$1" echo "SNOOPY INSTALL ERROR: $ERR_MSG" 1>&2 exit 1 } ### What to install? # ARG_INSTALL_MODE="${1:-unspecified}" case $ARG_INSTALL_MODE in git-*) SNOOPY_INSTALL_MODE="git-REFERENCE" SNOOPY_SOURCE_TYPE="git" SNOOPY_DOWNLOAD_MODE="git-clone" SNOOPY_GIT_REF_TO_INSTALL=`echo "$ARG_INSTALL_MODE" | sed -e 's/^git-//'` ;; latest-preview|preview|preview-latest) SNOOPY_INSTALL_MODE="git-latest-preview" SNOOPY_SOURCE_TYPE="git" SNOOPY_DOWNLOAD_MODE="git-clone" SNOOPY_GIT_REF_TO_INSTALL="master" ;; latest-stable|stable|stable-latest|latest) SNOOPY_INSTALL_MODE="package-latest-stable" SNOOPY_SOURCE_TYPE="package" SNOOPY_DOWNLOAD_MODE="package-download" SNOOPY_PACKAGE_DOWNLOAD="true" SNOOPY_VERSION_TO_INSTALL="latest" ;; download|download-only) SNOOPY_INSTALL_MODE="download-only" SNOOPY_SOURCE_TYPE="package" SNOOPY_DOWNLOAD_MODE="package-download" SNOOPY_PACKAGE_DOWNLOAD="true" SNOOPY_VERSION_TO_INSTALL="latest" ;; [1-9].[0-9]*.[0-9]*) SNOOPY_INSTALL_MODE="package-specific-version" SNOOPY_SOURCE_TYPE="package" SNOOPY_DOWNLOAD_MODE="package-download" SNOOPY_PACKAGE_DOWNLOAD="true" SNOOPY_VERSION_TO_INSTALL="$ARG_INSTALL_MODE" ;; *) # Check if file name/path has been passed - perform a local install if [[ $ARG_INSTALL_MODE =~ snoopy-[-_.0-9a-zA-Z]+\.tar\.gz$ ]] && [[ -f $ARG_INSTALL_MODE ]]; then SNOOPY_INSTALL_MODE="local-package-file" SNOOPY_SOURCE_TYPE="package" SNOOPY_DOWNLOAD_MODE="package-download" SNOOPY_PACKAGE_DOWNLOAD="false" SNOOPY_PACKAGE_PATH="$ARG_INSTALL_MODE" SNOOPY_VERSION_TO_INSTALL=`basename $SNOOPY_PACKAGE_PATH | sed -e 's/^snoopy-//' | sed -e 's/.tar.gz$//'` else echo echo "SNOOPY INSTALL ERROR: Unknown installation mode." echo _snoopy_install_showHelp echo exit 1 fi ;; esac ### Check if running as root # SNOOPY_INSTALL_RUNNING_AS_ROOT="true" if [ "`id -u`" != "0" ]; then SNOOPY_INSTALL_RUNNING_AS_ROOT="false" echo "SNOOPY INSTALL ERROR: This installation must be run as root." echo "Hint: 'sudo COMMAND' perhaps?" if [ "$SNOOPY_TRAVIS_BUILD" == "true" ]; then echo "SNOOPY INSTALL: Ignoring error above, we are running inside Travis CI." else exit 1 fi fi ### Software check & install functions # # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # _areAllRequiredProgramsPresent() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh REQUIRED_PROGRAMS="$1" ALL_REQUIRED_PROGRAMS_PRESENT="true" for REQUIRED_PROGRAM in $REQUIRED_PROGRAMS; do if ! command -v $REQUIRED_PROGRAM > /dev/null; then ALL_REQUIRED_PROGRAMS_PRESENT="false" _echo "The following program is missing: $REQUIRED_PROGRAM" fi done if [ "$ALL_REQUIRED_PROGRAMS_PRESENT" == "true" ]; then true else false fi } _detectOperatingSystem() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID set to "" # - Global variable OS_VERSION set to "" # # Sets: # - Global variable OS_ID # - Global variable OS_VERSION # # Returns: # - (nothing) OS_ID="" OS_VERSION="" . /etc/os-release OS_ID="$ID" OS_VERSION="${VERSION_ID:-}" # Debian Sid quirk if [[ $OS_ID == "debian" ]] && [[ "$OS_VERSION" == "" ]]; then OS_VERSION="sid" fi } _installPackages() { # NOTICE: Keep this code in sync in the following files: # - dev-tools/install-dev-software.sh # - install/install-snoopy.sh # # Expects: # - Global variable OS_ID # - Global variable OS_VERSION # - Global variable PACKAGE_NAMES_ALPINE # - Global variable PACKAGE_NAMES_ARCH # - Global variable PACKAGE_NAMES_DEBIAN # - Global variable PACKAGE_NAMES_REDHAT # - Global variable PACKAGE_NAMES_SUSE # # Sets: # - (nothing) # # Returns: # - false on error USE_SUDO="sudo -n" MY_UID=`id -u` if [ "$MY_UID" == "0" ]; then USE_SUDO="" fi case "$OS_ID" in alpine) $USE_SUDO apk add $PACKAGE_NAMES_ALPINE ;; arch) $USE_SUDO sudo pacman -Syu --noconfirm $PACKAGE_NAMES_ARCH ;; debian|ubuntu) DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get update -y DEBIAN_FRONTEND="noninteractive" $USE_SUDO apt-get install -y $PACKAGE_NAMES_DEBIAN ;; rhel|centos|almalinux) $USE_SUDO yum install -y $PACKAGE_NAMES_REDHAT ;; sles|opensuse-leap|opensuse-tumbleweed) $USE_SUDO zypper -n install $PACKAGE_NAMES_SUSE ;; *) _fatalError "Unknown OS: '$OS_ID'. Install the following programs manually: $PACKAGE_NAMES_DEBIAN" ;; esac } ### Install distro-dependent build prerequisites, if missing # # Since running a test suite has been removed from this script, # we don't look for 'ps' and 'socat' programs anymore. # # NOTICE: Certain changes here must potentially be reflected # in the ../dev-tools/install-dev-software.sh file too. # # NOTICE: Snoopy releases 2.4.10 and earlier actually _require_ `socat` and `ps` # to be present for the `./configure` step to succeed. Let's keep this here for # some time (at least until >2.4.10 is released). # # PROGRAM_NAMES=" find gcc gzip make ps socat tar wget" PACKAGE_NAMES_ALPINE=" gcc gzip make procps socat tar wget alpine-sdk" PACKAGE_NAMES_ARCH=" gcc gzip make procps socat tar wget" PACKAGE_NAMES_DEBIAN=" gcc gzip make procps socat tar wget" PACKAGE_NAMES_REDHAT=" gcc gzip make procps socat tar wget" PACKAGE_NAMES_SUSE="awk findutils gcc gzip make procps socat tar wget" if [ "$SNOOPY_SOURCE_TYPE" == "git" ]; then PROGRAM_NAMES="autoconf aclocal curl find gcc git gzip hostname libtoolize m4 make ps socat tar wget" PACKAGE_NAMES_ALPINE="autoconf automake curl gcc git gzip libtool m4 make procps socat tar wget alpine-sdk" PACKAGE_NAMES_ARCH="autoconf automake curl gcc git gzip inetutils libtool m4 make procps socat tar wget" PACKAGE_NAMES_DEBIAN="autoconf automake curl gcc git gzip libtool m4 make procps socat tar wget" PACKAGE_NAMES_REDHAT="autoconf automake curl gcc git gzip hostname libtool m4 make procps socat tar wget" PACKAGE_NAMES_SUSE="autoconf automake awk curl findutils gcc git gzip hostname libtool m4 make procps socat tar wget" fi if _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then echo "SNOOPY INSTALL: Required programs already present: $PROGRAM_NAMES" else if [ "$SNOOPY_INSTALL_RUNNING_AS_ROOT" != "true" ]; then _fatalError "Unable to run package installation, not running as root" fi # Detect OS OS_ID="" OS_VERSION="" _detectOperatingSystem if [ "$OS_ID" == "" ]; then _fatalError "Unable to detect your OS via /etc/os-release. Install the following programs manually: $PROGRAM_NAMES" fi _installPackages # Check again if ! _areAllRequiredProgramsPresent "$PROGRAM_NAMES"; then echo "SNOOPY INSTALL ERROR: Even after installing it, the program above cannot be found." echo "SNOOPY INSTALL ERROR: Install it manually and rerun Snoopy installer." exit 1 fi fi ### Start bash subshell, to evaluate potential errors # ( set -e set -u ### Starting installation # rm -f $SNOOPY_INSTALL_LOGFILE touch $SNOOPY_INSTALL_LOGFILE echo "SNOOPY INSTALL: Starting installation, log file: $SNOOPY_INSTALL_LOGFILE" | tee -a $SNOOPY_INSTALL_LOGFILE echo "SNOOPY INSTALL: Installation mode: $SNOOPY_INSTALL_MODE" | tee -a $SNOOPY_INSTALL_LOGFILE ### Obtain source code # if [[ "$SNOOPY_SOURCE_TYPE" == "git" ]] && [[ "$SNOOPY_DOWNLOAD_MODE" == "git-clone" ]]; then echo "SNOOPY INSTALL: Cloning git repository: $SNOOPY_GIT_ORIGIN_URI" | tee -a $SNOOPY_INSTALL_LOGFILE SNOOPY_LOCAL_GIT_DIR="install-snoopy-git-repo" rm -rf ./$SNOOPY_LOCAL_GIT_DIR git clone $SNOOPY_GIT_ORIGIN_URI $SNOOPY_LOCAL_GIT_DIR >> $SNOOPY_INSTALL_LOGFILE 2>&1 cd $SNOOPY_LOCAL_GIT_DIR echo "SNOOPY INSTALL: Checking out git ref: $SNOOPY_GIT_REF_TO_INSTALL" | tee -a $SNOOPY_INSTALL_LOGFILE git checkout $SNOOPY_GIT_REF_TO_INSTALL >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo -n "SNOOPY INSTALL: Bootstraping build environment... " | tee -a $SNOOPY_INSTALL_LOGFILE if [ -x bootstrap.sh ]; then ./bootstrap.sh >> $SNOOPY_INSTALL_LOGFILE 2>&1 elif [ -x autogen.sh ]; then # Run these two first, to avoid errors (git-snoopy-2.2.6 for example) aclocal >> $SNOOPY_INSTALL_LOGFILE 2>&1 automake --add-missing >> $SNOOPY_INSTALL_LOGFILE 2>&1 ./autogen.sh >> $SNOOPY_INSTALL_LOGFILE 2>&1 elif [ -x configure ]; then # Do nothing, ./configure is committed true else echo "SNOOPY INSTALL ERROR: This git ref is too old to be supported by this installation procedure." | tee -a $SNOOPY_INSTALL_LOGFILE echo "SNOOPY INSTALL ERROR: You will have to install it manually." | tee -a $SNOOPY_INSTALL_LOGFILE exit 1 fi echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE elif [[ "$SNOOPY_SOURCE_TYPE" == "package" ]] && [[ "$SNOOPY_DOWNLOAD_MODE" == "package-download" ]]; then ### If 'latest', determine version to install # if [ "$SNOOPY_VERSION_TO_INSTALL" == "latest" ]; then echo -n "SNOOPY INSTALL: Getting latest Snoopy version... " | tee -a $SNOOPY_INSTALL_LOGFILE SNOOPY_VERSION_TO_INSTALL=`wget -q -O - https://raw.githubusercontent.com/a2o/snoopy/master/README.md | grep -E '^## Latest version$' -A10 | grep -E '^[|] +Stable +' | cut -d'|' -f3 | tr -d '[:space:]'` echo "got it, $SNOOPY_VERSION_TO_INSTALL" | tee -a $SNOOPY_INSTALL_LOGFILE else echo -n "SNOOPY INSTALL: Snoopy version to be installed... " | tee -a $SNOOPY_INSTALL_LOGFILE echo "$SNOOPY_VERSION_TO_INSTALL" | tee -a $SNOOPY_INSTALL_LOGFILE fi ### Determine version from local package # if [ "$SNOOPY_PACKAGE_DOWNLOAD" == "false" ]; then SNOOPY_PACKAGE_FILENAME=`basename $SNOOPY_PACKAGE_PATH` else SNOOPY_PACKAGE_FILENAME="snoopy-$SNOOPY_VERSION_TO_INSTALL.tar.gz" fi SNOOPY_PACKAGE_DIRNAME=`echo "$SNOOPY_PACKAGE_FILENAME" | sed -e 's/\.tar.gz$//'` SNOOPY_PACKAGE_VERSION=`echo $SNOOPY_PACKAGE_FILENAME | sed -e 's/^snoopy-//' | sed -e 's/.tar.gz$//'` ### Download Snoopy package # if [ "$SNOOPY_PACKAGE_DOWNLOAD" == "true" ]; then SNOOPY_GITHUB_RELEASE_NAME="snoopy-$SNOOPY_VERSION_TO_INSTALL" SNOOPY_PACKAGE_URI="$SNOOPY_PACKAGE_DOWNLOAD_URI_PREFIX/$SNOOPY_GITHUB_RELEASE_NAME/$SNOOPY_PACKAGE_FILENAME" echo -n "SNOOPY INSTALL: Downloading from $SNOOPY_PACKAGE_URI... " | tee -a $SNOOPY_INSTALL_LOGFILE rm -f $SNOOPY_PACKAGE_FILENAME wget $SNOOPY_PACKAGE_URI >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE SNOOPY_PACKAGE_PATH="./$SNOOPY_PACKAGE_FILENAME" else echo -n "SNOOPY INSTALL: Will install the following local package: " | tee -a $SNOOPY_INSTALL_LOGFILE echo "$SNOOPY_PACKAGE_PATH" | tee -a $SNOOPY_INSTALL_LOGFILE fi ### Exit if in download-only mode # if [ "$SNOOPY_INSTALL_MODE" == "download-only" ]; then echo "SNOOPY INSTALL: Download-only mode detected, exiting." | tee -a $SNOOPY_INSTALL_LOGFILE exit 0 fi ### Untar, build and configure # echo -n "SNOOPY INSTALL: Unpacking $SNOOPY_PACKAGE_PATH... " | tee -a $SNOOPY_INSTALL_LOGFILE rm -rf $SNOOPY_PACKAGE_DIRNAME tar -xzf $SNOOPY_PACKAGE_PATH cd $SNOOPY_PACKAGE_DIRNAME echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE else echo -n "SNOOPY INSTALL ERROR: Internal error - undetermined download method" | tee -a $SNOOPY_INSTALL_LOGFILE exit 1 fi ### ### Configure, build, install, enable ### # Detect travis # if [ "$SNOOPY_TRAVIS_BUILD" == "true" ]; then SNOOPY_INSTALL_CONFIGURE_PREFIX="--prefix=$HOME/usr/local" SNOOPY_INSTALL_CONFIGURE_SYSCONFDIR="--sysconfdir=$HOME/etc" else SNOOPY_INSTALL_CONFIGURE_PREFIX="" SNOOPY_INSTALL_CONFIGURE_SYSCONFDIR="--sysconfdir=/etc" fi # Which configure flag is the right one # if ./configure --help | grep enable-filtering > /dev/null; then SNOOPY_INSTALL_CONFIGURE_FLAG_FILTERING="--enable-filtering" else SNOOPY_INSTALL_CONFIGURE_FLAG_FILTERING="--enable-filter" # Older variation fi echo -n "SNOOPY INSTALL: Configuring... " | tee -a $SNOOPY_INSTALL_LOGFILE ./configure \ --enable-config-file \ $SNOOPY_INSTALL_CONFIGURE_PREFIX \ $SNOOPY_INSTALL_CONFIGURE_SYSCONFDIR \ $SNOOPY_INSTALL_CONFIGURE_FLAG_FILTERING \ >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE echo -n "SNOOPY INSTALL: Building... " | tee -a $SNOOPY_INSTALL_LOGFILE make >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE # Disabled for two reasons: # - domain datasource was causing problems on misconfigured systems # - combined tests are failing if snoopy is already enabled via /etc/ld.so.preload #echo -n "SNOOPY INSTALL: Testing build... " | tee -a $SNOOPY_INSTALL_LOGFILE #make check >> $SNOOPY_INSTALL_LOGFILE 2>&1 #echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE echo -n "SNOOPY INSTALL: Installing... " | tee -a $SNOOPY_INSTALL_LOGFILE make install >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE if [ "$SNOOPY_TRAVIS_BUILD" == "true" ]; then echo "SNOOPY INSTALL: NOT enabling, as we are not running as root (Travis-CI build)." | tee -a $SNOOPY_INSTALL_LOGFILE else echo -n "SNOOPY INSTALL: Enabling... " | tee -a $SNOOPY_INSTALL_LOGFILE make enable >> $SNOOPY_INSTALL_LOGFILE 2>&1 echo "done." | tee -a $SNOOPY_INSTALL_LOGFILE ### Tell the user what to do next # echo echo "Snoopy Command Logger is now installed and enabled." echo echo "TIP #1: If Snoopy is to be enabled for all processes, you need" echo " to restart your system, or at least all services on it." echo echo "TIP #2: If you ever need to disable Snoopy, use the provided" echo " 'snoopyctl disable' command. Use 'snoopyctl enable' to reenable it." echo echo "TIP #3: Snoopy output can usually be found somewhere in /var/log/*" echo " Check your syslog configuration for details." echo echo "TIP #4: Configuration file location: /etc/snoopy.ini" echo " See included comments for additional configuration options." echo echo "Snoopy wishes you a happy logging experience:)" echo fi ### End bash subshell # ) if [ "$?" != "0" ]; then echo echo echo "Last 10 lines of Snoopy installation log file:" tail -n10 $SNOOPY_INSTALL_LOGFILE echo echo "SNOOPY INSTALL ERROR: Something weird happened!" echo "SNOOPY INSTALL ERROR: Please inspect log file for details ($SNOOPY_INSTALL_LOGFILE)" exit 1 fi ### All done # true snoopy-snoopy-2.5.2/lib/000077500000000000000000000000001470651710700151525ustar00rootroot00000000000000snoopy-snoopy-2.5.2/lib/Makefile.am000066400000000000000000000002531470651710700172060ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common SUBDIRS = ### INI file parser # if CONFIGFILE_ENABLED SUBDIRS += inih endif snoopy-snoopy-2.5.2/lib/inih/000077500000000000000000000000001470651710700161015ustar00rootroot00000000000000snoopy-snoopy-2.5.2/lib/inih/IMPORT.defs000066400000000000000000000005021470651710700177530ustar00rootroot00000000000000#!/bin/bash set -e set -u EXTLIB_GIT_REPO_URL="https://github.com/benhoyt/inih.git" EXTLIB_GIT_REF="tags/r55-0-gf7f69c6" _snoopy_extlib_import() { SRCDIR="$1" DESTDIR="$2" cp $SRCDIR/LICENSE.txt $DESTDIR/LICENSE cp $SRCDIR/ini.c $DESTDIR/src/ini.c cp $SRCDIR/ini.h $DESTDIR/src/ini.h } snoopy-snoopy-2.5.2/lib/inih/LICENSE000066400000000000000000000027461470651710700171170ustar00rootroot00000000000000 The "inih" library is distributed under the New BSD license: Copyright (c) 2009, Ben Hoyt All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Ben Hoyt nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY BEN HOYT ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEN HOYT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. snoopy-snoopy-2.5.2/lib/inih/Makefile.am000066400000000000000000000002301470651710700201300ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Subdir processing order # SUBDIRS = SUBDIRS += src snoopy-snoopy-2.5.2/lib/inih/patches/000077500000000000000000000000001470651710700175305ustar00rootroot00000000000000snoopy-snoopy-2.5.2/lib/inih/patches/0001-strip-value-quotes.diff000066400000000000000000000015551470651710700245370ustar00rootroot00000000000000--- src/ini.c.ORIG 2020-11-12 23:40:31.773490733 +0100 +++ src/ini.c 2020-11-12 23:41:06.825555329 +0100 @@ -209,6 +209,17 @@ value = lskip(value); rstrip(value); + /* Strip surrounding double and single quotes */ + if ((*value == '"') && (value[strlen(value) - 1] == '"')) { + value[strlen(value) - 1] = '\0'; + value += 1; + } else { + if ((*value == '\'') && (value[strlen(value) - 1] == '\'')) { + value[strlen(value) - 1] = '\0'; + value += 1; + } + } + /* Valid name[=:]value pair found, call handler */ strncpy0(prev_name, name, sizeof(prev_name)); if (!HANDLER(user, section, name, value) && !error) snoopy-snoopy-2.5.2/lib/inih/patches/0002-prefix-function-names.diff000066400000000000000000000010531470651710700251610ustar00rootroot00000000000000--- src/ini.h.ORIG 2020-11-26 03:37:52.533640594 +0100 +++ src/ini.h 2020-11-26 03:38:43.553738846 +0100 @@ -14,6 +14,13 @@ #ifndef INI_H #define INI_H +/* START For Snoopy - redefine function names, to avoid symbol name collisions */ +#define ini_parse snoopy_ini_parse +#define ini_parse_file snoopy_ini_parse_file +#define ini_parse_stream snoopy_ini_parse_stream +#define ini_parse_string snoopy_ini_parse_string +/* END For Snoopy */ + /* Make this header file easier to include in C++ code */ #ifdef __cplusplus extern "C" { snoopy-snoopy-2.5.2/lib/inih/patches/0003-fix-double-cast.diff000066400000000000000000000005731470651710700237350ustar00rootroot00000000000000--- src/ini.c +++ src/ini.c @@ -100,7 +100,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, /* Uses a fair bit of stack (use heap instead if you need to) */ #if INI_USE_STACK char line[INI_MAX_LINE]; - int max_line = INI_MAX_LINE; + size_t max_line = INI_MAX_LINE; #else char* line; size_t max_line = INI_INITIAL_ALLOC; snoopy-snoopy-2.5.2/lib/inih/src/000077500000000000000000000000001470651710700166705ustar00rootroot00000000000000snoopy-snoopy-2.5.2/lib/inih/src/Makefile.am000066400000000000000000000005471470651710700207320ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Override certain inih defaults # AM_CFLAGS += -DINI_MAX_LINE=1024 -DINI_INITIAL_ALLOC=1024 '-DINI_API=__attribute__((visibility("hidden")))' ### Create library "libinih" # noinst_LTLIBRARIES = \ libinih.la libinih_la_SOURCES = \ ini.c \ ini.h snoopy-snoopy-2.5.2/lib/inih/src/ini.c000066400000000000000000000206301470651710700176140ustar00rootroot00000000000000/* inih -- simple .INI file parser SPDX-License-Identifier: BSD-3-Clause Copyright (C) 2009-2020, Ben Hoyt inih is released under the New BSD license (see LICENSE.txt). Go to the project home page for more info: https://github.com/benhoyt/inih */ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS #endif #include #include #include #include "ini.h" #if !INI_USE_STACK #if INI_CUSTOM_ALLOCATOR #include void* ini_malloc(size_t size); void ini_free(void* ptr); void* ini_realloc(void* ptr, size_t size); #else #include #define ini_malloc malloc #define ini_free free #define ini_realloc realloc #endif #endif #define MAX_SECTION 50 #define MAX_NAME 50 /* Used by ini_parse_string() to keep track of string parsing state. */ typedef struct { const char* ptr; size_t num_left; } ini_parse_string_ctx; /* Strip whitespace chars off end of given string, in place. Return s. */ static char* rstrip(char* s) { char* p = s + strlen(s); while (p > s && isspace((unsigned char)(*--p))) *p = '\0'; return s; } /* Return pointer to first non-whitespace char in given string. */ static char* lskip(const char* s) { while (*s && isspace((unsigned char)(*s))) s++; return (char*)s; } /* Return pointer to first char (of chars) or inline comment in given string, or pointer to NUL at end of string if neither found. Inline comment must be prefixed by a whitespace character to register as a comment. */ static char* find_chars_or_comment(const char* s, const char* chars) { #if INI_ALLOW_INLINE_COMMENTS int was_space = 0; while (*s && (!chars || !strchr(chars, *s)) && !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { was_space = isspace((unsigned char)(*s)); s++; } #else while (*s && (!chars || !strchr(chars, *s))) { s++; } #endif return (char*)s; } /* Similar to strncpy, but ensures dest (size bytes) is NUL-terminated, and doesn't pad with NULs. */ static char* strncpy0(char* dest, const char* src, size_t size) { /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */ size_t i; for (i = 0; i < size - 1 && src[i]; i++) dest[i] = src[i]; dest[i] = '\0'; return dest; } /* See documentation in header file. */ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, void* user) { /* Uses a fair bit of stack (use heap instead if you need to) */ #if INI_USE_STACK char line[INI_MAX_LINE]; size_t max_line = INI_MAX_LINE; #else char* line; size_t max_line = INI_INITIAL_ALLOC; #endif #if INI_ALLOW_REALLOC && !INI_USE_STACK char* new_line; size_t offset; #endif char section[MAX_SECTION] = ""; char prev_name[MAX_NAME] = ""; char* start; char* end; char* name; char* value; int lineno = 0; int error = 0; #if !INI_USE_STACK line = (char*)ini_malloc(INI_INITIAL_ALLOC); if (!line) { return -2; } #endif #if INI_HANDLER_LINENO #define HANDLER(u, s, n, v) handler(u, s, n, v, lineno) #else #define HANDLER(u, s, n, v) handler(u, s, n, v) #endif /* Scan through stream line by line */ while (reader(line, (int)max_line, stream) != NULL) { #if INI_ALLOW_REALLOC && !INI_USE_STACK offset = strlen(line); while (offset == max_line - 1 && line[offset - 1] != '\n') { max_line *= 2; if (max_line > INI_MAX_LINE) max_line = INI_MAX_LINE; new_line = ini_realloc(line, max_line); if (!new_line) { ini_free(line); return -2; } line = new_line; if (reader(line + offset, (int)(max_line - offset), stream) == NULL) break; if (max_line >= INI_MAX_LINE) break; offset += strlen(line + offset); } #endif lineno++; start = line; #if INI_ALLOW_BOM if (lineno == 1 && (unsigned char)start[0] == 0xEF && (unsigned char)start[1] == 0xBB && (unsigned char)start[2] == 0xBF) { start += 3; } #endif start = lskip(rstrip(start)); if (strchr(INI_START_COMMENT_PREFIXES, *start)) { /* Start-of-line comment */ } #if INI_ALLOW_MULTILINE else if (*prev_name && *start && start > line) { /* Non-blank line with leading whitespace, treat as continuation of previous name's value (as per Python configparser). */ if (!HANDLER(user, section, prev_name, start) && !error) error = lineno; } #endif else if (*start == '[') { /* A "[section]" line */ end = find_chars_or_comment(start + 1, "]"); if (*end == ']') { *end = '\0'; strncpy0(section, start + 1, sizeof(section)); *prev_name = '\0'; #if INI_CALL_HANDLER_ON_NEW_SECTION if (!HANDLER(user, section, NULL, NULL) && !error) error = lineno; #endif } else if (!error) { /* No ']' found on section line */ error = lineno; } } else if (*start) { /* Not a comment, must be a name[=:]value pair */ end = find_chars_or_comment(start, "=:"); if (*end == '=' || *end == ':') { *end = '\0'; name = rstrip(start); value = end + 1; #if INI_ALLOW_INLINE_COMMENTS end = find_chars_or_comment(value, NULL); if (*end) *end = '\0'; #endif value = lskip(value); rstrip(value); /* Strip surrounding double and single quotes */ if ((*value == '"') && (value[strlen(value) - 1] == '"')) { value[strlen(value) - 1] = '\0'; value += 1; } else { if ((*value == '\'') && (value[strlen(value) - 1] == '\'')) { value[strlen(value) - 1] = '\0'; value += 1; } } /* Valid name[=:]value pair found, call handler */ strncpy0(prev_name, name, sizeof(prev_name)); if (!HANDLER(user, section, name, value) && !error) error = lineno; } else if (!error) { /* No '=' or ':' found on name[=:]value line */ #if INI_ALLOW_NO_VALUE *end = '\0'; name = rstrip(start); if (!HANDLER(user, section, name, NULL) && !error) error = lineno; #else error = lineno; #endif } } #if INI_STOP_ON_FIRST_ERROR if (error) break; #endif } #if !INI_USE_STACK ini_free(line); #endif return error; } /* See documentation in header file. */ int ini_parse_file(FILE* file, ini_handler handler, void* user) { return ini_parse_stream((ini_reader)fgets, file, handler, user); } /* See documentation in header file. */ int ini_parse(const char* filename, ini_handler handler, void* user) { FILE* file; int error; file = fopen(filename, "r"); if (!file) return -1; error = ini_parse_file(file, handler, user); fclose(file); return error; } /* An ini_reader function to read the next line from a string buffer. This is the fgets() equivalent used by ini_parse_string(). */ static char* ini_reader_string(char* str, int num, void* stream) { ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream; const char* ctx_ptr = ctx->ptr; size_t ctx_num_left = ctx->num_left; char* strp = str; char c; if (ctx_num_left == 0 || num < 2) return NULL; while (num > 1 && ctx_num_left != 0) { c = *ctx_ptr++; ctx_num_left--; *strp++ = c; if (c == '\n') break; num--; } *strp = '\0'; ctx->ptr = ctx_ptr; ctx->num_left = ctx_num_left; return str; } /* See documentation in header file. */ int ini_parse_string(const char* string, ini_handler handler, void* user) { ini_parse_string_ctx ctx; ctx.ptr = string; ctx.num_left = strlen(string); return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler, user); } snoopy-snoopy-2.5.2/lib/inih/src/ini.h000066400000000000000000000137541470651710700176320ustar00rootroot00000000000000/* inih -- simple .INI file parser SPDX-License-Identifier: BSD-3-Clause Copyright (C) 2009-2020, Ben Hoyt inih is released under the New BSD license (see LICENSE.txt). Go to the project home page for more info: https://github.com/benhoyt/inih */ #ifndef INI_H #define INI_H /* START For Snoopy - redefine function names, to avoid symbol name collisions */ #define ini_parse snoopy_ini_parse #define ini_parse_file snoopy_ini_parse_file #define ini_parse_stream snoopy_ini_parse_stream #define ini_parse_string snoopy_ini_parse_string /* END For Snoopy */ /* Make this header file easier to include in C++ code */ #ifdef __cplusplus extern "C" { #endif #include /* Nonzero if ini_handler callback should accept lineno parameter. */ #ifndef INI_HANDLER_LINENO #define INI_HANDLER_LINENO 0 #endif /* Visibility symbols, required for Windows DLLs */ #ifndef INI_API #if defined _WIN32 || defined __CYGWIN__ # ifdef INI_SHARED_LIB # ifdef INI_SHARED_LIB_BUILDING # define INI_API __declspec(dllexport) # else # define INI_API __declspec(dllimport) # endif # else # define INI_API # endif #else # if defined(__GNUC__) && __GNUC__ >= 4 # define INI_API __attribute__ ((visibility ("default"))) # else # define INI_API # endif #endif #endif /* Typedef for prototype of handler function. */ #if INI_HANDLER_LINENO typedef int (*ini_handler)(void* user, const char* section, const char* name, const char* value, int lineno); #else typedef int (*ini_handler)(void* user, const char* section, const char* name, const char* value); #endif /* Typedef for prototype of fgets-style reader function. */ typedef char* (*ini_reader)(char* str, int num, void* stream); /* Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section is "" if name=value pair parsed before any section heading. name:value pairs are also supported as a concession to Python's configparser. For each name=value pair parsed, call handler function with given user pointer as well as section, name, and value (data only valid for duration of handler call). Handler should return nonzero on success, zero on error. Returns 0 on success, line number of first error on parse error (doesn't stop on first error), -1 on file open error, or -2 on memory allocation error (only when INI_USE_STACK is zero). */ INI_API int ini_parse(const char* filename, ini_handler handler, void* user); /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't close the file when it's finished -- the caller must do that. */ INI_API int ini_parse_file(FILE* file, ini_handler handler, void* user); /* Same as ini_parse(), but takes an ini_reader function pointer instead of filename. Used for implementing custom or string-based I/O (see also ini_parse_string). */ INI_API int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, void* user); /* Same as ini_parse(), but takes a zero-terminated string with the INI data instead of a file. Useful for parsing INI data from a network socket or already in memory. */ INI_API int ini_parse_string(const char* string, ini_handler handler, void* user); /* Nonzero to allow multi-line value parsing, in the style of Python's configparser. If allowed, ini_parse() will call the handler with the same name for each subsequent line parsed. */ #ifndef INI_ALLOW_MULTILINE #define INI_ALLOW_MULTILINE 1 #endif /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of the file. See https://github.com/benhoyt/inih/issues/21 */ #ifndef INI_ALLOW_BOM #define INI_ALLOW_BOM 1 #endif /* Chars that begin a start-of-line comment. Per Python configparser, allow both ; and # comments at the start of a line by default. */ #ifndef INI_START_COMMENT_PREFIXES #define INI_START_COMMENT_PREFIXES ";#" #endif /* Nonzero to allow inline comments (with valid inline comment characters specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match Python 3.2+ configparser behaviour. */ #ifndef INI_ALLOW_INLINE_COMMENTS #define INI_ALLOW_INLINE_COMMENTS 1 #endif #ifndef INI_INLINE_COMMENT_PREFIXES #define INI_INLINE_COMMENT_PREFIXES ";" #endif /* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */ #ifndef INI_USE_STACK #define INI_USE_STACK 1 #endif /* Maximum line length for any line in INI file (stack or heap). Note that this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */ #ifndef INI_MAX_LINE #define INI_MAX_LINE 200 #endif /* Nonzero to allow heap line buffer to grow via realloc(), zero for a fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is zero. */ #ifndef INI_ALLOW_REALLOC #define INI_ALLOW_REALLOC 0 #endif /* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK is zero. */ #ifndef INI_INITIAL_ALLOC #define INI_INITIAL_ALLOC 200 #endif /* Stop parsing on first error (default is to keep parsing). */ #ifndef INI_STOP_ON_FIRST_ERROR #define INI_STOP_ON_FIRST_ERROR 0 #endif /* Nonzero to call the handler at the start of each new section (with name and value NULL). Default is to only call the handler on each name=value pair. */ #ifndef INI_CALL_HANDLER_ON_NEW_SECTION #define INI_CALL_HANDLER_ON_NEW_SECTION 0 #endif /* Nonzero to allow a name without a value (no '=' or ':' on the line) and call the handler with value NULL in this case. Default is to treat no-value lines as an error. */ #ifndef INI_ALLOW_NO_VALUE #define INI_ALLOW_NO_VALUE 0 #endif /* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory allocation functions (INI_USE_STACK must also be 0). These functions must have the same signatures as malloc/free/realloc and behave in a similar way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */ #ifndef INI_CUSTOM_ALLOCATOR #define INI_CUSTOM_ALLOCATOR 0 #endif #ifdef __cplusplus } #endif #endif /* INI_H */ snoopy-snoopy-2.5.2/packaging/000077500000000000000000000000001470651710700163305ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/arch/000077500000000000000000000000001470651710700172455ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/arch/PKGBUILD000066400000000000000000000025051470651710700203730ustar00rootroot00000000000000# Maintainer: Bostjan Skufca Jese pkgname="snoopy" pkgver=2.4.15_123_g05fa514_dirty pkgrel=1 pkgdesc="Snoopy Command Logger is a wrapper around execve() that captures all executed commands by all users and all processes and sends the data to syslog." arch=('x86_64') url="https://github.com/a2o/snoopy" license=('GPL') groups=() depends=('glibc') makedepends=( "autoconf" "automake" "diffutils" "file" "gcc" "git" "libtool" "m4" "make" ) checkdepends=( "inetutils" "procps" "socat" ) backup=( "etc/snoopy.ini" ) options=() install="packaging/arch/snoopy.install" changelog=ChangeLog pkgver() { cd $startdir ./dev-tools/libexec/get-release-version.sh | sed -e 's/-/_/g' } prepare() { cd $startdir if [ ! -f configure ]; then ./bootstrap.sh fi } build() { cd $startdir # On Arch, we need to "reroute" /usr/sbin/snoopyctl to /usr/bin/snoopyctl, # since /usr/sbin is a symlink to /usr/bin. # If we don't do this, we get the "conflicting files" error because of # the usr/sbin being an actual directory in the .pkg.tar.zst package. ./configure --prefix=/usr --sysconfdir=/etc --sbindir=/usr/bin make -j4 } check() { cd $startdir make -j4 check } package() { cd $startdir make DESTDIR="$pkgdir/" install } snoopy-snoopy-2.5.2/packaging/arch/env000066400000000000000000000002551470651710700177620ustar00rootroot00000000000000# # Environment variables, consumed by dev-tools/build-package-arch.sh # if [ "${PACKAGER:-}" == "" ]; then export PACKAGER="Bostjan Skufca Jese " fi snoopy-snoopy-2.5.2/packaging/arch/snoopy.install000066400000000000000000000001421470651710700221610ustar00rootroot00000000000000post_install() { /usr/bin/snoopyctl enable } pre_remove() { /usr/bin/snoopyctl disable } snoopy-snoopy-2.5.2/packaging/deb/000077500000000000000000000000001470651710700170625ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/deb/README.Build.md000066400000000000000000000002551470651710700214010ustar00rootroot00000000000000# Snoopy Command Logger - DEB packaging Consult the [packaging/deb/README.md](README.md) file in Snoopy's Git repository for up-to-date .deb package building instructions. snoopy-snoopy-2.5.2/packaging/deb/README.Debian000066400000000000000000000030271470651710700211250ustar00rootroot00000000000000Snoopy Command Logger ===================== Log format is: [login:%{login} ssh:(%{env:SSH_CONNECTION}) sid:%{sid} tty:%{tty} (%{tty_uid}/%{tty_username}) uid:%{username}(%{uid})/%{eusername}(%{euid}) gid:%{group}(%{gid})/%{egroup}(%{egid}) cwd:%{cwd}]: %{cmdline} With: - login: literal login name of logged-in user executing this process. Retrive the user login trying in order: - The login information from the processus. - the LOGNAME environment variable. - the SUDO_USER environment variable. return "unknown" otherwise. TIP to use with sudo and keep LOGNAME, add this in /etc/sudoers: Defaults env_reset Defaults env_keep="LOGNAME" - ssh: value of SSH_CONNECTION. - sid: Session leader process ID of current process. - tty: TTY of current process. - tty_uid: UID (User ID) of current controlling terminal, or -1 if not found. - tty_username: litaral username of current controlling terminal. - username: literal username of current process/ - uid: UID (User ID) of current process. - eusername: literal effective user name (User ID) of current process/ - euid: effective UID of current process. - group: literal group name (Group ID) of current process. - gid: GID (Group ID) number of currently running process. - egroup: literal effective group name (Group ID) of current process. - egid: effective UID of current process. - cwd: current working directory of current process. - cmdline: command line of current process. -- Sébastien Gross , Mon, 20 Oct 2014 01:56:35 +0200 snoopy-snoopy-2.5.2/packaging/deb/README.md000066400000000000000000000013641470651710700203450ustar00rootroot00000000000000# Snoopy Command Logger - DEB packaging ## Info The provided [packaging/debian](.) directory is not configured to be used directly, nor in a standalone fashion. It only works when used within this Git repository, and with the provided tooling. ## How to build a DEB package Steps: - Clone this Git repository onto a supported system, - Install the required development and packaging tools, and - Use the package building script. To clone this repository: ``` git clone https://github.com/a2o/snoopy cd snoopy ``` To install the required software (this only needs to be done once): ```bash ./dev-tools/install-dev-software.sh ./dev-tools/install-packaging-software.sh ``` To build a DEB package: ```bash ./dev-tools/build-package-deb.sh ``` Done. snoopy-snoopy-2.5.2/packaging/deb/changelog.TEMPLATE000066400000000000000000000015541470651710700221530ustar00rootroot00000000000000snoopy (DEB_PACKAGE_VERSION) unstable; urgency=medium * NOTICE: This is not a real changelog. * This .deb package has been provided by Snoopy maintainers. * Snoopy's git repository is the actual changelog for this package, at https://github.com/a2o/snoopy/. * NOTICE: While the intent of Snoopy maintainers is to keep their .deb packages in sync and interchangeable with distribution-provided Snoopy packages, the packaging efforts are not synchronized and thus incompatible differences may occur. * NOTICE: To build the .deb package yourself, use the provided ./dev-tools/build-package-deb.sh helper script. * NOTICE: To install the required software for building the .deb package, use the provided ./dev-tools/install-packaging-software.sh helper script. -- Bostjan Skufca Jese Sat, 06 Aug 2022 00:00:00 +0000 snoopy-snoopy-2.5.2/packaging/deb/compat000066400000000000000000000000031470651710700202610ustar00rootroot0000000000000010 snoopy-snoopy-2.5.2/packaging/deb/control000066400000000000000000000021221470651710700204620ustar00rootroot00000000000000Source: snoopy Section: admin Priority: optional Maintainer: Bostjan Skufca Jese Build-Depends: debhelper (>= 11.1), autoconf (>=2.69), dh-autoreconf, procps, socat Standards-Version: 4.6.1.0 Homepage: https://github.com/a2o/snoopy Vcs-Git: https://github.com/a2o/snoopy.git Vcs-Browser: https://github.com/a2o/snoopy Rules-Requires-Root: no Package: snoopy Architecture: linux-any Depends: ${shlibs:Depends}, ${misc:Depends} Conflicts: libsnoopy Replaces: libsnoopy Description: Snoopy Command Logger is a wrapper around execve() that captures all executed commands by all users and all processes and sends the data to syslog. Snoopy Command Logger is a shared library that interposes itself between dynamic executables and libc's execve() function. Once loaded, programs' calls to execve() are intercepted and logged. System administrators may find Snoopy Command Logger useful in tasks such as system diagnostics, tracking other administrators' actions as well as getting a good 'feel' of what's going on on their system (i.e. what CGI scripts are being launched by Apache). snoopy-snoopy-2.5.2/packaging/deb/copyright000066400000000000000000000063741470651710700210270ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: snoopy Source: https://github.com/a2o/snoopy Files: * Copyright: 2000-2010 Marius Aamodt Eriksen , Mike Baker 2010-2022 Bostjan Skufca Jese License: GPL-2+ Files: lib/inih/* Copyright: 2009 Ben Hoyt License: BSD-3-clause Files: packaging/deb/* Copyright: 2022 Bostjan Skufca Jese 2011 Sébastien Gross 2017-2021 Marcos Fouces 2018 SZ Lin (林上智) 2017 Raphaël Hertzog 2017 Lukas Schwaighofer 2011-2012,2015,2017 Zed Pobre 2008 Christian Perrier 2002-2008 Marc Haber 2001 Aubin Paul , License: GPL-2+ License: GPL-2+ 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 Street, Fifth Floor, Boston, MA 02110-1301, USA. . On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2 file. License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3) Neither the name of the ORGANIZATION nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. snoopy-snoopy-2.5.2/packaging/deb/extra-files/000077500000000000000000000000001470651710700213055ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/deb/extra-files/snapd-apparmor-profile000066400000000000000000000015251470651710700256150ustar00rootroot00000000000000# # Ubuntu Snap AppArmor profile additions by Snoopy Command Logger # # Snoopy installation from .deb currently does not reload apparmor profiles. # You will either need to do that manually, or reboot the whole system. # # Additionally, once "inside" snap, Snoopy is unable to read /etc/snoopy.ini # on the host's filesystem, which makes it revert back to the built-in default # configuration. # /lib/x86_64-linux-gnu/libsnoopy.so* mr, /etc/snoopy.ini r, /dev/pts/ r, /proc/*/loginuid r, /proc/[0-9]+/status r, /usr/lib/x86_64-linux-gnu/libnss_compat-*.so mr, /usr/lib/x86_64-linux-gnu/libnss_nis-*.so mr, /usr/lib/x86_64-linux-gnu/libnsl-*.so mr, unix (create, connect, send) type=dgram, unix (create, connect, send) type=stream, /dev/log w, /run/systemd/journal/dev-log w, /var/log/snoopy.log w, snoopy-snoopy-2.5.2/packaging/deb/rules000077500000000000000000000020351470651710700201420ustar00rootroot00000000000000#!/usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) OS_ID = $(shell cat /etc/os-release | grep ^ID= | cut -d= -f2) %: dh $@ override_dh_auto_configure: dh_auto_configure -- \ --prefix=/usr \ --libdir=/lib/$(DEB_HOST_MULTIARCH) \ --sysconfdir=/etc \ --with-message-format='[login:%{login} ssh:(%{env:SSH_CONNECTION}) sid:%{sid} tty:%{tty} (%{tty_uid}/%{tty_username}) uid:%{username}(%{uid})/%{eusername}(%{euid}) cwd:%{cwd}]: %{cmdline}' override_dh_auto_install: dh_auto_install find debian/ -name "*.la" -delete @if [ "$(OS_ID)" = "ubuntu" ] ; then \ mkdir -p debian/snoopy/var/lib/snapd/apparmor/snap-confine ; \ cp debian/extra-files/snapd-apparmor-profile debian/snoopy/var/lib/snapd/apparmor/snap-confine/snoopy ; \ fi override_dh_clean: dh_clean find . -name Makefile.in -exec rm {} \+ rm -f aclocal.m4 compile configure test-drive override_dh_missing: dh_missing --fail-missing snoopy-snoopy-2.5.2/packaging/deb/snoopy.config000066400000000000000000000003041470651710700215750ustar00rootroot00000000000000#!/bin/sh set -e PRELOAD="/etc/ld.so.preload" LIBNAME="libsnoopy.so" . /usr/share/debconf/confmodule [ -n "$SNOOPYDEBUG" ] && set -x db_input critical snoopy/install-ld-preload || true db_go snoopy-snoopy-2.5.2/packaging/deb/snoopy.docs000066400000000000000000000000121470651710700212540ustar00rootroot00000000000000README.md snoopy-snoopy-2.5.2/packaging/deb/snoopy.lintian-overrides000066400000000000000000000004011470651710700237640ustar00rootroot00000000000000# This package is not a library intended to build executables against # nor to be linked by any application. snoopy: link-to-shared-library-in-wrong-package snoopy: package-name-doesnt-match-sonames snoopy: no-symbols-control-file lib/*/libsnoopy.so.0.0.0 snoopy-snoopy-2.5.2/packaging/deb/snoopy.postinst000077500000000000000000000006131470651710700222210ustar00rootroot00000000000000#!/bin/sh set -e . /usr/share/debconf/confmodule case "$1" in configure) db_get snoopy/install-ld-preload if [ x"$RET" = x"true" ] ; then /usr/sbin/snoopyctl enable fi ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac #DEBHELPER# exit 0 snoopy-snoopy-2.5.2/packaging/deb/snoopy.prerm000077500000000000000000000003731470651710700214660ustar00rootroot00000000000000#!/bin/sh set -e case "$1" in remove|upgrade|deconfigure) /usr/sbin/snoopyctl disable ;; failed-upgrade) ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac #DEBHELPER# exit 0 snoopy-snoopy-2.5.2/packaging/deb/source.lintian-overrides000066400000000000000000000002231470651710700237370ustar00rootroot00000000000000snoopy source: native-package-with-dash-version snoopy source: maintainer-address-malformed Sébastien Gross snoopy-snoopy-2.5.2/packaging/deb/source/000077500000000000000000000000001470651710700203625ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/deb/source/format000066400000000000000000000000121470651710700215660ustar00rootroot000000000000003.0 (git) snoopy-snoopy-2.5.2/packaging/deb/templates000066400000000000000000000004671470651710700210120ustar00rootroot00000000000000Template: snoopy/install-ld-preload Type: boolean Default: false Description: Install Snoopy library to /etc/ld.so.preload? Snoopy is a library that can only reliably do its work if it is mandatorily preloaded via /etc/ld.so.preload. Since this can potentially do harm to the system, your consent is needed. snoopy-snoopy-2.5.2/packaging/rpm/000077500000000000000000000000001470651710700171265ustar00rootroot00000000000000snoopy-snoopy-2.5.2/packaging/rpm/README.md000066400000000000000000000013641470651710700204110ustar00rootroot00000000000000# Snoopy Command Logger - RPM packaging ## Info The provided [snoopy.spec](snoopy.spec) file is not configured to be used directly, nor in a standalone fashion. It only works when used within this Git repository, and with the provided tooling. ## How to build a RPM package Steps: - Clone this Git repository onto a supported system, - Install the required development and packaging tools, and - Use the package building script. To clone this repository: ``` git clone https://github.com/a2o/snoopy cd snoopy ``` To install the required software (this only needs to be done once): ```bash ./dev-tools/install-dev-software.sh ./dev-tools/install-packaging-software.sh ``` To build a RPM package: ```bash ./dev-tools/build-package-rpm.sh ``` Done. snoopy-snoopy-2.5.2/packaging/rpm/snoopy.spec000066400000000000000000000047231470651710700213370ustar00rootroot00000000000000# # Snoopy Command Logger - RPM builds # # This file is designed to work from within Snoopy's git repository working directory. # It should not be invoked directly. Rather, use the following script to build a .rpm # package: # # ./dev-tools/build-package-rpm.sh # Name: snoopy Version: %snoopy_rpm_package_version Release: %snoopy_rpm_release_tag Summary: Snoopy Command Logger is a wrapper around execve() that captures all executed commands by all users and all processes and sends the data to syslog. License: GPLv2+ URL: https://github.com/a2o/snoopy Packager: Bostjan Skufca Jese BuildRequires: automake BuildRequires: libtool BuildRequires: gcc BuildRequires: make # For tests BuildRequires: %{_bindir}/hostname BuildRequires: %{_bindir}/ps BuildRequires: %{_bindir}/socat %description Snoopy Command Logger is a shared library that interposes itself between dynamic executables and libc's execve() function. Once loaded, programs' calls to execve() are intercepted and logged. System administrators may find Snoopy Command Logger useful in tasks such as system diagnostics, tracking other administrators' actions as well as getting a good 'feel' of what's going on on their system (i.e. what CGI scripts are being launched by Apache). %build %configure %make_build check %install %make_install rm %{buildroot}%{_libdir}/libsnoopy.la %files %doc ../../../README.md %doc ../../../ChangeLog %doc ../../../COPYING %license ../../../COPYING %{_libdir}/* %{_sbindir}/* %{_sysconfdir}/* %config(noreplace) %{_sysconfdir}/snoopy.ini %post /usr/sbin/snoopyctl enable %preun /usr/sbin/snoopyctl disable %changelog * Sat Aug 6 2022 Bostjan Skufca Jese %snoopy_rpm_package_version - NOTICE: This is not a real changelog. - This .rpm package has been provided by Snoopy maintainers. - Snoopy's git repository is the actual changelog for this package, at https://github.com/a2o/snoopy/. - NOTICE: While the intent of Snoopy maintainers is to keep their .rpm packages in sync and interchangeable with distribution-provided Snoopy packages, the packaging efforts are not synchronized and thus incompatible differences may occur. - NOTICE: To build the .rpm package yourself, use the provided ./dev-tools/build-package-rpm.sh helper script. - NOTICE: To install the required software for building the .rpm package, use the provided ./dev-tools/install-packaging-software.sh helper script. snoopy-snoopy-2.5.2/src/000077500000000000000000000000001470651710700151735ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/Makefile.am000066400000000000000000000043661470651710700172400ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Subdir processing order # # `util` subdir must be the first to get processed, as `cli` depends on it SUBDIRS = SUBDIRS += util SUBDIRS += action SUBDIRS += cli SUBDIRS += entrypoint SUBDIRS += datasource if FILTERING_ENABLED SUBDIRS += filter endif SUBDIRS += output ### Create the main library, but without an entrypoint (i.e. execve() wrapper) # noinst_LTLIBRARIES = \ libsnoopy-no-entrypoint.la libsnoopy_no_entrypoint_la_SOURCES = \ configuration.c \ configuration.h \ error.c \ error.h \ genericregistry.c \ genericregistry.h \ init-deinit.c \ init-deinit.h \ inputdatastorage.c \ inputdatastorage.h \ datasourceregistry.c \ datasourceregistry.h \ message.c \ message.h \ outputregistry.c \ outputregistry.h \ snoopy.h libsnoopy_no_entrypoint_la_LDFLAGS = $(AM_LDFLAGS) libsnoopy_no_entrypoint_la_LIBADD = \ action/libsnoopy-actions-all.la \ datasource/libsnoopy_datasources_all.la \ output/libsnoopy_outputs_all.la \ util/libsnoopy-utils.la # If config file is enabled, build and link these too if CONFIGFILE_ENABLED libsnoopy_no_entrypoint_la_SOURCES += \ configfile.c \ configfile.h libsnoopy_no_entrypoint_la_LIBADD += \ ../lib/inih/src/libinih.la endif # If thread safety is enabled, build and link these too if THREAD_SAFETY_ENABLED libsnoopy_no_entrypoint_la_SOURCES += \ tsrm.c \ tsrm.h libsnoopy_no_entrypoint_la_LDFLAGS += -lpthread endif # If filtering is enabled, add these too if FILTERING_ENABLED libsnoopy_no_entrypoint_la_SOURCES += \ filtering.c \ filtering.h \ filterregistry.c \ filterregistry.h libsnoopy_no_entrypoint_la_LIBADD += \ filter/libsnoopy_filters_all.la endif ### Create the main library # lib_LTLIBRARIES = libsnoopy.la libsnoopy_la_SOURCES = libsnoopy_la_LIBADD = \ libsnoopy-no-entrypoint.la \ entrypoint/libsnoopy-entrypoint-execve-wrapper.la \ entrypoint/libsnoopy-entrypoint-cli.la ### Create a library to be included in `snoopy-test` CLI utility # noinst_LTLIBRARIES += libsnoopy-test-cli.la libsnoopy_test_cli_la_SOURCES = libsnoopy_test_cli_la_LIBADD = \ libsnoopy-no-entrypoint.la \ cli/libsnoopy-cli-subroutines.la \ entrypoint/libsnoopy-entrypoint-test-cli.la snoopy-snoopy-2.5.2/src/action/000077500000000000000000000000001470651710700164505ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/action/Makefile.am000066400000000000000000000005411470651710700205040ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Temporary library to build # noinst_LTLIBRARIES = libsnoopy-actions-all.la libsnoopy_actions_all_la_SOURCES = \ log-message-dispatch.c \ log-message-dispatch.h \ log-syscall-exec.c \ log-syscall-exec.h libsnoopy_actions_all_la_LDFLAGS = snoopy-snoopy-2.5.2/src/action/log-message-dispatch.c000066400000000000000000000030031470651710700226100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2014 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "log-message-dispatch.h" #include "snoopy.h" #include "outputregistry.h" #include #include #include /* * snoopy_action_log_message_dispatch * * Description: * Dispatch given message to configured output * * Params: * logMessage: message to dispatch * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_action_log_message_dispatch (const char *logMessage) { /* Dispatch only if non-zero size */ if (0 == strlen(logMessage)) { return SNOOPY_OUTPUT_GRACEFUL_DISCARD; } // Dispatch to configured output return snoopy_outputregistry_dispatch(logMessage); } snoopy-snoopy-2.5.2/src/action/log-message-dispatch.h000066400000000000000000000016111470651710700226200ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2014 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Log message dispatching action */ int snoopy_action_log_message_dispatch (const char *logMessage); snoopy-snoopy-2.5.2/src/action/log-syscall-exec.c000066400000000000000000000042541470651710700217740ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: log.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "log-syscall-exec.h" #include "log-message-dispatch.h" #include "snoopy.h" #include "configuration.h" #if defined(SNOOPY_FILTERING_ENABLED) #include "filtering.h" #endif #include "message.h" #include "outputregistry.h" #include #include #include /* * snoopy_action_log_syscall_exec * * Description: * Common routine that does execv(e)() logging * * Return: * void */ void snoopy_action_log_syscall_exec () { const snoopy_configuration_t * CFG; char *logMessage = NULL; /* Get config pointer */ CFG = snoopy_configuration_get(); #if defined(SNOOPY_FILTERING_ENABLED) /* Should message be passed to syslog or not? */ if ( (SNOOPY_TRUE == CFG->filtering_enabled) && (SNOOPY_FILTER_DROP == snoopy_filtering_check_chain(CFG->filter_chain)) ) { return; } #endif /* Initialize empty log message */ logMessage = malloc(CFG->log_message_max_length+1); logMessage[0] = '\0'; /* Generate log message in specified format */ snoopy_message_generateFromFormat(logMessage, CFG->log_message_max_length+1, CFG->datasource_message_max_length+1, CFG->message_format); /* Dispatch the message to configured output */ snoopy_action_log_message_dispatch(logMessage); /* Housekeeping */ free(logMessage); } snoopy-snoopy-2.5.2/src/action/log-syscall-exec.h000066400000000000000000000015311470651710700217740ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: log.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ void snoopy_action_log_syscall_exec (); snoopy-snoopy-2.5.2/src/cli/000077500000000000000000000000001470651710700157425ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/cli/Makefile.am000066400000000000000000000013721470651710700200010ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Variables to add final targets to # noinst_LTLIBRARIES = sbin_PROGRAMS = ### Build subroutines separately, it gets linked into `snoopy-test` too # noinst_LTLIBRARIES += libsnoopy-cli-subroutines.la libsnoopy_cli_subroutines_la_SOURCES = \ cli-subroutines.c \ cli-subroutines.h ### Program-based entry points # sbin_PROGRAMS += snoopyctl snoopyctl_SOURCES = \ action-conf.c \ action-conf.h \ action-disable.c \ action-disable.h \ action-enable.c \ action-enable.h \ action-status.c \ action-status.h \ action-version.c \ action-version.h \ snoopyctl.c snoopyctl_LDADD = \ libsnoopy-cli-subroutines.la \ ../util/libsnoopy-utils.la snoopy-snoopy-2.5.2/src/cli/action-conf.c000066400000000000000000000057521470651710700203170ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-conf.h" #include "cli-subroutines.h" #include "configfile.h" #include "configuration.h" #include #include #include #include #include int snoopy_cli_action_conf () { void (* snoopy_entrypoint_cli_init_ptr) (); void (* snoopy_entrypoint_cli_exit_ptr) (); snoopy_configuration_t * (* snoopy_configuration_get_ptr) (); snoopy_configfile_option_t * (* snoopy_configfile_optionRegistry_getAll_ptr) (); char * (* snoopy_configfile_optionRegistry_getOptionValueAsString_ptr) (char const * const optionName); snoopy_configuration_t * CFG; const snoopy_configfile_option_t * optionRegistry; // Load the library libsnoopySo_load(); // Find function pointers *(void **) (&snoopy_entrypoint_cli_init_ptr) = libsnoopySo_dlsym("snoopy_entrypoint_cli_init"); *(void **) (&snoopy_entrypoint_cli_exit_ptr) = libsnoopySo_dlsym("snoopy_entrypoint_cli_exit"); *(void **) (&snoopy_configuration_get_ptr) = libsnoopySo_dlsym("snoopy_configuration_get"); *(void **) (&snoopy_configfile_optionRegistry_getAll_ptr) = libsnoopySo_dlsym("snoopy_configfile_optionRegistry_getAll"); *(void **) (&snoopy_configfile_optionRegistry_getOptionValueAsString_ptr) = libsnoopySo_dlsym("snoopy_configfile_optionRegistry_getOptionValueAsString"); snoopy_entrypoint_cli_init_ptr(); // Get the configuration CFG = snoopy_configuration_get_ptr(); printf("; Options from config file (or defaults): %s\n", CFG->configfile_path); printf("[snoopy]\n"); // Print the configured options optionRegistry = snoopy_configfile_optionRegistry_getAll_ptr(); for (int i=0 ; 0 != strcmp(optionRegistry[i].name, "") ; i++) { char * optionValue = snoopy_configfile_optionRegistry_getOptionValueAsString_ptr(optionRegistry[i].name); printf("%s = %s\n", optionRegistry[i].name, optionValue); free(optionValue); } // Cleanup snoopy_entrypoint_cli_exit_ptr(); return 0; } snoopy-snoopy-2.5.2/src/cli/action-conf.h000066400000000000000000000014761470651710700203230ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_cli_action_conf (); snoopy-snoopy-2.5.2/src/cli/action-disable.c000066400000000000000000000106361470651710700207720ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-disable.h" #include "cli-subroutines.h" #include "snoopy.h" #include "util/string-snoopy.h" #include #include #include #include int snoopy_cli_action_disable () { const char * libsnoopySoPath; char * curEtcLdSoPreloadContent = 0; char * newEtcLdSoPreloadContent = 0; size_t newEtcLdSoPreloadContentLengthMax; unsigned int copyLength; const char * entryPtr = NULL; char * entryLine = NULL; const char * srcPosPtr = 0; char * destPosPtr = 0; const char * foundStringPos1 = NULL; const char * foundStringPos2 = NULL; // Get the file we're working with (prod or test) libsnoopySoPath = libsnoopySo_getFilePathNoCheck(); // Read current /etc/ld.so.preload content curEtcLdSoPreloadContent = etcLdSoPreload_readFile(); // Check for duplicate active libsnoopy.so foundStringPos1 = etcLdSoPreload_findNonCommentLineContainingString(curEtcLdSoPreloadContent, SNOOPY_SO_LIBRARY_NAME); if (foundStringPos1 != NULL) { foundStringPos2 = etcLdSoPreload_findNonCommentLineContainingString(foundStringPos1 + snoopy_util_string_getLineLength(foundStringPos1), SNOOPY_SO_LIBRARY_NAME); if (foundStringPos2 != NULL) { printDiagValue("Search string", SNOOPY_SO_LIBRARY_NAME); printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); fatalError("Duplicate libsnoopy.so entry encountered"); } } // Check if OUR Snoopy is already disabled entryPtr = etcLdSoPreload_findEntry(curEtcLdSoPreloadContent, libsnoopySoPath); if (entryPtr == NULL) { free(curEtcLdSoPreloadContent); printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("libsnoopy.so path", libsnoopySoPath); printNotice("Snoopy library is already absent from the ld.so.preload file."); return 0; } newEtcLdSoPreloadContentLengthMax = strlen(curEtcLdSoPreloadContent); newEtcLdSoPreloadContent = malloc(newEtcLdSoPreloadContentLengthMax+1); // +1 for terminating \0 newEtcLdSoPreloadContent[0] = '\0'; // Copy the initial part destPosPtr = newEtcLdSoPreloadContent; srcPosPtr = curEtcLdSoPreloadContent; copyLength = (unsigned int) (entryPtr - srcPosPtr); strncpy(destPosPtr, srcPosPtr, copyLength); // Skip the entry line we're removing, copy the rest destPosPtr = newEtcLdSoPreloadContent + copyLength; entryLine = snoopy_util_string_copyLineFromContent(entryPtr); srcPosPtr = entryPtr + strlen(entryLine); copyLength = (unsigned int) (strlen(curEtcLdSoPreloadContent) - (entryPtr - curEtcLdSoPreloadContent) - strlen(entryLine)); if (*srcPosPtr == '\n') { srcPosPtr++; copyLength--; } strncpy(destPosPtr, srcPosPtr, copyLength); destPosPtr += copyLength; *destPosPtr = '\0'; // Store new content etcLdSoPreload_writeFile(newEtcLdSoPreloadContent); printMessage("[SUCCESS] Snoopy has been removed from /etc/ld.so.preload."); printInfo("Existing processes may still have Snoopy enabled until they are restarted."); // Check if ANOTHER Snoopy instance is present if (etcLdSoPreload_findNonCommentLineContainingString(newEtcLdSoPreloadContent, SNOOPY_SO_LIBRARY_NAME) != NULL) { printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("Search string", SNOOPY_SO_LIBRARY_NAME); printWarning("Another Snoopy instance found in ld.so.preload file."); } free(curEtcLdSoPreloadContent); free(newEtcLdSoPreloadContent); free(entryLine); return 0; } snoopy-snoopy-2.5.2/src/cli/action-disable.h000066400000000000000000000015011470651710700207660ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_cli_action_disable (); snoopy-snoopy-2.5.2/src/cli/action-enable.c000066400000000000000000000121611470651710700206100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-enable.h" #include "cli-subroutines.h" #include "snoopy.h" #include #include #include #include int snoopy_cli_action_enable () { const char * libsnoopySoPath; char * curEtcLdSoPreloadContent = 0; char * newEtcLdSoPreloadContent = 0; size_t newEtcLdSoPreloadContentLength; size_t newEtcLdSoPreloadContentLengthBuf; char * strPosPtr = 0; // Get file we're working with (prod or test) libsnoopySoPath = libsnoopySo_getFilePath(); // Make sure the target SO library file exists and is readable if (access(libsnoopySoPath, F_OK) != 0) { printDiagValue("libsnoopy.so path", libsnoopySoPath); fatalError("File not found"); } if (access(libsnoopySoPath, R_OK) != 0) { printDiagValue("libsnoopy.so path", libsnoopySoPath); fatalError("File not readable"); } // Read current /etc/ld.so.preload content curEtcLdSoPreloadContent = etcLdSoPreload_readFile(); // Check if OUR Snoopy is already enabled if (etcLdSoPreload_findEntry(curEtcLdSoPreloadContent, libsnoopySoPath)) { free(curEtcLdSoPreloadContent); printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("Search string", libsnoopySoPath); printNotice("Snoopy is already enabled in /etc/ld.so.preload."); return 0; } // Check if ANOTHER Snoopy instance is already enabled if (etcLdSoPreload_findNonCommentLineContainingString(curEtcLdSoPreloadContent, SNOOPY_SO_LIBRARY_NAME) != NULL) { printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("Search string", SNOOPY_SO_LIBRARY_NAME); fatalError("Another Snoopy instance encountered."); } // Prepare the new content newEtcLdSoPreloadContentLength = strlen(curEtcLdSoPreloadContent) + strlen(libsnoopySoPath) + 2; // 2 = first (potential) newline (if the orig content doesn't contain the final newline) + last newline newEtcLdSoPreloadContentLengthBuf = newEtcLdSoPreloadContentLength + 1; // +1 for the final \0 newEtcLdSoPreloadContent = malloc(newEtcLdSoPreloadContentLengthBuf); /* * If the following line is missing, GCC throws the following error: * * error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] * * The added code is bogus, as the final \0 is added at the end of this code section anyway. */ newEtcLdSoPreloadContent[newEtcLdSoPreloadContentLength] = '\0'; // Copy the existing content (and add a newline at the end if missing) if (strlen(curEtcLdSoPreloadContent) == 0) { strPosPtr = newEtcLdSoPreloadContent; } else { strncpy(newEtcLdSoPreloadContent, curEtcLdSoPreloadContent, newEtcLdSoPreloadContentLengthBuf); strPosPtr = newEtcLdSoPreloadContent + strlen(curEtcLdSoPreloadContent)-1; // -1 Moves the pointer from the last \0 character to the penultimate one if (*strPosPtr != '\n') { strPosPtr++; *strPosPtr = '\n'; } strPosPtr++; } // Add our entry + the final newline /* * For the following `strncpy` call we had originally this implementation: * * strncpy(strPosPtr, libsnoopySoPath, strlen(libsnoopySoPath)+1); * * However, GCC (v9+, maybe even v8+) complains: * * error: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] * * Reworking the statement to the current version makes the warning go away, * despite having the exactly same effect (length of target buffer is calculated * from the length of the source buffer anyway). */ strncpy(strPosPtr, libsnoopySoPath, newEtcLdSoPreloadContentLengthBuf-(strPosPtr-newEtcLdSoPreloadContent)); strPosPtr += strlen(libsnoopySoPath); *strPosPtr = '\n'; strPosPtr++; *strPosPtr = '\0'; // Store new content etcLdSoPreload_writeFile(newEtcLdSoPreloadContent); printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("Snoopy library path", libsnoopySoPath); printMessage("SUCCESS: Snoopy has been enabled."); free(curEtcLdSoPreloadContent); free(newEtcLdSoPreloadContent); return 0; } snoopy-snoopy-2.5.2/src/cli/action-enable.h000066400000000000000000000015001470651710700206100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_cli_action_enable (); snoopy-snoopy-2.5.2/src/cli/action-status.c000066400000000000000000000127101470651710700207050ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #define _GNU_SOURCE // For RTDL_NEXT & dladdr() #include "action-status.h" #include "cli-subroutines.h" #include "snoopy.h" #include "util/string-snoopy.h" #include #include #include #include #include #ifndef RTLD_DEFAULT # define RTLD_DEFAULT ((void *) 0) #endif typedef struct { int libcPos; int libsnoopyPos; } solibsOrderT; static int dl_iterate_phdr_callback (struct dl_phdr_info *i, size_t size, void *data) { static int callCount = 0; solibsOrderT * solibsOrder; const char * strPos; solibsOrder = (solibsOrderT *) data; callCount++; const char * libsnoopyFileName = "/libsnoopy.so"; strPos = strstr(i->dlpi_name, libsnoopyFileName); if ((strPos != NULL) && (strPos[strlen(libsnoopyFileName)] == '\0')) { solibsOrder->libsnoopyPos = callCount; } const char * libcFileName = "/libc.so.6"; strPos = strstr(i->dlpi_name, libcFileName); if ((strPos != NULL) && (strPos[strlen(libcFileName)] == '\0')) { solibsOrder->libcPos = callCount; } return 0; } int snoopy_cli_action_status () { const char * libsnoopySoPath = NULL; char * etcLdSoPreloadContent = NULL; const char * linePtr = NULL; const char * entryPtr = NULL; // Get the file we're working with (prod or test) libsnoopySoPath = libsnoopySo_getFilePath(); // Check /etc/ld.so.preload etcLdSoPreloadContent = etcLdSoPreload_readFile(); linePtr = etcLdSoPreload_findNonCommentLineContainingString(etcLdSoPreloadContent, SNOOPY_SO_LIBRARY_NAME); if (linePtr == NULL) { printMessage("/etc/ld.so.preload: NOT OK - Snoopy is not enabled."); } else { // Check for multiple concurrently-enabled libsnoopy.so instances linePtr += snoopy_util_string_getLineLength(linePtr); linePtr = etcLdSoPreload_findNonCommentLineContainingString(linePtr, SNOOPY_SO_LIBRARY_NAME); if (linePtr != NULL) { printDiagValue("ld.so.preload path", g_etcLdSoPreloadPath); printDiagValue("Search string", SNOOPY_SO_LIBRARY_NAME); fatalError("Multiple Snoopy references found, aborting."); } // Check for the right Snoopy instance entryPtr = etcLdSoPreload_findEntry(etcLdSoPreloadContent, libsnoopySoPath); if (entryPtr == NULL) { printMessage("/etc/ld.so.preload: NOT OK - 'libsnoopy.so' found, but not with the expected path - is another Snoopy instance enabled?"); } else { printMessage("/etc/ld.so.preload: OK - Snoopy is enabled."); } } free(etcLdSoPreloadContent); // Check LD_PRELOAD environment variable? const char * envValue = NULL; envValue = getenv("LD_PRELOAD"); if (envValue == NULL) { printMessage("LD_PRELOAD environment var: NOT OK - Not set."); } else { if (strstr(envValue, SNOOPY_SO_LIBRARY_NAME) != NULL) { printMessage("LD_PRELOAD environment var: OK - Snoopy reference found."); } else { printMessage("LD_PRELOAD environment var: NOT SET - Set, but no Snoopy reference found."); } } // Check the order of shared libraries solibsOrderT solibsOrder = { .libcPos = 0, .libsnoopyPos = 0 }; dl_iterate_phdr(dl_iterate_phdr_callback, &solibsOrder); if (solibsOrder.libcPos == 0) { printWarning("Current process (shared libs): Unable to find libc.so.6"); } else if (solibsOrder.libsnoopyPos == 0) { printMessage("Current process (shared libs): NOT OK - Unable to find libsnoopy.so."); } else { if (solibsOrder.libsnoopyPos < solibsOrder.libcPos) { printMessage("Current process (shared libs): OK - libsnoopy.so is loaded in front of libc.so.6."); } else { printMessage("Current process (shared libs): NOT OK - libsnoopy.so is loaded _after_ libc.so.6."); } } // Check the current running process' `execve` address typedef int (*execveAddrT) (); execveAddrT execveAddrLibc; execveAddrT execveAddrCur; const char * libcPath = "libc.so.6"; void *libcHandle = dlopen(libcPath, RTLD_LAZY); *(void **) (&execveAddrCur) = dlsym(RTLD_DEFAULT, "execve"); *(void **) (&execveAddrLibc) = dlsym(libcHandle, "execve"); if (execveAddrLibc == execveAddrCur) { printMessage("Current process (execve addr): NOT OK - execve() symbol not overloaded, Snoopy is not loaded."); } else { printMessage("Current process (execve addr): OK - execve() symbol address changed, looks like Snoopy is loaded."); } dlclose(libcHandle); return 0; } snoopy-snoopy-2.5.2/src/cli/action-status.h000066400000000000000000000015001470651710700207050ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_cli_action_status (); snoopy-snoopy-2.5.2/src/cli/action-version.c000066400000000000000000000033441470651710700210520ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-version.h" #include "cli-subroutines.h" #include "snoopy.h" #include #include #include int snoopy_cli_action_version () { int (* snoopy_ds_version_ptr) (char * const resultBuf, size_t resultBufSize, char const * const arg); char ds_message_buf[255] = ""; int ds_status; // Load the library libsnoopySo_load(); // Find the desired datasource (that returns Snoopy version) *(void **) (&snoopy_ds_version_ptr) = libsnoopySo_dlsym("snoopy_datasource_snoopy_version"); // Call the function ds_status = snoopy_ds_version_ptr(ds_message_buf, 255, ""); if (SNOOPY_DATASOURCE_FAILED(ds_status)) { fatalError("Snoopy version datasource failed"); } printf("Snoopy CLI tool version: %s\n", SNOOPY_VERSION); printf("Snoopy library version: %s (path: %s)\n", ds_message_buf, g_libsnoopySoPath); return 0; } snoopy-snoopy-2.5.2/src/cli/action-version.h000066400000000000000000000015011470651710700210500ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_cli_action_version (); snoopy-snoopy-2.5.2/src/cli/cli-subroutines.c000066400000000000000000000234231470651710700212410ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "cli-subroutines.h" #include "snoopy.h" #include #include #include #include #include #include #include const char * g_etcLdSoPreloadPath; const char * g_libsnoopySoPath; void * g_libsnoopySoHandle; void printMessage (const char * const message) { printf("%s\n", message); } void printDiag (const char * const message) { printf("[DIAG] %s\n", message); } void printDiagValue (const char * const message, const char * const value) { printf("[DIAG] %s: '%s'\n", message, value); } void printInfo (const char * const message) { printf("[INFO] %s\n", message); } void printInfoValue (const char * const message, const char * const value) { printf("[INFO] %s: %s\n", message, value); } void printNotice (const char * const message) { printf("[NOTICE] %s\n", message); } void printNoticeValue (const char * const message, const char * const value) { printf("[NOTICE] %s: %s\n", message, value); } void printSuccess (const char * const message) { printf("[SUCCESS] %s\n", message); } void printWarning (const char * const message) { fprintf(stderr, "[WARNING] %s\n", message); } void printWarningValue (const char * const message, const char * const value) { fprintf(stderr, "[WARNING] %s: %s\n", message, value); } void printError (const char * const message) { fprintf(stderr, "[ERROR] %s\n", message); } void printErrorValue (const char * const message, const char * const value) { fprintf(stderr, "[ERROR] %s: %s\n", message, value); } __attribute__((noreturn)) void fatalError (const char * const message) { printError(message); exit(127); } __attribute__((noreturn)) void fatalErrorValue (const char * const message, const char * const value) { printErrorValue(message, value); exit(127); } __attribute__((noreturn)) void fatalErrorValueFree (const char * const message, char * const value) { printErrorValue(message, value); free(value); exit(127); } char * libsnoopySo_getFilePath () { char * filePath; filePath = libsnoopySo_getFilePathNoCheck(); if (access(filePath, R_OK) != 0) { printDiagValue("libsnoopy.so path", filePath); fatalError("Unable to access libsnoopy.so file"); } return filePath; } char * libsnoopySo_getFilePathNoCheck () { char * filePath; char * envValue; envValue = getenv("SNOOPY_TEST_LIBSNOOPY_SO_PATH"); if (envValue != NULL) { printWarningValue("Using non-default path to libsnoopy.so", envValue); filePath = envValue; } else { filePath = SNOOPY_SO_LIBRARY_PATH; } return filePath; } void libsnoopySo_load () { g_libsnoopySoPath = libsnoopySo_getFilePath(); // Load the library g_libsnoopySoHandle = dlopen(g_libsnoopySoPath, RTLD_LAZY); if (!g_libsnoopySoHandle) { printErrorValue("Dynamic linker error message", dlerror()); fatalError("Unable to load shared library"); } dlerror(); /* Clear any existing error */ } void * libsnoopySo_dlsym (char const * const functionName) { void * functionPtr; const char * error; functionPtr = dlsym(g_libsnoopySoHandle, functionName); error = dlerror(); if (error != NULL) { printDiagValue("libsnoopy.so path", g_libsnoopySoPath); fatalError(error); } return functionPtr; } const char * etcLdSoPreload_getFilePath () { const char * envValue = NULL; envValue = getenv("SNOOPY_TEST_LD_SO_PRELOAD_PATH"); if (envValue != NULL) { printWarningValue("Using non-standard path to ld.so.preload", envValue); return envValue; } else { return SNOOPY_ETC_LD_SO_PRELOAD_PATH; } } char * etcLdSoPreload_readFile () { const char * filePath; int fileContentLen; char * fileContentBuf = 0; filePath = etcLdSoPreload_getFilePath(); FILE * fileHandle = fopen(filePath, "r"); if (fileHandle == NULL) { if (errno == ENOENT) { // For now, handle a non-existing file as an empty one fileContentBuf = malloc(1); fileContentBuf[0] = '\0'; return fileContentBuf; } else { printDiagValue("ld.so.preload path", filePath); printDiagValue("Error message", strerror(errno)); fatalError("Unable to read ld.so.preload file."); } } if (fseek(fileHandle, 0, SEEK_END) != 0) { printDiagValue("ld.so.preload path", filePath); printDiagValue("function called", "fseek(fh, 0, SEEK_END)"); printDiagValue("Error message", strerror(errno)); fatalError("Unable to determine the size of the ld.so.preload file."); } fileContentLen = (int) ftell(fileHandle); if (fileContentLen == -1) { printDiagValue("ld.so.preload path", filePath); printDiagValue("function called", "ftell(fh)"); printDiagValue("Error message", strerror(errno)); fatalError("Unable to determine the size of the ld.so.preload file."); } fseek(fileHandle, 0, SEEK_SET); fileContentBuf = malloc(fileContentLen+1); if (fileContentBuf == NULL) { printDiagValue("ld.so.preload path", filePath); printDiagValue("Error message", strerror(errno)); fatalError("Unable to malloc() for reading the file content."); } if (fileContentLen == 0) { fileContentBuf[0] = '\0'; } else { long freadRes = fread(fileContentBuf, 1, fileContentLen, fileHandle); if (freadRes < fileContentLen) { fileContentBuf[freadRes] = '\0'; printDiagValue("ld.so.preload path", filePath); fatalError("Unable to read the whole content of the file."); } else { fileContentBuf[fileContentLen] = '\0'; } } fclose(fileHandle); g_etcLdSoPreloadPath = filePath; return fileContentBuf; } void etcLdSoPreload_writeFile (char * newContent) { const char * filePath; filePath = etcLdSoPreload_getFilePath(); FILE * fileHandle = fopen(filePath, "w+"); if (fileHandle == NULL) { printDiagValue("ld.so.preload path", filePath); printDiagValue("Error message", strerror(errno)); fatalError("Unable to open file for writing (missing sudo, maybe?)."); } if (fprintf(fileHandle, "%s", newContent) < 0) { printDiagValue("ld.so.preload path", filePath); printDiagValue("Error message", strerror(errno)); fatalError("Unable to write to file."); } fclose(fileHandle); } const char * etcLdSoPreload_findEntry (const char * content, const char * entry) { const char * contentPos = NULL; const char * entryPos = NULL; contentPos = content; while ((entryPos = strstr(contentPos, entry)) != NULL) { // Check the start of the line if ( ( // Start of the content (entryPos == content) || // The preceding character is a newline ((entryPos > content) && (entryPos[-1] == '\n')) ) && ( // End of content (entryPos[strlen(entry)] == '\0') || // Next character is a newline (entryPos[strlen(entry)] == '\n') || // Next character is a hash (start of a comment) (entryPos[strlen(entry)] == '#') || // Next character is a space (potentially followed by more space and/or a comment - a bit naive assumption, but hey!) (entryPos[strlen(entry)] == ' ') || // Next character is a tab (potentially followed by more tabs and/or a comment - a bit naive assumption, but hey!) (entryPos[strlen(entry)] == '\t') ) ) { return entryPos; } contentPos = entryPos + strlen(entry); } return NULL; } const char * etcLdSoPreload_findNonCommentLineContainingString (const char * content, const char * searchString) { const char * contentPos = NULL; const char * foundStringPos = NULL; const char * lineStartPtr = NULL; contentPos = content; while ((foundStringPos = strstr(contentPos, searchString)) != NULL) { // Search in reverse for a newline character, or start of the buffer for ( lineStartPtr = foundStringPos; (lineStartPtr > contentPos) && (*lineStartPtr != '\n'); lineStartPtr-- ); if (*lineStartPtr == '\n') { lineStartPtr++; } if (*lineStartPtr != '#') { // This is not a commented-out line, therefore a valid search string has been found return lineStartPtr; } // If the found search string above is in a commented-out line, continue the search from where we left off contentPos = foundStringPos + strlen(searchString); } return NULL; } snoopy-snoopy-2.5.2/src/cli/cli-subroutines.h000066400000000000000000000045751470651710700212550ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ void printMessage (const char * const message); void printDiag (const char * const message); void printDiagValue (const char * const message, const char * const value); void printInfo (const char * const message); void printInfoValue (const char * const message, const char * const value); void printNotice (const char * const message); void printNoticeValue (const char * const message, const char * const value); void printSuccess (const char * const message); void printWarning (const char * const message); void printWarningValue (const char * const message, const char * const value); void printError (const char * const message); void printErrorValue (const char * const message, const char * const value); void fatalError (const char * const message); void fatalErrorValue (const char * const message, const char * const value); void fatalErrorValueFree(const char * const message, char * const value); char * libsnoopySo_getFilePath (); char * libsnoopySo_getFilePathNoCheck (); void libsnoopySo_load (); void * libsnoopySo_dlsym (char const * const); const char * etcLdSoPreload_getFilePath (); char * etcLdSoPreload_readFile (); void etcLdSoPreload_writeFile (char * newContent); const char * etcLdSoPreload_findNonCommentLineContainingString (const char * content, const char * searchString); const char * etcLdSoPreload_findEntry (const char * content, const char * entry); extern const char * g_etcLdSoPreloadPath; extern const char * g_libsnoopySoPath; extern void * g_libsnoopySoHandle; snoopy-snoopy-2.5.2/src/cli/snoopyctl.c000066400000000000000000000062131470651710700201420ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2020 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #ifdef SNOOPY_CONFIGFILE_ENABLED #include "action-conf.h" #endif #include "action-disable.h" #include "action-enable.h" #include "action-status.h" #include "action-version.h" #include "cli-subroutines.h" #include #include #include void showAbout () { char * aboutContent = "Snoopy is a small library that logs all program executions on your Linux/BSD system (a.k.a. Snoopy Command Logger).\n" "The command line utility that you've just used to display this message is Snoopy's CLI management tool.\n" "\n" "More information about Snoopy is available at the following URL:\n" " https://github.com/a2o/snoopy/\n" "\n"; printf("%s", aboutContent); } void showHelp () { char * helpContent = "Snoopy CLI management tool usage:\n" " snoopyctl ACTION [ARGS]\n" "\n" "Available actions:\n" #ifdef SNOOPY_CONFIGFILE_ENABLED " conf Show configuration\n" #endif " disable Remove libsnoopy.so from /etc/ld.so.preload\n" " enable Add libsnoopy.so to /etc/ld.so.preload\n" " status Detect whether Snoopy is already enabled and loaded\n" "\n" " version Show Snoopy version\n" " about Show general information\n" " help Show this help\n" "\n"; printf("%s", helpContent); } int main (int argc, char *argv[]) { if (argc < 2) { showHelp(); fatalError("No action specified."); } if (0 == strcmp(argv[1], "status")) { return snoopy_cli_action_status(); #ifdef SNOOPY_CONFIGFILE_ENABLED } else if (0 == strcmp(argv[1], "conf")) { return snoopy_cli_action_conf(); #endif } else if (0 == strcmp(argv[1], "disable")) { return snoopy_cli_action_disable(); } else if (0 == strcmp(argv[1], "enable")) { return snoopy_cli_action_enable(); } else if (0 == strcmp(argv[1], "version")) { return snoopy_cli_action_version(); } else if (0 == strcmp(argv[1], "about")) { showAbout(); return 0; } else if (0 == strcmp(argv[1], "help")) { showHelp(); return 0; } else { showHelp(); fatalErrorValue("Unknown action", argv[1]); } } snoopy-snoopy-2.5.2/src/configfile.c000066400000000000000000000502571470651710700174550ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: configfile.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "configfile.h" #include "snoopy.h" #include "configuration.h" #include "outputregistry.h" #include "util/parser-snoopy.h" #include "util/string-snoopy.h" #include "util/syslog-snoopy.h" #include "lib/inih/src/ini.h" #ifndef _XOPEN_SOURCE // For strdup #define _XOPEN_SOURCE 500 #endif #include #include #include #include #include #include /* * Local defines */ #define SNOOPY_CONFIGFILE_OPTION_NOT_SUPPORTED -1 #define SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS 1 #define SNOOPY_CONFIGFILE_PARSEVALUE_ERROR 0 /* * Define supported config options */ snoopy_configfile_option_t snoopy_configfile_optionRegistry[] = { { "error_logging", { SNOOPY_CONFIGFILE_OPTION_TYPE_BOOL, &snoopy_configfile_parseValue_error_logging, &snoopy_configfile_getOptionValueAsString_error_logging } }, #ifdef SNOOPY_FILTERING_ENABLED { "filter_chain", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_filter_chain, &snoopy_configfile_getOptionValueAsString_filter_chain } }, #endif { "message_format", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_message_format, &snoopy_configfile_getOptionValueAsString_message_format } }, { "output", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_output, &snoopy_configfile_getOptionValueAsString_output } }, { "syslog_facility", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_facility, &snoopy_configfile_getOptionValueAsString_syslog_facility } }, { "syslog_ident", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_ident, &snoopy_configfile_getOptionValueAsString_syslog_ident } }, { "syslog_level", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_level, &snoopy_configfile_getOptionValueAsString_syslog_level } }, { "datasource_message_max_length", { SNOOPY_CONFIGFILE_OPTION_TYPE_INT, &snoopy_configfile_parseValue_datasource_message_max_length, &snoopy_configfile_getOptionValueAsString_datasource_message_max_length } }, { "log_message_max_length", { SNOOPY_CONFIGFILE_OPTION_TYPE_INT, &snoopy_configfile_parseValue_log_message_max_length, &snoopy_configfile_getOptionValueAsString_log_message_max_length } }, { "", { SNOOPY_CONFIGFILE_OPTION_TYPE_NONE, NULL, NULL } }, }; /* * snoopy_configfile_load_file * * Description: * Parses INI configuration file and overrides Snoopy * configuration with changed values. * * Params: * file Path log INI configuration file * * Return: * int 0 on success, -1 on error openinf file, other int for other errors */ int snoopy_configfile_load ( char *iniFilePath ) { int iniParseStatus; snoopy_configuration_t *CFG; /* Get config pointer */ CFG = snoopy_configuration_get(); /* Tell Snoopy we are using configuration file */ CFG->configfile_path = iniFilePath; /* Parse the INI configuration file first */ iniParseStatus = ini_parse(iniFilePath, snoopy_configfile_iniParser_callback, CFG); if (0 != iniParseStatus) { return -1; } CFG->configfile_found = SNOOPY_TRUE; /* Housekeeping */ CFG->configfile_parsed = SNOOPY_TRUE; // We have successfully parsed configuration file return 0; } /* * snoopy_configfile_parser_callback * * Description: * Callback function for each found ini value in parsed config file. * * Params: * ... * * Return: * ... */ int snoopy_configfile_iniParser_callback ( void* sth, const char* section, const char* name, const char* confValString ) { /* Qualify pointer? */ snoopy_configuration_t* CFG = (snoopy_configuration_t*)sth; /* Skip unknown sections */ if (0 != strcmp(section, "snoopy")) { return 1; } /* Handle a (supported) option */ int optionId = snoopy_configfile_optionRegistry_getIdFromName(name); if (optionId != SNOOPY_CONFIGFILE_OPTION_NOT_SUPPORTED) { return snoopy_configfile_optionRegistry[optionId].data.valueParserPtr(confValString, CFG); } /* Why are we returning 1 instead of zero everywhere? */ return 1; } /* * Parse 'error_logging' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_error_logging ( const char *confValString, snoopy_configuration_t* CFG ) { int confValInt = snoopy_configfile_getboolean(confValString, -1); if (-1 != confValInt) { CFG->error_logging_enabled = confValInt; } return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_error_logging () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); if (CFG->error_logging_enabled == SNOOPY_TRUE) { return strdup("yes"); } else { return strdup("no"); } } #ifdef SNOOPY_FILTERING_ENABLED /* * Parse 'filter_chain' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_filter_chain ( const char *confValString, snoopy_configuration_t* CFG ) { CFG->filter_chain = strdup(confValString); CFG->filter_chain_malloced = SNOOPY_TRUE; return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_filter_chain () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); return strdup(CFG->filter_chain); } #endif /* * Parse 'message_format' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_message_format ( const char *confValString, snoopy_configuration_t* CFG ) { CFG->message_format = strdup(confValString); CFG->message_format_malloced = SNOOPY_TRUE; return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_message_format () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); return strdup(CFG->message_format); } /* * Parse 'output' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_output ( const char *confValString, snoopy_configuration_t* CFG ) { char *confVal; const char * outputName; const char * outputArg; int outputArgFound = SNOOPY_FALSE; // Do not assign null to it explicitly, as you get "Explicit null dereference" Coverity error. // If you do not assign it, Coverity complains with "Uninitialized pointer read". char *saveptr1 = ""; // First clone the config value, as it gets freed by ini parsing library confVal = strdup(confValString); // Check if configured value contains argument(s) if (NULL == strchr(confVal, ':')) { outputName = confVal; CFG->output_arg = ""; CFG->output_arg_malloced = SNOOPY_FALSE; outputArg = ""; } else { // Separate output name from its arguments // (arguments may contain further ':' characters, like "file:/var/log/snoopy-%{datetime:%Y-%m-%d}") outputName = strtok_r(confVal, ":", &saveptr1); outputArg = outputName + strlen(outputName) + 1; outputArgFound = SNOOPY_TRUE; } // Determine output name if (SNOOPY_TRUE == snoopy_outputregistry_doesNameExist(outputName)) { CFG->output = strdup(outputName); CFG->output_malloced = SNOOPY_TRUE; if (SNOOPY_TRUE == outputArgFound) { // THINK What if conf.output_arg was set in previous call to this function, // and is already malloced? We need to detect that and free previous // allocation. CFG->output_arg = strdup(outputArg); CFG->output_arg_malloced = SNOOPY_TRUE; } } else { CFG->output = SNOOPY_OUTPUT_DEFAULT; CFG->output_malloced = SNOOPY_FALSE; CFG->output_arg = SNOOPY_OUTPUT_DEFAULT_ARG; CFG->output_arg_malloced = SNOOPY_FALSE; } // Housekeeping free(confVal); return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_output () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); char * outputString = NULL; if (0 == strcmp("", CFG->output_arg)) { outputString = strdup(CFG->output); } else { size_t outputStringBufSize = strlen(CFG->output) + 1 + strlen(CFG->output_arg) + 1; // First +1 for ':', second +1 for '\0' outputString = malloc(outputStringBufSize); snprintf(outputString, outputStringBufSize, "%s:%s", CFG->output, CFG->output_arg); outputString[outputStringBufSize-1] = '\0'; } return outputString; } /* * Parse 'syslog_facility' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_syslog_facility ( const char *confValString, snoopy_configuration_t* CFG ) { char *confVal; const char *confValCleaned; int facilityInt; // Duplicate the ini value, as we need to modify it confVal = strdup(confValString); // First cleanup the value confValCleaned = snoopy_configfile_syslog_value_cleanup(confVal); // Evaluate and set configuration flag facilityInt = snoopy_util_syslog_convertFacilityToInt(confValCleaned); if (-1 == facilityInt) { CFG->syslog_facility = SNOOPY_SYSLOG_FACILITY; } else { CFG->syslog_facility = facilityInt; } /* Housekeeping */ free(confVal); return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_syslog_facility () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); return strdup(snoopy_util_syslog_convertFacilityToStr(CFG->syslog_facility)); } /* * Parse 'syslog_ident' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_syslog_ident ( const char *confValString, snoopy_configuration_t* CFG ) { CFG->syslog_ident_format = strdup(confValString); CFG->syslog_ident_format_malloced = SNOOPY_TRUE; return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_syslog_ident () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); return strdup(CFG->syslog_ident_format); } /* * Parse 'syslog_level' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_syslog_level ( const char *confValString, snoopy_configuration_t* CFG ) { char *confVal; const char *confValCleaned; int levelInt; // Duplicate the ini value, as we need to modify it confVal = strdup(confValString); // First cleanup the value confValCleaned = snoopy_configfile_syslog_value_cleanup(confVal); // Evaluate and set configuration flag levelInt = snoopy_util_syslog_convertLevelToInt(confValCleaned); if (-1 == levelInt) { CFG->syslog_level = SNOOPY_SYSLOG_LEVEL; } else { CFG->syslog_level = levelInt; } /* Housekeeping */ free(confVal); return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_syslog_level () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); return strdup(snoopy_util_syslog_convertLevelToStr(CFG->syslog_level)); } /* * snoopy_configfile_syslog_value_cleanup * * Description: * Convert existing string to upper case, and remove LOG_ prefix * * Params: * confVal Pointer to string to change and to be operated on * * Return: * char * Pointer to cleaned string (either the same as initial argument, * or 4 characters advanced, to remove LOG_ prefix */ char *snoopy_configfile_syslog_value_cleanup (char *confVal) { char *confValCleaned; // Convert to upper case snoopy_util_string_toUpper(confVal); // Remove LOG_ prefix confValCleaned = snoopy_configfile_syslog_value_remove_prefix(confVal); return confValCleaned; } /* * snoopy_configfile_syslog_value_remove_prefix * * Description: * Remove the LOG_ prefix, return pointer to new string (either equal * or +4 chars advanced) * * Params: * string Pointer to string to remove LOG_ prefix * * Return: * char * Pointer to non LOG_ part of the string */ char *snoopy_configfile_syslog_value_remove_prefix (char *confVal) { if (0 == strncmp(confVal, "LOG_", 4)) { return confVal+4; } else { return confVal; } } /*-------------------------------------------------------------------------*/ /** @origin Literally copy-pasted from ndevilla's iniparser @brief Get the string associated to a key, convert to a boolean @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return integer This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. A true boolean is found if one of the following is matched: - A string starting with 'y' - A string starting with 'Y' - A string starting with 't' - A string starting with 'T' - A string starting with '1' A false boolean is found if one of the following is matched: - A string starting with 'n' - A string starting with 'N' - A string starting with 'f' - A string starting with 'F' - A string starting with '0' The notfound value returned if no boolean is identified, does not necessarily have to be 0 or 1. */ /*--------------------------------------------------------------------------*/ int snoopy_configfile_getboolean (const char *c, int notfound) { int ret; if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { ret = SNOOPY_TRUE; } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { ret = SNOOPY_FALSE; } else { ret = notfound ; } return ret; } /* * Parse 'datasource_message_max_length' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_datasource_message_max_length ( const char *confValString, snoopy_configuration_t* CFG ) { CFG->datasource_message_max_length = snoopy_util_parser_strByteLength( confValString, SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMIN, SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMAX, SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_DEFAULT ); return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } /* * Parse 'log_message_max_length' config option * * Params: * confValString: Value from configuration file * CFG: Snoopy configuration struct * * Return: * int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or * SNOOPY_CONFIGFILE_PARSEVALUE_ERROR */ int snoopy_configfile_parseValue_log_message_max_length ( const char *confValString, snoopy_configuration_t* CFG ) { CFG->log_message_max_length = snoopy_util_parser_strByteLength( confValString, SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMIN, SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMAX, SNOOPY_LOG_MESSAGE_MAX_LENGTH_DEFAULT ); return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS; } char * snoopy_configfile_getOptionValueAsString_datasource_message_max_length () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); size_t strBufSize = sizeof(CFG->datasource_message_max_length)*8 + 1; char * strBuf = malloc(strBufSize); snprintf(strBuf, strBufSize, "%zu", CFG->datasource_message_max_length); return strBuf; } char * snoopy_configfile_getOptionValueAsString_log_message_max_length () { const snoopy_configuration_t * CFG = snoopy_configuration_get(); size_t strBufSize = sizeof(CFG->log_message_max_length)*8 + 1; char * strBuf = malloc(strBufSize); snprintf(strBuf, strBufSize, "%zu", CFG->log_message_max_length); return strBuf; } /* * optionRegistry :: getIdFromName() * * Return: * int: Id of a given option, or * SNOOPY_CONFIGFILE_OPTION_NOT_SUPPORTED (-1) when not found. */ int snoopy_configfile_optionRegistry_getIdFromName (char const * const optionName) { for (int i=0 ; 0 != strcmp(snoopy_configfile_optionRegistry[i].name, "") ; i++) { if (strcmp(snoopy_configfile_optionRegistry[i].name, optionName) == 0) { return i; } } /* Not found */ return SNOOPY_CONFIGFILE_OPTION_NOT_SUPPORTED; } /* * optionRegistry :: getAll() * * Returns all supported config options. */ __attribute__((visibility("default"))) snoopy_configfile_option_t * snoopy_configfile_optionRegistry_getAll () { return snoopy_configfile_optionRegistry; } /* * optionRegistry :: getOptionValueAsString() * * Returns a malloc()-ed string representation of option value (that can be (re)used in a config file). */ __attribute__((visibility("default"))) char * snoopy_configfile_optionRegistry_getOptionValueAsString (char const * const optionName) { for (int i=0 ; 0 != strcmp(snoopy_configfile_optionRegistry[i].name, "") ; i++) { if (strcmp(snoopy_configfile_optionRegistry[i].name, optionName) == 0) { return snoopy_configfile_optionRegistry[i].data.getValueAsStringPtr(); } } return NULL; // Option not found } snoopy-snoopy-2.5.2/src/configfile.h000066400000000000000000000077511470651710700174630ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: configfile.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "snoopy.h" #include "configuration.h" #define SNOOPY_CONFIGFILE_OPTION_TYPE_BOOL 1 #define SNOOPY_CONFIGFILE_OPTION_TYPE_STRING 2 #define SNOOPY_CONFIGFILE_OPTION_TYPE_INT 3 #define SNOOPY_CONFIGFILE_OPTION_TYPE_NONE 0 // Reserved for internal use /* Config file data types */ typedef struct { int type; int (*valueParserPtr) (char const * const confValString, snoopy_configuration_t *CFG); char * (*getValueAsStringPtr) (); } snoopy_configfile_optionData_t; typedef struct { char const * const name; snoopy_configfile_optionData_t data; } snoopy_configfile_option_t; /* Config file loading/parsing */ int snoopy_configfile_load (char *iniFilePath); int snoopy_configfile_iniParser_callback ( void* sth, const char* section, const char* name, const char* confValString ); int snoopy_configfile_parseValue_error_logging (const char *confValString, snoopy_configuration_t* CFG); #ifdef SNOOPY_FILTERING_ENABLED int snoopy_configfile_parseValue_filter_chain (const char *confValString, snoopy_configuration_t* CFG); #endif int snoopy_configfile_parseValue_message_format (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_output (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_syslog_facility (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_syslog_ident (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_syslog_level (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_datasource_message_max_length (const char *confValString, snoopy_configuration_t* CFG); int snoopy_configfile_parseValue_log_message_max_length (const char *confValString, snoopy_configuration_t* CFG); char * snoopy_configfile_getOptionValueAsString_error_logging (); #ifdef SNOOPY_FILTERING_ENABLED char * snoopy_configfile_getOptionValueAsString_filter_chain (); #endif char * snoopy_configfile_getOptionValueAsString_message_format (); char * snoopy_configfile_getOptionValueAsString_output (); char * snoopy_configfile_getOptionValueAsString_syslog_facility (); char * snoopy_configfile_getOptionValueAsString_syslog_ident (); char * snoopy_configfile_getOptionValueAsString_syslog_level (); char * snoopy_configfile_getOptionValueAsString_datasource_message_max_length (); char * snoopy_configfile_getOptionValueAsString_log_message_max_length (); /* Internal cleanup/conversion methods */ char *snoopy_configfile_syslog_value_cleanup (char *confVal); char *snoopy_configfile_syslog_value_remove_prefix (char *confVal); int snoopy_configfile_getboolean (const char *c, int notfound); /* Config option registry */ int snoopy_configfile_optionRegistry_getIdFromName (char const * const itemName); snoopy_configfile_option_t * snoopy_configfile_optionRegistry_getAll (); char * snoopy_configfile_optionRegistry_getOptionValueAsString (char const * const configOptionName); snoopy-snoopy-2.5.2/src/configuration.c000066400000000000000000000254441470651710700202170ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: configuration.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "configuration.h" #include "snoopy.h" #ifdef SNOOPY_CONFIGFILE_ENABLED #include "configfile.h" #endif #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #include "tsrm.h" #endif #include #include #include #include #include #include #include /* * Flag that enables/disables configuration file parsing * * This is a runtime flag, used by binaries in tests/bin/ directory. * ./configure flags are wrapped around this. */ int snoopy_configuration_configFileParsingEnabled = SNOOPY_TRUE; /* * Should alternate configuration file be loaded? */ char * snoopy_configuration_altConfigFilePath = NULL; char snoopy_configuration_altConfigFilePathBuf[PATH_MAX] = ""; /* * Storage of Snoopy configuration for non-thread-safe builds */ #ifndef SNOOPY_CONF_THREAD_SAFETY_ENABLED snoopy_configuration_t snoopy_configuration_data = { .initialized = SNOOPY_FALSE, }; #endif /* * snoopy_configuration_preinit_disableConfigFileParsing * * Description: * Disables configuration file parsing at runtime. * * Params: * (none) * * Return: * void */ void snoopy_configuration_preinit_disableConfigFileParsing () { snoopy_configuration_configFileParsingEnabled = SNOOPY_FALSE; } /* * snoopy_configuration_preinit_enableConfigFileParsing * * Description: * Enables configuration file parsing at runtime. Optionally sets * alternative config file path. * * Params: * altConfigFilePath: path to alternate config file * * Return: * void */ void snoopy_configuration_preinit_enableAltConfigFileParsing (char * const altConfigFilePath) { if (NULL != altConfigFilePath) { snoopy_configuration_altConfigFilePath = altConfigFilePath; } snoopy_configuration_configFileParsingEnabled = SNOOPY_TRUE; } /* * snoopy_configuration_preinit_setConfigFilePathFromEnv * * Description: * Parses environment for SNOOPY_INI and if found, checks if * file exists and is readable, and sets path to snoopy.ini * accordingly. Also it enables runtime config file parsing. * * Params: * (none) * * Return: * void */ void snoopy_configuration_preinit_setConfigFilePathFromEnv () { const char *valuePtr; /* Does environmental variable exist? */ valuePtr = getenv("SNOOPY_INI"); if (NULL == valuePtr) { /* Nope. */ return; } /* Store it */ strncpy(snoopy_configuration_altConfigFilePathBuf, valuePtr, PATH_MAX-1); snoopy_configuration_altConfigFilePathBuf[PATH_MAX-1] = 0; /* Is file readable? */ if (0 != access(valuePtr, R_OK)) { /* Nope. */ snoopy_configuration_altConfigFilePathBuf[0] = 0; return; } snoopy_configuration_preinit_enableAltConfigFileParsing(snoopy_configuration_altConfigFilePathBuf); } /* * snoopy_configuration_ctor * * Description: * Populates snoopy_configuration config variable storage with * correct values, either from configuration file (if enabled) * or from ./configure arguments, or defaults are used as last * case scenario. * * Params: * (none) * * Return: * void */ void snoopy_configuration_ctor () { #ifdef SNOOPY_CONFIGFILE_ENABLED /* Is config file parsing disabled at runtime? */ if (SNOOPY_FALSE == snoopy_configuration_configFileParsingEnabled) { return; } /* Get config pointer */ snoopy_configuration_t *CFG = snoopy_configuration_get(); /* Parse INI file if enabled */ if (NULL != snoopy_configuration_altConfigFilePath) { // This is used by Snoopy testing suite - combined tests snoopy_configfile_load(snoopy_configuration_altConfigFilePath); } else { snoopy_configfile_load(CFG->configfile_path); } #endif } /* * snoopy_configuration_dtor * * Description: * Frees all configuration-related malloced resources, and sets * corresponding config settings back to their default values. * * Params: * (none) * * Return: * void */ void snoopy_configuration_dtor () { snoopy_configuration_t *CFG; /* Get config pointer */ CFG = snoopy_configuration_get(); /* * Reset config setting: configfile_path * * This might get changed by libsnoopy-test.so library. */ #ifdef SNOOPY_CONFIGFILE_ENABLED CFG->configfile_path = SNOOPY_CONFIGFILE_PATH; #endif /* * Reset config setting: message_format */ if (SNOOPY_TRUE == CFG->message_format_malloced) { free(CFG->message_format); /* * Set this to false - REQUIRED * * This needs to be done as a special condition can occur at boot/shutdown: * - Snoopy is loaded when snoopy.ini is visible (mounted, present) * - Snoopy parses it, and sets message_format and ..._malloced to TRUE * - on shutdown, snoopy.ini might disappear * - snoopy_configuration_ctor() tries to parse config file, and as it is * not found, it does no alteration of snoopy_configuraton struct * - CFG->message_format_malloced is left set to TRUE * - when snoopy_configuration_dtor() is called, it tries to free the * const char[] that contains the compiled-in message format */ CFG->message_format_malloced = SNOOPY_FALSE; /* * Set this to default value - REQUIRED * * Otherwise on next Snoopy run there will be no message format defined, * which would in best-case scenario cause no Snoopy output, but in * worst-case scenarion there would be a segfault and possible system * crash. */ CFG->message_format = SNOOPY_MESSAGE_FORMAT; } /* * Reset config setting: filter_chain */ if (SNOOPY_TRUE == CFG->filter_chain_malloced) { free(CFG->filter_chain); /* Set this to false - REQUIRED (see above) */ CFG->filter_chain_malloced = SNOOPY_FALSE; /* Set this to default value - REQUIRED (see above) */ #ifdef SNOOPY_FILTERING_ENABLED CFG->filter_chain = SNOOPY_FILTER_CHAIN; #else CFG->filter_chain = ""; #endif } /* * Reset config setting: output */ if (SNOOPY_TRUE == CFG->output_malloced) { free(CFG->output); /* Set this to false - REQUIRED (see above) */ CFG->output_malloced = SNOOPY_FALSE; /* Set this to default value - REQUIRED (see above) */ CFG->output = SNOOPY_OUTPUT_DEFAULT; } /* * Reset config setting: output_arg */ if (SNOOPY_TRUE == CFG->output_arg_malloced) { free(CFG->output_arg); /* Set this to false - REQUIRED (see above) */ CFG->output_arg_malloced = SNOOPY_FALSE; /* Set this to default value - REQUIRED (see above) */ CFG->output_arg = SNOOPY_OUTPUT_DEFAULT_ARG; } /* * Reset config setting: syslog_ident_format */ if (SNOOPY_TRUE == CFG->syslog_ident_format_malloced) { free(CFG->syslog_ident_format); CFG->syslog_ident_format_malloced = SNOOPY_FALSE; /* Set this to false - REQUIRED (see above) */ CFG->syslog_ident_format = SNOOPY_SYSLOG_IDENT_FORMAT; /* Set this to default value - REQUIRED (see above) */ } } /* * snoopy_configuration_setUninitialized * * Description: * Sets state of configuration array to uninitialized. * * Params: * (none) * * Return: * void */ void snoopy_configuration_setUninitialized ( snoopy_configuration_t *CFG ) { CFG->initialized = SNOOPY_FALSE; } /* * snoopy_configuration_setDefaults * * Description: * Sets the default values for all configuration variables. * Defaults are primarily defined by Snoopy, and possibly overridden by * ./configure flags. * * Params: * (none) * * Return: * void */ void snoopy_configuration_setDefaults ( snoopy_configuration_t *CFG ) { CFG->initialized = SNOOPY_TRUE; #ifdef SNOOPY_CONFIGFILE_ENABLED CFG->configfile_enabled = SNOOPY_TRUE; CFG->configfile_path = SNOOPY_CONFIGFILE_PATH; #else CFG->configfile_enabled = SNOOPY_FALSE; CFG->configfile_path = ""; #endif CFG->configfile_found = SNOOPY_FALSE; CFG->configfile_parsed = SNOOPY_FALSE; #ifdef SNOOPY_ERROR_LOGGING_ENABLED CFG->error_logging_enabled = SNOOPY_TRUE; #else CFG->error_logging_enabled = SNOOPY_FALSE; #endif CFG->message_format = SNOOPY_MESSAGE_FORMAT; CFG->message_format_malloced = SNOOPY_FALSE; #ifdef SNOOPY_FILTERING_ENABLED CFG->filtering_enabled = SNOOPY_TRUE; CFG->filter_chain = SNOOPY_FILTER_CHAIN; #else CFG->filtering_enabled = SNOOPY_FALSE; CFG->filter_chain = ""; #endif CFG->filter_chain_malloced = SNOOPY_FALSE; CFG->output = SNOOPY_OUTPUT_DEFAULT; CFG->output_malloced = SNOOPY_FALSE; CFG->output_arg = SNOOPY_OUTPUT_DEFAULT_ARG; CFG->output_arg_malloced = SNOOPY_FALSE; CFG->syslog_facility = SNOOPY_SYSLOG_FACILITY; CFG->syslog_ident_format = SNOOPY_SYSLOG_IDENT_FORMAT; CFG->syslog_ident_format_malloced = SNOOPY_FALSE; CFG->syslog_level = SNOOPY_SYSLOG_LEVEL; CFG->datasource_message_max_length = SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_DEFAULT; CFG->log_message_max_length = SNOOPY_LOG_MESSAGE_MAX_LENGTH_DEFAULT; } /* * snoopy_configuration_get() * * Description: * Retrieve pointer configuration struct. * * Params: * envp: environment array pointer to store * * Return: * snoopy_configuration_t* */ __attribute__((visibility("default"))) snoopy_configuration_t* snoopy_configuration_get () { snoopy_configuration_t *CFG; #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED CFG = snoopy_tsrm_get_configuration(); #else CFG = &snoopy_configuration_data; #endif if (SNOOPY_TRUE != CFG->initialized) { snoopy_configuration_setDefaults(CFG); } return CFG; } snoopy-snoopy-2.5.2/src/configuration.h000066400000000000000000000046511470651710700202210ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: configuration.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include /* * START: Prevent cyclic inclusions */ #ifndef __SNOOPY_CONFIGURATION_H #define __SNOOPY_CONFIGURATION_H /* * Array holding Snoopy configuration data in one place */ typedef struct { int initialized; int configfile_enabled; char *configfile_path; int configfile_found; int configfile_parsed; int error_logging_enabled; char *message_format; int message_format_malloced; int filtering_enabled; char *filter_chain; int filter_chain_malloced; char *output; int output_malloced; char *output_arg; int output_arg_malloced; int syslog_facility; int syslog_level; int syslog_ident_format_malloced; char *syslog_ident_format; size_t datasource_message_max_length; size_t log_message_max_length; } snoopy_configuration_t; /* * Pre-initialization functions * * Used by testing binaries, to disable config file parsing, or set alternate * config file path. */ void snoopy_configuration_preinit_disableConfigFileParsing(); void snoopy_configuration_preinit_enableAltConfigFileParsing(char * const altConfigFilePath); void snoopy_configuration_preinit_setConfigFilePathFromEnv(); /* * Management functions */ void snoopy_configuration_ctor (); void snoopy_configuration_dtor (); void snoopy_configuration_setUninitialized (snoopy_configuration_t *CFG); void snoopy_configuration_setDefaults (snoopy_configuration_t *CFG); /* * Retrieval functions */ snoopy_configuration_t* snoopy_configuration_get (); /* * END: Prevent cyclic inclusion */ #endif /* Cyclic inclusion */ snoopy-snoopy-2.5.2/src/datasource/000077500000000000000000000000001470651710700173255ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/datasource/Makefile.am000066400000000000000000000125471470651710700213720ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Create one library with all Snoopy data sources collected in it # noinst_LTLIBRARIES = libsnoopy_datasources_all.la ### Data sources collection is made of the following files # # Please maintain alphabetical order, equal to what `ls` would do. # libsnoopy_datasources_all_la_SOURCES = \ datasource-common.h \ failure.c \ failure.h \ noop.c \ noop.h libsnoopy_datasources_all_la_LDFLAGS = # Data source: cgroup # if DATASOURCE_ENABLED_cgroup libsnoopy_datasources_all_la_SOURCES += \ cgroup.c \ cgroup.h endif # Data source: cmdline # if DATASOURCE_ENABLED_cmdline libsnoopy_datasources_all_la_SOURCES += \ cmdline.c \ cmdline.h endif # Data source: cwd # if DATASOURCE_ENABLED_cwd libsnoopy_datasources_all_la_SOURCES += \ cwd.c \ cwd.h endif # Data source: datetime # if DATASOURCE_ENABLED_datetime libsnoopy_datasources_all_la_SOURCES += \ datetime.c \ datetime.h endif # Data source: domain # if DATASOURCE_ENABLED_domain libsnoopy_datasources_all_la_SOURCES += \ domain.c \ domain.h endif # Data source: egid # if DATASOURCE_ENABLED_egid libsnoopy_datasources_all_la_SOURCES += \ egid.c \ egid.h endif # Data source: egroup # if DATASOURCE_ENABLED_egroup libsnoopy_datasources_all_la_SOURCES += \ egroup.c \ egroup.h endif # Data source: env # if DATASOURCE_ENABLED_env libsnoopy_datasources_all_la_SOURCES += \ env.c \ env.h endif # Data source: env_all # if DATASOURCE_ENABLED_env_all libsnoopy_datasources_all_la_SOURCES += \ env_all.c \ env_all.h endif # Data source: euid # if DATASOURCE_ENABLED_euid libsnoopy_datasources_all_la_SOURCES += \ euid.c \ euid.h endif # Data source: eusername # if DATASOURCE_ENABLED_eusername libsnoopy_datasources_all_la_SOURCES += \ eusername.c \ eusername.h endif # Data source: filename # if DATASOURCE_ENABLED_filename libsnoopy_datasources_all_la_SOURCES += \ filename.c \ filename.h endif # Data source: gid # if DATASOURCE_ENABLED_gid libsnoopy_datasources_all_la_SOURCES += \ gid.c \ gid.h endif # Data source: group # if DATASOURCE_ENABLED_group libsnoopy_datasources_all_la_SOURCES += \ group.c \ group.h endif # Data source: hostname # if DATASOURCE_ENABLED_hostname libsnoopy_datasources_all_la_SOURCES += \ hostname.c \ hostname.h endif # Data source: ipaddr # if DATASOURCE_ENABLED_ipaddr libsnoopy_datasources_all_la_SOURCES += \ ipaddr.c \ ipaddr.h endif # Data source: login # if DATASOURCE_ENABLED_login libsnoopy_datasources_all_la_SOURCES += \ login.c \ login.h endif # Data source: pid # if DATASOURCE_ENABLED_pid libsnoopy_datasources_all_la_SOURCES += \ pid.c \ pid.h endif # Data source: ppid # if DATASOURCE_ENABLED_ppid libsnoopy_datasources_all_la_SOURCES += \ ppid.c \ ppid.h endif # Data source: rpname # if DATASOURCE_ENABLED_rpname libsnoopy_datasources_all_la_SOURCES += \ rpname.c \ rpname.h endif # Data source: sid # if DATASOURCE_ENABLED_sid libsnoopy_datasources_all_la_SOURCES += \ sid.c \ sid.h endif # Data source: snoopy_configure_command # if DATASOURCE_ENABLED_snoopy_configure_command libsnoopy_datasources_all_la_SOURCES += \ snoopy_configure_command.c \ snoopy_configure_command.h endif # Data source: snoopy_literal # if DATASOURCE_ENABLED_snoopy_literal libsnoopy_datasources_all_la_SOURCES += \ snoopy_literal.c \ snoopy_literal.h endif # Data source: snoopy_threads # if THREAD_SAFETY_ENABLED if DATASOURCE_ENABLED_snoopy_threads libsnoopy_datasources_all_la_SOURCES += \ snoopy_threads.c \ snoopy_threads.h endif endif # Data source: snoopy_version # if DATASOURCE_ENABLED_snoopy_version libsnoopy_datasources_all_la_SOURCES += \ snoopy_version.c \ snoopy_version.h endif # Data source: systemd_unit_name # if DATASOURCE_ENABLED_systemd_unit_name libsnoopy_datasources_all_la_SOURCES += \ systemd-unit-name.c \ systemd-unit-name.h endif # Data source: tid # if DATASOURCE_ENABLED_tid libsnoopy_datasources_all_la_SOURCES += \ tid.c \ tid.h # This one seems to be added automatically recently. libsnoopy_datasources_all_la_LDFLAGS += -lpthread endif # Data source: tid_kernel # if DATASOURCE_ENABLED_tid_kernel libsnoopy_datasources_all_la_SOURCES += \ tid_kernel.c \ tid_kernel.h endif # Data source: timestamp # if DATASOURCE_ENABLED_timestamp libsnoopy_datasources_all_la_SOURCES += \ timestamp.c \ timestamp.h endif # Data source: timestamp_ms # if DATASOURCE_ENABLED_timestamp_ms libsnoopy_datasources_all_la_SOURCES += \ timestamp_ms.c \ timestamp_ms.h endif # Data source: timestamp_us # if DATASOURCE_ENABLED_timestamp_us libsnoopy_datasources_all_la_SOURCES += \ timestamp_us.c \ timestamp_us.h endif # Data source: tty # if DATASOURCE_ENABLED_tty libsnoopy_datasources_all_la_SOURCES += \ tty.c \ tty.h endif # Data source: tty_uid # if DATASOURCE_ENABLED_tty_uid libsnoopy_datasources_all_la_SOURCES += \ tty_uid.c \ tty_uid.h endif # Data source: tty_username # if DATASOURCE_ENABLED_tty_username libsnoopy_datasources_all_la_SOURCES += \ tty_username.c \ tty_username.h endif # Common TTY-related code # if DATASOURCE_INCLUDE_tty__common libsnoopy_datasources_all_la_SOURCES += \ tty__common.c \ tty__common.h endif # Data source: uid # if DATASOURCE_ENABLED_uid libsnoopy_datasources_all_la_SOURCES += \ uid.c \ uid.h endif # Data source: username # if DATASOURCE_ENABLED_username libsnoopy_datasources_all_la_SOURCES += \ username.c \ username.h endif snoopy-snoopy-2.5.2/src/datasource/cgroup.c000066400000000000000000000125731470651710700210000ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "cgroup.h" #include "snoopy.h" #include "util/file-snoopy.h" #include "util/string-snoopy.h" #include #include #include #include /* * Local defines */ #define PROC_PID_CGROUP_PATH_SIZE_MAX 32 static int doesCgroupEntryContainController (char const * const cgroupEntry, char const * const controllerName); int snoopy_datasource_cgroup (char * const resultBuf, size_t resultBufSize, char const * const arg) { int myPid; char procPidCgroupFilePath[PROC_PID_CGROUP_PATH_SIZE_MAX]; char * procPidCgroupContent = NULL; char * cgroupEntry = NULL; int retMsgLen; // Verify the argument if (0 == strcmp(arg, "")) { snprintf(resultBuf, resultBufSize, "Missing cgroup selection argument"); return SNOOPY_DATASOURCE_FAILURE; } // Generate /proc/PID/cgroup path myPid = getpid(); snprintf(procPidCgroupFilePath, PROC_PID_CGROUP_PATH_SIZE_MAX, "/proc/%d/cgroup", myPid); // Get the cgroup info content if (snoopy_util_file_getSmallTextFileContent(procPidCgroupFilePath, &procPidCgroupContent) < 0) { snprintf(resultBuf, resultBufSize, "Unable to read file %s, reason: %s", procPidCgroupFilePath, procPidCgroupContent); free(procPidCgroupContent); return SNOOPY_DATASOURCE_FAILURE; } // Search if (SNOOPY_TRUE == snoopy_util_string_containsOnlyDigits(arg)) { // Search mode: ^MYNUMBER:.* size_t searchStringLen; char * searchString = NULL; searchStringLen = strlen(arg) + 2; // +1 for the ':' and +1 for the '\0' searchString = malloc(searchStringLen); snprintf(searchString, searchStringLen, "%s:", arg); cgroupEntry = snoopy_util_string_findLineStartingWith(procPidCgroupContent, searchString); free(searchString); if (cgroupEntry) { snoopy_util_string_nullTerminateLine(cgroupEntry); } } else { // Search mode: ^[^:]+:MYTEXT: // This search mangles the procPidCgroupContent, but it leaves a null-terminated // cgroupEntry ready for subsequent use. char * nextEntry = NULL; cgroupEntry = strtok_r(procPidCgroupContent, "\n", &nextEntry); while (cgroupEntry) { if (SNOOPY_TRUE == doesCgroupEntryContainController(cgroupEntry, arg)) { break; } cgroupEntry = strtok_r(NULL, "\n", &nextEntry); } } // Not found? if (NULL == cgroupEntry) { free(procPidCgroupContent); return snprintf(resultBuf, resultBufSize, "%s", "(none)"); } // Found retMsgLen = snprintf(resultBuf, resultBufSize, "%s", cgroupEntry); free(procPidCgroupContent); return retMsgLen; } static int doesCgroupEntryContainController (char const * const cgroupEntry, char const * const controllerName) { const char * firstColon; const char * controllerList; char * secondColon; // Find relevant colon characters to isolate the controller list firstColon = strchr(cgroupEntry, ':'); if (!firstColon) { return SNOOPY_ERROR; } controllerList = firstColon+1; secondColon = strchr(controllerList, ':'); if (!secondColon) { return SNOOPY_ERROR; } // If controller list is empty, we can't match then if (controllerList == secondColon) { return SNOOPY_FALSE; } // Change second colon to \0, to enable subsequent search *secondColon = '\0'; // Check whole literal match if (0 == strcmp(controllerList, controllerName)) { *secondColon = ':'; return SNOOPY_TRUE; } // Is there even a ',' character in controller list - if not, cut the execution short if (!strchr(controllerList, ',')) { *secondColon = ':'; return SNOOPY_FALSE; } // Parse the comma-separated list of controllers const char * tokenPtr = controllerList; while (tokenPtr) { char * commaPtr = strchr(tokenPtr, ','); if (commaPtr) { *commaPtr = '\0'; } // Token matches if (0 == strcmp(tokenPtr, controllerName)) { if (commaPtr) *commaPtr = ','; *secondColon = ':'; return SNOOPY_TRUE; } // Last iteration if (commaPtr) { // Not found, still stuff to search, so search on *commaPtr = ','; tokenPtr = commaPtr + 1; } else { // Last iteration tokenPtr = NULL; break; } } *secondColon = ':'; return SNOOPY_FALSE; } snoopy-snoopy-2.5.2/src/datasource/cgroup.h000066400000000000000000000017131470651710700207770ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: cgroup */ int snoopy_datasource_cgroup (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/cmdline.c000066400000000000000000000070431470651710700211100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/cmdline.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "cmdline.h" #include "snoopy.h" #include "inputdatastorage.h" #include #include #include /* * SNOOPY DATA SOURCE: cmdline * * Description: * Returns command line of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_cmdline (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { const snoopy_inputdatastorage_t * snoopy_inputdatastorage; size_t bytesWrittenToResultBuf; // Return on this impossible condition // We're only adding this check here because SonarCloud is detecting a "bug" with resultBufSize=0. if (resultBufSize <= 0) { return 0; } /* Get argument data of execv/e() call */ snoopy_inputdatastorage = snoopy_inputdatastorage_get(); /* * DirectAdmin does not follow the execve() convention (as described in its man page) * and passes NULL argv instead of what it's supposed to do. Let's work around that. * * Additionally, let's handle the `(char *[]) { NULL }` case in the same manner too. */ if ( (snoopy_inputdatastorage->argv == NULL) || (snoopy_inputdatastorage->argv[0] == NULL) ) { if (NULL == snoopy_inputdatastorage->filename) { return snprintf(resultBuf, resultBufSize, "(unknown)"); } else { return snprintf(resultBuf, resultBufSize, "%s", snoopy_inputdatastorage->filename); } } // Recompose the command into a result string bytesWrittenToResultBuf = 0; for (int argId=0 ; snoopy_inputdatastorage->argv[argId] != NULL ; argId++) { // Add space before every non-first argument if ((argId > 0) && (bytesWrittenToResultBuf < resultBufSize)) { bytesWrittenToResultBuf += snprintf( resultBuf + bytesWrittenToResultBuf, resultBufSize - bytesWrittenToResultBuf, " " ); } // Copy the content if (bytesWrittenToResultBuf < resultBufSize) { bytesWrittenToResultBuf += snprintf( resultBuf + bytesWrittenToResultBuf, resultBufSize - bytesWrittenToResultBuf, "%s", snoopy_inputdatastorage->argv[argId] ); } } // Ensure the presence of a terminating null character if (bytesWrittenToResultBuf < resultBufSize) { resultBuf[bytesWrittenToResultBuf] = '\0'; } else { resultBuf[resultBufSize-1] = '\0'; } return (int) bytesWrittenToResultBuf; } snoopy-snoopy-2.5.2/src/datasource/cmdline.h000066400000000000000000000017651470651710700211220ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/cmdline.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: cmdline */ int snoopy_datasource_cmdline (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/cwd.c000066400000000000000000000030641470651710700202510ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/cwd.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "cwd.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: cwd * * Description: * Returns current working directory of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_cwd (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { char cwdBuf[PATH_MAX+1]; if (getcwd(cwdBuf, PATH_MAX+1)) { return snprintf(resultBuf, resultBufSize, "%s", cwdBuf); } return SNOOPY_DATASOURCE_FAILURE; } snoopy-snoopy-2.5.2/src/datasource/cwd.h000066400000000000000000000017511470651710700202570ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/cwd.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: cwd */ int snoopy_datasource_cwd (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/datasource-common.h000066400000000000000000000016071470651710700231220ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/datasource-common.h * * Copyright (c) 2023 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Required for size_t type */ #include snoopy-snoopy-2.5.2/src/datasource/datetime.c000066400000000000000000000045451470651710700212750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/datetime.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "datetime.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: datetime * * Description: * Returns current date and time in ISO 8601 forma. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_datetime (char * const resultBuf, size_t resultBufSize, char const * const arg) { time_t curTime; struct tm curLocalTimeBuf; const struct tm *curLocalTime; char const *formatToUse; char timeBuffer[SNOOPY_DATASOURCE_DATETIME_sizeMaxWithNull]; // Get current time if ((time_t) -1 == time(&curTime)) { return snprintf(resultBuf, resultBufSize, "(error @ time(): %d)", errno); } // Convert to local time curLocalTime = localtime_r(&curTime, &curLocalTimeBuf); if (NULL == curLocalTime) { return snprintf(resultBuf, resultBufSize, "(error @ localtime_r())"); } // Determine the format to use if (arg[0] != '\0') { formatToUse = arg; } else { formatToUse = SNOOPY_DATASOURCE_DATETIME_defaultFormat; } // Format it if (0 == strftime(timeBuffer, SNOOPY_DATASOURCE_DATETIME_sizeMaxWithNull, formatToUse, curLocalTime)) { return snprintf(resultBuf, resultBufSize, "(error @ strftime())"); } // Copy it return snprintf(resultBuf, resultBufSize, "%s", timeBuffer); } snoopy-snoopy-2.5.2/src/datasource/datetime.h000066400000000000000000000022131470651710700212700ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/datetime.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * Local defines */ #define SNOOPY_DATASOURCE_DATETIME_defaultFormat "%FT%T%z" #define SNOOPY_DATASOURCE_DATETIME_sizeMaxWithNull 80 /* * SNOOPY DATA SOURCE: datetime */ int snoopy_datasource_datetime (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/domain.c000066400000000000000000000106521470651710700207440ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/domain.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ // This needs to be defined before including sys/utsname.h, // or struct utsname does not return domainname member. #define _GNU_SOURCE #include "domain.h" #include "snoopy.h" #include #include #include #include #include /* * Local defines */ #define HOST_NAME_BUF_SIZE HOST_NAME_MAX + 2 // +1 for terminal \0 and +1 because we'll be adding a trailing dot #define HOSTS_PATH "/etc/hosts" #define HOSTS_LINE_SIZE_MAX 1024 #define HOSTS_LINE_POS_MAX 1023 /* * SNOOPY DATA SOURCE: domain * * Description: * Returns domain of this system. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_domain (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { FILE *fp; char hostname[HOST_NAME_BUF_SIZE]; char line[HOSTS_LINE_SIZE_MAX]; int retVal; int hostnameLen; /* * START: COPY FROM datasource/hostname */ /* Get my hostname first */ retVal = gethostname(hostname, HOST_NAME_MAX); if (0 != retVal) { return snprintf(resultBuf, resultBufSize, "(error @ gethostname(): %d)", errno); } // If hostname was something alien (longer than HOST_NAME_MAX), then the // last character may not be NULL (the behavior is unspecified). // Let's avoid any surprises and null-terminate at the end of this buffer. hostname[HOST_NAME_BUF_SIZE-1] = '\0'; /* * END: Copy from datasource/hostname */ /* Check hostname length */ hostnameLen = (int) strlen(hostname); if (0 == hostnameLen) { snprintf(resultBuf, resultBufSize, "Got empty hostname"); return SNOOPY_DATASOURCE_FAILURE; } if (hostnameLen > HOST_NAME_BUF_SIZE - 2) { snprintf(resultBuf, resultBufSize, "INTERNAL ERROR: Got too long hostname, length: %d", hostnameLen); return SNOOPY_DATASOURCE_FAILURE; } /* Add a dot at the end of hostname, that is what we are searching for */ hostname[hostnameLen] = '.'; hostname[hostnameLen+1] = '\0'; /* Try to open file in read mode */ fp = fopen(HOSTS_PATH, "r"); if (NULL == fp) { snprintf(resultBuf, resultBufSize, "Unable to open file for reading: %s", HOSTS_PATH); return SNOOPY_OUTPUT_FAILURE; } /* Read line by line */ const char *linePtr; char *hashPtr; char *lineEntryPtr; char *savePtr; char *domainPtr = NULL; while (NULL != (linePtr = fgets(line, sizeof(line), fp))) { /* Is line a comment - ignore everything after '#' character */ hashPtr = strchr(linePtr, '#'); if (NULL != hashPtr) { *hashPtr = '\0'; } /* Try to find "hostname." there */ lineEntryPtr = strcasestr(linePtr, hostname); if (NULL != lineEntryPtr) { strtok_r(lineEntryPtr, " \t\n\r", &savePtr); /* Does not matter whether token has been found or not. */ /* If it was, strtok creates \0 at the end of it and returns pointer to it. */ /* If it was not, we must have met the EOF and just use everything. */ domainPtr = lineEntryPtr + strlen(hostname); break; } } /* Cleanup and return */ fclose(fp); if (NULL != domainPtr) { return snprintf(resultBuf, resultBufSize, "%s", domainPtr); } else { return snprintf(resultBuf, resultBufSize, "(none)"); } } snoopy-snoopy-2.5.2/src/datasource/domain.h000066400000000000000000000017551470651710700207550ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/domain.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: domain */ int snoopy_datasource_domain (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/egid.c000066400000000000000000000027071470651710700204070ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/egid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "egid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: egid * * Description: * Returns effective GID of currently running process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_egid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getegid()); } snoopy-snoopy-2.5.2/src/datasource/egid.h000066400000000000000000000017541470651710700204150ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/egid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: egid */ int snoopy_datasource_egid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/egroup.c000066400000000000000000000046401470651710700207760ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/egroup.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "egroup.h" #include "snoopy.h" #include #include #include #include #include /* * SNOOPY DATA SOURCE: egroup * * Description: * Returns literal effective group name (Group ID) of current process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_egroup (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct group gr; struct group *gr_gid = NULL; char *buffgr_gid = NULL; long buffgrsize_gid = 0; int messageLength = 0; /* Allocate memory */ buffgrsize_gid = sysconf(_SC_GETGR_R_SIZE_MAX); if (-1 == buffgrsize_gid) { buffgrsize_gid = 16384; } buffgr_gid = malloc(buffgrsize_gid); if (NULL == buffgr_gid) { return snprintf(resultBuf, resultBufSize, "ERROR(malloc)"); } /* Try to get data */ if (0 != getgrgid_r(getegid(), &gr, buffgr_gid, buffgrsize_gid, &gr_gid)) { messageLength = snprintf(resultBuf, resultBufSize, "ERROR(getgrgid_r)"); } else { if (NULL == gr_gid) { messageLength = snprintf(resultBuf, resultBufSize, "(undefined)"); } else { messageLength = snprintf(resultBuf, resultBufSize, "%s", gr_gid->gr_name); } } /* Cleanup and return */ free(buffgr_gid); return messageLength; } snoopy-snoopy-2.5.2/src/datasource/egroup.h000066400000000000000000000017621470651710700210050ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/egroup.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: egroup */ int snoopy_datasource_egroup (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/env.c000066400000000000000000000031471470651710700202660ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/env.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "env.h" #include "snoopy.h" #include #include /* * SNOOPY DATA SOURCE: env * * Description: * Returns environmental variable value, if set * * Params: * result: pointer to string, to write result into * arg: which environmental variable to get * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_env (char * const resultBuf, size_t resultBufSize, char const * const arg) { char *env = getenv(arg); /* Return empty string if environmental variable does not exist */ if (NULL == env) { return snprintf(resultBuf, resultBufSize, "(undefined)"); } return snprintf(resultBuf, resultBufSize, "%s", env); } snoopy-snoopy-2.5.2/src/datasource/env.h000066400000000000000000000017511470651710700202720ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/env.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: env */ int snoopy_datasource_env (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/env_all.c000066400000000000000000000063231470651710700211150ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/env_all.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "env_all.h" #include "snoopy.h" #include #include #include /* * Use this extenal variable */ extern char **environ; /* * SNOOPY DATA SOURCE: env_all * * Description: * Returns all environmental variables * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_env_all (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { int resultSize = 0; // Current size of message to be returned back - does not include trailing null character // Loop through all environmental variables char *envItem = *environ; // Get first environmental variable int i = 0; while (NULL != envItem) { i++; size_t remResultSize = resultBufSize - resultSize; // Add comma if required - must be still 5 characters available for this (,...\0) if ((i > 1) && (remResultSize >= 5)) { resultBuf[resultSize] = ','; resultBuf[resultSize+1] = '\0'; resultSize++; remResultSize--; } // Do we append whole environmental variable, or just part of it? // +3 to account for ... and +1 for null character if ((strlen(envItem) + 3 + 1) < remResultSize) { int strSizeCopied = 0; // Append whole ENV variable strSizeCopied = snprintf(&resultBuf[resultSize], remResultSize, "%s", envItem); resultSize += strSizeCopied; } else { size_t strSizeToCopy = 0; // This one includes null char, therefore the actual string length that will be copied is X-1 characters + \0 strSizeToCopy = remResultSize - 3; // -4 to account for "...\0" snprintf(&resultBuf[resultSize], strSizeToCopy, "%s", envItem); resultSize += strSizeToCopy - 1; // Account for added \0 at the end - we do not use strSizeCopied here, which already includes it strSizeToCopy = 4; // -4 to account for "...\0" snprintf(&resultBuf[resultSize], strSizeToCopy, "..."); resultSize += strSizeToCopy-1; break; } // Get next environmental variable envItem = *(environ+i); } return resultSize; } snoopy-snoopy-2.5.2/src/datasource/env_all.h000066400000000000000000000017601470651710700211220ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/env_all.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: env_all */ int snoopy_datasource_env_all (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/euid.c000066400000000000000000000026761470651710700204320ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/euid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "euid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: euid * * Description: * Returns effective UID of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_euid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", geteuid()); } snoopy-snoopy-2.5.2/src/datasource/euid.h000066400000000000000000000017541470651710700204330ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/euid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: euid */ int snoopy_datasource_euid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/eusername.c000066400000000000000000000046731470651710700214670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/eusername.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "eusername.h" #include "snoopy.h" #include #include #include #include #include /* * SNOOPY DATA SOURCE: eusername * * Description: * Returns literal effective user name (User ID) of current process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_eusername (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct passwd pwd; struct passwd *pwd_uid = NULL; char *buffpwd_uid = NULL; long buffpwdsize_uid = 0; int messageLength = 0; /* Allocate memory */ buffpwdsize_uid = sysconf(_SC_GETPW_R_SIZE_MAX); if (-1 == buffpwdsize_uid) { buffpwdsize_uid = 16384; } buffpwd_uid = malloc(buffpwdsize_uid); if (NULL == buffpwd_uid) { return snprintf(resultBuf, resultBufSize, "ERROR(malloc)"); } /* Try to get data */ if (0 != getpwuid_r(geteuid(), &pwd, buffpwd_uid, buffpwdsize_uid, &pwd_uid)) { messageLength = snprintf(resultBuf, resultBufSize, "ERROR(getpwuid_r)"); } else { if (NULL == pwd_uid) { messageLength = snprintf(resultBuf, resultBufSize, "(undefined)"); } else { messageLength = snprintf(resultBuf, resultBufSize, "%s", pwd_uid->pw_name); } } /* Cleanup and return */ free(buffpwd_uid); return messageLength; } snoopy-snoopy-2.5.2/src/datasource/eusername.h000066400000000000000000000017731470651710700214720ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/eusername.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: eusername */ int snoopy_datasource_eusername (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/failure.c000066400000000000000000000026621470651710700211260ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/failure.c * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "failure.h" #include "snoopy.h" #include /* * SNOOPY DATA SOURCE: failure * * Description: * Does nothing, just returns a failure with a message. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_failure (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { snprintf(resultBuf, resultBufSize, "Artificial datasource failure triggered"); return SNOOPY_DATASOURCE_FAILURE; } snoopy-snoopy-2.5.2/src/datasource/failure.h000066400000000000000000000017651470651710700211360ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/failure.h * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: failure */ int snoopy_datasource_failure (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/filename.c000066400000000000000000000032141470651710700212510ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/filename.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "filename.h" #include "snoopy.h" #include "inputdatastorage.h" #include /* * SNOOPY DATA SOURCE: filename * * Description: * Returns filename of program about to be executed * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_filename (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { const snoopy_inputdatastorage_t * snoopy_inputdatastorage; /* Get argument data of execv/e() call */ snoopy_inputdatastorage = snoopy_inputdatastorage_get(); return snprintf(resultBuf, resultBufSize, "%s", snoopy_inputdatastorage->filename); } snoopy-snoopy-2.5.2/src/datasource/filename.h000066400000000000000000000017701470651710700212630ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/filename.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: filename */ int snoopy_datasource_filename (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/gid.c000066400000000000000000000027131470651710700202370ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/gid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "gid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: gid * * Description: * Returns GID (Group ID) number of currently running process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_gid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getgid()); } snoopy-snoopy-2.5.2/src/datasource/gid.h000066400000000000000000000017511470651710700202450ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/gid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: gid */ int snoopy_datasource_gid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/group.c000066400000000000000000000046201470651710700206270ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/group.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "group.h" #include "snoopy.h" #include #include #include #include #include /* * SNOOPY DATA SOURCE: group * * Description: * Returns literal group name (Group ID) of current process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_group (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct group gr; struct group *gr_gid = NULL; char *buffgr_gid = NULL; long buffgrsize_gid = 0; int messageLength = 0; /* Allocate memory */ buffgrsize_gid = sysconf(_SC_GETGR_R_SIZE_MAX); if (-1 == buffgrsize_gid) { buffgrsize_gid = 16384; } buffgr_gid = malloc(buffgrsize_gid); if(NULL == buffgr_gid) { return snprintf(resultBuf, resultBufSize, "ERROR(malloc)"); } /* Try to get data */ if (0 != getgrgid_r(getgid(), &gr, buffgr_gid, buffgrsize_gid, &gr_gid)) { messageLength = snprintf(resultBuf, resultBufSize, "ERROR(getgrgid_r)"); } else { if (NULL == gr_gid) { messageLength = snprintf(resultBuf, resultBufSize, "(undefined)"); } else { messageLength = snprintf(resultBuf, resultBufSize, "%s", gr_gid->gr_name); } } /* Cleanup and return */ free(buffgr_gid); return messageLength; } snoopy-snoopy-2.5.2/src/datasource/group.h000066400000000000000000000017571470651710700206440ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/group.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: group */ int snoopy_datasource_group (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/hostname.c000066400000000000000000000034711470651710700213140ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/hostname.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "hostname.h" #include "snoopy.h" #include #include #include #include /* * SNOOPY DATA SOURCE: hostname * * Description: * Returns hostname of this system. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_hostname (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { int charCount; int retVal; retVal = gethostname(resultBuf, resultBufSize); if (0 != retVal) { return snprintf(resultBuf, resultBufSize, "(error @ gethostname(): %d)", errno); } // If hostname was something alien (longer than 1024 characters), // set last char to null just in case resultBuf[resultBufSize-1] = '\0'; charCount = (int) strlen(resultBuf); return charCount; } snoopy-snoopy-2.5.2/src/datasource/hostname.h000066400000000000000000000017631470651710700213230ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/hostname.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: hostname */ int snoopy_datasource_hostname (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/ipaddr.c000066400000000000000000000051351470651710700207400ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "ipaddr.h" #include "snoopy.h" #include "util/utmp-snoopy.h" #include #include #include #include #define SNOOPY_DS_IPADDR_TTY_PATH_BUF_LEN UT_LINESIZE + 5 // +5 for the initial "/dev/" /* * SNOOPY DATA SOURCE: ipaddr * * Description: * Returns IP address of the TTY that is connected to the current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_ipaddr (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { char ttyPathBuf[SNOOPY_DS_IPADDR_TTY_PATH_BUF_LEN]; struct utmp utmpEntryBuf; struct utmp * utmpEntry = &utmpEntryBuf; int retVal; // Get the TTY path ttyPathBuf[0] = '\0'; retVal = ttyname_r(STDIN_FILENO, ttyPathBuf, SNOOPY_DS_IPADDR_TTY_PATH_BUF_LEN); if (0 != retVal) { return snprintf(resultBuf, resultBufSize, "-"); } ttyPathBuf[SNOOPY_DS_IPADDR_TTY_PATH_BUF_LEN-1] = '\0'; // Find the matching utmp entry if (SNOOPY_TRUE != snoopy_util_utmp_findUtmpEntryByPath(ttyPathBuf, utmpEntry)) { return snprintf(resultBuf, resultBufSize, "-"); // This can happen, i.e. in in a `docker run ...` environment } // Does the associated IP address actually exist? if (SNOOPY_TRUE != snoopy_util_utmp_doesEntryContainIpAddr(utmpEntry)) { return snprintf(resultBuf, resultBufSize, "-"); } // Convert to string IP address snoopy_util_utmp_getUtmpIpAddrAsString(utmpEntry, resultBuf, resultBufSize); // Clean up return (int) strlen(resultBuf); } snoopy-snoopy-2.5.2/src/datasource/ipaddr.h000066400000000000000000000016461470651710700207500ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" int snoopy_datasource_ipaddr (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/login.c000066400000000000000000000054041470651710700206040ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/login.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "login.h" #include "snoopy.h" #include #include #include #include /* * Local defines */ #define SNOOPY_DATASOURCE_LOGIN_loginSizeMaxWithoutNull 254 #define SNOOPY_DATASOURCE_LOGIN_loginSizeMaxWithNull 255 /* * SNOOPY DATA SOURCE: login * * Description: * Returns literal login name of logged-in user executing this process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_login (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { int loginSizeMaxWithoutNull = SNOOPY_DATASOURCE_LOGIN_loginSizeMaxWithoutNull; int loginSizeMaxWithNull = SNOOPY_DATASOURCE_LOGIN_loginSizeMaxWithNull; static char login[SNOOPY_DATASOURCE_LOGIN_loginSizeMaxWithNull]; const char * loginptr = NULL; /* * Retrive the user login trying in order: * - The login information from the processus. * - the SUDO_USER environment variable. * - the LOGNAME environment variable. * * TIP to use with sudo and keep LOGNAME, add this in /etc/sudoers: * Defaults env_reset * Defaults env_keep="LOGNAME" */ if (0 != getlogin_r(login, loginSizeMaxWithNull)) { loginptr = getenv("SUDO_USER"); if (!loginptr) { loginptr = getenv("LOGNAME"); } if (!loginptr) { strcpy(login, "(unknown)"); } else { strncpy(login, loginptr, loginSizeMaxWithoutNull); // Coverity suggests using -1 size here if ((int)strlen(loginptr) > loginSizeMaxWithoutNull) { login[loginSizeMaxWithoutNull] = '\0'; } } } return snprintf(resultBuf, resultBufSize, "%s", login); } snoopy-snoopy-2.5.2/src/datasource/login.h000066400000000000000000000017571470651710700206200ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/login.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: login */ int snoopy_datasource_login (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/noop.c000066400000000000000000000024561470651710700204530ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/noop.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "noop.h" /* * SNOOPY DATA SOURCE: noop * * Description: * Does nothing. * * Params: * result: (ignored) * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_noop (__attribute__((unused)) char * const resultBuf, __attribute__((unused)) size_t resultBufSize, __attribute__((unused)) char const * const arg) { return 0; } snoopy-snoopy-2.5.2/src/datasource/noop.h000066400000000000000000000017541470651710700204600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/noop.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: noop */ int snoopy_datasource_noop (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/pid.c000066400000000000000000000026671470651710700202600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/pid.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "pid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: pid * * Description: * Returns PID (process ID) of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_pid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getpid()); } snoopy-snoopy-2.5.2/src/datasource/pid.h000066400000000000000000000017441470651710700202600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/pid.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: pid */ int snoopy_datasource_pid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/ppid.c000066400000000000000000000027041470651710700204300ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/ppid.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "ppid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: ppid * * Description: * Returns PPID (parent process ID) of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_ppid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getppid()); } snoopy-snoopy-2.5.2/src/datasource/ppid.h000066400000000000000000000017471470651710700204430ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/ppid.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: ppid */ int snoopy_datasource_ppid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/rpname.c000066400000000000000000000143721470651710700207620ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/rpname.c * * Copyright (c) 2015 Ariel Zach * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include "rpname.h" #include "snoopy.h" #include #include #include #include #include #include #include /* * Local defines */ #define ST_PATH_SIZE_MAX 32 // Path "/proc/nnnn/stat" where nnnn = some PID #define PID_ROOT 1 #define PID_ZERO 0 // In containers, if attached from the host #define PID_UNKNOWN -1 #define PROC_PID_STATUS_KEY_NAME "Name" #define PROC_PID_STATUS_KEY_PPID "PPid" #define PROC_PID_STATUS_VAL_MAX_LENGTH NAME_MAX // Pid is max 2^22 (7-digit number), name can be max 255 bytes #define PROC_PID_STATUS_VAL_MAX_LENGTH_STR PROC_PID_STATUS_VAL_MAX_LENGTH + 1 // +1 for null termination #define UNKNOWN_STR "(unknown)" /* * Non-public function prototypes */ static int get_parent_pid (int pid); static int get_rpname (int pid, char *resultBuf, size_t resultBufSize); static char* read_proc_property (int pid, const char * prop_name); /* * SNOOPY DATA SOURCE: rpname * * Description: * Returns root process name of current process tree. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_rpname (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return get_rpname(getpid(), resultBuf, resultBufSize); } /* Read /proc/{pid}/status file and extract the property */ static char* read_proc_property (int pid, const char * prop_name) { char pid_file[ST_PATH_SIZE_MAX]; FILE *fp; char *line = NULL; size_t lineLen = 0; const char *k; char *v; size_t vLen = 0; char returnValue[PROC_PID_STATUS_VAL_MAX_LENGTH_STR] = ""; /* Open file or return */ snprintf(pid_file, ST_PATH_SIZE_MAX, "/proc/%d/status", pid); fp = fopen(pid_file, "r"); if (NULL == fp) { return NULL; } /* Read line by line */ while (getline(&line, &lineLen, fp) != -1) { /* * Bail out on the following two conditions: * - If line is empty, bail out - no such thing in /proc/PID/status. * - The format must be "prop_name: value". * Otherwise bail out altogether - something must be wrong with this /proc/PID/status file. */ if ((0 == lineLen) || (NULL == strstr(line, ":"))){ goto RETURN_FREE_LINE_AND_CLOSE_FILE; } /* * Separate line content into two tokens: key and value * If separation fails, continue to the next line ("Groups:" key is one such example) */ k = line; v = strchr(line, ':'); if (NULL == v) { continue; } *v = '\0'; v++; /* The key we are looking for? */ if (strcmp(prop_name, k) == 0) { /* Yes! */ v++; // There is one tab in front of PID number vLen = strlen(v); v[vLen-1] = 0; // Terminate the newline at the end of value vLen--; // Length is now shorter for 1 character /* * Choose string copy mode depending on length of PID * - prevent segfault if sth happens to MAX PID in future */ if (vLen > PROC_PID_STATUS_VAL_MAX_LENGTH) { strncpy(returnValue, v, PROC_PID_STATUS_VAL_MAX_LENGTH); returnValue[PROC_PID_STATUS_VAL_MAX_LENGTH_STR-1] = 0; // Change newline into null character } else { strncpy(returnValue, v, PROC_PID_STATUS_VAL_MAX_LENGTH_STR-1); } // Do a cleanup and return a string duplicate, which should be freed by the caller free(line); fclose(fp); return strdup(returnValue); } /* * Line is not freed between subsequent iteration as the same buffer is reused * (and realloc()-ed if required) */ } RETURN_FREE_LINE_AND_CLOSE_FILE: /* Only free if this was actually allocated */ if (NULL != line) { free(line); } fclose(fp); return NULL; } /* Get parent pid */ static int get_parent_pid (int pid) { char *ppid_str; int ppid_int; ppid_str = read_proc_property(pid, PROC_PID_STATUS_KEY_PPID); if (NULL != ppid_str) { ppid_int = atoi(ppid_str); free(ppid_str); return ppid_int; } return PID_UNKNOWN; } /* Find root process name */ static int get_rpname (int pid, char *resultBuf, size_t resultBufSize) { int parentPid; char *name; size_t nameLen; parentPid = get_parent_pid(pid); if ((PID_ROOT == parentPid) || (PID_ZERO == parentPid)) { name = read_proc_property(pid, PROC_PID_STATUS_KEY_NAME); if (NULL != name) { nameLen = snprintf(resultBuf, resultBufSize, "%s", name); free(name); } else { nameLen = snprintf(resultBuf, resultBufSize, "%s", UNKNOWN_STR); } return (int) nameLen; } else if (PID_UNKNOWN == parentPid) { return snprintf(resultBuf, resultBufSize, "%s", UNKNOWN_STR); } else { return get_rpname(parentPid, resultBuf, resultBufSize); } } snoopy-snoopy-2.5.2/src/datasource/rpname.h000066400000000000000000000017551470651710700207700ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/rpname.h * * Copyright (c) 2015 Ariel Zach * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: rpname */ int snoopy_datasource_rpname (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/sid.c000066400000000000000000000031011470651710700202430ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/sid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "sid.h" #include "snoopy.h" #ifndef _XOPEN_SOURCE /* Needed to get getpgid and getsid on older glibc */ #define _XOPEN_SOURCE 500 #endif #include #include #include /* * SNOOPY DATA SOURCE: sid * * Description: * Returns SID (Session leader process ID) of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_sid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getsid(0)); } snoopy-snoopy-2.5.2/src/datasource/sid.h000066400000000000000000000017511470651710700202610ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/sid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: sid */ int snoopy_datasource_sid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/snoopy_configure_command.c000066400000000000000000000031101470651710700245520ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_configure_command.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy_configure_command.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: snoopy_configure_command * * Description: * Dummy data source that returns the configure command that was used to build Snoopy. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_snoopy_configure_command (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%s", SNOOPY_CONFIGURE_COMMAND); } snoopy-snoopy-2.5.2/src/datasource/snoopy_configure_command.h000066400000000000000000000020501470651710700245610ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_configure_command.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: snoopy_configure_command */ int snoopy_datasource_snoopy_configure_command (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/snoopy_literal.c000066400000000000000000000027311470651710700225370ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_literal.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy_literal.h" #include "snoopy.h" #include /* * SNOOPY DATA SOURCE: snoopy_literal * * Description: * Dummy data source that returns literal string that is passed to it as argument. * * Params: * result: pointer to string, to write result into * arg: string to copy into the result * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_snoopy_literal (char * const resultBuf, size_t resultBufSize, char const * const arg) { return snprintf(resultBuf, resultBufSize, "%s", arg); } snoopy-snoopy-2.5.2/src/datasource/snoopy_literal.h000066400000000000000000000020051470651710700225360ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_literal.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: snoopy_literal */ int snoopy_datasource_snoopy_literal (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/snoopy_threads.c000066400000000000000000000030731470651710700225350ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_threads.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy_version.h" #include "snoopy.h" #include "tsrm.h" #include #include #include /* * SNOOPY DATA SOURCE: snoopy_threads * * Description: * Return count of threads that are currently configured in Snoopy's * thread repository. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_snoopy_threads (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%d", snoopy_tsrm_get_threadCount()); } snoopy-snoopy-2.5.2/src/datasource/snoopy_threads.h000066400000000000000000000020051470651710700225340ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_threads.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: snoopy_threads */ int snoopy_datasource_snoopy_threads (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/snoopy_version.c000066400000000000000000000031621470651710700225670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_version.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy_version.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: snoopy_version * * Description: * Dummy data source that returns Snoopy version. * * Notice: * This function has been made public for `snoopy version` CLI command. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ __attribute__((visibility("default"))) int snoopy_datasource_snoopy_version (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%s", SNOOPY_VERSION); } snoopy-snoopy-2.5.2/src/datasource/snoopy_version.h000066400000000000000000000020121470651710700225650ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/snoopy_version.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: snoopy_version */ int snoopy_datasource_snoopy_version (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/systemd-unit-name.c000066400000000000000000000041251470651710700230560ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "systemd-unit-name.h" #include "cgroup.h" #include "snoopy.h" #include "util/systemd-snoopy.h" #include #include #include int snoopy_datasource_systemd_unit_name (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { char *cgroupEntry = NULL; int cgroupDsRetVal; char *unitName = NULL; int retMsgLen; // Get the cgroup entry cgroupEntry = malloc(resultBufSize); cgroupDsRetVal = snoopy_datasource_cgroup(cgroupEntry, resultBufSize, "name=systemd"); if ( (cgroupDsRetVal == SNOOPY_DATASOURCE_FAILURE) || (0 == strcmp(cgroupEntry, "(none)")) ) { snprintf(resultBuf, resultBufSize, "Cgroup entry 'name=systemd' not found"); free(cgroupEntry); return SNOOPY_DATASOURCE_FAILURE; } // Convert unitName = snoopy_util_systemd_convertCgroupEntryToUnitName(cgroupEntry); if (!unitName) { retMsgLen = snprintf(resultBuf, resultBufSize, "%s", cgroupEntry+strlen("1:name=systemd:/")); free(cgroupEntry); return retMsgLen; } free(cgroupEntry); // Return retMsgLen = snprintf(resultBuf, resultBufSize, "%s", unitName); free(unitName); return retMsgLen; } snoopy-snoopy-2.5.2/src/datasource/systemd-unit-name.h000066400000000000000000000017411470651710700230640ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: systemd_unit_name */ int snoopy_datasource_systemd_unit_name (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/tid.c000066400000000000000000000035461470651710700202610ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tid.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "tid.h" #include "snoopy.h" #include #include /* * SNOOPY DATA SOURCE: tid * * Description: * Returns TID (thread ID) of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_tid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { // Musl (on Alpine 3.16) has pthread_t defined as 'unsigned long', but glibc // defines it as 'unsigned long int'. // SonarCloud complains about redundant cast, but not doing this cast makes // build fail on Alpine 3.16. long unsigned tid = (long unsigned) pthread_self(); // This happens if -lpthread is not given to compiler if (0 == tid) { return snprintf(resultBuf, resultBufSize, "(error @ pthread_self())"); } return snprintf(resultBuf, resultBufSize, "%lu", tid); } snoopy-snoopy-2.5.2/src/datasource/tid.h000066400000000000000000000017441470651710700202640ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tid.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: tid */ int snoopy_datasource_tid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/tid_kernel.c000066400000000000000000000034111470651710700216100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tid_kernel.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #define _GNU_SOURCE #include "tid_kernel.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: tid_kernel * * Description: * Returns tid (thread ID) of current process. Queries kernel for it via * syscall SYS_gettid. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_tid_kernel (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { long unsigned int tid = (long unsigned int) syscall(SYS_gettid); // This happens if -lpthread is not given to compiler if (0 == tid) { return snprintf(resultBuf, resultBufSize, "(error @ syscall(SYS_gettid))"); } return snprintf(resultBuf, resultBufSize, "%lu", tid); } snoopy-snoopy-2.5.2/src/datasource/tid_kernel.h000066400000000000000000000017711470651710700216240ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tid_kernel.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: tid_kernel */ int snoopy_datasource_tid_kernel (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/timestamp.c000066400000000000000000000032271470651710700215000ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "timestamp.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: timestamp * * Description: * Returns current Unix timestamp. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_timestamp (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct timeval tv; int retVal; retVal = gettimeofday(&tv, NULL); if (0 == retVal) { return snprintf(resultBuf, resultBufSize, "%d", (int) tv.tv_sec); } else { return snprintf(resultBuf, resultBufSize, "(error: %d)", errno); } } snoopy-snoopy-2.5.2/src/datasource/timestamp.h000066400000000000000000000017661470651710700215130ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: timestamp */ int snoopy_datasource_timestamp (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/timestamp_ms.c000066400000000000000000000033001470651710700221670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp_ms.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "timestamp_ms.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: timestamp_ms * * Description: * Returns milliseconds part of current Unix timestamp. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_timestamp_ms (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct timeval tv; int retVal; retVal = gettimeofday(&tv, NULL); if (0 == retVal) { return snprintf(resultBuf, resultBufSize, "%03d", (int) tv.tv_usec/1000); } else { return snprintf(resultBuf, resultBufSize, "(error: %d)", errno); } } snoopy-snoopy-2.5.2/src/datasource/timestamp_ms.h000066400000000000000000000017771470651710700222140ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp_ms.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: timestamp_ms */ int snoopy_datasource_timestamp_ms (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/timestamp_us.c000066400000000000000000000032731470651710700222100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp_us.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "timestamp_us.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: timestamp_us * * Description: * Returns milliseconds part of current Unix timestamp. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_timestamp_us (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { struct timeval tv; int retVal; retVal = gettimeofday(&tv, NULL); if (0 == retVal) { return snprintf(resultBuf, resultBufSize, "%06d", (int) tv.tv_usec); } else { return snprintf(resultBuf, resultBufSize, "(error: %d)", errno); } } snoopy-snoopy-2.5.2/src/datasource/timestamp_us.h000066400000000000000000000017771470651710700222240ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/timestamp_us.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: timestamp_us */ int snoopy_datasource_timestamp_us (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/tty.c000066400000000000000000000040571470651710700203170ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "tty.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: tty * * Description: * Returns TTY of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_tty (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { char ttyPath[SNOOPY_DATASOURCE_TTY_sizeMaxWithNull]; size_t ttyPathLen = SNOOPY_DATASOURCE_TTY_sizeMaxWithoutNull; int retVal; retVal = ttyname_r(0, ttyPath, ttyPathLen); if (0 != retVal) { if (EBADF == retVal) { return snprintf(resultBuf, resultBufSize, "ERROR(ttyname_r->EBADF)"); } if (ERANGE == retVal) { return snprintf(resultBuf, resultBufSize, "ERROR(ttyname_r->ERANGE)"); } if (ENOTTY == retVal) { return snprintf(resultBuf, resultBufSize, "(none)"); } return snprintf(resultBuf, resultBufSize, "(unknown)"); } return snprintf(resultBuf, resultBufSize, "%s", ttyPath); } snoopy-snoopy-2.5.2/src/datasource/tty.h000066400000000000000000000022321470651710700203150ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * Local defines */ #define SNOOPY_DATASOURCE_TTY_sizeMaxWithoutNull 4096 // PATH_MAX does not work here? #define SNOOPY_DATASOURCE_TTY_sizeMaxWithNull 4097 /* * SNOOPY DATA SOURCE: tty */ int snoopy_datasource_tty (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/tty__common.c000066400000000000000000000047171470651710700220310ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty__common.c * * Copyright (c) 2020-2020 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "tty__common.h" #include "tty.h" #include "snoopy.h" #include #include #include #include #include #include #include /* * SNOOPY DATA SOURCE HELPER: get_tty_uid * * Description: * Returns UID (User ID) of current controlling terminal, or -1 if not found. * * Params: * ttyUid: pointer to uid_t to store the result into * result: pointer to string, to write the error into * * Return: * - 0 on success (result in ttyUid) * - number of characters in the returned string on error */ int snoopy_datasource_tty__get_tty_uid (uid_t * ttyUid, char * const resultBuf, size_t resultBufSize) { char ttyPath[SNOOPY_DATASOURCE_TTY_sizeMaxWithNull]; size_t ttyPathLen = SNOOPY_DATASOURCE_TTY_sizeMaxWithoutNull; int retVal; struct stat statbuffer; /* Get tty path */ retVal = ttyname_r(0, ttyPath, ttyPathLen); if (0 != retVal) { if (EBADF == retVal) { return snprintf(resultBuf, resultBufSize, "ERROR(ttyname_r->EBADF)"); } if (ERANGE == retVal) { return snprintf(resultBuf, resultBufSize, "ERROR(ttyname_r->ERANGE)"); } if (ENOTTY == retVal) { return snprintf(resultBuf, resultBufSize, "(none)"); } return snprintf(resultBuf, resultBufSize, "(unknown)"); } /* Get owner of tty */ if (-1 == stat(ttyPath, &statbuffer)) { return snprintf(resultBuf, resultBufSize, "ERROR(unable to stat() %s)", ttyPath); } *ttyUid = statbuffer.st_uid; return 0; } snoopy-snoopy-2.5.2/src/datasource/tty__common.h000066400000000000000000000020751470651710700220310ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty__common.h * * Copyright (c) 2020-2020 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" #include "snoopy.h" #include /* * SNOOPY DATA SOURCE: tty-related common functions */ int snoopy_datasource_tty__get_tty_uid (uid_t * ttyUid, char * const resultBuf, size_t resultBufSize); snoopy-snoopy-2.5.2/src/datasource/tty_uid.c000066400000000000000000000035371470651710700211620ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty_uid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "tty_uid.h" #include "tty__common.h" #include "tty.h" #include "snoopy.h" #include #include #include #include #include #include #include /* * SNOOPY DATA SOURCE: tty_uid * * Description: * Returns UID (User ID) of current controlling terminal, or -1 if not found. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_tty_uid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { int retVal; uid_t ttyUid; retVal = snoopy_datasource_tty__get_tty_uid(&ttyUid, resultBuf, resultBufSize); if (retVal > 0) { return retVal; // Error occurred, and the message about it is already in the result buffer } return snprintf(resultBuf, resultBufSize, "%u", ttyUid); } snoopy-snoopy-2.5.2/src/datasource/tty_uid.h000066400000000000000000000017651470651710700211700ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty_uid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: tty_uid */ int snoopy_datasource_tty_uid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/tty_username.c000066400000000000000000000041241470651710700222110ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty_username.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "tty_username.h" #include "tty__common.h" #include "tty.h" #include "snoopy.h" #include "util/pwd-snoopy.h" #include #include /* * SNOOPY DATA SOURCE: tty_username * * Description: * Returns litaral username of current controlling terminal * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_tty_username (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { int retVal; uid_t ttyUid; char *username = NULL; int retMsgLen = 0; /* Get tty UID */ retVal = snoopy_datasource_tty__get_tty_uid(&ttyUid, resultBuf, resultBufSize); if (retVal > 0) { return retVal; // Error occurred, and the message about it is already in the result buffer } username = snoopy_util_pwd_convertUidToUsername(ttyUid); if (username == NULL) { return snprintf(resultBuf, resultBufSize, "Unable to convert UID to username"); } retMsgLen = snprintf(resultBuf, resultBufSize, "%s", username); free(username); return retMsgLen; } snoopy-snoopy-2.5.2/src/datasource/tty_username.h000066400000000000000000000020041470651710700222110ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty_username.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: tty_username */ int snoopy_datasource_tty_username (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/uid.c000066400000000000000000000026711470651710700202600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/uid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "uid.h" #include "snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: uid * * Description: * Returns UID (User ID) of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_uid (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { return snprintf(resultBuf, resultBufSize, "%u", getuid()); } snoopy-snoopy-2.5.2/src/datasource/uid.h000066400000000000000000000017511470651710700202630ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/uid.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: uid */ int snoopy_datasource_uid (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasource/username.c000066400000000000000000000034141470651710700213120ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/username.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "username.h" #include "snoopy.h" #include "util/pwd-snoopy.h" #include #include #include /* * SNOOPY DATA SOURCE: username * * Description: * Returns literal username of current process * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_datasource_username (char * const resultBuf, size_t resultBufSize, __attribute__((unused)) char const * const arg) { char * username = NULL; int retMsgLen = 0; username = snoopy_util_pwd_convertUidToUsername(getuid()); if (username == NULL) { return snprintf(resultBuf, resultBufSize, "Unable to convert UID to username"); } retMsgLen = snprintf(resultBuf, resultBufSize, "%s", username); free(username); return retMsgLen; } snoopy-snoopy-2.5.2/src/datasource/username.h000066400000000000000000000017701470651710700213220ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/username.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "datasource-common.h" /* * SNOOPY DATA SOURCE: username */ int snoopy_datasource_username (char * const resultBuf, size_t resultBufSize, char const * const arg); snoopy-snoopy-2.5.2/src/datasourceregistry.c000066400000000000000000000304461470651710700212710ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: datasourceregistry.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "datasourceregistry.h" #include "snoopy.h" #include "genericregistry.h" #include /* * Include headers of all datasource functions */ #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cgroup #include "datasource/cgroup.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline #include "datasource/cmdline.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cwd #include "datasource/cwd.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_datetime #include "datasource/datetime.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_domain #include "datasource/domain.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egid #include "datasource/egid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egroup #include "datasource/egroup.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env #include "datasource/env.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env_all #include "datasource/env_all.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_euid #include "datasource/euid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_eusername #include "datasource/eusername.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_filename #include "datasource/filename.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_gid #include "datasource/gid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_group #include "datasource/group.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_hostname #include "datasource/hostname.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr #include "datasource/ipaddr.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_login #include "datasource/login.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_pid #include "datasource/pid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ppid #include "datasource/ppid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_rpname #include "datasource/rpname.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_sid #include "datasource/sid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_configure_command #include "datasource/snoopy_configure_command.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_literal #include "datasource/snoopy_literal.h" #endif #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_threads #include "datasource/snoopy_threads.h" #endif #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_version #include "datasource/snoopy_version.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name #include "datasource/systemd-unit-name.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid #include "datasource/tid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid_kernel #include "datasource/tid_kernel.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp #include "datasource/timestamp.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_ms #include "datasource/timestamp_ms.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_us #include "datasource/timestamp_us.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty #include "datasource/tty.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_uid #include "datasource/tty_uid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_username #include "datasource/tty_username.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_uid #include "datasource/uid.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_username #include "datasource/username.h" #endif /* This prevents "ISO C forbids empty initializer braces" error */ #include "datasource/failure.h" #include "datasource/noop.h" /* * Two arrays holding data about all data sources */ char* snoopy_datasourceregistry_names[] = { #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cgroup "cgroup", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline "cmdline", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cwd "cwd", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_datetime "datetime", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_domain "domain", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egid "egid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egroup "egroup", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env "env", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env_all "env_all", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_euid "euid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_eusername "eusername", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_filename "filename", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_gid "gid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_group "group", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_hostname "hostname", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr "ipaddr", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_login "login", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_pid "pid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ppid "ppid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_rpname "rpname", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_sid "sid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_configure_command "snoopy_configure_command", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_literal "snoopy_literal", #endif #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_threads "snoopy_threads", #endif #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_version "snoopy_version", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name "systemd_unit_name", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid "tid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid_kernel "tid_kernel", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp "timestamp", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_ms "timestamp_ms", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_us "timestamp_us", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty "tty", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_uid "tty_uid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_username "tty_username", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_uid "uid", #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_username "username", #endif /* This prevents "ISO C forbids empty initializer braces" error */ "failure", "noop", "", }; int (*snoopy_datasourceregistry_ptrs []) (char * const resultBuf, size_t resultBufSize, char const * const arg) = { #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cgroup snoopy_datasource_cgroup, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline snoopy_datasource_cmdline, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cwd snoopy_datasource_cwd, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_datetime snoopy_datasource_datetime, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_domain snoopy_datasource_domain, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egid snoopy_datasource_egid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_egroup snoopy_datasource_egroup, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env snoopy_datasource_env, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_env_all snoopy_datasource_env_all, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_euid snoopy_datasource_euid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_eusername snoopy_datasource_eusername, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_filename snoopy_datasource_filename, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_gid snoopy_datasource_gid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_group snoopy_datasource_group, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_hostname snoopy_datasource_hostname, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr snoopy_datasource_ipaddr, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_login snoopy_datasource_login, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_pid snoopy_datasource_pid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ppid snoopy_datasource_ppid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_rpname snoopy_datasource_rpname, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_sid snoopy_datasource_sid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_configure_command snoopy_datasource_snoopy_configure_command, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_literal snoopy_datasource_snoopy_literal, #endif #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_threads snoopy_datasource_snoopy_threads, #endif #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_snoopy_version snoopy_datasource_snoopy_version, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name snoopy_datasource_systemd_unit_name, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid snoopy_datasource_tid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tid_kernel snoopy_datasource_tid_kernel, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp snoopy_datasource_timestamp, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_ms snoopy_datasource_timestamp_ms, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_timestamp_us snoopy_datasource_timestamp_us, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty snoopy_datasource_tty, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_uid snoopy_datasource_tty_uid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_tty_username snoopy_datasource_tty_username, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_uid snoopy_datasource_uid, #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_username snoopy_datasource_username, #endif /* This prevents "ISO C forbids empty initializer braces" error */ snoopy_datasource_failure, snoopy_datasource_noop, }; /* * getCount() * * Return number of available datasources */ int snoopy_datasourceregistry_getCount () { return snoopy_genericregistry_getCount(snoopy_datasourceregistry_names); } /* * doesIdExist() * * True if datasource exists (by id), otherwise false */ int snoopy_datasourceregistry_doesIdExist (int datasourceId) { return snoopy_genericregistry_doesIdExist(snoopy_datasourceregistry_names, datasourceId); } /* * doesNameExist() * * True if datasource exists (by name), otherwise false */ int snoopy_datasourceregistry_doesNameExist (char const * const datasourceName) { return snoopy_genericregistry_doesNameExist(snoopy_datasourceregistry_names, datasourceName); } /* * getIdFromName() * * Return index of given datasource, or -1 if not found */ int snoopy_datasourceregistry_getIdFromName (char const * const datasourceName) { return snoopy_genericregistry_getIdFromName(snoopy_datasourceregistry_names, datasourceName); } /* * getName() * * Return name of given datasource, or NULL */ char* snoopy_datasourceregistry_getName (int datasourceId) { return snoopy_genericregistry_getName(snoopy_datasourceregistry_names, datasourceId); } /* * callById() * * Call the given datasource by id and return its output */ int snoopy_datasourceregistry_callById (int datasourceId, char * const resultBuf, size_t resultBufSize, char const * const datasourceArg) { if (SNOOPY_FALSE == snoopy_datasourceregistry_doesIdExist(datasourceId)) { return -1; } return snoopy_datasourceregistry_ptrs[datasourceId](resultBuf, resultBufSize, datasourceArg); } /* * callByName() * * Call the given datasource by name and return its output */ int snoopy_datasourceregistry_callByName (char const * const datasourceName, char * const resultBuf, size_t resultBufSize, char const * const datasourceArg) { int datasourceId; datasourceId = snoopy_datasourceregistry_getIdFromName(datasourceName); if (datasourceId == -1) { return -1; } return snoopy_datasourceregistry_ptrs[datasourceId](resultBuf, resultBufSize, datasourceArg); } snoopy-snoopy-2.5.2/src/datasourceregistry.h000066400000000000000000000030641470651710700212720ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: datasourceregistry.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include /* * Functions to manage and utilise datasources */ int snoopy_datasourceregistry_getCount (); int snoopy_datasourceregistry_doesIdExist (int datasourceId); int snoopy_datasourceregistry_doesNameExist (char const * const datasourceName); int snoopy_datasourceregistry_getIdFromName (char const * const datasourceName); char* snoopy_datasourceregistry_getName (int datasourceId); int snoopy_datasourceregistry_callById (int datasourceId, char * const resultBuf, size_t resultBufSize, char const * const datasourceArg); int snoopy_datasourceregistry_callByName (char const * const datasourceName, char * const resultBuf, size_t resultBufSize, char const * const datasourceArg); snoopy-snoopy-2.5.2/src/entrypoint/000077500000000000000000000000001470651710700174065ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/entrypoint/Makefile.am000066400000000000000000000030611470651710700214420ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Adjust cflags # # Exclude -Wpedantic from directory-level CFLAGS, because casting object pointer # received from dlsym() to function pointer is not allowed by ISO C. # # Earlier we had this enabled on a per-make-target basis, like this: # libsnoopy_eventsource_execve_wrapper_la_CFLAGS = `echo $(AM_CFLAGS) | sed -e 's/-Wpedantic//'` # Unfortunately, that produced prefixed .o|.gcna files, which were messing with # our code coverage analysis. # AM_CFLAGS += -Wno-pedantic ### Variables to add final build targets to # noinst_LTLIBRARIES = ### Library entry points # # Maintain alphabetical order, equal to what `ls` would do. # # Production entry point (for loaded library) noinst_LTLIBRARIES += libsnoopy-entrypoint-execve-wrapper.la libsnoopy_entrypoint_execve_wrapper_la_SOURCES = \ execve-wrapper.c \ execve-wrapper.h # Production entry point (for `snoopyctl` CLI utility) noinst_LTLIBRARIES += libsnoopy-entrypoint-cli.la libsnoopy_entrypoint_cli_la_SOURCES = \ cli.c \ cli.h # Test-related entry point (for loaded library) noinst_LTLIBRARIES += libsnoopy-entrypoint-execve-wrapper-test-configfile-env.la libsnoopy_entrypoint_execve_wrapper_test_configfile_env_la_SOURCES = \ execve-wrapper-test-configfile-env.c \ execve-wrapper-test-configfile-env.h # Test-related entry point (for `snoopy-test` CLI utility) noinst_LTLIBRARIES += libsnoopy-entrypoint-test-cli.la libsnoopy_entrypoint_test_cli_la_SOURCES = \ test-cli.c \ test-cli.h snoopy-snoopy-2.5.2/src/entrypoint/cli.c000066400000000000000000000025741470651710700203310ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "cli.h" #include "snoopy.h" #include "init-deinit.h" #include "configuration.h" #include "inputdatastorage.h" #include __attribute__((visibility("default"))) void snoopy_entrypoint_cli_init () { snoopy_init(); snoopy_inputdatastorage_store_filename("snoopy-cli"); char *argv[] = { NULL }; snoopy_inputdatastorage_store_argv(argv); char *envp[] = { NULL }; snoopy_inputdatastorage_store_envp(envp); } __attribute__((visibility("default"))) void snoopy_entrypoint_cli_exit () { snoopy_cleanup(); } snoopy-snoopy-2.5.2/src/entrypoint/cli.h000066400000000000000000000015421470651710700203300ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ void snoopy_entrypoint_cli_init (); void snoopy_entrypoint_cli_exit (); snoopy-snoopy-2.5.2/src/entrypoint/execve-wrapper-test-configfile-env.c000066400000000000000000000055641470651710700263670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2000 Marius Aamodt Eriksen * Copyright (c) 2000 Mike Baker * Copyright (c) 2010-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "execve-wrapper-test-configfile-env.h" #include "snoopy.h" #include "init-deinit.h" #include "action/log-syscall-exec.h" #include "configuration.h" #include "inputdatastorage.h" #include #include /* * Helpers to find pointer to overloaded function */ #if defined(RTLD_NEXT) # define REAL_LIBC RTLD_NEXT #else # define REAL_LIBC ((void *) -1L) #endif #define FN(ptr, type, name, args) ptr = (type (*)args)dlsym (REAL_LIBC, name) /* * Function wrapper - execv() */ __attribute__((visibility("default"))) int execv (const char *filename, char *const argv[]) { static int (*func)(const char *, char * const *); FN(func, int, "execv", (const char *, char * const *)); char *envp[] = { NULL }; snoopy_entrypoint_execve_wrapper_test_configfile_env_init(filename, argv, envp); snoopy_action_log_syscall_exec(); snoopy_entrypoint_execve_wrapper_test_configfile_env_exit(); return (*func) (filename, argv); } /* * Function wrapper - execve() */ __attribute__((visibility("default"))) int execve (const char *filename, char *const argv[], char *const envp[]) { static int (*func)(const char *, char * const *, char * const *); FN(func, int, "execve", (const char *, char * const *, char * const *)); snoopy_entrypoint_execve_wrapper_test_configfile_env_init(filename, argv, envp); snoopy_action_log_syscall_exec(); snoopy_entrypoint_execve_wrapper_test_configfile_env_exit(); return (*func) (filename, argv, envp); } void snoopy_entrypoint_execve_wrapper_test_configfile_env_init (const char *filename, char *const argv[], char *const envp[]) { snoopy_configuration_preinit_setConfigFilePathFromEnv(); snoopy_init(); snoopy_inputdatastorage_store_filename(filename); snoopy_inputdatastorage_store_argv(argv); snoopy_inputdatastorage_store_envp(envp); } void snoopy_entrypoint_execve_wrapper_test_configfile_env_exit () { snoopy_cleanup(); } snoopy-snoopy-2.5.2/src/entrypoint/execve-wrapper-test-configfile-env.h000066400000000000000000000022421470651710700263620ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2010-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Wrapper functions for libc */ int execv (const char *filename, char *const argv[]); int execve (const char *filename, char *const argv[], char *const envp[]); /* * Our functions */ void snoopy_entrypoint_execve_wrapper_test_configfile_env_init (const char *filename, char *const argv[], char *const envp[]); void snoopy_entrypoint_execve_wrapper_test_configfile_env_exit (); snoopy-snoopy-2.5.2/src/entrypoint/execve-wrapper.c000066400000000000000000000053311470651710700225110ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2000 Marius Aamodt Eriksen * Copyright (c) 2000 Mike Baker * Copyright (c) 2010-2015 Bostjan Skufca * * Part hacked on flight KL 0617, 30,000 ft or so over the Atlantic :) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "execve-wrapper.h" #include "snoopy.h" #include "init-deinit.h" #include "action/log-syscall-exec.h" #include "inputdatastorage.h" #include #include /* * Helpers to find pointer to overloaded function */ #if defined(RTLD_NEXT) # define REAL_LIBC RTLD_NEXT #else # define REAL_LIBC ((void *) -1L) #endif #define FN(ptr, type, name, args) ptr = (type (*)args)dlsym (REAL_LIBC, name) /* * Function wrapper - execv() */ __attribute__((visibility("default"))) int execv (const char *filename, char *const argv[]) { static int (*func)(const char *, char * const *); FN(func, int, "execv", (const char *, char * const *)); char *envp[] = { NULL }; snoopy_entrypoint_execve_wrapper_init(filename, argv, envp); snoopy_action_log_syscall_exec(); snoopy_entrypoint_execve_wrapper_exit(); return (*func) (filename, argv); } /* * Function wrapper - execve() */ __attribute__((visibility("default"))) int execve (const char *filename, char *const argv[], char *const envp[]) { static int (*func)(const char *, char * const *, char * const *); FN(func, int, "execve", (const char *, char * const *, char * const *)); snoopy_entrypoint_execve_wrapper_init(filename, argv, envp); snoopy_action_log_syscall_exec(); snoopy_entrypoint_execve_wrapper_exit(); return (*func) (filename, argv, envp); } void snoopy_entrypoint_execve_wrapper_init (const char *filename, char *const argv[], char *const envp[]) { snoopy_init(); snoopy_inputdatastorage_store_filename(filename); snoopy_inputdatastorage_store_argv(argv); snoopy_inputdatastorage_store_envp(envp); } void snoopy_entrypoint_execve_wrapper_exit () { snoopy_cleanup(); } snoopy-snoopy-2.5.2/src/entrypoint/execve-wrapper.h000066400000000000000000000024641470651710700225220ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2000 Marius Aamodt Eriksen * Copyright (c) 2000 Mike Baker * Copyright (c) 2010-2015 Bostjan Skufca * * Part hacked on flight KL 0617, 30,000 ft or so over the Atlantic :) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Wrapper functions for libc */ int execv (const char *filename, char *const argv[]); int execve (const char *filename, char *const argv[], char *const envp[]); /* * Our functions */ void snoopy_entrypoint_execve_wrapper_init (const char *filename, char *const argv[], char *const envp[]); void snoopy_entrypoint_execve_wrapper_exit (); snoopy-snoopy-2.5.2/src/entrypoint/test-cli.c000066400000000000000000000031601470651710700212760ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "test-cli.h" #include "snoopy.h" #include "init-deinit.h" #include "configuration.h" #include "inputdatastorage.h" #include void snoopy_entrypoint_test_cli_init (const char *filename, char *const argv[], char * const configFilePath) { if (configFilePath != NULL) { snoopy_configuration_preinit_enableAltConfigFileParsing(configFilePath); } else { snoopy_configuration_preinit_disableConfigFileParsing(); } snoopy_init(); snoopy_inputdatastorage_store_filename(filename); snoopy_inputdatastorage_store_argv(argv); char *envp[] = { NULL }; snoopy_inputdatastorage_store_envp(envp); } void snoopy_entrypoint_test_cli_threads_init () { snoopy_init(); } void snoopy_entrypoint_test_cli_exit () { snoopy_cleanup(); } snoopy-snoopy-2.5.2/src/entrypoint/test-cli.h000066400000000000000000000017411470651710700213060ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ void snoopy_entrypoint_test_cli_init (const char *filename, char *const argv[], char * const configFilePath); void snoopy_entrypoint_test_cli_threads_init(); void snoopy_entrypoint_test_cli_exit (); snoopy-snoopy-2.5.2/src/error.c000066400000000000000000000035051470651710700164730ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: error.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "error.h" #include "snoopy.h" #include "configuration.h" #include "action/log-message-dispatch.h" #include /* * Local defines */ #define SNOOPY_ERROR_MSG_BUF_SIZE 4096 /* * snoopy_error_handler * * Description: * Does the actual error handling. If error logging is enabled, the error * message is sent to the configured output. * * Params: * errorMsg: Error message, withouth the leading "ERROR:" prefix. * * Return: * void */ void snoopy_error_handler (char const * const errorMsg) { const snoopy_configuration_t * CFG; char errorMsgFormatted[SNOOPY_ERROR_MSG_BUF_SIZE]; errorMsgFormatted[0] = '\0'; CFG = snoopy_configuration_get(); if (SNOOPY_TRUE != CFG->error_logging_enabled) { return; } snprintf(errorMsgFormatted, SNOOPY_ERROR_MSG_BUF_SIZE, "SNOOPY ERROR: %s", errorMsg); errorMsgFormatted[SNOOPY_ERROR_MSG_BUF_SIZE-1] = '\0'; snoopy_action_log_message_dispatch(errorMsg); } snoopy-snoopy-2.5.2/src/error.h000066400000000000000000000016171470651710700165020ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: error.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Error-handling functions */ void snoopy_error_handler (char const * const errorMsg); snoopy-snoopy-2.5.2/src/filter/000077500000000000000000000000001470651710700164605ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/filter/Makefile.am000066400000000000000000000020271470651710700205150ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Create one library with all Snoopy filters collected in it # noinst_LTLIBRARIES = libsnoopy_filters_all.la ### Filter collection is made of the following files # # Please maintain alphabetical order, equal to what `ls` would do # libsnoopy_filters_all_la_SOURCES = \ noop.c \ noop.h ### Filter: exclude_spawns_of # if FILTER_ENABLED_exclude_spawns_of libsnoopy_filters_all_la_SOURCES += \ exclude_spawns_of.c \ exclude_spawns_of.h endif ### Filter: exclude_uid # if FILTER_ENABLED_exclude_uid libsnoopy_filters_all_la_SOURCES += \ exclude_uid.c \ exclude_uid.h endif ### Filter: only_root # if FILTER_ENABLED_only_root libsnoopy_filters_all_la_SOURCES += \ only_root.c \ only_root.h endif ### Filter: only_tty # if FILTER_ENABLED_only_tty libsnoopy_filters_all_la_SOURCES += \ only_tty.c \ only_tty.h endif ### Filter: only_uid # if FILTER_ENABLED_only_uid libsnoopy_filters_all_la_SOURCES += \ only_uid.c \ only_uid.h endif snoopy-snoopy-2.5.2/src/filter/exclude_spawns_of.c000066400000000000000000000175461470651710700223510ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/exclude_spawns_of.c * * Copyright (c) 2015 Datto, Inc. All rights reserved. * Author: Fred Mora - fmora@datto.com * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "exclude_spawns_of.h" #include "snoopy.h" #include #include #include #include #include /* * Local defines */ #define PROGLISTSEP ',' // Max bytes for command, including null #define ST_COMM_SIZE_MAX 32 // Max bytes needed from /proc//stat, including null: // 20 digit PID, space, command in parens, space, 1 char state, space, // 20 digit PPID, null #define ST_BUF_SIZE (46 + ST_COMM_SIZE_MAX) // Min valid bytes from /proc//stat, excluding null: // 1 digit PID, space, empty parens, space, 1 char state, space, // 1 digit PPID #define ST_SIZE_MIN 8 // Path "/proc/nnnn/stat" where nnnn = some PID #define ST_PATH_SIZE_MAX 32 /* * Non-public function prototypes */ static int find_ancestor_in_list(char **name_list); static int find_string_in_array(const char *str, char **str_array); static char **string_to_token_array(char *str); /* * SNOOPY FILTER: exclude_spawns_of * * Description: * Excludes all log messages for executables that have the specified program name in their ancestors. * Strategy: We parse arg to create the "list of specified programs" (LoSP). * Then, we walk up the parent process ID (PPID) chain and we check if each executable name is part * of the LoSP. * * Params: * logMessage: Pointer to string that contains formatted log message (may be manipulated) * arg: Comma-separated list of program names for the spawns of which log messages are dropped. * * Return: * SNOOPY_FILTER_PASS or SNOOPY_FILTER_DROP */ int snoopy_filter_exclude_spawns_of (char const * const arg) { char *argDup; // Must not alter arg char **losp; // List of specified programs derived from arg int is_ancestor_in_list = 0; // Turn comma-separated arg into array of program name strings argDup = strdup(arg); losp = string_to_token_array(argDup); if (losp == NULL) { // If failure, we cannot filter anything, just pass the message return SNOOPY_FILTER_PASS; } // Check if one of the program names in losp is an ancestor is_ancestor_in_list = find_ancestor_in_list(losp); free(losp); free(argDup); return (is_ancestor_in_list == 1) ? SNOOPY_FILTER_DROP : SNOOPY_FILTER_PASS; // Error means pass } // Helper functions /** * Description: * Walks the /proc tree from /proc/currentPID and iterate parent PIDs up to PID 1. For each PID, check if the * executable name is in name_list. * Params: * name_list: Ptr to array of char ptr. Each element point to the name of an executable. * Return: * 1 if the executable name of an ancestor process is found in name_list * 0 if there are no ancestor that have a name found in name_list * -1 if error. */ static int find_ancestor_in_list(char ** name_list) { pid_t ppid; char stat_path[ST_PATH_SIZE_MAX]; FILE * statf; int rc; int found; const char * left; const char * right; size_t len; /* * The following vars are read from /proc/PID/stat * * st_buf: * Buffer for PID, command, state, and PPID * st_comm: * Buffer for command. In kernel/include/linux/sched.h this is * defined as 16 byte string, but let's keep a bit of spare room if * something suddenly changes in the kernel. */ char st_buf[ST_BUF_SIZE]; char st_comm_buf[ST_COMM_SIZE_MAX]; char st_state; if (name_list == NULL) { return -1; } ppid = getppid(); // We start with the parent while (ppid != 0) { // Create the path to /proc//stat snprintf(stat_path, ST_PATH_SIZE_MAX, "/proc/%d/stat", ppid); statf = fopen(stat_path, "r"); if (statf == NULL) { return -1; } // Grab the first few elements from the stat pseudo-file rc = (int) fread(st_buf, 1, ST_BUF_SIZE - 1, statf); st_buf[rc] = '\0'; fclose(statf); if (rc < ST_SIZE_MIN) { return -1; } // Find the first opening paren and the last closing paren left = strchr(st_buf, '('); right = strrchr(st_buf, ')'); if (left == NULL || right == NULL) { return -1; } len = right - left - 1; if (len <= 0 || len >= ST_COMM_SIZE_MAX) { return -1; } // Copy the command memcpy(st_comm_buf, left + 1, len); st_comm_buf[len] = '\0'; // Parse the PPID rc = sscanf(right + 1, " %c %d", &st_state, &ppid); if (rc != 2) { return -1; } found = find_string_in_array(st_comm_buf, name_list); if (found) { return 1; } } return 0; // Nothing found } /** * Description: * Searches for a string in an array of strings. All strings are zero-terminated. * Params: * str: Ptr to the string we are looking for in str_array. * str_array: Ptr to array of char ptr, each of them pointing to a string to compare to str. * Return: * 1 if str matches one of the strings in str_array * 0 if there are no matches or if either argument is NULL. */ static int find_string_in_array(const char *str, char **str_array) { if ((str == NULL) || (str_array == NULL)) { return 0; } char **p = str_array; while (*p != NULL) { if (strcmp(str, *p) == 0) { return 1; } p++; } return 0; } /** * Description: * Tokenizes string str using comma as a separator. Returns an array of individual tokens between delimiters. * * Params: * str: string to be tokenized. The string is modified as per strtok (delimiters replaced with \0).. * Returns: * Ptr to array of char ptr. Each element point to an individual substring between delimiters. * The last element is the NULL pointer to act as a delimiter. * The returned pointer should be freed by the caller after use. * If str is NULL or empty, or if error, returns NULL. */ static char **string_to_token_array(char *str) { char *p; int sepcount = 0; int token_count; char **token_array; // Return value char *saveptr = NULL; // For strtok_r() if ((str == NULL) || (*str == '\0')) { return NULL; } // Count the occurences of PROGLISTSEP p = strchr(str, PROGLISTSEP); while (p != NULL) { sepcount++; p=strchr(p+1, PROGLISTSEP); } // Allocate storage for token_array: one more than the separator count, and one more for the NULL delimiter. token_count = sepcount +1; token_array = calloc(token_count + 1, sizeof(p)); if (token_array == NULL) { return NULL; } // Fill in token_array with ptrs to individual tokens char delim[] = { PROGLISTSEP, '\0'}; // Make a string of delimiters p = str; for (int i = 0; i < token_count; i++) { token_array[i] = strtok_r(p, delim, &saveptr); p = NULL; } token_array[token_count] = NULL; return token_array; } snoopy-snoopy-2.5.2/src/filter/exclude_spawns_of.h000066400000000000000000000017311470651710700223430ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/exclude_spawns_of.h * * Copyright (c) 2015 Datto, Inc. All rights reserved. * Author: Fred Mora - fmora@datto.com * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY FILTER: exclude_spawns_of */ int snoopy_filter_exclude_spawns_of (char const * const arg); snoopy-snoopy-2.5.2/src/filter/exclude_uid.c000066400000000000000000000050261470651710700211210ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/exclude_uid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "exclude_uid.h" #include "snoopy.h" #include "util/parser-snoopy.h" #include #include #include #include #include /* * SNOOPY FILTER: exclude_uid * * Description: * Excludes all log messages comming from specified UIDs * * Params: * logMessage: pointer to string that contains formatted log message (may be manipulated) * arg: Comma-separated list of UIDs for which log messages are dropped, passed for others * * Return: * SNOOPY_FILTER_PASS or SNOOPY_FILTER_DROP */ int snoopy_filter_exclude_uid (char const * const arg) { uid_t curUid; // Actual UID of running process char *argDup = NULL; char **argParsed = NULL; int argCount = 0; int retVal = -1; /* Get uid of current process */ curUid = getuid(); /* Parse arguments - values are malloc()-ed */ argDup = strdup(arg); argCount = snoopy_util_parser_csvToArgList(argDup, &argParsed); /* Loop through all UIDs passed to the filter as argument */ for (int i=0 ; i * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY FILTER: exclude_uid */ int snoopy_filter_exclude_uid (char const * const arg); snoopy-snoopy-2.5.2/src/filter/noop.c000066400000000000000000000023411470651710700175770ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/noop.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "noop.h" #include "snoopy.h" /* * SNOOPY FILTER: noop * * Description: * Does nothing (just passes). * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * SNOOPY_FILTER_PASS */ int snoopy_filter_noop(__attribute__((unused)) char const * const arg) { return SNOOPY_FILTER_PASS; } snoopy-snoopy-2.5.2/src/filter/noop.h000066400000000000000000000016231470651710700176060ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/noop.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY FILTER: noop */ int snoopy_filter_noop (char const * const arg); snoopy-snoopy-2.5.2/src/filter/only_root.c000066400000000000000000000027431470651710700206560ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/only_root.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "only_root.h" #include "snoopy.h" #include #include #include /* * SNOOPY FILTER: only_root * * Description: * Only logs messages from root (uid=0 actually) * * Params: * msg: pointer to string that contains formatted log message (may be manipulated) * arg: arguments passed to this filter * * Return: * SNOOPY_FILTER_PASS or SNOOPY_FILTER_DROP */ int snoopy_filter_only_root (__attribute__((unused)) char const * const arg) { if (0 == getuid()) { return SNOOPY_FILTER_PASS; } else { return SNOOPY_FILTER_DROP; } } snoopy-snoopy-2.5.2/src/filter/only_root.h000066400000000000000000000016361470651710700206630ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/only_root.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY FILTER: only_root */ int snoopy_filter_only_root (char const * const arg); snoopy-snoopy-2.5.2/src/filter/only_tty.c000066400000000000000000000031651470651710700205120ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "only_tty.h" #include "snoopy.h" #include #include #include /* * SNOOPY FILTER: only_tty * * Description: * Returns TTY of current process. * * Params: * result: pointer to string, to write result into * arg: (ignored) * * Return: * number of characters in the returned string, or SNOOPY_DATASOURCE_FAILURE */ int snoopy_filter_only_tty (__attribute__((unused)) char const * const arg) { char ttyPath[SNOOPY_DATASOURCE_TTY_sizeMaxWithNull]; size_t ttyPathLen = SNOOPY_DATASOURCE_TTY_sizeMaxWithoutNull; int retVal = ttyname_r(0, ttyPath, ttyPathLen); // Only pass in this case if (0 == retVal) { return SNOOPY_FILTER_PASS; } return SNOOPY_FILTER_DROP; } snoopy-snoopy-2.5.2/src/filter/only_tty.h000066400000000000000000000021141470651710700205100ustar00rootroot00000000000000 /* * SNOOPY COMMAND LOGGER * * File: snoopy/datasource/tty.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Local defines */ #define SNOOPY_DATASOURCE_TTY_sizeMaxWithoutNull 4096 // PATH_MAX does not work here? #define SNOOPY_DATASOURCE_TTY_sizeMaxWithNull 4097 /* * SNOOPY FILTER: only_tty */ int snoopy_filter_only_tty (char const * const arg); snoopy-snoopy-2.5.2/src/filter/only_uid.c000066400000000000000000000050111470651710700204430ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/filter/only_uid.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "only_uid.h" #include "snoopy.h" #include "util/parser-snoopy.h" #include #include #include #include #include /* * SNOOPY FILTER: only_uid * * Description: * Excludes all log messages not comming from specific UID * * Params: * logMessage: pointer to string that contains formatted log message (may be manipulated) * arg: Comma-separated list of UIDs for which log message is passed on, dropped for all others * * Return: * SNOOPY_FILTER_PASS or SNOOPY_FILTER_DROP */ int snoopy_filter_only_uid (char const * const arg) { uid_t curUid; // Actual UID of running process char *argDup = NULL; char **argParsed = NULL; int argCount = 0; int retVal = -1; /* Get uid of current process */ curUid = getuid(); /* Parse arguments - values are malloc()-ed */ argDup = strdup(arg); argCount = snoopy_util_parser_csvToArgList(argDup, &argParsed); /* Loop through all UIDs passed to the filter as argument */ for (int i=0 ; i * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY FILTER: only_uid */ int snoopy_filter_only_uid (char const * const arg); snoopy-snoopy-2.5.2/src/filtering.c000066400000000000000000000077311470651710700173320ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: filtering.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "filtering.h" #include "snoopy.h" #include "configuration.h" #include "filterregistry.h" #include "message.h" #ifndef _POSIX_SOURCE // For strtok_r #define _POSIX_SOURCE #endif #include #include #include /* * snoopy_filtering_check_chain * * Description: * Determines whether given message should be send to syslog or not * * Params: * chain: filter chain to check * * Return: * SNOOPY_FILTER_PASS or SNOOPY_FILTER_DROP */ int snoopy_filtering_check_chain (char const * const filterChain) { char filterChainCopy[SNOOPY_FILTER_CHAIN_MAX_SIZE]; // Must be here, or strtok_r segfaults char *str; char *rest = NULL; const char *filterSpec; // Single filter specification from defined filter chain const char *fcPos_filterSpecArg; // Pointer to argument part of single filter specification in a filter chain // Copy the filter chain specification to separate string, to be used in strtok_r strncpy(filterChainCopy, filterChain, SNOOPY_FILTER_CHAIN_MAX_SIZE - 1); filterChainCopy[SNOOPY_FILTER_CHAIN_MAX_SIZE-1] = '\0'; // Loop through all filters str = filterChainCopy; filterSpec = ""; int j = 0; while (filterSpec != NULL) { j++; char filterName[SNOOPY_FILTER_NAME_MAX_SIZE]; const char *filterNamePtr; size_t filterNameSize; char filterArg[SNOOPY_FILTER_ARG_MAX_SIZE]; const char *filterArgPtr; // Parse the (remaining) filter chain specification for a next filterSpec if (j > 1) str = NULL; filterSpec = strtok_r(str, ";", &rest); // If next filterSpec has been found if (NULL != filterSpec) { // If filter tag contains ":", then split it into filter name and filter argument fcPos_filterSpecArg = strstr(filterSpec, ":"); if (NULL == fcPos_filterSpecArg) { // filterSpec == filterName, there is no argument filterName[0] = '\0'; filterNamePtr = filterSpec; filterArg[0] = '\0'; filterArgPtr = filterArg; } else { // Change the colon to null character, which effectively splits the string in two parts. // Then point to first and second part with corresponding variables. filterNameSize = fcPos_filterSpecArg - filterSpec; filterName[0] = '\0'; strncpy(filterName, filterSpec, filterNameSize); filterName[filterNameSize] = '\0'; filterNamePtr = filterName; filterArgPtr = fcPos_filterSpecArg + 1; } // Check if filter actually exists if (SNOOPY_FALSE == snoopy_filterregistry_doesNameExist(filterNamePtr)) { continue; } // Consult the filter, and return immediately if message should be dropped if (SNOOPY_FILTER_DROP == snoopy_filterregistry_callByName(filterNamePtr, filterArgPtr)) { return SNOOPY_FILTER_DROP; } } } return SNOOPY_FILTER_PASS; } snoopy-snoopy-2.5.2/src/filtering.h000066400000000000000000000015571470651710700173370ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: filtering.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_filtering_check_chain (char const * const chain); snoopy-snoopy-2.5.2/src/filterregistry.c000066400000000000000000000105561470651710700204240ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: filterregistry.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "filterregistry.h" #include "snoopy.h" #include "genericregistry.h" /* * Include headers of all filter functions */ #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_spawns_of #include "filter/exclude_spawns_of.h" #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_uid #include "filter/exclude_uid.h" #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_root #include "filter/only_root.h" #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_tty #include "filter/only_tty.h" #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_uid #include "filter/only_uid.h" #endif /* This prevents "ISO C forbids empty initializer braces" error */ #include "filter/noop.h" /* * Two arrays holding data about filter functions */ char *snoopy_filterregistry_names[] = { #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_spawns_of "exclude_spawns_of", #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_uid "exclude_uid", #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_root "only_root", #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_tty "only_tty", #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_uid "only_uid", #endif /* This prevents "ISO C forbids empty initializer braces" error */ "noop", "", }; int (*snoopy_filterregistry_ptrs []) (char const * const arg) = { #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_spawns_of snoopy_filter_exclude_spawns_of, #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_exclude_uid snoopy_filter_exclude_uid, #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_root snoopy_filter_only_root, #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_tty snoopy_filter_only_tty, #endif #ifdef SNOOPY_CONF_FILTER_ENABLED_only_uid snoopy_filter_only_uid, #endif /* This prevents "ISO C forbids empty initializer braces" error */ snoopy_filter_noop, }; /* * getCount() * * Return number of available filters */ int snoopy_filterregistry_getCount () { return snoopy_genericregistry_getCount(snoopy_filterregistry_names); } /* * doesIdExist() * * True if filter exists (by id), otherwise false */ int snoopy_filterregistry_doesIdExist (int filterId) { return snoopy_genericregistry_doesIdExist(snoopy_filterregistry_names, filterId); } /* * doesNameExist() * * True if filter exists (by name), otherwise false */ int snoopy_filterregistry_doesNameExist (char const * const filterName) { return snoopy_genericregistry_doesNameExist(snoopy_filterregistry_names, filterName); } /* * getIdFromName() * * Return index of given filter, or -1 if not found */ int snoopy_filterregistry_getIdFromName (char const * const filterName) { return snoopy_genericregistry_getIdFromName(snoopy_filterregistry_names, filterName); } /* * getName() * * Return name of given filter, or NULL */ char* snoopy_filterregistry_getName (int filterId) { return snoopy_genericregistry_getName(snoopy_filterregistry_names, filterId); } /* * callById() * * Call the given filter by id and return its output */ int snoopy_filterregistry_callById (int filterId, char const * const filterArg) { if (SNOOPY_FALSE == snoopy_filterregistry_doesIdExist(filterId)) { return -1; } return snoopy_filterregistry_ptrs[filterId](filterArg); } /* * callByName() * * Call the given filter by name and return its output */ int snoopy_filterregistry_callByName (char const * const filterName, char const * const filterArg) { int filterId; filterId = snoopy_filterregistry_getIdFromName(filterName); if (filterId == -1) { return -1; } return snoopy_filterregistry_ptrs[filterId](filterArg); } snoopy-snoopy-2.5.2/src/filterregistry.h000066400000000000000000000025751470651710700204330ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: filterregistry.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Functions to manage and utilise filters */ int snoopy_filterregistry_getCount (); int snoopy_filterregistry_doesIdExist (int filterId); int snoopy_filterregistry_doesNameExist (char const * const filterName); int snoopy_filterregistry_getIdFromName (char const * const filterName); char* snoopy_filterregistry_getName (int filterId); int snoopy_filterregistry_callById (int filterId, char const * const filterArg); int snoopy_filterregistry_callByName (char const * const filterName, char const * const filterArg); snoopy-snoopy-2.5.2/src/genericregistry.c000066400000000000000000000046441470651710700205540ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: genericregistry.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "genericregistry.h" #include "snoopy.h" #include /* * getCount() * * Return number of available items */ int snoopy_genericregistry_getCount (char *regArray[]) { int i; i = 0; while (strcmp(regArray[i], "") != 0) { i++; } return i; } /* * doesIdExist() * * True if the item exists (by id) in the registry, otherwise false */ int snoopy_genericregistry_doesIdExist (char *regArray[], int itemId) { if ((0 <= itemId ) && (itemId < snoopy_genericregistry_getCount(regArray))) { return SNOOPY_TRUE; } else { return SNOOPY_FALSE; } } /* * doesNameExist() * * True if the item exists (by name) in the registry, otherwise false */ int snoopy_genericregistry_doesNameExist (char *regArray[], char const * const itemName) { if (snoopy_genericregistry_getIdFromName(regArray, itemName) == -1) { return SNOOPY_FALSE; } else { return SNOOPY_TRUE; } } /* * getIdFromName() * * Return id of given item, or -1 if not found */ int snoopy_genericregistry_getIdFromName (char *regArray[], char const * const itemName) { for (int i=0 ; 0 != strcmp(regArray[i], "") ; i++) { if (strcmp(regArray[i], itemName) == 0) { return i; } } /* Not found */ return -1; } /* * getName() * * Return name of given item, or NULL */ char* snoopy_genericregistry_getName (char *regArray[], int itemId) { if (snoopy_genericregistry_doesIdExist(regArray, itemId)) { return regArray[itemId]; } /* Not found */ return NULL; } snoopy-snoopy-2.5.2/src/genericregistry.h000066400000000000000000000023631470651710700205550ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: genericregistry.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Generic registry functions */ int snoopy_genericregistry_getCount (char *regArray[]); int snoopy_genericregistry_doesIdExist (char *regArray[], int itemId); int snoopy_genericregistry_doesNameExist (char *regArray[], char const * const itemName); int snoopy_genericregistry_getIdFromName (char *regArray[], char const * const itemName); char* snoopy_genericregistry_getName (char *regArray[], int itemId); snoopy-snoopy-2.5.2/src/init-deinit.c000066400000000000000000000036631470651710700175640ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: misc.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "init-deinit.h" #include "snoopy.h" #include "configuration.h" #include "error.h" #include "inputdatastorage.h" #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #include "tsrm.h" #endif #include #include #include #include /* * snoopy_init * * Description: * Handles Snoopy initialization/startup specifics. * This method must be called when initializing anything that is * Snoopy-based. This is especially true for thread-safe Snoopy builds. * * Params: * (none) * * Return: * void */ void snoopy_init () { #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED snoopy_tsrm_ctor(); #endif snoopy_configuration_ctor(); snoopy_inputdatastorage_ctor(); } /* * snoopy_cleanup (deinit) * * Description: * Handles all Snoopy deinitialization/shutdown specifics * * Params: * (none) * * Return: * void */ void snoopy_cleanup () { /* Reverse order from ctor */ snoopy_inputdatastorage_dtor(); snoopy_configuration_dtor(); #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED snoopy_tsrm_dtor(); #endif } snoopy-snoopy-2.5.2/src/init-deinit.h000066400000000000000000000015171470651710700175650ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ void snoopy_init (); void snoopy_cleanup (); snoopy-snoopy-2.5.2/src/inputdatastorage.c000066400000000000000000000113271470651710700207210ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: inputdatastorage.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "inputdatastorage.h" #include "snoopy.h" #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #include "tsrm.h" #endif #include /* * Storage of Snoopy's input data for non-thread-safe builds */ #ifndef SNOOPY_CONF_THREAD_SAFETY_ENABLED snoopy_inputdatastorage_t snoopy_inputdatastorage_data = { .initialized = SNOOPY_FALSE, }; #endif /* * snoopy_inputdatastorage_ctor * * Description: * Populates snoopy_inputdatastorage struct with default empty * data, in order to prevent data leaks between execv(e) calls. * * Params: * (none) * * Return: * void */ void snoopy_inputdatastorage_ctor () { /* Get IDS pointer */ snoopy_inputdatastorage_t *IDS = snoopy_inputdatastorage_get(); snoopy_inputdatastorage_setDefaults(IDS); } /* * snoopy_inputdatastorage_dtor * * Description: * Populates snoopy_inputdatastorage struct with default empty * data, in order to prevent data leaks between execv(e) calls. * * NOTE: This is intentional behaviour. Reset in ctor and in * dtor too. * * Params: * (none) * * Return: * void */ void snoopy_inputdatastorage_dtor () { /* Get IDS pointer */ snoopy_inputdatastorage_t *IDS = snoopy_inputdatastorage_get(); snoopy_inputdatastorage_setDefaults(IDS); } /* * snoopy_inputdatastorage_setUninitialized() * * Description: * Sets the state of IDS to uninitialized. * * Params: * (none) * * Return: * void */ void snoopy_inputdatastorage_setUninitialized ( snoopy_inputdatastorage_t *IDS ) { IDS->initialized = SNOOPY_FALSE; } /* * snoopy_inputdatastorage_setDefaults() * * Description: * Resets the input data storage to default values * * Params: * (none) * * Return: * void */ void snoopy_inputdatastorage_setDefaults ( snoopy_inputdatastorage_t *IDS ) { static const char * empty_string = ""; static char * empty_string_array[] = { NULL }; IDS->initialized = SNOOPY_TRUE; IDS->filename = empty_string; IDS->argv = empty_string_array; IDS->envp = empty_string_array; } /* * snoopy_inputdatastorage_store_filename() * * Description: * Store filename of execv()/execve() syscall * * Params: * filename: filename to store * * Return: * void */ void snoopy_inputdatastorage_store_filename ( const char *filename ) { /* Get IDS pointer */ snoopy_inputdatastorage_t *IDS = snoopy_inputdatastorage_get(); /* Store value */ IDS->filename = filename; } /* * snoopy_inputdatastorage_store_argv() * * Description: * Store argv[] of execv()/execve() syscall * * Params: * argv: argv pointer to store * * Return: * void */ void snoopy_inputdatastorage_store_argv ( char *const argv[] ) { /* Get IDS pointer */ snoopy_inputdatastorage_t *IDS = snoopy_inputdatastorage_get(); /* Store value */ IDS->argv = argv; } /* * snoopy_inputdatastorage_store_envp() * * Description: * Store envp[] of execve() syscall * * Params: * envp: environment array pointer to store * * Return: * void */ void snoopy_inputdatastorage_store_envp ( char *const envp[] ) { /* Get IDS pointer */ snoopy_inputdatastorage_t *IDS = snoopy_inputdatastorage_get(); /* Store value */ IDS->envp = envp; } /* * snoopy_inputdatastorage_get() * * Description: * Retrieve inpudatastorage struct pointer * * Params: * (none) * * Return: * snoopy_inputdatastorage_t*: Pointer to inputdatastorage struct */ snoopy_inputdatastorage_t* snoopy_inputdatastorage_get () { snoopy_inputdatastorage_t *IDS; #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED IDS = snoopy_tsrm_get_inputdatastorage(); #else IDS = &snoopy_inputdatastorage_data; #endif if (SNOOPY_TRUE != IDS->initialized) { snoopy_inputdatastorage_setDefaults(IDS); } return IDS; } snoopy-snoopy-2.5.2/src/inputdatastorage.h000066400000000000000000000035061470651710700207260ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: inputdatastorage.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * START: Prevent cyclic inclusions */ #ifndef __SNOOPY_INPUTDATASTORAGE_H #define __SNOOPY_INPUTDATASTORAGE_H /* * Store execution data for inputs to consume */ typedef struct { int initialized; const char *filename; char *const *argv; char *const *envp; } snoopy_inputdatastorage_t; /* * Init functions */ void snoopy_inputdatastorage_ctor (); void snoopy_inputdatastorage_dtor (); void snoopy_inputdatastorage_setUninitialized (snoopy_inputdatastorage_t *IDS); void snoopy_inputdatastorage_setDefaults (snoopy_inputdatastorage_t *IDS); /* * Functions that do the actual data storing */ void snoopy_inputdatastorage_store_filename (const char *filename); void snoopy_inputdatastorage_store_argv (char *const argv[]); void snoopy_inputdatastorage_store_envp (char *const envp[]); /* * Retrieval functions */ snoopy_inputdatastorage_t* snoopy_inputdatastorage_get (); /* * END: Prevent cyclic inclusion */ #endif /* Cyclic inclusion */ snoopy-snoopy-2.5.2/src/message.c000066400000000000000000000151361470651710700167710ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: message.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "message.h" #include "snoopy.h" #include "configuration.h" #include "error.h" #include "datasourceregistry.h" #include "util/string-snoopy.h" #include #include #include /* * snoopy_message_generateFromFormat * * Description: * Generates log message as specified by messageFormat, using * data sources where requested. * * Params: * logMessage: destination string to return message in * logMessageBufSize: size of the destination buffer * logMessageFormat: log message format to use * * Return: * void */ void snoopy_message_generateFromFormat ( char * const logMessage, size_t logMessageBufSize, size_t dataSourceMsgMaxLength, char const * const logMessageFormat ) { size_t dataSourceMsgBufSize; char * dataSourceMsg = NULL; char const * fmtPos_cur; char const * fmtPos_nextFormatTag; char const * fmtPos_nextFormatTagClose; int retVal; dataSourceMsgBufSize = dataSourceMsgMaxLength+1; dataSourceMsg = malloc(dataSourceMsgBufSize); fmtPos_cur = logMessageFormat; fmtPos_nextFormatTag = logMessageFormat; // Loop all the way to the end of log message format specification while (strlen(fmtPos_nextFormatTag) > 0) { size_t lengthToCopy; char dataSourceTag[100]; int dataSourceTagLength; char *fmtPos_dataSourceTagArg; const char *dataSourceNamePtr; const char *dataSourceArgPtr; char dataSourceArg[SNOOPY_DATASOURCE_ARG_MAX_SIZE]; // If no data source tag is found, just copy the text and bail out fmtPos_nextFormatTag = strstr(fmtPos_cur, "%{"); if (NULL == fmtPos_nextFormatTag) { snoopy_message_append(logMessage, logMessageBufSize, fmtPos_cur); free(dataSourceMsg); return; // Should be "break;" but SonarCloud is complaining about it } // Otherwise copy text up to the next data source tag lengthToCopy = (int) (fmtPos_nextFormatTag - fmtPos_cur + 1); // + 1 for null termination if (lengthToCopy > dataSourceMsgBufSize) { lengthToCopy = dataSourceMsgBufSize; } dataSourceMsg[0] = '\0'; // Let's just use this buffer, even if it is called something else snprintf(dataSourceMsg, lengthToCopy, "%s", fmtPos_cur); snoopy_message_append(logMessage, logMessageBufSize, dataSourceMsg); dataSourceMsg[0] = '\0'; // And wipe it for later reuse // Get data source tag fmtPos_nextFormatTagClose = strstr(fmtPos_nextFormatTag, "}"); if (NULL == fmtPos_nextFormatTagClose) { snoopy_message_append(logMessage, logMessageBufSize, "[ERROR: Closing data source tag ('}') not found.]"); free(dataSourceMsg); return; // Should be "break;" but SonarCloud is complaining about it } dataSourceTag[0] = '\0'; dataSourceTagLength = (int)((fmtPos_nextFormatTagClose-1) - (fmtPos_nextFormatTag+2) + 2); snprintf(dataSourceTag, dataSourceTagLength, "%s", fmtPos_nextFormatTag + 2); // If data source tag contains ":", then split it into data source name and data source argument fmtPos_dataSourceTagArg = strstr(dataSourceTag, ":"); if (NULL == fmtPos_dataSourceTagArg) { // Format tag == data source name ATM dataSourceNamePtr = dataSourceTag; dataSourceArg[0] = '\0'; dataSourceArgPtr = dataSourceArg; } else { // Change the colon to null string, and copy fist and second part to corresponding variables fmtPos_dataSourceTagArg[0] = '\0'; dataSourceNamePtr = dataSourceTag; dataSourceArgPtr = fmtPos_dataSourceTagArg + 1; } // Check if data source actually exists if (! snoopy_datasourceregistry_doesNameExist(dataSourceNamePtr)) { snoopy_message_append(logMessage, logMessageBufSize, "[ERROR: Data source '"); snoopy_message_append(logMessage, logMessageBufSize, dataSourceNamePtr); snoopy_message_append(logMessage, logMessageBufSize, "' not found.]"); free(dataSourceMsg); return; // Should be "break;" but SonarCloud is complaining about it } // Call the provider, and append the results to log message dataSourceMsg[0] = '\0'; retVal = snoopy_datasourceregistry_callByName(dataSourceNamePtr, dataSourceMsg, dataSourceMsgBufSize, dataSourceArgPtr); if (SNOOPY_DATASOURCE_FAILED(retVal)) { snoopy_message_append(logMessage, logMessageBufSize, "[ERROR: Data source '"); snoopy_message_append(logMessage, logMessageBufSize, dataSourceNamePtr); snoopy_message_append(logMessage, logMessageBufSize, "' failed with the following error message: '"); snoopy_message_append(logMessage, logMessageBufSize, dataSourceMsg); snoopy_message_append(logMessage, logMessageBufSize, "']"); } else { snoopy_message_append(logMessage, logMessageBufSize, dataSourceMsg); } // Where to start next iteration fmtPos_cur = fmtPos_nextFormatTagClose + 1; } free(dataSourceMsg); } /* * snoopy_message_append * * Description: * Appends content to the end of log message, watching for * buffer overrun. * * Params: * logMessage: message container to append to * appendThis: content to append to logMessage * * Return: * void */ void snoopy_message_append ( char * logMessage, size_t logMessageBufSize, char const * const appendThis ) { if (SNOOPY_ERROR == snoopy_util_string_append(logMessage, logMessageBufSize, appendThis)) { snoopy_error_handler("Maximum destination string size exceeded"); } } snoopy-snoopy-2.5.2/src/message.h000066400000000000000000000022561470651710700167750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: message.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include void snoopy_message_generateFromFormat ( char * const logMessage, size_t logMessageBufSize, size_t dataSourceMsgMaxLength, char const * const logMessageFormat ); void snoopy_message_append ( char * const logMessage, size_t logMessageBufSize, char const * const appendThis ); snoopy-snoopy-2.5.2/src/output/000077500000000000000000000000001470651710700165335ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/output/Makefile.am000066400000000000000000000026561470651710700206000ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Create one library with all Snoopy outputs collected in it # noinst_LTLIBRARIES = libsnoopy_outputs_all.la ### Filter collection is made of the following files # # Please maintain alphabetical order, equal to what `ls` would do. # libsnoopy_outputs_all_la_SOURCES = \ noopoutput.c \ noopoutput.h # Output: devlog # if OUTPUT_ENABLED_devlog libsnoopy_outputs_all_la_SOURCES += \ devlogoutput.c \ devlogoutput.h endif # Output: devnull # if OUTPUT_ENABLED_devnull libsnoopy_outputs_all_la_SOURCES += \ devnulloutput.c \ devnulloutput.h endif # Output: devtty # if OUTPUT_ENABLED_devtty libsnoopy_outputs_all_la_SOURCES += \ devttyoutput.c \ devttyoutput.h endif # Output: file # if OUTPUT_ENABLED_file libsnoopy_outputs_all_la_SOURCES += \ fileoutput.c \ fileoutput.h endif # Output: socket # # This one is always enabled, unconditionally # libsnoopy_outputs_all_la_SOURCES += \ socketoutput.c \ socketoutput.h # Output: stderr # if OUTPUT_ENABLED_stderr libsnoopy_outputs_all_la_SOURCES += \ stderroutput.c \ stderroutput.h endif # Output: stdout # if OUTPUT_ENABLED_stdout libsnoopy_outputs_all_la_SOURCES += \ stdoutoutput.c \ stdoutoutput.h endif # Output: syslog # if OUTPUT_ENABLED_syslog libsnoopy_outputs_all_la_SOURCES += \ syslogoutput.c \ syslogoutput.h endif snoopy-snoopy-2.5.2/src/output/devlogoutput.c000066400000000000000000000054431470651710700214460ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devlogoutput.c * * Copyright (c) 2014-2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "devlogoutput.h" #include "snoopy.h" #include "configuration.h" #include "message.h" #include "output/socketoutput.h" #include #include #include #include /* * SNOOPY OUTPUT: devlogoutput * * Description: * Sends given message directly to /dev/log socket, without using syslog() syscall * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_devlogoutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { /* Dispatch only if non-zero size */ if (0 == strlen(logMessage)) { return SNOOPY_OUTPUT_GRACEFUL_DISCARD; } /* Get config pointer */ const snoopy_configuration_t * CFG = snoopy_configuration_get(); /* Generate syslog ident string */ char syslogIdent[SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE] = {'\0'}; snoopy_message_generateFromFormat(syslogIdent, SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE, SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE, CFG->syslog_ident_format); /* Allocate buffer */ size_t logMessageWithPrefixSize = strlen(logMessage) + SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE + 100; // +100 ought to be enough for... whatever :) char * logMessageWithPrefix = malloc(logMessageWithPrefixSize); logMessageWithPrefix[0] = '\0'; /* Generate final message - add prefix which is otherwise added by syslog() syscall */ snprintf( logMessageWithPrefix, logMessageWithPrefixSize, "<%d>%.*s[%d]: %s", CFG->syslog_facility | CFG->syslog_level, SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE-1, syslogIdent, getpid(), logMessage ); /* Pass execution to another output provider */ int bytesWritten = snoopy_output_socketoutput(logMessageWithPrefix, "/dev/log"); free(logMessageWithPrefix); return bytesWritten; } snoopy-snoopy-2.5.2/src/output/devlogoutput.h000066400000000000000000000017241470651710700214510ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devlogoutput.h * * Copyright (c) 2014-2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: directly to /dev/log */ int snoopy_output_devlogoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/devnulloutput.c000066400000000000000000000025701470651710700216350ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devnulloutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "devnulloutput.h" #include "output/fileoutput.h" /* * SNOOPY OUTPUT: devnulloutput * * Description: * Sends given message directly to /dev/null * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_devnulloutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { return snoopy_output_fileoutput(logMessage, "/dev/null"); } snoopy-snoopy-2.5.2/src/output/devnulloutput.h000066400000000000000000000017211470651710700216370ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devnulloutput.h * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: directly to /dev/tty */ int snoopy_output_devnulloutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/devttyoutput.c000066400000000000000000000025671470651710700215110ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devttyoutput.c * * Copyright (c) 2014-2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "devttyoutput.h" #include "output/fileoutput.h" /* * SNOOPY OUTPUT: devttyoutput * * Description: * Sends given message directly to /dev/tty * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_devttyoutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { return snoopy_output_fileoutput(logMessage, "/dev/tty"); } snoopy-snoopy-2.5.2/src/output/devttyoutput.h000066400000000000000000000017241470651710700215100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/devttyoutput.h * * Copyright (c) 2014-2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: directly to /dev/tty */ int snoopy_output_devttyoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/fileoutput.c000066400000000000000000000041771470651710700211100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/fileoutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) */ #include "fileoutput.h" #include "snoopy.h" #include "configuration.h" #include "message.h" #include #include #include #include /* * SNOOPY OUTPUT: fileoutput (called like this because is system library * * Description: * Sends given message to socket * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_fileoutput (char const * const logMessage, char const * const arg) { char filePathBuf[PATH_MAX] = {'\0'}; char * filePath = filePathBuf; FILE *fp; int charCount; // Check if output file is properly configured if (0 == strcmp(arg, "")) { return SNOOPY_OUTPUT_FAILURE; } // Parse the output file specification (i.e. for %{datetime} or similar tags) snoopy_message_generateFromFormat(filePath, PATH_MAX, PATH_MAX, arg); // Try to open file in append mode fp = fopen(filePath, "a"); if (NULL == fp) { return SNOOPY_OUTPUT_FAILURE; } // Try to print to file charCount = fprintf(fp, "%s\n", logMessage); fclose(fp); return charCount; } snoopy-snoopy-2.5.2/src/output/fileoutput.h000066400000000000000000000017151470651710700211100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/fileoutput.h * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: write directly to file */ int snoopy_output_fileoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/noopoutput.c000066400000000000000000000023561470651710700211410ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/noopoutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "noopoutput.h" /* * SNOOPY OUTPUT: noopoutput * * Description: * Does nothing. * * Params: * message: message to send * arg: output argument(s) * * Return: * int: 0 */ int snoopy_output_noopoutput (__attribute__((unused)) char const * const logMessage, __attribute__((unused)) char const * const arg) { return 0; } snoopy-snoopy-2.5.2/src/output/noopoutput.h000066400000000000000000000016731470651710700211470ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/noopoutput.h * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: noop */ int snoopy_output_noopoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/socketoutput.c000066400000000000000000000056071470651710700214600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/socketoutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "socketoutput.h" #include "snoopy.h" #include "configuration.h" #include #include #include #include #include #include #include #include #define PATH_SIZE 107 /* * SNOOPY OUTPUT: socketoutput (called like this because is system library) * * Description: * Sends given message to socket * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_socketoutput (char const * const logMessage, char const * const arg) { int s; struct sockaddr_un remote; int remoteLength; /* Dispatch only if non-zero size */ if (0 == strlen(logMessage)) { return SNOOPY_OUTPUT_GRACEFUL_DISCARD; } #if (defined(__GLIBC__) && (2 == __GLIBC__) && (__GLIBC_MINOR__ < 9)) /* Prepare socket - non-blocking sockets are not supported on older glibc */ if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) == -1) { #else /* Prepare socket - NON BLOCKING (systemd blocks /dev/log if journald is not running) */ if ((s = socket(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) == -1) { #endif return SNOOPY_OUTPUT_FAILURE; } remote.sun_family = AF_LOCAL; strncpy(remote.sun_path, arg, PATH_SIZE); // Coverity suggests -1 here if (strlen(arg) > PATH_SIZE) remote.sun_path[PATH_SIZE] = '\0'; remoteLength = (int) strnlen(remote.sun_path, PATH_SIZE) + (int) sizeof(remote.sun_family); if (connect(s, (struct sockaddr *)&remote, remoteLength) == -1) { close(s); return SNOOPY_OUTPUT_FAILURE; } /* Send message - returns -1 on error, chars sent on success */ if (send(s, logMessage, strlen(logMessage), MSG_DONTWAIT|MSG_NOSIGNAL) == -1) { close(s); return SNOOPY_OUTPUT_FAILURE; } /* Return success status */ close(s); return (int) strlen(logMessage); } snoopy-snoopy-2.5.2/src/output/socketoutput.h000066400000000000000000000017011470651710700214540ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/socketoutput.h * * Copyright (c) 2014 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: socket */ int snoopy_output_socketoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/stderroutput.c000066400000000000000000000025161470651710700214670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/stderroutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "stderroutput.h" #include /* * SNOOPY OUTPUT: stderroutput * * Description: * Sends given message to STDERR * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_stderroutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { return fprintf(stderr, "%s\n", logMessage); } snoopy-snoopy-2.5.2/src/output/stderroutput.h000066400000000000000000000017121470651710700214710ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/stderroutput.h * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: write to stderr */ int snoopy_output_stderroutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/stdoutoutput.c000066400000000000000000000025161470651710700215060ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/stdoutoutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "stdoutoutput.h" #include /* * SNOOPY OUTPUT: stdoutoutput * * Description: * Sends given message to STDOUT * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_stdoutoutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { return fprintf(stdout, "%s\n", logMessage); } snoopy-snoopy-2.5.2/src/output/stdoutoutput.h000066400000000000000000000017121470651710700215100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/stdoutoutput.h * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: write to stdout */ int snoopy_output_stdoutoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/output/syslogoutput.c000066400000000000000000000042111470651710700214760ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/syslogoutput.c * * Copyright (c) 2015 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "syslogoutput.h" #include "snoopy.h" #include "configuration.h" #include "message.h" #include #include #include #include #include #include /* * SNOOPY OUTPUT: syslogouput (called like this because is system library * * Description: * Sends given message to syslog * * Params: * message: message to send * arg: output argument(s) * * Return: * int: See snoopy.h (SNOOPY_OUTPUT_*) for details. */ int snoopy_output_syslogoutput (char const * const logMessage, __attribute__((unused)) char const * const arg) { /* Dispatch only if non-zero size */ if (0 == strlen(logMessage)) { return SNOOPY_OUTPUT_GRACEFUL_DISCARD; } /* Get config pointer */ const snoopy_configuration_t * CFG = snoopy_configuration_get(); /* Generate syslog ident string */ char syslogIdent[SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE] = {'\0'}; snoopy_message_generateFromFormat(syslogIdent, SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE, SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE, CFG->syslog_ident_format); openlog(syslogIdent, LOG_PID, CFG->syslog_facility); syslog(CFG->syslog_level, "%s", logMessage); closelog(); return (int) strlen(logMessage); } snoopy-snoopy-2.5.2/src/output/syslogoutput.h000066400000000000000000000017011470651710700215040ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy/output/syslogoutput.h * * Copyright (c) 2014 Bostjan Skufca (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * SNOOPY OUTPUT: syslog */ int snoopy_output_syslogoutput (char const * const logMessage, char const * const arg); snoopy-snoopy-2.5.2/src/outputregistry.c000066400000000000000000000135401470651710700204730ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: outputregistry.c * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "outputregistry.h" #include "snoopy.h" #include "configuration.h" #include "genericregistry.h" #include /* * Include headers of all output functions * * Please maintain alphabetical order, equal to what `ls` would do. */ #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devlog #include "output/devlogoutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devnull #include "output/devnulloutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devtty #include "output/devttyoutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_file #include "output/fileoutput.h" #endif //#ifdef SNOOPY_CONF_OUTPUT_ENABLED_journald //#include "output/journaldoutput.h" //#endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_socket #include "output/socketoutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stderr #include "output/stderroutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stdout #include "output/stdoutoutput.h" #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_syslog #include "output/syslogoutput.h" #endif /* This prevents "ISO C forbids empty initializer braces" error */ #include "output/noopoutput.h" /* * Two arrays holding data about output functions * * Please maintain alphabetical order, equal to what `ls` would do. */ char *snoopy_outputregistry_names[] = { #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devlog "devlog", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devnull "devnull", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devtty "devtty", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_file "file", #endif //#ifdef SNOOPY_CONF_OUTPUT_ENABLED_journald // "journald", //#endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_socket "socket", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stderr "stderr", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stdout "stdout", #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_syslog "syslog", #endif /* This prevents "ISO C forbids empty initializer braces" error */ "noop", "", }; int (*snoopy_outputregistry_ptrs []) (char const * const logMessage, char const * const arg) = { #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devlog snoopy_output_devlogoutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devnull snoopy_output_devnulloutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_devtty snoopy_output_devttyoutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_file snoopy_output_fileoutput, #endif //#ifdef SNOOPY_CONF_OUTPUT_ENABLED_journald // snoopy_output_journaldoutput, //#endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_socket snoopy_output_socketoutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stderr snoopy_output_stderroutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_stdout snoopy_output_stdoutoutput, #endif #ifdef SNOOPY_CONF_OUTPUT_ENABLED_syslog snoopy_output_syslogoutput, #endif /* This prevents "ISO C forbids empty initializer braces" error */ snoopy_output_noopoutput, }; /* * getCount() * * Return number of available outputs */ int snoopy_outputregistry_getCount () { return snoopy_genericregistry_getCount(snoopy_outputregistry_names); } /* * doesIdExist() * * True if output exists (by id), otherwise false */ int snoopy_outputregistry_doesIdExist (int outputId) { return snoopy_genericregistry_doesIdExist(snoopy_outputregistry_names, outputId); } /* * doesNameExist() * * True if output exists (by name), otherwise false */ int snoopy_outputregistry_doesNameExist (char const * const outputName) { return snoopy_genericregistry_doesNameExist(snoopy_outputregistry_names, outputName); } /* * getIdFromName() * * Return index of given output, or -1 if not found */ int snoopy_outputregistry_getIdFromName (char const * const outputName) { return snoopy_genericregistry_getIdFromName(snoopy_outputregistry_names, outputName); } /* * getName() * * Return name of given output, or NULL */ char* snoopy_outputregistry_getName (int outputId) { return snoopy_genericregistry_getName(snoopy_outputregistry_names, outputId); } /* * callById() * * Call the given output by id and return its output */ int snoopy_outputregistry_callById (int outputId, char const * const logMessage, char const * const outputArg) { if (SNOOPY_FALSE == snoopy_outputregistry_doesIdExist(outputId)) { return -1; } return snoopy_outputregistry_ptrs[outputId](logMessage, outputArg); } /* * callByName() * * Call the given output by name and return its output */ int snoopy_outputregistry_callByName (char const * const outputName, char const * const logMessage, char const * const outputArg) { int outputId; outputId = snoopy_outputregistry_getIdFromName(outputName); if (outputId == -1) { return -1; } return snoopy_outputregistry_ptrs[outputId](logMessage, outputArg); } /* * dispatch() * * Dispatch the message to configured outputProvider */ int snoopy_outputregistry_dispatch (char const * const logMessage) { const snoopy_configuration_t *CFG; /* Get config pointer */ CFG = snoopy_configuration_get(); /* Dispatch */ return snoopy_outputregistry_callByName(CFG->output, logMessage, CFG->output_arg); } snoopy-snoopy-2.5.2/src/outputregistry.h000066400000000000000000000031001470651710700204670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: outputregistry.h * * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Functions to manage and utilise outputs */ int snoopy_outputregistry_getCount (); int snoopy_outputregistry_doesIdExist (int outputId); int snoopy_outputregistry_doesNameExist (char const * const outputName); int snoopy_outputregistry_getIdFromName (char const * const outputName); char* snoopy_outputregistry_getName (int outputId); int snoopy_outputregistry_callById (int outputId, char const * const logMessage, char const * const outputArg); int snoopy_outputregistry_callByName (char const * const outputName, char const * const logMessage, char const * const outputArg); int snoopy_outputregistry_dispatch (char const * const logMessage); snoopy-snoopy-2.5.2/src/snoopy.h000066400000000000000000000152531470651710700167010ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * snoopy.h * Copyright (c) 2014-2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * Define Snoopy-wide system header file inclusion parameters * * _XPEN_SOURCE does a few things: * - prevents GCC from complaining about not using strerror_r return value * - enables strdup() presence */ #define _XOPEN_SOURCE 700 /** * Include ./configured constants * * At least must be included before including this file, as * LOG_... constants are needed. */ #include "config.h" /** * SNOOPY_DATASOURCE_ARG_MAX_SIZE * * Maximum length of a string argument to each data source */ #define SNOOPY_DATASOURCE_ARG_MAX_SIZE 1024 /** * SNOOPY_DATASOURCE_MESSAGE_MAX_SIZE * * Maximum length of a string returned from any data source function, * including terminating null character. */ #define SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_DEFAULT 2047 #define SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMIN 255 #ifndef SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMAX #define SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMAX 1048575 #endif /** * SNOOPY_DATASOURCE_(SUCCESS|FAILURE|...) * * Datasource results */ #define SNOOPY_DATASOURCE_SUCCESS 1 #define SNOOPY_DATASOURCE_FAILURE -1 #define SNOOPY_DATASOURCE_SUCCEEDED(retVal) (retVal >= 0) #define SNOOPY_DATASOURCE_FAILED(retVal) (retVal < 0) /** * SNOOPY_FILTER_CHAIN_MAX_SIZE * * Maximum length of filter chain definition */ #define SNOOPY_FILTER_CHAIN_MAX_SIZE 4096 /** * SNOOPY_FILTER_NAME_MAX_SIZE * * Maximum length of each filter name */ #define SNOOPY_FILTER_NAME_MAX_SIZE 1024 /** * SNOOPY_FILTER_ARG_MAX_SIZE * * Maximum length of a string argument to each filter */ #define SNOOPY_FILTER_ARG_MAX_SIZE 1024 /** * SNOOPY_LOG_MESSAGE_BUF_SIZE * * Size of the log message buffer (message + \0). */ #define SNOOPY_LOG_MESSAGE_MAX_LENGTH_DEFAULT 16383 #define SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMIN 255 #ifndef SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMAX #define SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMAX 1048575 #endif /** * SNOOPY_VERSION * * Snoopy code version */ #define SNOOPY_VERSION PACKAGE_VERSION /** * SNOOPY_SO_LIBRARY_PATH * * Absolute filesystem path to libsnoopy.so */ #define SNOOPY_SO_LIBRARY_NAME "libsnoopy.so" #define SNOOPY_SO_LIBRARY_NAME_WITH_SLASH "/libsnoopy.so" #define SNOOPY_SO_LIBRARY_PATH SNOOPY_CONF_LIBDIR SNOOPY_SO_LIBRARY_NAME_WITH_SLASH #define SNOOPY_SO_LIBRARY_PATH_GIT "src/.libs/libsnoopy.so" /** * SNOOPY_ETC_LD_SO_PRELOAD_PATH */ #define SNOOPY_ETC_LD_SO_PRELOAD_PATH "/etc/ld.so.preload" /** * SNOOPY_MESSAGE_FORMAT * * Actual message format to use, unless configured otherwise in config file. * For format specification consult comments in etc/snoopy.ini. */ #define SNOOPY_MESSAGE_FORMAT SNOOPY_CONF_MESSAGE_FORMAT /** * True, false, success, error */ #define SNOOPY_TRUE 1 #define SNOOPY_FALSE 0 #define SNOOPY_SUCCESS 1 #define SNOOPY_ERROR -1 /** * Filter return values * * SNOOPY_FILTER_PASS - message should be passed on * SNOOPY_FILTER_DROP - message should be dropped */ #define SNOOPY_FILTER_PASS 1 #define SNOOPY_FILTER_DROP 0 /** * SNOOPY_FILTERING_ENABLED * * Whether filtering is enabled or not */ #ifdef SNOOPY_CONF_FILTERING_ENABLED #define SNOOPY_FILTERING_ENABLED 1 #endif /** * SNOOPY_FILTER_CHAIN * * Actual filter chain specification to use * * Filter chain format: * - example: filter1; filter2; filter3:arg1; filter3:arg2 * - you may pass argument to filter by suffixing it with :arg * - spaces are ignored */ #ifdef SNOOPY_FILTERING_ENABLED #define SNOOPY_FILTER_CHAIN SNOOPY_CONF_FILTER_CHAIN #endif /** * SNOOPY_CONFIGFILE_* * * Path to INI configuration file, if enabled * * If configuration file is enabled, this constant is defined * and holds absolute path to it */ #ifdef SNOOPY_CONF_CONFIGFILE_ENABLED #define SNOOPY_CONFIGFILE_ENABLED 1 #define SNOOPY_CONFIGFILE_PATH SNOOPY_CONF_CONFIGFILE_PATH #endif /** * SNOOPY_OUTPUT * * Where is the outlet of Snoopy messages * * By default, messages get sent to syslog. Groundwork for other outputs * is provided to facilitate unforseen uses. */ #ifdef SNOOPY_CONF_OUTPUT_DEFAULT #define SNOOPY_OUTPUT_DEFAULT SNOOPY_CONF_OUTPUT_DEFAULT #define SNOOPY_OUTPUT_DEFAULT_ARG SNOOPY_CONF_OUTPUT_DEFAULT_ARG #else /* SNOOPY_CONF_OUTPUT_DEFAULT */ #if (defined(__GLIBC__) && (2 == __GLIBC__) && (__GLIBC_MINOR__ < 9)) /* Use 'syslog' on older linuxes that od not support SOCK_CLOEXEC and SOCK_NONBLOCK */ #define SNOOPY_OUTPUT_DEFAULT "syslog" #else /* Otherwise do not use 'syslog' (was default before), because systemd is funny (blocks the syslog() call */ #define SNOOPY_OUTPUT_DEFAULT "devlog" #endif #define SNOOPY_OUTPUT_DEFAULT_ARG "" #endif /* SNOOPY_CONF_OUTPUT_DEFAULT */ /** * Output return values/macro * * SNOOPY_OUTPUT_SUCCESS - message was sent successfully * SNOOPY_OUTPUT_FAILURE - message was NOT sent */ #define SNOOPY_OUTPUT_SUCCESS 1 #define SNOOPY_OUTPUT_GRACEFUL_DISCARD 0 #define SNOOPY_OUTPUT_FAILURE -1 #define SNOOPY_OUTPUT_SUCCEEDED(retVal) (retVal >= 0) #define SNOOPY_OUTPUT_FAILED(retVal) (retVal < 0) /** * SNOOPY_LOG_ERRORS * * Whether errors are logged or not? * * If error logging is enabled, then all errors that occur when using Snoopy * will be sent to syslog. This is to aid developers and integrators with * their endeavours. */ #ifdef SNOOPY_CONF_ERROR_LOGGING_ENABLED #define SNOOPY_ERROR_LOGGING_ENABLED SNOOPY_CONF_ERROR_LOGGING_ENABLED #endif /** * SNOOPY_SYSLOG_* * * Default syslog configuration settings */ #define SNOOPY_SYSLOG_FACILITY SNOOPY_CONF_SYSLOG_FACILITY #define SNOOPY_SYSLOG_IDENT_FORMAT SNOOPY_CONF_SYSLOG_IDENT_FORMAT #define SNOOPY_SYSLOG_IDENT_FORMAT_BUF_SIZE 256 #define SNOOPY_SYSLOG_LEVEL SNOOPY_CONF_SYSLOG_LEVEL snoopy-snoopy-2.5.2/src/tsrm.c000066400000000000000000000237001470651710700163260ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: tsrm.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "tsrm.h" #include "configuration.h" #include "inputdatastorage.h" #include "util/list-snoopy.h" #include #include /* * Global variables */ pthread_once_t snoopy_tsrm_init_onceControl = PTHREAD_ONCE_INIT; pthread_mutex_t snoopy_tsrm_threadRepo_mutex; pthread_mutexattr_t snoopy_tsrm_threadRepo_mutexAttr; list_t snoopy_tsrm_threadRepo_data = { .first = NULL, .last = NULL, .count = 0, }; list_t *snoopy_tsrm_threadRepo = &snoopy_tsrm_threadRepo_data; /* * Non-exported function prototypes */ void snoopy_tsrm_init (); int snoopy_tsrm_doesThreadRepoEntryExist (snoopy_tsrm_threadId_t threadId, int mutex_already_locked); snoopy_tsrm_threadId_t snoopy_tsrm_getCurrentThreadId (); listNode_t* snoopy_tsrm_getCurrentThreadRepoEntry (); snoopy_tsrm_threadData_t* snoopy_tsrm_getCurrentThreadData (); snoopy_tsrm_threadData_t* snoopy_tsrm_createNewThreadData (snoopy_tsrm_threadId_t threadId); /* * snoopy_tsrm_ctor * * Description: * Initialize threadRepo list. * * Params: * (none) * * Return: * void */ void snoopy_tsrm_ctor () { snoopy_tsrm_threadId_t curTid; snoopy_tsrm_threadData_t *tData; // Initialize threading support pthread_once(&snoopy_tsrm_init_onceControl, &snoopy_tsrm_init); // Get my thread id - before mutex, no need for mutex here curTid = snoopy_tsrm_getCurrentThreadId(); // Mutex START pthread_mutex_lock(&snoopy_tsrm_threadRepo_mutex); // Create my entry if it does not exist if (SNOOPY_FALSE == snoopy_tsrm_doesThreadRepoEntryExist(curTid, SNOOPY_TRUE)) { tData = snoopy_tsrm_createNewThreadData(curTid); snoopy_util_list_push(snoopy_tsrm_threadRepo, tData); } // Mutex END pthread_mutex_unlock(&snoopy_tsrm_threadRepo_mutex); } /* * snoopy_tsrm_dtor * * Description: * Removes own entry from threadRepo, or removes threadRepo altogether. * * Params: * (none) * * Return: * void */ void snoopy_tsrm_dtor () { listNode_t *tRepoEntry; snoopy_tsrm_threadData_t *tData; // Get my thread data structure tRepoEntry = snoopy_tsrm_getCurrentThreadRepoEntry(); if (NULL == tRepoEntry) { // This is an error condition, but let's not free NULLs below return; } // Mutex START pthread_mutex_lock(&snoopy_tsrm_threadRepo_mutex); // Remove from repo tData = snoopy_util_list_remove(snoopy_tsrm_threadRepo, tRepoEntry); // Mutex END pthread_mutex_unlock(&snoopy_tsrm_threadRepo_mutex); // Free the results AFTER my node has been removed from repo free(tData->inputdatastorage); free(tData->configuration); free(tData); return; } /* * snoopy_tsrm_init * * Description: * Initialize threading subsystem. This function should be run * only once, by only one thread. * * Params: * (none) * * Return: * void */ void snoopy_tsrm_init () { // Initialize threadRepo mutex pthread_mutexattr_init (&snoopy_tsrm_threadRepo_mutexAttr); pthread_mutexattr_settype(&snoopy_tsrm_threadRepo_mutexAttr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init (&snoopy_tsrm_threadRepo_mutex, &snoopy_tsrm_threadRepo_mutexAttr); } /* * snoopy_tsrm_doesThreadRepoEntryExist * * Description: * Check if thread with id threadId already has an entry in Snoopy's thread * repository. * * Params: * snoopy_tsrm_threadId_t: Thread ID to look for * * Return: * int: SNOOPY_TRUE if yes, SNOOPY_FALSE if not */ int snoopy_tsrm_doesThreadRepoEntryExist (snoopy_tsrm_threadId_t threadId, int mutex_already_locked) { const snoopy_tsrm_threadData_t *tData; int retVal = SNOOPY_FALSE; // Mutex START if (SNOOPY_TRUE != mutex_already_locked) { pthread_mutex_lock(&snoopy_tsrm_threadRepo_mutex); } listNode_t * curNode = NULL; while (NULL != (curNode = snoopy_util_list_fetchNextNode(snoopy_tsrm_threadRepo, curNode))) { if (NULL == curNode->value) { continue; } tData = curNode->value; if (0 != pthread_equal(threadId, tData->threadId)) { /* Thread ID matches */ retVal = SNOOPY_TRUE; goto FOUND; } } FOUND: // Mutex END if (SNOOPY_TRUE != mutex_already_locked) { pthread_mutex_unlock(&snoopy_tsrm_threadRepo_mutex); } return retVal; } /* * snoopy_tsrm_createNewThreadData * * Description: * Mallocs space and creates new thread data structure, for given thread ID. * * Params: * snoopy_tsrm_threadId_t: Thread ID to create entry for * * Return: * snoopy_tsrm_threadData_t*: Pointer to newly-created threadData structure */ snoopy_tsrm_threadData_t* snoopy_tsrm_createNewThreadData (snoopy_tsrm_threadId_t threadId) { snoopy_tsrm_threadData_t *tData; // Allocte storage memory for new threadData structure tData = malloc(sizeof(snoopy_tsrm_threadData_t)); tData->configuration = malloc(sizeof(snoopy_configuration_t)); tData->inputdatastorage = malloc(sizeof(snoopy_inputdatastorage_t)); // Store thread ID tData->threadId = threadId; // Initialize empty values snoopy_configuration_setUninitialized (tData->configuration); snoopy_inputdatastorage_setUninitialized(tData->inputdatastorage); return tData; } /* * snoopy_tsrm_getCurrentThreadId * * Description: * Retrieve id of current thread * * Params: * (none) * * Return: * snoopy_tsrm_threadId_t: Current thread id */ snoopy_tsrm_threadId_t snoopy_tsrm_getCurrentThreadId () { return pthread_self(); } /* * snoopy_tsrm_getCurrentThreadRepoEntry * * Description: * Retrieve pointer to threadRepo list node structure of current thread. * * Params: * (none) * * Return: * listNode_t*: Current threadRepo entry, or null if it does not exist */ listNode_t * snoopy_tsrm_getCurrentThreadRepoEntry () { snoopy_tsrm_threadId_t myThreadId; listNode_t *tRepoEntry = NULL; const snoopy_tsrm_threadData_t *tData; // This is the thread ID we are looking for myThreadId = snoopy_tsrm_getCurrentThreadId(); // Mutex START pthread_mutex_lock(&snoopy_tsrm_threadRepo_mutex); listNode_t * curNode = NULL; while (NULL != (curNode = snoopy_util_list_fetchNextNode(snoopy_tsrm_threadRepo, curNode))) { // This should not happen, but maybe, just maybe, there is another thread // that is just creating a new entry. if (NULL == curNode->value) { continue; } tData = curNode->value; if (0 != pthread_equal(myThreadId, tData->threadId)) { tRepoEntry = curNode; goto FOUND; } } FOUND: // Mutex END pthread_mutex_unlock(&snoopy_tsrm_threadRepo_mutex); // Return return tRepoEntry; } /* * snoopy_tsrm_getCurrentThreadData * * Description: * Retrieve pointer to thread data structure of current thread. Creates * a new repo entry if it does not exist. * * Params: * (none) * * Return: * snoopy_tsrm_threadData_t: Current threadRepo list entry, or NULL */ snoopy_tsrm_threadData_t* snoopy_tsrm_getCurrentThreadData () { listNode_t *tRepoEntry; tRepoEntry = snoopy_tsrm_getCurrentThreadRepoEntry(); if (NULL == tRepoEntry) { return NULL; } return tRepoEntry->value; } /* * snoopy_tsrm_get_configuration() * * Description: * Retrieve configuration array pointer for current thread. * This function is to be consumed by the rest of Snoopy. * * Params: * (none) * * Return: * snoopy_configuration_t*: Pointer to thread-specific Snoopy configuration data structure */ snoopy_configuration_t* snoopy_tsrm_get_configuration () { snoopy_tsrm_threadData_t *tData; tData = snoopy_tsrm_getCurrentThreadData(); return tData->configuration; } /* * snoopy_tsrm_get_inputdatastorage() * * Description: * Retrieve input data storage array pointer for current thread. * This function is to be consumed by the rest of Snoopy. * * Params: * (none) * * Return: * snoopy_inputdatastorage_t*: Pointer to thread-specific input data storage structure */ snoopy_inputdatastorage_t* snoopy_tsrm_get_inputdatastorage () { snoopy_tsrm_threadData_t *tData; tData = snoopy_tsrm_getCurrentThreadData(); return tData->inputdatastorage; } /* * snoopy_tsrm_get_threadCount() * * Description: * Retrieves number of currently configured threads. * * Params: * (none) * * Return: * snoopy_inputdatastorage_t*: Pointer to thread-specific input data storage structure */ int snoopy_tsrm_get_threadCount () { int threadCount; // Mutex START pthread_mutex_lock(&snoopy_tsrm_threadRepo_mutex); // Get count threadCount = snoopy_tsrm_threadRepo->count; // Mutex END pthread_mutex_unlock(&snoopy_tsrm_threadRepo_mutex); return threadCount; } snoopy-snoopy-2.5.2/src/tsrm.h000066400000000000000000000032701470651710700163330ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: tsrm.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * START: Prevent cyclic inclusions */ #ifndef __SNOOPY_TSRM_H #define __SNOOPY_TSRM_H /* * Includes order: from local to global */ #include "configuration.h" #include "inputdatastorage.h" #include /* * Type alias: threadId */ typedef pthread_t snoopy_tsrm_threadId_t; /* * Type: thread data struct */ typedef struct { snoopy_tsrm_threadId_t threadId; snoopy_configuration_t *configuration; snoopy_inputdatastorage_t *inputdatastorage; } snoopy_tsrm_threadData_t; /* * Init/shutdown functions */ void snoopy_tsrm_ctor (); void snoopy_tsrm_dtor (); /* * Getter functions */ snoopy_configuration_t* snoopy_tsrm_get_configuration (); snoopy_inputdatastorage_t* snoopy_tsrm_get_inputdatastorage (); int snoopy_tsrm_get_threadCount (); /* * END: Prevent cyclic inclusion */ #endif /* Cyclic inclusion */ snoopy-snoopy-2.5.2/src/util/000077500000000000000000000000001470651710700161505ustar00rootroot00000000000000snoopy-snoopy-2.5.2/src/util/Makefile.am000066400000000000000000000014121470651710700202020ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Create one library with all Snoopy utils collected in it # # Maintain alphabetical order, equal to what `ls` would do. # noinst_LTLIBRARIES = libsnoopy-utils.la libsnoopy_utils_la_SOURCES = \ file.c \ file-snoopy.h \ parser.c \ parser-snoopy.h \ pwd.c \ pwd-snoopy.h \ string.c \ string-snoopy.h \ syslog.c \ syslog-snoopy.h if DATASOURCE_ENABLED_ipaddr libsnoopy_utils_la_SOURCES += \ utmp.c \ utmp-snoopy.h endif if DATASOURCE_ENABLED_systemd_unit_name libsnoopy_utils_la_SOURCES += \ systemd.c \ systemd-snoopy.h endif if THREAD_SAFETY_ENABLED libsnoopy_utils_la_SOURCES += \ list.c \ list-snoopy.h endif snoopy-snoopy-2.5.2/src/util/file-snoopy.h000066400000000000000000000021711470651710700205660ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE 10240 // 10 KB #define SNOOPY_UTIL_FILE__SMALL_FILE_FREAD_SIZE 1024 // Must divide the SMALL_FILX_MAX_SIZE, cannot be greater than 1024 #define SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE 1024 int snoopy_util_file_getSmallTextFileContent (const char * const filePath, char ** contentPtr); snoopy-snoopy-2.5.2/src/util/file.c000066400000000000000000000135661470651710700172460ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) */ #include "file-snoopy.h" #include "snoopy.h" #include #include #include #include /* * Returns content of a small file * * Description: * Reads the whole small* text** file and returns*** its whole content * * *small: A file that this function reads should not be large. Its content * should not exceed SNOOPY_UTIL_FILE_SMALL_FILE_MAX_SIZE bytes. * **text: Only textual files should be handled using this function. They * must not contain \0 byte(s). * should not exceed SNOOPY_UTIL_FILE_SMALL_FILE_MAX_SIZE bytes. * ***returns: A pointer to malloc()-ed memory block containing the whole * file content. * * Params: * filePath: Path to the file that should be read * contentPtr: File content will be returned with this pointer (or an error message). * Must be free()-d after use. * * Return: * int: The size of the file content pointed to by the contentPtr * (excluding the last \0), or -1 on error (and contentPtr will * contain a null-terminated malloc()-ed error message). */ int snoopy_util_file_getSmallTextFileContent (char const * const filePath, char ** contentPtrAddr) { FILE * fileHandle; char * contentPtr; char * errorMsgBuf; // Allocate the memory // Since this is mostly used for /proc reading, we can't use ftell() to get // the file size, hence we can't predict how much memory we'll need. contentPtr = malloc(SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE); if (contentPtr == NULL) { contentPtr = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); snprintf( contentPtr, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE, "Unable to malloc() %d bytes", SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE ); contentPtr[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; *contentPtrAddr = contentPtr; return -1; } contentPtr[0] = '\0'; // Open fileHandle = fopen(filePath, "r"); if (fileHandle == NULL) { free(contentPtr); contentPtr = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf[0] = '\0'; strerror_r(errno, errorMsgBuf, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; snprintf( contentPtr, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE, "Unable to open file %s for reading, reason: %s", filePath, errorMsgBuf ); contentPtr[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; *contentPtrAddr = contentPtr; free(errorMsgBuf); return -1; } // Read the file content size_t bytesReadTotal = 0; while (bytesReadTotal < SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE) { size_t bytesReadNow; bytesReadNow = fread(contentPtr+bytesReadTotal, 1, SNOOPY_UTIL_FILE__SMALL_FILE_FREAD_SIZE, fileHandle); bytesReadTotal += bytesReadNow; if (ferror(fileHandle)) { free(contentPtr); contentPtr = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf[0] = '\0'; strerror_r(errno, errorMsgBuf, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); errorMsgBuf[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; snprintf( contentPtr, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE, "Error reading file: %s", errorMsgBuf ); contentPtr[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; *contentPtrAddr = contentPtr; clearerr(fileHandle); fclose(fileHandle); free(errorMsgBuf); return -1; } if ( feof(fileHandle) || // At one point, feof() didn't seem to work as expected (at least not on /proc/ files). // Potentially remove this section in the future. (bytesReadNow < SNOOPY_UTIL_FILE__SMALL_FILE_FREAD_SIZE) ) { break; } } if (bytesReadTotal >= SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE) { free(contentPtr); contentPtr = malloc(SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE); snprintf( contentPtr, SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE, "INTERNAL ERROR: File too large for getSmallTextFileContent()" ); contentPtr[SNOOPY_UTIL_FILE__ERROR_MSG_MAX_SIZE-1] = '\0'; *contentPtrAddr = contentPtr; fclose(fileHandle); return -1; } if (bytesReadTotal < SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE-1) { contentPtr[bytesReadTotal] = '\0'; } else { contentPtr[SNOOPY_UTIL_FILE__SMALL_FILE_MAX_SIZE-1] = '\0'; } // Cleanup fclose(fileHandle); // Return *contentPtrAddr = contentPtr; return (int) bytesReadTotal; } snoopy-snoopy-2.5.2/src/util/list-snoopy.h000066400000000000000000000026541470651710700206300ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * Inspired by: https://github.com/zedshaw/liblcthw/blob/master/src/lcthw/list.h & dbh.h * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Type definitions */ struct listNode_t; typedef struct listNode_t { struct listNode_t *next; struct listNode_t *prev; void *value; } listNode_t; typedef struct list_t { int count; listNode_t *first; listNode_t *last; } list_t; /* * List handling functions */ int snoopy_util_list_push (list_t * list, void * newNodeValue); void * snoopy_util_list_remove (list_t * list, listNode_t * nodeToRemove); listNode_t * snoopy_util_list_fetchNextNode (list_t * list, listNode_t * curNode); snoopy-snoopy-2.5.2/src/util/list.c000066400000000000000000000101011470651710700172600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * Inspired by: https://github.com/zedshaw/liblcthw/blob/master/src/lcthw/list.c * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "util/list-snoopy.h" #include "snoopy.h" #include "error.h" #include /* * Push a value onto the doubly linked list, as a last node * * Params: * list_t: A list to work with * void *: Pointer to the new node's value * * Return: * int: SNOOPY_SUCCESS or SNOOPY_ERROR */ int snoopy_util_list_push (list_t * list, void * newNodeValue) { listNode_t * newNode; // Create a new node newNode = calloc(1, sizeof(listNode_t)); if (!newNode) { snoopy_error_handler("Unable to allocate memory for a new doubly linked list node"); return SNOOPY_ERROR; } newNode->value = newNodeValue; // Place it at the end of the list if (list->last == NULL) { list->first = newNode; list->last = newNode; newNode->prev = NULL; newNode->next = NULL; } else { list->last->next = newNode; newNode->prev = list->last; newNode->next = NULL; list->last = newNode; } // Update the list count list->count++; return SNOOPY_SUCCESS; } /* * Remove a node from a doubly-linked list * * Params: * list_t: A list to work with * listNode_t: A node to remove * * Return: * void *: Value pointer of a removed node, or NULL on failure */ void * snoopy_util_list_remove (list_t * list, listNode_t * nodeToRemove) { void * retVal = NULL; // Check the list and the node if (!list->first || !list->last) { snoopy_error_handler("The doubly linked list is empty"); return NULL; } if (!nodeToRemove) { snoopy_error_handler("No node given, unable to remove NULL"); return NULL; } // Remove the node from the list if (nodeToRemove == list->first && nodeToRemove == list->last) { list->first = NULL; list->last = NULL; } else if (nodeToRemove == list->first) { list->first = nodeToRemove->next; } else if (nodeToRemove == list->last) { list->last = nodeToRemove->prev; list->last->next = NULL; } else { listNode_t * nodeAfter = nodeToRemove->next; listNode_t * nodeBefore = nodeToRemove->prev; nodeAfter->prev = nodeBefore; nodeBefore->next = nodeAfter; } // Update the list count list->count--; // Prepare the return value retVal = nodeToRemove->value; // Cleanup free(nodeToRemove); return retVal; } /* * Fetch the next node on a list (or the first node if curNode == NULL) * * Params: * list_t: A list to work with * listNode_t: Node before the expected one (or NULL) * * Return: * listNode_t *: Next node, or NULL if list's end has been reached */ listNode_t * snoopy_util_list_fetchNextNode (list_t * list, listNode_t * curNode) { // If the list is empty, there is nothing to fetch if (!list->first || !list->last) { return NULL; } // If curNode == NULL, return the first node if (!curNode) { return list->first; } // Else simply return the next node (curNode->next is NULL when curNode is the last node on the list) return curNode->next; } snoopy-snoopy-2.5.2/src/util/parser-snoopy.h000066400000000000000000000020241470651710700211400ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: parser.h * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Parser functions */ int snoopy_util_parser_csvToArgList (char *argListRaw, char ***argListParsed); int snoopy_util_parser_strByteLength (const char *numberAsText, const int valMin, const int valMax, const int valDefault); snoopy-snoopy-2.5.2/src/util/parser.c000066400000000000000000000116261470651710700176160ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: parser.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "util/parser-snoopy.h" #include "util/string-snoopy.h" #include #include #include /* * Parses CSV list into an array of char pointers (modifies original CSV string) * * Last array entry contains only '\0' character. * * NOTE 1: argListRaw will be modified (commas will be replaced with \0s, * argListParsed array will contain pointers to parts of this newly * mangled argListRaw. * NOTE 2: argListParsed is malloc()-ed and must be freed after use. * * Params: * argListRaw: String containing CSV to parse * argListParsed: A pointer that will get malloc()-ed array of char pointers to individual CSV entries * * Return: * int: Number of arguments parsed out. */ int snoopy_util_parser_csvToArgList (char *argListRaw, char ***argListParsed) { int commaCount; int argCount; char **argListParsedPtr; int argListRaw_charCount; // excluding trailing \0 char *argListRaw_pos; char *nextCommaPtr; int i; // Get size of raw argument list argListRaw_charCount = (int) strlen(argListRaw); // Allocate memory for array of string pointers: // - 1st +1 is because of common sense (X commas =~ X-1 arguments) // - 2nd +1 is for "" at the end or array commaCount = snoopy_util_string_countChars(argListRaw, ','); argCount = commaCount + 1; argListParsedPtr = malloc(sizeof(char*) * (argCount+1)); // Initial assignment if (0 == argListRaw_charCount) { // Argument list is empty, assign nothing, keep argCount down argCount = 0; i = 0; } else { // Assign initial pointer, to beginning of character array // This might be the only argument if no comma was found. argListParsedPtr[0] = argListRaw; i = 1; } // Parse for commas, changing commas into '\0' characters and assigning pointers // Optimize: do not count characters 2 times (1st in snoopy_util_string_charCount() function) if (commaCount > 0 ) { argListRaw_pos = argListRaw; while (NULL != (nextCommaPtr = strchr(argListRaw_pos, ','))) { *nextCommaPtr = '\0'; argListRaw_pos = nextCommaPtr+1; argListParsedPtr[i] = argListRaw_pos; i++; } } // Assign last pointer - must point to terminating null character argListParsedPtr[i] = argListRaw + argListRaw_charCount+1; *argListParsed = argListParsedPtr; return argCount; } /* * Parses a textual representation of an integer into an actual integer * * Params: * textInt: String containing CSV to parse * argListParsed: A pointer that will get malloc()-ed array of char pointers to individual CSV entries * * Return: * int: Number of arguments parsed out. */ int snoopy_util_parser_strByteLength (char const * const numberAsText, const int valMin, const int valMax, const int valDefault) { char const *numberAsTextPtr = numberAsText; int numbersBufLength = 20; // 20 characters are needed to store max long long int in decimal representation + \0. char numbersBuf[numbersBufLength]; int numberInt; int factor = 1; int result; // Extract numbers while ((*numberAsTextPtr != '\0') && isdigit(*numberAsTextPtr) && (numberAsTextPtr-numberAsText < numbersBufLength-2)) { numbersBuf[numberAsTextPtr - numberAsText] = *numberAsTextPtr; numberAsTextPtr++; } numbersBuf[numberAsTextPtr - numberAsText] = '\0'; // Convert to int numberInt = atoi(numbersBuf); if (numberInt == 0) { return valDefault; } // Apply metric prefixes if ((*numberAsTextPtr == 'k') || (*numberAsTextPtr == 'K')) { factor = 1024; } else if ((*numberAsTextPtr == 'm') || (*numberAsTextPtr == 'M')) { factor = 1024*1024; } result = numberInt * factor; // Apply limits if (result < valMin) result = valMin; if (result > valMax) result = valMax; return result; } snoopy-snoopy-2.5.2/src/util/pwd-snoopy.h000066400000000000000000000016151470651710700204430ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "snoopy.h" #include char * snoopy_util_pwd_convertUidToUsername (uid_t uid); snoopy-snoopy-2.5.2/src/util/pwd.c000066400000000000000000000050431470651710700171100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) */ #include "pwd-snoopy.h" #include "snoopy.h" #include #include #include #include #include /* * Convert UID to username (malloc()-ed buffer, must be freed by the caller) * * Params: * uid: UID to convert to username * * Return: * char *: Returns: * - Pointer to malloc()-ed buffer containing the username * - Pointer to malloc()-ed buffer containing string "user-UID" for non-existent user * - NULL on failure */ char * snoopy_util_pwd_convertUidToUsername (uid_t uid) { struct passwd pwd; struct passwd *pwd_uid = NULL; char *buffpwd_uid = NULL; long buffpwdsize_uid = 0; char *username = NULL; /* Allocate memory */ buffpwdsize_uid = sysconf(_SC_GETPW_R_SIZE_MAX); if (-1 == buffpwdsize_uid) { buffpwdsize_uid = 16384; } buffpwd_uid = malloc(buffpwdsize_uid); if (NULL == buffpwd_uid) { return NULL; } username = malloc(LOGIN_NAME_MAX+1); if (NULL == username) { free(buffpwd_uid); return NULL; } username[0] = '\0'; /* Try uid->username conversion */ if (0 != getpwuid_r(uid, &pwd, buffpwd_uid, buffpwdsize_uid, &pwd_uid)) { free(buffpwd_uid); free(username); return NULL; } // Format the return if (NULL == pwd_uid) { snprintf(username, LOGIN_NAME_MAX, "user-%d", (int)uid); } else { snprintf(username, LOGIN_NAME_MAX, "%s", pwd_uid->pw_name); } username[LOGIN_NAME_MAX] = '\0'; // Just in case // Return free(buffpwd_uid); return username; } snoopy-snoopy-2.5.2/src/util/string-snoopy.h000066400000000000000000000030241470651710700211530ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include int snoopy_util_string_append (char *destString, size_t destStringBufSize, const char *appendThis); int snoopy_util_string_containsOnlyDigits (char const * const str); char * snoopy_util_string_copyLineFromContent (char const * const lineStartPtr); int snoopy_util_string_countChars (const char *stringToSearch, char characterToCount); char * snoopy_util_string_findLineStartingWith (char const * const content, char const * const searchString); int snoopy_util_string_getLineLength (char const * const lineStartPtr); void snoopy_util_string_nullTerminateLine (char const * const lineInContent); void snoopy_util_string_toUpper (char * s); snoopy-snoopy-2.5.2/src/util/string.c000066400000000000000000000150101470651710700176170ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) * * Header file must not be named "string.h" in order to not conflict with the global . * Therefore we're using the "-snoopy" suffix - "string-snoopy.h". */ #include "string-snoopy.h" #include "snoopy.h" #include #include #include /* * Append content to the end of string, watching for buffer overrun * * Params: * destString: string container to append to * destStringBufSize: maximum length of dest string, including \0 * appendThis: content to append to destString * * Return: * int: Appended size, or SNOOPY_ERROR (when remaining space in destination string is not big enough) */ int snoopy_util_string_append (char *destString, size_t destStringBufSize, const char *appendThis) { size_t destStringSize = 0; size_t destStringSizeRemaining = 0; size_t appendThisSize = 0; /* Verify the limits */ destStringSize = strlen(destString); appendThisSize = strlen(appendThis); destStringSizeRemaining = destStringBufSize - destStringSize; if (destStringSizeRemaining < appendThisSize) { return SNOOPY_ERROR; } /* Copy to the destination string */ strcat(&destString[destStringSize], appendThis); return (int) appendThisSize; } /* * Verify whether given string only contains characters 0-9 * * Params: * str: String to verify * * Return: * int: SNOOPY_TRUE or SNOOPY_FALSE */ int snoopy_util_string_containsOnlyDigits (const char * str) { while (*str) { if (isdigit(*str++) == 0) { return SNOOPY_FALSE; } } return SNOOPY_TRUE; } /* * Copy the pointed-to text line from content into a new buffer * * Params: * lineStartPtr: Pointer to the start of the line. Can be a pointer to a * random location inside a larger (multiline) string. Must * point to the actual beginning of the line, or else the * preceding characters on the line will be ignored. * * Return: * char *: Pointer to malloc()-ed buffer containing the line copy (not containing the (potentially) terminating \n character) */ char * snoopy_util_string_copyLineFromContent (char const * const lineStartPtr) { int lineLen = 0; char * copiedLine = NULL; lineLen = snoopy_util_string_getLineLength(lineStartPtr); copiedLine = malloc(lineLen+1); strncpy(copiedLine, lineStartPtr, lineLen); copiedLine[lineLen] = '\0'; return copiedLine; } /* * Count number of occurrences of specified character in a given string * * Params: * stringToSearch: string to look into * characterToCount: search for this character * * Return: * int Number of occurrences */ int snoopy_util_string_countChars (const char *stringToSearch, char characterToCount) { const char *strPtr = stringToSearch; int charCount = 0; while ('\0' != *strPtr) { if (*strPtr == characterToCount) { charCount++; } strPtr++; } return charCount; } /* * Find a line in a multiline content that start with searchString * * Params: * content: Multi-line content to scan through * searchString: String to search for at the beginning of each line * * Return: * const char *: Pointer to the line starting with searchString, or NULL if not found */ char * snoopy_util_string_findLineStartingWith (char const * const content, char const * const searchString) { const char * contentPos = NULL; char * foundStringPos = NULL; contentPos = content; while ((foundStringPos = strstr(contentPos, searchString)) != NULL) { // Check the start of the line if ( (foundStringPos == content) // Start of the content || ((foundStringPos > content) && (foundStringPos[-1] == '\n')) // The preceding character is a newline ) { return foundStringPos; } contentPos = foundStringPos + strlen(searchString); } return NULL; } /* * Get the length of a pointed-to text line * * Params: * lineStartPtr: Pointer to the start of the line. Can be a pointer to a * random location inside a larger (multiline) string. Must * point to the actual beginning of the line, or else the * preceding characters on the line will be ignored. * * Return: * int: Number of characters (bytes) in the pointed-to line (excluding the potential \n character) */ int snoopy_util_string_getLineLength (char const * const lineStartPtr) { long lineLen = 0; const char * newlineCharPos = NULL; newlineCharPos = strchr(lineStartPtr, '\n'); if (newlineCharPos == NULL) { lineLen = strlen(lineStartPtr); } else { lineLen = newlineCharPos - lineStartPtr; } return (int) lineLen; } /* * Null-terminate a line in content ("destroys" content in-place by replacing \n with \0) * * Params: * lineInContent: Pointer to a line in multiline content * * Return: * void */ void snoopy_util_string_nullTerminateLine (char const * const lineInContent) { char * newlineCharPos = NULL; newlineCharPos = strchr(lineInContent, '\n'); if (newlineCharPos != NULL) { *newlineCharPos = '\0'; } } /* * Convert string to upper case * * Params: * s: Pointer to string to work on * * Return: * void */ void snoopy_util_string_toUpper (char * s) { while (*s) { if ((*s >= 'a' ) && (*s <= 'z')) { *s -= ('a'-'A'); } s++; } } snoopy-snoopy-2.5.2/src/util/syslog-snoopy.h000066400000000000000000000021531470651710700211670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopy_util_syslog_convertFacilityToInt (const char *facilityStr); const char* snoopy_util_syslog_convertFacilityToStr (int facilityInt); int snoopy_util_syslog_convertLevelToInt (const char *levelStr); const char* snoopy_util_syslog_convertLevelToStr (int levelInt); snoopy-snoopy-2.5.2/src/util/syslog.c000066400000000000000000000165021470651710700176400ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) * * Header file must not be named "syslog.h" in order to not conflict with the global . * Therefore we're using the "-snoopy" suffix - "syslog-snoopy.h". */ #include "syslog-snoopy.h" #include "snoopy.h" #include #include /* * Return corresponding integer for each syslog facility * * Params: * facilityStr Syslog facility string to convert * * Return: * int Corresponding syslog facility id, or -1 if not found */ int snoopy_util_syslog_convertFacilityToInt (const char *facilityStr) { const char *facilityStrAdj; int facilityInt; facilityStrAdj = facilityStr; // If there is LOG_ prefix, loose it. if ('_' == facilityStr[3]) { facilityStrAdj = &facilityStr[4]; } // Evaluate if (strcmp(facilityStrAdj, "AUTH") == 0) { facilityInt = LOG_AUTH; } else if (strcmp(facilityStrAdj, "AUTHPRIV") == 0) { facilityInt = LOG_AUTHPRIV; } else if (strcmp(facilityStrAdj, "CRON") == 0) { facilityInt = LOG_CRON; } else if (strcmp(facilityStrAdj, "DAEMON") == 0) { facilityInt = LOG_DAEMON; } else if (strcmp(facilityStrAdj, "FTP") == 0) { facilityInt = LOG_FTP; } else if (strcmp(facilityStrAdj, "KERN") == 0) { facilityInt = LOG_KERN; } else if (strcmp(facilityStrAdj, "LOCAL0") == 0) { facilityInt = LOG_LOCAL0; } else if (strcmp(facilityStrAdj, "LOCAL1") == 0) { facilityInt = LOG_LOCAL1; } else if (strcmp(facilityStrAdj, "LOCAL2") == 0) { facilityInt = LOG_LOCAL2; } else if (strcmp(facilityStrAdj, "LOCAL3") == 0) { facilityInt = LOG_LOCAL3; } else if (strcmp(facilityStrAdj, "LOCAL4") == 0) { facilityInt = LOG_LOCAL4; } else if (strcmp(facilityStrAdj, "LOCAL5") == 0) { facilityInt = LOG_LOCAL5; } else if (strcmp(facilityStrAdj, "LOCAL6") == 0) { facilityInt = LOG_LOCAL6; } else if (strcmp(facilityStrAdj, "LOCAL7") == 0) { facilityInt = LOG_LOCAL7; } else if (strcmp(facilityStrAdj, "LPR") == 0) { facilityInt = LOG_LPR; } else if (strcmp(facilityStrAdj, "MAIL") == 0) { facilityInt = LOG_MAIL; } else if (strcmp(facilityStrAdj, "NEWS") == 0) { facilityInt = LOG_NEWS; } else if (strcmp(facilityStrAdj, "SYSLOG") == 0) { facilityInt = LOG_SYSLOG; } else if (strcmp(facilityStrAdj, "USER") == 0) { facilityInt = LOG_USER; } else if (strcmp(facilityStrAdj, "UUCP") == 0) { facilityInt = LOG_UUCP; } else { facilityInt = -1; } return facilityInt; } /* * Convert syslog facility from integer code to corresponding string * * Params: * facilityInt Syslog facility to convert * * Return: * const char * Corresponding syslog facility string */ const char* snoopy_util_syslog_convertFacilityToStr (int facilityInt) { const char *facilityStr; // Evaluate and set return value if (LOG_AUTH == facilityInt) { facilityStr = "AUTH"; } else if (LOG_AUTHPRIV == facilityInt) { facilityStr = "AUTHPRIV"; } else if (LOG_CRON == facilityInt) { facilityStr = "CRON"; } else if (LOG_DAEMON == facilityInt) { facilityStr = "DAEMON"; } else if (LOG_FTP == facilityInt) { facilityStr = "FTP"; } else if (LOG_KERN == facilityInt) { facilityStr = "KERN"; } else if (LOG_LOCAL0 == facilityInt) { facilityStr = "LOCAL0"; } else if (LOG_LOCAL1 == facilityInt) { facilityStr = "LOCAL1"; } else if (LOG_LOCAL2 == facilityInt) { facilityStr = "LOCAL2"; } else if (LOG_LOCAL3 == facilityInt) { facilityStr = "LOCAL3"; } else if (LOG_LOCAL4 == facilityInt) { facilityStr = "LOCAL4"; } else if (LOG_LOCAL5 == facilityInt) { facilityStr = "LOCAL5"; } else if (LOG_LOCAL6 == facilityInt) { facilityStr = "LOCAL6"; } else if (LOG_LOCAL7 == facilityInt) { facilityStr = "LOCAL7"; } else if (LOG_LPR == facilityInt) { facilityStr = "LPR"; } else if (LOG_MAIL == facilityInt) { facilityStr = "MAIL"; } else if (LOG_NEWS == facilityInt) { facilityStr = "NEWS"; } else if (LOG_SYSLOG == facilityInt) { facilityStr = "SYSLOG"; } else if (LOG_USER == facilityInt) { facilityStr = "USER"; } else if (LOG_UUCP == facilityInt) { facilityStr = "UUCP"; } else { facilityStr = "(invalid)"; } return facilityStr; } /* * Return corresponding integer for each syslog level * * Params: * levelStr Syslog level string to convert * * Return: * int Corresponding syslog level id, or -1 if not found */ int snoopy_util_syslog_convertLevelToInt (const char *levelStr) { const char *levelStrAdj; int levelInt; levelStrAdj = levelStr; // If there is LOG_ prefix, loose it. if ('_' == levelStr[3]) { levelStrAdj = &levelStr[4]; } // Evaluate and set return value if (strcmp(levelStrAdj, "EMERG") == 0) { levelInt = LOG_EMERG; } else if (strcmp(levelStrAdj, "ALERT") == 0) { levelInt = LOG_ALERT; } else if (strcmp(levelStrAdj, "CRIT") == 0) { levelInt = LOG_CRIT; } else if (strcmp(levelStrAdj, "ERR") == 0) { levelInt = LOG_ERR; } else if (strcmp(levelStrAdj, "WARNING") == 0) { levelInt = LOG_WARNING; } else if (strcmp(levelStrAdj, "NOTICE") == 0) { levelInt = LOG_NOTICE; } else if (strcmp(levelStrAdj, "INFO") == 0) { levelInt = LOG_INFO; } else if (strcmp(levelStrAdj, "DEBUG") == 0) { levelInt = LOG_DEBUG; } else { levelInt = SNOOPY_SYSLOG_LEVEL; } return levelInt; } /* * Convert syslog level from integer code to corresponding string * * Params: * levelInt Syslog level to convert * * Return: * const char * Corresponding syslog facility string */ const char * snoopy_util_syslog_convertLevelToStr (int levelInt) { const char *levelStr; // Evaluate and set return value if (LOG_EMERG == levelInt) { levelStr = "EMERG"; } else if (LOG_ALERT == levelInt) { levelStr = "ALERT"; } else if (LOG_CRIT == levelInt) { levelStr = "CRIT"; } else if (LOG_ERR == levelInt) { levelStr = "ERR"; } else if (LOG_WARNING == levelInt) { levelStr = "WARNING"; } else if (LOG_NOTICE == levelInt) { levelStr = "NOTICE"; } else if (LOG_INFO == levelInt) { levelStr = "INFO"; } else if (LOG_DEBUG == levelInt) { levelStr = "DEBUG"; } else { levelStr = "(invalid)"; } return levelStr; } snoopy-snoopy-2.5.2/src/util/systemd-snoopy.h000066400000000000000000000017351470651710700213440ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ char * snoopy_util_systemd_convertCgroupEntryToUnitName (char const * const cgroupEntry); char * snoopy_util_systemd_convertUserSliceInfoToUsername (char const * const userSliceInfo); snoopy-snoopy-2.5.2/src/util/systemd.c000066400000000000000000000125511470651710700200100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) */ #include "systemd-snoopy.h" //#include "snoopy.h" #include "util/pwd-snoopy.h" #include #include /* * Internal function prototypes */ static char const * cgroupEntry_movePastInitialChaff (char const * const cgroupEntry); /* * Local defines */ #define SYSTEMD_SLICE_TYPE__INIT "init.scope" #define SYSTEMD_SLICE_TYPE__SYSTEM "system.slice/" #define SYSTEMD_SLICE_TYPE__USER "user.slice/" /* * Try to convert cgroup info text "1:name=systemd:/..." to Systemd unit name * * Supports the following formats: * - 1:name=systemd:/ * - 1:name=systemd:/init.scope * - 1:name=systemd:/system.slice/dbus.service * - 1:name=systemd:/user.slice/user-1000.slice/session-3178.scope * * Params: * cgroupInfoText: The "1:name=systemd:/..." line from /proc/PID/cgroup file * * Return: * char *: Returns: * - Pointer to malloc()-ed buffer containing the unit name * - NULL on failure */ char * snoopy_util_systemd_convertCgroupEntryToUnitName (char const * const cgroupEntry) { const char * matchPtr = NULL; const char * dotPtr = NULL; // Get past the chaff (the initial "1:name=systemd:/" part of the cgroup definition) matchPtr = cgroupEntry_movePastInitialChaff(cgroupEntry); if (!matchPtr) { return NULL; } // Which type of systemd entry is it? // // Empty content, line "1:name=systemd:/" if (*matchPtr == '\0') { return strdup("-"); // Type: init.scope } else if (0 == strncmp(matchPtr, SYSTEMD_SLICE_TYPE__INIT, strlen(SYSTEMD_SLICE_TYPE__INIT))) { return strdup("init"); // Type: system.slice/ } else if (0 == strncmp(matchPtr, SYSTEMD_SLICE_TYPE__SYSTEM, strlen(SYSTEMD_SLICE_TYPE__SYSTEM))) { matchPtr += strlen(SYSTEMD_SLICE_TYPE__SYSTEM); dotPtr = strchr(matchPtr, '.'); if ((dotPtr != NULL) && (0 == strcmp(dotPtr, ".service"))) { return strndup(matchPtr, dotPtr-matchPtr); } else { return strdup(matchPtr); } // Type: user.slice/ } else if (0 == strncmp(matchPtr, SYSTEMD_SLICE_TYPE__USER, strlen(SYSTEMD_SLICE_TYPE__USER))) { matchPtr += strlen(SYSTEMD_SLICE_TYPE__USER); return snoopy_util_systemd_convertUserSliceInfoToUsername(matchPtr); } // Unknown format return NULL; } /* * Convert user slice info text (i.e. "user-1000.slice/session-3178.scope") to username * * The user slice info text comes from /proc/PID/cgroup file, from the follwing entry * 1:name=systemd:/user.slice/user-1000.slice/session-3178.scope * * Params: * userSliceInfo: The "user-1000.slice/session-3178.scope" part of the "1:name=systemd:/" line from /proc/PID/cgroup file * * Return: * char *: Returns: * - Pointer to malloc()-ed buffer containing the username * - Pointer to malloc()-ed buffer containig "user-UID" string when UID cannot be resolved to username * - NULL on failure */ char * snoopy_util_systemd_convertUserSliceInfoToUsername (char const * const userSliceInfo) { const char * matchPtr = userSliceInfo; char * dotPtr = NULL; uid_t uid; // Isolate UID string if (0 != strncmp(matchPtr, "user-", 5)) { return NULL; } matchPtr += 5; dotPtr = strchr(matchPtr, '.'); if (dotPtr == NULL) { return NULL; } *dotPtr = '\0'; // Convert UID string to uid_t uid = atoi(matchPtr); // Convert UID to username return snoopy_util_pwd_convertUidToUsername(uid); } /* * Take cgroup info text, and return a pointer to where the real content starts * * Example: * 1:name=systemd:/system.slice/dbus.service * ^ * | * This is where the return pointer will be pointing to. * * Params: * cgroupEntry: The "1:name=systemd:/..." line from /proc/PID/cgroup file * * Return: * char *: Returns: * - Pointer to the desired location in the given cgroupEntry text * - NULL on failure */ static char const * cgroupEntry_movePastInitialChaff (char const * const cgroupEntry) { char const * matchPtr = cgroupEntry; matchPtr = strchr(cgroupEntry, ':'); if (!matchPtr) { return NULL; } matchPtr++; matchPtr = strchr(matchPtr, ':'); if (!matchPtr) { return NULL; } matchPtr++; if (*matchPtr != '/') { return NULL; } matchPtr++; return matchPtr; } snoopy-snoopy-2.5.2/src/util/utmp-snoopy.h000066400000000000000000000026361470651710700206420ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GNU_SOURCE #define _GNU_SOURCE // For getutline_r() in utmp.c #endif #include #include int snoopy_util_utmp_findUtmpEntryByLine (char const * const ttyLine, struct utmp * const resultEntryBuf); int snoopy_util_utmp_findUtmpEntryByPath (char const * const ttyPath, struct utmp * const resultEntryBuf); int snoopy_util_utmp_doesEntryContainIpAddr (struct utmp const * const utmpEntry); int snoopy_util_utmp_getUtmpIpAddrAsString (struct utmp const * const utmpEntry, char * const resultBuf, size_t resultBufSize); void snoopy_util_utmp_test_setAlternateUtmpFilePath (char const * const utmpPath); snoopy-snoopy-2.5.2/src/util/utmp.c000066400000000000000000000103201470651710700172750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese (bostjan _A_T_ a2o.si) * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global (local, this-subsystem, snoopy.h, other-subsystems, global) */ #include "utmp-snoopy.h" #ifndef _GNU_SOURCE #define _GNU_SOURCE // for getutline_r() #endif #include "snoopy.h" #include #include #include #include /* * Try to find utmp entry matching TTY line * * Params: * ttyLine: TTY ("line") to search for, without the "/dev/" prefix * resultEntryBuf: Buffer to return result in * * Return: * int: SNOOPY_TRUE or * SNOOPY_FALSE (when not found, or error occurs) */ int snoopy_util_utmp_findUtmpEntryByLine (char const * const ttyLine, struct utmp * const resultEntryBuf) { struct utmp searchEntry; struct utmp * resultEntry; int retVal; // Prepare the search conditions strncpy(searchEntry.ut_line, ttyLine, UT_LINESIZE); searchEntry.ut_line[UT_LINESIZE-1] = '\0'; // Do the search setutent(); retVal = getutline_r(&searchEntry, resultEntryBuf, &resultEntry); endutent(); // Failure/not found if (retVal != 0) { return SNOOPY_FALSE; } // Found return SNOOPY_TRUE; } /* * Try to find utmp entry matching TTY path * * Params: * ttyLine: TTY defice path to search for, _including_ the "/dev/" prefix * resultEntryBuf: Buffer to return result in * * Return: * int: SNOOPY_TRUE or * SNOOPY_FALSE (when not found, or error occurs) */ int snoopy_util_utmp_findUtmpEntryByPath (char const * const ttyPath, struct utmp * const resultEntryBuf) { const char * ttyLine; // "Remove" the initial `/dev/` part if (0 != strncmp(ttyPath, "/dev/", strlen("/dev/"))) { return SNOOPY_FALSE; } ttyLine = ttyPath + strlen("/dev/"); return snoopy_util_utmp_findUtmpEntryByLine(ttyLine, resultEntryBuf); } /* * Check if utmp entry contains an IP address * * Params: * utmpEntry: UTMP entry to work with * * Return: * int: SNOOPY_TRUE or * SNOOPY_FALSE */ int snoopy_util_utmp_doesEntryContainIpAddr (struct utmp const * const utmpEntry) { if ((utmpEntry->ut_addr_v6[0] == 0) && (utmpEntry->ut_addr_v6[1] == 0) && (utmpEntry->ut_addr_v6[2] == 0) && (utmpEntry->ut_addr_v6[3] == 0) ) { return SNOOPY_FALSE; } else { return SNOOPY_TRUE; } } /* * Extract utmp entry's IP address as string * * Params: * utmpEntry: UTMP entry to work with * resultBuf: Buffer to return result in * resultBufSize: Size of resultBuf * * Return: * int: SNOOPY_TRUE or * SNOOPY_FALSE */ int snoopy_util_utmp_getUtmpIpAddrAsString (struct utmp const * const utmpEntry, char * const resultBuf, size_t resultBufSize) { if ((utmpEntry->ut_addr_v6[1] == 0) && (utmpEntry->ut_addr_v6[2] == 0) && (utmpEntry->ut_addr_v6[3] == 0) ) { inet_ntop(AF_INET, &(utmpEntry->ut_addr_v6[0]), resultBuf, (socklen_t) resultBufSize); } else { inet_ntop(AF_INET6, utmpEntry->ut_addr_v6, resultBuf, (socklen_t) resultBufSize); } return SNOOPY_TRUE; } /* * Set path to alternate utmp file, for other functions to use * * Params: * utmpPath: Path to UTMP file to use * * Return: * void */ void snoopy_util_utmp_test_setAlternateUtmpFilePath (char const * const utmpPath) { utmpname(utmpPath); } snoopy-snoopy-2.5.2/tests/000077500000000000000000000000001470651710700155465ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/Makefile.am000066400000000000000000000015251470651710700176050ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Subdir processing order # SUBDIRS = SUBDIRS += bin SUBDIRS += cli if CONFIGFILE_ENABLED SUBDIRS += configfile endif SUBDIRS += datasource if FILTERING_ENABLED SUBDIRS += filter endif SUBDIRS += general SUBDIRS += message SUBDIRS += output if THREAD_SAFETY_ENABLED SUBDIRS += threads endif SUBDIRS += unit # # Functional tests at last # if CONFIGFILE_ENABLED if DATASOURCE_ENABLED_cmdline if OUTPUT_ENABLED_file SUBDIRS += combined endif endif endif ### Include these files too # EXTRA_DIST = EXTRA_DIST += _bootstrap.sh EXTRA_DIST += _bootstrap-paths.sh ### Clean all test leftovers # # These are usually left behind when we rename files # clean-local-this-dir: rm -f */*.log ; rm -f */*.trs ; snoopy-snoopy-2.5.2/tests/_bootstrap-paths.sh.in000077500000000000000000000002601470651710700220010ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Get variables from the build system # SNOOPY_LIBDIR="@SNOOPY_LIBDIR@" LIBSNOOPY_SO_PATH="$SNOOPY_LIBDIR/libsnoopy.so" snoopy-snoopy-2.5.2/tests/_bootstrap.sh000077500000000000000000000044331470651710700202650ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Source build-based variables # . ../_bootstrap-paths.sh ### Get variables about current test # SNOOPY_CUR_TEST_PATH=`readlink -f $0` echo "Current test path: $SNOOPY_CUR_TEST_PATH" SNOOPY_CUR_TEST_DIR=`dirname $SNOOPY_CUR_TEST_PATH` SNOOPY_CUR_TEST_FILENAME=`basename $SNOOPY_CUR_TEST_PATH` SNOOPY_CUR_TEST_NAME=`echo $SNOOPY_CUR_TEST_FILENAME | sed -e 's/\.sh$//'` SNOOPY_CUR_TEST_GROUP_PATH=`dirname $SNOOPY_CUR_TEST_PATH` SNOOPY_CUR_TEST_GROUP_NAME=`basename $SNOOPY_CUR_TEST_GROUP_PATH` ### Configure paths # SNOOPY_TESTS_ROOTDIR=`dirname $SNOOPY_CUR_TEST_GROUP_PATH` # # Current working directory might not be the same, # if build is being done outside of source tree. # # Also now there is an assumption that all tests are placed in subdirs of # root tests/ directory. # # Do not use "readlink -f $THIS_FILE_PATH" - PWD differs when building outside of source dir # SNOOPY_CUR_TEST_WORKDIR=`pwd` SNOOPY_TESTS_BINDIR="$SNOOPY_CUR_TEST_WORKDIR/../bin" SNOOPY_TEST_CLI="$SNOOPY_TESTS_BINDIR/snoopy-test" export SNOOPY_LIBSNOOPY_TEST_SO_PATH="${SNOOPY_TESTS_BINDIR}/.libs/libsnoopy-test-execve-wrapper-env-ini-path.so" ### Test run function: info output # snoopy_testRun_info() { echo "$1" } ### Result function: PASS # snoopy_testResult_pass() { echo "PASS" if [ ! -z "${1:-}" ]; then echo "$1" fi exit 0 } ### Result function: PASS # snoopy_testResult_fail() { MSG="$1" echo "FAIL" echo "$1" exit 1 } ### Result function: SKIP # snoopy_testResult_skip() { MSG="$1" echo "SKIPPED: $MSG" exit 77 } ### Comparison function: PASS # snoopy_test_compareValues() { VAL_SNOOPY="$1" VAL_REAL="$2" if [ "$VAL_SNOOPY" != "$VAL_REAL" ]; then snoopy_testResult_fail "Values do not match (snoopy=\"$VAL_SNOOPY\", real=\"$VAL_REAL\")" fi snoopy_testResult_pass } ### Data retriever: from ps # snoopy_test_getValue_fromPs() { PID="$1" FIELD="$2" COUNT=`ps -eo pid,$FIELD | grep -E "^[ ]*$PID[ ]+" -c` if [ "$COUNT" != "1" ]; then echo "ERROR: Invalid number of processes matched while looking for $FIELD" return 1 fi VALUE=`ps -eo pid,$FIELD | grep -E "^[ ]*$PID[ ]+" | head -n1 | awk '{print $2}'` echo "$VALUE" return 0 } snoopy-snoopy-2.5.2/tests/bin/000077500000000000000000000000001470651710700163165ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/bin/Makefile.am000066400000000000000000000062511470651710700203560ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Init empty program install list, but always link with given library # noinst_PROGRAMS = ### Programs required by the test suite # noinst_PROGRAMS += snoopy-test snoopy_test_SOURCES = \ action-common.h \ action-run.c \ action-run.h \ action-run-datasource.c \ action-run-datasource.h \ action-run-everything.c \ action-run-everything.h \ action-run-messageformat.c \ action-run-messageformat.h \ action-run-output.c \ action-run-output.h \ action-stress.c \ action-stress.h \ action-unit.c \ action-unit.h \ action-unit-action.c \ action-unit-action.h \ action-unit-action-log-syscall-exec.c \ action-unit-action-log-syscall-exec.h \ action-unit-action-log-message-dispatch.c \ action-unit-action-log-message-dispatch.h \ action-unit-datasource.c \ action-unit-datasource.h \ action-unit-error.c \ action-unit-error.h \ action-unit-outputregistry.c \ action-unit-outputregistry.h \ action-unit-util.c \ action-unit-util.h \ action-unit-util-parser.c \ action-unit-util-parser.h \ action-unit-util-syslog.c \ action-unit-util-syslog.h \ snoopy-test.c snoopy_test_LDADD = \ ../../src/libsnoopy-test-cli.la if CONFIGFILE_ENABLED snoopy_test_SOURCES += \ action-run-configfile.c \ action-run-configfile.h \ action-unit-ext-ini.c \ action-unit-ext-ini.h endif if FILTERING_ENABLED snoopy_test_SOURCES += \ action-run-filter.c \ action-run-filter.h \ action-run-filterchain.c \ action-run-filterchain.h \ action-unit-filterregistry.c \ action-unit-filterregistry.h endif if THREAD_SAFETY_ENABLED snoopy_test_SOURCES += \ action-stress-threads.c \ action-stress-threads.h \ action-stress-threadsexec.c \ action-stress-threadsexec.h endif if DATASOURCE_ENABLED_cmdline snoopy_test_SOURCES += \ action-unit-datasource-cmdline.c \ action-unit-datasource-cmdline.h endif if DATASOURCE_ENABLED_systemd_unit_name snoopy_test_SOURCES += \ action-unit-util-systemd.c \ action-unit-util-systemd.h endif if DATASOURCE_ENABLED_ipaddr snoopy_test_SOURCES += \ action-unit-util-utmp.c \ action-unit-util-utmp.h endif noinst_PROGRAMS += spaceparent spaceparent_SOURCES = spaceparent.c ### Create a program called "space parent", for testing filter exclude_spawns_of # all-local: spaceparent @cp spaceparent "space parent" clean-local-this-dir: rm -f "space parent" ### Create test library, whole # # This library reads path to snoopy.ini from SNOOPY_INI environmental variable. # noinst_LTLIBRARIES = libsnoopy-test-execve-wrapper-env-ini-path.la libsnoopy_test_execve_wrapper_env_ini_path_la_SOURCES = libsnoopy_test_execve_wrapper_env_ini_path_la_LIBADD = \ ../../src/libsnoopy-no-entrypoint.la \ ../../src/entrypoint/libsnoopy-entrypoint-execve-wrapper-test-configfile-env.la # # This needs to be added as automake does not create shared library for # things in noinst_LTLIBRARIES. # libsnoopy_test_execve_wrapper_env_ini_path_la_LDFLAGS = -module -rpath /nowhere snoopy-snoopy-2.5.2/tests/bin/action-common.h000066400000000000000000000015611470651710700212350ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "cli/cli-subroutines.h" extern int g_argc; extern char ** g_argv; snoopy-snoopy-2.5.2/tests/bin/action-run-configfile.c000066400000000000000000000120611470651710700226440ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configfile.h" #include "configuration.h" #include "inputdatastorage.h" #include "util/syslog-snoopy.h" #include #include #include #include #include void displayHelp () { printf("\n"); printf("Usage: \n"); printf(" snoopy-test-configfile PATH-TO-INI CONFIG-VARIABLE-TO-DISPLAY\n"); printf("\n"); printf("Available configfile variables:\n"); printf(" (check etc/snoopy.ini for list of supported configuration variables)\n"); printf("\n"); } void snoopyTestCli_action_run_configfile_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `run` :: Subsystem `configfile`\n" "\n" "Usage:\n" " snoopy-test run configfile INI_FILE KEY\n" "\n" "Result:\n" " Prints value of the requested configuration KEY from the given INI_FILE.\n" "\n" "Supported configuration keys (check etc/snoopy.ini for more information):\n" " message_format\n" " filter_chain\n" " output\n" " syslog_facility\n" " syslog_ident\n" " syslog_level\n" " datasource_message_max_length\n" " log_message_max_length\n" "NOTICE: These keys MUST be placed in a section named [snoopy].\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_run_configfile (int argc, char **argv) { char *iniFilePath; const char *showConfigVar; snoopy_configuration_t *CFG; /* Check if all arguments are present */ if (argc < 1) { snoopyTestCli_action_run_configfile_showHelp(); fatalError("Missing argument: path to INI config file"); } if (0 == strcmp(argv[0], "--help")) { snoopyTestCli_action_run_configfile_showHelp(); return 0; } iniFilePath = argv[0]; if (argc < 2) { snoopyTestCli_action_run_configfile_showHelp(); fatalError("Missing argument: configuration variable to display"); } showConfigVar = argv[1]; /* Check if config file exists and is readable */ if (-1 == access(iniFilePath, R_OK)) { snoopyTestCli_action_run_configfile_showHelp(); printErrorValue("INI file path", iniFilePath); fatalErrorValue("Unable to open/read given INI file", strerror(errno)); } /* Initialize Snoopy, which parses alternate configuration file too */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, iniFilePath); /* Get config pointer */ CFG = snoopy_configuration_get(); /* Output appropriate value */ if (0 == strcmp(showConfigVar, "message_format")) { printf("%s\n", CFG->message_format); } else if (0 == strcmp(showConfigVar, "filter_chain")) { printf("%s\n", CFG->filter_chain); } else if (0 == strcmp(showConfigVar, "output")) { printf("%s", CFG->output); if ('\0' != CFG->output_arg[0]) { printf(":%s", CFG->output_arg); } printf("\n"); } else if (0 == strcmp(showConfigVar, "syslog_facility")) { printf("%s\n", snoopy_util_syslog_convertFacilityToStr(CFG->syslog_facility)); } else if (0 == strcmp(showConfigVar, "syslog_ident")) { printf("%s\n", CFG->syslog_ident_format); } else if (0 == strcmp(showConfigVar, "syslog_level")) { printf("%s\n", snoopy_util_syslog_convertLevelToStr(CFG->syslog_level)); } else if (0 == strcmp(showConfigVar, "datasource_message_max_length")) { char * valBuf = snoopy_configfile_getOptionValueAsString_datasource_message_max_length(); printf("%s\n", valBuf); free(valBuf); } else if (0 == strcmp(showConfigVar, "log_message_max_length")) { char * valBuf = snoopy_configfile_getOptionValueAsString_log_message_max_length(); printf("%s\n", valBuf); free(valBuf); } else if (0 == strcmp(showConfigVar, "error_logging")) { printf("%s\n", (CFG->error_logging_enabled == SNOOPY_TRUE ? "y" : "n")); } else { fatalErrorValue("Unknown setting given", showConfigVar); } /* Housekeeping and return */ snoopy_entrypoint_test_cli_exit(); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-run-configfile.h000066400000000000000000000015411470651710700226520ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_configfile (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-run-datasource.c000066400000000000000000000124531470651710700226760ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-run-datasource.h" #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include "error.h" #include "datasourceregistry.h" #include "inputdatastorage.h" #include #include #include void snoopyTestCli_action_run_datasource_showList () { printf("Available datasources:\n"); int dCount = snoopy_datasourceregistry_getCount(); for (int i=0 ; idatasource_message_max_length); return 0; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_run_datasource_showHelp(); return 0; } if (0 == strcmp(arg1, "--list")) { snoopyTestCli_action_run_datasource_showList(); return 0; } datasourceName = arg1; /* Check if what we got is a valid datasource name */ if (SNOOPY_FALSE == snoopy_datasourceregistry_doesNameExist(datasourceName)) { snoopyTestCli_action_run_datasource_showHelp(); fatalError("Invalid datasource name given"); } /* Is there an argument for this data source */ if (argc >= 2) { datasourceArg = argv[1]; } else { datasourceArg = ""; } /* Call the datasource */ datasourceResult = malloc(CFG->datasource_message_max_length+1); retVal = snoopy_datasourceregistry_callByName(datasourceName, datasourceResult, CFG->datasource_message_max_length+1, datasourceArg); if (SNOOPY_DATASOURCE_FAILED(retVal)) { fatalErrorValueFree("Datasource failed", datasourceResult); } /* Display */ printf("%s\n", datasourceResult); /* Housekeeping and return */ free(datasourceResult); snoopy_entrypoint_test_cli_exit(); return 0; } void snoopyTestCli_action_run_datasource_all (size_t datasource_message_max_length) { char *itemName = NULL; const char *itemArgs = NULL; char *itemResult = NULL; size_t itemResultBufSize; size_t itemResultSize; int dCount; /* Initialize variables and spaces */ itemResultBufSize = datasource_message_max_length + 1; itemResult = malloc(itemResultBufSize); /* Loop through all datasources and just send to output */ dCount = snoopy_datasourceregistry_getCount(); for (int i=0 ; i itemResultBufSize) { snoopy_error_handler("Maximum data source message size exceeded"); } /* Copy content, append */ printf("%s\n", itemResult); } /* Memory housekeeping */ free(itemResult); } snoopy-snoopy-2.5.2/tests/bin/action-run-datasource.h000066400000000000000000000017151470651710700227020ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include int snoopyTestCli_action_run_datasource (int argc, char ** argv); void snoopyTestCli_action_run_datasource_all (size_t datasource_message_max_length); snoopy-snoopy-2.5.2/tests/bin/action-run-everything.c000066400000000000000000000067611470651710700227350ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #include "action-run-datasource.h" #include "action-run-filter.h" #include "action-run-output.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #ifdef SNOOPY_FILTERING_ENABLED #include "filtering.h" #endif #include "inputdatastorage.h" #include "action/log-message-dispatch.h" #include "message.h" #include #include #include void snoopyTestCli_action_run_everything_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `run` :: Run everything (for Valgrind)\n" "\n" "Usage:\n" " snoopy-test run everything\n" "\n" "Result:\n" " Runs as many subsystems as possible, to cover as much code as possible.\n" " Useful for Valgrind analysis.\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_run_everything () { char *logMessage = NULL; const snoopy_configuration_t * CFG; /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); /* Get config pointer */ CFG = snoopy_configuration_get(); /* Initialize empty log message */ logMessage = malloc(CFG->log_message_max_length+1); logMessage[0] = '\0'; /* Run throught as much code as possible */ #ifdef SNOOPY_FILTERING_ENABLED printf("-----[ Filters ]---------------------------------------\n"); snoopyTestCli_action_run_filter_all(); #endif printf("-----[ Filtering ]-------------------------------------\n"); #ifdef SNOOPY_FILTERING_ENABLED snoopy_filtering_check_chain("exclude_uid:10,11,12;only_uid=0,1,2,3"); printf("Done.\n"); #else printf("SKIPPED - not enabled.\n"); #endif printf("-----[ Datasources ]-----------------------------------\n"); snoopyTestCli_action_run_datasource_all(CFG->datasource_message_max_length+1); printf("-----[ Outputs ]---------------------------------------\n"); snoopyTestCli_action_run_output_all(); printf("-----[ Message formatting ]----------------------------\n"); snoopy_message_generateFromFormat(logMessage, CFG->log_message_max_length+1, CFG->datasource_message_max_length+1, CFG->message_format); printf("Message: %s\n", logMessage); printf("-----[ Dispatching ]-----------------------------------\n"); snoopy_action_log_message_dispatch(logMessage); printf("Done.\n"); printf("\nAll done.\n"); /* Cleanup and return */ free(logMessage); snoopy_entrypoint_test_cli_exit(); /* Close these FDs too, otherwise valgrind complains */ fclose(stdin); fclose(stdout); fclose(stderr); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-run-everything.h000066400000000000000000000015131470651710700227300ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_everything (); snoopy-snoopy-2.5.2/tests/bin/action-run-filter.c000066400000000000000000000112641470651710700220300ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-run-filter.h" #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include "filterregistry.h" #include "inputdatastorage.h" #include #include #include void snoopyTestCli_action_run_filter_showList () { printf("Available filters:\n"); int fCount = snoopy_filterregistry_getCount(); for (int i=0 ; i 1) { filterArg = argv[1]; } else { filterArg = ""; } /* Check if what we got is a valid filter name */ if (SNOOPY_FALSE == snoopy_filterregistry_doesNameExist(filterName)) { snoopyTestCli_action_run_filter_showHelp(); fatalErrorValue("Invalid filter name given", filterName); } /* Call the filter */ filterResult = snoopy_filterregistry_callByName(filterName, filterArg); /* Housekeeping */ snoopy_entrypoint_test_cli_exit(); /* Display and return */ if (SNOOPY_FILTER_PASS == filterResult) { printf("PASS\n"); return 0; } else { printf("DROP\n"); return 1; } } void snoopyTestCli_action_run_filter_all () { char *itemName = NULL; const char *itemArgs = NULL; int itemResult; int fCount; /* Loop throught all filters and run them with bogus arguments */ fCount = snoopy_filterregistry_getCount(); for (int i=0 ; i * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_filter (int argc, char ** argv); void snoopyTestCli_action_run_filter_all (); snoopy-snoopy-2.5.2/tests/bin/action-run-filterchain.c000066400000000000000000000056461470651710700230420ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "filtering.h" #include #include #include void snoopyTestCli_action_run_filterchain_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `run` :: Subsystem `filterchain`\n" "\n" "Usage:\n" " snoopy-test run filterchain \"FILTER_CHAIN\"\n" " snoopy-test run filterchain --help\n" "\n" "Description:\n" " Runs MESSAGE through a specified FILTER_CHAIN, with filters acting on the data taken from the current process.\n" " Filter chain specification format is described in the comments of snoopy.ini.\n" "\n" "Result:\n" " Prints the result of a filter chain as a \"PASS\" or a \"DROP\" to stdout.\n" " Sets the exit status to 0 or PASS or 1 for DROP.\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_run_filterchain (int argc, char **argv) { const char * arg1; const char * filterChain; int filterResult; /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); /* Check if all arguments are present */ if (argc < 1) { snoopyTestCli_action_run_filterchain_showHelp(); fatalError("Missing argument: filter chain specification, or --help"); } arg1 = argv[0]; if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_run_filterchain_showHelp(); return 0; } // Arg1 is a filter chain spec filterChain = arg1; if (argc < 1) { snoopyTestCli_action_run_filterchain_showHelp(); fatalError("Missing argument: filter chain specification"); } // Process the filter chain filterResult = snoopy_filtering_check_chain(filterChain); /* Housekeeping */ snoopy_entrypoint_test_cli_exit(); /* Display and return */ if (SNOOPY_FILTER_PASS == filterResult) { printf("PASS\n"); return 0; } else { printf("DROP\n"); return 1; } } snoopy-snoopy-2.5.2/tests/bin/action-run-filterchain.h000066400000000000000000000015421470651710700230360ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_filterchain (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-run-messageformat.c000066400000000000000000000050241470651710700233750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy-test-message-format.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include "inputdatastorage.h" #include "message.h" #include #include void snoopyTestCli_action_run_messageformat_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `run` :: Subsystem `message formatter`\n" "\n" "Usage:\n" " snoopy-test run messageformat \"FORMAT SPECIFICATION\"\n" "\n" "Result:\n" " Prints a log message formatted according to the given format specification.\n" " Process data is taken from self.\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_run_messageformat (int argc, char **argv) { const char * messageFormat; char * message; const snoopy_configuration_t *CFG; /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); /* Get config pointer */ CFG = snoopy_configuration_get(); /* Check if all arguments are present */ if (argc < 1) { snoopyTestCli_action_run_messageformat_showHelp(); fatalError("Missing argument: message format"); } messageFormat = argv[0]; /* Initialize message */ message = malloc(CFG->log_message_max_length+1); message[0] = '\0'; /* Call the filter */ snoopy_message_generateFromFormat(message, CFG->log_message_max_length+1, CFG->datasource_message_max_length+1, messageFormat); /* Display result */ printf("%s\n", message); /* Housekeeping and return */ free(message); snoopy_entrypoint_test_cli_exit(); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-run-messageformat.h000066400000000000000000000015441470651710700234050ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_messageformat (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-run-output.c000066400000000000000000000117541470651710700221070ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-run-output.h" #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include "inputdatastorage.h" #include "outputregistry.h" #include #include #include #include void snoopyTestCli_action_run_output_showList () { printf("Available outputs:\n"); int oCount = snoopy_outputregistry_getCount(); for (int i=0 ; i 2) { outputArg = argv[2]; } else { outputArg = ""; } /* Check if what we got is a valid output name */ if (SNOOPY_FALSE == snoopy_outputregistry_doesNameExist(outputName)) { snoopyTestCli_action_run_output_showHelp(); fatalErrorValue("Invalid output name given", outputName); } /* Dispatch message to output */ retVal = snoopy_outputregistry_callByName(outputName, message, outputArg); if (SNOOPY_OUTPUT_FAILED(retVal)) { fatalError("Output failure"); } /* Housekeeping and return */ snoopy_entrypoint_test_cli_exit(); return 0; } void snoopyTestCli_action_run_output_all () { char *message = NULL; char *itemName = NULL; const char *itemArgs = NULL; int itemResult; int iCount; const snoopy_configuration_t *CFG; /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); /* Get config pointer */ CFG = snoopy_configuration_get(); /* Initialize variables and spaces */ message = malloc(CFG->log_message_max_length+1); snprintf(message, CFG->log_message_max_length+1, "Snoopy output debugging"); /* Loop throught all outputs and run them with bogus arguments */ iCount = snoopy_outputregistry_getCount(); for (int i=0 ; i * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run_output (int argc, char ** argv); void snoopyTestCli_action_run_output_all (); snoopy-snoopy-2.5.2/tests/bin/action-run.c000066400000000000000000000073671470651710700205560ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #ifdef SNOOPY_CONFIGFILE_ENABLED #include "action-run-configfile.h" #endif #include "action-run-datasource.h" #ifdef SNOOPY_FILTERING_ENABLED #include "action-run-filter.h" #include "action-run-filterchain.h" #endif #include "action-run-messageformat.h" #include "action-run-output.h" #include "action-run-everything.h" #include #include #include #include void snoopyTestCli_action_run_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `run`\n" "\n" "Usage:\n" " snoopy run SUBSYSTEM [ARGS]\n" "\n" "Available subsystems:\n" #ifdef SNOOPY_CONFIGFILE_ENABLED " configfile,cf Run a configfile (.ini) parser\n" #endif " datasource,ds Run a data source\n" #ifdef SNOOPY_FILTERING_ENABLED " filter,f Run a filter\n" " filterchain,fc Run a filter chain (as if it would be configured in snoopy.ini)\n" #endif " messageformat,mf Run the message formatter\n" " output,o Run an output\n" "\n" " everything Runs every subsystem, as much as possible (for Valgrind)\n" "\n" " help,h Show this help\n" " SUBSYSTEM help Show SUBSYSTEM's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_run (int argc, char ** argv) { if (argc < 1) { snoopyTestCli_action_run_showHelp(); fatalError("No subsystem specified."); } #ifdef SNOOPY_CONFIGFILE_ENABLED if ((0 == strcmp(argv[0], "configfile")) || (0 == strcmp(argv[0], "cf"))) { return snoopyTestCli_action_run_configfile(argc-1, &argv[1]); } #endif if ((0 == strcmp(argv[0], "datasource")) || (0 == strcmp(argv[0], "ds"))) { return snoopyTestCli_action_run_datasource(argc-1, &(argv[1])); } #ifdef SNOOPY_FILTERING_ENABLED if ((0 == strcmp(argv[0], "filter")) || (0 == strcmp(argv[0], "f"))) { return snoopyTestCli_action_run_filter(argc-1, &argv[1]); } if ((0 == strcmp(argv[0], "filterchain")) || (0 == strcmp(argv[0], "fc"))) { return snoopyTestCli_action_run_filterchain(argc-1, &argv[1]); } #endif if ((0 == strcmp(argv[0], "messageformat")) || (0 == strcmp(argv[0], "mf"))) { return snoopyTestCli_action_run_messageformat(argc-1, &argv[1]); } if ((0 == strcmp(argv[0], "output")) || (0 == strcmp(argv[0], "o"))) { return snoopyTestCli_action_run_output(argc-1, &argv[1]); } if (0 == strcmp(argv[0], "everything")) { return snoopyTestCli_action_run_everything(); } if ((0 == strcmp(argv[0], "help")) || (0 == strcmp(argv[0], "h"))) { snoopyTestCli_action_run_showHelp(); return 0; } snoopyTestCli_action_run_showHelp(); fatalErrorValue("Unknown subsystem", argv[0]); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-run.h000066400000000000000000000015261470651710700205520ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_run (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-stress-threads.c000066400000000000000000000235051470651710700227150ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy-test-datasource.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include "datasourceregistry.h" #include "tsrm.h" #include #include #include #include #include #include #include #include #include #include #define THREAD_COUNT_MAX 10000 #define DS_MESSAGE_BUF_SIZE 1024 /* * Thread data */ typedef struct { int seqNr; } tData_t; /* * We do not use separate .h file here */ void * snoopyTestCli_action_stress_threads_threadMain (void *arg); int snoopyTestCli_action_stress_threads_randomNumberInclusive (int idMin, int idMax); /* * Global variables */ pthread_t snoopyTestCli_action_stress_threads_tRepo[THREAD_COUNT_MAX]; pthread_mutex_t threadCountMutex = PTHREAD_MUTEX_INITIALIZER; int threadCountCreated = 0; // Created threads, as seen by each thread int threadCountAliveNow = 0; // Number of threads currently alive int threadCountAliveMax = 0; // Maximum number of threads alive at any one time int verbose; void snoopyTestCli_action_stress_threads_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `stress` :: Subsystem `threads`\n" "\n" "Usage:\n" " snoopy-test stress threads THREAD_COUNT [-v]\n" "\n" "Description:\n" " Stresses Snoopy's threading implementation by creating and destroying THREAD_COUNT\n" " threads as fast as possible.\n" "\n" "Arguments:\n" " THREAD_COUNT Number of threads to create and destroy\n" " -v Verbose debugging output\n" "\n" "Output:\n" " Various threading-related messages and some statistics at the end.\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_stress_threads (int argc, char ** argv) { int threadsToCreate; int maxConcurrentThreadsObserved = 0; int retVal = 0; /* Check arguments and parse them */ if (argc < 1) { snoopyTestCli_action_stress_threads_showHelp(); fatalError("Missing argument: number of threads to create"); } threadsToCreate = atoi(argv[0]); if ((threadsToCreate < 1) || (threadsToCreate > THREAD_COUNT_MAX)) { snoopyTestCli_action_stress_threads_showHelp(); fatalError("Invalid number of threads to create (min 1, max THREAD_COUNT_MAX)"); } if ((argc >= 2) && (0 == strcmp(argv[1], "-v"))) { verbose = 1; } else { verbose = 0; } // Disable config file parsing snoopy_configuration_preinit_disableConfigFileParsing(); // Do not call snoopy_init() in the main thread here, as we're letting the non-main threads // figure it out for themselves. // Create threads and run the function in them printf("M: Starting threads... "); for (int i=0 ; iseqNr = i; if (verbose) printf(" M: Starting thread #%d:\n", i+1); retVal = pthread_create(&snoopyTestCli_action_stress_threads_tRepo[i], NULL, &snoopyTestCli_action_stress_threads_threadMain, tArgs); } printf("done.\n"); printf("M: Threads alive right after thread creation was completed: %d\n", threadCountAliveNow); // Sleep a bit, and get thread count, should be max if (verbose) { struct timespec ts_sleep; ts_sleep.tv_sec = 0; ts_sleep.tv_nsec = 200000000; nanosleep(&ts_sleep, NULL); maxConcurrentThreadsObserved = snoopy_tsrm_get_threadCount(); printf("M: Threads after first sleep: %d\n", maxConcurrentThreadsObserved); // Sleep a bit more for all threads to finish nanosleep(&ts_sleep, NULL); printf("M: Threads after all threads are supposedly finished: %d\n", snoopy_tsrm_get_threadCount()); } // Wait for threads to finish printf("M: Waiting for all threads to finish... "); for (int i=0 ; iseqNr; int seqNrPub = seqNr + 1; int dsCount; int dsId; char *dsName; const char *dsArg = ""; char dsResult[DS_MESSAGE_BUF_SIZE]; int retVal; // Initialize thread pthread_mutex_lock(&threadCountMutex); threadCountCreated++; threadCountAliveNow++; if (threadCountAliveNow > threadCountAliveMax) { threadCountAliveMax = threadCountAliveNow; } pthread_mutex_unlock(&threadCountMutex); // Hello the user if (verbose) printf(" t%d %llu : Hello from thread #%d\n", seqNrPub, (unsigned long long)pthread_self(), seqNrPub); // Initialize Snoopy if (verbose) printf(" t%d %llu : Threads before snoopy_init(): %d\n", seqNrPub, (unsigned long long)pthread_self(), snoopy_tsrm_get_threadCount()); snoopy_entrypoint_test_cli_threads_init(); if (verbose) printf(" t%d %llu : Threads after snoopy_init(): %d\n", seqNrPub, (unsigned long long)pthread_self(), snoopy_tsrm_get_threadCount()); // Run a random snoopy datasource dsCount = snoopy_datasourceregistry_getCount(); dsId = snoopyTestCli_action_stress_threads_randomNumberInclusive(0, dsCount-1); dsName = snoopy_datasourceregistry_getName(dsId); retVal = snoopy_datasourceregistry_callById(dsId, dsResult, DS_MESSAGE_BUF_SIZE, dsArg); if (0 > retVal) { printf(" t%d %llu : Datasource %s returned negative result: %d\n", seqNrPub, (unsigned long long)pthread_self(), dsName, retVal); } else { printf(" t%d %llu : DS result: %30s = %s\n", seqNrPub, (unsigned long long)pthread_self(), dsName, dsResult); } // Retest at thread end if (verbose) printf(" t%d %llu : Threads before snoopy_cleanup(): %d\n", seqNrPub, (unsigned long long)pthread_self(), snoopy_tsrm_get_threadCount()); snoopy_entrypoint_test_cli_exit(); if (verbose) printf(" t%d %llu : Threads after snoopy_cleanup(): %d\n", seqNrPub, (unsigned long long)pthread_self(), snoopy_tsrm_get_threadCount()); // Goodbye to user if (verbose) printf(" t%d %llu : Thread exiting: #%d\n", seqNrPub, (unsigned long long)pthread_self(), seqNrPub); // Cleanup thread pthread_mutex_lock(&threadCountMutex); threadCountAliveNow--; pthread_mutex_unlock(&threadCountMutex); free (tArgs); return NULL; } /* * randomNumberInclusive() * * Description: * Return random number between idMin and idMax inclusive * * Params: * * Return: * int Random number */ int snoopyTestCli_action_stress_threads_randomNumberInclusive (int nMin, int nMax) { int randomNrRaw = 0; int randomNr; ssize_t bytesRead = 0; unsigned char buffer[sizeof(randomNrRaw)]; // Read the random content int fd = open("/dev/urandom", O_RDONLY); if (-1 == fd) { printf("ERROR: Unable to open /dev/urandom.\n"); return -1; // Yeah, not the best error handling } bytesRead = read(fd, buffer, sizeof(randomNrRaw)); close(fd); if (bytesRead != sizeof(randomNrRaw)) { // SonarCloud may complain about redundant casts here, but removing these // "redundant" casts causes builds to fail on non-64bit platforms. printf("ERROR: Unable to read %lu bytes from /dev/urandom, only got %li bytes.\n", (long unsigned) sizeof(randomNrRaw), (long int) bytesRead); return -1; } // Convert the read bytes to random positive number for (unsigned int i=0 ; i * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_stress_threads (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-stress-threadsexec.c000066400000000000000000000202461470651710700235610ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * File: snoopy-test-datasource.c * * Copyright (c) 2015 Bostjan Skufca * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-common.h" #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #define THREAD_COUNT_MAX 10000 /* * Thread data */ typedef struct { int seqNr; int verbose; int joined; } tData_t; /* * We do not use separate .h file here */ void * snoopyTestCli_action_stress_threadsexec_threadMain (const void *args); /* * Global variables */ char **snoopyTestCli_action_stress_threadsexec_runCmdAndArgv; pthread_t snoopyTestCli_action_stress_threadsexec_tRepo[THREAD_COUNT_MAX]; tData_t *tArgsRepo[THREAD_COUNT_MAX]; void snoopyTestCli_action_stress_threadsexec_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `stress` :: Subsystem `threadsexec`\n" "\n" "Usage:\n" " snoopy-test stress threadsexec [-v] THREAD_COUNT CMD [CMD_ARGS]\n" "\n" "Description:\n" " Stresses Snoopy's threading implementation by creating and destroying THREAD_COUNT\n" " threads as fast as possible and executing CMD from those threads.\n" "\n" "Arguments:\n" " -v Verbose mode (dangerous - using stdout while threading and forking can result in a deadlock)\n" " THREAD_COUNT Number of threads to create and destroy\n" " CMD External command to execute from each newly created thread\n" " [CMD_ARGS] Optional argument(s) for the external command\n" "\n" "Output:\n" " Various threading-related messages are shown, followed by a word \"SUCCESS!\".\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_stress_threadsexec (int argc, char ** argv) { int verbose = 0; int threadsToCreate; int retVal = 0; /* Check arguments and parse them */ if (argc < 1) { snoopyTestCli_action_stress_threadsexec_showHelp(); fatalError("Missing argument: number of threads to run"); } /* Check for the -v flag - this is a bad way to avoid using getopt() */ if (strcmp(argv[0], "-v") == 0) { verbose = 1; argc--; argv = &argv[1]; } threadsToCreate = atoi(argv[0]); if ((threadsToCreate < 1) || (threadsToCreate > THREAD_COUNT_MAX)) { snoopyTestCli_action_stress_threadsexec_showHelp(); fatalErrorValue("Invalid number of threads to create (min 1, max THREAD_COUNT_MAX)", argv[0]); } if (argc < 2) { snoopyTestCli_action_stress_threadsexec_showHelp(); fatalError("Missing argument: external command to run"); } snoopyTestCli_action_stress_threadsexec_runCmdAndArgv = &argv[1]; printf("M: Allocating memory for each thread's args:\n"); for (int i=0 ; iseqNr = i; tData->verbose = verbose; tData->joined = 0; tArgsRepo[i] = tData; } // Create threads and run the function in them printf("M: Starting threads:\n"); if (!verbose) { printf("M: From now on, the output supressed (use the dangerous -v flag to show it).\n"); } for (int i=0 ; ijoined == 1) { threadsJoined++; } else { int res; res = pthread_tryjoin_np(snoopyTestCli_action_stress_threadsexec_tRepo[i], NULL); if (res == EBUSY) { if (verbose) printf(" M: Thread #%d has not finished executing yet.\n", i+1); if (verbose) fflush(stdout); } else { if (verbose) printf(" M: Thread #%d joined.\n", i+1); if (verbose) fflush(stdout); tArgsRepo[i]->joined = 1; } } } if (verbose) printf(" M: Thread join loop pass #%d done.\n", p); if (threadsJoined == threadsToCreate) { if (verbose) printf("M: All threads have joined, exiting the wait loop.\n"); break; } // SonarCloud may complain about redundant casts here, but removing these // "redundant" casts causes builds to fail on non-64bit platforms. if (verbose) printf(" M: Not all threads have joined yet, sleeping for %lld ns now.\n", (long long int) sleepTime.tv_nsec); if (verbose) fflush(stdout); nanosleep(&sleepTime, NULL); } if (p >= pMax) { // SonarCloud may complain about redundant casts here, but removing these // "redundant" casts causes builds to fail on non-64bit platforms. printf("M: ERROR - Not all threads have joined (timeout after %d * %lld ns).\n", pMax, (long long int) sleepTime.tv_nsec); return 1; } printf("M: All threads have finished.\n"); /* Housekeeping and return */ printf("SUCCESS!\n"); return retVal; } /* * threadMain() * * Description: * Main thread routine * * Params: * errorMsg Error message to display to user * * Return: * int Exit status to return to calling process */ void* snoopyTestCli_action_stress_threadsexec_threadMain (const void *args) { const tData_t *tArgs = args; char *cmd; char **argv; if (tArgs->verbose) printf(" t%d : Hello from thread #%d.\n", tArgs->seqNr+1, tArgs->seqNr+1); // Fork pid_t pid = fork(); if (pid > 0) { // Parent if (tArgs->verbose) printf(" t%dp: Hello from parent proc\n", tArgs->seqNr+1); int * status = 0; waitpid(pid, status, 0); if (tArgs->verbose) printf(" t%dp: Child proc has finished\n", tArgs->seqNr+1); } else if (pid == 0) { // Child if (tArgs->verbose) printf(" t%dc: Hello from child proc\n", tArgs->seqNr+1); // Set variables cmd = snoopyTestCli_action_stress_threadsexec_runCmdAndArgv[0]; argv = &snoopyTestCli_action_stress_threadsexec_runCmdAndArgv[0]; if (tArgs->verbose) printf(" t%dc: running cmd %s %s\n", tArgs->seqNr+1, cmd, argv[0]); execv(cmd, argv); } else { // fork failed if (tArgs->verbose) printf(" t%d : Fork failed!\n", tArgs->seqNr+1); } return NULL; } snoopy-snoopy-2.5.2/tests/bin/action-stress-threadsexec.h000066400000000000000000000015451470651710700235670ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_stress_threadsexec (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-stress.c000066400000000000000000000051151470651710700212620ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED #include "action-stress-threads.h" #include "action-stress-threadsexec.h" #endif #include #include #include #include void snoopyTestCli_action_stress_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `stress`\n" "\n" "Usage:\n" " snoopy stress SUBSYSTEM [ARGS]\n" "\n" "Available subsystems:\n" #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED " threads,t Stress internal threading implementation\n" " threadsexec,te Stress threading implementation by including execution of an external command\n" #endif "\n" " help,h Show this help\n" " SUBSYSTEM help Show SUBSYSTEM's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_stress (int argc, char ** argv) { const char * subsystem; if (argc < 1) { snoopyTestCli_action_stress_showHelp(); fatalError("No subsystem specified."); } subsystem = argv[0]; if ((0 == strcmp(subsystem, "help")) || (0 == strcmp(subsystem, "h"))) { snoopyTestCli_action_stress_showHelp(); return 0; } #ifdef SNOOPY_CONF_THREAD_SAFETY_ENABLED if ((0 == strcmp(subsystem, "threads")) || (0 == strcmp(subsystem, "t"))) { return snoopyTestCli_action_stress_threads(argc-1, &argv[1]); } if ((0 == strcmp(subsystem, "threadsexec")) || (0 == strcmp(subsystem, "te"))) { return snoopyTestCli_action_stress_threadsexec(argc-1, &argv[1]); } #endif snoopyTestCli_action_stress_showHelp(); fatalErrorValue("Unknown subsystem", subsystem); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-stress.h000066400000000000000000000015311470651710700212650ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_stress (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-action-log-message-dispatch.c000066400000000000000000000047131470651710700261720ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-action-log-message-dispatch.h" #include "action-common.h" #include "snoopy.h" #include "action/log-message-dispatch.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include #include void snoopyTestCli_action_unit_action_log_message_dispatch_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `action` :: Subunit 'log-message-dispatch'\n" "\n" "Description:\n" " Mocks src/action/log-message-dispatch.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit action log-message-dispatch\n" " snoopy-test unit action log-message-dispatch --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_action_log_message_dispatch (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_action_log_message_dispatch_showHelp(); return 0; } /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); // Do the mocking snoopy_configuration_t * CFG; CFG = snoopy_configuration_get(); CFG->output = "stdout"; snoopy_action_log_message_dispatch("Test error message, sent out via stdout output."); /* Cleanup */ snoopy_entrypoint_test_cli_exit(); printSuccess("Mocking src/action/log-message-dispatch.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-action-log-message-dispatch.h000066400000000000000000000015631470651710700261770ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_action_log_message_dispatch (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-action-log-syscall-exec.c000066400000000000000000000047261470651710700253510ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-action-log-syscall-exec.h" #include "action-common.h" #include "snoopy.h" #include "action/log-syscall-exec.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include #include void snoopyTestCli_action_unit_action_log_syscall_exec_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `action` :: Subunit 'log-syscall-exec'\n" "\n" "Description:\n" " Mocks src/action/log-syscall-exec.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit action log-syscall-exec\n" " snoopy-test unit action log-syscall-exec --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_action_log_syscall_exec (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_action_log_syscall_exec_showHelp(); return 0; } /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); // Do the mocking snoopy_configuration_t * CFG; CFG = snoopy_configuration_get(); CFG->message_format = "Test error message, sent out via stdout output."; CFG->filter_chain = ""; CFG->output = "stdout"; snoopy_action_log_syscall_exec(); /* Cleanup */ snoopy_entrypoint_test_cli_exit(); printSuccess("Mocking src/action/log-syscall-exec.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-action-log-syscall-exec.h000066400000000000000000000015571470651710700253550ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_action_log_syscall_exec (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-action.c000066400000000000000000000047731470651710700222020ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #include "action-unit-action-log-message-dispatch.h" #include "action-unit-action-log-syscall-exec.h" #include #include void snoopyTestCli_action_unit_action_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `action`\n" "\n" "Usage:\n" " snoopy-test unit action SUBUNIT [ARGS]\n" "\n" "Available subunits:\n" " log-message-dispatch,lmd Run a unit test on src/action/log-message-dispatch.c\n" " log-syscall-exec,lse Run a unit test on src/action/log-syscall-exec.c\n" "\n" " --help,-h Show this help\n" " UNIT --help Show UNIT's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_action (int argc, char ** argv) { const char * subunit; if (argc < 1) { snoopyTestCli_action_unit_action_showHelp(); fatalError("No subunit specified."); } subunit = argv[0]; if ((0 == strcmp(subunit, "log-message-dispatch")) || (0 == strcmp(subunit, "lmd"))) { return snoopyTestCli_action_unit_action_log_message_dispatch(argc-1, &argv[1]); } if ((0 == strcmp(subunit, "log-syscall-exec")) || (0 == strcmp(subunit, "lse"))) { return snoopyTestCli_action_unit_action_log_syscall_exec(argc-1, &argv[1]); } if ((0 == strcmp(subunit, "--help")) || (0 == strcmp(subunit, "-h"))) { snoopyTestCli_action_unit_action_showHelp(); return 0; } snoopyTestCli_action_unit_action_showHelp(); fatalErrorValue("Unknown subunit", subunit); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-unit-action.h000066400000000000000000000015361470651710700222010ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_action (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-datasource-cmdline.c000066400000000000000000000313231470651710700244570ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-datasource-cmdline.h" #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "datasource/cmdline.h" #include #include #include #define RESULT_BUF_SIZE 2048 /* * Local helper functions */ static void mockDatasourceCmdline ( char const * const testId, char const * const filename, char * const argv[], char const * const expectedResult ); void snoopyTestCli_action_unit_datasource_cmdline_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `datasource` :: Subunit `cmdline`\n" "\n" "Description:\n" " Mocks src/datasource/cmdline.c" "\n" "Usage:\n" " snoopy-test unit datasource cmdline\n" " snoopy-test unit datasource cmdline --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_datasource_cmdline (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_datasource_cmdline_showHelp(); return 0; } // Mock the basics mockDatasourceCmdline("test01", "cmdInFn", (char *[]) {"cmdInArgv", NULL}, "cmdInArgv"); mockDatasourceCmdline("test02", "cmdInFn", (char *[]) {"cmdInArgv", "arg1", NULL}, "cmdInArgv arg1"); mockDatasourceCmdline("test03", "cmdInFn", (char *[]) {"cmdInArgv", "arg1", "arg2", NULL}, "cmdInArgv arg1 arg2"); // Edge cases #1 mockDatasourceCmdline("test11", "cmdInFn", (char *[]) {"cmdInArgv", "arg1", "", NULL}, "cmdInArgv arg1 "); mockDatasourceCmdline("test12", "cmdInFn", (char *[]) {"cmdInArgv", "", "", NULL}, "cmdInArgv "); mockDatasourceCmdline("test13", "cmdInFn", (char *[]) {"cmdInArgv", "", "arg2", NULL}, "cmdInArgv arg2"); mockDatasourceCmdline("test14", "cmdInFn", (char *[]) {"", "", "", NULL}, " "); // Edge cases #2 mockDatasourceCmdline("test21", "cmdInFn", NULL, "cmdInFn"); // DirectAdmin does this :/ mockDatasourceCmdline("test22", "cmdInFn", (char *[]) {NULL}, "cmdInFn"); mockDatasourceCmdline("test23", NULL, NULL, "(unknown)"); // Edge cases #3 char * str2045 = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"; char const * str2045exp = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345 1"; char * str2047 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"; char * str2048 = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"; mockDatasourceCmdline("test31", str2047, (char *[]) { NULL}, str2047); mockDatasourceCmdline("test32", str2048, (char *[]) { NULL}, str2047); mockDatasourceCmdline("test33", "cmdInFn", (char *[]) {str2047, NULL}, str2047); mockDatasourceCmdline("test34", "cmdInFn", (char *[]) {str2048, NULL}, str2047); mockDatasourceCmdline("test35", "cmdInFn", (char *[]) {str2045, "1", NULL}, str2045exp); printSuccess("Mocking src/datasource/cmdline.c complete (@datasource_message_max_length=2047)."); return 0; } static void mockDatasourceCmdline ( char const * const testId, char const * const filename, char * const argv[], char const * const expectedResult) { char resultBuf[RESULT_BUF_SIZE] = {'\0'}; char * result = resultBuf; int retVal; // Init snoopy_entrypoint_test_cli_init(filename, argv, NULL); // Run the datasource retVal = snoopy_datasource_cmdline(result, RESULT_BUF_SIZE, NULL); if (SNOOPY_DATASOURCE_FAILED(retVal)) { fatalErrorValue("Datasource failure", expectedResult); } // Deinit Snoopy snoopy_entrypoint_test_cli_exit(); // Evaluate the result if (0 != strcmp(result, expectedResult)) { printDiagValue("Expected result", expectedResult); printDiagValue("Actual result", result); fatalErrorValue("Datasource returned unexpected result, testId", testId); } return; } snoopy-snoopy-2.5.2/tests/bin/action-unit-datasource-cmdline.h000066400000000000000000000015521470651710700244650ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_datasource_cmdline (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-datasource.c000066400000000000000000000045201470651710700230450ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline #include "action-unit-datasource-cmdline.h" #endif #include #include void snoopyTestCli_action_unit_datasource_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `datasource`\n" "\n" "Usage:\n" " snoopy-test unit datasource SUBUNIT [ARGS]\n" "\n" "Available subunits:\n" #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline " cmdline Run a unit test on src/datasource/cmdline.c\n" #endif "\n" " --help,-h Show this help\n" " UNIT --help Show UNIT's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_datasource (int argc, char ** argv) { const char * subunit; if (argc < 1) { snoopyTestCli_action_unit_datasource_showHelp(); fatalError("No subunit specified. Use --help flag to list available subunits."); } subunit = argv[0]; #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_cmdline if (0 == strcmp(subunit, "cmdline")) { return snoopyTestCli_action_unit_datasource_cmdline(argc-1, &argv[1]); } #endif if ((0 == strcmp(subunit, "--help")) || (0 == strcmp(subunit, "-h"))) { snoopyTestCli_action_unit_datasource_showHelp(); return 0; } snoopyTestCli_action_unit_datasource_showHelp(); fatalErrorValue("Unknown subunit", subunit); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-unit-datasource.h000066400000000000000000000015421470651710700230530ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_datasource (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-error.c000066400000000000000000000043241470651710700220460ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-error.h" #include "action-common.h" #include "snoopy.h" #include "error.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include #include void snoopyTestCli_action_unit_error_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `error`\n" "\n" "Description:\n" " Mocks src/error.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit error\n" " snoopy-test unit error --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_error (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_error_showHelp(); return 0; } /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); // Do the mocking snoopy_configuration_t * CFG; CFG = snoopy_configuration_get(); CFG->output = "stderr"; snoopy_error_handler("Test error message, sent out via stderr output."); /* Cleanup */ snoopy_entrypoint_test_cli_exit(); printSuccess("Mocking src/error.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-error.h000066400000000000000000000015351470651710700220540ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_error (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-ext-ini.c000066400000000000000000000062161470651710700222740ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-ext-ini.h" #include "action-common.h" #include "snoopy.h" #include "entrypoint/test-cli.h" #include "lib/inih/src/ini.h" #include #include #include void snoopyTestCli_action_unit_ext_ini_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `ext-ini`\n" "\n" "Description:\n" " Mocks external ini implementation code paths (mainly for the code coverage of parts not used by Snoopy).\n" "\n" "Usage:\n" " snoopy-test unit ext-ini\n" " snoopy-test unit ext-ini --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_ext_ini_parserCallback ( void * userPtr, const char* section, const char* name, const char* value ) { const char ** errorMessage = (const char **) userPtr; // Check if we're already in an error state if (*errorMessage != NULL) { return 1; } if (0 != strcmp(section, "sectionName")) { *errorMessage = "Unexpected section"; return 1; } if (0 != strcmp(name, "testKey")) { *errorMessage = "Unexpected key"; return 1; } if (0 != strcmp(value, "testVal")) { *errorMessage = "Unexpected value"; return 1; } return 1; } int snoopyTestCli_action_unit_ext_ini (int argc, char ** argv) { const char *arg1; /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_ext_ini_showHelp(); return 0; } // Do the mocking const char * iniContent = "[sectionName]\n" "testKey=testVal\n"; const char * errorMessage = NULL; int parserStatus = 0; parserStatus = ini_parse_string(iniContent, snoopyTestCli_action_unit_ext_ini_parserCallback, (void *)&errorMessage); if (parserStatus < 0) { fatalError("INI parsing failed"); } if (errorMessage != NULL) { fatalErrorValue("INI parsing failure", errorMessage); } printSuccess("Mocking lib/inih/src/ini.c complete."); /* Housekeeping and return */ snoopy_entrypoint_test_cli_exit(); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-ext-ini.h000066400000000000000000000015371470651710700223020ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_ext_ini (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-filterregistry.c000066400000000000000000000061621470651710700237750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-filterregistry.h" #include "action-common.h" #include "snoopy.h" #include "filterregistry.h" #include #include void snoopyTestCli_action_unit_filterregistry_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `filterregistry`\n" "\n" "Description:\n" " Mocks filterregistry implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit filterregistry\n" " snoopy-test unit filterregistry --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_filterregistry (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_filterregistry_showHelp(); return 0; } // Do the mocking const char * filterName = NULL; int filterCount = 0; int filterIdPreset = 0; int filterIdReceived = 0; filterCount = snoopy_filterregistry_getCount(); if (filterCount < 1) { fatalError("No filters available, filter count is 0"); } printf("[DEBUG] Number of filters available: %d\n", filterCount); if (snoopy_filterregistry_doesIdExist(filterIdPreset) != SNOOPY_TRUE) { fatalError("Filter with a preset ID (0) does not exist"); } filterName = snoopy_filterregistry_getName(filterIdPreset); filterIdReceived = snoopy_filterregistry_getIdFromName(filterName); if (filterIdPreset != filterIdReceived) { fatalError("Filter ID returned when searching by name differs from the initially used ID to find that same filter"); } filterName = "noop"; filterIdReceived = snoopy_filterregistry_getIdFromName(filterName); snoopy_filterregistry_callById(filterIdReceived, ""); if (-1 != snoopy_filterregistry_callById(-1, "")) { fatalError("Filter ID -1 unexpectedly exists"); } if (-1 != snoopy_filterregistry_callByName("fakeFilterNameThatShouldNeverExist", "")) { fatalError("Filter with an unexpected name actually exists"); } printSuccess("Mocking src/filterregistry.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-filterregistry.h000066400000000000000000000015461470651710700240030ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_filterregistry (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-outputregistry.c000066400000000000000000000067631470651710700240570ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-outputregistry.h" #include "action-common.h" #include "snoopy.h" #include "outputregistry.h" #include "entrypoint/test-cli.h" #include "configuration.h" #include #include void snoopyTestCli_action_unit_outputregistry_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `outputregistry`\n" "\n" "Description:\n" " Mocks outputregistry implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit outputregistry\n" " snoopy-test unit outputregistry --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_outputregistry (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_outputregistry_showHelp(); return 0; } // Do the mocking const char * outputName = NULL; int outputCount = 0; int outputIdPreset = 0; int outputIdReceived = 0; outputCount = snoopy_outputregistry_getCount(); if (outputCount < 1) { fatalError("No outputs available, output count is 0"); } printf("[DEBUG] Number of outputs available: %d\n", outputCount); if (snoopy_outputregistry_doesIdExist(outputIdPreset) != SNOOPY_TRUE) { fatalError("Output with a preset ID (0) does not exist"); } outputName = snoopy_outputregistry_getName(outputIdPreset); outputIdReceived = snoopy_outputregistry_getIdFromName(outputName); if (outputIdPreset != outputIdReceived) { fatalError("Output ID returned when searching by name differs from the initially used ID to find that same output"); } outputName = "noop"; outputIdReceived = snoopy_outputregistry_getIdFromName(outputName); snoopy_outputregistry_callById(outputIdReceived, NULL, ""); if (-1 != snoopy_outputregistry_callById(-1, NULL, "")) { fatalError("Output ID -1 unexpectedly exists"); } if (-1 != snoopy_outputregistry_callByName("fakeOutputNameThatShouldNeverExist", NULL, "")) { fatalError("Output with an unexpected name actually exists"); } /* Initialize Snoopy */ snoopy_entrypoint_test_cli_init((char const *)g_argv[0], g_argv, NULL); snoopy_configuration_t * CFG; CFG = snoopy_configuration_get(); CFG->output = "noop"; snoopy_outputregistry_dispatch(NULL); /* Cleanup */ snoopy_entrypoint_test_cli_exit(); printSuccess("Mocking src/outputregistry.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-outputregistry.h000066400000000000000000000015461470651710700240560ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_outputregistry (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-util-parser.c000066400000000000000000000101471470651710700231640ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-util-parser.h" #include "action-common.h" #include "snoopy.h" #include "util/parser-snoopy.h" #include #include #include void snoopyTestCli_action_unit_util_parser_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `misc` :: Subunit `parser`\n" "\n" "Description:\n" " Mocks src/unit/parser.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit util parser\n" " snoopy-test unit util parser --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_util_parser (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_util_parser_showHelp(); return 0; } // Do the mocking if (snoopy_util_parser_strByteLength( "1", 100, 30000, 2000) != 100) fatalErrorValue("Error parsing byte length string", "1"); if (snoopy_util_parser_strByteLength( "100", 100, 30000, 2000) != 100) fatalErrorValue("Error parsing byte length string", "100"); if (snoopy_util_parser_strByteLength( "101", 100, 30000, 2000) != 101) fatalErrorValue("Error parsing byte length string", "101"); if (snoopy_util_parser_strByteLength( "1000", 100, 30000, 2000) != 1000) fatalErrorValue("Error parsing byte length string", "1000"); if (snoopy_util_parser_strByteLength( "2000", 100, 30000, 2000) != 2000) fatalErrorValue("Error parsing byte length string", "2000"); if (snoopy_util_parser_strByteLength("29999", 100, 30000, 2000) != 29999) fatalErrorValue("Error parsing byte length string", "29999"); if (snoopy_util_parser_strByteLength("30000", 100, 30000, 2000) != 30000) fatalErrorValue("Error parsing byte length string", "30000"); if (snoopy_util_parser_strByteLength("30001", 100, 30000, 2000) != 30000) fatalErrorValue("Error parsing byte length string", "30001"); if (snoopy_util_parser_strByteLength( "1k", 100, 3000000, 2000) != 1024) fatalErrorValue("Error parsing byte length string", "1k"); if (snoopy_util_parser_strByteLength( "3k", 100, 3000000, 2000) != 3072) fatalErrorValue("Error parsing byte length string", "3k"); if (snoopy_util_parser_strByteLength( "32k", 100, 3000000, 2000) != 32768) fatalErrorValue("Error parsing byte length string", "32k"); if (snoopy_util_parser_strByteLength( "1m", 100, 3000000, 2000) != 1048576) fatalErrorValue("Error parsing byte length string", "1m"); if (snoopy_util_parser_strByteLength("" , 100, 30000, 2000) != 2000) fatalErrorValue("Error parsing byte length string", "(nul)"); if (snoopy_util_parser_strByteLength("0", 100, 30000, 2000) != 2000) fatalErrorValue("Error parsing byte length string", "0"); if (snoopy_util_parser_strByteLength("asdf", 100, 30000, 2000) != 2000) fatalErrorValue("Error parsing byte length string", "asdf"); printSuccess("Mocking src/util/parser.c (strByteLength-only) complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-util-parser.h000066400000000000000000000015431470651710700231710ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_util_parser (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-util-syslog.c000066400000000000000000000350231470651710700232100ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-util-syslog.h" #include "action-common.h" #include "snoopy.h" #include "util/syslog-snoopy.h" #include #include #include void snoopyTestCli_action_unit_util_syslog_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `misc` :: Subunit `syslog`\n" "\n" "Description:\n" " Mocks src/unit/syslog.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit util syslog\n" " snoopy-test unit util syslog --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_util_syslog (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_util_syslog_showHelp(); return 0; } // Do the mocking if (snoopy_util_syslog_convertFacilityToInt("AUTH") != LOG_AUTH) fatalErrorValue("Error converting syslog facility str to int", "AUTH"); if (snoopy_util_syslog_convertFacilityToInt("AUTHPRIV") != LOG_AUTHPRIV) fatalErrorValue("Error converting syslog facility str to int", "AUTHPRIV"); if (snoopy_util_syslog_convertFacilityToInt("CRON") != LOG_CRON) fatalErrorValue("Error converting syslog facility str to int", "CRON"); if (snoopy_util_syslog_convertFacilityToInt("DAEMON") != LOG_DAEMON) fatalErrorValue("Error converting syslog facility str to int", "DAEMON"); if (snoopy_util_syslog_convertFacilityToInt("FTP") != LOG_FTP) fatalErrorValue("Error converting syslog facility str to int", "FTP"); if (snoopy_util_syslog_convertFacilityToInt("KERN") != LOG_KERN) fatalErrorValue("Error converting syslog facility str to int", "KERN"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL0") != LOG_LOCAL0) fatalErrorValue("Error converting syslog facility str to int", "LOCAL0"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL1") != LOG_LOCAL1) fatalErrorValue("Error converting syslog facility str to int", "LOCAL1"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL2") != LOG_LOCAL2) fatalErrorValue("Error converting syslog facility str to int", "LOCAL2"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL3") != LOG_LOCAL3) fatalErrorValue("Error converting syslog facility str to int", "LOCAL3"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL4") != LOG_LOCAL4) fatalErrorValue("Error converting syslog facility str to int", "LOCAL4"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL5") != LOG_LOCAL5) fatalErrorValue("Error converting syslog facility str to int", "LOCAL5"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL6") != LOG_LOCAL6) fatalErrorValue("Error converting syslog facility str to int", "LOCAL6"); if (snoopy_util_syslog_convertFacilityToInt("LOCAL7") != LOG_LOCAL7) fatalErrorValue("Error converting syslog facility str to int", "LOCAL7"); if (snoopy_util_syslog_convertFacilityToInt("LPR") != LOG_LPR) fatalErrorValue("Error converting syslog facility str to int", "LPR"); if (snoopy_util_syslog_convertFacilityToInt("MAIL") != LOG_MAIL) fatalErrorValue("Error converting syslog facility str to int", "MAIL"); if (snoopy_util_syslog_convertFacilityToInt("NEWS") != LOG_NEWS) fatalErrorValue("Error converting syslog facility str to int", "NEWS"); if (snoopy_util_syslog_convertFacilityToInt("SYSLOG") != LOG_SYSLOG) fatalErrorValue("Error converting syslog facility str to int", "SYSLOG"); if (snoopy_util_syslog_convertFacilityToInt("USER") != LOG_USER) fatalErrorValue("Error converting syslog facility str to int", "USER"); if (snoopy_util_syslog_convertFacilityToInt("UUCP") != LOG_UUCP) fatalErrorValue("Error converting syslog facility str to int", "UUCP"); if (snoopy_util_syslog_convertFacilityToInt("LOG_AUTH") != LOG_AUTH) fatalErrorValue("Error converting syslog facility str to int", "LOG_AUTH"); if (snoopy_util_syslog_convertFacilityToInt("LOG_AUTHPRIV") != LOG_AUTHPRIV) fatalErrorValue("Error converting syslog facility str to int", "LOG_AUTHPRIV"); if (snoopy_util_syslog_convertFacilityToInt("LOG_CRON") != LOG_CRON) fatalErrorValue("Error converting syslog facility str to int", "LOG_CRON"); if (snoopy_util_syslog_convertFacilityToInt("LOG_DAEMON") != LOG_DAEMON) fatalErrorValue("Error converting syslog facility str to int", "LOG_DAEMON"); if (snoopy_util_syslog_convertFacilityToInt("LOG_FTP") != LOG_FTP) fatalErrorValue("Error converting syslog facility str to int", "LOG_FTP"); if (snoopy_util_syslog_convertFacilityToInt("LOG_KERN") != LOG_KERN) fatalErrorValue("Error converting syslog facility str to int", "LOG_KERN"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL0") != LOG_LOCAL0) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL0"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL1") != LOG_LOCAL1) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL1"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL2") != LOG_LOCAL2) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL2"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL3") != LOG_LOCAL3) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL3"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL4") != LOG_LOCAL4) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL4"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL5") != LOG_LOCAL5) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL5"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL6") != LOG_LOCAL6) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL6"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LOCAL7") != LOG_LOCAL7) fatalErrorValue("Error converting syslog facility str to int", "LOG_LOCAL7"); if (snoopy_util_syslog_convertFacilityToInt("LOG_LPR") != LOG_LPR) fatalErrorValue("Error converting syslog facility str to int", "LOG_LPR"); if (snoopy_util_syslog_convertFacilityToInt("LOG_MAIL") != LOG_MAIL) fatalErrorValue("Error converting syslog facility str to int", "LOG_MAIL"); if (snoopy_util_syslog_convertFacilityToInt("LOG_NEWS") != LOG_NEWS) fatalErrorValue("Error converting syslog facility str to int", "LOG_NEWS"); if (snoopy_util_syslog_convertFacilityToInt("LOG_SYSLOG") != LOG_SYSLOG) fatalErrorValue("Error converting syslog facility str to int", "LOG_SYSLOG"); if (snoopy_util_syslog_convertFacilityToInt("LOG_USER") != LOG_USER) fatalErrorValue("Error converting syslog facility str to int", "LOG_USER"); if (snoopy_util_syslog_convertFacilityToInt("LOG_UUCP") != LOG_UUCP) fatalErrorValue("Error converting syslog facility str to int", "LOG_UUCP"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_AUTH) , "AUTH") ) fatalErrorValue("Error converting syslog facility int to str", "AUTH"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_AUTHPRIV), "AUTHPRIV")) fatalErrorValue("Error converting syslog facility int to str", "AUTHPRIV"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_CRON) , "CRON") ) fatalErrorValue("Error converting syslog facility int to str", "CRON"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_DAEMON) , "DAEMON") ) fatalErrorValue("Error converting syslog facility int to str", "DAEMON"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_FTP) , "FTP") ) fatalErrorValue("Error converting syslog facility int to str", "FTP"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_KERN) , "KERN") ) fatalErrorValue("Error converting syslog facility int to str", "KERN"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL0) , "LOCAL0") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL0"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL1) , "LOCAL1") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL1"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL2) , "LOCAL2") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL2"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL3) , "LOCAL3") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL3"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL4) , "LOCAL4") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL4"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL5) , "LOCAL5") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL5"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL6) , "LOCAL6") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL6"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LOCAL7) , "LOCAL7") ) fatalErrorValue("Error converting syslog facility int to str", "LOCAL7"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_LPR) , "LPR") ) fatalErrorValue("Error converting syslog facility int to str", "LPR"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_MAIL) , "MAIL") ) fatalErrorValue("Error converting syslog facility int to str", "MAIL"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_NEWS) , "NEWS") ) fatalErrorValue("Error converting syslog facility int to str", "NEWS"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_SYSLOG) , "SYSLOG") ) fatalErrorValue("Error converting syslog facility int to str", "SYSLOG"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_USER) , "USER") ) fatalErrorValue("Error converting syslog facility int to str", "USER"); if (0 != strcmp(snoopy_util_syslog_convertFacilityToStr(LOG_UUCP) , "UUCP") ) fatalErrorValue("Error converting syslog facility int to str", "UUCP"); if (snoopy_util_syslog_convertLevelToInt("EMERG") != LOG_EMERG) fatalErrorValue("Error converting syslog level str to int", "EMERG"); if (snoopy_util_syslog_convertLevelToInt("ALERT") != LOG_ALERT) fatalErrorValue("Error converting syslog level str to int", "ALERT"); if (snoopy_util_syslog_convertLevelToInt("CRIT") != LOG_CRIT) fatalErrorValue("Error converting syslog level str to int", "CRIT"); if (snoopy_util_syslog_convertLevelToInt("ERR") != LOG_ERR) fatalErrorValue("Error converting syslog level str to int", "ERR"); if (snoopy_util_syslog_convertLevelToInt("WARNING") != LOG_WARNING) fatalErrorValue("Error converting syslog level str to int", "WARNING"); if (snoopy_util_syslog_convertLevelToInt("NOTICE") != LOG_NOTICE) fatalErrorValue("Error converting syslog level str to int", "NOTICE"); if (snoopy_util_syslog_convertLevelToInt("INFO") != LOG_INFO) fatalErrorValue("Error converting syslog level str to int", "INFO"); if (snoopy_util_syslog_convertLevelToInt("DEBUG") != LOG_DEBUG) fatalErrorValue("Error converting syslog level str to int", "DEBUG"); if (snoopy_util_syslog_convertLevelToInt("LOG_EMERG") != LOG_EMERG) fatalErrorValue("Error converting syslog level str to int", "EMERG"); if (snoopy_util_syslog_convertLevelToInt("LOG_ALERT") != LOG_ALERT) fatalErrorValue("Error converting syslog level str to int", "ALERT"); if (snoopy_util_syslog_convertLevelToInt("LOG_CRIT") != LOG_CRIT) fatalErrorValue("Error converting syslog level str to int", "CRIT"); if (snoopy_util_syslog_convertLevelToInt("LOG_ERR") != LOG_ERR) fatalErrorValue("Error converting syslog level str to int", "ERR"); if (snoopy_util_syslog_convertLevelToInt("LOG_WARNING") != LOG_WARNING) fatalErrorValue("Error converting syslog level str to int", "WARNING"); if (snoopy_util_syslog_convertLevelToInt("LOG_NOTICE") != LOG_NOTICE) fatalErrorValue("Error converting syslog level str to int", "NOTICE"); if (snoopy_util_syslog_convertLevelToInt("LOG_INFO") != LOG_INFO) fatalErrorValue("Error converting syslog level str to int", "INFO"); if (snoopy_util_syslog_convertLevelToInt("LOG_DEBUG") != LOG_DEBUG) fatalErrorValue("Error converting syslog level str to int", "DEBUG"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_EMERG) , "EMERG") ) fatalErrorValue("Error converting syslog level int to str", "EMERG"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_ALERT) , "ALERT") ) fatalErrorValue("Error converting syslog level int to str", "ALERT"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_CRIT) , "CRIT") ) fatalErrorValue("Error converting syslog level int to str", "CRIT"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_ERR) , "ERR") ) fatalErrorValue("Error converting syslog level int to str", "ERR"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_WARNING), "WARNING")) fatalErrorValue("Error converting syslog level int to str", "WARNING"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_NOTICE) , "NOTICE") ) fatalErrorValue("Error converting syslog level int to str", "NOTICE"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_INFO) , "INFO") ) fatalErrorValue("Error converting syslog level int to str", "INFO"); if (0 != strcmp(snoopy_util_syslog_convertLevelToStr(LOG_DEBUG) , "DEBUG") ) fatalErrorValue("Error converting syslog level int to str", "DEBUG"); printSuccess("Mocking src/misc.c complete."); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-util-syslog.h000066400000000000000000000015431470651710700232150ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_util_syslog (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-util-systemd.c000066400000000000000000000112011470651710700233500ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-util-systemd.h" #include "action-common.h" #include "util/systemd-snoopy.h" #include #include #include /* * Local helper functions */ static void mockCgroupEntryConversion(char const * const cgroupEntry, char const * const expectedUnitName); void snoopyTestCli_action_unit_util_systemd_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `util` :: Subunit 'systemd'\n" "\n" "Description:\n" " Mocks src/action/systemd.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit util systemd\n" " snoopy-test unit util systemd --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_util_systemd (int argc, char ** argv) { const char *arg1; if (argc > 0) { arg1 = argv[0]; } else { arg1 = ""; } if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_util_systemd_showHelp(); return 0; } char cgroupEntry1[] = "1:name=systemd:/init.scope"; const char * expectedUnitName1 = "init"; mockCgroupEntryConversion(cgroupEntry1, expectedUnitName1); char cgroupEntry2[] = "1:name=systemd:/system.slice/dbus.service"; const char * expectedUnitName2 = "dbus"; mockCgroupEntryConversion(cgroupEntry2, expectedUnitName2); char cgroupEntry3[] = "1:name=systemd:/user.slice/user-0.slice/session-3177.scope"; const char * expectedUnitName3 = "root"; // Expected to exist mockCgroupEntryConversion(cgroupEntry3, expectedUnitName3); char cgroupEntry4[] = "1:name=systemd:/user.slice/user-57123.slice/session-3177.scope"; const char * expectedUnitName4 = "user-57123"; // Expected to not exist on the system mockCgroupEntryConversion(cgroupEntry4, expectedUnitName4); char cgroupEntry5[] = "1:name=systemd:/"; const char * expectedUnitName5 = "-"; mockCgroupEntryConversion(cgroupEntry5, expectedUnitName5); char cgroupEntry6[] = "0::/whatever"; const char * expectedUnitName6 = NULL; mockCgroupEntryConversion(cgroupEntry6, expectedUnitName6); char cgroupEntry7[] = "1:name=systemd:/actions_job/44e2bfe9d6f3ece192a9f762d91c9514131b8cfbbd0469b1722fd8637ef6feac"; const char * expectedUnitName7 = NULL; mockCgroupEntryConversion(cgroupEntry7, expectedUnitName7); printSuccess("Mocking src/unit/systemd.c complete."); return 0; } static void mockCgroupEntryConversion(char const * const cgroupEntry, char const * const expectedUnitName) { char * unitName = snoopy_util_systemd_convertCgroupEntryToUnitName(cgroupEntry); if (!unitName && !expectedUnitName) { return; // Both are NULL, so it's expected } if (!unitName && expectedUnitName) { printDiagValue("cgroupEntry", cgroupEntry); printDiagValue("Expected unit name", expectedUnitName); fatalError("Unable to convert cgroup entry to Systemd unit name"); return; // Fake for Sonar CI, fatalError() exits } if (unitName && !expectedUnitName) { printDiagValue("cgroupEntry", cgroupEntry); printDiagValue("Converted unit name", unitName); fatalError("Cgroup entry not converted to NULL"); return; // Fake for Sonar CI, fatalError() exits } if (0 != strcmp(expectedUnitName, unitName)) { printDiagValue("cgroupEntry", cgroupEntry); printDiagValue("Expected unit name", expectedUnitName); printDiagValue("Converted unit name", unitName); fatalError("Unexpected unit name conversion"); return; // Fake for Sonar CI, fatalError() exits } free(unitName); return; } snoopy-snoopy-2.5.2/tests/bin/action-unit-util-systemd.h000066400000000000000000000015441470651710700233660ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_util_systemd (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-util-utmp.c000066400000000000000000000055511470651710700226600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2015 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-unit-util-utmp.h" #include "action-common.h" #include "snoopy.h" #include "util/utmp-snoopy.h" #include #include #include void snoopyTestCli_action_unit_util_utmp_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `util` :: Subunit 'utmp'\n" "\n" "Description:\n" " Helps with mocking src/unit/utmp.c implementation code paths (mainly for the coverage of code parts/paths not covered by the test suite).\n" "\n" "Usage:\n" " snoopy-test unit util utmp TTY_PATH [UTMP_FILE_PATH]\n" " snoopy-test unit util utmp --help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_util_utmp (int argc, char ** argv) { const char * arg1 = NULL; const char * ttyPath = NULL; const char * utmpPath = NULL; struct utmp utmpEntryBuf; struct utmp * utmpEntry = &utmpEntryBuf; // Parse arg #1 if (argc == 0) { fatalError("First argument is required (a TTY_PATH, or --help)"); } arg1 = argv[0]; if (0 == strcmp(arg1, "--help")) { snoopyTestCli_action_unit_util_utmp_showHelp(); return 0; } ttyPath = arg1; // Parse arg #2 if (argc >= 2) { utmpPath = argv[1]; snoopy_util_utmp_test_setAlternateUtmpFilePath(utmpPath); printWarningValue("Using alternative utmp file path", utmpPath); } // Find the entry if (SNOOPY_TRUE != snoopy_util_utmp_findUtmpEntryByPath(ttyPath, utmpEntry)) { printf("(Entry not found.)\n"); return 0; } // Check if it contains an IP address if (SNOOPY_TRUE != snoopy_util_utmp_doesEntryContainIpAddr(utmpEntry)) { printf("-\n"); return 0; } // Convert IP address to string char ipAddrStrBuf[256] = {'\0'}; char * ipAddrStr = ipAddrStrBuf; snoopy_util_utmp_getUtmpIpAddrAsString(utmpEntry, ipAddrStr, 256); // Print it printf("%s\n", ipAddrStr); return 0; } snoopy-snoopy-2.5.2/tests/bin/action-unit-util-utmp.h000066400000000000000000000015411470651710700226600ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_util_utmp (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit-util.c000066400000000000000000000061131470651710700216700ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #include "action-unit-util-parser.h" #include "action-unit-util-syslog.h" #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name #include "action-unit-util-systemd.h" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr #include "action-unit-util-utmp.h" #endif #include #include void snoopyTestCli_action_unit_util_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit` :: Unit `util`\n" "\n" "Usage:\n" " snoopy-test unit util SUBUNIT [ARGS]\n" "\n" "Available subunits:\n" " parser Run a unit test on src/util/parser.c\n" " syslog Run a unit test on src/util/syslog.c\n" #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name " systemd Run a unit test on src/util/systemd.c\n" #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr " utmp Unit test helper for src/util/utmp.c\n" #endif "\n" " --help,-h Show this help\n" " UNIT --help Show UNIT's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit_util (int argc, char ** argv) { const char * subunit; if (argc < 1) { snoopyTestCli_action_unit_util_showHelp(); fatalError("No subunit specified."); } subunit = argv[0]; if (0 == strcmp(subunit, "parser")) { return snoopyTestCli_action_unit_util_parser(argc-1, &argv[1]); } if (0 == strcmp(subunit, "syslog")) { return snoopyTestCli_action_unit_util_syslog(argc-1, &argv[1]); } #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_systemd_unit_name if (0 == strcmp(subunit, "systemd")) { return snoopyTestCli_action_unit_util_systemd(argc-1, &argv[1]); } #endif #ifdef SNOOPY_CONF_DATASOURCE_ENABLED_ipaddr if (0 == strcmp(subunit, "utmp")) { return snoopyTestCli_action_unit_util_utmp(argc-1, &argv[1]); } #endif if ((0 == strcmp(subunit, "--help")) || (0 == strcmp(subunit, "-h"))) { snoopyTestCli_action_unit_util_showHelp(); return 0; } snoopyTestCli_action_unit_util_showHelp(); fatalErrorValue("Unknown subunit", subunit); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-unit-util.h000066400000000000000000000015341470651710700216770ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit_util (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/action-unit.c000066400000000000000000000073611470651710700207230ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "snoopy.h" #include "action-common.h" #include "action-unit-action.h" #include "action-unit-datasource.h" #include "action-unit-error.h" #ifdef SNOOPY_CONFIGFILE_ENABLED #include "action-unit-ext-ini.h" #endif #ifdef SNOOPY_FILTERING_ENABLED #include "action-unit-filterregistry.h" #endif #include "action-unit-outputregistry.h" #include "action-unit-util.h" #include #include void snoopyTestCli_action_unit_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility :: Action `unit`\n" "\n" "Usage:\n" " snoopy-test unit UNIT [ARGS]\n" "\n" "Available units:\n" " action,a Run a unit test on action/*.c\n" " datasource,ds Run a unit test on datasource/*.c\n" " error,e Run a unit test on src/error.c\n" #ifdef SNOOPY_CONFIGFILE_ENABLED " ext-ini,ei Run a unit test on lib/inih/src/ini.c\n" #endif #ifdef SNOOPY_FILTERING_ENABLED " filterregistry,fr Run a unit test on src/filterregistry.c\n" #endif " outputregistry,or Run a unit test on src/outputregistry.c\n" " util,u Run a unit test on src/util/*.c\n" "\n" " --help,-h Show this help\n" " UNIT --help Show UNIT's help\n" "\n"; printf("%s", helpContent); } int snoopyTestCli_action_unit (int argc, char ** argv) { const char * unit; if (argc < 1) { snoopyTestCli_action_unit_showHelp(); fatalError("No unit specified."); } unit = argv[0]; if ((0 == strcmp(unit, "action")) || (0 == strcmp(unit, "a"))) { return snoopyTestCli_action_unit_action(argc-1, &argv[1]); } if ((0 == strcmp(unit, "datasource")) || (0 == strcmp(unit, "ds"))) { return snoopyTestCli_action_unit_datasource(argc-1, &argv[1]); } if ((0 == strcmp(unit, "error")) || (0 == strcmp(unit, "e"))) { return snoopyTestCli_action_unit_error(argc-1, &argv[1]); } #ifdef SNOOPY_CONFIGFILE_ENABLED if ((0 == strcmp(unit, "ext-ini")) || (0 == strcmp(unit, "ei"))) { return snoopyTestCli_action_unit_ext_ini(argc-1, &argv[1]); } #endif #ifdef SNOOPY_FILTERING_ENABLED if ((0 == strcmp(unit, "filterregistry")) || (0 == strcmp(unit, "fr"))) { return snoopyTestCli_action_unit_filterregistry(argc-1, &argv[1]); } #endif if ((0 == strcmp(unit, "outputregistry")) || (0 == strcmp(unit, "or"))) { return snoopyTestCli_action_unit_outputregistry(argc-1, &argv[1]); } if ((0 == strcmp(unit, "util")) || (0 == strcmp(unit, "u"))) { return snoopyTestCli_action_unit_util(argc-1, &argv[1]); } if ((0 == strcmp(unit, "--help")) || (0 == strcmp(unit, "-h"))) { snoopyTestCli_action_unit_showHelp(); return 0; } snoopyTestCli_action_unit_showHelp(); fatalErrorValue("Unknown unit", unit); return 127; } snoopy-snoopy-2.5.2/tests/bin/action-unit.h000066400000000000000000000015271470651710700207260ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ int snoopyTestCli_action_unit (int argc, char ** argv); snoopy-snoopy-2.5.2/tests/bin/snoopy-test.c000066400000000000000000000045441470651710700207750ustar00rootroot00000000000000/* * SNOOPY COMMAND LOGGER * * Copyright (c) 2022 Bostjan Skufca Jese * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Includes order: from local to global */ #include "action-run.h" #include "action-stress.h" #include "action-unit.h" #include "cli/cli-subroutines.h" #include #include #include /* * Store original argc & argv in global space */ int g_argc; char ** g_argv; void snoopyTestCli_showHelp () { char * helpContent = "Snoopy TEST SUITE CLI utility\n" "\n" "Usage:\n" " snoopy ACTION [SUBACTION] [ARGS]\n" "\n" "Available actions:\n" " run Run Snoopy's subsystem\n" " stress Run stress tests\n" " unit Run unit tests\n" "\n" " --help,-h Show this help\n" " ACTION --help Show ACTION's help\n" "\n"; printf("%s", helpContent); } int main (int argc, char ** argv) { const char * action; g_argc = argc; g_argv = argv; if (argc < 2) { snoopyTestCli_showHelp(); fatalError("No action specified."); } action = argv[1]; if ((0 == strcmp(action, "--help")) || (0 == strcmp(action, "-h"))) { snoopyTestCli_showHelp(); return 0; } if (0 == strcmp(action, "run")) { return snoopyTestCli_action_run(argc-2, &argv[2]); } if (0 == strcmp(action, "stress")) { return snoopyTestCli_action_stress(argc-2, &argv[2]); } if (0 == strcmp(action, "unit")) { return snoopyTestCli_action_unit(argc-2, &argv[2]); } snoopyTestCli_showHelp(); fatalErrorValue("Unknown action", action); } snoopy-snoopy-2.5.2/tests/bin/spaceparent.c000066400000000000000000000016771470651710700210020ustar00rootroot00000000000000#include #include #include #include /* for fork */ #include /* for pid_t */ #include /* for wait */ int main (int argc, char **argv) { if (argc < 2) { printf("Pass command to run as an argument: \"./space parent\" /cmd/to/run [args]\n"); exit(1); } /* Spawn a child to run the program. */ pid_t pid = fork(); if (pid == -1) { /* fork failed */ printf("fork() failed\n"); exit(2); } if (pid == 0) { /* child process */ execv(argv[1], &argv[1]); /* This only gets executed if execv fails */ printf("execv() failed\n"); exit(3); } else { /* pid!=0; parent process */ int status; waitpid(pid, &status, 0); /* wait for child to exit */ if (status != 0) { printf("Child regurned with a non-zero status: %d\n", status); exit(4); } } } snoopy-snoopy-2.5.2/tests/cli/000077500000000000000000000000001470651710700163155ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/cli/Makefile.am000066400000000000000000000040731470651710700203550ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = TESTS += cli-action-about.sh if CONFIGFILE_ENABLED TESTS += cli-action-conf.sh endif TESTS += cli-action-disable-1-nofile.sh TESTS += cli-action-disable-2-emptyfile.sh TESTS += cli-action-disable-31-only-entry.sh TESTS += cli-action-disable-32-only-entry-no-newline.sh TESTS += cli-action-disable-33-only-entry-and-space.sh TESTS += cli-action-disable-34-only-entry-and-tab.sh TESTS += cli-action-disable-35-only-entry-and-comment.sh TESTS += cli-action-disable-41-first.sh TESTS += cli-action-disable-42-middle.sh TESTS += cli-action-disable-43-last.sh TESTS += cli-action-disable-44-last-no-newline.sh TESTS += cli-action-disable-45-after-identical-comment.sh TESTS += cli-action-disable-51-dupe-mine.sh TESTS += cli-action-disable-52-dupe-alien.sh TESTS += cli-action-disable-53-dupe-mixed.sh TESTS += cli-action-enable-1-nofile.sh TESTS += cli-action-enable-2-emptyfile.sh TESTS += cli-action-enable-31-non-empty.sh TESTS += cli-action-enable-32-non-empty-no-newline.sh TESTS += cli-action-enable-45-after-identical-comment.sh TESTS += cli-action-enable-51-already-enabled.sh TESTS += cli-action-enable-52-another-instance-enabled.sh TESTS += cli-action-help.sh TESTS += cli-action-status-ld.so.preload-alien.sh TESTS += cli-action-status-ld.so.preload-absent.sh TESTS += cli-action-status-ld.so.preload-dupe.sh TESTS += cli-action-status-ld.so.preload-present.sh TESTS += cli-action-status-LD_PRELOAD-absent.sh TESTS += cli-action-status-LD_PRELOAD-present.sh TESTS += cli-action-status-LD_PRELOAD-set-but-not-present.sh TESTS += cli-action-version-cli.sh TESTS += cli-action-version-library.sh TESTS += cli-err-action-missing-msg.sh TESTS += cli-err-action-missing-status.sh TESTS += cli-err-action-unknown-msg.sh TESTS += cli-err-action-unknown-status.sh ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) ### Remove stale temporary test files, if tests got stuck # clean-local-this-dir: rm -f *.sh.* ; snoopy-snoopy-2.5.2/tests/cli/_bootstrap.sh000077500000000000000000000011501470651710700210250ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh ### This dir-specific settings # # Path to the freshly built `snoopyctl` CLI tool export SNOOPY_CLI="$SNOOPY_CUR_TEST_WORKDIR/../../src/cli/snoopyctl" # This one changes the behaviour of `snoopyctl ...` CLI tool, to look for `libsnoopy.so` # in the specified location instead of the configured one. # For now, this does not change what `snoopyctl enable` puts into the `ld.so.preload` file. export SNOOPY_TEST_LIBSNOOPY_SO_PATH="$SNOOPY_CUR_TEST_WORKDIR/../../src/.libs/libsnoopy.so" snoopy-snoopy-2.5.2/tests/cli/cli-action-about.sh000077500000000000000000000005651470651710700220140ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # EXPECTED_STRING="https://github.com/a2o/snoopy" if ! $SNOOPY_CLI about | fgrep "$EXPECTED_STRING" > /dev/null ; then snoopy_testResult_fail "Expected string not encountered: '$EXPECTED_STRING'" fi ### Evaluate # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-conf.sh000077500000000000000000000005451470651710700216250ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # EXPECTED_STRING="message_format" if ! $SNOOPY_CLI conf | fgrep "$EXPECTED_STRING" > /dev/null ; then snoopy_testResult_fail "Expected string not encountered: '$EXPECTED_STRING'" fi ### Evaluate # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-1-nofile.sh000077500000000000000000000007711470651710700237140ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly appeared" fi snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-2-emptyfile.sh000077500000000000000000000014201470651710700244270ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH touch $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-31-only-entry.sh000077500000000000000000000014621470651710700246410ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-32-only-entry-no-newline.sh000077500000000000000000000014651470651710700267160ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-33-only-entry-and-space.sh000077500000000000000000000014741470651710700264770ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH # comment" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-34-only-entry-and-tab.sh000077500000000000000000000014741470651710700261530ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH # comment" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-35-only-entry-and-comment.sh000077500000000000000000000014731470651710700270470ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH# comment" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Run the command # $SNOOPY_CLI disable ### Evaluate # if [ ! -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly missing" fi FILESIZE=`stat -c "%s" $SNOOPY_TEST_LD_SO_PRELOAD_PATH` if [ "$FILESIZE" != "0" ]; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) unexpectedly non-empty" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-41-first.sh000077500000000000000000000014501470651710700236460ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH # asdf # bsdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # bsdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI disable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-42-middle.sh000077500000000000000000000014501470651710700237560ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf $SNOOPY_TEST_LIBSNOOPY_SO_PATH # bsdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # bsdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI disable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-43-last.sh000077500000000000000000000014501470651710700234640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # bsdf $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # bsdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI disable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-44-last-no-newline.sh000077500000000000000000000014571470651710700255450ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "# asdf # bsdf $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "# asdf # bsdf " > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI disable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-45-after-identical-comment.sh000077500000000000000000000015431470651710700272210ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "# asdf # $SNOOPY_TEST_LIBSNOOPY_SO_PATH $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "# asdf # $SNOOPY_TEST_LIBSNOOPY_SO_PATH " > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI disable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-51-dupe-mine.sh000077500000000000000000000017751470651710700244150ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command & test the exit status # if $SNOOPY_CLI disable ; then snoopy_testResult_fail "Unexpected zero exit status" fi ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-52-dupe-alien.sh000077500000000000000000000020111470651710700245360ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result echo "/another/instance/of/libsnoopy.so /another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "/another/instance/of/libsnoopy.so /another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command & test the exit status # if $SNOOPY_CLI disable ; then snoopy_testResult_fail "Unexpected zero exit status" fi ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-disable-53-dupe-mixed.sh000077500000000000000000000020031470651710700245560ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH /another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH /another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command & test the exit status # if $SNOOPY_CLI disable ; then snoopy_testResult_fail "Unexpected zero exit status" fi ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-1-nofile.sh000077500000000000000000000013431470651710700235330ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-2-emptyfile.sh000077500000000000000000000014111470651710700242520ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH touch $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-31-non-empty.sh000077500000000000000000000014321470651710700242670ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-32-non-empty-no-newline.sh000077500000000000000000000014351470651710700263440ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo -n "# asdf" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-45-after-identical-comment.sh000077500000000000000000000015341470651710700270440ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# asdf # $SNOOPY_TEST_LIBSNOOPY_SO_PATH $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-51-already-enabled.sh000077500000000000000000000014531470651710700253570ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command # $SNOOPY_CLI enable ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-enable-52-another-instance-enabled.sh000077500000000000000000000016161470651710700272020ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Setup the test environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "/another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "/another/instance/of/libsnoopy.so" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ### Run the command & test the exit status # if $SNOOPY_CLI enable ; then snoopy_testResult_fail "Unexpected zero exit status" fi ### Evaluate # if ! diff -u $SNOOPY_TEST_LD_SO_PRELOAD_PATH $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result ; then snoopy_testResult_fail "ld.so.preload test file ($SNOOPY_TEST_LD_SO_PRELOAD_PATH) content not as expected" fi rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH.expected-result snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-help.sh000077500000000000000000000005501470651710700216240ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # EXPECTED_STRING="Available actions:" if ! $SNOOPY_CLI help | fgrep "$EXPECTED_STRING" > /dev/null ; then snoopy_testResult_fail "Expected string not encountered: '$EXPECTED_STRING'" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-LD_PRELOAD-absent.sh000077500000000000000000000010111470651710700251250ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" unset LD_PRELOAD ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E '^LD_PRELOAD environment var: +NOT OK - Not set' > /dev/null ; then snoopy_testResult_fail "LD_PRELOAD unset, but status says otherwise" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-LD_PRELOAD-present.sh000077500000000000000000000010611470651710700253360ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" export LD_PRELOAD="$SNOOPY_TEST_LIBSNOOPY_SO_PATH" ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E '^LD_PRELOAD environment var: +OK - Snoopy reference found.' > /dev/null ; then snoopy_testResult_fail "LD_PRELOAD contains valid libsnoopy.so reference, but status says otherwise" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-LD_PRELOAD-set-but-not-present.sh000077500000000000000000000011331470651710700275150ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" export LD_PRELOAD="" ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E '^LD_PRELOAD environment var: +NOT SET - Set, but no Snoopy reference found' > /dev/null ; then snoopy_testResult_fail "LD_PRELOAD set but does not contain a valid libsnoopy.so reference, yet status says otherwise" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-ld.so.preload-absent.sh000077500000000000000000000012251470651710700261330ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "# something random in here" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E '^/etc/ld.so.preload: +NOT OK - Snoopy is not enabled' > /dev/null ; then snoopy_testResult_fail "ld.so.preload does not contain a valid libsnoopy.so reference, but status says otherwise" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-ld.so.preload-alien.sh000077500000000000000000000013141470651710700257460ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "/unknown/lib/$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E "^/etc/ld.so.preload: +NOT OK - 'libsnoopy.so' found, but not with the expected path" > /dev/null ; then snoopy_testResult_fail "ld.so.preload contains invalid libsnoopy.so reference, but status error message not as expected" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-ld.so.preload-dupe.sh000077500000000000000000000011471470651710700256170ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH $SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Execute & verify # if $SNOOPY_CLI status > /dev/null ; then snoopy_testResult_fail "ld.so.preload contains duplicate libsnoopy.so reference, but status didn't fail" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-status-ld.so.preload-present.sh000077500000000000000000000012101470651710700263310ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Prepare the environment # export SNOOPY_TEST_LD_SO_PRELOAD_PATH="$SNOOPY_CUR_TEST_FILENAME.ld.so.preload" rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH echo "$SNOOPY_TEST_LIBSNOOPY_SO_PATH" > $SNOOPY_TEST_LD_SO_PRELOAD_PATH ### Execute & verify # if ! $SNOOPY_CLI status 2>&1 | grep -E '^/etc/ld.so.preload: +OK - Snoopy is enabled.' > /dev/null ; then snoopy_testResult_fail "ld.so.preload contains valid libsnoopy.so reference, but status says otherwise" fi ### Success # rm -f $SNOOPY_TEST_LD_SO_PRELOAD_PATH snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-version-cli.sh000077500000000000000000000006011470651710700231230ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # SEARCH_REGEX="^Snoopy CLI tool version: [-.a-z0-9]+" if ! $SNOOPY_CLI version | grep -E "$SEARCH_REGEX" > /dev/null ; then snoopy_testResult_fail "Unable to find expected version information: $SEARCH_REGEX" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-action-version-library.sh000077500000000000000000000006011470651710700240200ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # SEARCH_REGEX="^Snoopy library version: [-.a-z0-9]+" if ! $SNOOPY_CLI version | grep -E "$SEARCH_REGEX" > /dev/null ; then snoopy_testResult_fail "Unable to find expected version information: $SEARCH_REGEX" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-err-action-missing-msg.sh000077500000000000000000000006411470651710700237200ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # EXPECTED_ERROR_MESSAGE="[ERROR] No action specified" RES=`$SNOOPY_CLI 2>&1 | fgrep -c "$EXPECTED_ERROR_MESSAGE"` || true if [ "$RES" != "1" ]; then snoopy_testResult_fail "Expected error message not encountered: '$EXPECTED_ERROR_MESSAGE'" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-err-action-missing-status.sh000077500000000000000000000004201470651710700244500ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # if $SNOOPY_CLI > /dev/null 2>&1 ; then snoopy_testResult_fail "Expected non-zero exit status" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-err-action-unknown-msg.sh000077500000000000000000000007121470651710700237450ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # ACTION="sampleUnknownAction" EXPECTED_ERROR_MESSAGE="[ERROR] Unknown action: $ACTION" RES=`$SNOOPY_CLI $ACTION 2>&1 | fgrep -c "$EXPECTED_ERROR_MESSAGE"` || true if [ "$RES" != "1" ]; then snoopy_testResult_fail "Expected error message not encountered: '$EXPECTED_ERROR_MESSAGE'" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/cli/cli-err-action-unknown-status.sh000077500000000000000000000004441470651710700245040ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Test for error(s) # if $SNOOPY_CLI sampleUnknownAction > /dev/null 2>&1 ; then snoopy_testResult_fail "Expected non-zero exit status" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/combined/000077500000000000000000000000001470651710700173265ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/combined/Makefile.am000066400000000000000000000013341470651710700213630ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = TESTS += combined-nofilter-1.sh TESTS += combined-nofilter-2.sh if FILTERING_ENABLED if FILTER_ENABLED_exclude_uid TESTS += combined-filter-exclude_uid-drop.sh TESTS += combined-filter-exclude_uid-pass.sh endif if FILTER_ENABLED_only_uid TESTS += combined-filter-only_uid-drop.sh TESTS += combined-filter-only_uid-pass.sh endif endif ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += combined-generic.sh EXTRA_DIST += $(TESTS) ### Remove stale temporary test files, if tests got stuck # clean-local-this-dir: rm -f *.ini ; rm -f *.out ; snoopy-snoopy-2.5.2/tests/combined/_bootstrap.sh000077500000000000000000000002011470651710700220320ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/combined/combined-filter-exclude_uid-drop.sh000077500000000000000000000004331470651710700261620ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # MY_UID=`id -u` ARG_1="ls -la /" ARG_2="%{cmdline}" ARG_3="exclude_uid:$MY_UID" ARG_4="0" ARG_5="" ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/combined/combined-filter-exclude_uid-pass.sh000077500000000000000000000006021470651710700261620ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # CUR_TIMESTAMP=`date +%s` MY_UID=`id -u` MY_UID_PLUS_1=`expr $MY_UID + 1` ARG_1="ls -la /" ARG_2="$CUR_TIMESTAMP %{cmdline}" ARG_3="exclude_uid:$MY_UID_PLUS_1" ARG_4="1" ARG_5="$CUR_TIMESTAMP ls -la /" ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/combined/combined-filter-only_uid-drop.sh000077500000000000000000000005001470651710700255050ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # MY_UID=`id -u` MY_UID_PLUS_1=`expr $MY_UID + 1` ARG_1="ls -la /" ARG_2="%{cmdline}" ARG_3="only_uid:$MY_UID_PLUS_1" ARG_4="0" ARG_5="" ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/combined/combined-filter-only_uid-pass.sh000077500000000000000000000005251470651710700255160ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # CUR_TIMESTAMP=`date +%s` MY_UID=`id -u` ARG_1="ls -la /" ARG_2="$CUR_TIMESTAMP %{cmdline}" ARG_3="only_uid:$MY_UID" ARG_4="1" ARG_5="$CUR_TIMESTAMP $ARG_1" ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/combined/combined-generic.sh000077500000000000000000000035531470651710700230650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get arguments # # If this file is sourced from other tests, get arguments from ARG_x variables. # Otherwise use CLI args. # if [ "x$ARG_1" != "x" ]; then COMMAND="$ARG_1" MESSAGE_FORMAT="$ARG_2" FILTER_CHAIN="$ARG_3" EXPECTED_OUTPUT_LINECOUNT="$ARG_4" EXPECTED_OUTPUT_CONTENT="$ARG_5" else COMMAND="$1" MESSAGE_FORMAT="$2" FILTER_CHAIN="$3" EXPECTED_OUTPUT_LINECOUNT="$4" EXPECTED_OUTPUT_CONTENT="$5" fi TMP_INI=$SNOOPY_CUR_TEST_FILENAME.$$.ini TMP_OUT=$SNOOPY_CUR_TEST_FILENAME.$$.out # Remove possibly stale files rm -f $TMP_INI rm -f $TMP_OUT # Readlink fails if file does not exist touch $TMP_INI touch $TMP_OUT # Make paths absolute TMP_INI=`readlink -f $TMP_INI` TMP_OUT=`readlink -f $TMP_OUT` cat > $TMP_INI < /dev/null ) unset LD_PRELOAD unset SNOOPY_INI ### Compare output line count # OUTPUT_LINECOUNT=`cat $TMP_OUT | wc -l` if [ "$OUTPUT_LINECOUNT" != "$EXPECTED_OUTPUT_LINECOUNT" ]; then snoopy_testResult_fail "Expected line count ($EXPECTED_OUTPUT_LINECOUNT) does not equal actual line count ($OUTPUT_LINECOUNT)." fi # If linecount is zero, there is no point comparing content if [ "$OUTPUT_LINECOUNT" == "0" ]; then # Cleanup too rm -f $TMP_INI rm -f $TMP_OUT snoopy_testResult_pass fi ### Compare content # OUTPUT_CONTENT=`cat $TMP_OUT` ### Cleanup # rm -f $TMP_INI rm -f $TMP_OUT ### Evaluate # snoopy_test_compareValues "$OUTPUT_CONTENT" "$EXPECTED_OUTPUT_CONTENT" snoopy-snoopy-2.5.2/tests/combined/combined-nofilter-1.sh000077500000000000000000000004011470651710700234160ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # ARG_1="ls -la /" ARG_2="%{cmdline}" ARG_3="" ARG_4="1" ARG_5="ls -la /" ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/combined/combined-nofilter-2.sh000077500000000000000000000004161470651710700234250ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Set test configuration # ARG_1="ls -la /; ls /" ARG_2="%{cmdline}" ARG_3="" ARG_4="2" ARG_5=$'ls -la /\nls /' ### Call/source common combined test implementation # . `dirname $BASH_SOURCE`/combined-generic.sh snoopy-snoopy-2.5.2/tests/configfile/000077500000000000000000000000001470651710700176535ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/configfile/Makefile.am000066400000000000000000000036741470651710700217210ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = TESTS += configfile-bom.sh TESTS += configfile-datasource_message_max_length-min.sh TESTS += configfile-datasource_message_max_length-purenumeric.sh TESTS += configfile-datasource_message_max_length-suffix-k.sh TESTS += configfile-datasource_message_max_length-suffix-m-max.sh TESTS += configfile-error_logging-y1.sh TESTS += configfile-error_logging-y2.sh TESTS += configfile-error_logging-y3.sh TESTS += configfile-error_logging-n1.sh TESTS += configfile-error_logging-n2.sh TESTS += configfile-error_logging-n3.sh TESTS += configfile-inline-comment.sh TESTS += configfile-line-length-1023.sh TESTS += configfile-line-length-1024.sh XFAIL_TESTS += configfile-line-length-1024.sh TESTS += configfile-log_message_max_length-min.sh TESTS += configfile-log_message_max_length-purenumeric.sh TESTS += configfile-log_message_max_length-suffix-k.sh TESTS += configfile-log_message_max_length-suffix-m-max.sh if FILTERING_ENABLED TESTS += configfile-filter_chain-1.sh endif TESTS += configfile-message_format-1.sh TESTS += configfile-message_format-unquoted.sh TESTS += configfile-message_format-single-quoted.sh TESTS += configfile-message_format-double-quoted.sh TESTS += configfile-output-devlog.sh if OUTPUT_ENABLED_file TESTS += configfile-output-file.sh endif TESTS += configfile-output-invalid.sh XFAIL_TESTS += configfile-output-invalid.sh TESTS += configfile-output-socket.sh TESTS += configfile-syslog_facility.sh TESTS += configfile-syslog_ident.sh TESTS += configfile-syslog_level.sh ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += configfile-generic.sh EXTRA_DIST += $(TESTS) snoopy-snoopy-2.5.2/tests/configfile/_bootstrap.sh000077500000000000000000000002011470651710700223570ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/configfile/configfile-bom.sh000077500000000000000000000006601470651710700230740ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="someRandomValue" TMP_INI=$SNOOPY_CUR_TEST_FILENAME.ini rm -f $TMP_INI echo -e "\xEF\xBB\xBF[snoopy] message_format = $VAL_REAL" > $TMP_INI VAL_SNOOPY=`$SNOOPY_TEST_CLI run configfile "$TMP_INI" "message_format"` rm -f $TMP_INI ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/configfile/configfile-datasource_message_max_length-min.sh000077500000000000000000000005101470651710700311360ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Set parameters # CONFIG_VARIABLE="datasource_message_max_length" VAL_CONF="1" VAL_EXPECTED="255" ### Execute generic test # $SNOOPY_CUR_TEST_DIR/configfile-generic.sh "$CONFIG_VARIABLE" "$VAL_CONF" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/configfile/configfile-datasource_message_max_length-purenumeric.sh000077500000000000000000000004501470651710700327140ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Set parameters # CONFIG_VARIABLE="datasource_message_max_length" VAL_REAL="1511" ### Execute generic test # $SNOOPY_CUR_TEST_DIR/configfile-generic.sh "$CONFIG_VARIABLE" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/configfile/configfile-datasource_message_max_length-suffix-k.sh000077500000000000000000000005121470651710700321110ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Set parameters # CONFIG_VARIABLE="datasource_message_max_length" VAL_CONF="7k" VAL_EXPECTED="7168" ### Execute generic test # $SNOOPY_CUR_TEST_DIR/configfile-generic.sh "$CONFIG_VARIABLE" "$VAL_CONF" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/configfile/configfile-datasource_message_max_length-suffix-m-max.sh000077500000000000000000000005151470651710700327010ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Set parameters # CONFIG_VARIABLE="datasource_message_max_length" VAL_CONF="1m" VAL_EXPECTED="1048575" ### Execute generic test # $SNOOPY_CUR_TEST_DIR/configfile-generic.sh "$CONFIG_VARIABLE" "$VAL_CONF" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/configfile/configfile-error_logging-n1.sh000077500000000000000000000006471470651710700254770ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_INI="n" VAL_PARSED="n" TMP_INI=$SNOOPY_CUR_TEST_FILENAME.ini rm -f $TMP_INI cat > $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < $TMP_INI < /dev/null; then snoopy_testResult_skip "Cgroup with multiple controllers does not exist" fi ### Evaluate # CONTROLLER_NAME=`cat /proc/self/cgroup | grep -E '^[0-9]:[^,:]+,[^:]+:' | head -n1 | cut -d: -f2 | cut -d, -f1` VAL_EXPECTED=`cat /proc/self/cgroup | grep -E "^[0-9]:$CONTROLLER_NAME," | head -n1` VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup "$CONTROLLER_NAME"` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-name-last.sh000077500000000000000000000014561470651710700256350ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi if ! grep -E '^[0-9]:[^,:]+,[^:]+:' /proc/self/cgroup > /dev/null; then snoopy_testResult_skip "Cgroup with multiple controllers does not exist" fi ### Evaluate # CONTROLLER_NAME=`cat /proc/self/cgroup | grep -E '^[0-9]:[^:]+,[^:]+:' | head -n1 | cut -d: -f2 | awk -F ',' '{print $NF}'` VAL_EXPECTED=`cat /proc/self/cgroup | grep -E "^[0-9]:[^:]+,$CONTROLLER_NAME:" | head -n1` VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup "$CONTROLLER_NAME"` echo $CONTROLLER_NAME echo $VAL_SNOOPY echo $VAL_EXPECTED snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-name-mid.sh000077500000000000000000000013741470651710700254420ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi if ! grep -E '^[0-9]:[^,:]+,[^,:]+,[^:]+:' /proc/self/cgroup > /dev/null; then snoopy_testResult_skip "Cgroup with more than two controllers does not exist" fi ### Evaluate # CONTROLLER_NAME=`cat /proc/self/cgroup | grep -E '^[0-9]:[^,:]+,[^,:]+,[^:]+:' | head -n1 | cut -d: -f2 | cut -d, -f2` VAL_EXPECTED=`cat /proc/self/cgroup | grep -E "^[0-9]:[^,:]+,$CONTROLLER_NAME," | head -n1` VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup "$CONTROLLER_NAME"` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-name-notfound.sh000077500000000000000000000006611470651710700265230ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi ### Evaluate # VAL_EXPECTED="(none)" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup randomCgroupNameThatDefinitelyDoesntExist` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-name.sh000077500000000000000000000011061470651710700246640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi if ! grep -E ':name=systemd:' /proc/self/cgroup > /dev/null; then snoopy_testResult_skip "Cgroup :name=systemd: does not exist" fi ### Evaluate # VAL_EXPECTED=`cat /proc/self/cgroup | grep -E ':name=systemd:'` VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup name=systemd` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-number-notfound.sh000077500000000000000000000006451470651710700270750ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi ### Evaluate # VAL_EXPECTED="(none)" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup 93459234592394523419132942314` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cgroup-number.sh000077500000000000000000000010311470651710700252310ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi if ! grep -E '^1:' /proc/self/cgroup > /dev/null; then snoopy_testResult_skip "Cgroup 1: does not exist" fi ### Evaluate # VAL_EXPECTED=`cat /proc/self/cgroup | grep -E '^1:'` VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cgroup 1` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_cmdline.sh000077500000000000000000000004341470651710700240650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # COMMAND="$SNOOPY_TEST_CLI run datasource cmdline" VAL_SNOOPY=`$COMMAND` VAL_REAL="$COMMAND" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_cwd.sh000077500000000000000000000004011470651710700232210ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource cwd` VAL_REAL="$PWD" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_datetime-fmt-epoch.sh000077500000000000000000000012621470651710700261260ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # DATE_FORMAT="%s" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource datetime "$DATE_FORMAT"` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date "+$DATE_FORMAT"` snoopy_testRun_info "Real value: $VAL_REAL" VAL_DIFF=`expr $VAL_SNOOPY - $VAL_REAL | sed -e 's/^-//'` snoopy_testRun_info "Difference: $VAL_DIFF" ### Evaluate # # We allow 3 seconds of difference, just in case. # if [ "$VAL_DIFF" -le "3" ]; then snoopy_testResult_pass else snoopy_testResult_fail "Too much difference (diff=\"$VAL_DIFF\", snoopy=\"$VAL_SNOOPY\", real=\"$VAL_REAL\")" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_datetime-fmt-static.sh000077500000000000000000000006521470651710700263210ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # DATE_FORMAT="staticStringArgumentHere" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource datetime "$DATE_FORMAT"` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date "+$DATE_FORMAT"` snoopy_testRun_info "Real value: $VAL_REAL" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_datetime-fmt-too-long.sh000077500000000000000000000010131470651710700265600ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # DATE_FORMAT="1-------10--------20--------30--------40--------50--------60--------70---75%s" # should exceed 80 character limit and fail VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource datetime "$DATE_FORMAT"` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date "+$DATE_FORMAT"` snoopy_testRun_info "Real value: $VAL_REAL" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_datetime-fmt-ymd.sh000077500000000000000000000006321470651710700256210ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # DATE_FORMAT="%Y-%m-%d" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource datetime "$DATE_FORMAT"` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date "+$DATE_FORMAT"` snoopy_testRun_info "Real value: $VAL_REAL" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_datetime.sh000077500000000000000000000020551470651710700242470ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource datetime` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date "+%Y-%m-%dT%H:%M:%S%z"` snoopy_testRun_info "Real value: $VAL_REAL" # Busybox-based `date` utility does not recognize "yyyy-mm-ddThh:mm:ss+zzzz" format, # so let's convert it to "yyyy-mm-dd hh:mm:ss" format for a more universal handling. VAL_SNOOPY=`echo "$VAL_SNOOPY" | cut -d+ -f1 | sed -e 's/T/ /'` VAL_REAL=`echo "$VAL_REAL" | cut -d+ -f1 | sed -e 's/T/ /'` VAL_SNOOPY_TS=`date --date="$VAL_SNOOPY" "+%s"` VAL_REAL_TS=` date --date="$VAL_REAL" "+%s"` VAL_DIFF=`expr $VAL_SNOOPY_TS - $VAL_REAL_TS | sed -e 's/^-//'` snoopy_testRun_info "Difference: $VAL_DIFF" ### Evaluate # # We allow 3 seconds of difference, just in case. # if [ "$VAL_DIFF" -le "3" ]; then snoopy_testResult_pass else snoopy_testResult_fail "Too much difference (diff=\"$VAL_DIFF\", snoopy=\"$VAL_SNOOPY\", real=\"$VAL_REAL\")" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_domain.sh000077500000000000000000000013271470651710700237230ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource domain` # Getting domain is tricky on some hosts (Travis CI build boxes return empty string) # Therefore try multiple sources. VAL_REAL=`hostname -d` if [ "$VAL_REAL" == "" ]; then SNOOPY_HOSTNAME=`hostname` VAL_REAL=`cat /etc/hosts | sed -e 's/#.*//' | grep -Eo "$SNOOPY_HOSTNAME\.[-_.a-z0-9]+" | sed -e "s/$SNOOPY_HOSTNAME\.//" | head -n1` fi ### Adjust data # if [ "$VAL_REAL" == "(none)" ]; then VAL_REAL="" fi if [ "$VAL_SNOOPY" == "(none)" ]; then VAL_SNOOPY="" fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_egid.sh000077500000000000000000000004641470651710700233650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource egid` MY_PID=$$ VAL_REAL=`snoopy_test_getValue_fromPs "$MY_PID" "egid"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_egroup.sh000077500000000000000000000005461470651710700237570ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource egroup` MY_PID=$$ MY_EGID=`snoopy_test_getValue_fromPs "$MY_PID" "egid"` VAL_REAL=`getent group "$MY_EGID" | cut -d: -f1` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_env-set.sh000077500000000000000000000005521470651710700240340ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # export SNOOPY_TEST_DATASOURCE_ENV_SET="asdf" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource env "SNOOPY_TEST_DATASOURCE_ENV_SET"` VAL_REAL="$SNOOPY_TEST_DATASOURCE_ENV_SET" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_env-unset.sh000077500000000000000000000005221470651710700243740ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # unset SNOOPY_TEST_DATASOURCE_ENV_UNSET VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource env "SNOOPY_TEST_DATASOURCE_ENV_UNSET"` VAL_REAL="(undefined)" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_env_all.sh000077500000000000000000000004611470651710700240720ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource env_all` ### Evaluate # if [ "$VAL_SNOOPY" != "" ]; then snoopy_testResult_pass else snoopy_testResult_fail "$VAL_SNOOPY" "" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_euid.sh000077500000000000000000000004031470651710700233740ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource euid` VAL_REAL="$EUID" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_eusername.sh000077500000000000000000000004711470651710700244370ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource eusername` MY_EUID="$EUID" VAL_REAL=`getent passwd "$MY_EUID" | cut -d: -f1` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_failure.sh000077500000000000000000000004211470651710700240750ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Evaluate # if $SNOOPY_TEST_CLI run datasource failure ; then snoopy_testResult_fail "Datasource 'failure' didn't fail as expected" fi snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/datasource/datasource_filename.sh000077500000000000000000000004651470651710700242360ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # COMMAND_NO_ARGS="$SNOOPY_TEST_CLI" VAL_SNOOPY=`$COMMAND_NO_ARGS run datasource filename` VAL_REAL="$COMMAND_NO_ARGS" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_gid.sh000077500000000000000000000004021470651710700232100ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource gid` VAL_REAL=`id -g` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_group.sh000077500000000000000000000004071470651710700236060ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource group` VAL_REAL=`id -g -n` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_hostname.sh000077500000000000000000000004121470651710700242640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource hostname` VAL_REAL=`hostname` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_ipaddr.sh000077500000000000000000000005341470651710700237160ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource ipaddr` VAL_REAL=`who -m --ips | awk '{print $5}'` || true if [[ "$VAL_REAL" == "" ]]; then VAL_REAL="-" fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_login.sh000077500000000000000000000007701470651710700235650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource login` if ! logname 2>/dev/null; then VAL_REAL="" else VAL_REAL=`logname` fi if [ "$VAL_REAL" == "" ]; then VAL_REAL=${SUDO_USER:-} fi if [ "$VAL_REAL" == "" ]; then VAL_REAL=${LOGNAME:-} fi if [ "$VAL_REAL" == "" ]; then VAL_REAL="(unknown)" fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_pid.sh000077500000000000000000000007401470651710700232260ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # # Run this command first, in background $SNOOPY_TEST_CLI run datasource pid > datasource_pid.out.tmp & # Capture its pid from BASH VAL_REAL=$! # Wait for it to finish wait $VAL_REAL # Get its output VAL_SNOOPY=`cat datasource_pid.out.tmp` # Do a cleanup rm -f datasource_pid.out.tmp ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_ppid.sh000077500000000000000000000003761470651710700234130ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource ppid` VAL_REAL=$$ ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_rpname.sh000077500000000000000000000014401470651710700237320ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource rpname` # Get root process PID CUR_PID=$$ NEW_PPID=`snoopy_test_getValue_fromPs "$CUR_PID" "ppid"` I=0 # Stop at: # - PID 1: init # - PID 0: appears in container when attached to it from the host while [[ "$NEW_PPID" != "1" ]] && [[ "$NEW_PPID" != "0" ]]; do I=`expr $I + 1` if [ "$I" -gt "100" ]; then snoopy_testResult_fail "Endless loop". fi CUR_PID="$NEW_PPID" NEW_PPID=`snoopy_test_getValue_fromPs "$NEW_PPID" "ppid"` done # Get root parent process name VAL_REAL=`cat /proc/$CUR_PID/status | grep '^Name:' | sed 's/^Name:\t//'` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_sid.sh000077500000000000000000000004621470651710700232320ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource sid` MY_PID=$$ VAL_REAL=`snoopy_test_getValue_fromPs "$MY_PID" "sid"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_snoopy_configure_command.sh000077500000000000000000000006151470651710700275410ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource snoopy_configure_command` ### Evaluate # if [[ $VAL_SNOOPY =~ \./configure ]]; then snoopy_testResult_pass else snoopy_testResult_fail "The output does not start with './configure'. Instead, we got this: $VAL_SNOOPY" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_snoopy_literal.sh000077500000000000000000000004521470651710700255150ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="test-string-`date +%s`" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource snoopy_literal "$VAL_REAL"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_snoopy_threads.sh000077500000000000000000000004141470651710700255110ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="1" VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource snoopy_threads ""` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_snoopy_version.sh000077500000000000000000000020551470651710700255470ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource snoopy_version` ### Evaluate # # Supported formats examples: # - 1.0.0 - Stable versions # # - 1.0.0rc1 - RC format used until 2.5.0 # - 1.0.0-rc.1 - Semver-compatible rc format, potentially used since 2.5.0 # - 1.0.0rc.1 - Lazy test regex programming artifact #1, not really used nor supported # - 1.0.0-rc1 - Lazy test regex programming artifact #2, not really used nor supported # # - 1.0.0-1-gdeadbeef - 1 commit after git tag snoopy-1.0.0. Commit's sha hash starts with "deadbeef") # # - deadbeef - Git commit id, used when no tags are present in the repo (i.e. when a GitHub fork is cloned) # # - [any-valid-version-here]-dirty - When the git working directory is dirty # if [[ $VAL_SNOOPY =~ ^([0-9]+\.[0-9]+\.[0-9]+(-?rc\.?[0-9]+)?(-[0-9]+-g[0-9a-f]+)?|[0-9a-f]+)(-dirty)?(-geezer-os)?$ ]]; then snoopy_testResult_pass else snoopy_testResult_fail "$VAL_SNOOPY" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_systemd_unit_name.sh000077500000000000000000000027561470651710700262120ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Verify the environment # if [ ! -f /proc/self/cgroup ]; then snoopy_testResult_skip "File /proc/self/cgroup does not exist" fi if ! grep -E ':name=systemd:' /proc/self/cgroup > /dev/null; then snoopy_testResult_skip "Cgroup :name=systemd: does not exist" fi ### Get the real value # VAL_EXPECTED="SNOOPY-TEST-SUITE(undefined)" VAL_SYSTEMD_UNIT_TYPE=`cat /proc/self/cgroup | grep -E ':name=systemd:' | sed -e 's#^1:name=systemd:/##' | cut -d/ -f1` if [ "$VAL_SYSTEMD_UNIT_TYPE" == "user.slice" ]; then VAL_SYSTEMD_UNIT_UID=`cat /proc/self/cgroup | grep -E ':name=systemd:' | sed -e 's#^1:name=systemd:/##' | cut -d/ -f2 | sed -e 's/^user-//' | sed -e 's/.slice//'` if id -nu $VAL_SYSTEMD_UNIT_UID >/dev/null 2>&1; then VAL_EXPECTED=`id -nu $VAL_SYSTEMD_UNIT_UID` else VAL_EXPECTED="user-$VAL_SYSTEMD_UNIT_UID" fi elif [ "$VAL_SYSTEMD_UNIT_TYPE" == "system.slice" ]; then VAL_EXPECTED=`cat /proc/self/cgroup | grep -E ':name=systemd:' | sed -e 's#^1:name=systemd:/##' | cut -d/ -f2 | sed -e 's/.service$//'` else VAL_EXPECTED=`cat /proc/self/cgroup | grep -E ':name=systemd:' | sed -e 's#^1:name=systemd:/##'` fi # Adjust the empty value to pass the test if [ "$VAL_EXPECTED" == "" ]; then VAL_EXPECTED="-" fi ### Evaluate # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource systemd_unit_name` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/datasource/datasource_tid.sh000077500000000000000000000005231470651710700232310ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource tid` ### Evaluate # if [[ $VAL_SNOOPY =~ ^[0-9]{10,16}$ ]]; then snoopy_testResult_pass else snoopy_testResult_fail "Unexpected thread ID format: $VAL_SNOOPY" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_tid_kernel.sh000077500000000000000000000005301470651710700245670ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource tid_kernel` ### Evaluate # if [[ $VAL_SNOOPY =~ ^[0-9]{1,7}$ ]]; then snoopy_testResult_pass else snoopy_testResult_fail "Unexpected thread ID format: $VAL_SNOOPY" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_timestamp.sh000077500000000000000000000012111470651710700244470ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource timestamp` snoopy_testRun_info "Snoopy value: $VAL_SNOOPY" VAL_REAL=`date +"%s"` snoopy_testRun_info "Real value: $VAL_REAL" VAL_DIFF=`expr $VAL_SNOOPY - $VAL_REAL | sed -e 's/^-//'` snoopy_testRun_info "Difference: $VAL_DIFF" ### Evaluate # # We allow 3 seconds of difference, just in case. # if [ "$VAL_DIFF" -le "3" ]; then snoopy_testResult_pass else snoopy_testResult_fail "Too much difference (diff=\"$VAL_DIFF\", snoopy=\"$VAL_SNOOPY\", real=\"$VAL_REAL\")" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_timestamp_ms.sh000077500000000000000000000012641470651710700251560ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY_1=`$SNOOPY_TEST_CLI run datasource timestamp_ms` sleep 0.005 VAL_SNOOPY_2=`$SNOOPY_TEST_CLI run datasource timestamp_ms` if [ "$VAL_SNOOPY_1" -gt "$VAL_SNOOPY_2" ]; then VAL_SNOOPY_1=`$SNOOPY_TEST_CLI run datasource timestamp_ms` sleep 0.005 VAL_SNOOPY_2=`$SNOOPY_TEST_CLI run datasource timestamp_ms` fi ### Evaluate # VAL_DIFF=`expr $VAL_SNOOPY_2 - $VAL_SNOOPY_1` if [[ "$VAL_DIFF" -ge "5" ]] && [[ "$VAL_DIFF" -lt "500" ]]; then snoopy_testResult_pass "$VAL_DIFF" else snoopy_testResult_fail "${VAL_SNOOPY_1}ms ${VAL_SNOOPY_2}ms" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_timestamp_us.sh000077500000000000000000000012711470651710700251640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY_1=`$SNOOPY_TEST_CLI run datasource timestamp_us` sleep 0.005 VAL_SNOOPY_2=`$SNOOPY_TEST_CLI run datasource timestamp_us` if [ "$VAL_SNOOPY_1" -gt "$VAL_SNOOPY_2" ]; then VAL_SNOOPY_1=`$SNOOPY_TEST_CLI run datasource timestamp_us` sleep 0.005 VAL_SNOOPY_2=`$SNOOPY_TEST_CLI run datasource timestamp_us` fi ### Evaluate # VAL_DIFF=`expr $VAL_SNOOPY_2 - $VAL_SNOOPY_1` if [[ "$VAL_DIFF" -ge "5000" ]] && [[ "$VAL_DIFF" -lt "50000" ]]; then snoopy_testResult_pass "$VAL_DIFF" else snoopy_testResult_fail "${VAL_SNOOPY_1}ms ${VAL_SNOOPY_2}ms" fi snoopy-snoopy-2.5.2/tests/datasource/datasource_tty.sh000077500000000000000000000007071470651710700232750ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource tty` if [ "(unknown)" == "$VAL_SNOOPY" ]; then VAL_SNOOPY="(none)" fi if ! tty -s; then VAL_REAL="(none)" else VAL_REAL=`tty` if [ "not a tty" == "$VAL_REAL" ]; then VAL_REAL="(none)" fi fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_tty_uid.sh000077500000000000000000000010331470651710700241270ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource tty_uid` if [ "(unknown)" == "$VAL_SNOOPY" ]; then VAL_SNOOPY="(none)" fi if ! tty -s; then VAL_REAL="(none)" else VAL_REAL=`tty` if [ "not a tty" == "$VAL_REAL" ]; then VAL_REAL="(none)" else VAL_REAL=`echo "$VAL_REAL" | xargs ls -lan | awk '{print $3}'` fi fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_tty_username.sh000077500000000000000000000010011470651710700251600ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource tty_username` if [ "(unknown)" == "$VAL_SNOOPY" ]; then VAL_SNOOPY="(none)" fi if ! tty -s; then VAL_REAL="(none)" else TTY_PATH=`tty` if [ "not a tty" == "$TTY_PATH" ]; then VAL_REAL="(none)" else VAL_REAL=`stat -c %U $TTY_PATH` fi fi ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_uid.sh000077500000000000000000000004021470651710700232260ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource uid` VAL_REAL=`id -u` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/datasource/datasource_username.sh000077500000000000000000000004121470651710700242650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_SNOOPY=`$SNOOPY_TEST_CLI run datasource username` VAL_REAL=`id -u -n` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/filter/000077500000000000000000000000001470651710700170335ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/filter/Makefile.am000066400000000000000000000032621470651710700210720ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = if FILTER_ENABLED_exclude_spawns_of TESTS += filter_exclude_spawns_of-mustdrop-multiarg-first.sh TESTS += filter_exclude_spawns_of-mustdrop-multiarg-last.sh TESTS += filter_exclude_spawns_of-mustdrop-multiarg-mid.sh TESTS += filter_exclude_spawns_of-mustdrop-singlearg.sh TESTS += filter_exclude_spawns_of-mustdrop-spaceparent.sh TESTS += filter_exclude_spawns_of-mustlog-multiarg.sh TESTS += filter_exclude_spawns_of-mustlog-singlearg.sh TESTS += filter_exclude_spawns_of-mustlog-spaceparent.sh endif if DATASOURCE_ENABLED_uid if FILTER_ENABLED_exclude_uid TESTS += filter_exclude_uid-pass.sh TESTS += filter_exclude_uid-pass-multi.sh TESTS += filter_exclude_uid-drop.sh TESTS += filter_exclude_uid-drop-multi.sh endif endif if FILTER_ENABLED_only_tty TESTS += filter_only_tty.sh endif if DATASOURCE_ENABLED_uid if FILTER_ENABLED_only_uid TESTS += filter_only_uid-pass.sh TESTS += filter_only_uid-pass-multi.sh TESTS += filter_only_uid-drop.sh TESTS += filter_only_uid-drop-multi.sh TESTS += filterchain-double-bothdrop.sh TESTS += filterchain-double-bothpass.sh TESTS += filterchain-double-firstdrops.sh TESTS += filterchain-double-seconddrops.sh TESTS += filterchain-single-drop.sh TESTS += filterchain-single-pass.sh TESTS += filterchain-trailing-semicolon-drop.sh TESTS += filterchain-trailing-semicolon-pass.sh endif endif TESTS += filterchain-unknown-filter.sh ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) snoopy-snoopy-2.5.2/tests/filter/_bootstrap.sh000077500000000000000000000002011470651710700215370ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustdrop-multiarg-first.sh000077500000000000000000000012301470651710700312650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Shell workaround # # CI usually runs commands in a way similar to `docker exec ...`, and certain # distro containers report shell in a process table as `sh` and not as `bash`. # PARENT_PROC_NAME="bash" . /etc/os-release if [[ $ID =~ ^(alpine|arch|almalinux|centos|fedora|rhel|opensuse) ]]; then PARENT_PROC_NAME="sh" fi ### Get data # if ! $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "$PARENT_PROC_NAME,aaaa,bbbb" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustdrop-multiarg-last.sh000077500000000000000000000012301470651710700311010ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Shell workaround # # CI usually runs commands in a way similar to `docker exec ...`, and certain # distro containers report shell in a process table as `sh` and not as `bash`. # PARENT_PROC_NAME="bash" . /etc/os-release if [[ $ID =~ ^(alpine|arch|almalinux|centos|fedora|rhel|opensuse) ]]; then PARENT_PROC_NAME="sh" fi ### Get data # if ! $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "aaaa,bbbb,$PARENT_PROC_NAME" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustdrop-multiarg-mid.sh000077500000000000000000000012301470651710700307070ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Shell workaround # # CI usually runs commands in a way similar to `docker exec ...`, and certain # distro containers report shell in a process table as `sh` and not as `bash`. # PARENT_PROC_NAME="bash" . /etc/os-release if [[ $ID =~ ^(alpine|arch|almalinux|centos|fedora|rhel|opensuse) ]]; then PARENT_PROC_NAME="sh" fi ### Get data # if ! $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "aaaa,$PARENT_PROC_NAME,bbbb" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustdrop-singlearg.sh000077500000000000000000000012161470651710700302730ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Shell workaround # # CI usually runs commands in a way similar to `docker exec ...`, and certain # distro containers report shell in a process table as `sh` and not as `bash`. # PARENT_PROC_NAME="bash" . /etc/os-release if [[ $ID =~ ^(alpine|arch|almalinux|centos|fedora|rhel|opensuse) ]]; then PARENT_PROC_NAME="sh" fi ### Get data # if ! $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "$PARENT_PROC_NAME" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustdrop-spaceparent.sh000077500000000000000000000005261470651710700306300ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # if ! "$SNOOPY_TESTS_BINDIR/space parent" $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "space parent"; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustlog-multiarg.sh000077500000000000000000000004621470651710700277630ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # if $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "aaaa,bbbb,cccc" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message unexpectedly dropped." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustlog-singlearg.sh000077500000000000000000000004501470651710700301070ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # if $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "aaaa" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "Message unexpectedly dropped." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_spawns_of-mustlog-spaceparent.sh000077500000000000000000000005271470651710700304460ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # if "$SNOOPY_TESTS_BINDIR/space parent" $SNOOPY_TEST_CLI run filter "exclude_spawns_of" "parachuteparent"; then snoopy_testResult_pass else snoopy_testResult_fail "Message passed through when it shouldn't." fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_uid-drop-multi.sh000077500000000000000000000006461470651710700253310ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` MY_UID_PLUS_2=`expr $MY_UID + 2` if ! $SNOOPY_TEST_CLI run filter "exclude_uid" "$MY_UID_PLUS_1,$MY_UID,$MY_UID_PLUS_2" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_uid-drop.sh000077500000000000000000000005061470651710700241740ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` if ! $SNOOPY_TEST_CLI run filter "exclude_uid" "$MY_UID" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_uid-pass-multi.sh000077500000000000000000000007161470651710700253310ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` MY_UID_PLUS_2=`expr $MY_UID + 2` MY_UID_PLUS_3=`expr $MY_UID + 3` if ! $SNOOPY_TEST_CLI run filter "exclude_uid" "$MY_UID_PLUS_1,$MY_UID_PLUS_2,$MY_UID_PLUS_3" > /dev/null; then snoopy_testResult_fail "My UID: $MY_UID" else snoopy_testResult_pass fi snoopy-snoopy-2.5.2/tests/filter/filter_exclude_uid-pass.sh000077500000000000000000000005561470651710700242030ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filter "exclude_uid" "$MY_UID_PLUS_1" > /dev/null; then snoopy_testResult_fail "My UID: $MY_UID" else snoopy_testResult_pass fi snoopy-snoopy-2.5.2/tests/filter/filter_only_tty.sh000077500000000000000000000020251470651710700226170ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Check if currently running on tty # # These do not work correctly: # if [[ $- == *i* ]]; then # if [ -t 1 ]; then # # In $(tty), tty is a program. When test suite is run with -j1, it runs in # interactive shell. If -j16 is used, then it runs in background. # RES="$(tty)" || RES="not-on-tty" # This || is here to compensate for non-zero exit status. if [[ $RES == /dev/* ]]; then ON_TTY="true" else ON_TTY="false" fi ### Execute on-tty-dependent check # if [ "$ON_TTY" == "true" ]; then if $SNOOPY_TEST_CLI run filter "only_tty" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "only_tty check failed (test is running on an interactive tty)" fi else if ! $SNOOPY_TEST_CLI run filter "only_tty" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "only_tty check failed (test is NOT running on an interactive tty)" fi fi snoopy-snoopy-2.5.2/tests/filter/filter_only_uid-drop-multi.sh000077500000000000000000000007131470651710700246540ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` MY_UID_PLUS_2=`expr $MY_UID + 2` MY_UID_PLUS_3=`expr $MY_UID + 3` if ! $SNOOPY_TEST_CLI run filter "only_uid" "$MY_UID_PLUS_1,$MY_UID_PLUS_2,$MY_UID_PLUS_3" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filter_only_uid-drop.sh000077500000000000000000000005541470651710700235270ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filter "only_uid" "$MY_UID_PLUS_1" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filter_only_uid-pass-multi.sh000077500000000000000000000006431470651710700246600ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` MY_UID_PLUS_2=`expr $MY_UID + 2` if ! $SNOOPY_TEST_CLI run filter "only_uid" "$MY_UID_PLUS_1,$MY_UID,$MY_UID_PLUS_2" > /dev/null; then snoopy_testResult_fail "My UID: $MY_UID" else snoopy_testResult_pass fi snoopy-snoopy-2.5.2/tests/filter/filter_only_uid-pass.sh000077500000000000000000000005031470651710700235230ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` if ! $SNOOPY_TEST_CLI run filter "only_uid" "$MY_UID" > /dev/null; then snoopy_testResult_fail "My UID: $MY_UID" else snoopy_testResult_pass fi snoopy-snoopy-2.5.2/tests/filter/filterchain-double-bothdrop.sh000077500000000000000000000006051470651710700247520ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID_PLUS_1;only_uid:$MY_UID_PLUS_1" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-double-bothpass.sh000077500000000000000000000005241470651710700247540ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` if $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID;only_uid:$MY_UID" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-double-firstdrops.sh000077500000000000000000000005761470651710700253370ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID_PLUS_1;only_uid:$MY_UID" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-double-seconddrops.sh000077500000000000000000000005761470651710700254630ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID;only_uid:$MY_UID_PLUS_1" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-single-drop.sh000077500000000000000000000005551470651710700241100ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID_PLUS_1" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-single-pass.sh000077500000000000000000000005041470651710700241040ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID" > /dev/null; then snoopy_testResult_fail "My UID: $MY_UID" else snoopy_testResult_pass fi snoopy-snoopy-2.5.2/tests/filter/filterchain-trailing-semicolon-drop.sh000077500000000000000000000005561470651710700264270ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` MY_UID_PLUS_1=`expr $MY_UID + 1` if ! $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID_PLUS_1;" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-trailing-semicolon-pass.sh000077500000000000000000000005041470651710700264220ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # MY_UID=`$SNOOPY_TEST_CLI run datasource uid` if $SNOOPY_TEST_CLI run filterchain "only_uid:$MY_UID;" > /dev/null; then snoopy_testResult_pass else snoopy_testResult_fail "My UID: $MY_UID" fi snoopy-snoopy-2.5.2/tests/filter/filterchain-unknown-filter.sh000077500000000000000000000012531470651710700246430ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Search for failures # ORIG_MESSAGE="msg" FILTER_CHAIN="someUnknownFilter:someBogusArgument" if ! $SNOOPY_TEST_CLI run filterchain "$FILTER_CHAIN" > /dev/null; then snoopy_testResult_fail "Filter unexpectedly dropped the message" fi ADJ_MESSAGE=`$SNOOPY_TEST_CLI run filterchain "$FILTER_CHAIN" | grep -E '^ *Adjusted message: ' | sed -e 's/^ *Adjusted message: //'` if [[ "$ORIG_MESSAGE" == "$ADJ_MESSAGE" ]]; then snoopy_testResult_fail "Filter chain processor didn't adjust the message to report an unknown filter" fi ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/general/000077500000000000000000000000001470651710700171635ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/general/Makefile.am000066400000000000000000000006331470651710700212210ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = TESTS += general-symbol-leaks.sh ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) ### Remove stale temporary test files, if tests got stuck # clean-local-this-dir: rm -f *.ini ; rm -f *.out ; snoopy-snoopy-2.5.2/tests/general/_bootstrap.sh000077500000000000000000000002011470651710700216670ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/general/general-symbol-leaks.sh000077500000000000000000000013051470651710700235360ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Check for leaked global symbols # RES=`nm $SNOOPY_LIBSNOOPY_TEST_SO_PATH | grep ' T ' | grep -v ' snoopy_' | grep -Ev ' (execve?|_init|_fini|__gcov_sort_n_vals|mangle_path)$' | grep -c . | cat` if [ "$RES" != "0" ]; then nm $SNOOPY_LIBSNOOPY_TEST_SO_PATH | grep ' T ' | grep -v ' snoopy_' | grep -Ev ' (execve?|_init|_fini)$' | cat snoopy_testResult_fail "The .so library is leaking global symbols that are not prefixed with 'snoopy_' prefix or declared as 'static'. Inspect with 'nm $SNOOPY_LIBSNOOPY_TEST_SO_PATH' manually." else snoopy_testResult_pass "No leaked symbols found." fi snoopy-snoopy-2.5.2/tests/message/000077500000000000000000000000001470651710700171725ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/message/Makefile.am000066400000000000000000000010111470651710700212170ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = TESTS += message_format-datasource-arg.sh TESTS += message_format-datasource-noarg.sh TESTS += message_format-ds-closing-tag-missing.sh TESTS += message_format-ds-unknown.sh TESTS += message_format-ds-failure.sh TESTS += message_format-empty.sh TESTS += message_format-static.sh ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) snoopy-snoopy-2.5.2/tests/message/_bootstrap.sh000077500000000000000000000002011470651710700216760ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/message/message_format-datasource-arg.sh000077500000000000000000000011661470651710700254300ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Check if there is ENV datasource available # RES=`$SNOOPY_TEST_CLI run datasource --list | grep -E '^ *(snoopy_version|env)$' -c` if [ "$RES" -eq "1" ]; then snoopy_testResult_skip "Required datasource 'env' is not available" fi ### Get data # VAR_NAME="SNOOPY_TEST_MESSAGE_FORMAT_`date +%s`" VAR_VALUE="${VAR_NAME}-value" export $VAR_NAME="$VAR_VALUE" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "%{env:$VAR_NAME}"` VAL_REAL="$VAR_VALUE" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-datasource-noarg.sh000077500000000000000000000005261470651710700257640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # DATASOURCE="snoopy_version" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "%{$DATASOURCE}"` VAL_REAL=`$SNOOPY_TEST_CLI run datasource "$DATASOURCE"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-ds-closing-tag-missing.sh000077500000000000000000000004711470651710700270070ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="[ERROR: Closing data source tag ('}') not found.]" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "%{failure"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-ds-failure.sh000077500000000000000000000005721470651710700245620ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="[ERROR: Data source 'failure' failed with the following error message: 'Artificial datasource failure triggered']" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "%{failure}"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-ds-unknown.sh000077500000000000000000000005301470651710700246240ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="[ERROR: Data source 'dataSourceThatDoesNotExist' not found.]" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "%{dataSourceThatDoesNotExist}"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-empty.sh000077500000000000000000000004161470651710700236620ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # STR="" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "$STR"` VAL_REAL="$STR" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/message/message_format-static.sh000077500000000000000000000004521470651710700240130ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # STR="staticUselessText-`date +%s`" VAL_SNOOPY=`$SNOOPY_TEST_CLI run messageformat "$STR"` VAL_REAL="$STR" ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/000077500000000000000000000000001470651710700171065ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/output/Makefile.am000066400000000000000000000013321470651710700211410ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = if OUTPUT_ENABLED_devnull TESTS += output_devnull.sh endif if OUTPUT_ENABLED_file TESTS += output_file.sh if DATASOURCE_ENABLED_username TESTS += output_file-dynamic.sh endif if DATASOURCE_ENABLED_snoopy_literal TESTS += output_file-dynamic-arg.sh endif endif TESTS += output_noop.sh if OUTPUT_ENABLED_socket TESTS += output_socket.sh endif if OUTPUT_ENABLED_stderr TESTS += output_stderr.sh endif if OUTPUT_ENABLED_stdout TESTS += output_stdout.sh endif ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) snoopy-snoopy-2.5.2/tests/output/_bootstrap.sh000077500000000000000000000002011470651710700216120ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/output/output_devnull.sh000077500000000000000000000004221470651710700225340ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL="" VAL_SNOOPY=`$SNOOPY_TEST_CLI run output "$VAL_REAL" "devnull"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_file-dynamic-arg.sh000077500000000000000000000010611470651710700241730ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` MY_PID=$$ MY_USERNAME=`whoami` FILE_EXPECTED="output_file-dynamic-arg.sh.$MY_PID-asdf.tmp.out" FILE_FORMAT="output_file-dynamic-arg.sh.$MY_PID-%{snoopy_literal:asdf}.tmp.out" # Write rm -f $FILE_EXPECTED $SNOOPY_TEST_CLI run output "$VAL_REAL" "file" "$FILE_FORMAT" > /dev/null # Read VAL_SNOOPY=`cat $FILE_EXPECTED` rm -f $FILE_EXPECTED ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_file-dynamic.sh000077500000000000000000000010461470651710700234270ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` MY_PID=$$ MY_USERNAME=`whoami` FILE_EXPECTED="output_file-dynamic.sh.$MY_PID-$MY_USERNAME.tmp.out" FILE_FORMAT="output_file-dynamic.sh.$MY_PID-%{username}.tmp.out" # Write rm -f $FILE_EXPECTED $SNOOPY_TEST_CLI run output "$VAL_REAL" "file" "$FILE_FORMAT" > /dev/null # Read VAL_SNOOPY=`cat $FILE_EXPECTED` rm -f $FILE_EXPECTED ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_file.sh000077500000000000000000000006201470651710700220020ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` MY_PID=$$ FILE="output_file.sh.$MY_PID.tmp.out" # Write rm -f $FILE $SNOOPY_TEST_CLI run output "$VAL_REAL" "file" "$FILE" > /dev/null # Read VAL_SNOOPY=`cat $FILE` rm -f $FILE ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_noop.sh000077500000000000000000000004171470651710700220420ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL="" VAL_SNOOPY=`$SNOOPY_TEST_CLI run output "$VAL_REAL" "noop"` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_socket.sh000077500000000000000000000021101470651710700223470ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` MY_PID=$$ FILE_SOCKET="output_socket.sh.$MY_PID.socket" FILE_OUT="output_socket.sh.$MY_PID.sock.out" # Listen rm -f $FILE_SOCKET rm -f $FILE_OUT touch $FILE_OUT socat UNIX-RECV:$FILE_SOCKET OPEN:$FILE_OUT & SOCAT_PID=$! # Wait for the socket file to appear i=0 while [ ! -e $FILE_SOCKET ]; do i=`expr $i + 1` snoopy_testRun_info "Waiting for socket ($i)..." sleep 0.1 if [ "$i" -gt "100" ]; then snoopy_testResult_fail "Socat listening socket $FILE_SOCKET did not appear." fi done # Send content to this socket $SNOOPY_TEST_CLI run output "$VAL_REAL" socket $FILE_SOCKET # Kill the listener if it is still alive by accident #wait $SOCAT_PID PS_COUNT=`ps -p 1,$SOCAT_PID -o pid,cmd | grep -E -c '^[ ]*[0-9]+[ ]+'` if [ "$PS_COUNT" -gt "2" ]; then kill -9 $SOCAT_PID fi # Read what has been written VAL_SNOOPY=`cat $FILE_OUT` rm -f $FILE_OUT ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_stderr.sh000077500000000000000000000004511470651710700223700ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` VAL_SNOOPY=`$SNOOPY_TEST_CLI run output "$VAL_REAL" "stderr" 2>&1 >/dev/null` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/output/output_stdout.sh000077500000000000000000000004451470651710700224120ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Output data # VAL_REAL=`date +%s` VAL_SNOOPY=`$SNOOPY_TEST_CLI run output "$VAL_REAL" "stdout" 2>/dev/null` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/threads/000077500000000000000000000000001470651710700172005ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/threads/Makefile.am000066400000000000000000000005741470651710700212420ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = if THREAD_SAFETY_ENABLED TESTS += threads_creation.sh TESTS += threads_fork_exec.sh TESTS += threads_try-to-segfault.sh endif ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) snoopy-snoopy-2.5.2/tests/threads/_bootstrap.sh000077500000000000000000000002011470651710700217040ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/threads/threads_creation.sh000077500000000000000000000005571470651710700230640ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="100" #$SNOOPY_TEST_THREADS $VAL_REAL #VAL_SNOOPY=`$SNOOPY_TEST_THREADS $VAL_REAL| grep '^SUCCESS' | grep -Eo '[0-9]+$'` $SNOOPY_TEST_CLI stress threads $VAL_REAL ### Evaluate # #snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/threads/threads_fork_exec.sh000077500000000000000000000005561470651710700232240ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # #set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Get data # VAL_REAL="1" THREAD_COUNT="100" THREAD_EXEC_CMD="/bin/hostname" VAL_SNOOPY=`$SNOOPY_TEST_CLI stress threadsexec $THREAD_COUNT $THREAD_EXEC_CMD | grep '^SUCCESS' -c | cat` ### Evaluate # snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL" snoopy-snoopy-2.5.2/tests/threads/threads_try-to-segfault.sh000077500000000000000000000014641470651710700243240ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Default config # ITERATIONS="100" THREAD_COUNT="200" ### Override with CLI args # if [ ! -z ${1:-} ]; then ITERATIONS="$1" fi if [ ! -z ${2:-} ]; then THREAD_COUNT="$2" fi ### Run the test # echo "Running $ITERATIONS iterations with $THREAD_COUNT threads in each:" for i in `seq 1 $ITERATIONS`; do echo -n " Iteration #$i... " $SNOOPY_TEST_CLI stress threads $THREAD_COUNT > /dev/null RES=$? if [ "$RES" == "0" ]; then echo "done, exit status = $?" else echo echo " ERROR: Exit status = $?" fi done ### Evaluate # snoopy_testResult_pass "No segmentation faults occured. Iterations: $ITERATIONS. Threads-per-iteration: $THREAD_COUNT." snoopy-snoopy-2.5.2/tests/unit/000077500000000000000000000000001470651710700165255ustar00rootroot00000000000000snoopy-snoopy-2.5.2/tests/unit/Makefile.am000066400000000000000000000017651470651710700205720ustar00rootroot00000000000000### Include common Makefile configuration # include $(top_srcdir)/build/Makefile.am.common ### Which tests to run # TESTS = XFAIL_TESTS = if OUTPUT_ENABLED_stdout TESTS += unit-action-log-message-dispatch.sh TESTS += unit-action-log-syscall-exec.sh endif if DATASOURCE_ENABLED_cmdline TESTS += unit-datasource-cmdline.sh endif TESTS += unit-error.sh if CONFIGFILE_ENABLED TESTS += unit-ext-ini.sh endif if FILTERING_ENABLED TESTS += unit-filterregistry.sh endif TESTS += unit-outputregistry.sh TESTS += unit-util-parser.sh TESTS += unit-util-syslog.sh if DATASOURCE_ENABLED_systemd_unit_name TESTS += unit-util-systemd.sh endif if DATASOURCE_ENABLED_ipaddr TESTS += unit-util-utmp-entry-missing.sh TESTS += unit-util-utmp-entry-without-ip-address.sh TESTS += unit-util-utmp-ipv4.sh TESTS += unit-util-utmp-ipv6.sh endif ### Include tests in distribution archive # EXTRA_DIST = _bootstrap.sh EXTRA_DIST += $(TESTS) if DATASOURCE_ENABLED_ipaddr EXTRA_DIST += unit-util-utmp-testUtmpFile endif snoopy-snoopy-2.5.2/tests/unit/_bootstrap.sh000077500000000000000000000002011470651710700212310ustar00rootroot00000000000000#!/bin/bash ### Configure shell # set -e set -u ### Include main _bootstrap.sh # . `dirname $BASH_SOURCE`/../_bootstrap.sh snoopy-snoopy-2.5.2/tests/unit/unit-action-log-message-dispatch.sh000077500000000000000000000005051470651710700253140ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="Test error message, sent out via stdout output." VAL_SNOOPY=`$SNOOPY_TEST_CLI unit action log-message-dispatch | head -n1` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-action-log-syscall-exec.sh000077500000000000000000000005011470651710700244630ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="Test error message, sent out via stdout output." VAL_SNOOPY=`$SNOOPY_TEST_CLI unit action log-syscall-exec | head -n1` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-datasource-cmdline.sh000077500000000000000000000003241470651710700236030ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit datasource cmdline ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-error.sh000077500000000000000000000003071470651710700211720ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit error ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-ext-ini.sh000077500000000000000000000003111470651710700214110ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit ext-ini ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-filterregistry.sh000077500000000000000000000003201470651710700231120ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit filterregistry ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-outputregistry.sh000077500000000000000000000003201470651710700231650ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit outputregistry ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-util-parser.sh000077500000000000000000000003151470651710700223070ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit util parser ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-util-syslog.sh000077500000000000000000000003151470651710700223330ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit util syslog ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-util-systemd.sh000077500000000000000000000003161470651710700225040ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # $SNOOPY_TEST_CLI unit util systemd ### Success # snoopy_testResult_pass snoopy-snoopy-2.5.2/tests/unit/unit-util-utmp-entry-missing.sh000077500000000000000000000005071470651710700246110ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="(Entry not found.)" VAL_SNOOPY=`$SNOOPY_TEST_CLI unit util utmp /dev/pts/9 $SNOOPY_CUR_TEST_DIR/unit-util-utmp-testUtmpFile` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-util-utmp-entry-without-ip-address.sh000077500000000000000000000004651470651710700266770ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="-" VAL_SNOOPY=`$SNOOPY_TEST_CLI unit util utmp /dev/tty1 $SNOOPY_CUR_TEST_DIR/unit-util-utmp-testUtmpFile` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-util-utmp-ipv4.sh000077500000000000000000000005011470651710700226550ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="89.16.143.91" VAL_SNOOPY=`$SNOOPY_TEST_CLI unit util utmp /dev/pts/1 $SNOOPY_CUR_TEST_DIR/unit-util-utmp-testUtmpFile` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-util-utmp-ipv6.sh000077500000000000000000000005111470651710700226600ustar00rootroot00000000000000#!/bin/bash ### Configure shell and bootstrap # set -e set -u . `dirname $BASH_SOURCE`/_bootstrap.sh ### Run the mock test # VAL_EXPECTED="2a01:4f8:c17:785c::1" VAL_SNOOPY=`$SNOOPY_TEST_CLI unit util utmp /dev/pts/2 $SNOOPY_CUR_TEST_DIR/unit-util-utmp-testUtmpFile` snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_EXPECTED" snoopy-snoopy-2.5.2/tests/unit/unit-util-utmp-testUtmpFile000066400000000000000000000066001470651710700240120ustar00rootroot00000000000000~~~reboot5.4.0-117-genericbb5~~~runlevel5.4.0-117-genericob jH-ttyS0tyS0tyS0LOGINjH-tb_(tty1tty1bostjanwH-b2(pts/0ts/0bostjan89.16.143.91bY[4(pts/1ts/1bostjan89.16.143.91b> Y[$pts/3ts/3b%* x\(pts/2ts/2bostjan2a01:4f8:c17:785c::1b?L* x\=pts/4ts/4hHb6Y[