Skip to content

src/vipw.c: Superfluous file copy in TCB mode? #1507

@alejandro-colomar

Description

@alejandro-colomar

shadow/src/vipw.c

Lines 414 to 443 in a49d2ac

#ifdef WITH_TCB
if (tcb_mode) {
f = fopen (fileedit, "r");
if (NULL == f) {
vipwexit (_("failed to open scratch file"), errno, 1);
}
if (unlink (fileedit) != 0) {
vipwexit (_("failed to unlink scratch file"), errno, 1);
}
if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) {
vipwexit (_("failed to drop privileges"), errno, 1);
}
if (stat (file, &st1) != 0) {
vipwexit (_("failed to stat edited file"), errno, 1);
}
to_rename = aprintf("%s,XXXXXX", file);
if (to_rename == NULL)
vipwexit (_("aprintf() failed"), errno, 1);
if (create_backup_file (f, to_rename, &st1) != 0) {
free(to_rename);
vipwexit (_("failed to create backup file"), errno, 1);
}
(void) fclose (f);
} else {
#endif /* WITH_TCB */
to_rename = fileedit;
#ifdef WITH_TCB
}
#endif /* WITH_TCB */

I'm trying to understand this code, but can't make sense of it.

  • We already created, edited, and closed fileedit, which is the temporary file used by the editor.
  • We now open it again, unlink it, drop privileges, and copy the entire file to a new different temporary file.

Later we will rename the temporary file to file.

So, my question is, what is the point of this entire block? Why do we need a second temporary file? Can't we directly rename the temporary file used by the editor, like we do in the non-TCB case? Am I missing some detail inherent to TCB that makes this block necessary or beneficial?

Cc: @stoeckmann , @sem-gh, @ldv-alt

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions