Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 14, 2026

Cc: @stoeckmann


Revisions:

v1b
  • Rebase
$ git rd 
1:  b80a2811e = 1:  64af7e26e lib/fs/copy/: fcopy(): Add function to copy the contents of a file into another
2:  9ce666a3d = 2:  ff6f6933b lib/, src/: Use fcopy() instead of its pattern
v2
  • Add mask for mode_t in vipw(8) surrounding code. [@stoeckmann ]
$ git rd 
1:  64af7e26e = 1:  64af7e26e lib/fs/copy/: fcopy(): Add function to copy the contents of a file into another
2:  ff6f6933b = 2:  ff6f6933b lib/, src/: Use fcopy() instead of its pattern
-:  --------- > 3:  3bdea8b75 src/vipw.c: create_backup_file(): Use mask for mode_t
v2b
  • Fix copyright year.
$ git rd 
1:  64af7e26e ! 1:  81ba76135 lib/fs/copy/: fcopy(): Add function to copy the contents of a file into another
    @@ lib/Makefile.am: libshadow_la_SOURCES = \
     
      ## lib/fs/copy/fcopy.c (new) ##
     @@
    -+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]>
    ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar <[email protected]>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
     +
    @@ lib/fs/copy/fcopy.c (new)
     
      ## lib/fs/copy/fcopy.h (new) ##
     @@
    -+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]>
    ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar <[email protected]>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
     +
2:  ff6f6933b = 2:  b37bbc39a lib/, src/: Use fcopy() instead of its pattern
3:  3bdea8b75 = 3:  27d38068a src/vipw.c: create_backup_file(): Use mask for mode_t
v2c
  • Rebase
$ git rd 
1:  81ba76135 = 1:  0decb1cf3 lib/fs/copy/: fcopy(): Add function to copy the contents of a file into another
2:  b37bbc39a = 2:  27a3472c6 lib/, src/: Use fcopy() instead of its pattern
3:  27d38068a = 3:  8f22b1d3b src/vipw.c: create_backup_file(): Use mask for mode_t

@alejandro-colomar alejandro-colomar force-pushed the fcopy branch 2 times, most recently from f4c01e9 to 9ce666a Compare January 14, 2026 13:48
@alejandro-colomar alejandro-colomar marked this pull request as ready for review January 14, 2026 14:19
@alejandro-colomar alejandro-colomar force-pushed the fcopy branch 2 times, most recently from 3bdea8b to 27d3806 Compare January 15, 2026 13:01
…to another

We could probably implement this more efficiently, but this is simple
and works.  It is based on code from lib/commonio.c:create_backup().

Verify that the destination file is empty before writing to it.  All
callers have an empty file, but being a generic API, let's verify
anyway.  If we didn't verify, and the file was larger than the source
file, then we'd end up with a mix of the old and new contents.

Signed-off-by: Alejandro Colomar <[email protected]>
No changes intended.

Signed-off-by: Alejandro Colomar <[email protected]>
This is consistent with fmkstemp_set_perms() in lib/commonio.c.

This avoids accidentally granting dangerous permissions.

Closes: <shadow-maint#1500>
Reported-by: Alejandro Colomar <[email protected]>
Suggested-by: Tobias Stoeckmann <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar alejandro-colomar linked an issue Jan 15, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mode_t mask in backups

1 participant