diff --git a/etc/login.defs b/etc/login.defs index 1b81afd82e..c05bb3ba59 100644 --- a/etc/login.defs +++ b/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname # diff --git a/lib/tz.c b/lib/tz.c index b2d9531e20..bbcddb4253 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -1,57 +1,55 @@ -/* - * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1991 - 1994, Chip Rosenthal - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2007 - 2010, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1991-1994, Chip Rosenthal +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2007-2010, Nicolas François +// SPDX-FileCopyrightText: 2026, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + #include "config.h" #ifndef USE_PAM -#ident "$Id$" - +#include #include -#include -#include "defines.h" -#include "getdef.h" #include "io/fgets/fgets.h" #include "prototypes.h" #include "string/strtok/stpsep.h" +#define DEFAULT_TZ "TZ=UTC" + + /* * tz - return local timezone name * * tz() determines the name of the local timezone by reading the - * contents of the file named by ``fname''. + * contents of the file named by 'path'. */ -/*@observer@*/const char *tz (const char *fname) +/*@observer@*/ +const char * +tz(const char *path) { - FILE *fp = NULL; - const char *result; - static char tzbuf[BUFSIZ]; - - fp = fopen (fname, "r"); - if ( (NULL == fp) - || (fgets_a(tzbuf, fp) == NULL)) { - result = "TZ=CST6CDT"; - } else { - stpsep(tzbuf, "\n"); - result = tzbuf; - } - - if (NULL != fp) { - (void) fclose (fp); - } - - return result; + FILE *fp; + static char buf[LINE_MAX + 1]; + + fp = fopen(path, "r"); + if (fp == NULL) + return DEFAULT_TZ; + + if (fgets_a(buf, fp) == NULL) + goto def; + if (stpsep(buf, "\n") == NULL) + goto def; + + fclose(fp); + return buf; +def: + fclose(fp); + return DEFAULT_TZ; } #else /* !USE_PAM */ extern int ISO_C_forbids_an_empty_translation_unit; #endif /* !USE_PAM */ - diff --git a/man/login.defs.d/ENV_TZ.xml b/man/login.defs.d/ENV_TZ.xml index 04d208ed05..bef702f58e 100644 --- a/man/login.defs.d/ENV_TZ.xml +++ b/man/login.defs.d/ENV_TZ.xml @@ -11,14 +11,14 @@ If set, it will be used to define the TZ environment variable when a user login. The value can be the name of a timezone preceded by TZ= (for example - TZ=CST6CDT), or the full path to the file + TZ=UTC), or the full path to the file containing the timezone specification (for example /etc/tzname). If a full path is specified but the file does not exist or cannot be - read, the default is to use TZ=CST6CDT. + read, the default is to use TZ=UTC. diff --git a/tests/newusers/62_create_user_no_aging/config/etc/login.defs b/tests/newusers/62_create_user_no_aging/config/etc/login.defs index 1e61b5cd41..8beb789ee3 100644 --- a/tests/newusers/62_create_user_no_aging/config/etc/login.defs +++ b/tests/newusers/62_create_user_no_aging/config/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname # diff --git a/tests/system/etc/login.defs b/tests/system/etc/login.defs index 7f1feffd64..2286c0b85b 100644 --- a/tests/system/etc/login.defs +++ b/tests/system/etc/login.defs @@ -143,7 +143,7 @@ HUSHLOGIN_FILE .hushlogin # If defined, either a TZ environment parameter spec or the # fully-rooted pathname of a file containing such a spec. # -#ENV_TZ TZ=CST6CDT +#ENV_TZ TZ=UTC #ENV_TZ /etc/tzname #