Skip to content
Open
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
1 change: 0 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ libshadow_la_SOURCES = \
find_new_uid.c \
find_new_sub_gids.c \
find_new_sub_uids.c \
fputsx.c \
fs/mkstemp/fmkomstemp.c \
fs/mkstemp/fmkomstemp.h \
fs/mkstemp/mkomstemp.c \
Expand Down
41 changes: 12 additions & 29 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <utime.h>

#include "alloc/malloc.h"
#include "alloc/reallocf.h"
#include "atoi/getnum.h"
#include "commonio.h"
#include "defines.h"
Expand Down Expand Up @@ -180,7 +180,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
errno = EINVAL;
return 0;
}
len = read (fd, buf, sizeof (buf) - 1);
len = read(fd, buf, sizeof(buf) - 1);
close (fd);
if (len <= 0) {
if (log) {
Expand Down Expand Up @@ -566,11 +566,9 @@ static void add_one_entry_nis (struct commonio_db *db,
}
#endif /* KEEP_NIS_AT_END */

/* Initial buffer size, as well as increment if not sufficient
(for reading very long lines in group files). */
#define BUFLEN 4096

int commonio_open (struct commonio_db *db, int mode)
int
commonio_open(struct commonio_db *db, int mode)
{
char *buf;
char *line;
Expand Down Expand Up @@ -632,28 +630,12 @@ int commonio_open (struct commonio_db *db, int mode)
return 0;
}

buflen = BUFLEN;
buf = MALLOC(buflen, char);
if (NULL == buf)
goto cleanup_errno;

while (db->ops->cio_fgets(buf, buflen, db->fp) == buf) {
buf = NULL;
while (getline(&buf, &buflen, db->fp) != -1) {
struct commonio_entry *p;

while ( (strrchr (buf, '\n') == NULL)
&& (feof (db->fp) == 0)) {
size_t len;

buflen += BUFLEN;
buf = REALLOCF(buf, buflen, char);
if (NULL == buf)
goto cleanup_errno;

len = strlen (buf);
if (db->ops->cio_fgets(buf + len, buflen - len, db->fp) == NULL)
goto cleanup_buf;
}
stpsep(buf, "\n");
if (stpsep(buf, "\n") == NULL)
goto cleanup_buf;

line = strdup (buf);
if (NULL == line) {
Expand Down Expand Up @@ -714,6 +696,7 @@ int commonio_open (struct commonio_db *db, int mode)
return 0;
}


/*
* Sort given db according to cmp function (usually compares uids)
*/
Expand Down Expand Up @@ -766,7 +749,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
entries[n] = ptr;
n++;
}
qsort (entries, n, sizeof (struct commonio_entry *), cmp);
qsort(entries, n, sizeof(struct commonio_entry *), cmp);

/* Take care of the head and tail separately */
db->head = entries[0];
Expand Down Expand Up @@ -868,7 +851,7 @@ static int write_all (const struct commonio_db *db)
return -1;
}
} else if (NULL != p->line) {
if (db->ops->cio_fputs(p->line, db->fp) == EOF)
if (fputs(p->line, db->fp) == EOF)
return -1;

if (putc ('\n', db->fp) == EOF) {
Expand Down Expand Up @@ -904,7 +887,7 @@ int commonio_close (struct commonio_db *db, bool process_selinux)
goto fail;
}

memzero (&sb, sizeof sb);
memzero(&sb, sizeof(sb));
if (NULL != db->fp) {
if (fstat (fileno (db->fp), &sb) != 0) {
(void) fclose (db->fp);
Expand Down
9 changes: 0 additions & 9 deletions lib/commonio.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ struct commonio_ops {
*/
int (*cio_put)(const void *, FILE *);

/*
* fgets and fputs (can be replaced by versions that
* understand line continuation conventions).
*/
ATTR_ACCESS(write_only, 1, 2)
/*@null@*/char *(*cio_fgets)(/*@returned@*/char *restrict s, int n,
FILE *restrict stream);
int (*cio_fputs)(const char *, FILE *);

/*
* open_hook and close_hook.
* If non NULL, these functions will be called after the database
Expand Down
2 changes: 1 addition & 1 deletion lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ is_listed(const char *cfgin, const char *tty, bool def)
* See if this tty is listed in the console file.
*/

while (fgets (buf, sizeof (buf), fp) != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
stpsep(buf, "\n");
if (streq(buf, tty)) {
(void) fclose (fp);
Expand Down
2 changes: 1 addition & 1 deletion lib/copydir.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst,
char buf[8192];
ssize_t cnt;

cnt = read (ifd, buf, sizeof buf);
cnt = read(ifd, buf, sizeof(buf));
if (cnt < 0) {
if (errno == EINTR) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void set_env (int argc, char *const *argv)
char *cp;

for (; argc > 0; argc--, argv++) {
if (strlen (*argv) >= sizeof variable) {
if (strlen(*argv) >= sizeof(variable)) {
continue; /* ignore long entries */
}

Expand Down
14 changes: 7 additions & 7 deletions lib/failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
void failure (uid_t uid, const char *tty, struct faillog *fl)
{
int fd;
off_t offset_uid = (off_t) (sizeof *fl) * uid;
off_t offset_uid = (off_t) sizeof(*fl) * uid;

/*
* Don't do anything if failure logging isn't set up.
Expand All @@ -59,15 +59,15 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
*/

if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
|| (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) {
|| (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) {
/* This is not necessarily a failure. The file is
* initially zero length.
*
* If lseek() or read() failed for any other reason, this
* might reset the counter. But the new failure will be
* logged.
*/
memzero (fl, sizeof *fl);
memzero(fl, sizeof(*fl));
}

/*
Expand All @@ -92,7 +92,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
*/

if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
|| (write_full(fd, fl, sizeof *fl) == -1)) {
|| (write_full(fd, fl, sizeof(*fl)) == -1)) {
goto err_write;
}

Expand Down Expand Up @@ -150,7 +150,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed)
{
int fd;
struct faillog fail;
off_t offset_uid = (off_t) (sizeof *fl) * uid;
off_t offset_uid = (off_t) sizeof(*fl) * uid;

/*
* Suppress the check if the log file isn't there.
Expand Down Expand Up @@ -182,7 +182,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed)
*/

if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
|| (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) {
|| (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) {
(void) close (fd);
return 1;
}
Expand All @@ -204,7 +204,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed)
fail.fail_cnt = 0;

if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid)
|| (write_full(fd, &fail, sizeof fail) == -1)) {
|| (write_full(fd, &fail, sizeof(fail)) == -1)) {
goto err_write;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include "fields.h"

#include <ctype.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include "prototypes.h"
#include "string/ctype/strisascii/strisprint.h"
Expand Down Expand Up @@ -62,15 +63,14 @@ change_field(char *buf, size_t maxsize, const char *prompt)
char newf[200];
char *cp;

if (maxsize > sizeof (newf)) {
maxsize = sizeof (newf);
if (maxsize > sizeof(newf)) {
maxsize = sizeof(newf);
}

printf ("\t%s [%s]: ", prompt, buf);
(void) fflush (stdout);
if (fgets (newf, maxsize, stdin) != newf) {
if (fgets(newf, maxsize, stdin) == NULL)
return;
}

if (stpsep(newf, "\n") == NULL)
return;
Expand Down
67 changes: 0 additions & 67 deletions lib/fputsx.c

This file was deleted.

2 changes: 1 addition & 1 deletion lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static void def_load (void)
/*
* Go through all of the lines in the file.
*/
while (fgets (buf, sizeof (buf), fp) != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {

/*
* Trim trailing whitespace.
Expand Down
2 changes: 0 additions & 2 deletions lib/groupio.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static struct commonio_ops group_ops = {
group_getname,
group_parse,
group_put,
fgetsx,
fputsx,
group_open_hook,
group_close_hook
};
Expand Down
3 changes: 2 additions & 1 deletion lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ident "$Id$"

#include <pwd.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
Expand Down Expand Up @@ -73,7 +74,7 @@ bool hushed (const char *username)
if (NULL == fp) {
return false;
}
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
for (found = false; !found && (fgets(buf, sizeof(buf), fp) != NULL);) {
stpsep(buf, "\n");
found = streq(buf, pw->pw_shell) ||
streq(buf, pw->pw_name);
Expand Down
8 changes: 4 additions & 4 deletions lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void dolastlog (
* for this UID. Negative UID's will create problems, but ...
*/

offset = (off_t) pw->pw_uid * sizeof newlog;
offset = (off_t) pw->pw_uid * sizeof(newlog);

if (lseek (fd, offset, SEEK_SET) != offset) {
SYSLOG ((LOG_WARN,
Expand All @@ -71,8 +71,8 @@ void dolastlog (
* the way we read the old one in.
*/

if (read (fd, &newlog, sizeof newlog) != (ssize_t) sizeof newlog) {
memzero (&newlog, sizeof newlog);
if (read(fd, &newlog, sizeof(newlog)) != (ssize_t) sizeof(newlog)) {
memzero(&newlog, sizeof(newlog));
}
if (NULL != ll) {
*ll = newlog;
Expand All @@ -86,7 +86,7 @@ void dolastlog (
STRNCPY(newlog.ll_host, host);
#endif
if ( (lseek (fd, offset, SEEK_SET) != offset)
|| (write_full(fd, &newlog, sizeof newlog) == -1)) {
|| (write_full(fd, &newlog, sizeof(newlog)) == -1)) {
goto err_write;
}

Expand Down
Loading
Loading