]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
*/: s/STRTCPY/strtcpy_a/
authorAlejandro Colomar <alx@kernel.org>
Tue, 14 Oct 2025 10:58:00 +0000 (12:58 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 28 Nov 2025 02:50:48 +0000 (20:50 -0600)
This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 files changed:
lib/console.c
lib/failure.c
lib/log.c
lib/string/README
lib/string/strcpy/strtcpy.h
src/chage.c
src/chfn.c
src/chsh.c
src/gpasswd.c
src/login.c
src/passwd.c
src/su.c
tests/unit/test_strtcpy.c

index 7ce1a60ee38f29828fad4fb5f0bf36fe1cebceec..66cec24533fcda40e55ba3e0267fd2629b3d2c7c 100644 (file)
@@ -52,7 +52,7 @@ is_listed(const char *cfgin, const char *tty, bool def)
        if (*cons != '/') {
                char *pbuf;
 
-               STRTCPY(buf, cons);
+               strtcpy_a(buf, cons);
                pbuf = buf;
                while (NULL != (s = strsep(&pbuf, ":"))) {
                        if (streq(s, tty)) {
index a0307e65e052ca7c2940f06f1e6044e50807ca2e..924c1925989f4122cbec14b924091a69ac837327 100644 (file)
@@ -81,7 +81,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
                fl->fail_cnt++;
        }
 
-       STRTCPY(fl->fail_line, tty);
+       strtcpy_a(fl->fail_line, tty);
        fl->fail_time = time(NULL);
 
        /*
index 10da612b94ce038676aa3ad7a8441775d132a541..d812b41293f823e56de4172300024563a66cda20 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -81,7 +81,7 @@ void dolastlog (
        ll_time = newlog.ll_time;
        ll_time = time(NULL);
        newlog.ll_time = ll_time;
-       STRTCPY(newlog.ll_line, line);
+       strtcpy_a(newlog.ll_line, line);
 #if HAVE_LL_HOST
        strncpy_a(newlog.ll_host, host);
 #endif
index c2a7f2251c0144b18128783ea7981c9ce917303d..0c7c4b3f41c1896e076bb5758b393a9fd4c392c1 100644 (file)
@@ -186,7 +186,7 @@ strcpy/ - String copying
        This is what the Linux kernel calls strscpy().
        If you need more than one call to form a string,
        use stpecpy() instead.
-    STRTCPY()
+    strtcpy_a()
        Like strtcpy(), but takes an array.
 
     strtcat()  // Unimplemented
index d14e27f29901064b858138ae23df66d876caf6e5..a440bcdfb327adef390b1faa3678ee670163f507 100644 (file)
 #include "sizeof.h"
 
 
-/*
- * SYNOPSIS
- *     [[gnu::null_terminated_string_arg(2)]]
- *     int STRTCPY(char dst[restrict], const char *restrict src);
- *
- * ARGUMENTS
- *     dst     Destination buffer where to copy a string.
- *     src     Source string to be copied into dst.
- *
- * DESCRIPTION
- *     This macro copies the string pointed to by src, into a string
- *     at the buffer pointed to by dst.  If the destination buffer,
- *     isn't large enough to hold the copy, the resulting string is
- *     truncated.  The size of the buffer is calculated internally via
- *     countof().
- *
- * RETURN VALUE
- *     -1      If this call truncated the resulting string.
- *
- *     strlen(dst)
- *             On success.
- *
- * ERRORS
- *     This function doesn't set errno.
- */
-
-
-#define STRTCPY(dst, src)  strtcpy(dst, src, countof(dst))
+// strtcpy_a - string truncate copy array
+#define strtcpy_a(dst, src)  strtcpy(dst, src, countof(dst))
 
 
 ATTR_STRING(2)
@@ -52,6 +26,7 @@ inline ssize_t strtcpy(char *restrict dst, const char *restrict src,
     size_t dsize);
 
 
+// strtcpy - string truncate copy
 inline ssize_t
 strtcpy(char *restrict dst, const char *restrict src, size_t dsize)
 {
index d1b04b4dda39de03664a0618354621104e067a50..f2500736f04587bde319d5addf98405c9aa2333c 100644 (file)
@@ -793,7 +793,7 @@ int main (int argc, char **argv)
                fail_exit (E_NOPERM, process_selinux);
        }
 
-       STRTCPY(user_name, pw->pw_name);
+       strtcpy_a(user_name, pw->pw_name);
 #ifdef WITH_TCB
        if (shadowtcb_set_user (pw->pw_name) == SHADOWTCB_FAILURE) {
                fail_exit (E_NOPERM, process_selinux);
index acc21a985de7cb7a7ba5fb8a6ee54d54c3fc5b35..2fe99ac197a28d7ffba01c453e189184a392f9c2 100644 (file)
@@ -244,7 +244,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                                exit (E_NOPERM);
                        }
                        fflg = true;
-                       STRTCPY(fullnm, optarg);
+                       strtcpy_a(fullnm, optarg);
                        break;
                case 'h':
                        if (!may_change_field ('h')) {
@@ -253,7 +253,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                                exit (E_NOPERM);
                        }
                        hflg = true;
-                       STRTCPY(homeph, optarg);
+                       strtcpy_a(homeph, optarg);
                        break;
                case 'o':
                        if (!amroot) {
@@ -267,7 +267,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                                         _("%s: fields too long\n"), Prog);
                                exit (E_NOPERM);
                        }
-                       STRTCPY(slop, optarg);
+                       strtcpy_a(slop, optarg);
                        break;
                case 'r':
                        if (!may_change_field ('r')) {
@@ -276,7 +276,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                                exit (E_NOPERM);
                        }
                        rflg = true;
-                       STRTCPY(roomno, optarg);
+                       strtcpy_a(roomno, optarg);
                        break;
                case 'R': /* no-op, handled in process_root_flag () */
                        flags->chroot = true;
@@ -291,7 +291,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                                exit (E_NOPERM);
                        }
                        wflg = true;
-                       STRTCPY(workph, optarg);
+                       strtcpy_a(workph, optarg);
                        break;
                default:
                        usage (E_USAGE);
@@ -483,7 +483,7 @@ static void get_old_fields (const char *gecos)
        char        old_gecos[BUFSIZ];
        const char  *f;
 
-       STRTCPY(old_gecos, gecos);
+       strtcpy_a(old_gecos, gecos);
        p = old_gecos;
 
        f = strsep(&p, ",");
index bb65a82d614ad6d6f71baaca5765073c2bf35f4f..ce5f5b46e3dbfed8983302ff66fc1146bc5877be 100644 (file)
@@ -242,7 +242,7 @@ static void process_flags (int argc, char **argv, struct option_flags *flags)
                        break;
                case 's':
                        sflg = true;
-                       STRTCPY(loginsh, optarg);
+                       strtcpy_a(loginsh, optarg);
                        break;
                default:
                        usage (E_USAGE);
@@ -524,7 +524,7 @@ int main (int argc, char **argv)
         * file, or use the value from the command line.
         */
        if (!sflg) {
-               STRTCPY(loginsh, pw->pw_shell);
+               strtcpy_a(loginsh, pw->pw_shell);
        }
 
        /*
index 1224d80a8970354eb29c08c772bc7bcfea99dc9a..14ffedb81e58f8f252145d7213388e3fe53d29b6 100644 (file)
@@ -822,7 +822,7 @@ static void change_passwd (struct group *gr)
                        exit (1);
                }
 
-               STRTCPY(pass, cp);
+               strtcpy_a(pass, cp);
                erase_pass (cp);
                cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
index dfc0f96c6f2fbf37097c3252b661f23fc938811a..2fa9407484da3f7db86a2696957dcd2a962fc8da 100644 (file)
@@ -517,7 +517,7 @@ int main (int argc, char **argv)
        if (NULL == tmptty) {
                tmptty = "UNKNOWN";
        }
-       STRTCPY(tty, tmptty);
+       strtcpy_a(tty, tmptty);
 
 #ifndef USE_PAM
        is_console = console (tty);
@@ -646,7 +646,7 @@ int main (int argc, char **argv)
                if (gethostname (hostn, sizeof (hostn)) == 0) {
                        stprintf_a(loginprompt, _("%s login: "), hostn);
                } else {
-                       STRTCPY(loginprompt, _("login: "));
+                       strtcpy_a(loginprompt, _("login: "));
                }
 
                retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);
index c44f404a31871e828406cf31435493d2483ac215..f6c4f47a413fbcb5e67c6bbb13059d33c772afd1 100644 (file)
@@ -233,7 +233,7 @@ static int new_password (const struct passwd *pw)
                                        pw->pw_name);
                        return -1;
                }
-               STRTCPY(orig, clear);
+               strtcpy_a(orig, clear);
                erase_pass (clear);
                strzero (cipher);
        } else {
@@ -292,7 +292,7 @@ static int new_password (const struct passwd *pw)
                if (NULL == cp) {
                        return -1;
                }
-               ret = STRTCPY (pass, cp);
+               ret = strtcpy_a(pass, cp);
                erase_pass (cp);
                if (ret == -1) {
                        (void) fputs (_("Password is too long.\n"), stderr);
@@ -311,7 +311,7 @@ static int new_password (const struct passwd *pw)
                        if (warned && !streq(pass, cp)) {
                                warned = false;
                        }
-                       ret = STRTCPY (pass, cp);
+                       ret = strtcpy_a(pass, cp);
                        erase_pass (cp);
                        if (ret == -1) {
                                (void) fputs (_("Password is too long.\n"), stderr);
@@ -373,7 +373,7 @@ static int new_password (const struct passwd *pw)
                return -1;
        }
 
-       STRTCPY(crypt_passwd, cp);
+       strtcpy_a(crypt_passwd, cp);
        return 0;
 }
 
@@ -1065,7 +1065,7 @@ main(int argc, char **argv)
                 * If there are no other flags, just change the password.
                 */
                if (!anyflag) {
-                       STRTCPY(crypt_passwd, cp);
+                       strtcpy_a(crypt_passwd, cp);
 
                        /*
                         * See if the user is permitted to change the password.
index 2cfb2cf56a43ac90ceaf5979eaa9d36e282795be..5ba80e64904f6ff2644b2cfc7db781aaa79c4724 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -686,7 +686,7 @@ static /*@only@*/struct passwd * do_check_perms (void)
                SYSLOG ((LOG_INFO,
                         "Change user from '%s' to '%s' as requested by PAM",
                         name, tmp_name));
-               if (STRTCPY(name, tmp_name) == -1) {
+               if (strtcpy_a(name, tmp_name) == -1) {
                        fprintf (stderr, _("Overlong user name '%s'\n"),
                                 tmp_name);
                        SYSLOG ((LOG_NOTICE, "Overlong user name '%s'",
@@ -785,7 +785,7 @@ save_caller_context(void)
                         (unsigned long) caller_uid));
                su_failure (caller_tty, true); /* unknown target UID*/
        }
-       STRTCPY(caller_name, pw->pw_name);
+       strtcpy_a(caller_name, pw->pw_name);
 
 #ifndef USE_PAM
 #ifdef SU_ACCESS
@@ -861,7 +861,7 @@ static void process_flags (int argc, char **argv)
        }
 
        if (optind < argc) {
-               STRTCPY(name, argv[optind++]);  /* use this login id */
+               strtcpy_a(name, argv[optind++]);  /* use this login id */
        }
        if (streq(name, "")) {          /* use default user */
                struct passwd *root_pw = getpwnam ("root");
index 6b793fcbcb99b4766f3f8b6c48bc65ba72c06244..5e292caaf80b4fef454cbefbbfd5685925d77b43 100644 (file)
 #include "string/strcpy/strtcpy.h"
 
 
-static void test_STRTCPY_trunc(void **state);
-static void test_STRTCPY_ok(void **state);
+static void test_strtcpy_a_trunc(void **state);
+static void test_strtcpy_a_ok(void **state);
 
 
 int
 main(void)
 {
     const struct CMUnitTest  tests[] = {
-        cmocka_unit_test(test_STRTCPY_trunc),
-        cmocka_unit_test(test_STRTCPY_ok),
+        cmocka_unit_test(test_strtcpy_a_trunc),
+        cmocka_unit_test(test_strtcpy_a_ok),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
@@ -35,33 +35,33 @@ main(void)
 
 
 static void
-test_STRTCPY_trunc(void **state)
+test_strtcpy_a_trunc(void **state)
 {
        char  buf[countof("foo")];
 
        // Test that we're not returning SIZE_MAX
-       assert_true(STRTCPY(buf, "fooo") < 0);
+       assert_true(strtcpy_a(buf, "fooo") < 0);
        assert_string_equal(buf, "foo");
 
-       assert_int_equal(STRTCPY(buf, "barbaz"), -1);
+       assert_int_equal(strtcpy_a(buf, "barbaz"), -1);
        assert_string_equal(buf, "bar");
 }
 
 
 static void
-test_STRTCPY_ok(void **state)
+test_strtcpy_a_ok(void **state)
 {
        char  buf[countof("foo")];
 
-       assert_int_equal(STRTCPY(buf, "foo"), strlen("foo"));
+       assert_int_equal(strtcpy_a(buf, "foo"), strlen("foo"));
        assert_string_equal(buf, "foo");
 
-       assert_int_equal(STRTCPY(buf, "fo"), strlen("fo"));
+       assert_int_equal(strtcpy_a(buf, "fo"), strlen("fo"));
        assert_string_equal(buf, "fo");
 
-       assert_int_equal(STRTCPY(buf, "f"), strlen("f"));
+       assert_int_equal(strtcpy_a(buf, "f"), strlen("f"));
        assert_string_equal(buf, "f");
 
-       assert_int_equal(STRTCPY(buf, ""), strlen(""));
+       assert_int_equal(strtcpy_a(buf, ""), strlen(""));
        assert_string_equal(buf, "");
 }