Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/login.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
9 changes: 5 additions & 4 deletions lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,12 @@ static void def_load (void)
* Go through all of the lines in the file.
*/
while (fgets_a(buf, fp) != NULL) {
if (stpsep(buf, "\n") == NULL) {
SYSLOG(LOG_CRIT, "%s: %s", def_fname, _("Non-text file."));
exit(EXIT_FAILURE);
}

/*
* Trim trailing whitespace.
*/
stpcpy(stprspn(buf, " \t\n"), "");
stpcpy(stprspn(buf, " \t"), "");

/*
* Break the line into two fields.
Expand Down
5 changes: 4 additions & 1 deletion lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ bool hushed (const char *username)
return false;
}
for (found = false; !found && (fgets_a(buf, fp) != NULL);) {
stpsep(buf, "\n");
if (stpsep(buf, "\n") == NULL) {
fclose(fp);
return false;
}
found = streq(buf, pw->pw_shell) ||
streq(buf, pw->pw_name);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,13 @@ static int setup_user_limits (const char *uname)
* FIXME: a better (smarter) checking should be done
*/
while (fgets_a(buf, fil) != NULL) {
if (strprefix(buf, "#") || strprefix(buf, "\n")) {
continue;
if (stpsep(buf, "\n") == NULL) {
fclose(fil);
return 0;
}
if (strspn(buf, "#") || streq(buf, ""))
continue;

memzero_a(tempbuf);
/* a valid line should have a username, then spaces,
* then limits
Expand Down
8 changes: 6 additions & 2 deletions lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ getportent(void)
errno = saveerr;
return NULL;
}

if (stpsep(buf, "\n") == NULL) {
errno = EINVAL;
return NULL;
}

if (strprefix(buf, "#"))
goto next;

stpsep(buf, "\n");

if (strsep2arr_a(buf, ":", fields) == -1)
goto next;

Expand Down
68 changes: 33 additions & 35 deletions lib/tz.c
Original file line number Diff line number Diff line change
@@ -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 <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#ifndef USE_PAM

#ident "$Id$"

#include <limits.h>
#include <stdio.h>
#include <string.h>

#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 */

4 changes: 4 additions & 0 deletions lib/user_busy.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ static int check_status (const char *name, uid_t uid, pid_t pid, pid_t tid)
return 0;
}
while (fgets_a(line, sfile) != NULL) {
if (stpsep(line, "\n") == NULL)
goto nontext;

if (strprefix(line, "Uid:\t")) {
unsigned long ruid, euid, suid;

Expand Down Expand Up @@ -158,6 +161,7 @@ static int check_status (const char *name, uid_t uid, pid_t pid, pid_t tid)
return 0;
}
}
nontext:
(void) fclose (sfile);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions man/login.defs.d/ENV_TZ.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
<replaceable>TZ=</replaceable> (for example
<replaceable>TZ=CST6CDT</replaceable>), or the full path to the file
<replaceable>TZ=UTC</replaceable>), or the full path to the file
containing the timezone specification (for example
<filename>/etc/tzname</filename>).
</para>
<!-- TODO: it can in fact be used to set any other variable-->
<para>
If a full path is specified but the file does not exist or cannot be
read, the default is to use <replaceable>TZ=CST6CDT</replaceable>.
read, the default is to use <replaceable>TZ=UTC</replaceable>.
</para>
</listitem>
</varlistentry>
40 changes: 15 additions & 25 deletions src/chgpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ int main (int argc, char **argv)

const struct group *gr;
struct group newgr;
bool errors = false;
intmax_t line = 0;
struct option_flags flags = {.chroot = false};
bool process_selinux;
Expand Down Expand Up @@ -387,10 +386,8 @@ int main (int argc, char **argv)
while (fgets_a(buf, stdin) != NULL) {
line++;
if (stpsep(buf, "\n") == NULL) {
fprintf (stderr, _("%s: line %jd: line too long\n"),
Prog, line);
errors = true;
continue;
fprintf(stderr, "%s: %jd: %s\n", Prog, line, _("Non-text file."));
goto fail;
}

/*
Expand All @@ -408,8 +405,7 @@ int main (int argc, char **argv)
fprintf (stderr,
_("%s: line %jd: missing new password\n"),
Prog, line);
errors = true;
continue;
goto fail;
}
newpwd = cp;
if ( (!eflg)
Expand Down Expand Up @@ -452,8 +448,7 @@ int main (int argc, char **argv)
fprintf (stderr,
_("%s: line %jd: group '%s' does not exist\n"), Prog,
line, name);
errors = true;
continue;
goto fail;
}
#ifdef SHADOWGRP
if (is_shadow_grp) {
Expand Down Expand Up @@ -512,8 +507,7 @@ int main (int argc, char **argv)
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, sgr_dbname (), newsg.sg_namp);
errors = true;
continue;
goto fail;
}
}
if ( (NULL == sg)
Expand All @@ -524,30 +518,26 @@ int main (int argc, char **argv)
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, gr_dbname (), newgr.gr_name);
errors = true;
continue;
goto fail;
}
}
}

close_files (&flags);

nscd_flush_cache ("group");
sssd_flush_cache (SSSD_DB_GROUP);

return (0);
fail:
/*
* Any detected errors will cause the entire set of changes to be
* aborted. Unlocking the group file will cause all of the
* changes to be ignored. Otherwise the file is closed, causing the
* changes to be written out all at once, and then unlocked
* afterwards.
*/
if (errors) {
fprintf (stderr,
_("%s: error detected, changes ignored\n"), Prog);
fail_exit (1, process_selinux);
}

close_files (&flags);

nscd_flush_cache ("group");
sssd_flush_cache (SSSD_DB_GROUP);

return (0);
fprintf(stderr, "%s: %s\n", Prog, _("error detected, changes ignored\n"));
fail_exit(1, process_selinux);
}

Loading
Loading