├── .github └── workflows │ ├── build.yml │ ├── coverity.yml │ └── intg.yml ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── COPYING ├── Common.am ├── Dockerfile.centos8 ├── Dockerfile.fedora ├── Doxyfile ├── Makefile.am ├── README.md ├── configure.ac ├── doc ├── .gitignore ├── Makefile.am ├── log_format.md ├── mapping.json └── schema.json ├── include ├── Makefile.am ├── tlog │ ├── Makefile.am │ ├── conf_origin.h │ ├── delay.h │ ├── errs.h │ ├── es_json_reader.h │ ├── fd_json_reader.h │ ├── fd_json_writer.h │ ├── grc.h │ ├── journal_json_reader.h │ ├── journal_json_writer.h │ ├── journal_misc.h │ ├── json_chunk.h │ ├── json_dispatcher.h │ ├── json_misc.h │ ├── json_msg.h │ ├── json_reader.h │ ├── json_reader_type.h │ ├── json_sink.h │ ├── json_source.h │ ├── json_stream.h │ ├── json_writer.h │ ├── json_writer_type.h │ ├── mem_json_reader.h │ ├── mem_json_writer.h │ ├── misc.h │ ├── pkt.h │ ├── play.h │ ├── play_conf.h │ ├── play_conf_cmd.h │ ├── play_conf_validate.h │ ├── rc.h │ ├── rec.h │ ├── rec_conf.h │ ├── rec_conf_cmd.h │ ├── rec_conf_validate.h │ ├── rec_item.h │ ├── rec_session_conf.h │ ├── rec_session_conf_cmd.h │ ├── rec_session_conf_validate.h │ ├── rl_json_writer.h │ ├── session.h │ ├── sink.h │ ├── sink_type.h │ ├── source.h │ ├── source_type.h │ ├── syslog_json_writer.h │ ├── syslog_misc.h │ ├── tap.h │ ├── timespec.h │ ├── timestr.h │ ├── trx.h │ ├── trx_act.h │ ├── trx_basic.h │ ├── trx_frame.h │ ├── trx_iface.h │ ├── trx_level.h │ ├── trx_state.h │ ├── tty_sink.h │ ├── tty_source.h │ └── utf8.h └── tltest │ ├── Makefile.am │ ├── json_sink.h │ ├── json_source.h │ ├── json_stream_enc.h │ └── misc.h ├── lib ├── .gitignore ├── Makefile.am ├── tlitest │ ├── config.py │ ├── journal-bad-timing.txt │ ├── journal-good.txt │ ├── journal-missing-entry.txt │ ├── misc.py │ ├── test_env_config.py │ ├── test_tlog_play.py │ ├── test_tlog_play_remote.py │ ├── test_tlog_rec.py │ ├── test_tlog_rec_perf_opts.py │ └── test_tlog_rec_session.py ├── tlog │ ├── Makefile.am │ ├── conf_validate.c.m4 │ ├── delay.c │ ├── errs.c │ ├── es_json_reader.c │ ├── fd_json_reader.c │ ├── fd_json_writer.c │ ├── grc.c │ ├── journal_json_reader.c │ ├── journal_json_writer.c │ ├── journal_misc.c │ ├── json_chunk.c │ ├── json_dispatcher.c │ ├── json_misc.c │ ├── json_msg.c │ ├── json_reader.c │ ├── json_sink.c │ ├── json_source.c │ ├── json_stream.c │ ├── json_writer.c │ ├── mem_json_reader.c │ ├── mem_json_writer.c │ ├── misc.c │ ├── pkt.c │ ├── play.c │ ├── play_conf.c │ ├── play_conf_cmd.c.m4 │ ├── rc.c │ ├── rec.c │ ├── rec_conf.c │ ├── rec_conf_cmd.c.m4 │ ├── rec_item.c │ ├── rec_session_conf.c │ ├── rec_session_conf_cmd.c.m4 │ ├── rl_json_writer.c │ ├── session.c │ ├── sink.c │ ├── source.c │ ├── syslog_json_writer.c │ ├── syslog_misc.c │ ├── tap.c │ ├── timespec.c │ ├── timestr.c │ ├── tty_sink.c │ ├── tty_source.c │ └── utf8.c └── tltest │ ├── Makefile.am │ ├── json_sink.c │ ├── json_source.c │ ├── json_stream_enc.c │ └── misc.c ├── m4 ├── Makefile.am ├── autotools │ ├── .gitignore │ ├── ax_pthread.m4 │ └── libcurl.m4 └── tlog │ ├── Makefile.am │ ├── conf_cmd.m4 │ ├── conf_misc.m4 │ ├── conf_origin.m4 │ ├── conf_schema.m4 │ ├── man.m4 │ ├── misc.m4 │ ├── play_conf_schema.m4 │ ├── rec_common_conf_schema.m4 │ ├── rec_conf_schema.m4 │ └── rec_session_conf_schema.m4 ├── man ├── .gitignore ├── Makefile.am ├── tlog-play.8.m4 ├── tlog-play.conf.5.m4 ├── tlog-rec-session.8.m4 ├── tlog-rec-session.conf.5.m4 ├── tlog-rec.8.m4 └── tlog-rec.conf.5.m4 ├── notes.txt ├── src ├── Makefile.am ├── tlitest │ ├── README.md │ ├── tlitest-run │ ├── tlitest-setup │ └── tlitest-teardown ├── tlog │ ├── .gitignore │ ├── Makefile.am │ ├── tlog-play.c │ ├── tlog-prog.conf.m4 │ ├── tlog-rec-session.c │ └── tlog-rec.c └── tltest │ ├── .gitignore │ ├── Makefile.am │ ├── tltest-fd-json-reader.c │ ├── tltest-grc.c │ ├── tltest-json-esc.c │ ├── tltest-json-overlay.c │ ├── tltest-json-passthrough.c │ ├── tltest-json-sink.c │ ├── tltest-json-source.c │ ├── tltest-json-stream-btoa.c │ ├── tltest-json-stream-enc-bin.c │ ├── tltest-json-stream-enc-txt.c │ ├── tltest-json-stream.c │ ├── tltest-timespec.c │ └── tltest-timestr.c └── tlog.spec /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | branches: [ main ] 5 | pull_request: 6 | branches: [ main ] 7 | 8 | jobs: 9 | make-check: 10 | runs-on: ubuntu-latest 11 | container: fedora:latest 12 | env: 13 | CFLAGS: -Wall -Wextra -Werror -g 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v2 17 | - name: Install dependencies 18 | run: | 19 | dnf -y install autoconf automake make libtool \ 20 | systemd-devel json-c-devel libcurl-devel libutempter-devel 21 | - name: Build 22 | run: | 23 | autoreconf -if && ./configure 24 | make 25 | make check 26 | make distcheck 27 | - name: Upload artifacts 28 | if: always() 29 | uses: actions/upload-artifact@v4 30 | with: 31 | name: config logs 32 | path: config.log 33 | -------------------------------------------------------------------------------- /.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | name: Coverity scan 2 | on: 3 | # run once daily at 12:30 UTC due to 4 | # https://scan.coverity.com/faq#frequency 5 | schedule: 6 | - cron: '30 12 * * *' 7 | 8 | jobs: 9 | coverity: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v2 14 | 15 | - name: Install dependencies 16 | run: | 17 | sudo apt update 18 | sudo apt -y install autoconf automake make libtool \ 19 | pkg-config libjson-c-dev libsystemd-dev libcurl-*-dev \ 20 | libutempter-dev 21 | 22 | - name: Configure 23 | run: autoreconf -if && ./configure 24 | 25 | - name: Execute and submit coverity scan 26 | uses: vapier/coverity-scan-action@v1 27 | with: 28 | email: 'jstephen@redhat.com' 29 | token: ${{ secrets.COVERITY_SCAN_TOKEN }} 30 | -------------------------------------------------------------------------------- /.github/workflows/intg.yml: -------------------------------------------------------------------------------- 1 | name: Integration tests 2 | on: 3 | push: 4 | branches: [ main ] 5 | pull_request: 6 | branches: [ main ] 7 | 8 | jobs: 9 | fedora-build: 10 | runs-on: ubuntu-latest 11 | env: 12 | IMAGE: fedora-img 13 | CONTAINER: fedora-container 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | - name: Build the Docker image 18 | run: sudo -E XDG_RUNTIME_DIR= podman build . --file Dockerfile.fedora --tag ${IMAGE} 19 | - name: Run the container 20 | run: sudo podman run --privileged --security-opt seccomp=unconfined --security-opt apparmor=unconfined --security-opt label=disable --detach -p 80:80 --cap-add=CAP_DAC_READ_SEARCH --cap-add=CAP_DAC_OVERRIDE --name=${CONTAINER} ${IMAGE} 21 | - name: Check the container is up 22 | run: sudo podman ps 23 | - name: Setup ./configure 24 | run: sudo podman exec ${CONTAINER} autoreconf -if 25 | - name: Configure 26 | run: sudo podman exec ${CONTAINER} ./configure --disable-dependency-tracking --prefix=/usr --sysconfdir=/etc --localstatedir=/var 27 | - name: Make dist 28 | run: sudo podman exec ${CONTAINER} make dist 29 | - name: Build and Install the RPM 30 | run: sudo podman exec ${CONTAINER} sh -c 'rpmbuild -tb *tar.gz && dnf install -y ~/rpmbuild/RPMS/x86_64/tlog*' 31 | - name: Integration tests setup 32 | run: sudo podman exec -e CONTAINER_ENV=true ${CONTAINER} ./src/tlitest/tlitest-setup 33 | - name: Workaround failing login 34 | # login during tests calls 'unix_chkpwd' and this fails with 35 | # openat(AT_FDCWD, "/etc/shadow", O_RDONLY|O_CLOEXEC) = -1 EACCES 36 | # for unclear reason (CAP_DAC_* are granted) 37 | run: sudo podman exec -t ${CONTAINER} chmod 777 /etc/shadow 38 | - name: Run tests 39 | # Hostnames test won't work in a container 40 | run: sudo podman exec -t ${CONTAINER} ./src/tlitest/tlitest-run -k "not hostnames" 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /aclocal.m4 2 | /ar-lib 3 | /autom4te.cache 4 | /compile 5 | /config.guess 6 | /config.h 7 | /config.h.in 8 | /config.h.in~ 9 | /config.log 10 | /config.status 11 | /config.sub 12 | /configure 13 | /depcomp 14 | /install-sh 15 | /libtool 16 | /ltmain.sh 17 | /missing 18 | /stamp-h1 19 | /cscope.out 20 | /test-driver 21 | *~ 22 | .* 23 | !.git* 24 | !.travis.yml 25 | *.tar.gz 26 | *.o 27 | *.deps 28 | *.log 29 | *.trs 30 | *.lo 31 | *.la 32 | Makefile 33 | Makefile.in 34 | __pycache__/ 35 | *.py[co] 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: required 3 | dist: xenial 4 | env: 5 | - CONFIGURE_ARGS="" DISTCHECK=yes 6 | - CONFIGURE_ARGS="--enable-debug" DISTCHECK=yes 7 | - CONFIGURE_ARGS="--disable-debug" DISTCHECK=yes 8 | - COVERAGE=yes CFLAGS="--coverage" LDFLAGS="--coverage" CONFIGURE_ARGS="--enable-debug" 9 | - CLANG_SCAN_BUILD="scan-build --status-bugs" 10 | compiler: 11 | - clang 12 | - gcc 13 | os: linux 14 | arch: 15 | - amd64 16 | - ppc64le 17 | addons: 18 | apt: 19 | packages: 20 | - autoconf 21 | - libjson-c-dev 22 | - libcurl4-gnutls-dev 23 | - libsystemd-dev 24 | - libutempter-dev 25 | - clang 26 | - lcov 27 | - rpm 28 | - lsb-release 29 | - xz-utils 30 | - perl 31 | - sed 32 | - dpkg-dev 33 | - pax 34 | - bzip2 35 | - fakeroot 36 | - patch 37 | - wget 38 | 39 | before_install: 40 | - gem install coveralls-lcov 41 | - mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS,SDEBS,DEBS} 42 | - ln -sr ~/rpmbuild ~/debbuild 43 | before_script: 44 | - wget https://github.com/debbuild/debbuild/releases/download/20.12.1/debbuild_20.12.1-0ubuntu18.04_all.deb 45 | - sudo dpkg -i debbuild_20.12.1-0ubuntu18.04_all.deb 46 | - echo "%_default_verbosity 2" >> ~/.debmacros 47 | - autoreconf -i -f 48 | - $CLANG_SCAN_BUILD ./configure --disable-silent-rules $CONFIGURE_ARGS 49 | script: 50 | - $CLANG_SCAN_BUILD make 51 | - $CLANG_SCAN_BUILD make check 52 | - make distcheck 53 | - rpmbuild -ta --nodeps tlog-*.tar.gz 54 | - debbuild -ta tlog-*.tar.gz 55 | - test "x$DISTCHECK" = xyes && make distcheck || true 56 | after_success: 57 | - test "x$COVERAGE" = xyes -a "x$CC" = "xgcc" && lcov --compat-libtool --directory ./lib/tlog/ --capture --output-file coverage.info && coveralls-lcov coverage.info 58 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Tlog 2 | The Tlog project welcomes new contributors. This document will guide you 3 | through the process. 4 | 5 | ## Pull Requests 6 | We actively welcome your pull requests. There are a few guidelines that 7 | we need contributors to follow so that we can keep the codebase consistent 8 | and clean. 9 | 10 | * Fork the main repository and clone it to your local machine. 11 | * Create a topic branch from master. Please avoid working directly on 12 | the ```master``` branch. 13 | * Make commits of logical units, and make sure to follow the 14 | coding style guidelines. 15 | * Submit the pull request (PR) on Github. 16 | 17 | ## Issues 18 | We use GitHub [issues tracker](https://github.com/Scribery/tlog/issues) 19 | to track bugs. 20 | Please ensure your description is clear and has sufficient instructions; 21 | so we are able to reproduce the issue. 22 | 23 | ## Coding Style guidelines 24 | 25 | * Use four spaces for indentation, please don't use tabs except where 26 | required, such as in Makefiles. 27 | 28 | * Lines should be at most 78 chars. 29 | 30 | * Please don't leave trailing whitespace at the ends of lines. 31 | 32 | * Braces open on the same line as the `for`/`while`/`if`/`else` 33 | /`switch`/etc. Closing braces are put on a line of their own, except 34 | in the `else` of an `if` statement or before a `while` of a `do`-`while` 35 | statement. Always use braces for `if` and `while`. 36 | 37 | ```c 38 | if (a == b) { 39 | ... 40 | } 41 | 42 | if (a == b) { 43 | ... 44 | } else if (a > b) { 45 | ... 46 | } 47 | 48 | if (a == b) { 49 | do_something(); 50 | } else { 51 | do_something_else(); 52 | } 53 | 54 | do { 55 | do_something(); 56 | } while (cond); 57 | 58 | while (cond) { 59 | do_something(); 60 | } 61 | 62 | switch (expression) { 63 | case constant-expression: 64 | ... 65 | case constant-expression: 66 | ... 67 | default: 68 | ... 69 | } 70 | 71 | ``` 72 | 73 | * For function, `static` and return type are put on the same line. 74 | Function's name is put on a line of its own. 75 | 76 | ```c 77 | static tlog_grc 78 | tlog_play_run(struct tlog_errs **perrs, int *psignal) 79 | { 80 | ... 81 | } 82 | ``` 83 | 84 | * For regular comments, use C style (`/*` `*/`) comments, even for one-line. 85 | 86 | * For doc-comments (Doxygen comments), use the `/**` `*/` style featured. 87 | 88 | * For wrapping (`\`) of macro, be sure to follow: 89 | 90 | ```c 91 | #define CMP_BOOL(_name) \ 92 | do { \ 93 | if (_name != t._name##_out) { \ 94 | FAIL(#_name " %s != %s", \ 95 | BOOL_STR(_name), BOOL_STR(t._name##_out)); \ 96 | } \ 97 | } while (0) 98 | ``` 99 | 100 | ## Directories 101 | Tlog source is organized as follows. 102 | 103 | ``` 104 | . <- Top-level build and documentation files. 105 | ├── doc <- Documentation. 106 | ├── include <- C headers. 107 | │ ├── tlog <- Tlog library headers. 108 | │ ├── tltest <- Tlog test library headers. 109 | ├── lib <- C library sources. 110 | │ ├── tlog <- Tlog library sources. 111 | │ ├── tltest <- Tlog test library sources. 112 | ├── src <- Program sources. 113 | │ ├── tlog <- Tlog sources. 114 | │ ├── tltest <- Tlog test sources. 115 | ├── m4 <- M4 macros. 116 | │ ├── autotools <- Autotools macros. 117 | │ ├── tlog <- Tlog macros 118 | └── man <- Manpages. 119 | ``` 120 | 121 | Follow instructions in [README](README.md) for how to compile and run 122 | test code. 123 | 124 | ## License 125 | By contributing to Tlog, you agree that your contributions will be licensed 126 | under the [GNU GPL v2 or later](COPYING). 127 | -------------------------------------------------------------------------------- /Dockerfile.centos8: -------------------------------------------------------------------------------- 1 | FROM centos:8 2 | COPY . . 3 | RUN dnf -y install dnf-plugins-core 4 | RUN dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm 5 | RUN dnf config-manager --set-enabled PowerTools 6 | RUN dnf repolist 7 | RUN dnf -y install autoconf \ 8 | automake \ 9 | make \ 10 | libtool \ 11 | rpm-build \ 12 | systemd-devel \ 13 | json-c-devel \ 14 | libcurl-devel \ 15 | libutempter-devel \ 16 | openssh-server \ 17 | openssh-clients \ 18 | passwd \ 19 | glibc-locale-source \ 20 | glibc-langpack-ru \ 21 | cracklib-dicts \ 22 | audit \ 23 | && dnf clean all \ 24 | && sed -i 's/.*PermitRootLogin .*/#&/g' /etc/ssh/sshd_config \ 25 | && echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config \ 26 | && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd \ 27 | && systemctl enable sshd 28 | 29 | EXPOSE 22 30 | CMD [ "/sbin/init" ] 31 | -------------------------------------------------------------------------------- /Dockerfile.fedora: -------------------------------------------------------------------------------- 1 | FROM fedora:rawhide 2 | WORKDIR /tlbuild 3 | COPY . . 4 | RUN dnf -y --nogpgcheck install autoconf \ 5 | automake \ 6 | make \ 7 | libtool \ 8 | rpm-build \ 9 | systemd-devel \ 10 | json-c-devel \ 11 | libcurl-devel \ 12 | libutempter-devel \ 13 | openssh-server \ 14 | openssh-clients \ 15 | passwd \ 16 | glibc-locale-source \ 17 | glibc-langpack-ru \ 18 | cracklib-dicts \ 19 | audit \ 20 | && dnf clean all \ 21 | && sed -i 's/.*PermitRootLogin .*/#&/g' /etc/ssh/sshd_config \ 22 | && echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config \ 23 | && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd \ 24 | && systemctl enable sshd 25 | 26 | EXPOSE 22 27 | CMD [ "/sbin/init" ] 28 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | ACLOCAL_AMFLAGS = -Im4/autotools 23 | SUBDIRS = m4 include lib src doc man 24 | dist_doc_DATA = README.md 25 | dist_noinst_DATA = tlog.spec 26 | 27 | # Remove coverage data files and clang results generated by CI runs 28 | clean-local: 29 | find '$(top_builddir)' -name '*.gcno' -delete -or -name '*.gcda' -delete 30 | -rm -rf clang_output_* 31 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | html 2 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | dist_doc_DATA = \ 23 | log_format.md \ 24 | mapping.json \ 25 | schema.json 26 | -------------------------------------------------------------------------------- /doc/mapping.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "ver": { 4 | "type": "string" 5 | }, 6 | "host": { 7 | "type": "string", 8 | "fields": { 9 | "raw": { 10 | "type": "string", 11 | "index": "not_analyzed" 12 | } 13 | } 14 | }, 15 | "rec": { 16 | "type": "string", 17 | "index": "not_analyzed" 18 | }, 19 | "user": { 20 | "type": "string", 21 | "fields": { 22 | "raw": { 23 | "type": "string", 24 | "index": "not_analyzed" 25 | } 26 | } 27 | }, 28 | "session": { 29 | "type": "long" 30 | }, 31 | "term": { 32 | "type": "string", 33 | "index": "not_analyzed" 34 | }, 35 | "id": { 36 | "type": "long" 37 | }, 38 | "pos": { 39 | "type": "long" 40 | }, 41 | "time": { 42 | "type": "double" 43 | }, 44 | "timing": { 45 | "type": "string", 46 | "index": "not_analyzed" 47 | }, 48 | "in_txt": { 49 | "type": "string" 50 | }, 51 | "in_bin": { 52 | "type": "short" 53 | }, 54 | "out_txt": { 55 | "type": "string" 56 | }, 57 | "out_bin": { 58 | "type": "short" 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /doc/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Tlog message", 3 | "$schema": "http://json-schema.org/draft-04/schema#", 4 | 5 | "type": "object", 6 | 7 | "properties": { 8 | "ver": { 9 | "description": "Message format version", 10 | "type": "string", 11 | "pattern": "^[0-9]+(\\.[0-9]+)?$" 12 | }, 13 | "host": { 14 | "description": "Name of the host recording was made on", 15 | "type": "string" 16 | }, 17 | "rec": { 18 | "description": "ID of the recording on the host", 19 | "type": "string" 20 | }, 21 | "user": { 22 | "description": "Recorded user name", 23 | "type": "string" 24 | }, 25 | "term": { 26 | "description": "Terminal type name", 27 | "type": "string" 28 | }, 29 | "session": { 30 | "description": "Audit session ID", 31 | "type": "integer", 32 | "minimum": 1 33 | }, 34 | "id": { 35 | "description": "ID of the message within the recording", 36 | "type": "integer", 37 | "minimum": 1 38 | }, 39 | "pos": { 40 | "description": "Message position in the recording, milliseconds", 41 | "type": "integer", 42 | "minimum": 0 43 | }, 44 | "time": { 45 | "description": "System clock timestamp of the message", 46 | "type": "double" 47 | }, 48 | "timing": { 49 | "description": "Distribution of this message's events in time", 50 | "type": "string" 51 | }, 52 | 53 | "in_txt": { 54 | "description": "Input text with invalid characters scrubbed", 55 | "type": "string" 56 | }, 57 | "in_bin": { 58 | "description": "Scrubbed invalid input characters as bytes", 59 | "type": "array", 60 | "items": { 61 | "type": "integer", 62 | "minimum": 0, 63 | "maximum": 255 64 | } 65 | }, 66 | 67 | "out_txt": { 68 | "description": "Output text with invalid characters scrubbed", 69 | "type": "string" 70 | }, 71 | "out_bin": { 72 | "description": "Scrubbed invalid output characters as bytes", 73 | "type": "array", 74 | "items": { 75 | "type": "integer", 76 | "minimum": 0, 77 | "maximum": 255 78 | } 79 | } 80 | }, 81 | 82 | "required": [ 83 | "ver", 84 | "host", 85 | "rec", 86 | "user", 87 | "term", 88 | "session", 89 | "id", 90 | "pos", 91 | "timing" 92 | ] 93 | } 94 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | SUBDIRS = tlog tltest 23 | -------------------------------------------------------------------------------- /include/tlog/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | tlogdir = $(includedir)/tlog 23 | 24 | tlog_HEADERS = \ 25 | conf_origin.h \ 26 | delay.h \ 27 | errs.h \ 28 | es_json_reader.h \ 29 | fd_json_reader.h \ 30 | fd_json_writer.h \ 31 | grc.h \ 32 | json_chunk.h \ 33 | json_dispatcher.h \ 34 | json_misc.h \ 35 | json_msg.h \ 36 | json_reader.h \ 37 | json_reader_type.h \ 38 | json_sink.h \ 39 | json_source.h \ 40 | json_stream.h \ 41 | json_writer.h \ 42 | json_writer_type.h \ 43 | mem_json_reader.h \ 44 | mem_json_writer.h \ 45 | misc.h \ 46 | pkt.h \ 47 | play.h \ 48 | play_conf.h \ 49 | play_conf_cmd.h \ 50 | play_conf_validate.h \ 51 | rc.h \ 52 | rec.h \ 53 | rec_conf.h \ 54 | rec_conf_cmd.h \ 55 | rec_conf_validate.h \ 56 | rec_item.h \ 57 | rec_session_conf.h \ 58 | rec_session_conf_cmd.h \ 59 | rec_session_conf_validate.h \ 60 | rl_json_writer.h \ 61 | session.h \ 62 | sink.h \ 63 | sink_type.h \ 64 | source.h \ 65 | source_type.h \ 66 | syslog_json_writer.h \ 67 | syslog_misc.h \ 68 | tap.h \ 69 | timespec.h \ 70 | timestr.h \ 71 | trx.h \ 72 | trx_act.h \ 73 | trx_basic.h \ 74 | trx_frame.h \ 75 | trx_iface.h \ 76 | trx_level.h \ 77 | trx_state.h \ 78 | tty_sink.h \ 79 | tty_source.h \ 80 | utf8.h 81 | 82 | if TLOG_JOURNAL_ENABLED 83 | tlog_HEADERS += \ 84 | journal_json_reader.h \ 85 | journal_json_writer.h \ 86 | journal_misc.h 87 | endif 88 | -------------------------------------------------------------------------------- /include/tlog/conf_origin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Configuration parameter origin. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_CONF_ORIGIN_H 27 | #define _TLOG_CONF_ORIGIN_H 28 | 29 | /** Configuration parameter origin codes, lowest priority first */ 30 | enum tlog_conf_origin { 31 | TLOG_CONF_ORIGIN_FILE = 1, /**< Configuration file */ 32 | TLOG_CONF_ORIGIN_ENV, /**< Environment variable(s) */ 33 | TLOG_CONF_ORIGIN_NAME, /**< Command name (argv[0]) */ 34 | TLOG_CONF_ORIGIN_OPTS, /**< Command-line options */ 35 | TLOG_CONF_ORIGIN_ARGS /**< Command-line positional arguments */ 36 | }; 37 | 38 | #endif /* _TLOG_CONF_ORIGIN_H */ 39 | -------------------------------------------------------------------------------- /include/tlog/delay.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Supported time span (delay) constants 4 | * 5 | * These constants describe minimum and maximum time span values supported by 6 | * JSON messages. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_DELAY_H 29 | #define _TLOG_DELAY_H 30 | 31 | #include 32 | #include 33 | 34 | /** Minimum delay in seconds, as a number */ 35 | #define TLOG_DELAY_MIN_S_NUM 0 36 | /** Minimum delay in seconds, as a string */ 37 | #define TLOG_DELAY_MIN_S_STR "" 38 | /** Minimum delay in milliseconds, as a number */ 39 | #define TLOG_DELAY_MIN_MS_NUM 1 40 | /** Minimum delay in milliseconds, as a string */ 41 | #define TLOG_DELAY_MIN_MS_STR "1" 42 | 43 | /** Minimum delay's struct timespec tv_sec field value */ 44 | #define TLOG_DELAY_MIN_TIMESPEC_SEC \ 45 | TLOG_DELAY_MIN_S_NUM 46 | 47 | /** Minimum delay's struct timespec tv_nsec field value */ 48 | #define TLOG_DELAY_MIN_TIMESPEC_NSEC \ 49 | (TLOG_DELAY_MIN_MS_NUM % 1000 * 1000000) 50 | 51 | /** Minimum delay as a timespec initializer */ 52 | #define TLOG_DELAY_MIN_TIMESPEC \ 53 | (struct timespec){ \ 54 | .tv_sec = TLOG_DELAY_MIN_TIMESPEC_SEC, \ 55 | .tv_nsec = TLOG_DELAY_MIN_TIMESPEC_NSEC \ 56 | } 57 | 58 | /** Minimum delay as a timespec constant */ 59 | extern const struct timespec tlog_delay_min_timespec; 60 | 61 | /** Maximum delay in seconds, as a number */ 62 | #define TLOG_DELAY_MAX_S_NUM INT32_MAX 63 | /** Maximum delay in seconds, as a string */ 64 | #define TLOG_DELAY_MAX_S_STR "2147483647" 65 | /** Maximum delay in milliseconds, as a number */ 66 | #define TLOG_DELAY_MAX_MS_NUM ((int64_t)TLOG_DELAY_MAX_S_NUM * 1000 + 999) 67 | /** Maximum delay in milliseconds, as a string */ 68 | #define TLOG_DELAY_MAX_MS_STR TLOG_DELAY_MAX_S_STR "999" 69 | 70 | /** Maximum delay's struct timespec tv_sec field value */ 71 | #define TLOG_DELAY_MAX_TIMESPEC_SEC \ 72 | TLOG_DELAY_MAX_S_NUM 73 | 74 | /** Maximum delay's struct timespec tv_nsec field value */ 75 | #define TLOG_DELAY_MAX_TIMESPEC_NSEC \ 76 | (TLOG_DELAY_MAX_MS_NUM % 1000 * 1000000) 77 | 78 | /** Maximum delay as a timespec initializer */ 79 | #define TLOG_DELAY_MAX_TIMESPEC \ 80 | (struct timespec){ \ 81 | .tv_sec = TLOG_DELAY_MAX_TIMESPEC_SEC, \ 82 | .tv_nsec = TLOG_DELAY_MAX_TIMESPEC_NSEC \ 83 | } 84 | 85 | /** Maximum delay as a timespec constant */ 86 | extern const struct timespec tlog_delay_max_timespec; 87 | 88 | #endif /* _TLOG_DELAY_H */ 89 | -------------------------------------------------------------------------------- /include/tlog/es_json_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Elasticsearch JSON message reader. 4 | * 5 | * An implementation of a reader retrieving JSON log messages from 6 | * Elasticsearch, provided base URL and a query. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_ES_JSON_READER_H 29 | #define _TLOG_ES_JSON_READER_H 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * Minimum number of messages to request from Elasticsearch in one HTTP 36 | * request 37 | */ 38 | #define TLOG_ES_JSON_READER_SIZE_MIN 1 39 | 40 | /** 41 | * Elasticsearch message reader type 42 | * 43 | * Creation arguments: 44 | * 45 | * const char *base_url The base URL to request Elasticsearch, without the 46 | * query or the fragment parts. 47 | * const char *query The query string to send to ElastiSearch. 48 | * size_t size Number of messages to request from Elasticsearch 49 | * in one HTTP request. 50 | * 51 | */ 52 | extern const struct tlog_json_reader_type tlog_es_json_reader_type; 53 | 54 | /** 55 | * Check if a base URL is valid for use with an Elasticsearch reader, that is, 56 | * if it doesn't contain the query (?...) or the fragment (#...) parts. 57 | * 58 | * @param base_url The base URL to check. 59 | * 60 | * @return True if the base URL is valid, false otherwise. 61 | */ 62 | extern bool tlog_es_json_reader_base_url_is_valid(const char *base_url); 63 | 64 | /** 65 | * Create an Elasticsearch reader. 66 | * 67 | * @param preader Location for the created reader pointer, will be set to 68 | * NULL in case of error. 69 | * @param base_url The base URL to request Elasticsearch, without the query 70 | * or the fragment parts. 71 | * @param query The query string to send to ElastiSearch. 72 | * @param size Number of messages to request from Elasticsearch in one 73 | * HTTP request. 74 | * 75 | * @return Global return code. 76 | */ 77 | static inline tlog_grc 78 | tlog_es_json_reader_create(struct tlog_json_reader **preader, 79 | const char *base_url, 80 | const char *query, 81 | size_t size, 82 | bool verbose) 83 | { 84 | assert(preader != NULL); 85 | assert(tlog_es_json_reader_base_url_is_valid(base_url)); 86 | assert(query != NULL); 87 | return tlog_json_reader_create(preader, &tlog_es_json_reader_type, 88 | base_url, query, size, verbose); 89 | } 90 | 91 | #endif /* _TLOG_ES_JSON_READER_H */ 92 | -------------------------------------------------------------------------------- /include/tlog/fd_json_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief File descriptor JSON message reader. 4 | * 5 | * An implementation of a JSON message reader retrieving log messages from a 6 | * file descriptor. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_FD_JSON_READER_H 29 | #define _TLOG_FD_JSON_READER_H 30 | 31 | #include 32 | #include 33 | 34 | /** File descriptor message reader type */ 35 | extern const struct tlog_json_reader_type tlog_fd_json_reader_type; 36 | 37 | /** 38 | * Create a file descriptor reader. 39 | * 40 | * @param preader Location for the created reader pointer, will be set to 41 | * NULL in case of error. 42 | * @param fd File descriptor to read messages from. 43 | * @param fd_owned True if the file descriptor should be closed upon 44 | * destruction of the reader, false otherwise. 45 | * @param size Text buffer size (non-zero). 46 | * @param match Recording ID string to match, NULL if not provided. 47 | * 48 | * @return Global return code. 49 | */ 50 | static inline tlog_grc 51 | tlog_fd_json_reader_create(struct tlog_json_reader **preader, 52 | int fd, bool fd_owned, size_t size, 53 | const char *match) 54 | { 55 | assert(preader != NULL); 56 | assert(fd >= 0); 57 | assert(size > 0); 58 | return tlog_json_reader_create(preader, &tlog_fd_json_reader_type, 59 | fd, fd_owned, size, match); 60 | } 61 | 62 | #endif /* _TLOG_FD_JSON_READER_H */ 63 | -------------------------------------------------------------------------------- /include/tlog/fd_json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief File descriptor JSON message writer. 4 | * 5 | * An implementation of a writer writing JSON log messages into a file 6 | * descriptor. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_FD_JSON_WRITER_H 29 | #define _TLOG_FD_JSON_WRITER_H 30 | 31 | #include 32 | #include 33 | 34 | /** File descriptor message writer type */ 35 | extern const struct tlog_json_writer_type tlog_fd_json_writer_type; 36 | 37 | /** 38 | * Create an instance of file descriptor writer. 39 | * 40 | * @param pwriter Location for the created writer pointer, will be set to 41 | * NULL in case of error. 42 | * @param fd File descriptor to write messages to. 43 | * @param fd_owned True if the file descriptor should be closed upon 44 | * destruction of the writer, false otherwise. 45 | * 46 | * @return Global return code. 47 | */ 48 | static inline tlog_grc 49 | tlog_fd_json_writer_create(struct tlog_json_writer **pwriter, 50 | int fd, bool fd_owned) 51 | { 52 | assert(fd >= 0); 53 | return tlog_json_writer_create(pwriter, &tlog_fd_json_writer_type, 54 | fd, fd_owned); 55 | } 56 | 57 | #endif /* _TLOG_FD_JSON_WRITER_H */ 58 | -------------------------------------------------------------------------------- /include/tlog/journal_json_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Systemd journal JSON message reader. 4 | * 5 | * An implementation of a JSON message reader retrieving log messages from 6 | * systemd journal. 7 | */ 8 | /* 9 | * Copyright (C) 2017 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_JOURNAL_JSON_READER_H 29 | #define _TLOG_JOURNAL_JSON_READER_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** Systemd journal message reader type */ 36 | extern const struct tlog_json_reader_type tlog_journal_json_reader_type; 37 | 38 | /** 39 | * Create a systemd journal reader. 40 | * 41 | * @param preader Location for the created reader pointer, will be 42 | * set to NULL in case of error. 43 | * @param since The realtime timestamp to seek to before 44 | * reading entries, in microseconds since epoch. 45 | * @param until The realtime timestamp to read entries until, 46 | * in microseconds since epoch. 47 | * @param match_sym_list NULL-terminated array of string pointers, 48 | * containing journal matche symbols to filter entries with. 49 | * See sd_journal_add_match(3). NULL means empty. 50 | * @param namespace Optional Journal namespace to read recordings from. 51 | * See sd_journal_open_namespace(3). If NULL - default 52 | * namespace is used. 53 | * 54 | * @return Global return code. 55 | */ 56 | static inline tlog_grc 57 | tlog_journal_json_reader_create(struct tlog_json_reader **preader, 58 | uint64_t since, uint64_t until, 59 | const char * const *match_sym_list, 60 | const char *namespace) 61 | { 62 | assert(preader != NULL); 63 | assert(match_sym_list == NULL || 64 | tlog_journal_match_sym_list_is_valid(match_sym_list)); 65 | return tlog_json_reader_create(preader, &tlog_journal_json_reader_type, 66 | since, until, match_sym_list, namespace); 67 | } 68 | 69 | #endif /* _TLOG_JOURNAL_JSON_READER_H */ 70 | -------------------------------------------------------------------------------- /include/tlog/journal_json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Systemd journal JSON message writer 4 | * 5 | * An implementation of a JSON log message writer which sends messages to 6 | * systemd's journal service. 7 | */ 8 | /* 9 | * Copyright (C) 2017 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_JOURNAL_JSON_WRITER_H 29 | #define _TLOG_JOURNAL_JSON_WRITER_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** 36 | * Syslog message writer type 37 | * 38 | * Creation arguments: 39 | * 40 | * int priority The "priority" argument to pass to journal(3). 41 | */ 42 | extern const struct tlog_json_writer_type tlog_journal_json_writer_type; 43 | 44 | /** 45 | * Create an instance of journal writer. 46 | * 47 | * @param pwriter Location for the created writer pointer, will be set to 48 | * NULL in case of error. 49 | * @param priority The "priority" argument to pass to journal(3). 50 | * @param augment True if any fields beside MESSAGE and PRIORITY should 51 | * be added to Journal entries, false otherwise. 52 | * @param recording Host-unique recording ID. 53 | * Cannot be NULL, ignored if augment is false 54 | * @param username Name of the user being recorded. 55 | * Cannot be NULL, ignored if augment is false 56 | * @param session_id Audit session ID of the recording. 57 | * Cannot be zero, ignored if augment is false 58 | * 59 | * @return Global return code. 60 | */ 61 | static inline tlog_grc 62 | tlog_journal_json_writer_create(struct tlog_json_writer **pwriter, 63 | int priority, 64 | bool augment, 65 | const char *recording, 66 | const char *username, 67 | unsigned int session_id) 68 | { 69 | assert(pwriter != NULL); 70 | assert(tlog_syslog_priority_is_valid(priority)); 71 | assert(!augment || recording != NULL); 72 | assert(!augment || username != NULL); 73 | assert(!augment || session_id != 0); 74 | return tlog_json_writer_create(pwriter, &tlog_journal_json_writer_type, 75 | priority, augment, 76 | recording, username, session_id); 77 | } 78 | 79 | #endif /* _TLOG_JOURNAL_JSON_WRITER_H */ 80 | -------------------------------------------------------------------------------- /include/tlog/json_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Abstract JSON message reader. 4 | * 5 | * An abstract interface for a JSON log message reader. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLOG_JSON_READER_H 28 | #define _TLOG_JSON_READER_H 29 | 30 | #include 31 | 32 | /** Abstract reader */ 33 | struct tlog_json_reader { 34 | const struct tlog_json_reader_type *type; /**< Type */ 35 | }; 36 | 37 | /** 38 | * Allocate and initialize a reader of the specified type, with specified 39 | * arguments. See the particular type description for specific arguments 40 | * required. 41 | * 42 | * @param preader Location for the created reader pointer, will be set to 43 | * NULL in case of error. 44 | * @param type The type of reader to create. 45 | * @param ... The type-specific reader creation arguments. 46 | * 47 | * @return Global return code. 48 | */ 49 | extern tlog_grc tlog_json_reader_create( 50 | struct tlog_json_reader **preader, 51 | const struct tlog_json_reader_type *type, 52 | ...); 53 | 54 | /** 55 | * Check if a reader is valid. 56 | * 57 | * @param reader The reader to check. 58 | * 59 | * @return True if the reader is valid. 60 | */ 61 | extern bool tlog_json_reader_is_valid( 62 | const struct tlog_json_reader *reader); 63 | 64 | /** 65 | * Retrieve current opaque location of the reader. 66 | * 67 | * @param reader The reader to retrieve current location from. 68 | * 69 | * @return Opaque location value. 70 | */ 71 | extern size_t tlog_json_reader_loc_get( 72 | const struct tlog_json_reader *reader); 73 | 74 | /** 75 | * Format opaque location as a string. 76 | * 77 | * @param reader The reader to format location for. 78 | * @param loc Opaque location value to format. 79 | * 80 | * @return Dynamically-allocated string describing the location, or NULL in 81 | * case of error (see errno). 82 | */ 83 | extern char *tlog_json_reader_loc_fmt(const struct tlog_json_reader *reader, 84 | size_t loc); 85 | 86 | /** 87 | * Read with a reader. 88 | * 89 | * @param reader The reader to operate on. 90 | * @param pobject Location for a JSON object, set to NULL on error or end of 91 | * stream; call json_object_put after the returned object is 92 | * no longer needed. Not modified on error. 93 | * 94 | * @return Global return code. 95 | */ 96 | extern tlog_grc tlog_json_reader_read(struct tlog_json_reader *reader, 97 | struct json_object **pobject); 98 | 99 | /** 100 | * Cleanup and deallocate a reader. 101 | * 102 | * @param reader The reader to destroy, can be NULL. 103 | */ 104 | extern void tlog_json_reader_destroy(struct tlog_json_reader *reader); 105 | 106 | #endif /* _TLOG_JSON_READER_H */ 107 | -------------------------------------------------------------------------------- /include/tlog/json_sink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief JSON terminal data sink. 4 | * 5 | * JSON terminal data sink accepts packets, formats log messages and sends 6 | * them to the writer specified upon creation. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_JSON_SINK_H 29 | #define _TLOG_JSON_SINK_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** Minimum value of data chunk size */ 36 | #define TLOG_JSON_SINK_CHUNK_SIZE_MIN TLOG_JSON_CHUNK_SIZE_MIN 37 | 38 | /** JSON sink creation parameters */ 39 | struct tlog_json_sink_params { 40 | /** JSON log message writer */ 41 | struct tlog_json_writer *writer; 42 | /** 43 | * True if the writer should be destroyed upon destruction of the sink, 44 | * false otherwise 45 | */ 46 | bool writer_owned; 47 | /** Hostname to use in log messages, must be valid UTF-8 */ 48 | const char *hostname; 49 | /** Recording ID to use in log messages, must be valid UTF-8 */ 50 | const char *recording; 51 | /** Username to use in log messages, must be valid UTF-8 */ 52 | const char *username; 53 | /** Terminal type string to use in log messages, must be valid UTF-8 */ 54 | const char *terminal; 55 | /** Session ID to use in log messages */ 56 | unsigned int session_id; 57 | /** Maximum data chunk length */ 58 | size_t chunk_size; 59 | }; 60 | 61 | /** 62 | * Check if JSON sink creation parameters structure is valid. 63 | * 64 | * @param params The parameters structure to check. 65 | * 66 | * @return True if the parameters structure is valid, false otherwise. 67 | */ 68 | extern bool tlog_json_sink_params_is_valid( 69 | const struct tlog_json_sink_params *params); 70 | 71 | /** JSON sink type */ 72 | extern const struct tlog_sink_type tlog_json_sink_type; 73 | 74 | /** 75 | * Create (allocate and initialize) a JSON log sink. 76 | * 77 | * @param psink Location for created sink pointer, 78 | * set to NULL in case of error. 79 | * @param params Creation parameters structure. 80 | * 81 | * @return Global return code. 82 | */ 83 | static inline tlog_grc 84 | tlog_json_sink_create(struct tlog_sink **psink, 85 | const struct tlog_json_sink_params *params) 86 | { 87 | assert(psink != NULL); 88 | assert(tlog_json_sink_params_is_valid(params)); 89 | 90 | return tlog_sink_create(psink, &tlog_json_sink_type, params); 91 | } 92 | 93 | #endif /* _TLOG_JSON_SINK_H */ 94 | -------------------------------------------------------------------------------- /include/tlog/json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Abstract JSON log message writer. 4 | * 5 | * An abstract interface for a JSON log message writer. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLOG_JSON_WRITER_H 28 | #define _TLOG_JSON_WRITER_H 29 | 30 | #include 31 | 32 | /** Abstract writer */ 33 | struct tlog_json_writer { 34 | const struct tlog_json_writer_type *type; /**< Type */ 35 | }; 36 | 37 | /** 38 | * Allocate and initialize a writer of the specified type, with specified 39 | * arguments. See the particular type description for specific arguments 40 | * required. 41 | * 42 | * @param pwriter Location for the created writer pointer, will be set to 43 | * NULL in case of error. 44 | * @param type The type of writer to create. 45 | * @param ... The type-specific writer creation arguments. 46 | * 47 | * @return Global return code. 48 | */ 49 | extern tlog_grc tlog_json_writer_create( 50 | struct tlog_json_writer **pwriter, 51 | const struct tlog_json_writer_type *type, 52 | ...); 53 | 54 | /** 55 | * Check if a writer is valid. 56 | * 57 | * @param writer The writer to check. 58 | * 59 | * @return True if the writer is valid. 60 | */ 61 | extern bool tlog_json_writer_is_valid(const struct tlog_json_writer *writer); 62 | 63 | /** 64 | * Write with a writer. 65 | * Atomic, i.e. always writes everything, or nothing, 66 | * unless an error beside EINTR occurs. 67 | * 68 | * @param writer The writer to write with. 69 | * @param id ID of the message in the buffer. Cannot be zero. 70 | * @param buf The pointer to the message buffer to write. 71 | * @param len The length of the message buffer to write. 72 | * 73 | * @return Global return code. 74 | * Can return TLOG_GRC_FROM(errno, EINTR), if writing was interrupted 75 | * by a signal before anything was written. 76 | */ 77 | extern tlog_grc tlog_json_writer_write(struct tlog_json_writer *writer, 78 | size_t id, 79 | const uint8_t *buf, size_t len); 80 | 81 | /** 82 | * Cleanup and deallocate a writer. 83 | * 84 | * @param writer The writer to destroy, can be NULL. 85 | */ 86 | extern void tlog_json_writer_destroy(struct tlog_json_writer *writer); 87 | 88 | #endif /* _TLOG_JSON_WRITER_H */ 89 | -------------------------------------------------------------------------------- /include/tlog/mem_json_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Memory buffer JSON message reader. 4 | * 5 | * An implementation of a reader reading log messages from a memory buffer, 6 | * mostly for use in tests. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_MEM_JSON_READER_H 29 | #define _TLOG_MEM_JSON_READER_H 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * Memory buffer message reader type 36 | * 37 | * Creation arguments: 38 | * 39 | * const char *buf Pointer to the buffer to read from. 40 | * size_t len Length of the buffer to read from. 41 | */ 42 | extern const struct tlog_json_reader_type tlog_mem_json_reader_type; 43 | 44 | /** 45 | * Create a memory buffer reader. 46 | * 47 | * @param preader Location for the created reader pointer, will be set to 48 | * NULL in case of error. 49 | * @param buf Pointer to the buffer to read from. 50 | * @param len Length of the buffer to read from. 51 | * 52 | * @return Global return code. 53 | */ 54 | static inline tlog_grc 55 | tlog_mem_json_reader_create(struct tlog_json_reader **preader, 56 | const char *buf, size_t len) 57 | { 58 | assert(preader != NULL); 59 | assert(buf != NULL || len == 0); 60 | return tlog_json_reader_create(preader, &tlog_mem_json_reader_type, buf, len); 61 | } 62 | 63 | #endif /* _TLOG_MEM_JSON_READER_H */ 64 | -------------------------------------------------------------------------------- /include/tlog/mem_json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Memory buffer JSON message writer. 4 | * 5 | * An implementation of a writer writing JSON log messages to a memory buffer, 6 | * mostly for use in tests. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_MEM_JSON_WRITER_H 29 | #define _TLOG_MEM_JSON_WRITER_H 30 | 31 | #include 32 | #include 33 | 34 | /** 35 | * Memory buffer JSON message writer type 36 | * 37 | * Creation arguments: 38 | * 39 | * char **pbuf Location for the allocated buffer pointer. 40 | * size_t *plen Location for the length of the buffer contents. The memory 41 | * allocated for the buffer can be larger. 42 | */ 43 | extern const struct tlog_json_writer_type tlog_mem_json_writer_type; 44 | 45 | /** 46 | * Create an instance of memory buffer writer. 47 | * 48 | * @param pwriter Location for the pointer to the created writer. 49 | * @param pbuf Location for the allocated buffer pointer. 50 | * @param plen Location for the length of the buffer contents. The memory 51 | * allocated for the buffer can be larger. 52 | * 53 | * @return Global return code. 54 | */ 55 | static inline tlog_grc 56 | tlog_mem_json_writer_create(struct tlog_json_writer **pwriter, 57 | char **pbuf, size_t *plen) 58 | { 59 | assert(pbuf != NULL); 60 | assert(plen != NULL); 61 | return tlog_json_writer_create(pwriter, &tlog_mem_json_writer_type, 62 | pbuf, plen); 63 | } 64 | 65 | #endif /* _TLOG_MEM_JSON_WRITER_H */ 66 | -------------------------------------------------------------------------------- /include/tlog/play.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Generic playback process 4 | */ 5 | /* 6 | * Copyright (C) 2017 Red Hat 7 | * 8 | * This file is part of tlog. 9 | * 10 | * Tlog is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tlog is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with tlog; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _TLOG_PLAY_H 26 | #define _TLOG_PLAY_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /** 33 | * Run playback. 34 | * 35 | * @param perrs Location for the error stack. Can be NULL. 36 | * @param cmd_help Command-line usage help message. 37 | * @param conf Configuration JSON object. 38 | * @param psignal Location for the number of the signal which caused 39 | * playback to exit, zero if none. Not modified in case of 40 | * error. Can be NULL. 41 | * 42 | * @return Global return code. 43 | */ 44 | extern tlog_grc tlog_play(struct tlog_errs **perrs, 45 | const char *cmd_help, 46 | struct json_object *conf, 47 | int *psignal); 48 | 49 | #endif /* _TLOG_PLAY_H */ 50 | -------------------------------------------------------------------------------- /include/tlog/play_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-play configuration parsing 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_PLAY_CONF_H 27 | #define _TLOG_PLAY_CONF_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /** 34 | * Load tlog-play configuration from various sources and extract program name. 35 | * 36 | * @param perrs Location for the error stack. Can be NULL. 37 | * @param pcmd_help Location for the dynamically-allocated command-line usage 38 | * help message. Cannot be NULL. 39 | * @param pconf Location for the pointer to the JSON object representing 40 | * the loaded configuration. Cannot be NULL. 41 | * @param argc Tlog-play argc value. 42 | * @param argv Tlog-play argv value. Cannot be NULL. 43 | * 44 | * @return Global return code. 45 | */ 46 | extern tlog_grc tlog_play_conf_load(struct tlog_errs **perrs, 47 | char **pcmd_help, 48 | struct json_object **pconf, 49 | int argc, char **argv); 50 | 51 | #endif /* _TLOG_PLAY_CONF_H */ 52 | -------------------------------------------------------------------------------- /include/tlog/play_conf_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-play command line configuration management. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_PLAY_CONF_CMD_H 27 | #define _TLOG_PLAY_CONF_CMD_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /** 34 | * Load tlog-play configuration from the command line and extract program name. 35 | * 36 | * @param perrs Location for the error stack. Can be NULL. 37 | * @param phelp Location for the dynamically-allocated usage help message. 38 | * Cannot be NULL. 39 | * @param pconf Location for the pointer to the JSON object representing 40 | * the loaded configuration. Cannot be NULL. 41 | * @param argc Tlog-play argc value. 42 | * @param argv Tlog-play argv value. Cannot be NULL. 43 | * 44 | * @return Global return code. 45 | */ 46 | extern tlog_grc tlog_play_conf_cmd_load(struct tlog_errs **perrs, 47 | char **phelp, 48 | struct json_object **pconf, 49 | int argc, char **argv); 50 | 51 | #endif /* _TLOG_PLAY_CONF_CMD_H */ 52 | -------------------------------------------------------------------------------- /include/tlog/play_conf_validate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-play JSON configuration validation. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_PLAY_CONF_VALIDATE_H 27 | #define _TLOG_PLAY_CONF_VALIDATE_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** 35 | * Check tlog-play JSON configuration: if there are no unkown nodes and the 36 | * present node types and values are valid. 37 | * 38 | * @param perrs Location for the error stack. Can be NULL. 39 | * @param conf The configuration JSON object to check. 40 | * @param origin The configuration origin. 41 | * 42 | * @return Global return code. 43 | */ 44 | extern tlog_grc tlog_play_conf_validate(struct tlog_errs **perrs, 45 | struct json_object *conf, 46 | enum tlog_conf_origin origin); 47 | 48 | #endif /* _TLOG_PLAY_CONF_VALIDATE_H */ 49 | -------------------------------------------------------------------------------- /include/tlog/rc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Native function return codes (rc's). 4 | * 5 | * These are tlog-specific function return codes, which are usually 6 | * incorporated into global return codes upon use. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_RC_H 29 | #define _TLOG_RC_H 30 | 31 | #include 32 | 33 | /** Minimum function return code */ 34 | #define TLOG_RC_MIN 0 35 | 36 | /** Function return codes */ 37 | typedef enum tlog_rc { 38 | TLOG_RC_OK = TLOG_RC_MIN, 39 | TLOG_RC_FAILURE, 40 | TLOG_RC_JSON_MSG_FIELD_MISSING, 41 | TLOG_RC_JSON_MSG_FIELD_INVALID_TYPE, 42 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_VER, 43 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_SESSION, 44 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_ID, 45 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_POS, 46 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TIME, 47 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TIMING, 48 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TXT, 49 | TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_BIN, 50 | TLOG_RC_FD_JSON_READER_INCOMPLETE_LINE, 51 | TLOG_RC_JSON_SOURCE_MSG_ID_OUT_OF_ORDER, 52 | TLOG_RC_JSON_SOURCE_PKT_TS_OUT_OF_ORDER, 53 | TLOG_RC_JSON_SOURCE_TERMINAL_MISMATCH, 54 | TLOG_RC_ES_JSON_READER_CURL_INIT_FAILED, 55 | TLOG_RC_ES_JSON_READER_REPLY_INVALID, 56 | TLOG_RC_MEM_JSON_READER_INCOMPLETE_LINE, 57 | /* Return code upper boundary (not a valid return code) */ 58 | TLOG_RC_MAX_PLUS_ONE 59 | } tlog_rc; 60 | 61 | /** 62 | * Check if an rc is valid. 63 | * 64 | * @param rc The rc to check. 65 | * 66 | * @return True if the rc is valid, false otherwise. 67 | */ 68 | static inline bool 69 | tlog_rc_is_valid(tlog_rc rc) 70 | { 71 | return rc < TLOG_RC_MAX_PLUS_ONE; 72 | } 73 | 74 | /** 75 | * Retrieve a global return code description. 76 | * 77 | * @param rc The global return code to retrieve description for. 78 | * 79 | * @return Description as a static, constant string. 80 | */ 81 | extern const char *tlog_rc_strerror(tlog_rc rc); 82 | 83 | #endif /* _TLOG_RC_H */ 84 | -------------------------------------------------------------------------------- /include/tlog/rec.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Generic recording process 4 | */ 5 | /* 6 | * Copyright (C) 2015-2017 Red Hat 7 | * 8 | * This file is part of tlog. 9 | * 10 | * Tlog is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tlog is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with tlog; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _TLOG_REC_H 26 | #define _TLOG_REC_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** tlog_rec option bits (must be ascending powers of two) */ 35 | enum tlog_rec_opt { 36 | /** Recording option bit: drop privileges */ 37 | TLOG_REC_OPT_DROP_PRIVS = TLOG_EXEC_OPT_DROP_PRIVS, 38 | /** Recording option bit: search for program in PATH */ 39 | TLOG_REC_OPT_SEARCH_PATH = TLOG_EXEC_OPT_SEARCH_PATH, 40 | /** Recording option bit: enable session locking */ 41 | TLOG_REC_OPT_LOCK_SESS = 0x04, 42 | /** Maximum option bit value plus one (not a valid bit) */ 43 | TLOG_REC_OPT_MAX_PLUS_ONE 44 | }; 45 | 46 | /** Bitmask with all tlog_rec_opt bits on */ 47 | #define TLOG_REC_OPT_MASK (((TLOG_REC_OPT_MAX_PLUS_ONE - 1) << 1) - 1) 48 | 49 | /** 50 | * Run recording with specified configuration and environment. 51 | * 52 | * @param perrs Location for the error stack. Can be NULL. 53 | * @param euid The effective UID the program was started with. 54 | * @param egid The effective GID the program was started with. 55 | * @param cmd_help Command-line usage help message. 56 | * @param conf Recording program configuration JSON object. 57 | * @param opts A bitmask of TLOG_REC_OPT_* bits. 58 | * @param path Path to the recorded program to execute. 59 | * @param argv ARGV array for the recorded program. 60 | * @param in_fd Stdin to connect to, or -1 if none. 61 | * @param out_fd Stdout to connect to, or -1 if none. 62 | * @param err_fd Stderr to connect to, or -1 if none. 63 | * @param pstatus Location for the recorded program exit status as returned 64 | * by waitpid(2). Not modified in case of error. Can be NULL, 65 | * if not needed. 66 | * @param psignal Location for the number of signal which caused recording 67 | * termination, or for zero, if terminated for other reason. 68 | * Not modified in case of error. Can be NULL, if not needed. 69 | * 70 | * @return Global return code. 71 | */ 72 | extern tlog_grc tlog_rec(struct tlog_errs **perrs, uid_t euid, gid_t egid, 73 | const char *cmd_help, 74 | struct json_object *conf, unsigned int opts, 75 | const char *path, char **argv, 76 | int in_fd, int out_fd, int err_fd, 77 | int *pstatus, int *psignal); 78 | 79 | #endif /* _TLOG_REC_H */ 80 | -------------------------------------------------------------------------------- /include/tlog/rec_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec configuration parsing 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_CONF_H 27 | #define _TLOG_REC_CONF_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /** 34 | * Load tlog-rec configuration from various sources and extract program name. 35 | * 36 | * @param perrs Location for the error stack. Can be NULL. 37 | * @param pcmd_help Location for the dynamically-allocated command-line usage 38 | * help message. Cannot be NULL. 39 | * @param pconf Location for the pointer to the JSON object representing 40 | * the loaded configuration. Cannot be NULL. 41 | * @param argc Tlog-rec argc value. 42 | * @param argv Tlog-rec argv value. Cannot be NULL. 43 | * 44 | * @return Global return code. 45 | */ 46 | extern tlog_grc tlog_rec_conf_load(struct tlog_errs **perrs, 47 | char **pcmd_help, 48 | struct json_object **pconf, 49 | int argc, char **argv); 50 | 51 | /** 52 | * Get the path and the ARGV array of a program to record from a loaded 53 | * tlog-rec configuration JSON object. 54 | * 55 | * @param perrs Location for the error stack. Can be NULL. 56 | * @param conf Tlog-rec configuration JSON object. 57 | * @param ppath Location for the program path pointer, references the 58 | * configuration object. 59 | * @param pargv Location for the NULL-terminated program ARGV array, to be 60 | * freed, both the array and the elements. 61 | * 62 | * @return Global return code. 63 | */ 64 | extern tlog_grc tlog_rec_conf_get_prog(struct tlog_errs **perrs, 65 | struct json_object *conf, 66 | const char **ppath, 67 | char ***pargv); 68 | 69 | #endif /* _TLOG_REC_CONF_H */ 70 | -------------------------------------------------------------------------------- /include/tlog/rec_conf_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec command line configuration management. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_CONF_CMD_H 27 | #define _TLOG_REC_CONF_CMD_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** 35 | * Load tlog-rec configuration from the command line and extract program name. 36 | * 37 | * @param perrs Location for the error stack. Can be NULL. 38 | * @param phelp Location for the dynamically-allocated usage help message. 39 | * Cannot be NULL. 40 | * @param pconf Location for the pointer to the JSON object representing 41 | * the loaded configuration. Cannot be NULL. 42 | * @param argc Tlog-rec argc value. 43 | * @param argv Tlog-rec argv value. Cannot be NULL. 44 | * 45 | * @return Global return code. 46 | */ 47 | extern tlog_grc tlog_rec_conf_cmd_load(struct tlog_errs **perrs, 48 | char **phelp, 49 | struct json_object **pconf, 50 | int argc, char **argv); 51 | 52 | #endif /* _TLOG_REC_CONF_CMD_H */ 53 | -------------------------------------------------------------------------------- /include/tlog/rec_conf_validate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec JSON configuration validation. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_CONF_VALIDATE_H 27 | #define _TLOG_REC_CONF_VALIDATE_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** 35 | * Check tlog-rec JSON configuration: if there are no unkown nodes and the 36 | * present node types and values are valid. 37 | * 38 | * @param perrs Location for the error stack. Can be NULL. 39 | * @param conf The configuration JSON object to check. 40 | * @param origin The configuration origin. 41 | * 42 | * @return Global return code. 43 | */ 44 | extern tlog_grc tlog_rec_conf_validate(struct tlog_errs **perrs, 45 | struct json_object *conf, 46 | enum tlog_conf_origin origin); 47 | 48 | #endif /* _TLOG_REC_CONF_VALIDATE_H */ 49 | -------------------------------------------------------------------------------- /include/tlog/rec_item.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Recorded data item 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016-2017 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_ITEM_H 27 | #define _TLOG_REC_ITEM_H 28 | 29 | #include 30 | 31 | /** Recorded data item */ 32 | enum tlog_rec_item { 33 | TLOG_REC_ITEM_INPUT = 0, 34 | TLOG_REC_ITEM_OUTPUT, 35 | TLOG_REC_ITEM_WINDOW 36 | }; 37 | 38 | /** 39 | * Get recorded data item of a (non-void) packet. 40 | * 41 | * @param pkt The packet to get data item of. Must be non-void. 42 | * 43 | * @return The item packet represents. 44 | */ 45 | extern enum tlog_rec_item tlog_rec_item_from_pkt(const struct tlog_pkt *pkt); 46 | 47 | #endif /* _TLOG_REC_ITEM_H */ 48 | -------------------------------------------------------------------------------- /include/tlog/rec_session_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec-session configuration parsing 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_SESSION_CONF_H 27 | #define _TLOG_REC_SESSION_CONF_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /** 34 | * Load tlog-rec-session configuration from various sources and extract 35 | * program name. 36 | * 37 | * @param perrs Location for the error stack. Can be NULL. 38 | * @param pcmd_help Location for the dynamically-allocated command-line usage 39 | * help message. Cannot be NULL. 40 | * @param pconf Location for the pointer to the JSON object representing 41 | * the loaded configuration. Cannot be NULL. 42 | * @param argc Tlog-rec-session argc value. 43 | * @param argv Tlog-rec-session argv value. Cannot be NULL. 44 | * 45 | * @return Global return code. 46 | */ 47 | extern tlog_grc tlog_rec_session_conf_load(struct tlog_errs **perrs, 48 | char **pcmd_help, 49 | struct json_object **pconf, 50 | int argc, char **argv); 51 | 52 | /** 53 | * Get shell parameters from a loaded tlog-rec-session configuration JSON 54 | * object. 55 | * 56 | * @param perrs Location for the error stack. Can be NULL. 57 | * @param conf Tlog-rec-session configuration JSON object. 58 | * @param ppath Location for the shell path pointer, references the 59 | * configuration object. 60 | * @param pargv Location for the NULL-terminated shell argv array, to be 61 | * freed, both the array and the elements. 62 | * 63 | * @return Global return code. 64 | */ 65 | extern tlog_grc tlog_rec_session_conf_get_shell(struct tlog_errs **perrs, 66 | struct json_object *conf, 67 | const char **ppath, 68 | char ***pargv); 69 | 70 | #endif /* _TLOG_REC_SESSION_CONF_H */ 71 | -------------------------------------------------------------------------------- /include/tlog/rec_session_conf_cmd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec-session command line configuration management. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_SESSION_CONF_CMD_H 27 | #define _TLOG_REC_SESSION_CONF_CMD_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** 35 | * Load tlog-rec-session configuration from the command line and extract 36 | * program name. 37 | * 38 | * @param perrs Location for the error stack. Can be NULL. 39 | * @param phelp Location for the dynamically-allocated usage help message. 40 | * Cannot be NULL. 41 | * @param pconf Location for the pointer to the JSON object representing 42 | * the loaded configuration. Cannot be NULL. 43 | * @param argc Tlog-rec-session argc value. 44 | * @param argv Tlog-rec-session argv value. Cannot be NULL. 45 | * 46 | * @return Global return code. 47 | */ 48 | extern tlog_grc tlog_rec_session_conf_cmd_load(struct tlog_errs **perrs, 49 | char **phelp, 50 | struct json_object **pconf, 51 | int argc, char **argv); 52 | 53 | #endif /* _TLOG_REC_SESSION_CONF_CMD_H */ 54 | -------------------------------------------------------------------------------- /include/tlog/rec_session_conf_validate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Tlog-rec-session JSON configuration validation. 4 | */ 5 | /* 6 | * 7 | * Copyright (C) 2016 Red Hat 8 | * 9 | * This file is part of tlog. 10 | * 11 | * Tlog is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * Tlog is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with tlog; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | #ifndef _TLOG_REC_SESSION_CONF_VALIDATE_H 27 | #define _TLOG_REC_SESSION_CONF_VALIDATE_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /** 35 | * Check tlog-rec-session JSON configuration: if there are no unkown nodes and 36 | * the present node types and values are valid. 37 | * 38 | * @param perrs Location for the error stack. Can be NULL. 39 | * @param conf The configuration JSON object to check. 40 | * @param origin The configuration origin. 41 | * 42 | * @return Global return code. 43 | */ 44 | extern tlog_grc tlog_rec_session_conf_validate(struct tlog_errs **perrs, 45 | struct json_object *conf, 46 | enum tlog_conf_origin origin); 47 | 48 | #endif /* _TLOG_REC_SESSION_CONF_VALIDATE_H */ 49 | -------------------------------------------------------------------------------- /include/tlog/rl_json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Rate-limiting JSON message writer. 4 | * 5 | * Rate-limiting JSON writer passes messages written to it to a "below" 6 | * writer, calculating and limiting their rate and "burstiness". Each written 7 | * message size is compared to the specified rate and burst threshold. If it 8 | * passes, then the message is written to the "below" writer. If it fails the 9 | * check, then, depending on creation parameters, it is either discarded and 10 | * the writer reports success, or the write to the "below" writer is delayed 11 | * until the message conforms to the rate and the burst threshold. 12 | */ 13 | /* 14 | * Copyright (C) 2017 Red Hat 15 | * 16 | * This file is part of tlog. 17 | * 18 | * Tlog is free software; you can redistribute it and/or modify 19 | * it under the terms of the GNU General Public License as published by 20 | * the Free Software Foundation; either version 2 of the License, or 21 | * (at your option) any later version. 22 | * 23 | * Tlog is distributed in the hope that it will be useful, 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | * GNU General Public License for more details. 27 | * 28 | * You should have received a copy of the GNU General Public License 29 | * along with tlog; if not, write to the Free Software 30 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 31 | */ 32 | 33 | #ifndef _TLOG_RL_JSON_WRITER_H 34 | #define _TLOG_RL_JSON_WRITER_H 35 | 36 | #include 37 | #include 38 | 39 | /** Rate-limiting JSON message writer type */ 40 | extern const struct tlog_json_writer_type tlog_rl_json_writer_type; 41 | 42 | /** 43 | * Create an instance of rate-limiting writer. 44 | * 45 | * @param pwriter Location for the pointer to the created writer. 46 | * @param below The "below" writer to write messages to. 47 | * @param below_owned True if the "below" writer should be destroyed when 48 | * the created rate limit writer is destroyed. 49 | * @param clock_id ID of the clock to use to calculate message rate and 50 | * to delay messages. 51 | * @param rate Average message data rate, bytes per second. 52 | * @param burst Maximum message burst size, bytes. 53 | * @param drop False if writing a message exceeding maximum rate 54 | * should be delayed until it fits, true if the message 55 | * should be discarded instead. 56 | * 57 | * @return Global return code. 58 | */ 59 | static inline tlog_grc 60 | tlog_rl_json_writer_create(struct tlog_json_writer **pwriter, 61 | struct tlog_json_writer *below, bool below_owned, 62 | clockid_t clock_id, 63 | size_t rate, size_t burst, bool drop) 64 | { 65 | assert(pwriter != NULL); 66 | assert(tlog_json_writer_is_valid(below)); 67 | return tlog_json_writer_create(pwriter, &tlog_rl_json_writer_type, 68 | below, below_owned, clock_id, 69 | rate, burst, drop); 70 | } 71 | 72 | #endif /* _TLOG_RL_JSON_WRITER_H */ 73 | -------------------------------------------------------------------------------- /include/tlog/session.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Handling of the process audit session. 4 | */ 5 | /* 6 | * Copyright (C) 2017 Red Hat 7 | * 8 | * This file is part of tlog. 9 | * 10 | * Tlog is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * Tlog is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with tlog; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _TLOG_SESSION_H 26 | #define _TLOG_SESSION_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /** 33 | * Get process session ID. 34 | * 35 | * @param pid Location for the retrieved session ID. 36 | * 37 | * @return Global return code. 38 | */ 39 | extern tlog_grc tlog_session_get_id(unsigned int *pid); 40 | 41 | /** 42 | * Lock a session. 43 | * 44 | * @param perrs Location for the error stack. Can be NULL. 45 | * @param id ID of the session to lock 46 | * @param euid EUID to use while creating the lock. 47 | * @param egid EGID to use while creating the lock. 48 | * @param pacquired Location for the flag which is set to true if the session 49 | * lock was acquired , and to false if the session was 50 | * already locked. Not modified in case of error. 51 | * 52 | * @return Global return code. 53 | */ 54 | extern tlog_grc tlog_session_lock(struct tlog_errs **perrs, unsigned int id, 55 | uid_t euid, gid_t egid, bool *pacquired); 56 | 57 | /** 58 | * Unlock a session. 59 | * 60 | * @param perrs Location for the error stack. Can be NULL. 61 | * @param id ID of the session to unlock 62 | * @param euid EUID to use while removing the lock. 63 | * @param egid EGID to use while removing the lock. 64 | * 65 | * @return Global return code. 66 | */ 67 | extern tlog_grc tlog_session_unlock(struct tlog_errs **perrs, unsigned int id, 68 | uid_t euid, gid_t egid); 69 | 70 | #endif /* _TLOG_SESSION_H */ 71 | -------------------------------------------------------------------------------- /include/tlog/source.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Abstract terminal data source. 4 | * 5 | * Abstract terminal data source allows creation and usage of sources of 6 | * specific types. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_SOURCE_H 29 | #define _TLOG_SOURCE_H 30 | 31 | #include 32 | 33 | /** Abstract source */ 34 | struct tlog_source { 35 | const struct tlog_source_type *type; /**< Type */ 36 | #ifndef NDEBUG 37 | struct timespec last_timestamp; /**< Last timestamp */ 38 | #endif 39 | }; 40 | 41 | /** 42 | * Allocate and initialize a source of the specified type, with specified 43 | * arguments. See the particular type description for specific arguments 44 | * required. 45 | * 46 | * @param psource Location for the created source pointer, will be set to 47 | * NULL in case of error. 48 | * @param type The type of source to create. 49 | * @param ... The type-specific source creation arguments. 50 | * 51 | * @return Global return code. 52 | */ 53 | extern tlog_grc tlog_source_create(struct tlog_source **psource, 54 | const struct tlog_source_type *type, 55 | ...); 56 | 57 | /** 58 | * Check if a source is valid. 59 | * 60 | * @param source The source to check. 61 | * 62 | * @return True if the source is valid. 63 | */ 64 | extern bool tlog_source_is_valid(const struct tlog_source *source); 65 | 66 | /** 67 | * Retrieve current opaque location of the source. 68 | * 69 | * @param source The source to retrieve current location from. 70 | * 71 | * @return Opaque location value. 72 | */ 73 | extern size_t tlog_source_loc_get(const struct tlog_source *source); 74 | 75 | /** 76 | * Format opaque location as a string. 77 | * 78 | * @param source The source to format location for. 79 | * @param loc Opaque location value to format. 80 | * 81 | * @return Dynamically-allocated string describing the location, or NULL in 82 | * case of error (see errno). 83 | */ 84 | extern char *tlog_source_loc_fmt(const struct tlog_source *source, 85 | size_t loc); 86 | 87 | /** 88 | * Read a packet from the source. 89 | * 90 | * @param source The source to read from. 91 | * @param pkt The packet to write the received data into, must be void, 92 | * will be void on end-of-stream, or in case of error. 93 | * 94 | * @return Global return code. 95 | */ 96 | extern tlog_grc tlog_source_read(struct tlog_source *source, 97 | struct tlog_pkt *pkt); 98 | 99 | /** 100 | * Destroy (cleanup and free) a log source. 101 | * 102 | * @param source Pointer to the source to destroy, can be NULL. 103 | */ 104 | extern void tlog_source_destroy(struct tlog_source *source); 105 | 106 | #endif /* _TLOG_SOURCE_H */ 107 | -------------------------------------------------------------------------------- /include/tlog/syslog_json_writer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Syslog JSON message writer 4 | * 5 | * An implementation of a JSON log message writer which sends messages to 6 | * syslog. 7 | */ 8 | /* 9 | * Copyright (C) 2015 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_SYSLOG_JSON_WRITER_H 29 | #define _TLOG_SYSLOG_JSON_WRITER_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** 36 | * Syslog message writer type 37 | * 38 | * Creation arguments: 39 | * 40 | * int priority The "priority" argument to pass to syslog(3). 41 | */ 42 | extern const struct tlog_json_writer_type tlog_syslog_json_writer_type; 43 | 44 | /** 45 | * Create an instance of syslog writer. 46 | * 47 | * @param pwriter Location for the created writer pointer, will be set to 48 | * NULL in case of error. 49 | * @param priority The "priority" argument to pass to syslog(3). 50 | * 51 | * @return Global return code. 52 | */ 53 | static inline tlog_grc 54 | tlog_syslog_json_writer_create(struct tlog_json_writer **pwriter, 55 | int priority) 56 | { 57 | assert(pwriter != NULL); 58 | assert(tlog_syslog_priority_is_valid(priority)); 59 | return tlog_json_writer_create(pwriter, &tlog_syslog_json_writer_type, 60 | priority); 61 | } 62 | 63 | #endif /* _TLOG_SYSLOG_JSON_WRITER_H */ 64 | -------------------------------------------------------------------------------- /include/tlog/syslog_misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Miscellaneous syslog-related functions. 4 | * 5 | * A collection of miscellaneous syslog-related function. 6 | */ 7 | /* 8 | * Copyright (C) 2016 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLOG_SYSLOG_MISC_H 28 | #define _TLOG_SYSLOG_MISC_H 29 | 30 | #include 31 | #include 32 | 33 | /** 34 | * Convert syslog facility value to string. 35 | * 36 | * @param facility The facility value to convert. 37 | * 38 | * @return The facility name, or NULL, if the value was invalid. 39 | */ 40 | extern const char *tlog_syslog_facility_to_str(int facility); 41 | 42 | /** 43 | * Check if a syslog facility value is valid. 44 | * 45 | * @param facility The facility value to check. 46 | * 47 | * @return True if the facility value is valid, false otherwise. 48 | */ 49 | static inline bool tlog_syslog_facility_is_valid(int facility) 50 | { 51 | return tlog_syslog_facility_to_str(facility) != NULL; 52 | } 53 | 54 | /** 55 | * Convert syslog facility string to integer value. 56 | * 57 | * @param str The string to convert. 58 | * 59 | * @return The facility value, which can be supplied to openlog(3) and 60 | * syslog(3), or a negative number, if the string was unrecognized. 61 | */ 62 | extern int tlog_syslog_facility_from_str(const char *str); 63 | 64 | /** 65 | * Convert syslog priority value to string. 66 | * 67 | * @param priority The priority value to convert. 68 | * 69 | * @return The priority name, or NULL, if the value was invalid. 70 | */ 71 | extern const char *tlog_syslog_priority_to_str(int priority); 72 | 73 | /** 74 | * Check if a syslog priority value is valid. 75 | * 76 | * @param priority The priority value to check. 77 | * 78 | * @return True if the priority value is valid, false otherwise. 79 | */ 80 | static inline bool tlog_syslog_priority_is_valid(int priority) 81 | { 82 | return tlog_syslog_priority_to_str(priority) != NULL; 83 | } 84 | 85 | /** 86 | * Convert syslog priority string to integer value. 87 | * 88 | * @param str The string to convert. 89 | * 90 | * @return The priority value, which can be supplied to openlog(3) and 91 | * syslog(3), or a negative number, if the string was unrecognized. 92 | */ 93 | extern int tlog_syslog_priority_from_str(const char *str); 94 | 95 | #endif /* _TLOG_SYSLOG_MISC_H */ 96 | -------------------------------------------------------------------------------- /include/tlog/timestr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Timestamp string 4 | * 5 | * Timestamp string has format HH:MM:SS.sss, where any part except SS can 6 | * omitted. 7 | */ 8 | /* 9 | * Copyright (C) 2017 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef _TLOG_TIMESTR_H 29 | #define _TLOG_TIMESTR_H 30 | 31 | #include 32 | #include 33 | 34 | /** The timestamp string parser state */ 35 | struct tlog_timestr_parser { 36 | /** List of timestamp components being received */ 37 | long comp_list[3]; 38 | /** Number of timestamp components received so far */ 39 | size_t comp_num; 40 | /** True if received a decimal point */ 41 | bool got_point; 42 | /** Length of the fraction part */ 43 | size_t frac_len; 44 | /** Value of the fraction (multiplied by 10^frac_len) */ 45 | long frac_val; 46 | }; 47 | 48 | /** Timestamp string parser initializer */ 49 | #define TLOG_TIMESTR_PARSER_INIT \ 50 | (struct tlog_timestr_parser){.comp_num = 0, .got_point = false} 51 | 52 | /** 53 | * Reset a timestamp string parser. 54 | * Must be called before parsing a new string. 55 | * 56 | * @param parser The timestamp string parser to reset. 57 | */ 58 | extern void tlog_timestr_parser_reset(struct tlog_timestr_parser *parser); 59 | 60 | /** 61 | * Check if a timestamp string parser is valid. 62 | * 63 | * @param parser The parser to check. 64 | * 65 | * @return True if the parser is valid, false otherwise. 66 | */ 67 | extern bool tlog_timestr_parser_is_valid( 68 | const struct tlog_timestr_parser *parser); 69 | 70 | /** 71 | * Feed a character into a timestamp string parser. 72 | * 73 | * @param parser The timestamp string parser to feed the character into. 74 | * @param c The character to feed into the parser. 75 | * 76 | * @return True if the character was accepted, false otherwise. 77 | */ 78 | extern bool tlog_timestr_parser_feed(struct tlog_timestr_parser *parser, 79 | char c); 80 | 81 | /** 82 | * Yield a timespec value from a timestamp string parser state. 83 | * 84 | * @param parser The timestamp string parser to yield the timespec from. 85 | * @param pts Location for the yielded timespec value. 86 | * 87 | * @return True if the parser state could be represented as a timespec and pts 88 | * location was updated. False if an overflow occurred, and pts 89 | * location wasn't updated. 90 | */ 91 | extern bool tlog_timestr_parser_yield(const struct tlog_timestr_parser *parser, 92 | struct timespec *pts); 93 | 94 | /** 95 | * Convert a timestamp string to a timespec, ignoring any leading or trailing 96 | * whitespace. 97 | * 98 | * @param timestr The timestamp string to convert. 99 | * @param pts Location for the resulting timespec value. 100 | * 101 | * @return True if converted succesfully and pts location was updated, 102 | * false if the timestamp string was invalid and pts location wasn't 103 | * updated. 104 | */ 105 | extern bool tlog_timestr_to_timespec(const char *timestr, 106 | struct timespec *pts); 107 | 108 | #endif /* _TLOG_TIMESTR_H */ 109 | -------------------------------------------------------------------------------- /include/tlog/trx.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Transaction support. 4 | * 5 | * Transactions are used to keep objects consistent on failures in the middle 6 | * of operations. So e.g. if a function fails in the middle, the object 7 | * returns to the previous state. 8 | * 9 | * The rule of thumb is: if your function can abort in the middle of 10 | * processing and doesn't roll back (e.g. it's difficult to implement), then 11 | * it needs to use transactions. 12 | * 13 | * Each such function needs to accept a transaction state argument 14 | * (tlog_trx_state), define a transaction frame, which is a list of 15 | * participating objects, begin transaction before processing, commit it on 16 | * success, or abort on failure. Any transaction-aware functions called from 17 | * such function need to be passed the transaction state. 18 | * 19 | * Transaction state holds the transaction nesting level and transaction stack 20 | * depth. When transaction is started transaction state stack depth is 21 | * increased. The transaction data is backed up/restored/discarded only on 22 | * stack depth zero. 23 | */ 24 | /* 25 | * Copyright (C) 2015 Red Hat 26 | * 27 | * This file is part of tlog. 28 | * 29 | * Tlog is free software; you can redistribute it and/or modify 30 | * it under the terms of the GNU General Public License as published by 31 | * the Free Software Foundation; either version 2 of the License, or 32 | * (at your option) any later version. 33 | * 34 | * Tlog is distributed in the hope that it will be useful, 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | * GNU General Public License for more details. 38 | * 39 | * You should have received a copy of the GNU General Public License 40 | * along with tlog; if not, write to the Free Software 41 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 42 | */ 43 | 44 | #ifndef _TLOG_TRX_H 45 | #define _TLOG_TRX_H 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #endif /* _TLOG_TRX_H */ 53 | -------------------------------------------------------------------------------- /include/tlog/trx_act.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Transaction data actions. 4 | * 5 | * Each transaction-aware object is supposed to define a function which 6 | * handles object data backup, restore, and discarding. At the beginning of a 7 | * transaction this function is called to backup object data that can change 8 | * within the transaction. When transaction is aborted this function is called 9 | * to restore that data. When transaction is committed, this function is 10 | * called to discard, or invalidate the backup storage. The way the data is 11 | * backed up is up to that function, however it should have separate storage 12 | * for each separate transaction level. 13 | */ 14 | /* 15 | * Copyright (C) 2015 Red Hat 16 | * 17 | * This file is part of tlog. 18 | * 19 | * Tlog is free software; you can redistribute it and/or modify 20 | * it under the terms of the GNU General Public License as published by 21 | * the Free Software Foundation; either version 2 of the License, or 22 | * (at your option) any later version. 23 | * 24 | * Tlog is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | * GNU General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU General Public License 30 | * along with tlog; if not, write to the Free Software 31 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 32 | */ 33 | 34 | #ifndef _TLOG_TRX_ACT_H 35 | #define _TLOG_TRX_ACT_H 36 | 37 | #include 38 | 39 | /** Transaction data action type */ 40 | enum tlog_trx_act_type { 41 | TLOG_TRX_ACT_TYPE_BACKUP, 42 | TLOG_TRX_ACT_TYPE_RESTORE, 43 | TLOG_TRX_ACT_TYPE_DISCARD 44 | }; 45 | 46 | /** 47 | * Transaction data action function prototype. 48 | * 49 | * @param level Transaction nesting level. 50 | * @param act_type Action type. 51 | * @param abstract_object The abstract object to act on. 52 | */ 53 | typedef void (*tlog_trx_act_fn)(tlog_trx_level level, 54 | enum tlog_trx_act_type act_type, 55 | void *abstract_object); 56 | 57 | #endif /* _TLOG_TRX_ACT_H */ 58 | -------------------------------------------------------------------------------- /include/tlog/trx_iface.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Object's transaction management interface. 4 | * 5 | * This structure defines the object's transaction management interface. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLOG_TRX_IFACE_H 28 | #define _TLOG_TRX_IFACE_H 29 | 30 | #include 31 | 32 | /** An object's transaction management interface */ 33 | struct tlog_trx_iface { 34 | tlog_trx_act_fn act; /**< Transaction data transfer function */ 35 | }; 36 | 37 | #endif /* _TLOG_TRX_IFACE_H */ 38 | -------------------------------------------------------------------------------- /include/tlog/trx_level.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Transaction nesting level. 4 | * 5 | * Levels are used to distinguish nested transactions and let each have its 6 | * own commit/abort boundaries and storage. The top transaction level is 7 | * TLOG_TRX_LEVEL_MIN and the deepest possible nesting level is 8 | * TLOG_TRX_LEVEL_MAX. 9 | */ 10 | /* 11 | * Copyright (C) 2015 Red Hat 12 | * 13 | * This file is part of tlog. 14 | * 15 | * Tlog is free software; you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation; either version 2 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * Tlog is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with tlog; if not, write to the Free Software 27 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | */ 29 | 30 | #ifndef _TLOG_TRX_LEVEL_H 31 | #define _TLOG_TRX_LEVEL_H 32 | 33 | #include 34 | 35 | /** Transaction nesting level */ 36 | typedef unsigned int tlog_trx_level; 37 | 38 | /** Minimum transaction nesting level */ 39 | #define TLOG_TRX_LEVEL_MIN 0 40 | 41 | /** Maximum transaction nesting level */ 42 | #define TLOG_TRX_LEVEL_MAX 3 43 | 44 | /** Number of available transaction nesting levels */ 45 | #define TLOG_TRX_LEVEL_NUM (TLOG_TRX_LEVEL_MAX + 1) 46 | 47 | /** Number of bits required to store a transaction nesting level */ 48 | #define TLOG_TRX_LEVEL_BITS 2 49 | 50 | #endif /* _TLOG_TRX_LEVEL_H */ 51 | -------------------------------------------------------------------------------- /include/tlog/trx_state.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Transaction state. 4 | * 5 | * Transaction state keeps track of transaction level and stack depth. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLOG_TRX_STATE_H 28 | #define _TLOG_TRX_STATE_H 29 | 30 | #include 31 | #include 32 | 33 | /** Transaction state (level and frame) */ 34 | typedef unsigned int tlog_trx_state; 35 | 36 | /** LSB of transaction level in a transaction state */ 37 | #define TLOG_TRX_STATE_LEVEL_LSB \ 38 | ((sizeof(tlog_trx_state) * 8) - TLOG_TRX_LEVEL_BITS) 39 | 40 | /** Mask of transaction level in a transaction state */ 41 | #define TLOG_TRX_STATE_LEVEL_MASK \ 42 | (TLOG_TRX_LEVEL_MAX << TLOG_TRX_STATE_LEVEL_LSB) 43 | 44 | /** Mask of transaction frame in a transaction state */ 45 | #define TLOG_TRX_STATE_DEPTH_MASK \ 46 | (~TLOG_TRX_STATE_LEVEL_MASK) 47 | 48 | /** Get transaction level from a transaction state */ 49 | #define TLOG_TRX_STATE_GET_LEVEL(_trx) \ 50 | ((_trx) >> TLOG_TRX_STATE_LEVEL_LSB) 51 | 52 | /** Get transaction stack depth from a transaction state */ 53 | #define TLOG_TRX_STATE_GET_DEPTH(_trx) \ 54 | ((_trx) & TLOG_TRX_STATE_DEPTH_MASK) 55 | 56 | /** Maximum stack depth which can be stored in a transaction state */ 57 | #define TLOG_TRX_STATE_MAX_DEPTH \ 58 | ((~(tlog_trx_state)0) >> TLOG_TRX_LEVEL_BITS) 59 | 60 | /** Root transaction state initializer */ 61 | #define TLOG_TRX_STATE_ROOT 0 62 | 63 | /** Sub-transaction state initializer */ 64 | #define TLOG_TRX_STATE_SUB(_parent) \ 65 | ({ \ 66 | tlog_trx_state _level = TLOG_TRX_STATE_GET_LEVEL(_parent) + 1; \ 67 | assert(_level <= TLOG_TRX_LEVEL_MAX); \ 68 | (_level << TLOG_TRX_STATE_LEVEL_LSB); \ 69 | }) 70 | 71 | #endif /* _TLOG_TRX_STATE_H */ 72 | -------------------------------------------------------------------------------- /include/tlog/tty_sink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief TTY terminal data sink. 4 | * 5 | * TTY terminal data sink accepts packets and writes them to up to three file 6 | * descriptors: for input, output and window size changes. Any of them can be 7 | * omitted. Timestamps are ignored by the sink. 8 | */ 9 | /* 10 | * Copyright (C) 2016 Red Hat 11 | * 12 | * This file is part of tlog. 13 | * 14 | * Tlog is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * Tlog is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with tlog; if not, write to the Free Software 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 | */ 28 | 29 | #ifndef _TLOG_TTY_SINK_H 30 | #define _TLOG_TTY_SINK_H 31 | 32 | #include 33 | 34 | /** TTY sink type */ 35 | extern const struct tlog_sink_type tlog_tty_sink_type; 36 | 37 | /** 38 | * Create (allocate and initialize) a log sink. 39 | * 40 | * @param psink Location for created sink pointer, set to NULL 41 | * in case of error. 42 | * @param in_fd File descriptor to write terminal input to, 43 | * or negative number if that's not needed. 44 | * @param out_fd File descriptor to write terminal output to, 45 | * or negative number if that's not needed. 46 | * @param win_fd File descriptor to write window sizes to, 47 | * or negative number if that's not needed. 48 | * 49 | * @return Global return code. 50 | */ 51 | static inline tlog_grc 52 | tlog_tty_sink_create(struct tlog_sink **psink, 53 | int in_fd, int out_fd, int win_fd) 54 | { 55 | assert(psink != NULL); 56 | return tlog_sink_create(psink, &tlog_tty_sink_type, 57 | in_fd, out_fd, win_fd); 58 | } 59 | 60 | #endif /* _TLOG_TTY_SINK_H */ 61 | -------------------------------------------------------------------------------- /include/tlog/tty_source.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief TTY terminal data source. 4 | * 5 | * TTY terminal data source provides an interface to read terminal data 6 | * packets from two file descriptors (bound to TTYs or files), optionally 7 | * aided by a SIGWINCH handler. 8 | */ 9 | /* 10 | * Copyright (C) 2016 Red Hat 11 | * 12 | * This file is part of tlog. 13 | * 14 | * Tlog is free software; you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation; either version 2 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * Tlog is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | * GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with tlog; if not, write to the Free Software 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 | */ 28 | 29 | #ifndef _TLOG_TTY_SOURCE_H 30 | #define _TLOG_TTY_SOURCE_H 31 | 32 | #include 33 | 34 | /** Minimum size of the I/O buffer */ 35 | #define TLOG_TTY_SOURCE_IO_SIZE_MIN 32 36 | 37 | /** TTY source type */ 38 | extern const struct tlog_source_type tlog_tty_source_type; 39 | 40 | /** 41 | * Create (allocate and initialize) a TTY source. 42 | * 43 | * @param psource Location for created source pointer, set to NULL 44 | * in case of error. 45 | * @param in_fd File descriptor to read terminal input from, 46 | * or negative number if that's not needed. 47 | * @param out_fd File descriptor to read terminal output from, 48 | * or negative number if that's not needed. 49 | * @param win_fd File descriptor to read window sizes from, 50 | * or negative number if that's not needed. 51 | * @param io_size Size of I/O data buffer used in packets. 52 | * @param clock_id Clock to use for timestamps. 53 | * 54 | * @return Global return code. 55 | */ 56 | static inline tlog_grc 57 | tlog_tty_source_create(struct tlog_source **psource, 58 | int in_fd, int out_fd, int win_fd, 59 | size_t io_size, clockid_t clock_id) 60 | { 61 | assert(psource != NULL); 62 | assert(io_size >= TLOG_TTY_SOURCE_IO_SIZE_MIN); 63 | return tlog_source_create(psource, &tlog_tty_source_type, 64 | in_fd, out_fd, win_fd, io_size, 65 | clock_id); 66 | } 67 | 68 | #endif /* _TLOG_TTY_SOURCE_H */ 69 | -------------------------------------------------------------------------------- /include/tltest/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | noinst_HEADERS = \ 23 | json_sink.h \ 24 | json_source.h \ 25 | json_stream_enc.h \ 26 | misc.h 27 | -------------------------------------------------------------------------------- /include/tltest/json_sink.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Sink test functions. 4 | * 5 | * Functions and types specific to sink testing. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLTEST_JSON_SINK_H 28 | #define _TLTEST_JSON_SINK_H 29 | 30 | #include 31 | 32 | enum tltest_json_sink_op_type { 33 | TLTEST_JSON_SINK_OP_TYPE_NONE, 34 | TLTEST_JSON_SINK_OP_TYPE_WRITE, 35 | TLTEST_JSON_SINK_OP_TYPE_FLUSH, 36 | TLTEST_JSON_SINK_OP_TYPE_CUT, 37 | TLTEST_JSON_SINK_OP_TYPE_NUM 38 | }; 39 | 40 | extern const char* tltest_json_sink_op_type_to_str( 41 | enum tltest_json_sink_op_type type); 42 | 43 | struct tltest_json_sink_op { 44 | enum tltest_json_sink_op_type type; 45 | union { 46 | struct tlog_pkt write; 47 | } data; 48 | }; 49 | 50 | #define TLTEST_JSON_SINK_OP_NONE \ 51 | ((struct tltest_json_sink_op) \ 52 | {.type = TLTEST_JSON_SINK_OP_TYPE_NONE}) 53 | 54 | #define TLTEST_JSON_SINK_OP_WRITE(_pkt) \ 55 | ((struct tltest_json_sink_op){ \ 56 | .type = TLTEST_JSON_SINK_OP_TYPE_WRITE, \ 57 | .data.write = _pkt \ 58 | }) 59 | 60 | #define TLTEST_JSON_SINK_OP_FLUSH \ 61 | ((struct tltest_json_sink_op) \ 62 | {.type = TLTEST_JSON_SINK_OP_TYPE_FLUSH}) 63 | 64 | #define TLTEST_JSON_SINK_OP_CUT \ 65 | ((struct tltest_json_sink_op) \ 66 | {.type = TLTEST_JSON_SINK_OP_TYPE_CUT}) 67 | 68 | struct tltest_json_sink_input { 69 | const char *hostname; 70 | const char *recording; 71 | const char *username; 72 | const char *terminal; 73 | unsigned int session_id; 74 | size_t chunk_size; 75 | struct tltest_json_sink_op op_list[16]; 76 | }; 77 | 78 | extern bool tltest_json_sink_run( 79 | const char *name, 80 | const struct tltest_json_sink_input *input, 81 | char **pres_output_buf, 82 | size_t *pres_output_len); 83 | 84 | struct tltest_json_sink { 85 | struct tltest_json_sink_input input; 86 | const char *output; 87 | }; 88 | 89 | extern bool tltest_json_sink(const char *file, int line, const char *name, 90 | const struct tltest_json_sink test); 91 | 92 | #endif /* _TLTEST_JSON_SINK_H */ 93 | -------------------------------------------------------------------------------- /include/tltest/json_source.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Source test functions. 4 | * 5 | * Functions and types specific to sink testing. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLTEST_JSON_SOURCE_H 28 | #define _TLTEST_JSON_SOURCE_H 29 | 30 | #include 31 | 32 | enum tltest_json_source_op_type { 33 | TLTEST_JSON_SOURCE_OP_TYPE_NONE, 34 | TLTEST_JSON_SOURCE_OP_TYPE_READ, 35 | TLTEST_JSON_SOURCE_OP_TYPE_LOC_GET, 36 | TLTEST_JSON_SOURCE_OP_TYPE_NUM 37 | }; 38 | 39 | extern const char *tltest_json_source_op_type_to_str( 40 | enum tltest_json_source_op_type type); 41 | 42 | struct tltest_json_source_op_data_loc_get { 43 | size_t exp_loc; 44 | }; 45 | 46 | struct tltest_json_source_op_data_read { 47 | int exp_grc; 48 | struct tlog_pkt exp_pkt; 49 | }; 50 | 51 | struct tltest_json_source_op { 52 | enum tltest_json_source_op_type type; 53 | union { 54 | struct tltest_json_source_op_data_loc_get loc_get; 55 | struct tltest_json_source_op_data_read read; 56 | } data; 57 | }; 58 | 59 | #define TLTEST_JSON_SOURCE_OP_NONE \ 60 | ((struct tltest_json_source_op){ \ 61 | .type = TLTEST_JSON_SOURCE_OP_TYPE_NONE \ 62 | }) 63 | 64 | #define TLTEST_JSON_SOURCE_OP_LOC_GET(_exp_loc) \ 65 | ((struct tltest_json_source_op){ \ 66 | .type = TLTEST_JSON_SOURCE_OP_TYPE_LOC_GET, \ 67 | .data = {.loc_get = {.exp_loc = _exp_loc}} \ 68 | }) 69 | 70 | #define TLTEST_JSON_SOURCE_OP_READ(_exp_grc, _exp_pkt) \ 71 | ((struct tltest_json_source_op){ \ 72 | .type = TLTEST_JSON_SOURCE_OP_TYPE_READ, \ 73 | .data = {.read = {.exp_grc = _exp_grc, .exp_pkt = _exp_pkt}} \ 74 | }) 75 | 76 | struct tltest_json_source_output { 77 | const char *hostname; 78 | const char *username; 79 | const char *terminal; 80 | unsigned int session_id; 81 | size_t io_size; 82 | struct tltest_json_source_op op_list[16]; 83 | }; 84 | 85 | extern bool tltest_json_source_run( 86 | const char *name, 87 | const char *input_buf, 88 | size_t input_len, 89 | const struct tltest_json_source_output *output); 90 | 91 | struct tltest_json_source { 92 | const char *input; 93 | struct tltest_json_source_output output; 94 | }; 95 | 96 | extern bool tltest_json_source(const char *file, int line, const char *name, 97 | const struct tltest_json_source test); 98 | 99 | #endif /* _TLTEST_JSON_SOURCE_H */ 100 | -------------------------------------------------------------------------------- /include/tltest/json_stream_enc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief tlog_json_stream_enc_* function test module. 4 | * 5 | * A module for testing tlog_json_stream_enc_txt/bin functions. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLTEST_JSON_STREAM_ENC_H 28 | #define _TLTEST_JSON_STREAM_ENC_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define TLTEST_JSON_STREAM_ENC_BUF_SIZE 32 35 | 36 | typedef bool (*tltest_json_stream_enc_func)( 37 | tlog_trx_state trx, 38 | struct tlog_json_dispatcher *dispatcher, 39 | uint8_t *obuf, size_t *polen, 40 | size_t *pirun, size_t *pidig, 41 | const uint8_t *ibuf, size_t ilen); 42 | 43 | struct tltest_json_stream_enc { 44 | tltest_json_stream_enc_func func; 45 | const uint8_t ibuf_in[TLTEST_JSON_STREAM_ENC_BUF_SIZE]; 46 | size_t ilen_in; 47 | const uint8_t obuf_out[TLTEST_JSON_STREAM_ENC_BUF_SIZE]; 48 | size_t orem_in; 49 | size_t orem_out; 50 | size_t olen_in; 51 | size_t olen_out; 52 | size_t irun_in; 53 | size_t irun_out; 54 | size_t idig_in; 55 | size_t idig_out; 56 | bool fit_out; /**< Expected func return value */ 57 | }; 58 | 59 | /** 60 | * Run a tlog_json_stream_enc_* function test. 61 | * 62 | * @param n Test name. 63 | * @param t Test structure. 64 | * 65 | * @return True if test passed, false otherwise. 66 | */ 67 | extern bool tltest_json_stream_enc( 68 | const char *file, 69 | int line, 70 | const char *n, 71 | const struct tltest_json_stream_enc t); 72 | 73 | #endif /* _TLTEST_JSON_STREAM_ENC_H */ 74 | -------------------------------------------------------------------------------- /include/tltest/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Miscellaneous test functions. 4 | * 5 | * Miscellaneous test-related functions, which don't deserve their own module. 6 | */ 7 | /* 8 | * Copyright (C) 2015 Red Hat 9 | * 10 | * This file is part of tlog. 11 | * 12 | * Tlog is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * Tlog is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with tlog; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef _TLTEST_MISC_H 28 | #define _TLTEST_MISC_H 29 | 30 | #include 31 | #include 32 | 33 | /** 34 | * Output a description of differences between two buffers to an stdio stream. 35 | * 36 | * @param stream The stdio stream to output to. 37 | * @param res_buf "Result" buffer. 38 | * @param res_len "Result" length. 39 | * @param exp_buf "Expected" buffer. 40 | * @param exp_len "Expected" length. 41 | */ 42 | extern void tltest_diff(FILE *stream, 43 | const uint8_t *res_buf, size_t res_len, 44 | const uint8_t *exp_buf, size_t exp_len); 45 | 46 | #endif /* _TLTEST_MISC_H */ 47 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *_conf_cmd.c 2 | *_conf_validate.c 3 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | SUBDIRS = tlog tltest 23 | -------------------------------------------------------------------------------- /lib/tlitest/test_tlog_play_remote.py: -------------------------------------------------------------------------------- 1 | """ tlog remote recording tests """ 2 | import os 3 | 4 | import pexpect 5 | 6 | import pytest 7 | 8 | 9 | class TestTlogPlayRemote: 10 | """ Test tlog-play for remotely recorded journal sessions """ 11 | bootid = '6211b985bd1e49908726bd24cd514099' 12 | cases = {'good': '600-b0b9', 13 | 'bad-timing': '72d-df52', 14 | 'missing-entry': '786-11109'} 15 | 16 | @classmethod 17 | def setup_class(cls): 18 | """ 19 | Import remotely recorded sessions for test cases to the 20 | journal 21 | """ 22 | tpath = os.path.dirname(os.path.abspath(__file__)) 23 | shell = pexpect.spawn('/bin/bash', cwd=os.getcwd()) 24 | remdir = '/var/log/journal/remote' 25 | imported = '{}/test-journals-imported'.format(remdir) 26 | jremote = '/usr/lib/systemd/systemd-journal-remote' 27 | finish = 'Finishing after writing' 28 | if os.path.isfile(imported): 29 | return 30 | if not os.path.isdir(remdir): 31 | os.makedirs(remdir, mode=755, exist_ok=True) 32 | # for jtype in cls.cases.keys(): 33 | for jtype, _ in cls.cases.items(): 34 | jfile = '{}/journal-{}.txt'.format(tpath, jtype) 35 | jremfile = '{}/remote-{}.journal'.format(remdir, jtype) 36 | cmd = 'cat {}|{} -o {} -'.format(jfile, jremote, jremfile) 37 | shell.sendline(cmd) 38 | out = shell.expect([pexpect.TIMEOUT, finish], timeout=10) 39 | if out == 0: 40 | print('\nTestTlogPlayRemote setup TIMEOUT.') 41 | print('\nThere was a problem importing journals') 42 | assert out == 1 43 | open(imported, 'a').close() 44 | shell.close() 45 | 46 | @pytest.mark.tier1 47 | def test_play_remote_good_session(self): 48 | """ 49 | Check tlog-play can playback remote session imported to 50 | journal 51 | """ 52 | pattern = 'logout' 53 | shell = pexpect.spawn('/bin/bash') 54 | tlog_rec = 'TLOG_REC={}-{}'.format(self.bootid, 55 | self.cases['good']) 56 | cmd = 'tlog-play -r journal -M {} -g end'.format(tlog_rec) 57 | shell.sendline(cmd) 58 | out = shell.expect([pexpect.TIMEOUT, pattern], timeout=10) 59 | if out == 0: 60 | print('test_play_remote_good_session TIMEOUT') 61 | assert out == 1 62 | shell.close() 63 | 64 | def test_play_remote_bad_timing(self): 65 | """ 66 | Check tlog-play fails on remote session with invalid timing 67 | """ 68 | pattern = 'invalid "timing"' 69 | shell = pexpect.spawn('/bin/bash') 70 | tlog_rec = 'TLOG_REC={}-{}'.format(self.bootid, 71 | self.cases['bad-timing']) 72 | cmd = 'tlog-play -r journal -M {} -g end'.format(tlog_rec) 73 | shell.sendline(cmd) 74 | out = shell.expect([pexpect.TIMEOUT, pattern], timeout=10) 75 | if out == 0: 76 | print('test_play_remote_bad_timing TIMEOUT') 77 | assert out == 1 78 | shell.close() 79 | 80 | def test_play_remote_missing_entry(self): 81 | """ 82 | Check tlog-play fails on remote session missing message 83 | """ 84 | pattern = 'ID is out of order' 85 | shell = pexpect.spawn('/bin/bash') 86 | tlog_rec = 'TLOG_REC={}-{}'.format(self.bootid, 87 | self.cases['missing-entry']) 88 | cmd = 'tlog-play -r journal -M {} -g end'.format(tlog_rec) 89 | shell.sendline(cmd) 90 | out = shell.expect([pexpect.TIMEOUT, pattern], timeout=10) 91 | if out == 0: 92 | print('test_play_remote_missing_entry TIMEOUT') 93 | assert out == 1 94 | shell.close() 95 | -------------------------------------------------------------------------------- /lib/tlog/delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Supported time span (delay) constants. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | 25 | /* NOTE: Not using the macro from the header to workaround a gcc 4.8 bug */ 26 | const struct timespec tlog_delay_min_timespec = { 27 | .tv_sec = TLOG_DELAY_MIN_TIMESPEC_SEC, 28 | .tv_nsec = TLOG_DELAY_MIN_TIMESPEC_NSEC 29 | }; 30 | /* NOTE: Not using the macro from the header to workaround a gcc 4.8 bug */ 31 | const struct timespec tlog_delay_max_timespec = { 32 | .tv_sec = TLOG_DELAY_MAX_TIMESPEC_SEC, 33 | .tv_nsec = TLOG_DELAY_MAX_TIMESPEC_NSEC 34 | }; 35 | -------------------------------------------------------------------------------- /lib/tlog/fd_json_writer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File descriptor JSON log message writer. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | /** FD writer data */ 29 | struct tlog_fd_json_writer { 30 | struct tlog_json_writer writer; /**< Abstract writer instance */ 31 | int fd; /**< FD to write to */ 32 | bool fd_owned; /**< True if FD is owned */ 33 | }; 34 | 35 | static tlog_grc 36 | tlog_fd_json_writer_init(struct tlog_json_writer *writer, va_list ap) 37 | { 38 | struct tlog_fd_json_writer *fd_json_writer = 39 | (struct tlog_fd_json_writer*)writer; 40 | fd_json_writer->fd = va_arg(ap, int); 41 | fd_json_writer->fd_owned = (bool)va_arg(ap, int); 42 | return TLOG_RC_OK; 43 | } 44 | 45 | static void 46 | tlog_fd_json_writer_cleanup(struct tlog_json_writer *writer) 47 | { 48 | struct tlog_fd_json_writer *fd_json_writer = 49 | (struct tlog_fd_json_writer*)writer; 50 | if (fd_json_writer->fd_owned) { 51 | close(fd_json_writer->fd); 52 | fd_json_writer->fd_owned = false; 53 | } 54 | } 55 | 56 | static tlog_grc 57 | tlog_fd_json_writer_write(struct tlog_json_writer *writer, 58 | size_t id, const uint8_t *buf, size_t len) 59 | { 60 | struct tlog_fd_json_writer *fd_json_writer = 61 | (struct tlog_fd_json_writer*)writer; 62 | ssize_t rc; 63 | const uint8_t *p = buf; 64 | 65 | (void)id; 66 | 67 | while (true) { 68 | rc = write(fd_json_writer->fd, p, len); 69 | if (rc < 0) { 70 | /* If interrupted after writing something */ 71 | if (errno == EINTR && p > buf) { 72 | continue; 73 | } else { 74 | return TLOG_GRC_ERRNO; 75 | } 76 | } 77 | if ((size_t)rc == len) { 78 | return TLOG_RC_OK; 79 | } 80 | p += rc; 81 | len -= (size_t)rc; 82 | } 83 | } 84 | 85 | const struct tlog_json_writer_type tlog_fd_json_writer_type = { 86 | .size = sizeof(struct tlog_fd_json_writer), 87 | .init = tlog_fd_json_writer_init, 88 | .write = tlog_fd_json_writer_write, 89 | .cleanup = tlog_fd_json_writer_cleanup, 90 | }; 91 | -------------------------------------------------------------------------------- /lib/tlog/journal_misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Miscellaneous systemd journal-related functions. 3 | * 4 | * Copyright (C) 2017 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | bool 28 | tlog_journal_match_is_valid(const void *data, size_t size) 29 | { 30 | const char *str = data; 31 | size_t i; 32 | char c; 33 | 34 | if (data == NULL) { 35 | return false; 36 | } 37 | 38 | for (i = 0; size == 0 || i < size; i++) { 39 | c = str[i]; 40 | if (c == '\0' && size == 0) { 41 | return false; 42 | } if (c == '=') { 43 | return (i > 0); 44 | } else if (c == '_') { 45 | if (i == 1 && str[0] == '_') { 46 | return false; 47 | } 48 | } else if ((c < 'A' || c > 'Z') && (c < '0' || c > '9')) { 49 | return false; 50 | } 51 | } 52 | 53 | return true; 54 | } 55 | 56 | bool 57 | tlog_journal_match_sym_is_valid(const char *match_sym) 58 | { 59 | return match_sym != NULL && 60 | (tlog_journal_match_is_valid(match_sym, 0) || 61 | strcasecmp(match_sym, "OR") == 0 || 62 | strcasecmp(match_sym, "AND") == 0); 63 | } 64 | 65 | int 66 | tlog_journal_add_match_sym(sd_journal *j, const char *match_sym) 67 | { 68 | assert(j != NULL); 69 | assert(tlog_journal_match_sym_is_valid(match_sym)); 70 | 71 | if (strcasecmp(match_sym, "AND") == 0) { 72 | return sd_journal_add_conjunction(j); 73 | } else if (strcasecmp(match_sym, "OR") == 0) { 74 | return sd_journal_add_disjunction(j); 75 | } else { 76 | return sd_journal_add_match(j, match_sym, 0); 77 | } 78 | } 79 | 80 | bool 81 | tlog_journal_match_sym_list_is_valid(const char * const *match_sym_list) 82 | { 83 | const char * const *p; 84 | 85 | if (match_sym_list == NULL) { 86 | return false; 87 | } 88 | 89 | for (p = match_sym_list; *p != NULL; p++) { 90 | if (!tlog_journal_match_sym_is_valid(*p)) { 91 | return false; 92 | } 93 | } 94 | 95 | return true; 96 | } 97 | 98 | int 99 | tlog_journal_add_match_sym_list(sd_journal *j, 100 | const char * const *match_sym_list) 101 | { 102 | const char * const *p; 103 | int sd_rc; 104 | 105 | assert(j != NULL); 106 | assert(match_sym_list == NULL || 107 | tlog_journal_match_sym_list_is_valid(match_sym_list)); 108 | 109 | if (match_sym_list != NULL) { 110 | for (p = match_sym_list; *p != NULL; p++) { 111 | sd_rc = tlog_journal_add_match_sym(j, *p); 112 | if (sd_rc < 0) { 113 | return sd_rc; 114 | } 115 | } 116 | } 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /lib/tlog/json_dispatcher.c: -------------------------------------------------------------------------------- 1 | /* 2 | * JSON encoder dispatcher interface. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | 25 | static 26 | TLOG_TRX_BASIC_ACT_SIG(tlog_json_dispatcher) 27 | { 28 | struct tlog_json_dispatcher *dispatcher = \ 29 | (struct tlog_json_dispatcher *)abstract_object; 30 | dispatcher->container_trx_iface->act(level, act_type, 31 | dispatcher->container); 32 | } 33 | 34 | void 35 | tlog_json_dispatcher_init(struct tlog_json_dispatcher *dispatcher, 36 | tlog_json_dispatcher_advance_fn advance, 37 | tlog_json_dispatcher_reserve_fn reserve, 38 | tlog_json_dispatcher_write_fn write, 39 | void *container, 40 | const struct tlog_trx_iface *container_trx_iface) 41 | { 42 | assert(dispatcher != NULL); 43 | assert(advance != NULL); 44 | assert(reserve != NULL); 45 | assert(write != NULL); 46 | assert(container != NULL); 47 | assert(container_trx_iface != NULL); 48 | dispatcher->advance = advance; 49 | dispatcher->reserve = reserve; 50 | dispatcher->write = write; 51 | dispatcher->trx_iface = TLOG_TRX_BASIC_IFACE(tlog_json_dispatcher); 52 | dispatcher->container = container; 53 | dispatcher->container_trx_iface = container_trx_iface; 54 | assert(tlog_json_dispatcher_is_valid(dispatcher)); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /lib/tlog/json_reader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Abstract message reader. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | tlog_grc 32 | tlog_json_reader_create(struct tlog_json_reader **preader, 33 | const struct tlog_json_reader_type *type, 34 | ...) 35 | { 36 | va_list ap; 37 | struct tlog_json_reader *reader; 38 | tlog_grc grc; 39 | 40 | assert(preader != NULL); 41 | assert(tlog_json_reader_type_is_valid(type)); 42 | assert(type->size >= sizeof(*reader)); 43 | 44 | reader = calloc(type->size, 1); 45 | if (reader == NULL) { 46 | grc = TLOG_GRC_ERRNO; 47 | } else { 48 | reader->type = type; 49 | 50 | va_start(ap, type); 51 | grc = type->init(reader, ap); 52 | va_end(ap); 53 | 54 | if (grc == TLOG_RC_OK) { 55 | assert(tlog_json_reader_is_valid(reader)); 56 | } else { 57 | free(reader); 58 | reader = NULL; 59 | } 60 | } 61 | 62 | *preader = reader; 63 | return grc; 64 | } 65 | 66 | bool 67 | tlog_json_reader_is_valid(const struct tlog_json_reader *reader) 68 | { 69 | return reader != NULL && 70 | tlog_json_reader_type_is_valid(reader->type) && ( 71 | reader->type->is_valid == NULL || 72 | reader->type->is_valid(reader) 73 | ); 74 | } 75 | 76 | size_t 77 | tlog_json_reader_loc_get(const struct tlog_json_reader *reader) 78 | { 79 | assert(tlog_json_reader_is_valid(reader)); 80 | return (reader->type->loc_get != NULL) 81 | ? reader->type->loc_get(reader) 82 | : 0; 83 | } 84 | 85 | char * 86 | tlog_json_reader_loc_fmt(const struct tlog_json_reader *reader, size_t loc) 87 | { 88 | assert(tlog_json_reader_is_valid(reader)); 89 | if (reader->type->loc_fmt != NULL) { 90 | return reader->type->loc_fmt(reader, loc); 91 | } else if (reader->type->loc_get != NULL) { 92 | char *str; 93 | return asprintf(&str, "location %zu", loc) >= 0 ? str : NULL; 94 | } else { 95 | return strdup("unknown location"); 96 | } 97 | } 98 | 99 | tlog_grc 100 | tlog_json_reader_read(struct tlog_json_reader *reader, 101 | struct json_object **pobject) 102 | { 103 | tlog_grc grc; 104 | #ifndef NDEBUG 105 | struct json_object *orig_object; 106 | #endif 107 | assert(tlog_json_reader_is_valid(reader)); 108 | assert(pobject != NULL); 109 | #ifndef NDEBUG 110 | orig_object = *pobject; 111 | #endif 112 | grc = reader->type->read(reader, pobject); 113 | assert(grc == TLOG_RC_OK || *pobject == orig_object); 114 | assert(tlog_json_reader_is_valid(reader)); 115 | return grc; 116 | } 117 | 118 | void 119 | tlog_json_reader_destroy(struct tlog_json_reader *reader) 120 | { 121 | assert(reader == NULL || tlog_json_reader_is_valid(reader)); 122 | 123 | if (reader == NULL) { 124 | return; 125 | } 126 | if (reader->type->cleanup != NULL) { 127 | reader->type->cleanup(reader); 128 | } 129 | free(reader); 130 | } 131 | -------------------------------------------------------------------------------- /lib/tlog/json_writer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Abstract JSON log message writer. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | tlog_grc 29 | tlog_json_writer_create(struct tlog_json_writer **pwriter, 30 | const struct tlog_json_writer_type *type, 31 | ...) 32 | { 33 | va_list ap; 34 | tlog_grc grc; 35 | struct tlog_json_writer *writer; 36 | 37 | assert(pwriter != NULL); 38 | assert(tlog_json_writer_type_is_valid(type)); 39 | assert(type->size >= sizeof(*writer)); 40 | 41 | writer = calloc(type->size, 1); 42 | if (writer == NULL) { 43 | grc = TLOG_GRC_ERRNO; 44 | } else { 45 | writer->type = type; 46 | 47 | va_start(ap, type); 48 | grc = type->init(writer, ap); 49 | va_end(ap); 50 | 51 | if (grc == TLOG_RC_OK) { 52 | assert(tlog_json_writer_is_valid(writer)); 53 | } else { 54 | free(writer); 55 | writer = NULL; 56 | } 57 | } 58 | 59 | *pwriter = writer; 60 | return grc; 61 | } 62 | 63 | bool 64 | tlog_json_writer_is_valid(const struct tlog_json_writer *writer) 65 | { 66 | return writer != NULL && 67 | tlog_json_writer_type_is_valid(writer->type) && ( 68 | writer->type->is_valid == NULL || 69 | writer->type->is_valid(writer) 70 | ); 71 | } 72 | 73 | tlog_grc 74 | tlog_json_writer_write(struct tlog_json_writer *writer, 75 | size_t id, 76 | const uint8_t *buf, size_t len) 77 | { 78 | assert(tlog_json_writer_is_valid(writer)); 79 | assert(id > 0); 80 | assert(buf != NULL || len == 0); 81 | 82 | return writer->type->write(writer, id, buf, len); 83 | } 84 | 85 | void 86 | tlog_json_writer_destroy(struct tlog_json_writer *writer) 87 | { 88 | assert(writer == NULL || tlog_json_writer_is_valid(writer)); 89 | 90 | if (writer == NULL) { 91 | return; 92 | } 93 | if (writer->type->cleanup != NULL) { 94 | writer->type->cleanup(writer); 95 | } 96 | free(writer); 97 | } 98 | -------------------------------------------------------------------------------- /lib/tlog/mem_json_writer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Memory buffer JSON message writer. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /** Memory buffer writer data */ 30 | struct tlog_mem_json_writer { 31 | struct tlog_json_writer writer; /**< Abstract writer instance */ 32 | char **pbuf; /**< Location for the buffer pointer */ 33 | size_t *plen; /**< Location for the buffer length */ 34 | size_t size; /**< Allocated size of the buffer */ 35 | }; 36 | 37 | static tlog_grc 38 | tlog_mem_json_writer_init(struct tlog_json_writer *writer, va_list ap) 39 | { 40 | struct tlog_mem_json_writer *mem_json_writer = 41 | (struct tlog_mem_json_writer*)writer; 42 | mem_json_writer->pbuf = va_arg(ap, char **); 43 | mem_json_writer->plen = va_arg(ap, size_t *); 44 | mem_json_writer->size = 256; 45 | 46 | *mem_json_writer->plen = 0; 47 | *mem_json_writer->pbuf = malloc(mem_json_writer->size); 48 | if (*mem_json_writer->pbuf == NULL) { 49 | return TLOG_GRC_ERRNO; 50 | } 51 | return TLOG_RC_OK; 52 | } 53 | 54 | static tlog_grc 55 | tlog_mem_json_writer_write(struct tlog_json_writer *writer, 56 | size_t id, const uint8_t *buf, size_t len) 57 | { 58 | struct tlog_mem_json_writer *mem_json_writer = 59 | (struct tlog_mem_json_writer*)writer; 60 | size_t new_len = *mem_json_writer->plen + len; 61 | 62 | (void)id; 63 | 64 | if (new_len > mem_json_writer->size) { 65 | size_t new_size; 66 | char *new_buf; 67 | for (new_size = mem_json_writer->size; 68 | new_size < new_len; 69 | new_size *= 2); 70 | new_buf = realloc(*mem_json_writer->pbuf, new_size); 71 | if (new_buf == NULL) { 72 | return TLOG_GRC_ERRNO; 73 | } 74 | *mem_json_writer->pbuf = new_buf; 75 | mem_json_writer->size = new_size; 76 | } 77 | 78 | memcpy(*mem_json_writer->pbuf + *mem_json_writer->plen, buf, len); 79 | *mem_json_writer->plen = new_len; 80 | return TLOG_RC_OK; 81 | } 82 | 83 | const struct tlog_json_writer_type tlog_mem_json_writer_type = { 84 | .size = sizeof(struct tlog_mem_json_writer), 85 | .init = tlog_mem_json_writer_init, 86 | .write = tlog_mem_json_writer_write, 87 | }; 88 | -------------------------------------------------------------------------------- /lib/tlog/play_conf_cmd.c.m4: -------------------------------------------------------------------------------- 1 | m4_include(`misc.m4')m4_dnl 2 | m4_include(`conf_cmd.m4')m4_dnl 3 | m4_changecom()m4_dnl 4 | /* 5 | * Tlog-M4_PROG_NAME() command-line parsing. 6 | * 7 | m4_generated_warning(` * ')m4_dnl 8 | * 9 | * Copyright (C) 2016 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static const char *tlog_play_conf_cmd_help_fmt = 43 | "Usage: %1$s [OPTION...]\n" 44 | "Play back a terminal I/O recording done by tlog-rec.\n" 45 | M4_CONF_CMD_HELP_OPTS()m4_dnl 46 | ""; 47 | 48 | M4_CONF_CMD_LOAD_ARGS()m4_dnl 49 | 50 | tlog_grc 51 | tlog_play_conf_cmd_load(struct tlog_errs **perrs, 52 | char **phelp, struct json_object **pconf, 53 | int argc, char **argv) 54 | { 55 | tlog_grc grc; 56 | char *progpath = NULL; 57 | char *progname = NULL; 58 | char *help = NULL; 59 | struct json_object *conf = NULL; 60 | 61 | assert(phelp != NULL); 62 | assert(pconf != NULL); 63 | assert(argv != NULL); 64 | 65 | /* Create empty configuration */ 66 | conf = json_object_new_object(); 67 | if (conf == NULL) { 68 | grc = TLOG_GRC_ERRNO; 69 | TLOG_ERRS_RAISECS(grc, "Failed creating configuration object"); 70 | } 71 | 72 | /* Extract program name */ 73 | progpath = strdup(argv[0]); 74 | if (progpath == NULL) { 75 | grc = TLOG_GRC_ERRNO; 76 | TLOG_ERRS_RAISECS(grc, "Failed allocating a copy of program path"); 77 | } 78 | progname = strdup(basename(progpath)); 79 | if (progname == NULL) { 80 | grc = TLOG_GRC_ERRNO; 81 | TLOG_ERRS_RAISECS(grc, "Failed allocating program name"); 82 | } 83 | 84 | /* Extract options and positional arguments */ 85 | if (asprintf(&help, tlog_play_conf_cmd_help_fmt, progname) < 0) { 86 | grc = TLOG_GRC_ERRNO; 87 | TLOG_ERRS_RAISECS(grc, "Failed formatting help message"); 88 | } 89 | grc = tlog_play_conf_cmd_load_args(perrs, conf, help, argc, argv); 90 | if (grc != TLOG_RC_OK) { 91 | TLOG_ERRS_RAISES("Failed extracting configuration " 92 | "from options and arguments"); 93 | } 94 | 95 | /* Validate the result */ 96 | grc = tlog_play_conf_validate(perrs, conf, TLOG_CONF_ORIGIN_ARGS); 97 | if (grc != TLOG_RC_OK) { 98 | TLOG_ERRS_RAISES("Validation of loaded configuration failed"); 99 | } 100 | 101 | *phelp = help; 102 | help = NULL; 103 | *pconf = conf; 104 | conf = NULL; 105 | grc = TLOG_RC_OK; 106 | 107 | cleanup: 108 | free(help); 109 | free(progname); 110 | free(progpath); 111 | json_object_put(conf); 112 | return grc; 113 | } 114 | -------------------------------------------------------------------------------- /lib/tlog/rc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Function return codes. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | static const char *tlog_rc_desc_list[TLOG_RC_MAX_PLUS_ONE - TLOG_RC_MIN] = { 28 | [TLOG_RC_OK] = 29 | "Success", 30 | [TLOG_RC_FAILURE] = 31 | "Failure", 32 | [TLOG_RC_JSON_MSG_FIELD_MISSING] = 33 | "A message field is missing", 34 | [TLOG_RC_JSON_MSG_FIELD_INVALID_TYPE] = 35 | "A message field has invalid type", 36 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_VER] = 37 | "Message has unsupported \"ver\" field value", 38 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_SESSION] = 39 | "Message has invalid \"session\" field value", 40 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_ID] = 41 | "Message has invalid \"id\" field value", 42 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_POS] = 43 | "Message has invalid \"pos\" field value", 44 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TIME] = 45 | "Message has invalid \"time\" field value", 46 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TIMING] = 47 | "Message has invalid \"timing\" field value", 48 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_TXT] = 49 | "Message has invalid \"in_txt\" or \"out_txt\" field value", 50 | [TLOG_RC_JSON_MSG_FIELD_INVALID_VALUE_BIN] = 51 | "Message has invalid \"in_bin\" or \"out_bin\" field value", 52 | [TLOG_RC_FD_JSON_READER_INCOMPLETE_LINE] = 53 | "Incomplete message object line encountered", 54 | [TLOG_RC_JSON_SOURCE_MSG_ID_OUT_OF_ORDER] = 55 | "Message ID is out of order", 56 | [TLOG_RC_JSON_SOURCE_PKT_TS_OUT_OF_ORDER] = 57 | "Packet timestamp is out of order", 58 | [TLOG_RC_JSON_SOURCE_TERMINAL_MISMATCH] = 59 | "Message terminal type mismatch", 60 | [TLOG_RC_ES_JSON_READER_CURL_INIT_FAILED] = 61 | "Curl handle creation failed", 62 | [TLOG_RC_ES_JSON_READER_REPLY_INVALID] = 63 | "Invalid reply received from HTTP server", 64 | [TLOG_RC_MEM_JSON_READER_INCOMPLETE_LINE] = 65 | "Incomplete message object line encountered", 66 | }; 67 | 68 | const char * 69 | tlog_rc_strerror(tlog_rc rc) 70 | { 71 | const char *desc; 72 | assert(tlog_rc_is_valid(rc)); 73 | 74 | desc = tlog_rc_desc_list[rc]; 75 | assert(desc != NULL); 76 | return desc ? desc : "Unknown return code"; 77 | } 78 | -------------------------------------------------------------------------------- /lib/tlog/rec_conf_cmd.c.m4: -------------------------------------------------------------------------------- 1 | m4_include(`misc.m4')m4_dnl 2 | m4_include(`conf_cmd.m4')m4_dnl 3 | m4_changecom()m4_dnl 4 | /* 5 | * Tlog-M4_PROG_NAME() command-line parsing. 6 | * 7 | m4_generated_warning(` * ')m4_dnl 8 | * 9 | * Copyright (C) 2016 Red Hat 10 | * 11 | * This file is part of tlog. 12 | * 13 | * Tlog is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * Tlog is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with tlog; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static const char *tlog_rec_conf_cmd_help_fmt = 43 | "Usage: %1$s [OPTION...] [CMD_FILE [CMD_ARG...]]\n" 44 | "Record terminal I/O of a program or a user shell.\n" 45 | M4_CONF_CMD_HELP_OPTS()m4_dnl 46 | ""; 47 | 48 | M4_CONF_CMD_LOAD_ARGS()m4_dnl 49 | 50 | tlog_grc 51 | tlog_rec_conf_cmd_load(struct tlog_errs **perrs, 52 | char **phelp, struct json_object **pconf, 53 | int argc, char **argv) 54 | { 55 | tlog_grc grc; 56 | char *progpath = NULL; 57 | char *progname = NULL; 58 | char *help = NULL; 59 | struct json_object *conf = NULL; 60 | 61 | assert(phelp != NULL); 62 | assert(pconf != NULL); 63 | assert(argv != NULL); 64 | 65 | /* Create empty configuration */ 66 | conf = json_object_new_object(); 67 | if (conf == NULL) { 68 | grc = TLOG_GRC_ERRNO; 69 | TLOG_ERRS_RAISECS(grc, "Failed creating configuration object"); 70 | } 71 | 72 | /* Extract program name */ 73 | progpath = strdup(argv[0]); 74 | if (progpath == NULL) { 75 | grc = TLOG_GRC_ERRNO; 76 | TLOG_ERRS_RAISECS(grc, "Failed allocating a copy of program path"); 77 | } 78 | progname = strdup(basename(progpath)); 79 | if (progname == NULL) { 80 | grc = TLOG_GRC_ERRNO; 81 | TLOG_ERRS_RAISECS(grc, "Failed allocating program name"); 82 | } 83 | 84 | /* Extract options and positional arguments */ 85 | if (asprintf(&help, tlog_rec_conf_cmd_help_fmt, progname) < 0) { 86 | grc = TLOG_GRC_ERRNO; 87 | TLOG_ERRS_RAISECS(grc, "Failed formatting help message"); 88 | } 89 | grc = tlog_rec_conf_cmd_load_args(perrs, conf, help, argc, argv); 90 | if (grc != TLOG_RC_OK) { 91 | TLOG_ERRS_RAISES("Failed extracting configuration " 92 | "from options and arguments"); 93 | } 94 | 95 | /* Validate the result */ 96 | grc = tlog_rec_conf_validate(perrs, conf, TLOG_CONF_ORIGIN_ARGS); 97 | if (grc != TLOG_RC_OK) { 98 | TLOG_ERRS_RAISES("Validation of loaded configuration failed"); 99 | } 100 | 101 | *phelp = help; 102 | help = NULL; 103 | *pconf = conf; 104 | conf = NULL; 105 | grc = TLOG_RC_OK; 106 | 107 | cleanup: 108 | free(help); 109 | free(progname); 110 | free(progpath); 111 | json_object_put(conf); 112 | return grc; 113 | } 114 | -------------------------------------------------------------------------------- /lib/tlog/rec_item.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Recorded item. 3 | * 4 | * Copyright (C) 2016-2017 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | 25 | enum tlog_rec_item 26 | tlog_rec_item_from_pkt(const struct tlog_pkt *pkt) 27 | { 28 | assert(tlog_pkt_is_valid(pkt)); 29 | assert(!tlog_pkt_is_void(pkt)); 30 | return pkt->type == TLOG_PKT_TYPE_WINDOW 31 | ? TLOG_REC_ITEM_WINDOW 32 | : (pkt->data.io.output 33 | ? TLOG_REC_ITEM_OUTPUT 34 | : TLOG_REC_ITEM_INPUT); 35 | } 36 | -------------------------------------------------------------------------------- /lib/tlog/syslog_json_writer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Syslog JSON message writer. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | /** Syslog writer data */ 28 | struct tlog_syslog_json_writer { 29 | struct tlog_json_writer writer; /**< Abstract writer instance */ 30 | int priority; /**< Logging priority */ 31 | }; 32 | 33 | static tlog_grc 34 | tlog_syslog_json_writer_init(struct tlog_json_writer *writer, va_list ap) 35 | { 36 | struct tlog_syslog_json_writer *syslog_json_writer = 37 | (struct tlog_syslog_json_writer*)writer; 38 | syslog_json_writer->priority = va_arg(ap, int); 39 | return TLOG_RC_OK; 40 | } 41 | 42 | static tlog_grc 43 | tlog_syslog_json_writer_write(struct tlog_json_writer *writer, 44 | size_t id, const uint8_t *buf, size_t len) 45 | { 46 | struct tlog_syslog_json_writer *syslog_json_writer = 47 | (struct tlog_syslog_json_writer*)writer; 48 | (void)id; 49 | syslog(syslog_json_writer->priority, "%.*s", 50 | (int)len, (const char *)buf); 51 | return TLOG_RC_OK; 52 | } 53 | 54 | const struct tlog_json_writer_type tlog_syslog_json_writer_type = { 55 | .size = sizeof(struct tlog_syslog_json_writer), 56 | .init = tlog_syslog_json_writer_init, 57 | .write = tlog_syslog_json_writer_write, 58 | }; 59 | -------------------------------------------------------------------------------- /lib/tlog/syslog_misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Miscellaneous syslog-related functions. 3 | * 4 | * Copyright (C) 2016 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #define SYSLOG_NAMES 26 | #include 27 | 28 | /** 29 | * Find a code value in a syslog code list and return its name. 30 | * 31 | * @param list The syslog code list to search. 32 | * @param val The code value to find. 33 | * 34 | * @return The code name, or NULL, if the code value was not found. 35 | */ 36 | static const char * 37 | tlog_syslog_code_to_str(CODE *list, int val) 38 | { 39 | CODE *item; 40 | 41 | for (item = list; item->c_name != NULL; item++) { 42 | if (item->c_val == val) { 43 | return item->c_name; 44 | } 45 | } 46 | return NULL; 47 | } 48 | 49 | /** 50 | * Find a code name in a syslog code list and return its value. 51 | * 52 | * @param list The syslog code list to search. 53 | * @param name The code name to find. 54 | * 55 | * @return The code value, or a negative number, if the name was not found in 56 | * the list. 57 | */ 58 | static int 59 | tlog_syslog_code_from_str(CODE *list, const char *name) 60 | { 61 | CODE *item; 62 | 63 | for (item = list; item->c_name != NULL; item++) { 64 | if (strcasecmp(name, item->c_name) == 0) { 65 | return item->c_val; 66 | } 67 | } 68 | return -1; 69 | } 70 | 71 | const char * 72 | tlog_syslog_facility_to_str(int val) 73 | { 74 | return tlog_syslog_code_to_str(facilitynames, val); 75 | } 76 | 77 | int 78 | tlog_syslog_facility_from_str(const char *str) 79 | { 80 | return tlog_syslog_code_from_str(facilitynames, str); 81 | } 82 | 83 | const char * 84 | tlog_syslog_priority_to_str(int val) 85 | { 86 | return tlog_syslog_code_to_str(prioritynames, val); 87 | } 88 | 89 | int 90 | tlog_syslog_priority_from_str(const char *str) 91 | { 92 | return tlog_syslog_code_from_str(prioritynames, str); 93 | } 94 | -------------------------------------------------------------------------------- /lib/tlog/utf8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * UTF-8 byte sequence validation state. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | 25 | /** Source: Unicode 7.0.0 Chapter 3, Table 3-7 */ 26 | const struct tlog_utf8_seq tlog_utf8_seq_list[] = { 27 | {{{0x00, 0x7f}}}, 28 | {{{0xc2, 0xdf}, {0x80, 0xbf}}}, 29 | {{{0xe0, 0xe0}, {0xa0, 0xbf}, {0x80, 0xbf}}}, 30 | {{{0xe1, 0xec}, {0x80, 0xbf}, {0x80, 0xbf}}}, 31 | {{{0xed, 0xed}, {0x80, 0x9f}, {0x80, 0xbf}}}, 32 | {{{0xee, 0xef}, {0x80, 0xbf}, {0x80, 0xbf}}}, 33 | {{{0xf0, 0xf0}, {0x90, 0xbf}, {0x80, 0xbf}, {0x80, 0xbf}}}, 34 | {{{0xf1, 0xf3}, {0x80, 0xbf}, {0x80, 0xbf}, {0x80, 0xbf}}}, 35 | {{{0xf4, 0xf4}, {0x80, 0x8f}, {0x80, 0xbf}, {0x80, 0xbf}}}, 36 | {{}} 37 | }; 38 | 39 | bool 40 | tlog_utf8_buf_is_valid(const char *ptr, size_t len) 41 | { 42 | struct tlog_utf8 utf8 = TLOG_UTF8_INIT; 43 | 44 | assert(ptr != NULL || len == 0); 45 | 46 | for (; len > 0; len--, ptr++) { 47 | if (!tlog_utf8_add(&utf8, *(const uint8_t *)ptr)) { 48 | return false; 49 | } 50 | if (tlog_utf8_is_ended(&utf8)) { 51 | tlog_utf8_reset(&utf8); 52 | } 53 | } 54 | 55 | return !tlog_utf8_is_started(&utf8); 56 | } 57 | -------------------------------------------------------------------------------- /lib/tltest/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2015 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | AM_CPPFLAGS = \ 23 | $(JSON_CFLAGS) \ 24 | $(SYSTEMD_JOURNAL_CFLAGS) \ 25 | $(LIBCURL_CPPFLAGS) 26 | 27 | noinst_LTLIBRARIES = libtltest.la 28 | 29 | libtltest_la_SOURCES = \ 30 | json_sink.c \ 31 | json_source.c \ 32 | json_stream_enc.c \ 33 | misc.c 34 | 35 | libtltest_la_LIBADD = ../tlog/libtlog.la 36 | -------------------------------------------------------------------------------- /lib/tltest/misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Miscellaneous test functions. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | static void 27 | tltest_diff_side(FILE *stream, const char *name, 28 | const uint8_t *out_buf, size_t out_len, 29 | const uint8_t *exp_buf, size_t exp_len) 30 | { 31 | size_t min_len = TLOG_MIN(out_len, exp_len); 32 | size_t max_len = TLOG_MAX(out_len, exp_len); 33 | size_t col; 34 | size_t i; 35 | const uint8_t *o; 36 | const uint8_t *e; 37 | uint8_t c; 38 | 39 | fprintf(stream, "%s str:\n", name); 40 | for (o = out_buf, i = 0; i < out_len; o++, i++) { 41 | c = *o; 42 | fputc(((c >= 0x20 && c < 0x7f) ? c : ' '), stream); 43 | } 44 | fputc('\n', stream); 45 | for (o = out_buf, e = exp_buf, i = 0; i < max_len; o++, e++, i++) { 46 | fprintf(stream, "%c", 47 | ((i < min_len && *o == *e) ? ' ' : '^')); 48 | } 49 | 50 | fprintf(stream, "\n%s hex:\n", name); 51 | for (o = out_buf, e = exp_buf, i = 0, col = 0; 52 | i < max_len; 53 | o++, e++, i++) { 54 | fprintf(stream, " %c%c%c", 55 | ((i < min_len && *o == *e) ? ' ' : '!'), 56 | (i < out_len ? tlog_nibble_digit(*o >> 4) : ' '), 57 | (i < out_len ? tlog_nibble_digit(*o & 0xf) : ' ')); 58 | col++; 59 | if (col > 0xf) { 60 | col = 0; 61 | fprintf(stream, "\n"); 62 | } 63 | } 64 | if (col != 0) { 65 | fprintf(stream, "\n"); 66 | } 67 | } 68 | 69 | void 70 | tltest_diff(FILE *stream, 71 | const uint8_t *res_buf, size_t res_len, 72 | const uint8_t *exp_buf, size_t exp_len) 73 | { 74 | tltest_diff_side(stream, "expected", exp_buf, exp_len, res_buf, res_len); 75 | fprintf(stream, "\n"); 76 | tltest_diff_side(stream, "result", res_buf, res_len, exp_buf, exp_len); 77 | } 78 | 79 | -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | SUBDIRS = tlog 23 | -------------------------------------------------------------------------------- /m4/autotools/.gitignore: -------------------------------------------------------------------------------- 1 | libtool.m4 2 | lt*.m4 3 | -------------------------------------------------------------------------------- /m4/tlog/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | dist_noinst_DATA = \ 23 | conf_cmd.m4 \ 24 | conf_misc.m4 \ 25 | conf_origin.m4 \ 26 | man.m4 \ 27 | misc.m4 \ 28 | conf_schema.m4 \ 29 | play_conf_schema.m4 \ 30 | rec_common_conf_schema.m4 \ 31 | rec_conf_schema.m4 \ 32 | rec_session_conf_schema.m4 33 | -------------------------------------------------------------------------------- /m4/tlog/conf_misc.m4: -------------------------------------------------------------------------------- 1 | m4_dnl 2 | m4_dnl Miscellaneous configuration schema handling macros. 3 | m4_dnl 4 | m4_dnl Copyright (C) 2017 Red Hat 5 | m4_dnl 6 | m4_dnl This file is part of tlog. 7 | m4_dnl 8 | m4_dnl Tlog is free software; you can redistribute it and/or modify 9 | m4_dnl it under the terms of the GNU General Public License as published by 10 | m4_dnl the Free Software Foundation; either version 2 of the License, or 11 | m4_dnl (at your option) any later version. 12 | m4_dnl 13 | m4_dnl Tlog is distributed in the hope that it will be useful, 14 | m4_dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | m4_dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | m4_dnl GNU General Public License for more details. 17 | m4_dnl 18 | m4_dnl You should have received a copy of the GNU General Public License 19 | m4_dnl along with tlog; if not, write to the Free Software 20 | m4_dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | m4_dnl 22 | m4_include(`conf_origin.m4')m4_dnl 23 | m4_divert(-1) 24 | 25 | m4_dnl 26 | m4_dnl Increment macro M4_CONF_CONTAINER_SIZE_VAL, if a parameter belongs to 27 | m4_dnl the container specified with M4_CONF_PREFIX and M4_CONF_ORIGIN is in 28 | m4_dnl its range. 29 | m4_dnl Macros: 30 | m4_dnl 31 | m4_dnl M4_CONF_PREFIX - container prefix (`' for root) 32 | m4_dnl M4_CONF_ORIGIN - origin to match against 33 | m4_dnl M4_CONF_CONTAINER_SIZE_VAL - the macro to increment 34 | m4_dnl 35 | m4_define( 36 | `_M4_CONF_CONTAINER_SIZE_ADD_PARAM', 37 | `m4_ifelse(`$1', M4_CONF_PREFIX(), 38 | `m4_ifelse(m4_conf_origin_is_in_range(M4_CONF_ORIGIN(), `$3'), 1, 39 | `m4_define(`M4_CONF_CONTAINER_SIZE_VAL', 40 | m4_incr(M4_CONF_CONTAINER_SIZE_VAL)m4_dnl 41 | )'m4_dnl 42 | )'m4_dnl 43 | )'m4_dnl 44 | ) 45 | 46 | m4_dnl 47 | m4_dnl Expand to the number of parameters directly under specified container, 48 | m4_dnl which match the specified origin. 49 | m4_dnl Arguments: 50 | m4_dnl 51 | m4_dnl $1 Path to the schema file 52 | m4_dnl $2 Container prefix 53 | m4_dnl $3 Origin to match against 54 | m4_dnl 55 | m4_define( 56 | `M4_CONF_CONTAINER_SIZE', 57 | `m4_pushdef(`M4_CONF_CONTAINER_SIZE_VAL', `0')m4_dnl 58 | m4_pushdef(`M4_CONTAINER', `')m4_dnl 59 | m4_pushdef(`M4_PARAM', m4_defn(`_M4_CONF_CONTAINER_SIZE_ADD_PARAM'))m4_dnl 60 | m4_pushdef(`M4_CONF_PREFIX', `$2')m4_dnl 61 | m4_pushdef(`M4_CONF_ORIGIN', `$3')m4_dnl 62 | m4_include(`$1')m4_dnl 63 | m4_popdef(`M4_CONF_ORIGIN')m4_dnl 64 | m4_popdef(`M4_CONF_PREFIX')m4_dnl 65 | m4_popdef(`M4_PARAM')m4_dnl 66 | m4_popdef(`M4_CONTAINER')m4_dnl 67 | M4_CONF_CONTAINER_SIZE_VAL()m4_dnl 68 | m4_popdef(`M4_CONF_CONTAINER_SIZE_VAL')'m4_dnl 69 | ) 70 | 71 | m4_divert(0)m4_dnl 72 | -------------------------------------------------------------------------------- /m4/tlog/conf_schema.m4: -------------------------------------------------------------------------------- 1 | m4_dnl 2 | m4_dnl Tlog common configuration schema 3 | m4_dnl 4 | m4_dnl Copyright (C) 2016 Red Hat 5 | m4_dnl 6 | m4_dnl This file is part of tlog. 7 | m4_dnl 8 | m4_dnl Tlog is free software; you can redistribute it and/or modify 9 | m4_dnl it under the terms of the GNU General Public License as published by 10 | m4_dnl the Free Software Foundation; either version 2 of the License, or 11 | m4_dnl (at your option) any later version. 12 | m4_dnl 13 | m4_dnl Tlog is distributed in the hope that it will be useful, 14 | m4_dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | m4_dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | m4_dnl GNU General Public License for more details. 17 | m4_dnl 18 | m4_dnl You should have received a copy of the GNU General Public License 19 | m4_dnl along with tlog; if not, write to the Free Software 20 | m4_dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | m4_dnl 22 | m4_dnl M4_LINES - specify text as a list of lines without terminating newlines 23 | m4_dnl Arguments: 24 | m4_dnl 25 | m4_dnl $@ Text lines 26 | m4_dnl 27 | m4_dnl 28 | m4_dnl M4_CONTAINER - describe a container 29 | m4_dnl Arguments: 30 | m4_dnl 31 | m4_dnl $1 Container prefix (`' for root) 32 | m4_dnl $2 Container name 33 | m4_dnl $3 Container description 34 | m4_dnl 35 | m4_dnl 36 | m4_dnl M4_PARAM - describe a parameter 37 | m4_dnl Arguments: 38 | m4_dnl 39 | m4_dnl $1 Container prefix (`' for root) 40 | m4_dnl $2 Parameter name 41 | m4_dnl $3 Parameter origin range (see conf_origin.m4) 42 | m4_dnl $4 Type, must be an invocation of M4_TYPE_*. 43 | m4_dnl $5 `true' if has default value, `false' otherwise 44 | m4_dnl $6 Option letter 45 | m4_dnl $7 Option value placeholder 46 | m4_dnl $8 Option summary 47 | m4_dnl $9 Option description prologue 48 | m4_dnl $10 Configuration description prologue 49 | m4_dnl $11 Common description epilogue, must be an invocation of M4_LINES 50 | m4_dnl 51 | m4_dnl M4_TYPE_INT - describe integer type 52 | m4_dnl Arguments: 53 | m4_dnl 54 | m4_dnl $1 Default value 55 | m4_dnl $2 Minimum value 56 | m4_dnl 57 | m4_dnl M4_TYPE_DOUBLE - describe double precision floating point type 58 | m4_dnl Arguments: 59 | m4_dnl 60 | m4_dnl $1 Default value 61 | m4_dnl $2 Minimum value 62 | m4_dnl 63 | m4_dnl M4_TYPE_STRING - describe string type 64 | m4_dnl 65 | m4_dnl $1 Default value 66 | m4_dnl 67 | m4_dnl M4_TYPE_BOOL - describe boolean type 68 | m4_dnl 69 | m4_dnl $1 Default value 70 | m4_dnl 71 | m4_dnl M4_TYPE_CHOICE - describe a string choice type 72 | m4_dnl Arguments: 73 | m4_dnl 74 | m4_dnl $1 Default value 75 | m4_dnl $@ Choices 76 | m4_dnl 77 | m4_dnl M4_TYPE_STRING_ARRAY - describe a string array type 78 | m4_dnl Arguments: 79 | m4_dnl 80 | m4_dnl $@ Default values 81 | m4_dnl 82 | M4_PARAM(`', `args', `args', 83 | `M4_TYPE_STRING_ARRAY()', false, 84 | `', `', `', 85 | `', `', 86 | `M4_LINES(`Non-option positional command-line arguments.')')m4_dnl 87 | m4_dnl 88 | M4_PARAM(`', `help', `opts', 89 | `M4_TYPE_BOOL(false)', true, 90 | `h', `', `Output a command-line usage message and exit', 91 | `', `', 92 | `M4_LINES(`')')m4_dnl 93 | m4_dnl 94 | M4_PARAM(`', `version', `opts', 95 | `M4_TYPE_BOOL(false)', true, 96 | `v', `', `Output version information and exit', 97 | `', `', 98 | `M4_LINES(`')')m4_dnl 99 | m4_dnl 100 | M4_PARAM(`', `configuration', `opts', 101 | `M4_TYPE_BOOL(false)', true, 102 | `', `', `Output program configuration in JSON and exit', 103 | `', `', 104 | `M4_LINES(`')')m4_dnl 105 | -------------------------------------------------------------------------------- /m4/tlog/rec_conf_schema.m4: -------------------------------------------------------------------------------- 1 | m4_dnl 2 | m4_dnl Tlog-rec configuration schema 3 | m4_dnl 4 | m4_dnl See conf_schema.m4 for macro invocations expected here. 5 | m4_dnl 6 | m4_dnl Copyright (C) 2016 Red Hat 7 | m4_dnl 8 | m4_dnl This file is part of tlog. 9 | m4_dnl 10 | m4_dnl Tlog is free software; you can redistribute it and/or modify 11 | m4_dnl it under the terms of the GNU General Public License as published by 12 | m4_dnl the Free Software Foundation; either version 2 of the License, or 13 | m4_dnl (at your option) any later version. 14 | m4_dnl 15 | m4_dnl Tlog is distributed in the hope that it will be useful, 16 | m4_dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | m4_dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | m4_dnl GNU General Public License for more details. 19 | m4_dnl 20 | m4_dnl You should have received a copy of the GNU General Public License 21 | m4_dnl along with tlog; if not, write to the Free Software 22 | m4_dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | m4_dnl 24 | m4_include(`conf_schema.m4')m4_dnl 25 | m4_dnl 26 | m4_pushdef(`_M4_PARAM', `M4_PARAM($@)')m4_dnl 27 | m4_include(`rec_common_conf_schema.m4')m4_dnl 28 | m4_popdef(`_M4_PARAM')m4_dnl 29 | m4_dnl 30 | m4_ifelse(M4_JOURNAL_ENABLED(), `1', 31 | `M4_PARAM(`', `writer', `file-', 32 | `M4_TYPE_CHOICE(`file', `journal', `syslog', `file')', true, 33 | `w', `=STRING', `Use STRING log writer (journal/syslog/file, default file)', 34 | `STRING is the ', `The ', 35 | `M4_LINES(`type of "log writer" to use for logging. The writer needs', 36 | `to be configured using its dedicated parameters.')')', 37 | `M4_PARAM(`', `writer', `file-', 38 | `M4_TYPE_CHOICE(`file', `syslog', `file')', true, 39 | `w', `=STRING', `Use STRING log writer (syslog/file, default file)', 40 | `STRING is the ', `The ', 41 | `M4_LINES(`type of "log writer" to use for logging. The writer needs', 42 | `to be configured using its dedicated parameters.')')')m4_dnl 43 | m4_dnl 44 | M4_PARAM(`', `semaphore', `opts', 45 | `M4_TYPE_STRING()', false, 46 | `', `=FILE', `Write "READY" to FILE when recording is setup', 47 | `FILE is a ', `A ', 48 | `M4_LINES(`path to a "semaphore" file to write string "READY" to, when the ', 49 | `recording setup is done, and I/O can be passed to and from the ', 50 | `recorded program.')')m4_dnl 51 | m4_dnl 52 | -------------------------------------------------------------------------------- /man/.gitignore: -------------------------------------------------------------------------------- 1 | *.8 2 | *.5 3 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | dist_noinst_DATA = \ 23 | tlog-play.8.m4 \ 24 | tlog-play.conf.5.m4 \ 25 | tlog-rec.8.m4 \ 26 | tlog-rec.conf.5.m4 \ 27 | tlog-rec-session.8.m4 \ 28 | tlog-rec-session.conf.5.m4 29 | 30 | TLOG_CONF_DEPS += $(top_srcdir)/m4/tlog/man.m4 31 | 32 | tlog-play.8: tlog-play.8.m4 $(TLOG_PLAY_CONF_DEPS) 33 | m4 $(M4FLAGS) \ 34 | -D M4_CONF_PATH="$(TLOG_PLAY_CONF_LOCAL_INST_PATH)" \ 35 | -D M4_PROG_NAME=play \ 36 | -D M4_PROG_SYM=play \ 37 | $< > $@ || \ 38 | { rm $@ && false; } 39 | 40 | tlog-rec.8: tlog-rec.8.m4 $(TLOG_REC_CONF_DEPS) 41 | m4 $(M4FLAGS) \ 42 | -D M4_CONF_PATH="$(TLOG_REC_CONF_LOCAL_INST_PATH)" \ 43 | -D M4_PROG_NAME=rec \ 44 | -D M4_PROG_SYM=rec \ 45 | $< > $@ || \ 46 | { rm $@ && false; } 47 | 48 | tlog-rec-session.8: tlog-rec-session.8.m4 $(TLOG_REC_SESSION_CONF_DEPS) 49 | m4 $(M4FLAGS) \ 50 | -D M4_CONF_PATH="$(TLOG_REC_SESSION_CONF_LOCAL_INST_PATH)" \ 51 | -D M4_PROG_NAME=rec-session \ 52 | -D M4_PROG_SYM=rec_session \ 53 | $< > $@ || \ 54 | { rm $@ && false; } 55 | 56 | tlog-rec.conf.5: tlog-rec.conf.5.m4 $(TLOG_REC_CONF_DEPS) 57 | m4 $(M4FLAGS) \ 58 | -D M4_PROG_NAME=rec \ 59 | -D M4_PROG_SYM=rec \ 60 | $< > $@ || \ 61 | { rm $@ && false; } 62 | 63 | tlog-rec-session.conf.5: tlog-rec-session.conf.5.m4 $(TLOG_REC_SESSION_CONF_DEPS) 64 | m4 $(M4FLAGS) \ 65 | -D M4_PROG_NAME=rec-session \ 66 | -D M4_PROG_SYM=rec_session \ 67 | $< > $@ || \ 68 | { rm $@ && false; } 69 | 70 | tlog-play.conf.5: tlog-play.conf.5.m4 $(TLOG_PLAY_CONF_DEPS) 71 | m4 $(M4FLAGS) \ 72 | -D M4_PROG_NAME=play \ 73 | -D M4_PROG_SYM=play \ 74 | $< > $@ || \ 75 | { rm $@ && false; } 76 | 77 | nodist_man_MANS = \ 78 | tlog-play.8 \ 79 | tlog-play.conf.5 \ 80 | tlog-rec.8 \ 81 | tlog-rec.conf.5 \ 82 | tlog-rec-session.8 \ 83 | tlog-rec-session.conf.5 84 | 85 | CLEANFILES = \ 86 | tlog-play.8 \ 87 | tlog-play.conf.5 \ 88 | tlog-rec.8 \ 89 | tlog-rec.conf.5 \ 90 | tlog-rec-session.8 \ 91 | tlog-rec-session.conf.5 92 | 93 | install-data-hook: 94 | : Remove "DO NOT EDIT" warning 95 | $(SED) -i -e '/vim:nomodifiable/,/\*\{73\}/ d' \ 96 | $(DESTDIR)$(mandir)/man5/tlog-play.conf.5 \ 97 | $(DESTDIR)$(mandir)/man5/tlog-rec.conf.5 \ 98 | $(DESTDIR)$(mandir)/man5/tlog-rec-session.conf.5 \ 99 | $(DESTDIR)$(mandir)/man8/tlog-play.8 \ 100 | $(DESTDIR)$(mandir)/man8/tlog-rec.8 \ 101 | $(DESTDIR)$(mandir)/man8/tlog-rec-session.8 102 | 103 | -------------------------------------------------------------------------------- /man/tlog-play.conf.5.m4: -------------------------------------------------------------------------------- 1 | m4_include(`man.m4')m4_dnl 2 | .\" Process this file with 3 | .\" groff -man -Tascii 4 | m4_generated_warning(`.\" ')m4_dnl 5 | .\" 6 | .\" Copyright (C) 2016 Red Hat 7 | .\" 8 | .\" This file is part of tlog. 9 | .\" 10 | .\" Tlog is free software; you can redistribute it and/or modify 11 | .\" it under the terms of the GNU General Public License as published by 12 | .\" the Free Software Foundation; either version 2 of the License, or 13 | .\" (at your option) any later version. 14 | .\" 15 | .\" Tlog is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public License 21 | .\" along with tlog; if not, write to the Free Software 22 | .\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | .\" 24 | .TH tlog-play.conf "5" "March 2016" "Tlog" 25 | .SH NAME 26 | tlog-M4_PROG_NAME().conf \- tlog-play configuration file 27 | 28 | .SH DESCRIPTION 29 | .B tlog-play.conf 30 | is a JSON-format configuration file for 31 | .B tlog-play 32 | program. 33 | Contrary to the strict JSON specification, both C and C++ style comments are 34 | allowed in the file. 35 | 36 | The file must contain a single JSON object with the objects and fields 37 | described below. 38 | Some of them are optional and assume a default value. 39 | Those that do require a value can still be omitted and specified to 40 | .B tlog-play 41 | via command-line options. 42 | 43 | .SH OBJECTS AND FIELDS 44 | M4_MAN_CONF() 45 | .SH EXAMPLES 46 | .TP 47 | A configuration specifying only the reader: 48 | .nf 49 | 50 | { 51 | "reader": "file" 52 | } 53 | .fi 54 | 55 | .TP 56 | A configuration specifying Elasticsearch reader, along with the base URL. 57 | .nf 58 | 59 | { 60 | "reader": "es" 61 | "es" : { 62 | "baseurl": "http://localhost:9200/tlog/tlog/_search" 63 | } 64 | } 65 | .fi 66 | 67 | .SH SEE ALSO 68 | tlog-M4_PROG_NAME()(8), http://json.org/ 69 | 70 | .SH AUTHOR 71 | Nikolai Kondrashov 72 | -------------------------------------------------------------------------------- /man/tlog-rec-session.conf.5.m4: -------------------------------------------------------------------------------- 1 | m4_include(`man.m4')m4_dnl 2 | .\" Process this file with 3 | .\" groff -man -Tascii 4 | m4_generated_warning(`.\" ')m4_dnl 5 | .\" 6 | .\" Copyright (C) 2016 Red Hat 7 | .\" 8 | .\" This file is part of tlog. 9 | .\" 10 | .\" Tlog is free software; you can redistribute it and/or modify 11 | .\" it under the terms of the GNU General Public License as published by 12 | .\" the Free Software Foundation; either version 2 of the License, or 13 | .\" (at your option) any later version. 14 | .\" 15 | .\" Tlog is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public License 21 | .\" along with tlog; if not, write to the Free Software 22 | .\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | .\" 24 | .TH tlog-M4_PROG_NAME().conf "5" "February 2016" "Tlog" 25 | .SH NAME 26 | tlog-rec-session.conf \- tlog-rec-session configuration file 27 | 28 | .SH DESCRIPTION 29 | .B tlog-rec-session.conf 30 | is a JSON-format configuration file for 31 | .B tlog-rec-session 32 | program. 33 | Contrary to the strict JSON specification, both C and C++ style comments are 34 | allowed in the file. 35 | 36 | The file must contain a single JSON object with the objects and fields 37 | described below. 38 | Almost all of them are optional and assume a default value. 39 | However, those that do require a value can still be omitted and specified to 40 | .B tlog-rec-session 41 | in other ways: through environment variables or command line. 42 | 43 | .SH OBJECTS AND FIELDS 44 | M4_MAN_CONF() 45 | .SH EXAMPLES 46 | .TP 47 | A configuration specifying only a shell: 48 | .nf 49 | 50 | { 51 | "shell": "/usr/bin/zsh" 52 | } 53 | .fi 54 | 55 | .TP 56 | A configuration enabling logging user input: 57 | .nf 58 | 59 | { 60 | "log": { 61 | "input": true 62 | } 63 | } 64 | .fi 65 | 66 | .TP 67 | A configuration specifying logging to a file: 68 | .nf 69 | 70 | { 71 | "writer": "file", 72 | "file" : { 73 | "path": "/var/log/tlog-rec-session.log" 74 | } 75 | } 76 | .fi 77 | 78 | .SH SEE ALSO 79 | tlog-M4_PROG_NAME()(8), http://json.org/ 80 | 81 | .SH AUTHOR 82 | Nikolai Kondrashov 83 | -------------------------------------------------------------------------------- /man/tlog-rec.8.m4: -------------------------------------------------------------------------------- 1 | m4_include(`man.m4')m4_dnl 2 | .\" Process this file with 3 | .\" groff -man -Tascii 4 | m4_generated_warning(`.\" ')m4_dnl 5 | .\" 6 | .\" Copyright (C) 2016-2017 Red Hat 7 | .\" 8 | .\" This file is part of tlog. 9 | .\" 10 | .\" Tlog is free software; you can redistribute it and/or modify 11 | .\" it under the terms of the GNU General Public License as published by 12 | .\" the Free Software Foundation; either version 2 of the License, or 13 | .\" (at your option) any later version. 14 | .\" 15 | .\" Tlog is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public License 21 | .\" along with tlog; if not, write to the Free Software 22 | .\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | .\" 24 | .TH tlog-M4_PROG_NAME() "8" "May 2017" "Tlog" 25 | .SH NAME 26 | tlog-M4_PROG_NAME() \- record terminal I/O of a program or a user shell 27 | 28 | .SH SYNOPSIS 29 | .B tlog-rec 30 | [OPTION...] [CMD_FILE [CMD_ARG...]] 31 | 32 | .SH DESCRIPTION 33 | .B Tlog-rec 34 | is a terminal I/O logging program. It starts a program under a pseudo-TTY, 35 | connects it to the actual terminal and logs whatever passes between them 36 | including user input, program output, and terminal window size changes. 37 | 38 | CMD_FILE argument specifies the program to run and record. If CMD_FILE 39 | contains a slash (/) character, then it is assumed to contain a path to the 40 | program to run. Otherwise a program file with CMD_FILE name is searched for in 41 | directories specified with the PATH environment variable. If this variable is 42 | not set, then the current directory is searched, followed by the 43 | system-default directories output by "getconf CS_PATH", which is usually 44 | "/bin:/usr/bin". 45 | 46 | CMD_ARG arguments are used as arguments to the program to run and record. 47 | 48 | If no non-option arguments are specified, then tlog-rec starts and records a 49 | user shell specified with the SHELL environment variable, or if that is not 50 | set, it starts the shell specified in the NSS database for the user tlog-rec 51 | runs as. 52 | 53 | .B Tlog-rec 54 | loads its parameters first from the system-wide configuration file 55 | M4_CONF_PATH(), then from the file pointed at by TLOG_REC_CONF_FILE 56 | environment variable (if set), then from the contents of the TLOG_REC_CONF_TEXT 57 | environment variable (if set), and then from command-line options. Parameters 58 | from each of these sources override the previous one in turn. 59 | 60 | .SH OPTIONS 61 | M4_MAN_OPTS() 62 | 63 | .SH ENVIRONMENT 64 | .TP 65 | TLOG_REC_CONF_FILE 66 | Specifies the location of a configuration file to be read. 67 | The configuration parameters in this file override the ones in the system-wide 68 | configuration file M4_CONF_PATH(). 69 | 70 | .TP 71 | TLOG_REC_CONF_TEXT 72 | Specifies the configuration text to be read. 73 | The configuration parameters in this variable override the ones in the file 74 | specified with TLOG_REC_CONF_FILE. 75 | 76 | .TP 77 | SHELL 78 | Specifies the shell to run, if no positional arguments are found on the 79 | command line. 80 | 81 | .SH FILES 82 | .TP 83 | M4_CONF_PATH() 84 | The system-wide configuration file 85 | 86 | .SH EXAMPLES 87 | .TP 88 | Record a vim session to a file: 89 | .B tlog-rec -o vim.log vim 90 | 91 | .TP 92 | Record user input only: 93 | .B tlog-rec --log-input=on --log-output=off --log-window=off 94 | 95 | .TP 96 | Record with minimal latency: 97 | .B tlog-rec --latency=1 98 | 99 | .SH SEE ALSO 100 | tlog-M4_PROG_NAME().conf(5), tlog-rec-session(8), tlog-play(8) 101 | 102 | .SH AUTHOR 103 | Nikolai Kondrashov 104 | -------------------------------------------------------------------------------- /man/tlog-rec.conf.5.m4: -------------------------------------------------------------------------------- 1 | m4_include(`man.m4')m4_dnl 2 | .\" Process this file with 3 | .\" groff -man -Tascii 4 | m4_generated_warning(`.\" ')m4_dnl 5 | .\" 6 | .\" Copyright (C) 2016-2017 Red Hat 7 | .\" 8 | .\" This file is part of tlog. 9 | .\" 10 | .\" Tlog is free software; you can redistribute it and/or modify 11 | .\" it under the terms of the GNU General Public License as published by 12 | .\" the Free Software Foundation; either version 2 of the License, or 13 | .\" (at your option) any later version. 14 | .\" 15 | .\" Tlog is distributed in the hope that it will be useful, 16 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | .\" GNU General Public License for more details. 19 | .\" 20 | .\" You should have received a copy of the GNU General Public License 21 | .\" along with tlog; if not, write to the Free Software 22 | .\" Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | .\" 24 | .TH tlog-M4_PROG_NAME().conf "5" "May 2017" "Tlog" 25 | .SH NAME 26 | tlog-rec.conf \- tlog-rec configuration file 27 | 28 | .SH DESCRIPTION 29 | .B tlog-rec.conf 30 | is a JSON-format configuration file for 31 | .B tlog-rec 32 | program. 33 | Contrary to the strict JSON specification, both C and C++ style comments are 34 | allowed in the file. 35 | 36 | The file must contain a single JSON object with the objects and fields 37 | described below. 38 | Almost all of them are optional and assume a default value. 39 | However, those that do require a value can still be omitted and specified to 40 | .B tlog-rec 41 | in other ways: through environment variables or command line. 42 | 43 | .SH OBJECTS AND FIELDS 44 | M4_MAN_CONF() 45 | .SH EXAMPLES 46 | .TP 47 | A configuration specifying only a reduced latency: 48 | .nf 49 | 50 | { 51 | "latency": 3 52 | } 53 | .fi 54 | 55 | .TP 56 | A configuration enabling logging user input: 57 | .nf 58 | 59 | { 60 | "log": { 61 | "input": true 62 | } 63 | } 64 | .fi 65 | 66 | .TP 67 | A configuration specifying logging to a file: 68 | .nf 69 | 70 | { 71 | "writer": "file" 72 | "file" : { 73 | "path": "/var/log/tlog-rec.log" 74 | } 75 | } 76 | .fi 77 | 78 | .SH SEE ALSO 79 | tlog-M4_PROG_NAME()(8), http://json.org/ 80 | 81 | .SH AUTHOR 82 | Nikolai Kondrashov 83 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 Red Hat 3 | # 4 | # This file is part of tlog. 5 | # 6 | # Tlog is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Tlog is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with tlog; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | include $(top_srcdir)/Common.am 21 | 22 | SUBDIRS = tlog tltest 23 | -------------------------------------------------------------------------------- /src/tlitest/README.md: -------------------------------------------------------------------------------- 1 | Tlog Integration Tests 2 | ====================== 3 | 4 | Tlog Integration Tests provide real world tests for various features 5 | and functionalities of tlog. Although these tests are meant for 6 | OS package build gating, they can be run for general testing purposes 7 | as well. 8 | 9 | This README.md will provide information on how to prepare for, run, 10 | and cleanup after the tests. 11 | 12 | Setup 13 | ----- 14 | 15 | In the src/tlitest directory, run the main setup script: 16 | ./tlitest-setup 17 | 18 | This will install necessary packages, add users and setup a wheel 19 | based no password sudoer rule file. 20 | 21 | As a part of setup, we also take note of the specified packages that 22 | were already installed before setup. This allows us to skip them 23 | during package removal of cleanup (teardown). 24 | 25 | Also, during setup, we take note of users the same way so that 26 | pre-existing users will skip delete during cleanup. 27 | 28 | Run 29 | --- 30 | 31 | To run the tests, you must execute pytest. In the src/tlitest 32 | directory run: 33 | ./tlitest-run 34 | 35 | If you want to generate a junit xml file for upload for reporting, 36 | run: 37 | ./tlitest-run --junit-xml=/tmp/path-to-your-junit-xml-file 38 | 39 | Cleanup 40 | ------- 41 | 42 | The cleanup after the tests, inside the src/tlitest directory run: 43 | ./tlitest-teardown 44 | 45 | This will look for pre-existing packages and skip them. Packages 46 | installed by setup will be removed. 47 | 48 | This will also look for pre-existing users and skip them. Users 49 | added by setup will be removed. 50 | 51 | The sudoers rule file added by setup will also be removed. 52 | -------------------------------------------------------------------------------- /src/tlitest/tlitest-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | pytest-3 -v "$(dirname $0)/../../lib/tlitest" "$@" 4 | -------------------------------------------------------------------------------- /src/tlitest/tlitest-setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PKGS=" 4 | systemd-journal-remote 5 | glibc-all-langpacks 6 | python3 7 | python3-pytest 8 | python3-pexpect 9 | python3-systemd 10 | tcsh 11 | " 12 | 13 | [[ -z "${CONTAINER_ENV}" ]] && PKGS+="tlog" 14 | 15 | PKGSFILE="/tmp/tlitest-setup_packages_found" 16 | if [ -f "$PKGSFILE" ]; then 17 | echo "Backing up previous runs found packages file" 18 | mv "$PKGSFILE" "$PKGSFILE.$(date +%Y-%m-%h_%H:%M:%S)" 19 | fi 20 | 21 | echo "Check and install packages to run tlog integration tests" 22 | dnf config-manager --enable epel 23 | for P in $PKGS; do 24 | rpm -q "$P" > /dev/null 25 | if [ $? -ne 0 ]; then 26 | echo "RPM [$P] missing..installing" 27 | dnf -y --nogpgcheck install $P 28 | else 29 | echo "RPM [$P] already installed...saving" 30 | echo "$P" >> $PKGSFILE 31 | fi 32 | done 33 | 34 | USERS=" 35 | tlitestlocaluser1 36 | tlitestlocaluser2 37 | tlitestlocaladmin1 38 | " 39 | USERSFILE="/tmp/tlitest-setup_users_found" 40 | echo "Check and create users to run tlog integration tests" 41 | for U in $USERS; do 42 | id "$U" > /dev/null 2>&1 43 | if [ $? -ne 0 ]; then 44 | echo "User [$U] missing...adding" 45 | useradd -m "$U" 46 | echo -e "Secret123\nSecret123" |passwd "$U" 47 | else 48 | echo "User [$U] already exists...saving" 49 | echo "$U" >> $USERSFILE 50 | fi 51 | done 52 | 53 | echo "%wheel ALL=(ALL) NOPASSWD: ALL" > \ 54 | /etc/sudoers.d/01_wheel_nopass_tlitest 55 | 56 | # tlitestlocaluser1 and tlitestlocaladmin1 are required to be in the 57 | # systemd-journal group in RHEL8 in order to be able to read journal 58 | # for play tests 59 | 60 | usermod tlitestlocaladmin1 -aG wheel,systemd-journal 61 | usermod tlitestlocaluser1 -aG systemd-journal 62 | usermod tlitestlocaluser2 -s /usr/bin/tlog-rec-session 63 | 64 | # Generate ssh key for testing 65 | user="tlitestlocaluser2" 66 | rm -rf ~/.ssh/id_rsa_${user}* 67 | ssh-keygen -t rsa -b 2048 -N "" -C stdin_test -f ~/.ssh/id_rsa_${user} 68 | user_dir=$(eval echo "~${user}") 69 | mkdir -p ${user_dir}/.ssh 70 | cat ~/.ssh/id_rsa_${user}.pub >> ${user_dir}/.ssh/authorized_keys 71 | chown -R ${user}:${user} ${user_dir}/.ssh 72 | -------------------------------------------------------------------------------- /src/tlitest/tlitest-teardown: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PKGS=" 4 | python3-pytest 5 | python3-pexpect 6 | python3-systemd 7 | tcsh 8 | tlog 9 | " 10 | PKGSFILE="/tmp/tlitest-setup_packages_found" 11 | echo "Check and remove packages from tlog integration tests" 12 | for P in $PKGS; do 13 | if [ -f $PKGSFILE ]; then 14 | if grep -q "$P" $PKGSFILE; then 15 | echo "RPM [$P] found before tests..skipping remove" 16 | continue 17 | fi 18 | fi 19 | rpm -q "$P" > /dev/null 20 | if [ $? -eq 0 ]; then 21 | echo "RPM [$P] missing..installing" 22 | dnf -y remove $P 23 | fi 24 | done 25 | 26 | USERS=" 27 | tlitestlocaluser1 28 | tlitestlocaladmin1 29 | " 30 | USERSFILE="/tmp/tlitest-setup_users_found" 31 | echo "Check and create users to run tlog integration tests" 32 | for U in $USERS; do 33 | if [ -f $USERSFILE ]; then 34 | if grep -q "$U" $USERSFILE; then 35 | echo "User [$U] found before tests...skipping remove" 36 | continue 37 | fi 38 | fi 39 | id "$U" > /dev/null 2>&1 40 | if [ $? -ne 0 ]; then 41 | echo "User [$U] missing...adding" 42 | useradd -m "$U" -s /usr/bin/tlog-rec-session 43 | echo -e "Secret123\nSecret123" |passwd "$U" 44 | fi 45 | done 46 | 47 | if [ -f /etc/sudoers.d/01_wheel_nopass_tlitest ]; then 48 | echo "Found test sudoers file...removing" 49 | rm /etc/sudoers.d/01_wheel_nopass_tlitest 50 | fi 51 | 52 | user="tlitestlocaluser2" 53 | if [ -f ~/.ssh/id_rsa_${user} ]; then 54 | rm -rf ~/.ssh/id_rsa_${user}* 55 | fi 56 | -------------------------------------------------------------------------------- /src/tlog/.gitignore: -------------------------------------------------------------------------------- 1 | /tlog-rec 2 | /tlog-rec-session 3 | /tlog-play 4 | *.conf 5 | -------------------------------------------------------------------------------- /src/tlog/tlog-play.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Red Hat 3 | * 4 | * This file is part of tlog. 5 | * 6 | * Tlog is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * Tlog is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with tlog; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | int 33 | main(int argc, char **argv) 34 | { 35 | tlog_grc grc; 36 | struct tlog_errs *errs = NULL; 37 | struct tlog_errs **perrs = &errs; 38 | struct json_object *conf = NULL; 39 | char *cmd_help = NULL; 40 | const char *charset; 41 | int signal = 0; 42 | 43 | /* Set locale from environment variables */ 44 | if (setlocale(LC_ALL, "") == NULL) { 45 | grc = TLOG_GRC_ERRNO; 46 | TLOG_ERRS_RAISECS(grc, "Failed setting locale from " 47 | "environment variables"); 48 | } 49 | 50 | /* Read configuration and command-line usage message */ 51 | grc = tlog_play_conf_load(&errs, &cmd_help, &conf, argc, argv); 52 | if (grc != TLOG_RC_OK) { 53 | goto cleanup; 54 | } 55 | 56 | /* Check that the character encoding is supported */ 57 | charset = nl_langinfo(CODESET); 58 | if (strcmp(charset, "UTF-8") != 0) { 59 | if (strcmp(charset, "ANSI_X3.4-1968") == 0) { 60 | tlog_errs_pushf(&errs, "Locale charset is ANSI_X3.4-1968 (ASCII)"); 61 | tlog_errs_pushf(&errs, "Assuming locale environment is lost " 62 | "and charset is UTF-8"); 63 | } else { 64 | grc = TLOG_RC_FAILURE; 65 | TLOG_ERRS_RAISEF("Unsupported locale charset: %s", charset); 66 | } 67 | } 68 | 69 | /* Run */ 70 | grc = tlog_play(&errs, cmd_help, conf, &signal); 71 | 72 | cleanup: 73 | 74 | /* Print error stack, if any */ 75 | tlog_errs_print(stderr, errs); 76 | 77 | json_object_put(conf); 78 | free(cmd_help); 79 | tlog_errs_destroy(&errs); 80 | 81 | /* Reproduce the exit signal to get proper exit status */ 82 | if (signal != 0) { 83 | raise(signal); 84 | } 85 | 86 | return grc != TLOG_RC_OK; 87 | } 88 | -------------------------------------------------------------------------------- /src/tltest/.gitignore: -------------------------------------------------------------------------------- 1 | tltest-* 2 | !tltest-*.c 3 | -------------------------------------------------------------------------------- /src/tltest/tltest-grc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tlog grc (global return code) module test. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | bool 34 | test(const char *file, int line, const char *name, bool res) 35 | { 36 | fprintf(stderr, "%s %s:%d %s\n", (res ? "PASS" : "FAIL"), 37 | file, line, name); 38 | return res; 39 | } 40 | 41 | int 42 | main(void) 43 | { 44 | bool passed = true; 45 | 46 | #define TEST(_name_token, _expr) \ 47 | passed = test(__FILE__, __LINE__, #_name_token, _expr) && passed 48 | 49 | TEST(invalid, !tlog_grc_is_valid(INT_MAX)); 50 | 51 | #define native_from(x) (x) 52 | #define errno_from(x) (-(x) - 10000) 53 | #define gai_from(x) (-(x) + 10000) 54 | #define json_from(x) ((x) + 20000) 55 | #define curl_from(x) ((x) + 30000) 56 | 57 | #define TEST_CODE(_range_name_token, _rc_name_token, _value, _strerror) \ 58 | do { \ 59 | int rc = _value; \ 60 | tlog_grc grc = tlog_grc_from(&tlog_grc_range_##_range_name_token, \ 61 | rc); \ 62 | \ 63 | TEST(_range_name_token##_##_rc_name_token##_from, \ 64 | grc == _range_name_token##_from(rc)); \ 65 | TEST(_range_name_token##_##_rc_name_token##_is_valid, \ 66 | tlog_grc_is_valid(grc)); \ 67 | TEST(_range_name_token##_##_rc_name_token##_is, \ 68 | tlog_grc_is(&tlog_grc_range_##_range_name_token, grc)); \ 69 | TEST(_range_name_token##_##_rc_name_token##_strerror_match, \ 70 | tlog_grc_strerror(grc) == _strerror(rc)); \ 71 | TEST(_range_name_token##_##_rc_name_token##_to, \ 72 | tlog_grc_to(&tlog_grc_range_##_range_name_token, grc) == rc); \ 73 | } while (0) 74 | 75 | TEST_CODE(native, ok, TLOG_RC_OK, tlog_rc_strerror); 76 | TEST_CODE(native, failure, TLOG_RC_FAILURE, tlog_rc_strerror); 77 | TEST_CODE(errno, einval, EINVAL, strerror); 78 | TEST_CODE(errno, efault, EFAULT, strerror); 79 | TEST_CODE(gai, again, EAI_AGAIN, gai_strerror); 80 | TEST_CODE(gai, noname, EAI_NONAME, gai_strerror); 81 | TEST_CODE(json, success, json_tokener_success, json_tokener_error_desc); 82 | TEST_CODE(json, error_size, json_tokener_error_depth, json_tokener_error_desc); 83 | TEST_CODE(curl, failed_init, CURLE_FAILED_INIT, curl_easy_strerror); 84 | TEST_CODE(curl, couldnt_resolve_host, CURLE_COULDNT_RESOLVE_HOST, 85 | curl_easy_strerror); 86 | 87 | return !passed; 88 | } 89 | -------------------------------------------------------------------------------- /src/tltest/tltest-json-stream-btoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tlog tlog_json_stream_btoa function test. 3 | * 4 | * Copyright (C) 2015 Red Hat 5 | * 6 | * This file is part of tlog. 7 | * 8 | * Tlog is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * Tlog is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with tlog; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | int 29 | main(void) 30 | { 31 | uint8_t i = 0; 32 | uint8_t btoa_buf[4] = {0,}; 33 | size_t btoa_rc; 34 | uint8_t snprintf_buf[4] = {0,}; 35 | int snprintf_rc; 36 | do { 37 | snprintf_rc = snprintf((char *)snprintf_buf, sizeof(snprintf_buf), 38 | "%hhu", i); 39 | btoa_rc = tlog_json_stream_btoa(btoa_buf, sizeof(btoa_buf), i); 40 | if (btoa_rc != (size_t)snprintf_rc) { 41 | fprintf(stderr, "%hhu: rc mismatch: %zu != %d\n", 42 | i, btoa_rc, snprintf_rc); 43 | return 1; 44 | } 45 | if (memcmp(btoa_buf, snprintf_buf, 4) != 0) { 46 | fprintf(stderr, 47 | "%hhu: buffer mismatch: " 48 | "%02hhx %02hhx %02hhx %02hhx != " 49 | "%02hhx %02hhx %02hhx %02hhx\n", 50 | i, 51 | btoa_buf[0], btoa_buf[1], 52 | btoa_buf[2], btoa_buf[3], 53 | snprintf_buf[0], snprintf_buf[1], 54 | snprintf_buf[2], snprintf_buf[3]); 55 | return 1; 56 | } 57 | printf("%hhu: %zu == %d, %s == %s\n", 58 | i, btoa_rc, snprintf_rc, btoa_buf, snprintf_buf); 59 | } while (i++ != 255); 60 | return 0; 61 | } 62 | --------------------------------------------------------------------------------