/*
** Copyright (c) 1999-2003, 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 <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sendmail/sendmail.h>
#if (DB_VERSION_MAJOR >= 2)
struct smdb_db2_database
{
int smdb2_lock_fd;
};
/*
** SMDB_TYPE_TO_DB2_TYPE -- Translates smdb database type to db2 type.
**
** Parameters:
** type -- The type to translate.
**
** Returns:
** The DB2 type that corresponsds to the passed in SMDB type.
** Returns -1 if there is no equivalent type.
**
*/
{
if (type == SMDB_TYPE_DEFAULT)
return DB_HASH;
return DB_HASH;
return DB_BTREE;
return DB_UNKNOWN;
}
/*
** DB2_ERROR_TO_SMDB -- Translates db2 errors to smdbe errors
**
** Parameters:
** error -- The error to translate.
**
** Returns:
** The SMDBE error corresponding to the db2 error.
** If we don't have a corresponding error, it returs errno.
**
*/
int
int error;
{
int result;
switch (error)
{
# ifdef DB_INCOMPLETE
case DB_INCOMPLETE:
break;
# endif /* DB_INCOMPLETE */
# ifdef DB_NOTFOUND
case DB_NOTFOUND:
break;
# endif /* DB_NOTFOUND */
# ifdef DB_KEYEMPTY
case DB_KEYEMPTY:
break;
# endif /* DB_KEYEMPTY */
# ifdef DB_KEYEXIST
case DB_KEYEXIST:
break;
# endif /* DB_KEYEXIST */
# ifdef DB_LOCK_DEADLOCK
case DB_LOCK_DEADLOCK:
break;
# endif /* DB_LOCK_DEADLOCK */
# ifdef DB_LOCK_NOTGRANTED
case DB_LOCK_NOTGRANTED:
break;
# endif /* DB_LOCK_NOTGRANTED */
# ifdef DB_LOCK_NOTHELD
case DB_LOCK_NOTHELD:
break;
# endif /* DB_LOCK_NOTHELD */
# ifdef DB_RUNRECOVERY
case DB_RUNRECOVERY:
break;
# endif /* DB_RUNRECOVERY */
# ifdef DB_OLD_VERSION
case DB_OLD_VERSION:
break;
# endif /* DB_OLD_VERSION */
case 0:
break;
default:
}
return result;
}
/*
** SMDB_PUT_FLAGS_TO_DB2_FLAGS -- Translates smdb put flags to db2 put flags.
**
** Parameters:
** flags -- The flags to translate.
**
** Returns:
** The db2 flags that are equivalent to the smdb flags.
**
** Notes:
** Any invalid flags are ignored.
**
*/
unsigned int
{
int return_flags;
return_flags = 0;
return return_flags;
}
/*
** SMDB_CURSOR_GET_FLAGS_TO_DB2 -- Translates smdb cursor get flags to db2
** getflags.
**
** Parameters:
** flags -- The flags to translate.
**
** Returns:
** The db2 flags that are equivalent to the smdb flags.
**
** Notes:
** -1 is returned if flag is unknown.
**
*/
int
{
switch (flags)
{
case SMDB_CURSOR_GET_FIRST:
return DB_FIRST;
case SMDB_CURSOR_GET_LAST:
return DB_LAST;
case SMDB_CURSOR_GET_NEXT:
return DB_NEXT;
case SMDB_CURSOR_GET_RANGE:
return DB_SET_RANGE;
default:
return -1;
}
}
/*
** Except for smdb_db_open, the rest of these functions correspond to the
** interface laid out in smdb.h.
*/
{
return db2;
}
int
{
int result;
return result;
}
int
unsigned int flags;
{
}
int
int *fd;
{
}
int
{
return db2->smdb2_lock_fd;
}
int
unsigned int flags;
{
int result;
return db2_error_to_smdb(result);
}
int
unsigned int flags;
{
}
int
{
# if HASFCHOWN
int fd;
int result;
if (result != 0)
return result;
if (result < 0)
return errno;
# endif /* HASFCHOWN */
return SMDBE_OK;
}
int
unsigned int flags;
{
}
int
{
int ret;
return ret;
}
int
{
}
int
{
int db2_flags;
int result;
if (result == DB_NOTFOUND)
return SMDBE_LAST_ENTRY;
return db2_error_to_smdb(result);
}
int
{
}
int
{
int result;
# else /* DB_VERSION_MAJOR > 2 || DB_VERSION_MINOR >= 6 */
# endif /* DB_VERSION_MAJOR > 2 || DB_VERSION_MINOR >= 6 */
if (result != 0)
return db2_error_to_smdb(result);
return SMDBE_MALLOC;
return SMDBE_OK;
}
# if DB_VERSION_MAJOR == 2
static int
char *db_name;
int db_flags;
{
void *params;
{
if (db_params->smdbp_allow_dup)
}
}
# endif /* DB_VERSION_MAJOR == 2 */
# if DB_VERSION_MAJOR > 2
static int
char *db_name;
int db_flags;
{
int result;
return result;
{
db_params->smdbp_cache_size, 0);
if (result != 0)
{
return db2_error_to_smdb(result);
}
{
if (result != 0)
{
return db2_error_to_smdb(result);
}
}
if (db_params->smdbp_allow_dup)
{
if (result != 0)
{
return db2_error_to_smdb(result);
}
}
}
DBTXN /* transaction for DB 4.1 */
if (result != 0)
{
}
return db2_error_to_smdb(result);
}
# endif /* DB_VERSION_MAJOR > 2 */
/*
** SMDB_DB_OPEN -- Opens a db database.
**
** Parameters:
** database -- An unallocated database pointer to a pointer.
** db_name -- The name of the database without extension.
** mode -- File permisions for a created database.
** mode_mask -- Mode bits that must match on an opened database.
** sff -- Flags for safefile.
** type -- The type of database to open
** See smdb_type_to_db2_type for valid types.
** user_info -- User information 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, other errno:
** SMDBE_MALLOC -- Cannot allocate memory.
** SMDBE_BAD_OPEN -- db_open didn't return an error, but
** somehow the DB pointer is NULL.
** Anything else: translated error from db2
*/
int
char *db_name;
int mode;
int mode_mask;
long sff;
{
bool lockcreated = false;
int result;
int db_flags;
int lock_fd;
int db_fd;
return SMDBE_VERSION_MISMATCH;
return result;
return result;
lock_fd = -1;
lockcreated = true;
return result;
if (lockcreated)
{
}
db2 = smdb2_malloc_database();
{
return SMDBE_MALLOC;
}
db_flags = 0;
db_flags |= DB_TRUNCATE;
{
if (result == 0)
}
else
{
/* Try and narrow down on the problem */
if (result != 0)
else
}
&stat_info);
{
/* Everything is ok. Setup driver */
return SMDBE_OK;
}
return result;
}
#endif /* (DB_VERSION_MAJOR >= 2) */