1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
/*
* Copyright (c) 1999-2002, 2018 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.
*
* $Id: smdb.h,v 8.42 2013-11-22 20:51:28 ca Exp $
*
*/
#ifndef _SMDB_H_
# define _SMDB_H_
# include <sys/types.h>
# include <sys/stat.h>
# include <sm/gen.h>
# include <sm/errstring.h>
# if NDBM
# include <ndbm.h>
# endif
# if NEWDB
# include "sm/bdb.h"
# endif
/*
** Some size constants
*/
#define SMDB_MAX_USER_NAME_LEN 1024
/*
** This file defines the abstraction for database lookups. It is pretty
** much a copy of the db2 interface with the exception that every function
** returns 0 on success and non-zero on failure. The non-zero return code
** is meaningful.
**
** I'm going to put the function comments in this file since the interface
** MUST be the same for all inheritors of this interface.
*/
typedef struct database_struct SMDB_DATABASE;
typedef struct cursor_struct SMDB_CURSOR;
typedef struct entry_struct SMDB_DBENT;
/*
** DB_CLOSE_FUNC -- close the database
**
** Parameters:
** db -- The database to close.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_close_func) __P((SMDB_DATABASE *db));
/*
** DB_DEL_FUNC -- removes a key and data pair from the database
**
** Parameters:
** db -- The database to close.
** key -- The key to remove.
** flags -- delete options. There are currently no defined
** flags for delete.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_del_func) __P((SMDB_DATABASE *db,
SMDB_DBENT *key, unsigned int flags));
/*
** DB_FD_FUNC -- Returns a pointer to a file used for the database.
**
** Parameters:
** db -- The database to close.
** fd -- A pointer to store the returned fd in.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_fd_func) __P((SMDB_DATABASE *db, int* fd));
/*
** DB_GET_FUNC -- Gets the data associated with a key.
**
** Parameters:
** db -- The database to close.
** key -- The key to access.
** data -- A place to store the returned data.
** flags -- get options. There are currently no defined
** flags for get.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_get_func) __P((SMDB_DATABASE *db,
SMDB_DBENT *key,
SMDB_DBENT *data, unsigned int flags));
/*
** DB_PUT_FUNC -- Sets some data according to the key.
**
** Parameters:
** db -- The database to close.
** key -- The key to use.
** data -- The data to store.
** flags -- put options:
** SMDBF_NO_OVERWRITE - Return an error if key already
** exists.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_put_func) __P((SMDB_DATABASE *db,
SMDB_DBENT *key,
SMDB_DBENT *data, unsigned int flags));
/*
** DB_SYNC_FUNC -- Flush any cached information to disk.
**
** Parameters:
** db -- The database to sync.
** flags -- sync options:
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_sync_func) __P((SMDB_DATABASE *db, unsigned int flags));
/*
** DB_SET_OWNER_FUNC -- Set the owner and group of the database files.
**
** Parameters:
** db -- The database to set.
** uid -- The UID for the new owner (-1 for no change)
** gid -- The GID for the new owner (-1 for no change)
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_set_owner_func) __P((SMDB_DATABASE *db, uid_t uid, gid_t gid));
/*
** DB_CURSOR -- Obtain a cursor for sequential access
**
** Parameters:
** db -- The database to use.
** cursor -- The address of a cursor pointer.
** flags -- sync options:
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_cursor_func) __P((SMDB_DATABASE *db,
SMDB_CURSOR **cursor, unsigned int flags));
typedef int (*db_lockfd_func) __P((SMDB_DATABASE *db));
struct database_struct
{
db_close_func smdb_close;
db_del_func smdb_del;
db_fd_func smdb_fd;
db_get_func smdb_get;
db_put_func smdb_put;
db_sync_func smdb_sync;
db_set_owner_func smdb_set_owner;
db_cursor_func smdb_cursor;
db_lockfd_func smdb_lockfd;
void *smdb_impl;
};
/*
** DB_CURSOR_CLOSE -- Close a cursor
**
** Parameters:
** cursor -- The cursor to close.
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_cursor_close_func) __P((SMDB_CURSOR *cursor));
/*
** DB_CURSOR_DEL -- Delete the key/value pair of this cursor
**
** Parameters:
** cursor -- The cursor.
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_cursor_del_func) __P((SMDB_CURSOR *cursor,
unsigned int flags));
/*
** DB_CURSOR_GET -- Get the key/value of this cursor.
**
** Parameters:
** cursor -- The cursor.
** key -- The current key.
** value -- The current value
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
** SMDBE_LAST_ENTRY - This is a success condition that
** gets returned when the end of the
** database is hit.
**
*/
typedef int (*db_cursor_get_func) __P((SMDB_CURSOR *cursor,
SMDB_DBENT *key,
SMDB_DBENT *data,
unsigned int flags));
/*
** Flags for DB_CURSOR_GET
*/
#define SMDB_CURSOR_GET_FIRST 0 /* NOT USED by any application */
#define SMDB_CURSOR_GET_LAST 1 /* NOT USED by any application */
#define SMDB_CURSOR_GET_NEXT 2
#define SMDB_CURSOR_GET_RANGE 3 /* NOT USED by any application */
/*
** DB_CURSOR_PUT -- Put the key/value at this cursor.
**
** Parameters:
** cursor -- The cursor.
** key -- The current key.
** value -- The current value
** flags -- flags
**
** Returns:
** 0 - Success, otherwise errno.
**
*/
typedef int (*db_cursor_put_func) __P((SMDB_CURSOR *cursor,
SMDB_DBENT *key,
SMDB_DBENT *data,
unsigned int flags));
struct cursor_struct
{
db_cursor_close_func smdbc_close;
db_cursor_del_func smdbc_del;
db_cursor_get_func smdbc_get;
db_cursor_put_func smdbc_put;
void *smdbc_impl;
};
struct database_params_struct
{
unsigned int smdbp_num_elements;
unsigned int smdbp_cache_size;
bool smdbp_allow_dup;
};
typedef struct database_params_struct SMDB_DBPARAMS;
struct database_user_struct
{
uid_t smdbu_id;
gid_t smdbu_group_id;
char smdbu_name[SMDB_MAX_USER_NAME_LEN];
};
typedef struct database_user_struct SMDB_USER_INFO;
struct entry_struct
{
void *data;
size_t size;
};
typedef char *SMDB_DBTYPE;
typedef unsigned int SMDB_FLAG;
/*
** These are types of databases.
*/
# define SMDB_TYPE_DEFAULT NULL
# define SMDB_TYPE_DEFAULT_LEN 0
# define SMDB_TYPE_IMPL "implicit"
# define SMDB_TYPE_IMPL_LEN 9
# define SMDB_TYPE_HASH "hash"
# define SMDB_TYPE_HASH_LEN 5
# define SMDB_TYPE_BTREE "btree"
# define SMDB_TYPE_BTREE_LEN 6
# define SMDB_TYPE_NDBM "dbm"
# define SMDB_TYPE_NDBM_LEN 4
# define SMDB_TYPE_CDB "cdb"
# define SMDB_TYPE_CDB_LEN 4
# define SMDB_IS_TYPE_HASH(type) (strncmp(type, SMDB_TYPE_HASH, SMDB_TYPE_HASH_LEN) == 0)
# define SMDB_IS_TYPE_BTREE(type) (strncmp(type, SMDB_TYPE_BTREE, SMDB_TYPE_BTREE_LEN) == 0)
# define SMDB_IS_TYPE_NDBM(type) (strncmp(type, SMDB_TYPE_NDBM, SMDB_TYPE_NDBM_LEN) == 0)
# define SMDB_IS_TYPE_CDB(type) (strncmp(type, SMDB_TYPE_CDB, SMDB_TYPE_CDB_LEN) == 0)
# define SMDB_IS_TYPE_DEFAULT(t) (((t) == SMDB_TYPE_DEFAULT) \
|| (strncmp(type, SMDB_TYPE_IMPL, SMDB_TYPE_IMPL_LEN) == 0) \
)
# if CDB >= 2
# define SMCDB_FILE_EXTENSION "db"
# else
# define SMCDB_FILE_EXTENSION "cdb"
# endif
# define SMDB1_FILE_EXTENSION "db"
# define SMDB2_FILE_EXTENSION "db"
# define SMNDB_DIR_FILE_EXTENSION "dir"
/*
** These are flags
*/
/* Flags for put */
# define SMDBF_NO_OVERWRITE 0x00000001
typedef int (smdb_open_func) __P((SMDB_DATABASE **, char *, int, int, long, SMDB_DBTYPE, SMDB_USER_INFO *, SMDB_DBPARAMS *));
extern SMDB_DATABASE *smdb_malloc_database __P((void));
extern void smdb_free_database __P((SMDB_DATABASE *));
extern smdb_open_func smdb_open_database;
# if NEWDB
extern smdb_open_func smdb_db_open;
# else
# define smdb_db_open NULL
# endif
# if NDBM
extern smdb_open_func smdb_ndbm_open;
# else
# define smdb_ndbm_open NULL
# endif
extern int smdb_add_extension __P((char *, int, char *, char *));
extern int smdb_setup_file __P((char *, char *, int, long,
SMDB_USER_INFO *, struct stat *));
extern int smdb_lock_file __P((int *, char *, int, long, char *));
extern int smdb_unlock_file __P((int));
extern int smdb_filechanged __P((char *, char *, int,
struct stat *));
extern void smdb_print_available_types __P((bool));
extern bool smdb_is_db_type __P((const char *));
extern char *smdb_db_definition __P((SMDB_DBTYPE));
extern int smdb_lock_map __P((SMDB_DATABASE *, int));
extern int smdb_unlock_map __P((SMDB_DATABASE *));
# if CDB
extern smdb_open_func smdb_cdb_open;
# else
# define smdb_cdb_open NULL
# endif
#endif /* ! _SMDB_H_ */
|