From: Carlos O'Donell <carlos@redhat.com>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 02/11] nss_compat: Do not use mmap to read database files (bug 26258)
Date: Mon, 20 Jul 2020 23:27:41 -0400 [thread overview]
Message-ID: <4e6551da-1c8a-5b6e-24f5-663043859084@redhat.com> (raw)
In-Reply-To: <df85d85088d06f7161d4c7719a56ec231d356e6d.1594974444.git.fweimer@redhat.com>
On 7/17/20 4:30 AM, Florian Weimer via Libc-alpha wrote:
> This avoids crashes in case the files are truncated for some reason.
> For typically file sizes, it is also going to be slightly faster.
> Using __nss_files_fopen instead mirrors what nss_files does.
OK for 2.32.
Correct, using __nss_files_fopen activates the handle resulting in
use of the underlying caches.
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> nss/nss_compat/compat-grp.c | 6 ++----
> nss/nss_compat/compat-initgroups.c | 6 ++----
> nss/nss_compat/compat-pwd.c | 6 ++----
> nss/nss_compat/compat-spwd.c | 6 ++----
> 4 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/nss/nss_compat/compat-grp.c b/nss/nss_compat/compat-grp.c
> index d4f750b95c..510d49e8c7 100644
> --- a/nss/nss_compat/compat-grp.c
> +++ b/nss/nss_compat/compat-grp.c
> @@ -26,6 +26,7 @@
> #include <string.h>
> #include <libc-lock.h>
> #include <kernel-features.h>
> +#include <nss_files.h>
OK.
>
> NSS_DECLARE_MODULE_FUNCTIONS (compat)
>
> @@ -108,13 +109,10 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
>
> if (ent->stream == NULL)
> {
> - ent->stream = fopen ("/etc/group", "rme");
> + ent->stream = __nss_files_fopen ("/etc/group");
>
> if (ent->stream == NULL)
> status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> - else
> - /* We take care of locking ourself. */
> - __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> }
> else
> rewind (ent->stream);
> diff --git a/nss/nss_compat/compat-initgroups.c b/nss/nss_compat/compat-initgroups.c
> index 3671bef48b..c0dcdf839d 100644
> --- a/nss/nss_compat/compat-initgroups.c
> +++ b/nss/nss_compat/compat-initgroups.c
> @@ -29,6 +29,7 @@
> #include <libc-lock.h>
> #include <kernel-features.h>
> #include <scratch_buffer.h>
> +#include <nss_files.h>
>
> NSS_DECLARE_MODULE_FUNCTIONS (compat)
>
> @@ -122,13 +123,10 @@ internal_setgrent (ent_t *ent)
> else
> ent->blacklist.current = 0;
>
> - ent->stream = fopen ("/etc/group", "rme");
> + ent->stream = __nss_files_fopen ("/etc/group");
>
> if (ent->stream == NULL)
> status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> - else
> - /* We take care of locking ourself. */
> - __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
>
> return status;
> }
> diff --git a/nss/nss_compat/compat-pwd.c b/nss/nss_compat/compat-pwd.c
> index 394e39b811..3a212a0dab 100644
> --- a/nss/nss_compat/compat-pwd.c
> +++ b/nss/nss_compat/compat-pwd.c
> @@ -27,6 +27,7 @@
> #include <string.h>
> #include <libc-lock.h>
> #include <kernel-features.h>
> +#include <nss_files.h>
>
> #include "netgroup.h"
> #include "nisdomain.h"
> @@ -223,13 +224,10 @@ internal_setpwent (ent_t *ent, int stayopen, int needent)
>
> if (ent->stream == NULL)
> {
> - ent->stream = fopen ("/etc/passwd", "rme");
> + ent->stream = __nss_files_fopen ("/etc/passwd");
>
> if (ent->stream == NULL)
> status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> - else
> - /* We take care of locking ourself. */
> - __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> }
> else
> rewind (ent->stream);
> diff --git a/nss/nss_compat/compat-spwd.c b/nss/nss_compat/compat-spwd.c
> index ec5bf283cd..d802ee0302 100644
> --- a/nss/nss_compat/compat-spwd.c
> +++ b/nss/nss_compat/compat-spwd.c
> @@ -27,6 +27,7 @@
> #include <string.h>
> #include <libc-lock.h>
> #include <kernel-features.h>
> +#include <nss_files.h>
>
> #include "netgroup.h"
> #include "nisdomain.h"
> @@ -179,13 +180,10 @@ internal_setspent (ent_t *ent, int stayopen, int needent)
>
> if (ent->stream == NULL)
> {
> - ent->stream = fopen ("/etc/shadow", "rme");
> + ent->stream = __nss_files_fopen ("/etc/shadow");
>
> if (ent->stream == NULL)
> status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
> - else
> - /* We take care of locking ourself. */
> - __fsetlocking (ent->stream, FSETLOCKING_BYCALLER);
> }
> else
> rewind (ent->stream);
>
--
Cheers,
Carlos.
next prev parent reply other threads:[~2020-07-21 3:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-17 8:29 [PATCH 00/11] Fix fgetsgent_r data corruption bug (20338) Florian Weimer
2020-07-17 8:30 ` [PATCH 01/11] nss_files: Consolidate file opening in __nss_files_fopen Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 02/11] nss_compat: Do not use mmap to read database files (bug 26258) Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell [this message]
2020-07-17 8:30 ` [PATCH 03/11] nss_files: Consolidate line parse declarations in <nss_files.h> Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 04/11] nss_files: Use generic result pointer in parse_line Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 05/11] libio: Add fseterr_unlocked for internal use Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 06/11] nss: Add __nss_fgetent_r Florian Weimer
2020-07-21 3:27 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 07/11] grp: Implement fgetgrent_r using __nss_fgetent_r Florian Weimer
2020-07-21 3:28 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 08/11] gshadow: Implement fgetsgent_r using __nss_fgetent_r (bug 20338) Florian Weimer
2020-07-21 3:28 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 09/11] pwd: Implement fgetpwent_r using __nss_fgetent_r Florian Weimer
2020-07-21 3:28 ` Carlos O'Donell
2020-07-17 8:30 ` [PATCH 10/11] shadow: Implement fgetspent_r " Florian Weimer
2020-07-21 3:28 ` Carlos O'Donell
2020-07-17 8:31 ` [PATCH 11/11] libio: Remove __libc_readline_unlocked Florian Weimer
2020-07-21 3:28 ` Carlos O'Donell
2020-07-21 3:27 ` [PATCH 00/11] Fix fgetsgent_r data corruption bug (20338) Carlos O'Donell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4e6551da-1c8a-5b6e-24f5-663043859084@redhat.com \
--to=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).