Back to index

glibc  2.9
nss_db.h
Go to the documentation of this file.
00001 /* Common database open/close routines for nss_db.
00002    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _NSS_DB_H
00021 #define _NSS_DB_H    1
00022 
00023 #include <nss.h>
00024 #include <stdint.h>
00025 
00026 /* Variables which keep track of the error values.  */
00027 extern int db_keyexist;
00028 extern int db_notfound;
00029 
00030 /* This flag is the same for all versions of the Berkeley DB library.  */
00031 #define DB_CREATE    0x000001
00032 
00033 /* But constants which vary from version to version are actually
00034    variables here.  */
00035 extern int db_first;
00036 extern int db_next;
00037 extern int db_nooverwrite;
00038 extern int db_truncate;
00039 extern int db_rdonly;
00040 
00041 /* The `DBT' type is the same in all versions we support.  */
00042 typedef struct
00043 {
00044   void *data;
00045   uint32_t size;
00046   uint32_t ulen;
00047   uint32_t dlen;
00048   uint32_t doff;
00049   uint32_t flags;
00050 } DBT;
00051 
00052 /* But the cursor object is very different from version to version.  */
00053 typedef struct
00054 {
00055   void *cursor;
00056   int (*c_get) (void *, DBT *, DBT *, uint32_t);
00057 } NSS_DBC;
00058 
00059 /* We need a helper function for it.  */
00060 extern int db_cursor (void *db, void *txn, NSS_DBC **dbcp);
00061 
00062 /* This is the wrapper we put around the `DB' structures to provide a
00063    uniform interface to the higher-level functions.  */
00064 typedef struct
00065 {
00066   void *db;
00067   int (*close) (void *, uint32_t);
00068   int (*cursor) (void *, void *, NSS_DBC **);
00069   int (*fd) (void *, int *);
00070   int (*get) (void *, void *, DBT *, DBT *, uint32_t);
00071   int (*put) (void *, void *, DBT *, DBT *, uint32_t);
00072 } NSS_DB;
00073 
00074 /* Open the database stored in FILE.  If succesful, store the database
00075    handle in *DBP and return NSS_STATUS_SUCCESS.  On failure, return
00076    the appropriate lookup status.  */
00077 extern enum nss_status internal_setent (const char *file, NSS_DB **dbp);
00078 
00079 /* Close the database *DBP.  */
00080 extern void internal_endent (NSS_DB **dbp);
00081 
00082 /* Dynamically load the Berkeley DB library.  Return zero if
00083    successful, non-zero if no suitable version of the library could be
00084    loaded.  */
00085 extern enum nss_status load_db (void);
00086 
00087 /* Open the database in FNAME, for access specified by FLAGS.  If
00088    opening the database causes the file FNAME to be created, it is
00089    created with MODE.  If succesful, store the database handle in *DBP
00090    and return NSS_STATUS_SUCCESS.  On failure, return the appropriate
00091    lookup status.  */
00092 extern int dbopen (const char *fname, int oper, int mode, NSS_DB **dbp);
00093 
00094 #endif /* nss_db.h */