Skip to content

Commit b34974d

Browse files
src/vipw.c: vipwedit(): Set fileedit closer to its use
Signed-off-by: Alejandro Colomar <alx@kernel.org>
1 parent fead1f4 commit b34974d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/vipw.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,10 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool))
219219
if (shadowtcb_drop_priv () == SHADOWTCB_FAILURE) {
220220
vipwexit (_("failed to drop privileges"), errno, 1);
221221
}
222-
stprintf_a(fileedit,
223-
TCB_DIR "/" SHADOWTCB_SCRATCHDIR "/.%s.shadow.%s.XXXXXX",
224-
Prog, user);
225-
} else {
226-
#endif /* WITH_TCB */
227-
stprintf_a(fileedit, "/etc/.%s.XXXXXX", Prog);
228-
#ifdef WITH_TCB
229222
}
230-
#endif /* WITH_TCB */
223+
#endif
231224
unlock = file_unlock;
232225
filename = file;
233-
fileeditname = fileedit;
234226

235227
if (access (file, F_OK) != 0) {
236228
vipwexit (file, 1, 1);
@@ -274,6 +266,16 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool))
274266
if (NULL == f) {
275267
vipwexit (file, 1, 1);
276268
}
269+
#ifdef WITH_TCB
270+
if (tcb_mode) {
271+
stprintf_a(fileedit,
272+
TCB_DIR "/" SHADOWTCB_SCRATCHDIR "/.%s.shadow.%s.XXXXXX",
273+
Prog, user);
274+
} else
275+
#endif
276+
{
277+
stprintf_a(fileedit, "/etc/.%s.XXXXXX", Prog);
278+
}
277279
#ifdef WITH_TCB
278280
if (tcb_mode && (shadowtcb_gain_priv () == SHADOWTCB_FAILURE))
279281
vipwexit (_("failed to gain privileges"), errno, 1);
@@ -282,6 +284,7 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (bool))
282284
vipwexit (_("Couldn't make backup"), errno, 1);
283285
}
284286
(void) fclose (f);
287+
fileeditname = fileedit;
285288
createedit = true;
286289

287290
editor = getenv ("VISUAL");

0 commit comments

Comments
 (0)