Back to index

glibc  2.9
db-netgrp.c
Go to the documentation of this file.
00001 /* Netgroup file parser in nss_db modules.
00002    Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <dlfcn.h>
00022 #include <errno.h>
00023 #include <fcntl.h>
00024 #include <netgroup.h>
00025 #include <string.h>
00026 #include <bits/libc-lock.h>
00027 #include <paths.h>
00028 
00029 #include "nsswitch.h"
00030 #include "nss_db.h"
00031 
00032 
00033 #define DBFILE              _PATH_VARDB "netgroup.db"
00034 
00035 
00036 /* Locks the static variables in this file.  */
00037 __libc_lock_define_initialized (static, lock)
00038 
00039 /* Maintenance of the shared handle open on the database.  */
00040 static NSS_DB *db;
00041 static char *entry;
00042 static char *cursor;
00043 
00044 enum nss_status
00045 _nss_db_setnetgrent (const char *group)
00046 {
00047   enum nss_status status;
00048 
00049   __libc_lock_lock (lock);
00050 
00051   status = internal_setent (DBFILE, &db);
00052 
00053   if (status == NSS_STATUS_SUCCESS)
00054     {
00055       DBT key = { data: (void *) group, size: strlen (group), flags: 0 };
00056       DBT value;
00057 
00058       value.flags = 0;
00059       if (DL_CALL_FCT (db->get, (db->db, NULL, &key, &value, 0)) != 0)
00060        status = NSS_STATUS_NOTFOUND;
00061       else
00062        cursor = entry = value.data;
00063     }
00064 
00065   __libc_lock_unlock (lock);
00066 
00067   return status;
00068 
00069 }
00070 
00071 
00072 enum nss_status
00073 _nss_db_endnetgrent (void)
00074 {
00075   __libc_lock_lock (lock);
00076 
00077   internal_endent (&db);
00078 
00079   __libc_lock_unlock (lock);
00080 
00081   return NSS_STATUS_SUCCESS;
00082 }
00083 
00084 
00085 extern enum nss_status _nss_netgroup_parseline (char **cursor,
00086                                           struct __netgrent *result,
00087                                           char *buffer, size_t buflen,
00088                                           int *errnop);
00089 
00090 enum nss_status
00091 _nss_db_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
00092                      int *errnop)
00093 {
00094   int status;
00095 
00096   __libc_lock_lock (lock);
00097 
00098   status = _nss_netgroup_parseline (&cursor, result, buffer, buflen, errnop);
00099 
00100   __libc_lock_unlock (lock);
00101 
00102   return status;
00103 }