]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/, lib/, tests/: Rename STRLCPY() to STRTCPY()
authorAlejandro Colomar <alx@kernel.org>
Sun, 12 Nov 2023 13:00:47 +0000 (14:00 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 22 Nov 2023 11:55:26 +0000 (12:55 +0100)
It is a wrapper around STRTCPY(), so use a proper name.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
12 files changed:
lib/console.c
lib/strlcpy.h
lib/utmp.c
src/chage.c
src/chfn.c
src/chsh.c
src/gpasswd.c
src/login.c
src/passwd.c
src/su.c
src/sulogin.c
tests/unit/test_strlcpy.c

index a847720a4882b8c680f600356c8761d7f97266ea..9284cf6382a0889c197d988d142c1bc8ab63d7e8 100644 (file)
@@ -45,7 +45,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
 
        if (*cons != '/') {
                char *pbuf;
-               STRLCPY(buf, cons);
+               STRTCPY(buf, cons);
                pbuf = &buf[0];
                while ((s = strtok (pbuf, ":")) != NULL) {
                        if (strcmp (s, tty) == 0) {
index 36d847c4453f583959f6ee65f952f6160067c161..60f44f9f1c391e5e88ce7e352eb4504c76d997c6 100644 (file)
@@ -4,8 +4,8 @@
  */
 
 
-#ifndef SHADOW_INCLUDE_LIB_STRLCPY_H_
-#define SHADOW_INCLUDE_LIB_STRLCPY_H_
+#ifndef SHADOW_INCLUDE_LIB_STRTCPY_H_
+#define SHADOW_INCLUDE_LIB_STRTCPY_H_
 
 
 #include <config.h>
@@ -20,7 +20,7 @@
 
 /*
  * SYNOPSIS
- *     int STRLCPY(char dst[restrict], const char *restrict src);
+ *     int STRTCPY(char dst[restrict], const char *restrict src);
  *
  * ARGUMENTS
  *     dst     Destination buffer where to copy a string.
@@ -44,7 +44,7 @@
  */
 
 
-#define STRLCPY(dst, src)  strtcpy(dst, src, SIZEOF_ARRAY(dst))
+#define STRTCPY(dst, src)  strtcpy(dst, src, SIZEOF_ARRAY(dst))
 
 
 inline ssize_t strtcpy(char *restrict dst, const char *restrict src,
index 43eb2f5df9e487614fbdb59f806996a04a63c567..56c6cd3fcc31d575d3f2602732e187f945fcb15d 100644 (file)
@@ -47,7 +47,7 @@ static bool is_my_tty (const char tty[UT_LINESIZE])
        if ('\0' == tmptty[0]) {
                const char *tname = ttyname (STDIN_FILENO);
                if (NULL != tname)
-                       STRLCPY(tmptty, tname);
+                       STRTCPY(tmptty, tname);
        }
 
        if ('\0' == tmptty[0]) {
index 6896cb15a3e5e54dcec457653a7d53826757dd7a..0ee688943a851a9873654e82736a877f3326e53a 100644 (file)
@@ -823,7 +823,7 @@ int main (int argc, char **argv)
                fail_exit (E_NOPERM);
        }
 
-       STRLCPY(user_name, pw->pw_name);
+       STRTCPY(user_name, pw->pw_name);
 #ifdef WITH_TCB
        if (shadowtcb_set_user (pw->pw_name) == SHADOWTCB_FAILURE) {
                fail_exit (E_NOPERM);
index 242868f47ebf8909b882459652f3214c8563c2a6..c35cae4eeb27c49b77e262ef09de77d9f255dcc1 100644 (file)
@@ -276,7 +276,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        fflg = true;
-                       STRLCPY(fullnm, optarg);
+                       STRTCPY(fullnm, optarg);
                        break;
                case 'h':
                        if (!may_change_field ('h')) {
@@ -285,7 +285,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        hflg = true;
-                       STRLCPY(homeph, optarg);
+                       STRTCPY(homeph, optarg);
                        break;
                case 'o':
                        if (!amroot) {
@@ -299,7 +299,7 @@ static void process_flags (int argc, char **argv)
                                         _("%s: fields too long\n"), Prog);
                                exit (E_NOPERM);
                        }
-                       STRLCPY(slop, optarg);
+                       STRTCPY(slop, optarg);
                        break;
                case 'r':
                        if (!may_change_field ('r')) {
@@ -308,7 +308,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        rflg = true;
-                       STRLCPY(roomno, optarg);
+                       STRTCPY(roomno, optarg);
                        break;
                case 'R': /* no-op, handled in process_root_flag () */
                        break;
@@ -322,7 +322,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_NOPERM);
                        }
                        wflg = true;
-                       STRLCPY(workph, optarg);
+                       STRTCPY(workph, optarg);
                        break;
                default:
                        usage (E_USAGE);
@@ -510,7 +510,7 @@ static void get_old_fields (const char *gecos)
        char *cp;               /* temporary character pointer       */
        char old_gecos[BUFSIZ]; /* buffer for old GECOS fields       */
 
-       STRLCPY(old_gecos, gecos);
+       STRTCPY(old_gecos, gecos);
 
        /*
         * Now get the full name. It is the first comma separated field in
index 29f8afc8cf2dfb8004c78ed0f399fa401bc11ddf..c676f1f994736ac6c6bc112d5de209898f6ebe40 100644 (file)
@@ -258,7 +258,7 @@ static void process_flags (int argc, char **argv)
                        break;
                case 's':
                        sflg = true;
-                       STRLCPY(loginsh, optarg);
+                       STRTCPY(loginsh, optarg);
                        break;
                default:
                        usage (E_USAGE);
@@ -553,7 +553,7 @@ int main (int argc, char **argv)
         * file, or use the value from the command line.
         */
        if (!sflg) {
-               STRLCPY(loginsh, pw->pw_shell);
+               STRTCPY(loginsh, pw->pw_shell);
        }
 
        /*
index a8a78d8591c9c96ab4a13e4af5d5b092d1549f5c..9d972662a66a9212b8bd0b999034df0c4ffe494e 100644 (file)
@@ -897,7 +897,7 @@ static void change_passwd (struct group *gr)
                        exit (1);
                }
 
-               STRLCPY(pass, cp);
+               STRTCPY(pass, cp);
                erase_pass (cp);
                cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
index 93fd248c1f48a64ee482eae47f22b978e9bd589a..c7572f71d74137c12f4bfca9af59e5f6779383ee 100644 (file)
@@ -553,7 +553,7 @@ int main (int argc, char **argv)
        if (NULL == tmptty) {
                tmptty = "UNKNOWN";
        }
-       STRLCPY(tty, tmptty);
+       STRTCPY(tty, tmptty);
 
 #ifndef USE_PAM
        is_console = console (tty);
@@ -711,7 +711,7 @@ int main (int argc, char **argv)
                                  sizeof (loginprompt),
                                  _("%s login: "), hostn);
                } else {
-                       STRLCPY(loginprompt, _("login: "));
+                       STRTCPY(loginprompt, _("login: "));
                }
 
                retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);
index 5bcd339561167c5d3cb35607bf19ebb253e2276c..13eeb426d45207509bfe033709eb1e746285f113 100644 (file)
@@ -241,7 +241,7 @@ static int new_password (const struct passwd *pw)
                                        pw->pw_name);
                        return -1;
                }
-               STRLCPY(orig, clear);
+               STRTCPY(orig, clear);
                erase_pass (clear);
                strzero (cipher);
        } else {
@@ -303,7 +303,7 @@ static int new_password (const struct passwd *pw)
                if (warned && (strcmp (pass, cp) != 0)) {
                        warned = false;
                }
-               STRLCPY(pass, cp);
+               STRTCPY(pass, cp);
                erase_pass (cp);
 
                if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
@@ -360,7 +360,7 @@ static int new_password (const struct passwd *pw)
 #ifdef HAVE_LIBCRACK_HIST
        HistUpdate (pw->pw_name, crypt_passwd);
 #endif                         /* HAVE_LIBCRACK_HIST */
-       STRLCPY(crypt_passwd, cp);
+       STRTCPY(crypt_passwd, cp);
        return 0;
 }
 
@@ -1031,7 +1031,7 @@ int main (int argc, char **argv)
                 * If there are no other flags, just change the password.
                 */
                if (!anyflag) {
-                       STRLCPY(crypt_passwd, cp);
+                       STRTCPY(crypt_passwd, cp);
 
                        /*
                         * See if the user is permitted to change the password.
index 9c577f35a015c790fe42becb3ff3e1e9a2235a70..6f66b3e311756b2efc30e146cb5da16124864504 100644 (file)
--- a/src/su.c
+++ b/src/su.c
@@ -676,7 +676,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 (STRLCPY(name, tmp_name) == -1) {
+               if (STRTCPY(name, tmp_name) == -1) {
                        fprintf (stderr, _("Overlong user name '%s'\n"),
                                 tmp_name);
                        SYSLOG ((LOG_NOTICE, "Overlong user name '%s'",
@@ -778,7 +778,7 @@ static void save_caller_context (char **argv)
                         (unsigned long) caller_uid));
                su_failure (caller_tty, true); /* unknown target UID*/
        }
-       STRLCPY(caller_name, pw->pw_name);
+       STRTCPY(caller_name, pw->pw_name);
 
 #ifndef USE_PAM
 #ifdef SU_ACCESS
@@ -853,7 +853,7 @@ static void process_flags (int argc, char **argv)
        }
 
        if (optind < argc) {
-               STRLCPY(name, argv[optind++]);  /* use this login id */
+               STRTCPY(name, argv[optind++]);  /* use this login id */
        }
        if ('\0' == name[0]) {          /* use default user */
                struct passwd *root_pw = getpwnam ("root");
index ee8c962299193c4bb45b5a8d2db10b1793f5c10d..8b43ee7ae9c49b12cb7a059efd658c8b7fad7c5c 100644 (file)
@@ -160,7 +160,7 @@ static void catch_signals (unused int sig)
 #endif
                        exit (0);
                }
-               STRLCPY(pass, cp);
+               STRTCPY(pass, cp);
                erase_pass (cp);
 
                if (valid (pass, &pwent)) {     /* check encrypted passwords ... */
index 1c8aa8f6b87d441ff1707dad1cd104c175e11965..0dec0b74d1ddb24828c4b70590a852d35d6a55ce 100644 (file)
 #include "strlcpy.h"
 
 
-static void test_STRLCPY_trunc(void **state);
-static void test_STRLCPY_ok(void **state);
+static void test_STRTCPY_trunc(void **state);
+static void test_STRTCPY_ok(void **state);
 
 
 int
 main(void)
 {
     const struct CMUnitTest  tests[] = {
-        cmocka_unit_test(test_STRLCPY_trunc),
-        cmocka_unit_test(test_STRLCPY_ok),
+        cmocka_unit_test(test_STRTCPY_trunc),
+        cmocka_unit_test(test_STRTCPY_ok),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
@@ -35,33 +35,33 @@ main(void)
 
 
 static void
-test_STRLCPY_trunc(void **state)
+test_STRTCPY_trunc(void **state)
 {
        char  buf[NITEMS("foo")];
 
        // Test that we're not returning SIZE_MAX
-       assert_true(STRLCPY(buf, "fooo") < 0);
+       assert_true(STRTCPY(buf, "fooo") < 0);
        assert_string_equal(buf, "foo");
 
-       assert_int_equal(STRLCPY(buf, "barbaz"), -1);
+       assert_int_equal(STRTCPY(buf, "barbaz"), -1);
        assert_string_equal(buf, "bar");
 }
 
 
 static void
-test_STRLCPY_ok(void **state)
+test_STRTCPY_ok(void **state)
 {
        char  buf[NITEMS("foo")];
 
-       assert_int_equal(STRLCPY(buf, "foo"), strlen("foo"));
+       assert_int_equal(STRTCPY(buf, "foo"), strlen("foo"));
        assert_string_equal(buf, "foo");
 
-       assert_int_equal(STRLCPY(buf, "fo"), strlen("fo"));
+       assert_int_equal(STRTCPY(buf, "fo"), strlen("fo"));
        assert_string_equal(buf, "fo");
 
-       assert_int_equal(STRLCPY(buf, "f"), strlen("f"));
+       assert_int_equal(STRTCPY(buf, "f"), strlen("f"));
        assert_string_equal(buf, "f");
 
-       assert_int_equal(STRLCPY(buf, ""), strlen(""));
+       assert_int_equal(STRTCPY(buf, ""), strlen(""));
        assert_string_equal(buf, "");
 }