/*
** Copyright (c) 1999-2002, 2004, 2009 Sendmail, Inc. and its suppliers.
** All rights reserved.
**
** By using this file, you agree to the terms and conditions set
** forth in the LICENSE file which can be found at the top level of
** the sendmail distribution.
*/
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sendmail/sendmail.h>
#if (DB_VERSION_MAJOR == 1)
struct smdb_db1_struct
{
int smdb1_lock_fd;
bool smdb1_cursor_in_use;
};
struct smdb_db1_cursor
{
};
/*
** SMDB_TYPE_TO_DB1_TYPE -- Translates smdb database type to db1 type.
**
** Parameters:
** type -- The type to translate.
**
** Returns:
** The DB1 type that corresponsds to the passed in SMDB type.
** Returns -1 if there is no equivalent type.
**
*/
static DBTYPE
{
if (type == SMDB_TYPE_DEFAULT)
return DB_HASH;
return DB_HASH;
return DB_BTREE;
/* Should never get here thanks to test in smdb_db_open() */
return DB_HASH;
}
/*
** SMDB_PUT_FLAGS_TO_DB1_FLAGS -- Translates smdb put flags to db1 put flags.
**
** Parameters:
** flags -- The flags to translate.
**
** Returns:
** The db1 flags that are equivalent to the smdb flags.
**
** Notes:
** Any invalid flags are ignored.
**
*/
static unsigned int
{
int return_flags;
return_flags = 0;
return return_flags;
}
/*
** SMDB_CURSOR_GET_FLAGS_TO_SMDB1
**
** Parameters:
** flags -- The flags to translate.
**
** Returns:
** The db1 flags that are equivalent to the smdb flags.
**
** Notes:
** Returns -1 if we don't support the flag.
**
*/
static int
{
switch(flags)
{
case SMDB_CURSOR_GET_FIRST:
return R_FIRST;
case SMDB_CURSOR_GET_LAST:
return R_LAST;
case SMDB_CURSOR_GET_NEXT:
return R_NEXT;
case SMDB_CURSOR_GET_RANGE:
return R_CURSOR;
default:
return -1;
}
}
/*
** The rest of these functions correspond to the interface laid out in smdb.h.
*/
static SMDB_DB1_DATABASE *
{
{
db1->smdb1_cursor_in_use = false;
}
return db1;
}
static int
{
int result;
return result;
}
static int
unsigned int flags;
{
}
static int
int *fd;
{
if (*fd == -1)
return errno;
return SMDBE_OK;
}
static int
{
return db1->smdb1_lock_fd;
}
static int
unsigned int flags;
{
int result;
if (result != 0)
{
if (result == 1)
return SMDBE_NOT_FOUND;
return errno;
}
return SMDBE_OK;
}
static int
unsigned int flags;
{
}
static int
{
# if HASFCHOWN
int fd;
int result;
if (fd == -1)
return errno;
if (result < 0)
return errno;
# endif /* HASFCHOWN */
return SMDBE_OK;
}
static int
unsigned int flags;
{
}
static int
{
if (!db1->smdb1_cursor_in_use)
return SMDBE_NOT_A_VALID_CURSOR;
db1->smdb1_cursor_in_use = false;
return SMDBE_OK;
}
static int
unsigned int flags;
{
}
static int
{
int db1_flags;
int result;
if (result == -1)
return errno;
if (result == 1)
return SMDBE_LAST_ENTRY;
return SMDBE_OK;
}
static int
{
}
static int
unsigned int flags;
{
if (db1->smdb1_cursor_in_use)
return SMDBE_ONLY_SUPPORTS_ONE_CURSOR;
if (db1_cursor == NULL)
return SMDBE_MALLOC;
{
return SMDBE_MALLOC;
}
db1->smdb1_cursor_in_use = true;
return SMDBE_OK;
}
/*
** SMDB_DB_OPEN -- Opens a db1 database.
**
** Parameters:
** database -- An unallocated database pointer to a pointer.
** db_name -- The name of the database without extension.
** mode -- File permisions on the database if created.
** mode_mask -- Mode bits that must match on an existing database.
** sff -- Flags for safefile.
** type -- The type of database to open
** See smdb_type_to_db1_type for valid types.
** user_info -- Information on the user to use for file
** permissions.
** db_params --
** An SMDB_DBPARAMS struct including params. These
** are processed according to the type of the
** database. Currently supported params (only for
** HASH type) are:
** num_elements
** cache_size
**
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
char *db_name;
int mode;
int mode_mask;
long sff;
{
bool lockcreated = false;
int db_fd;
int lock_fd;
int result;
void *params;
return SMDBE_UNKNOWN_DB_TYPE;
return result;
return result;
lockcreated = true;
lock_fd = -1;
return result;
if (lockcreated)
{
}
db1 = smdb1_malloc_database();
{
(void) smdb_unlock_file(lock_fd);
return SMDBE_MALLOC;
}
{
}
{
if (db_params->smdbp_allow_dup)
params = &btree_info;
}
{
&stat_info);
}
else
{
if (errno == 0)
else
}
{
/* Everything is ok. Setup driver */
return SMDBE_OK;
}
/* Error opening database */
return result;
}
#endif /* (DB_VERSION_MAJOR == 1) */