]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login-utils: Use _PATH macros
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 7 Jan 2026 16:09:03 +0000 (17:09 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 7 Jan 2026 16:16:13 +0000 (17:16 +0100)
Avoid defining own macros which could be toggled with DEBUG.
Also add backup passwd file suffix to pathnames.h.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
include/pathnames.h
login-utils/chfn.c
login-utils/setpwnam.c
login-utils/setpwnam.h
login-utils/vipw.c

index 036f365fd08f1051494c4eb32d5db0ed4cba0318..c6a7c57d822233b72e04c1445637a9607b0d64b3 100644 (file)
@@ -62,6 +62,7 @@
 #define _PATH_GROUP            "/etc/group"
 #define _PATH_SHADOW_PASSWD    "/etc/shadow"
 #define _PATH_SHELLS           "/etc/shells"
+#define _PATH_PASSWDBAK_SUFFIX  "-"
 
 #ifndef _PATH_TMP
 # define _PATH_TMP             "/tmp/"
index 8577916a2865cf4247585721aa4729544b7a9a1d..6a529ea117a9556c00a5d3e81082c2d8e87e4fb6 100644 (file)
@@ -38,6 +38,7 @@
 #include "closestream.h"
 #include "islocal.h"
 #include "nls.h"
+#include "pathnames.h"
 #include "setpwnam.h"
 #include "strutils.h"
 #include "xalloc.h"
index e48e4cedc0595cb9f5f48b96f18909fb35c942a2..a1edfc1f83b99f0f608a98fb4c82bb64f0946016 100644 (file)
@@ -61,6 +61,7 @@
 #include "c.h"
 #include "fileutils.h"
 #include "closestream.h"
+#include "pathnames.h"
 #include "setpwnam.h"
 
 static void pw_init(void);
@@ -94,7 +95,7 @@ int setpwnam(struct passwd *pwd, const char *prefix)
        if (lckpwdf() < 0)
                goto fail;
        locked = 1;
-       pwf = fopen(PASSWD_FILE, "r");
+       pwf = fopen(_PATH_PASSWD, "r");
        if (!pwf)
                goto fail;
 
@@ -138,11 +139,11 @@ int setpwnam(struct passwd *pwd, const char *prefix)
        }
 
        /* we don't care if we can't remove the backup file */
-       unlink(PASSWD_FILE "-");
+       unlink(_PATH_PASSWD _PATH_PASSWDBAK_SUFFIX);
        /* we don't care if we can't create the backup file */
-       ignore_result(link(PASSWD_FILE, PASSWD_FILE "-"));
+       ignore_result(link(_PATH_PASSWD, _PATH_PASSWD _PATH_PASSWDBAK_SUFFIX));
        /* we DO care if we can't rename to the passwd file */
-       if (rename(tmpname, PASSWD_FILE) < 0)
+       if (rename(tmpname, _PATH_PASSWD) < 0)
                goto fail;
        /* finally:  success */
        ulckpwdf();
index 95785923f6351778004f3c213457c7abab03d928..85bf39a024a5e5e68365e32dc35b580847fa3e75 100644 (file)
 #ifndef UTIL_LINUX_SETPWNAM_H
 #define UTIL_LINUX_SETPWNAM_H
 
-#include "pathnames.h"
-
-#ifndef DEBUG
-# define PASSWD_FILE   _PATH_PASSWD
-# define GROUP_FILE    _PATH_GROUP
-# define SHADOW_FILE   _PATH_SHADOW_PASSWD
-# define SGROUP_FILE   _PATH_GSHADOW
-#else
-# define PASSWD_FILE   "/tmp/passwd"
-# define GROUP_FILE    "/tmp/group"
-# define SHADOW_FILE   "/tmp/shadow"
-# define SGROUP_FILE   "/tmp/gshadow"
-#endif
-
 extern int setpwnam (struct passwd *pwd, const char *prefix);
 
 #endif /* UTIL_LINUX_SETPWNAM_H */
index 30a4e17011781c684d28168a8e003aeca445f39f..74e1706852f525724e85cbfa7df64dbcb2be9680 100644 (file)
@@ -67,7 +67,7 @@
 #include "fileutils.h"
 #include "closestream.h"
 #include "nls.h"
-#include "setpwnam.h"
+#include "pathnames.h"
 #include "strutils.h"
 #include "xalloc.h"
 #include "rpmatch.h"
@@ -145,7 +145,7 @@ static void pw_write(void)
 {
        char tmp[FILENAMELEN + 4];
 
-       snprintf(tmp, sizeof(tmp), "%s%s", orig_file, "-");
+       snprintf(tmp, sizeof(tmp), "%s%s", orig_file, _PATH_PASSWDBAK_SUFFIX);
        unlink(tmp);
 
        if (link(orig_file, tmp))
@@ -325,10 +325,10 @@ int main(int argc, char *argv[])
 
        if (!strcmp(program_invocation_short_name, "vigr")) {
                program = VIGR;
-               xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file));
+               xstrncpy(orig_file, _PATH_GROUP, sizeof(orig_file));
        } else {
                program = VIPW;
-               xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file));
+               xstrncpy(orig_file, _PATH_PASSWD, sizeof(orig_file));
        }
 
        while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) {
@@ -345,9 +345,9 @@ int main(int argc, char *argv[])
        edit_file(0);
 
        if (program == VIGR)
-               xstrncpy(orig_file, SGROUP_FILE, sizeof(orig_file));
+               xstrncpy(orig_file, _PATH_GSHADOW, sizeof(orig_file));
        else
-               xstrncpy(orig_file, SHADOW_FILE, sizeof(orig_file));
+               xstrncpy(orig_file, _PATH_SHADOW, sizeof(orig_file));
 
        if (access(orig_file, F_OK) == 0) {
                char response[80];