lib/tcbfuncs: operate on file descriptor rather than path

This commit is contained in:
Christian Göttsche
2023-02-28 16:05:09 +01:00
committed by Iker Pedrosa
parent f45498a6c2
commit 1aaa4ec5ba
+5 -4
View File
@@ -527,7 +527,7 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid)
struct stat tcbdir_stat;
gid_t shadowgid, authgid;
struct group *gr;
int fd;
int fd = -1;
shadowtcb_status ret = SHADOWTCB_FAILURE;
if (!getdef_bool ("USE_TCB")) {
@@ -566,14 +566,13 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid)
shadow_progname, shadow, strerror (errno));
goto out_free;
}
close (fd);
if (chown (shadow, 0, authgid) != 0) {
if (fchown (fd, 0, authgid) != 0) {
fprintf (shadow_logfd,
_("%s: Cannot change owner of %s: %s\n"),
shadow_progname, shadow, strerror (errno));
goto out_free;
}
if (chmod (shadow, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) {
if (fchmod (fd, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) {
fprintf (shadow_logfd,
_("%s: Cannot change mode of %s: %s\n"),
shadow_progname, shadow, strerror (errno));
@@ -597,6 +596,8 @@ shadowtcb_status shadowtcb_create (const char *name, uid_t uid)
}
ret = SHADOWTCB_SUCCESS;
out_free:
if (fd != -1)
close(fd);
free (dir);
free (shadow);
return ret;