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.
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
#include <string.h>
#include <libc-lock.h>
#include <kernel-features.h>
+#include <nss_files.h>
NSS_DECLARE_MODULE_FUNCTIONS (compat)
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);
#include <libc-lock.h>
#include <kernel-features.h>
#include <scratch_buffer.h>
+#include <nss_files.h>
NSS_DECLARE_MODULE_FUNCTIONS (compat)
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;
}
#include <string.h>
#include <libc-lock.h>
#include <kernel-features.h>
+#include <nss_files.h>
#include "netgroup.h"
#include "nisdomain.h"
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);
#include <string.h>
#include <libc-lock.h>
#include <kernel-features.h>
+#include <nss_files.h>
#include "netgroup.h"
#include "nisdomain.h"
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);