src/, lib/, tests/: Rename STRLCPY() to STRTCPY()

It is a wrapper around STRTCPY(), so use a proper name.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-11-22 12:55:26 +01:00
committed by Iker Pedrosa
parent 6adaa40135
commit 090c019ada
12 changed files with 38 additions and 38 deletions
+1 -1
View 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) {
+4 -4
View 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,
+1 -1
View 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]) {
+1 -1
View 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);
+6 -6
View 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
+2 -2
View 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);
}
/*
+1 -1
View 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) {
+2 -2
View 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);
+4 -4
View 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.
+3 -3
View File
@@ -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");
+1 -1
View 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 ... */
+12 -12
View File
@@ -18,16 +18,16 @@
#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, "");
}