nsscash/nsscash.git
8 months agogo.mod: update github.com/pkg/errors to v0.9.1 master 0.2
Simon Ruderich [Sat, 16 Jan 2021 10:44:16 +0000 (11:44 +0100)]
go.mod: update github.com/pkg/errors to v0.9.1

8 months agogo.mod: update github.com/google/renameio to v1.0.0
Simon Ruderich [Sat, 16 Jan 2021 10:44:01 +0000 (11:44 +0100)]
go.mod: update github.com/google/renameio to v1.0.0

8 months agoGuarantee durability after renaming temporary files
Simon Ruderich [Sat, 16 Jan 2021 10:34:59 +0000 (11:34 +0100)]
Guarantee durability after renaming temporary files

8 months agoUpdate copyright years
Simon Ruderich [Sat, 16 Jan 2021 10:23:53 +0000 (11:23 +0100)]
Update copyright years

15 months agoAdd workflow for GitHub Actions
Simon Ruderich [Mon, 8 Jun 2020 19:35:25 +0000 (21:35 +0200)]
Add workflow for GitHub Actions

16 months agobuild.sr.ht: run tests on freebsd
Simon Ruderich [Sat, 16 May 2020 06:52:36 +0000 (08:52 +0200)]
build.sr.ht: run tests on freebsd

16 months agonss/tests: add missing headers for WIFEXITED/WEXITSTATUS
Simon Ruderich [Sat, 16 May 2020 07:03:47 +0000 (09:03 +0200)]
nss/tests: add missing headers for WIFEXITED/WEXITSTATUS

Found on FreeBSD which fails to build without these headers.

16 months agobuild.sr.ht: run tests on fedora
Simon Ruderich [Sat, 16 May 2020 06:52:08 +0000 (08:52 +0200)]
build.sr.ht: run tests on fedora

16 months agobuild.sr.ht: run tests on archlinux
Simon Ruderich [Sat, 16 May 2020 06:34:00 +0000 (08:34 +0200)]
build.sr.ht: run tests on archlinux

18 months agoUse github.com/google/renameio for atomic file updates
Simon Ruderich [Tue, 18 Feb 2020 05:02:17 +0000 (06:02 +0100)]
Use github.com/google/renameio for atomic file updates

This also fixes a very unlikely race condition which could delete a
temporary file from a concurrent nsscash run if it chooses the same
temporary file name after os.Rename() was called but before our deferred
os.Remove() remove it. This race would cause the second nsscash run to
fail but not cause any corruption of persistent files.

18 months agoUpdate copyright years
Simon Ruderich [Tue, 18 Feb 2020 05:01:47 +0000 (06:01 +0100)]
Update copyright years

20 months agoREADME.adoc: fix syntax for nested list
Simon Ruderich [Sun, 22 Dec 2019 10:21:35 +0000 (11:21 +0100)]
README.adoc: fix syntax for nested list

21 months agonsscash: main_test: add disabled test case for todo 0.1
Simon Ruderich [Sun, 15 Dec 2019 21:48:33 +0000 (22:48 +0100)]
nsscash: main_test: add disabled test case for todo

21 months agonsscash: main_test: use configPath variable
Simon Ruderich [Sun, 15 Dec 2019 14:53:16 +0000 (15:53 +0100)]
nsscash: main_test: use configPath variable

21 months agonsscash: main_test: use time.Since()
Simon Ruderich [Sun, 15 Dec 2019 14:52:49 +0000 (15:52 +0100)]
nsscash: main_test: use time.Since()

21 months agonsscash: main_test: add missing check for statePath
Simon Ruderich [Sun, 15 Dec 2019 14:51:08 +0000 (15:51 +0100)]
nsscash: main_test: add missing check for statePath

21 months agonsscash: main_test: use existing t variable instead of a.t
Simon Ruderich [Sun, 15 Dec 2019 14:50:27 +0000 (15:50 +0100)]
nsscash: main_test: use existing t variable instead of a.t

t is set at the beginning of each function.

21 months agonsscash: fix typos in comments
Simon Ruderich [Sun, 15 Dec 2019 14:50:10 +0000 (15:50 +0100)]
nsscash: fix typos in comments

21 months agotestdata: rename README to README.adoc
Simon Ruderich [Sun, 15 Dec 2019 14:48:59 +0000 (15:48 +0100)]
testdata: rename README to README.adoc

21 months agoREADME.adoc: fix asciidoc syntax
Simon Ruderich [Sun, 15 Dec 2019 10:38:11 +0000 (11:38 +0100)]
README.adoc: fix asciidoc syntax

Lists must be separated by an empty line

21 months agoREADME.adoc: reorder requirements
Simon Ruderich [Sun, 15 Dec 2019 10:37:40 +0000 (11:37 +0100)]
README.adoc: reorder requirements

21 months agonsscash: guard against unexpected 304
Simon Ruderich [Sun, 15 Dec 2019 10:19:33 +0000 (11:19 +0100)]
nsscash: guard against unexpected 304

A 304 (status not modified) from the server was always considered a
non-error even if we did not send a If-Modified-Since. This could hide
errors for buggy servers.

21 months ago.gitlab-ci.yml: use ci/run and switch to GOPATH-less build
Simon Ruderich [Sun, 15 Dec 2019 10:22:07 +0000 (11:22 +0100)]
.gitlab-ci.yml: use ci/run and switch to GOPATH-less build

The ca-certificates package is required for connections to
proxy.golang.org

21 months agoAdd build manifests for build.sr.ht
Simon Ruderich [Sun, 15 Dec 2019 10:04:11 +0000 (11:04 +0100)]
Add build manifests for build.sr.ht

Also add ci/run as helper script

21 months agonsscash: main_test: create state file in sub-directory
Simon Ruderich [Sun, 15 Dec 2019 09:34:38 +0000 (10:34 +0100)]
nsscash: main_test: create state file in sub-directory

This is the proper way to test what happens when this directory is not
writable. The previous solution was hacky.

21 months agoREADME.adoc, TODO.adoc: mention endian limitations
Simon Ruderich [Sun, 15 Dec 2019 08:17:17 +0000 (09:17 +0100)]
README.adoc, TODO.adoc: mention endian limitations

21 months agoREADME.adoc: misc updates
Simon Ruderich [Sun, 15 Dec 2019 07:52:48 +0000 (08:52 +0100)]
README.adoc: misc updates

21 months agonss/tests: rename variable
Simon Ruderich [Sun, 15 Dec 2019 07:50:05 +0000 (08:50 +0100)]
nss/tests: rename variable

21 months agoAdd TODO.adoc
Simon Ruderich [Sun, 15 Dec 2019 07:48:09 +0000 (08:48 +0100)]
Add TODO.adoc

21 months agoREADME: rename to README.adoc
Simon Ruderich [Sun, 15 Dec 2019 07:32:11 +0000 (08:32 +0100)]
README: rename to README.adoc

22 months agoREADME: misc updates
Simon Ruderich [Sun, 10 Nov 2019 10:13:58 +0000 (11:13 +0100)]
README: misc updates

2 years agoREADME: remove Debian Stretch
Simon Ruderich [Mon, 12 Aug 2019 06:33:07 +0000 (08:33 +0200)]
README: remove Debian Stretch

There are build problems with go generate (caused by stringer) in Debian
Stretch's backports version of Go.

2 years agoAdd go.mod and go.sum
Simon Ruderich [Mon, 12 Aug 2019 06:31:47 +0000 (08:31 +0200)]
Add go.mod and go.sum

2 years agoAdd .gitlab-ci.yml to run tests in Docker container
Simon Ruderich [Sat, 3 Aug 2019 18:18:35 +0000 (20:18 +0200)]
Add .gitlab-ci.yml to run tests in Docker container

2 years agonsscash: go fmt
Simon Ruderich [Sat, 3 Aug 2019 05:06:20 +0000 (07:06 +0200)]
nsscash: go fmt

2 years agonsscash: add "username"/"passsword" options for files
Simon Ruderich [Sat, 3 Aug 2019 05:04:41 +0000 (07:04 +0200)]
nsscash: add "username"/"passsword" options for files

2 years agonsscash: force UTC timezone for If-Modified-Since header
Simon Ruderich [Fri, 2 Aug 2019 19:04:25 +0000 (21:04 +0200)]
nsscash: force UTC timezone for If-Modified-Since header

This is not strictly required as lastModified is already stored in UTC
(servers use UTC for the Last-Modified header). However, it's good
practice and prevents copy & past errors in the future. See d71bfc6
("nsscash: main_test: fix Last-Modified/If-Modified-Since headers",
2019-08-02) for the details.

2 years agonsscash: main_test: test new server response which causes an update
Simon Ruderich [Fri, 2 Aug 2019 19:00:51 +0000 (21:00 +0200)]
nsscash: main_test: test new server response which causes an update

The existing tests only tested that a modified local version of the file
causes a download from the server. However, the modified local version
is caught by the checksum in the state file and does not verify that an
update from the server is properly applied. Thus, add this new test.

2 years agonsscash: main_test: fix Last-Modified/If-Modified-Since headers
Simon Ruderich [Fri, 2 Aug 2019 18:53:43 +0000 (20:53 +0200)]
nsscash: main_test: fix Last-Modified/If-Modified-Since headers

http.TimeFormat requires a time in UTC for a proper Last-Modified
header. Previously, the time was in CEST (my local timezone) which
caused all Last-Modified headers to have an offset of two hours. This
also hid a bug in the If-Modified-Since header handling: The last change
time must be truncated to seconds as the If-Modified-Since header has
only a second precision.

These bugs did not affect the current test cases. However, it affects
the test case which will be added in the next commit.

2 years agoREADME: clarify indices are not stored in separate files
Simon Ruderich [Fri, 2 Aug 2019 05:35:18 +0000 (07:35 +0200)]
README: clarify indices are not stored in separate files

2 years agonsscash: go fmt
Simon Ruderich [Fri, 2 Aug 2019 05:35:04 +0000 (07:35 +0200)]
nsscash: go fmt

2 years agonsscash: add "ca" option for files
Simon Ruderich [Thu, 1 Aug 2019 21:21:58 +0000 (23:21 +0200)]
nsscash: add "ca" option for files

Also run all main_test tests with HTTP and HTTPS.

2 years agonsscash: go fmt and rewrap comments
Simon Ruderich [Thu, 1 Aug 2019 21:08:05 +0000 (23:08 +0200)]
nsscash: go fmt and rewrap comments

2 years agonsscash: main_test: refactor in preparation for HTTPS
Simon Ruderich [Thu, 1 Aug 2019 21:06:56 +0000 (23:06 +0200)]
nsscash: main_test: refactor in preparation for HTTPS

2 years agonsscash: main_test: wrap overlong line
Simon Ruderich [Thu, 1 Aug 2019 20:16:13 +0000 (22:16 +0200)]
nsscash: main_test: wrap overlong line

2 years agonsscash: add basic tests for ParsePasswds()
Simon Ruderich [Thu, 1 Aug 2019 20:07:12 +0000 (22:07 +0200)]
nsscash: add basic tests for ParsePasswds()

2 years agonsscash: fix typo in test comment
Simon Ruderich [Sun, 14 Jul 2019 06:18:33 +0000 (08:18 +0200)]
nsscash: fix typo in test comment

2 years agoREADME: fix typo
Simon Ruderich [Sat, 29 Jun 2019 08:18:58 +0000 (10:18 +0200)]
README: fix typo

2 years agonsscash: main_test: add special tests
Simon Ruderich [Wed, 26 Jun 2019 12:13:31 +0000 (14:13 +0200)]
nsscash: main_test: add special tests

2 years agonsscash: main_test: add group tests
Simon Ruderich [Wed, 26 Jun 2019 12:13:02 +0000 (14:13 +0200)]
nsscash: main_test: add group tests

2 years agonsscash: main_test: add plain tests
Simon Ruderich [Wed, 26 Jun 2019 12:12:26 +0000 (14:12 +0200)]
nsscash: main_test: add plain tests

2 years agonsscash: main_test: add passwd tests
Simon Ruderich [Wed, 26 Jun 2019 12:11:29 +0000 (14:11 +0200)]
nsscash: main_test: add passwd tests

2 years agonsscash: main_test: add infrastructure and first basic test
Simon Ruderich [Wed, 26 Jun 2019 12:07:32 +0000 (14:07 +0200)]
nsscash: main_test: add infrastructure and first basic test

2 years agonsscash: file_test: restore log output after the test
Simon Ruderich [Wed, 26 Jun 2019 07:30:24 +0000 (09:30 +0200)]
nsscash: file_test: restore log output after the test

Otherwise this affects other test files as well.

2 years agoREADME: mention why write bits are removed from generated files
Simon Ruderich [Tue, 25 Jun 2019 08:07:45 +0000 (10:07 +0200)]
README: mention why write bits are removed from generated files

2 years agonsscash: remove write permissions of created files
Simon Ruderich [Mon, 17 Jun 2019 19:17:03 +0000 (21:17 +0200)]
nsscash: remove write permissions of created files

2 years agonsscash: test deployFile() sets permissions properly
Simon Ruderich [Mon, 17 Jun 2019 19:07:19 +0000 (21:07 +0200)]
nsscash: test deployFile() sets permissions properly

2 years agonss: remove pointer indirection in search_key's id member
Simon Ruderich [Mon, 17 Jun 2019 18:43:42 +0000 (20:43 +0200)]
nss: remove pointer indirection in search_key's id member

There's no reason to use a pointer here. Setting name to NULL already
marks that an id is to be used.

2 years agonss: reduce code duplication in _nss_cash_setpwent/_nss_cash_setgrent
Simon Ruderich [Mon, 17 Jun 2019 18:39:52 +0000 (20:39 +0200)]
nss: reduce code duplication in _nss_cash_setpwent/_nss_cash_setgrent

2 years agonsscash: convert: create file atomically
Simon Ruderich [Fri, 14 Jun 2019 18:28:29 +0000 (20:28 +0200)]
nsscash: convert: create file atomically

Previously the file was first truncated or created and then written to.
Although "convert" is not designed to be used for deployment, it is a
unexpected behavior.

2 years agonsscash: go fmt
Simon Ruderich [Fri, 14 Jun 2019 18:21:12 +0000 (20:21 +0200)]
nsscash: go fmt

2 years agonsscash: return error instead of calling log.Fatal()
Simon Ruderich [Fri, 14 Jun 2019 18:20:25 +0000 (20:20 +0200)]
nsscash: return error instead of calling log.Fatal()

2 years agonsscash: split main() into separate functions
Simon Ruderich [Fri, 14 Jun 2019 18:19:02 +0000 (20:19 +0200)]
nsscash: split main() into separate functions

2 years agonsscash: store and check hash of deployed files
Simon Ruderich [Thu, 13 Jun 2019 06:25:09 +0000 (08:25 +0200)]
nsscash: store and check hash of deployed files

The goal is to detect manual modifications of the deployed files. As we
store only the last modification in the state file and don't check the
deployed file itself, modifications go unnoticed.

An alternative would be to check the last modification time of the
deployed files. But a hash is safer as possible corruptions to the file
are detected as well.

2 years agonsscash: write state on each successful run
Simon Ruderich [Thu, 13 Jun 2019 05:58:04 +0000 (07:58 +0200)]
nsscash: write state on each successful run

2 years agoMakefile: remove recursion from go commands
Simon Ruderich [Wed, 12 Jun 2019 07:30:35 +0000 (09:30 +0200)]
Makefile: remove recursion from go commands

All go files are in the top level directory.

2 years agonss: add todo
Simon Ruderich [Wed, 12 Jun 2019 07:20:10 +0000 (09:20 +0200)]
nss: add todo

2 years agoREADME: use proper comment character for TOML files
Simon Ruderich [Wed, 12 Jun 2019 06:51:30 +0000 (08:51 +0200)]
README: use proper comment character for TOML files

2 years agoMakefile: run go test in test target, not all target
Simon Ruderich [Wed, 12 Jun 2019 06:51:13 +0000 (08:51 +0200)]
Makefile: run go test in test target, not all target

2 years agonsscash: go fmt
Simon Ruderich [Wed, 12 Jun 2019 06:50:39 +0000 (08:50 +0200)]
nsscash: go fmt

2 years agonsscash: replace %s with %v in format string for File.Type
Simon Ruderich [Wed, 12 Jun 2019 06:48:16 +0000 (08:48 +0200)]
nsscash: replace %s with %v in format string for File.Type

File.Type is an int value with a stringer go:generate statement. Using
%s breaks running `go test` (which runs `go vet`) before running `go
generate`. Using %v has the same result and uses the stringified version
when available.

2 years agonsscash: report error for passwd/group without trailing newline
Simon Ruderich [Wed, 12 Jun 2019 06:45:49 +0000 (08:45 +0200)]
nsscash: report error for passwd/group without trailing newline

Previously this case was hidden because ReadString() can return a string
and an EOF error. To prevent this issue from going unnoticed error out.

2 years agonss: Makefile: don't link against asan
Simon Ruderich [Tue, 11 Jun 2019 09:05:49 +0000 (11:05 +0200)]
nss: Makefile: don't link against asan

This is not necessary and was only a hack to handle non-empty LD_PRELOAD
environment variables. We explicitly empty LD_PRELOAD before calling our
test binaries.

2 years agoCheck size limits and abort if they are violated
Simon Ruderich [Tue, 11 Jun 2019 09:05:08 +0000 (11:05 +0200)]
Check size limits and abort if they are violated

Also document them in the README and add tests.

2 years agonsscash: handle errors in SerializePasswd(), SerializeGroup()
Simon Ruderich [Tue, 11 Jun 2019 08:56:44 +0000 (10:56 +0200)]
nsscash: handle errors in SerializePasswd(), SerializeGroup()

No such errors are defined yet.

2 years agonsscash: support longer lines in passwd/group files
Simon Ruderich [Tue, 11 Jun 2019 08:53:43 +0000 (10:53 +0200)]
nsscash: support longer lines in passwd/group files

bufio.Scanner has an internal limit on the maximum token (= line)
length. We want to support larger lines in the future.

2 years agonss: tests: sort included headers
Simon Ruderich [Tue, 11 Jun 2019 07:48:05 +0000 (09:48 +0200)]
nss: tests: sort included headers

2 years agonss: Makefile: build libcash_test.so in tests/
Simon Ruderich [Mon, 10 Jun 2019 21:53:49 +0000 (23:53 +0200)]
nss: Makefile: build libcash_test.so in tests/

Prevents accidentally copying the test library instead of the actual NSS
library.

2 years agoREADME: document practices and tested systems
Simon Ruderich [Mon, 10 Jun 2019 21:40:00 +0000 (23:40 +0200)]
README: document practices and tested systems

2 years agonsscash: improve comments
Simon Ruderich [Mon, 10 Jun 2019 21:36:05 +0000 (23:36 +0200)]
nsscash: improve comments

2 years agonsscash: add alignBufferTo() helper
Simon Ruderich [Mon, 10 Jun 2019 21:34:45 +0000 (23:34 +0200)]
nsscash: add alignBufferTo() helper

2 years agonss: improve comments
Simon Ruderich [Mon, 10 Jun 2019 21:00:25 +0000 (23:00 +0200)]
nss: improve comments

2 years agonss: gr/pw: re-used variable
Simon Ruderich [Mon, 10 Jun 2019 20:59:08 +0000 (22:59 +0200)]
nss: gr/pw: re-used variable

Now that the key argument is const we can use this to reduces code
duplication.

2 years agonss: gr/pw: use key->name for NULL check
Simon Ruderich [Mon, 10 Jun 2019 20:57:40 +0000 (22:57 +0200)]
nss: gr/pw: use key->name for NULL check

This is consistent with search.c's bsearch_callback() which also checks
key->name first.

2 years agonss: gr/pw: make data const
Simon Ruderich [Mon, 10 Jun 2019 20:56:17 +0000 (22:56 +0200)]
nss: gr/pw: make data const

We cannot modify it anyway.

2 years agonss: search: make search_key argument const
Simon Ruderich [Mon, 10 Jun 2019 20:48:39 +0000 (22:48 +0200)]
nss: search: make search_key argument const

2 years agonss: search.h: re-order struct file members
Simon Ruderich [Mon, 10 Jun 2019 20:41:48 +0000 (22:41 +0200)]
nss: search.h: re-order struct file members

2 years agonss: file.h: re-order struct file members
Simon Ruderich [Mon, 10 Jun 2019 20:27:48 +0000 (22:27 +0200)]
nss: file.h: re-order struct file members

2 years agonss: merge cash.h into file.h
Simon Ruderich [Mon, 10 Jun 2019 20:26:00 +0000 (22:26 +0200)]
nss: merge cash.h into file.h

file.h is a more logical place anyway and this gets rid of a useless
header file.

2 years agonss: simplify initialization of struct file in map_file()
Simon Ruderich [Mon, 10 Jun 2019 20:14:50 +0000 (22:14 +0200)]
nss: simplify initialization of struct file in map_file()

It's not necessary to initialize ->fd at the beginning of map_file() as
the call to open(2) will overwrite it anyway.

Also adapt a check for a valid file descriptor. Although POSIX states
that open(2) returns -1 on error, there is no reason to hard-code this
constant. Instead, check for any negative value.

2 years agoREADME: minor updates and fixes
Simon Ruderich [Sun, 9 Jun 2019 12:25:52 +0000 (14:25 +0200)]
README: minor updates and fixes

2 years agonss: Makefile: fix typo in LD_PRELOAD variable name
Simon Ruderich [Sun, 9 Jun 2019 12:11:31 +0000 (14:11 +0200)]
nss: Makefile: fix typo in LD_PRELOAD variable name

2 years agoREADME: add requirements and usage instructions
Simon Ruderich [Sat, 8 Jun 2019 14:26:17 +0000 (16:26 +0200)]
README: add requirements and usage instructions

2 years agoMakefile: run all and clean in nss/ as well
Simon Ruderich [Sat, 8 Jun 2019 13:57:23 +0000 (15:57 +0200)]
Makefile: run all and clean in nss/ as well

This way a single `make all` builds the whole project.

2 years agoMakefile: add test target
Simon Ruderich [Sat, 8 Jun 2019 13:55:58 +0000 (15:55 +0200)]
Makefile: add test target

2 years agonsscache: add comment
Simon Ruderich [Sat, 8 Jun 2019 13:54:35 +0000 (15:54 +0200)]
nsscache: add comment

2 years agonss: tests: fix typo in comment
Simon Ruderich [Sat, 8 Jun 2019 13:51:44 +0000 (15:51 +0200)]
nss: tests: fix typo in comment

2 years agonsscash: use WriteByte() instead of Write() with cast
Simon Ruderich [Sat, 8 Jun 2019 13:50:34 +0000 (15:50 +0200)]
nsscash: use WriteByte() instead of Write() with cast

Less to type and easier to read.

The old solution used '0' to pad instead 0. This isn't an issue as these
bytes are not used. But fix it as well.

2 years agonsscash: improve index sanity check
Simon Ruderich [Sat, 8 Jun 2019 13:49:55 +0000 (15:49 +0200)]
nsscash: improve index sanity check

This ensures that the index has the proper size and is not missing any
entries.

2 years agoAdd support for group files
Simon Ruderich [Sat, 8 Jun 2019 13:49:33 +0000 (15:49 +0200)]
Add support for group files