/*
** Copyright (c) 1999-2002 Proofpoint, 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>
static bool smdb_lockfile __P((int, int));
/*
** SMDB_MALLOC_DATABASE -- Allocates a database structure.
**
** Parameters:
** None
**
** Returns:
** An pointer to an allocated SMDB_DATABASE structure or
** NULL if it couldn't allocate the memory.
*/
{
return db;
}
/*
** SMDB_FREE_DATABASE -- Unallocates a database structure.
**
** Parameters:
** database -- a SMDB_DATABASE pointer to deallocate.
**
** Returns:
** None
*/
void
{
}
/*
** SMDB_LOCKFILE -- lock a file using flock or (shudder) fcntl locking
**
** Parameters:
** fd -- the file descriptor of the file.
** type -- type of the lock. Bits can be:
** LOCK_EX -- exclusive lock.
** LOCK_NB -- non-blocking.
**
** Returns:
** true if the lock was acquired.
** false otherwise.
*/
static bool
int fd;
int type;
{
int i;
int save_errno;
#if !HASFLOCK
int action;
else
else
continue;
if (i >= 0)
return true;
save_errno = errno;
/*
** as type "tmp" (that is, served from swap space), the
** previous fcntl will fail with "Invalid argument" errors.
** Since this is fairly common during testing, we will assume
** that this indicates that the lock is successfully grabbed.
*/
if (save_errno == EINVAL)
return true;
{
# if 0
# endif /* 0 */
errno = save_errno;
return false;
}
#else /* !HASFLOCK */
continue;
if (i >= 0)
return true;
save_errno = errno;
{
# if 0
# endif /* 0 */
errno = save_errno;
return false;
}
#endif /* !HASFLOCK */
errno = save_errno;
return false;
}
/*
** SMDB_OPEN_DATABASE -- Opens a database.
**
** This opens a database. If type is SMDB_DEFAULT it tries to
** use a DB1 or DB2 hash. If that isn't available, it will try
** to use NDBM. If a specific type is given it will try to open
** a database of that type.
**
** Parameters:
** database -- An pointer to a SMDB_DATABASE pointer where the
** opened database will be stored. This should
** be unallocated.
** db_name -- The name of the database to open. Do not include
** the file name extension.
** mode -- The mode to set on the database file or files.
** mode_mask -- Mode bits that must match on an opened database.
** sff -- Flags to safefile.
** type -- The type of database to open. Supported types
** vary depending on what was compiled in.
** user_info -- Information on the user to use for file
** permissions.
** params -- Params specific to the database being opened.
** Only supports some DB hash options right now
** (see smdb_db_open() for details).
**
** Returns:
** SMDBE_OK -- Success.
** Anything else is an error. Look up more info about the
** error in the comments for the specific open() used.
*/
int
char *db_name;
int mode;
int mode_mask;
long sff;
{
bool type_was_default = false;
if (type == SMDB_TYPE_DEFAULT)
{
type_was_default = true;
#ifdef NEWDB
#else /* NEWDB */
# ifdef NDBM
# endif /* NDBM */
#endif /* NEWDB */
}
if (type == SMDB_TYPE_DEFAULT)
return SMDBE_UNKNOWN_DB_TYPE;
{
#ifdef NEWDB
int result;
# ifdef NDBM
else
# endif /* NDBM */
return result;
#else /* NEWDB */
return SMDBE_UNSUPPORTED_DB_TYPE;
#endif /* NEWDB */
}
{
#ifdef NDBM
int result;
return result;
#else /* NDBM */
return SMDBE_UNSUPPORTED_DB_TYPE;
#endif /* NDBM */
}
return SMDBE_UNKNOWN_DB_TYPE;
}
/*
** SMDB_ADD_EXTENSION -- Adds an extension to a file name.
**
** Just adds a . followed by a string to a db_name if there
** is room and the db_name does not already have that extension.
**
** Parameters:
** full_name -- The final file name.
** max_full_name_len -- The max length for full_name.
** db_name -- The name of the db.
** extension -- The extension to add.
**
** Returns:
** SMDBE_OK -- Success.
** Anything else is an error. Look up more info about the
** error in the comments for the specific open() used.
*/
int
char *full_name;
int max_full_name_len;
char *db_name;
char *extension;
{
int extension_len;
int db_name_len;
return SMDBE_INVALID_PARAMETER;
return SMDBE_DB_NAME_TOO_LONG;
else
return SMDBE_OK;
}
/*
** SMDB_LOCK_FILE -- Locks the database file.
**
** Locks the actual database file.
**
** Parameters:
** lock_fd -- The resulting descriptor for the locked file.
** db_name -- The name of the database without extension.
** mode -- The open mode.
** sff -- Flags to safefile.
** extension -- The extension for the file.
**
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
int *lock_fd;
char *db_name;
int mode;
long sff;
char *extension;
{
int result;
return result;
if (*lock_fd < 0)
return errno;
return SMDBE_OK;
}
/*
** SMDB_UNLOCK_FILE -- Unlocks a file
**
** Unlocks a file.
**
** Parameters:
** lock_fd -- The descriptor for the locked file.
**
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
int lock_fd;
{
int result;
if (result != 0)
return errno;
return SMDBE_OK;
}
/*
** SMDB_LOCK_MAP -- Locks a database.
**
** Parameters:
** database -- database description.
** type -- type of the lock. Bits can be:
** LOCK_EX -- exclusive lock.
** LOCK_NB -- non-blocking.
**
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
int type;
{
int fd;
if (fd < 0)
return SMDBE_NOT_FOUND;
return SMDBE_LOCK_NOT_GRANTED;
return SMDBE_OK;
}
/*
** SMDB_UNLOCK_MAP -- Unlocks a database
**
** Parameters:
** database -- database description.
**
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
{
int fd;
if (fd < 0)
return SMDBE_NOT_FOUND;
return SMDBE_LOCK_NOT_HELD;
return SMDBE_OK;
}
/*
** SMDB_SETUP_FILE -- Gets db file ready for use.
**
** Makes sure permissions on file are safe and creates it if it
** doesn't exist.
**
** Parameters:
** db_name -- The name of the database without extension.
** extension -- The extension.
** sff -- Flags to safefile.
** mode_mask -- Mode bits that must match.
** user_info -- Information on the user to use for file
** permissions.
** stat_info -- A place to put the stat info for the file.
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
char *db_name;
char *extension;
int mode_mask;
long sff;
{
int st;
int result;
return result;
if (st != 0)
return st;
return SMDBE_OK;
}
/*
** SMDB_FILECHANGED -- Checks to see if a file changed.
**
** Compares the passed in stat_info with a current stat on
** the passed in file descriptor. Check filechanged for
** return values.
**
** Parameters:
** db_name -- The name of the database without extension.
** extension -- The extension.
** db_fd -- A file descriptor for the database file.
** stat_info -- An old stat_info.
** Returns:
** SMDBE_OK -- Success, otherwise errno.
*/
int
char *db_name;
char *extension;
int db_fd;
{
int result;
return result;
}
/*
** SMDB_PRINT_AVAILABLE_TYPES -- Prints the names of the available types.
**
** Parameters:
** None
**
** Returns:
** None
*/
void
{
#ifdef NDBM
printf("dbm\n");
#endif /* NDBM */
#ifdef NEWDB
printf("hash\n");
printf("btree\n");
#endif /* NEWDB */
}
/*
** SMDB_DB_DEFINITION -- Given a database type, return database definition
**
** Reads though a structure making an association with the database
** List size is dynamic and must be NULL terminated.
**
** Parameters:
** type -- The name of the database type.
**
** Returns:
** definition for type, otherwise NULL.
*/
typedef struct
{
char *dbdef;
} dbtype;
{
{ SMDB_TYPE_HASH, "NEWDB" },
{ SMDB_TYPE_BTREE, "NEWDB" },
{ SMDB_TYPE_NDBM, "NDBM" },
{ NULL, "OOPS" }
};
char *
{
{
ptr++;
}
return NULL;
}