1 /* Netgroup file parser in nss_db modules.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include <bits/libc-lock.h>
31 #define DBFILE _PATH_VARDB "netgroup.db"
34 /* Locks the static variables in this file. */
35 __libc_lock_define_initialized (static, lock)
37 /* Maintenance of the shared handle open on the database. */
43 _nss_db_setnetgrent (const char *group)
45 enum nss_status status = NSS_STATUS_SUCCESS;
47 __libc_lock_lock (lock);
49 /* Make sure the data base file is open. */
52 db = __dbopen (DBFILE, O_RDONLY, 0, DB_BTREE, NULL);
55 status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
58 /* We have to make sure the file is `closed on exec'. */
61 result = flags = fcntl ((*db->fd) (db), F_GETFD, 0);
65 result = fcntl ((*db->fd) (db), F_SETFD, flags);
69 /* Something went wrong. Close the stream and return a
73 status = NSS_STATUS_UNAVAIL;
78 if (status == NSS_STATUS_SUCCESS)
80 DBT key = { data: (void *) group, size: strlen (group) };
83 if ((*db->get) (db, &key, &value, 0) != 0)
84 status = NSS_STATUS_NOTFOUND;
86 cursor = entry = value.data;
89 __libc_lock_unlock (lock);
97 _nss_db_endnetgrent (void)
99 __libc_lock_lock (lock);
107 __libc_lock_unlock (lock);
109 return NSS_STATUS_SUCCESS;
113 extern enum nss_status _nss_netgroup_parseline (char **cursor,
114 struct __netgrent *result,
115 char *buffer, size_t buflen,
119 _nss_db_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
124 __libc_lock_lock (lock);
126 status = _nss_netgroup_parseline (&cursor, result, buffer, buflen, errnop);
128 __libc_lock_unlock (lock);