2000-01-08 05:28:22 +00:00
|
|
|
/* Common database routines for nss_db.
|
2017-01-01 00:14:16 +00:00
|
|
|
Copyright (C) 2000-2017 Free Software Foundation, Inc.
|
2000-01-02 04:20:21 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-01-02 04:20:21 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
2000-01-02 04:20:21 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-01-02 04:20:21 +00:00
|
|
|
|
2000-01-08 05:28:22 +00:00
|
|
|
#include <errno.h>
|
2000-01-02 04:20:21 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdlib.h>
|
2000-05-08 04:50:45 +00:00
|
|
|
#include <string.h>
|
2011-06-24 06:57:27 +00:00
|
|
|
#include <unistd.h>
|
2011-06-15 02:21:51 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <not-cancel.h>
|
2000-01-02 04:20:21 +00:00
|
|
|
|
|
|
|
#include "nss_db.h"
|
|
|
|
|
2011-06-15 02:21:51 +00:00
|
|
|
/* Open the database stored in FILE. If succesful, store either a
|
|
|
|
pointer to the mapped file or a file handle for the file in H and
|
|
|
|
return NSS_STATUS_SUCCESS. On failure, return the appropriate
|
|
|
|
lookup status. */
|
2000-05-08 04:50:45 +00:00
|
|
|
enum nss_status
|
2011-06-15 02:21:51 +00:00
|
|
|
internal_setent (const char *file, struct nss_db_map *mapping)
|
2000-05-08 04:50:45 +00:00
|
|
|
{
|
2011-06-15 02:21:51 +00:00
|
|
|
enum nss_status status = NSS_STATUS_UNAVAIL;
|
|
|
|
|
2017-04-18 12:56:51 +00:00
|
|
|
int fd = open_not_cancel_2 (file, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
|
2011-06-15 02:21:51 +00:00
|
|
|
if (fd != -1)
|
2000-01-02 04:20:21 +00:00
|
|
|
{
|
2011-06-15 02:21:51 +00:00
|
|
|
struct nss_db_header header;
|
2000-01-02 04:20:21 +00:00
|
|
|
|
2011-06-15 02:21:51 +00:00
|
|
|
if (read (fd, &header, sizeof (header)) == sizeof (header))
|
2000-01-02 04:20:21 +00:00
|
|
|
{
|
2011-06-15 02:21:51 +00:00
|
|
|
mapping->header = mmap (NULL, header.allocate, PROT_READ,
|
|
|
|
MAP_PRIVATE, fd, 0);
|
|
|
|
mapping->len = header.allocate;
|
|
|
|
if (mapping->header != MAP_FAILED)
|
|
|
|
status = NSS_STATUS_SUCCESS;
|
|
|
|
else if (errno == ENOMEM)
|
|
|
|
status = NSS_STATUS_TRYAGAIN;
|
2000-01-02 04:20:21 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 02:21:51 +00:00
|
|
|
close_not_cancel_no_status (fd);
|
2000-01-08 05:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 02:21:51 +00:00
|
|
|
/* Close the database. */
|
2000-01-08 05:28:22 +00:00
|
|
|
void
|
2011-06-15 02:21:51 +00:00
|
|
|
internal_endent (struct nss_db_map *mapping)
|
2000-01-08 05:28:22 +00:00
|
|
|
{
|
2011-06-15 02:21:51 +00:00
|
|
|
munmap (mapping->header, mapping->len);
|
2000-01-02 04:20:21 +00:00
|
|
|
}
|