mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-09 23:00:07 +00:00
Update.
2000-01-07 Andreas Jaeger <aj@suse.de> Add support for Berkeley db 3.0.x and merge db support: * nss/nss_db/dummy-db.h (struct db30): New. (struct dbc30): New. Added DB30* flags. * nss/makedb.c: Move all database routines to db-open.c. (main): Adjust to interface changes. Load database early to initialize version dependend variables. * nss/db-open.c: Merge database routines from makedb.c. Define version dependend constansts as variables. (load_db): Check also for db 3. (internal_setent): Call dbopen. (db_cursor): New function from makedb; handles db 3 now. (dbopen): New function from makedb; handles db 3. * nss/nss_db/db-XXX.c: Use db_notfound since the value is different in different DB versions. * nss/nss_db/nss_db.h: Add version dependend constants as variables, add exportet interfaces from db-open.c. * nss/Makefile ($(objpfx)makedb): Link against db-open. 2000-01-07 Ulrich Drepper <drepper@cygnus.com> * misc/error.c: Don't use `defined _LIBC', only `_LIBC'. Reported by Jim Meyering. * time/strftime.c: Pretty printing. 2000-01-07 Andreas Jaeger <aj@suse.de> * manual/socket.texi (Host Names): Fix example. Reported by Marco Budde <budde@telos.de>.
This commit is contained in:
parent
f14854aab2
commit
9d8525f2a1
38
ChangeLog
38
ChangeLog
@ -1,3 +1,41 @@
|
||||
2000-01-07 Andreas Jaeger <aj@suse.de>
|
||||
|
||||
Add support for Berkeley db 3.0.x and merge db support:
|
||||
* nss/nss_db/dummy-db.h (struct db30): New.
|
||||
(struct dbc30): New.
|
||||
Added DB30* flags.
|
||||
|
||||
* nss/makedb.c: Move all database routines to db-open.c.
|
||||
(main): Adjust to interface changes.
|
||||
Load database early to initialize version dependend variables.
|
||||
|
||||
* nss/db-open.c: Merge database routines from makedb.c.
|
||||
Define version dependend constansts as variables.
|
||||
(load_db): Check also for db 3.
|
||||
(internal_setent): Call dbopen.
|
||||
(db_cursor): New function from makedb; handles db 3 now.
|
||||
(dbopen): New function from makedb; handles db 3.
|
||||
|
||||
* nss/nss_db/db-XXX.c: Use db_notfound since the value is
|
||||
different in different DB versions.
|
||||
|
||||
* nss/nss_db/nss_db.h: Add version dependend constants as
|
||||
variables, add exportet interfaces from db-open.c.
|
||||
|
||||
* nss/Makefile ($(objpfx)makedb): Link against db-open.
|
||||
|
||||
2000-01-07 Ulrich Drepper <drepper@cygnus.com>
|
||||
|
||||
* misc/error.c: Don't use `defined _LIBC', only `_LIBC'.
|
||||
Reported by Jim Meyering.
|
||||
|
||||
* time/strftime.c: Pretty printing.
|
||||
|
||||
2000-01-07 Andreas Jaeger <aj@suse.de>
|
||||
|
||||
* manual/socket.texi (Host Names): Fix example.
|
||||
Reported by Marco Budde <budde@telos.de>.
|
||||
|
||||
2000-01-06 Ulrich Drepper <drepper@cygnus.com>
|
||||
|
||||
* localedata/Makefile (install-locales): Create locale directory
|
||||
|
@ -1310,6 +1310,7 @@ gethostname (char *host)
|
||||
int herr;
|
||||
|
||||
hstbuflen = 1024;
|
||||
/* Allocate buffer, remember to free it to avoid a memory leakage. */
|
||||
tmphstbuf = malloc (hstbuflen);
|
||||
|
||||
while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
|
||||
@ -1322,7 +1323,7 @@ gethostname (char *host)
|
||||
/* Check for errors. */
|
||||
if (res || hp == NULL)
|
||||
return NULL;
|
||||
return hp->h_name;
|
||||
return hp;
|
||||
@}
|
||||
@end smallexample
|
||||
@end deftypefun
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Error handler for noninteractive utilities
|
||||
Copyright (C) 1990,91,92,93,94,95,96,97,98 Free Software Foundation, Inc.
|
||||
Copyright (C) 1990-1998, 2000 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU C Library. Its master source is NOT part of
|
||||
the C library, however. The master source lives in /gd/gnu/lib.
|
||||
@ -156,7 +156,7 @@ error (status, errnum, message, va_alist)
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || defined _LIBC
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
|
||||
#else
|
||||
@ -231,7 +231,7 @@ error_at_line (status, errnum, file_name, line_number, message, va_alist)
|
||||
++error_message_count;
|
||||
if (errnum)
|
||||
{
|
||||
#if defined HAVE_STRERROR_R || defined _LIBC
|
||||
#if defined HAVE_STRERROR_R || _LIBC
|
||||
char errbuf[1024];
|
||||
fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
|
||||
#else
|
||||
|
@ -72,7 +72,7 @@ generated += $(filter-out db-alias.c db-netgrp.c, \
|
||||
distribute += db-XXX.c nss_db.h dummy-db.h
|
||||
|
||||
|
||||
$(objpfx)makedb: $(libdl)
|
||||
$(objpfx)makedb: $(libdl) $(objpfx)db-open.o
|
||||
|
||||
# Build static module if requested
|
||||
ifneq ($(build-static-nss),yes)
|
||||
|
206
nss/makedb.c
206
nss/makedb.c
@ -50,23 +50,6 @@ static int be_quiet;
|
||||
/* Name of output file. */
|
||||
static const char *output_name;
|
||||
|
||||
/* Various definitions for the libdb handling. */
|
||||
enum {
|
||||
nodb,
|
||||
db24,
|
||||
db27
|
||||
} libdb_version;
|
||||
static int (*db_open) (const char *, int,
|
||||
uint32_t, int, void *, void *, void **);
|
||||
|
||||
/* Constants which vary from version to version are actually variables
|
||||
here. */
|
||||
static int db_first;
|
||||
static int db_next;
|
||||
static int db_nooverwrite;
|
||||
static int db_truncate;
|
||||
|
||||
|
||||
/* Name and version of program. */
|
||||
static void print_version (FILE *stream, struct argp_state *state);
|
||||
void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
|
||||
@ -107,7 +90,6 @@ static struct argp argp =
|
||||
static int process_input (FILE *input, const char *inname, NSS_DB *output,
|
||||
int to_lowercase, int be_quiet);
|
||||
static int print_database (NSS_DB *db);
|
||||
static NSS_DB *dbopen (const char *fname, int oper, int mode);
|
||||
|
||||
|
||||
int
|
||||
@ -154,10 +136,15 @@ main (int argc, char *argv[])
|
||||
output_name = argv[remaining];
|
||||
}
|
||||
|
||||
/* First load the shared object to initialize version dependend
|
||||
variables. */
|
||||
if (load_db ())
|
||||
error (EXIT_FAILURE, 0, gettext ("No usable database library found."));
|
||||
|
||||
/* Special handling if we are asked to print the database. */
|
||||
if (do_undo)
|
||||
{
|
||||
db_file = dbopen (input_name, DB_RDONLY, 0666);
|
||||
dbopen (input_name, db_rdonly, 0666, &db_file);
|
||||
if (db_file == NULL)
|
||||
error (EXIT_FAILURE, 0, gettext ("cannot open database file `%s': %s"),
|
||||
input_name,
|
||||
@ -191,7 +178,7 @@ main (int argc, char *argv[])
|
||||
|
||||
/* Open output file. This must not be standard output so we don't
|
||||
handle "-" and "/dev/stdout" special. */
|
||||
db_file = dbopen (output_name, DB_CREATE | db_truncate, mode);
|
||||
dbopen (output_name, DB_CREATE | db_truncate, mode, &db_file);
|
||||
if (db_file == NULL)
|
||||
error (EXIT_FAILURE, errno, gettext ("cannot open output file `%s'"),
|
||||
output_name);
|
||||
@ -336,7 +323,7 @@ process_input (input, inname, output, to_lowercase, be_quiet)
|
||||
status = output->put (output->db, NULL, &key, &val, db_nooverwrite);
|
||||
if (status != 0)
|
||||
{
|
||||
if (status == DB_KEYEXIST)
|
||||
if (status == db_keyexist)
|
||||
{
|
||||
if (!be_quiet)
|
||||
error_at_line (0, 0, inname, linenr,
|
||||
@ -392,7 +379,7 @@ print_database (db)
|
||||
status = cursor->c_get (cursor->cursor, &key, &val, db_next);
|
||||
}
|
||||
|
||||
if (status != DB_NOTFOUND)
|
||||
if (status != db_notfound)
|
||||
{
|
||||
error (0, status, gettext ("while reading database"));
|
||||
return EXIT_FAILURE;
|
||||
@ -400,178 +387,3 @@ print_database (db)
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
load_db (void)
|
||||
{
|
||||
static const char *libnames[] = { "libdb.so.3" };
|
||||
int x;
|
||||
void *handle;
|
||||
|
||||
for(x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
|
||||
{
|
||||
handle = dlopen (libnames[x], RTLD_LAZY);
|
||||
if (handle == NULL)
|
||||
continue;
|
||||
|
||||
db_open = dlsym (handle, "db_open");
|
||||
if (db_open != NULL)
|
||||
{
|
||||
/* Alright, we got a library. Now find out which version it is. */
|
||||
const char *(*db_version) (int *, int *, int *);
|
||||
|
||||
db_version = dlsym (handle, "db_version");
|
||||
if (db_version != NULL)
|
||||
{
|
||||
/* Call the function and get the information. */
|
||||
int major, minor, subminor;
|
||||
|
||||
DL_CALL_FCT (db_version, (&major, &minor, &subminor));
|
||||
if (major == 2)
|
||||
{
|
||||
/* We currently cannot handle other versions than the
|
||||
2.x series. */
|
||||
if (minor < 6 || (minor == 6 && subminor < 4))
|
||||
{
|
||||
libdb_version = db24;
|
||||
db_first = DB24_FIRST;
|
||||
db_next = DB24_NEXT;
|
||||
db_nooverwrite = DB24_NOOVERWRITE;
|
||||
db_truncate = DB24_TRUNCATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
libdb_version = db27;
|
||||
db_first = DB27_FIRST;
|
||||
db_next = DB27_NEXT;
|
||||
db_nooverwrite = DB27_NOOVERWRITE;
|
||||
db_truncate = DB27_TRUNCATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (libdb_version != nodb)
|
||||
return 0;
|
||||
}
|
||||
|
||||
dlclose (handle);
|
||||
}
|
||||
|
||||
(void) dlerror ();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
db_cursor (void *db, void *txn, NSS_DBC **dbcp)
|
||||
{
|
||||
void *ptr;
|
||||
NSS_DBC *dbc = NULL;
|
||||
int ret;
|
||||
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
ret = ((struct db24 *) db)->cursor (db, txn, &ptr);
|
||||
break;
|
||||
case db27:
|
||||
ret = ((struct db27 *) db)->cursor (db, txn, &ptr, 0);
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
dbc = (NSS_DBC *) malloc (sizeof (NSS_DBC));
|
||||
if (dbc == NULL)
|
||||
error (EXIT_FAILURE, errno, gettext ("while reading database"));
|
||||
dbc->cursor = ptr;
|
||||
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
dbc->c_get =
|
||||
(int (*) (void *, void *, void *, uint32_t))
|
||||
((struct dbc24 *) ptr)->c_get;
|
||||
break;
|
||||
case db27:
|
||||
dbc->c_get =
|
||||
(int (*) (void *, void *, void *, uint32_t))
|
||||
((struct dbc27 *) ptr)->c_get;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
*dbcp = dbc;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static NSS_DB *
|
||||
dbopen (const char *fname, int oper, int mode)
|
||||
{
|
||||
int err;
|
||||
void *odb;
|
||||
NSS_DB *db;
|
||||
|
||||
/* First load the shared object. */
|
||||
load_db ();
|
||||
|
||||
if (db_open == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Actually open the database. */
|
||||
err = DL_CALL_FCT (db_open, (fname, DB_BTREE, oper, mode, NULL, NULL, &odb));
|
||||
if (err != 0)
|
||||
{
|
||||
errno = err;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Construct the object we pass up. */
|
||||
db = (NSS_DB *) malloc (sizeof (NSS_DB));
|
||||
if (db != NULL)
|
||||
{
|
||||
db->db = odb;
|
||||
|
||||
/* The functions are at different positions for the different
|
||||
versions. Sigh. */
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
db->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db24 *) odb)->close;
|
||||
db->fd =
|
||||
(int (*) (void *, int *)) ((struct db24 *) odb)->fd;
|
||||
db->get =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db24 *) odb)->get;
|
||||
db->put =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db24 *) odb)->put;
|
||||
break;
|
||||
case db27:
|
||||
db->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db27 *) odb)->close;
|
||||
db->fd =
|
||||
(int (*) (void *, int *)) ((struct db27 *) odb)->fd;
|
||||
db->get =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db27 *) odb)->get;
|
||||
db->put =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db27 *) odb)->put;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
db->cursor = db_cursor;
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ lookup (DBT *key, struct STRUCTURE *result,
|
||||
err = DL_CALL_FCT (db->get, (db->db, NULL, key, &value, 0));
|
||||
if (err != 0)
|
||||
{
|
||||
if (err == DB_NOTFOUND)
|
||||
if (err == db_notfound)
|
||||
{
|
||||
H_ERRNO_SET (HOST_NOT_FOUND);
|
||||
status = NSS_STATUS_NOTFOUND;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Common database open/close routines for nss_db.
|
||||
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
|
||||
/* Common database routines for nss_db.
|
||||
Copyright (C) 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -17,10 +17,12 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <libintl.h>
|
||||
#include <bits/libc-lock.h>
|
||||
|
||||
#include "dummy-db.h"
|
||||
@ -41,30 +43,54 @@ static void *libdb_handle;
|
||||
enum {
|
||||
nodb,
|
||||
db24,
|
||||
db27
|
||||
db27,
|
||||
db30
|
||||
} libdb_version;
|
||||
static int (*libdb_db_open) (const char *, int,
|
||||
uint32_t, int, void *, void *, void **);
|
||||
|
||||
static int (*libdb_db_create) (void *, void *, uint32_t);
|
||||
|
||||
/* Constants which vary from version to version are actually variables
|
||||
here. */
|
||||
int db_first;
|
||||
int db_next;
|
||||
int db_nooverwrite;
|
||||
int db_truncate;
|
||||
int db_rdonly;
|
||||
/* Variables which keep track of the error values. */
|
||||
int db_keyexist;
|
||||
int db_notfound;
|
||||
|
||||
/* Locks the static variables in this file. */
|
||||
__libc_lock_define_initialized (static, lock)
|
||||
|
||||
/* Dynamically load the database library.
|
||||
We try libdb2.so.3, maybe others in the future. */
|
||||
static int
|
||||
We try currently:
|
||||
- libdb.so.3: the name used by glibc 2.1
|
||||
- libdb-3.0.so: the name used by db-3.0.x
|
||||
and maybe others in the future. */
|
||||
|
||||
int
|
||||
load_db (void)
|
||||
{
|
||||
static const char *libnames[] = { "libdb.so.3" };
|
||||
static const char *libnames[] = { "libdb.so.3", "libdb-3.0.so" };
|
||||
int x;
|
||||
|
||||
for(x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
|
||||
for (x = 0; x < sizeof (libnames) / sizeof (libnames[0]); ++x)
|
||||
{
|
||||
libdb_handle = dlopen (libnames[x], RTLD_LAZY);
|
||||
if (libdb_handle == NULL)
|
||||
continue;
|
||||
|
||||
libdb_db_open = dlsym (libdb_handle, "db_open");
|
||||
if (libdb_db_open != NULL)
|
||||
/* db 3.0 has db_create instead of db_open. */
|
||||
libdb_db_create = dlsym (libdb_handle, "db_create");
|
||||
|
||||
if (libdb_db_create == NULL)
|
||||
/* db 2.x uses db_open. */
|
||||
libdb_db_open = dlsym (libdb_handle, "db_open");
|
||||
|
||||
if (libdb_db_open != NULL || libdb_db_create != NULL)
|
||||
{
|
||||
/* Alright, we got a library. Now find out which version it is. */
|
||||
const char *(*db_version) (int *, int *, int *);
|
||||
@ -76,19 +102,55 @@ load_db (void)
|
||||
int major, minor, subminor;
|
||||
|
||||
DL_CALL_FCT (db_version, (&major, &minor, &subminor));
|
||||
if (major == 2)
|
||||
switch (major)
|
||||
{
|
||||
/* We currently cannot handle other versions than the
|
||||
2.x series. */
|
||||
if (minor < 6 || (minor == 6 && subminor < 4))
|
||||
libdb_version = db24;
|
||||
else
|
||||
libdb_version = db27;
|
||||
case 2:
|
||||
/* Sanity check: Do we have db_open? */
|
||||
if (libdb_db_open != NULL)
|
||||
{
|
||||
if (minor < 6 || (minor == 6 && subminor < 4))
|
||||
{
|
||||
libdb_version = db24;
|
||||
db_first = DB24_FIRST;
|
||||
db_next = DB24_NEXT;
|
||||
db_nooverwrite = DB24_NOOVERWRITE;
|
||||
db_truncate = DB24_TRUNCATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
libdb_version = db27;
|
||||
db_first = DB27_FIRST;
|
||||
db_next = DB27_NEXT;
|
||||
db_nooverwrite = DB27_NOOVERWRITE;
|
||||
db_truncate = DB27_TRUNCATE;
|
||||
}
|
||||
db_keyexist = DB2x_KEYEXIST;
|
||||
db_notfound = DB2x_NOTFOUND;
|
||||
db_rdonly = DB2x_RDONLY;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
/* Sanity check: Do we have db_create? */
|
||||
if (libdb_db_create != NULL)
|
||||
{
|
||||
libdb_version = db30;
|
||||
db_first = DB30_FIRST;
|
||||
db_next = DB30_NEXT;
|
||||
db_keyexist = DB30_KEYEXIST;
|
||||
db_notfound = DB30_NOTFOUND;
|
||||
db_rdonly = DB30_RDONLY;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (libdb_version != nodb)
|
||||
return 0;
|
||||
|
||||
/* Clear variables. */
|
||||
libdb_db_open = NULL;
|
||||
libdb_db_create = NULL;
|
||||
}
|
||||
|
||||
dlclose (libdb_handle);
|
||||
@ -98,7 +160,6 @@ load_db (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Make sure we don't use the library anymore once we are shutting down. */
|
||||
static void __attribute__ ((destructor))
|
||||
unload_db (void)
|
||||
@ -106,83 +167,206 @@ unload_db (void)
|
||||
if (libdb_handle != NULL)
|
||||
{
|
||||
libdb_db_open = NULL;
|
||||
libdb_db_create = NULL;
|
||||
libdb_version = nodb;
|
||||
dlclose (libdb_handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum nss_status
|
||||
internal_setent (const char *file, NSS_DB **dbp)
|
||||
{
|
||||
enum nss_status status = NSS_STATUS_SUCCESS;
|
||||
int err;
|
||||
void *db;
|
||||
int fd;
|
||||
int result;
|
||||
|
||||
|
||||
if (*dbp == NULL)
|
||||
{
|
||||
if (libdb_db_open == NULL)
|
||||
if (libdb_db_open == NULL && libdb_db_create == NULL)
|
||||
{
|
||||
__libc_lock_lock (lock);
|
||||
|
||||
err = load_db ();
|
||||
status = load_db ();
|
||||
|
||||
__libc_lock_unlock (lock);
|
||||
|
||||
if (err != 0)
|
||||
return NSS_STATUS_UNAVAIL;
|
||||
if (status != 0)
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Open the database. Fortunately this interface seems to be the
|
||||
same for all supported versions. */
|
||||
err = DL_CALL_FCT (libdb_db_open,
|
||||
(file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db));
|
||||
status = dbopen (file, db_rdonly, 0, dbp);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* Close the database file. */
|
||||
void
|
||||
internal_endent (NSS_DB **dbp)
|
||||
{
|
||||
NSS_DB *db = *dbp;
|
||||
if (db != NULL)
|
||||
{
|
||||
DL_CALL_FCT (db->close, (db->db, 0));
|
||||
*dbp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
db_cursor (void *db, void *txn, NSS_DBC **dbcp)
|
||||
{
|
||||
void *ptr;
|
||||
NSS_DBC *dbc = NULL;
|
||||
int ret;
|
||||
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
ret = ((struct db24 *) db)->cursor (db, txn, &ptr);
|
||||
break;
|
||||
case db27:
|
||||
ret = ((struct db27 *) db)->cursor (db, txn, &ptr, 0);
|
||||
break;
|
||||
case db30:
|
||||
ret = ((struct db30 *) db)->cursor (db, txn, &ptr, 0);
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
dbc = (NSS_DBC *) malloc (sizeof (NSS_DBC));
|
||||
if (dbc == NULL)
|
||||
return 1;
|
||||
dbc->cursor = ptr;
|
||||
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
dbc->c_get =
|
||||
(int (*) (void *, void *, void *, uint32_t))
|
||||
((struct dbc24 *) ptr)->c_get;
|
||||
break;
|
||||
case db27:
|
||||
dbc->c_get =
|
||||
(int (*) (void *, void *, void *, uint32_t))
|
||||
((struct dbc27 *) ptr)->c_get;
|
||||
break;
|
||||
case db30:
|
||||
dbc->c_get =
|
||||
(int (*) (void *, void *, void *, uint32_t))
|
||||
((struct dbc30 *) ptr)->c_get;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
*dbcp = dbc;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
dbopen (const char *fname, int oper, int mode, NSS_DB **dbp)
|
||||
{
|
||||
int err;
|
||||
int result;
|
||||
int fd;
|
||||
void *odb;
|
||||
enum nss_status status = NSS_STATUS_SUCCESS;
|
||||
NSS_DB *db;
|
||||
|
||||
/* 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, &odb));
|
||||
if (err != 0)
|
||||
{
|
||||
__set_errno (err);
|
||||
*dbp = NULL;
|
||||
return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
|
||||
}
|
||||
break;
|
||||
case db30:
|
||||
err = DL_CALL_FCT (libdb_db_create, (&odb, NULL, 0));
|
||||
if (err != 0)
|
||||
{
|
||||
__set_errno (err);
|
||||
*dbp = NULL;
|
||||
return err == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
|
||||
}
|
||||
err = ((struct db30 *) odb)->open (odb, fname, NULL, DB_BTREE,
|
||||
oper, mode);
|
||||
if (err != 0)
|
||||
{
|
||||
__set_errno (err);
|
||||
/* Free all resources. */
|
||||
((struct db30 *) odb)->close (odb, 0);
|
||||
*dbp = NULL;
|
||||
return NSS_STATUS_UNAVAIL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
/* Construct the object we pass up. */
|
||||
*dbp = (NSS_DB *) malloc (sizeof (NSS_DB));
|
||||
if (*dbp == NULL)
|
||||
return NSS_STATUS_UNAVAIL;
|
||||
|
||||
(*dbp)->db = db;
|
||||
/* Construct the object we pass up. */
|
||||
db = (NSS_DB *) malloc (sizeof (NSS_DB));
|
||||
if (db != NULL)
|
||||
{
|
||||
db->db = odb;
|
||||
|
||||
/* The functions are at different positions for the different
|
||||
versions. Sigh. */
|
||||
switch (libdb_version)
|
||||
{
|
||||
case db24:
|
||||
(*dbp)->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db24 *) db)->close;
|
||||
(*dbp)->fd =
|
||||
(int (*) (void *, int *)) ((struct db24 *) db)->fd;
|
||||
(*dbp)->get =
|
||||
db->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db24 *) odb)->close;
|
||||
db->fd =
|
||||
(int (*) (void *, int *)) ((struct db24 *) odb)->fd;
|
||||
db->get =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db24 *) db)->get;
|
||||
((struct db24 *) odb)->get;
|
||||
db->put =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db24 *) odb)->put;
|
||||
break;
|
||||
case db27:
|
||||
(*dbp)->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db27 *) db)->close;
|
||||
(*dbp)->fd =
|
||||
(int (*) (void *, int *)) ((struct db27 *) db)->fd;
|
||||
(*dbp)->get =
|
||||
db->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db27 *) odb)->close;
|
||||
db->fd =
|
||||
(int (*) (void *, int *)) ((struct db27 *) odb)->fd;
|
||||
db->get =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db27 *) db)->get;
|
||||
((struct db27 *) odb)->get;
|
||||
db->put =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db27 *) odb)->put;
|
||||
break;
|
||||
case db30:
|
||||
db->close =
|
||||
(int (*) (void *, uint32_t)) ((struct db30 *) odb)->close;
|
||||
db->fd =
|
||||
(int (*) (void *, int *)) ((struct db30 *) odb)->fd;
|
||||
db->get =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db30 *) odb)->get;
|
||||
db->put =
|
||||
(int (*) (void *, void *, void *, void *, uint32_t))
|
||||
((struct db30 *) odb)->put;
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
db->cursor = db_cursor;
|
||||
|
||||
/* We have to make sure the file is `closed on exec'. */
|
||||
err = DL_CALL_FCT ((*dbp)->fd, (db, &fd));
|
||||
err = DL_CALL_FCT (db->fd, (odb, &fd));
|
||||
if (err != 0)
|
||||
{
|
||||
__set_errno (err);
|
||||
@ -202,25 +386,13 @@ internal_setent (const char *file, NSS_DB **dbp)
|
||||
{
|
||||
/* Something went wrong. Close the stream and return a
|
||||
failure. */
|
||||
DL_CALL_FCT ((*dbp)->close, (db, 0));
|
||||
DL_CALL_FCT (db->close, (odb, 0));
|
||||
free (db);
|
||||
status = NSS_STATUS_UNAVAIL;
|
||||
free (*dbp);
|
||||
*dbp = NULL;
|
||||
db = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*dbp = db;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* Close the database file. */
|
||||
void
|
||||
internal_endent (NSS_DB **dbp)
|
||||
{
|
||||
NSS_DB *db = *dbp;
|
||||
if (db != NULL)
|
||||
{
|
||||
DL_CALL_FCT (db->close, (db->db, 0));
|
||||
*dbp = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,18 @@
|
||||
Define only what we really need. */
|
||||
#define DB_BTREE (1)
|
||||
|
||||
/* Permission flags are also not changed. */
|
||||
#define DB_RDONLY 0x010000
|
||||
/* Permission flags. */
|
||||
#define DB2x_RDONLY 0x010000
|
||||
|
||||
/* Access methods. */
|
||||
#define DB24_FIRST 0x000020
|
||||
#define DB24_NEXT 0x000800
|
||||
#define DB24_NOOVERWRITE 0x001000
|
||||
|
||||
/* The error values that are needed. */
|
||||
#define DB2x_KEYEXIST ( -3)
|
||||
#define DB2x_NOTFOUND ( -7)
|
||||
|
||||
|
||||
/* This is for the db-2.x version up to 2.x.y. We use the name `db24' since
|
||||
this is the version which was shipped with glibc 2.1. */
|
||||
@ -173,3 +177,135 @@ struct dbc27
|
||||
#define DB27_FIRST 7
|
||||
#define DB27_NEXT 15
|
||||
#define DB27_NOOVERWRITE 17
|
||||
|
||||
/* Versions for 3.0, incompatible with version 2.x. */
|
||||
struct db30
|
||||
{
|
||||
size_t pgsize;
|
||||
void (*db_feedback) (void *, int, int);
|
||||
void *(*db_malloc) (size_t);
|
||||
void *(*db_realloc) (void *, size_t);
|
||||
int (*dup_compare) (const DBT *, const DBT *);
|
||||
void *dbenv;
|
||||
enum { dummy30 } type;
|
||||
void *mpf;
|
||||
void *mutexp;
|
||||
u_int8_t fileid[20];
|
||||
int32_t log_fileid;
|
||||
void *open_txn;
|
||||
void *saved_open_fhp;
|
||||
struct
|
||||
{
|
||||
void *tqh_first;
|
||||
void **tqh_last;
|
||||
} free_queue;
|
||||
struct
|
||||
{
|
||||
void *tqh_first;
|
||||
void **tqh_last;
|
||||
} active_queue;
|
||||
void *bt_internal;
|
||||
void *cj_internal;
|
||||
void *h_internal;
|
||||
void *q_internal;
|
||||
void *xa_internal;
|
||||
/* Functions. */
|
||||
int (*close) (void *, uint32_t);
|
||||
int (*cursor) (void *, void *, void **, uint32_t);
|
||||
int (*del) (void *, void *, DBT *, uint32_t);
|
||||
void (*err) (void *, int, const char *, ...);
|
||||
void (*errx) (void *, const char *, ...);
|
||||
int (*fd) (void *, int *);
|
||||
int (*get) (void *, void *, DBT *, DBT *, uint32_t);
|
||||
int (*get_byteswapped) (void *);
|
||||
int (*get_type) (void *);
|
||||
int (*join) (void *, void **, void **, uint32_t);
|
||||
int (*open) (void *, const char *, const char *, int, uint32_t, int);
|
||||
int (*put) (void *, void *, DBT *, DBT *, uint32_t);
|
||||
int (*remove) (void *, const char *, const char *, uint32_t);
|
||||
int (*set_cachesize) (void *, uint32_t, uint32_t, int);
|
||||
int (*set_dup_compare) (void *, int (*)(const DBT *, const DBT *));
|
||||
void (*set_errcall) (void *, void (*)(const char *, char *));
|
||||
void (*set_errfile) (void *, void *);
|
||||
void (*set_errpfx) (void *, const char *);
|
||||
void (*set_feedback) (void *, void (*)(void *, int, int));
|
||||
int (*set_flags) (void *, uint32_t);
|
||||
int (*set_lorder) (void *, int);
|
||||
int (*set_malloc) (void *, void *(*)(size_t));
|
||||
int (*set_pagesize) (void *, uint32_t);
|
||||
void (*set_paniccall) (void *, void (*)(void *, int));
|
||||
int (*set_realloc) (void *, void *(*)(void *, size_t));
|
||||
int (*stat) (void *, void *, void *(*)(size_t), uint32_t);
|
||||
int (*sync) (void *, uint32_t);
|
||||
int (*upgrade) (void *, const char *, uint32_t);
|
||||
|
||||
int (*set_bt_compare) (void *, int (*)(const DBT *, const DBT *));
|
||||
int (*set_bt_maxkey) (void *, uint32_t);
|
||||
int (*set_bt_minkey) (void *, uint32_t);
|
||||
int (*set_bt_prefix) (void *, size_t (*)(const DBT *, const DBT *));
|
||||
|
||||
int (*set_h_ffactor) (void *, uint32_t);
|
||||
int (*set_h_hash) (void *, uint32_t (*)(const void *, uint32_t));
|
||||
int (*set_h_nelem) (void *, uint32_t);
|
||||
|
||||
int (*set_re_delim) (void *, int);
|
||||
int (*set_re_len) (void *, uint32_t);
|
||||
int (*set_re_pad) (void *, int);
|
||||
int (*set_re_source) (void *, const char *);
|
||||
|
||||
uint32_t am_ok;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
|
||||
struct dbc30
|
||||
{
|
||||
void *dbp;
|
||||
void *txn;
|
||||
struct
|
||||
{
|
||||
void *tqe_next;
|
||||
void **tqe_prev;
|
||||
} links;
|
||||
uint32_t lid; /* Default process' locker id. */
|
||||
uint32_t locker; /* Locker for this operation. */
|
||||
DBT lock_dbt; /* DBT referencing lock. */
|
||||
struct
|
||||
{
|
||||
uint32_t pgno;
|
||||
uint8_t fileid[20];
|
||||
} lock;
|
||||
struct
|
||||
{
|
||||
size_t off;
|
||||
uint32_t ndx;
|
||||
uint32_t gen;
|
||||
} mylock;
|
||||
DBT rkey;
|
||||
DBT rdata;
|
||||
int (*c_close) (void *);
|
||||
int (*c_del) (void *, uint32_t);
|
||||
int (*c_dup) (void *, void **, uint32_t);
|
||||
int (*c_get) (void *, DBT *, DBT *, uint32_t);
|
||||
int (*c_put) (void *, DBT *, DBT *, uint32_t);
|
||||
int (*c_am_close) (void *);
|
||||
int (*c_am_destroy) (void *);
|
||||
void *internal;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
/* Flags which changed. */
|
||||
#define DB30_TRUNCATE 0x020000
|
||||
|
||||
/* Access methods. */
|
||||
#define DB30_FIRST 9
|
||||
#define DB30_NEXT 17
|
||||
#define DB30_NOOVERWRITE 20
|
||||
|
||||
/* Permission flags are changed. */
|
||||
#define DB30_RDONLY 0x000010
|
||||
|
||||
|
||||
/* The error values that are needed. */
|
||||
#define DB30_KEYEXIST (-30997)
|
||||
#define DB30_NOTFOUND (-30994)
|
||||
|
@ -22,10 +22,17 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* The error values kept the same values though new values were added.
|
||||
Define only those which we need. */
|
||||
#define DB_KEYEXIST ( -3)
|
||||
#define DB_NOTFOUND ( -7)
|
||||
/* Variables which keep track of the error values. */
|
||||
extern int db_keyexist;
|
||||
extern int db_notfound;
|
||||
|
||||
/* Constants which vary from version to version are actually variables
|
||||
here. */
|
||||
extern int db_first;
|
||||
extern int db_next;
|
||||
extern int db_nooverwrite;
|
||||
extern int db_truncate;
|
||||
extern int db_rdonly;
|
||||
|
||||
/* Flags are also unchanged. */
|
||||
#define DB_CREATE 0x000001
|
||||
@ -69,5 +76,9 @@ typedef struct {
|
||||
|
||||
extern enum nss_status internal_setent (const char *file, NSS_DB **dbp);
|
||||
extern void internal_endent (NSS_DB **dbp);
|
||||
extern int db_cursor (void *db, void *txn, NSS_DBC **dbcp);
|
||||
extern int load_db (void);
|
||||
extern int dbopen (const char *fname, int oper, int mode, NSS_DB **dbp);
|
||||
|
||||
|
||||
#endif /* nss_db.h */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -495,11 +495,11 @@ my_strftime (s, maxsize, format, tp ut_argument)
|
||||
# define ap_len STRLEN (ampm)
|
||||
#else
|
||||
# if !HAVE_STRFTIME
|
||||
# define f_wkday (weekday_name[tp->tm_wday])
|
||||
# define f_month (month_name[tp->tm_mon])
|
||||
# define a_wkday f_wkday
|
||||
# define a_month f_month
|
||||
# define ampm (L_("AMPM") + 2 * (tp->tm_hour > 11))
|
||||
# define f_wkday (weekday_name[tp->tm_wday])
|
||||
# define f_month (month_name[tp->tm_mon])
|
||||
# define a_wkday f_wkday
|
||||
# define a_month f_month
|
||||
# define ampm (L_("AMPM") + 2 * (tp->tm_hour > 11))
|
||||
|
||||
size_t aw_len = 3;
|
||||
size_t am_len = 3;
|
||||
|
Loading…
Reference in New Issue
Block a user