Back to index

glibc  2.9
Classes | Defines | Functions | Variables
nss_db.h File Reference
#include <nss.h>
#include <stdint.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DBT
struct  NSS_DBC
struct  NSS_DB

Defines

#define DB_CREATE   0x000001

Functions

int db_cursor (void *db, void *txn, NSS_DBC **dbcp)
enum nss_status internal_setent (const char *file, NSS_DB **dbp)
void internal_endent (NSS_DB **dbp)
enum nss_status load_db (void)
int dbopen (const char *fname, int oper, int mode, NSS_DB **dbp)

Variables

int db_keyexist
int db_notfound
int db_first
int db_next
int db_nooverwrite
int db_truncate
int db_rdonly

Class Documentation

struct DBT

Definition at line 42 of file nss_db.h.

Class Members
void * data
uint32_t dlen
uint32_t doff
uint32_t flags
uint32_t size
uint32_t ulen

Define Documentation

#define DB_CREATE   0x000001

Definition at line 31 of file nss_db.h.


Function Documentation

int db_cursor ( void *  db,
void *  txn,
NSS_DBC **  dbcp 
)

Definition at line 250 of file db-open.c.

{
  NSS_DBC *dbc;
  int ret;

  dbc = (NSS_DBC *) malloc (sizeof (NSS_DBC));
  if (dbc == NULL)
    return ENOMEM;

  switch (libdb_version)
    {
    case db24:
      ret = ((struct db24 *) db)->cursor (db, txn, &dbc->cursor);

      if (ret == 0)
       dbc->c_get = ((struct dbc24 *) dbc->cursor)->c_get;
      break;

    case db27:
      ret = ((struct db27 *) db)->cursor (db, txn, &dbc->cursor, 0);

      if (ret == 0)
       dbc->c_get = ((struct dbc27 *) dbc->cursor)->c_get;
      break;

    case db30:
      ret = ((struct db30 *) db)->cursor (db, txn, &dbc->cursor, 0);

      if (ret == 0)
       dbc->c_get = ((struct dbc30 *) dbc->cursor)->c_get;
      break;

    default:
      abort ();
    }

  if (ret != 0)
    {
      free (dbc);
      return ret;
    }

  *dbcp = dbc;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int dbopen ( const char *  fname,
int  oper,
int  mode,
NSS_DB **  dbp 
)

Definition at line 304 of file db-open.c.

{
  int err;
  int fd;
  NSS_DB *db;

  /* Construct the object we pass up.  */
  db = (NSS_DB *) calloc (1, sizeof (NSS_DB));
  if (db == NULL)
    return NSS_STATUS_UNAVAIL;

  /* Initialize the object.  */
  db->cursor = db_cursor;

  /* Actually open the database.  */
  switch (libdb_version)
    {
    case db24:
    case db27:
      err = DL_CALL_FCT (libdb_db_open,
                      (fname, DB_BTREE, oper, mode, NULL, NULL, &db->db));
      if (err != 0)
       goto fail;

      if (libdb_version)
       {
         db->close = ((struct db24 *) db->db)->close;
         db->fd = ((struct db24 *) db->db)->fd;
         db->get = ((struct db24 *) db->db)->get;
         db->put = ((struct db24 *) db->db)->put;
       }
      else
       {
         db->close = ((struct db27 *) db->db)->close;
         db->fd = ((struct db27 *) db->db)->fd;
         db->get = ((struct db27 *) db->db)->get;
         db->put = ((struct db27 *) db->db)->put;
       }
      break;

    case db30:
      err = DL_CALL_FCT (libdb_db_create, (db->db, NULL, 0));
      if (err != 0)
       goto fail;

      db->close = ((struct db30 *) db->db)->close;
      db->fd = ((struct db30 *) db->db)->fd;
      db->get = ((struct db30 *) db->db)->get;
      db->put = ((struct db30 *) db->db)->put;

      err = ((struct db30 *) db->db)->open (db->db, fname, NULL, DB_BTREE,
                                       oper, mode);
      if (err != 0)
       goto fail;
      break;

    default:
      abort ();
    }

  /* We have to make sure the file is `closed on exec'.  */
  err = DL_CALL_FCT (db->fd, (db->db, &fd));
  if (err != 0)
    goto fail;
  if (set_cloexec_flag (fd) < 0)
    goto fail;

  *dbp = db;

  return NSS_STATUS_UNAVAIL;

 fail:
  /* Something went wrong.  Close the database if necessary.  */
  if (db)
    {
      if (db->db && db->close)
       DL_CALL_FCT (db->close, (db->db, 0));
      free (db);
    }

  /* Make sure `errno' is set.  */
  if (err)
    __set_errno (err);

  return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void internal_endent ( NSS_DB **  dbp)

Definition at line 235 of file db-open.c.

{
  NSS_DB *db = *dbp;

  if (db != NULL)
    {
      DL_CALL_FCT (db->close, (db->db, 0));
      *dbp = NULL;
    }
}

Here is the caller graph for this function:

enum nss_status internal_setent ( const char *  file,
NSS_DB **  dbp 
)

Definition at line 209 of file db-open.c.

{
  enum nss_status status = NSS_STATUS_SUCCESS;

  if (*dbp == NULL)
    {
      if (libdb_db_open == NULL && libdb_db_create == NULL)
       {
         __libc_lock_lock (lock);

         if (libdb_db_open == NULL && libdb_db_create == NULL)
           status = load_db ();

         __libc_lock_unlock (lock);
       }

      if (status == NSS_STATUS_SUCCESS)
       status = dbopen (file, db_rdonly, 0, dbp);
    }

  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

enum nss_status load_db ( void  )

Here is the caller graph for this function:


Variable Documentation

Definition at line 63 of file db-open.c.

Definition at line 69 of file db-open.c.

Definition at line 64 of file db-open.c.

Definition at line 65 of file db-open.c.

Definition at line 70 of file db-open.c.

Definition at line 67 of file db-open.c.

Definition at line 66 of file db-open.c.