Skip to content

fcopy(): Add function, and use it instead of its pattern#1499

Draft
alejandro-colomar wants to merge 3 commits intoshadow-maint:masterfrom
alejandro-colomar:fcopy
Draft

fcopy(): Add function, and use it instead of its pattern#1499
alejandro-colomar wants to merge 3 commits intoshadow-maint:masterfrom
alejandro-colomar:fcopy

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 <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar <alx@kernel.org>
     +// SPDX-License-Identifier: BSD-3-Clause
     +
     +
    @@ lib/fs/copy/fcopy.c (new)
     
      ## lib/fs/copy/fcopy.h (new) ##
     @@
    -+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
    ++// SPDX-FileCopyrightText: 2026, Alejandro Colomar <alx@kernel.org>
     +// 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
v2d
  • Rebase
$ git rd 
1:  0decb1cf3de4 = 1:  aa35b48a13e4 lib/fs/copy/: fcopy(): Add function to copy the contents of a file into another
2:  27a3472c6bbd = 2:  b0d9421e493c lib/, src/: Use fcopy() instead of its pattern
3:  8f22b1d3bfab = 3:  4049e3953483 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 3 times, most recently from 27d3806 to 8f22b1d Compare January 15, 2026 13:02
@alejandro-colomar alejandro-colomar linked an issue Jan 15, 2026 that may be closed by this pull request
@alejandro-colomar alejandro-colomar marked this pull request as draft February 20, 2026 00:23
…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 <alx@kernel.org>
No changes intended.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
Suggested-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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