Update.
[glibc.git] / nss / nss_db / db-netgrp.c
blob47e845a6b900ae1d343fe4ca2387f6a7de638e6d
1 /* Netgroup file parser in nss_db modules.
2 Copyright (C) 1996, 1997, 1999, 2000 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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <dlfcn.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <netgroup.h>
25 #include <string.h>
26 #include <bits/libc-lock.h>
27 #include <paths.h>
29 #include "nsswitch.h"
30 #include "nss_db.h"
33 #define DBFILE _PATH_VARDB "netgroup.db"
36 /* Locks the static variables in this file. */
37 __libc_lock_define_initialized (static, lock)
39 /* Maintenance of the shared handle open on the database. */
40 static NSS_DB *db;
41 static char *entry;
42 static char *cursor;
44 enum nss_status
45 _nss_db_setnetgrent (const char *group)
47 enum nss_status status;
49 __libc_lock_lock (lock);
51 status = internal_setent (DBFILE, &db);
53 if (status == NSS_STATUS_SUCCESS)
55 DBT key = { data: (void *) group, size: strlen (group), flags: 0 };
56 DBT value;
58 value.flags = 0;
59 if (DL_CALL_FCT (db->get, (db->db, NULL, &key, &value, 0)) != 0)
60 status = NSS_STATUS_NOTFOUND;
61 else
62 cursor = entry = value.data;
65 __libc_lock_unlock (lock);
67 return status;
72 enum nss_status
73 _nss_db_endnetgrent (void)
75 __libc_lock_lock (lock);
77 internal_endent (&db);
79 __libc_lock_unlock (lock);
81 return NSS_STATUS_SUCCESS;
85 extern enum nss_status _nss_netgroup_parseline (char **cursor,
86 struct __netgrent *result,
87 char *buffer, size_t buflen,
88 int *errnop);
90 enum nss_status
91 _nss_db_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
92 int *errnop)
94 int status;
96 __libc_lock_lock (lock);
98 status = _nss_netgroup_parseline (&cursor, result, buffer, buflen, errnop);
100 __libc_lock_unlock (lock);
102 return status;