1/*++ 2/* NAME 3/* dict_fail 3 4/* SUMMARY 5/* dictionary manager interface to 'always fail' table 6/* SYNOPSIS 7/* #include <dict_fail.h> 8/* 9/* DICT *dict_fail_open(name, open_flags, dict_flags) 10/* const char *name; 11/* int open_flags; 12/* int dict_flags; 13/* DESCRIPTION 14/* dict_fail_open() implements a dummy dictionary that fails 15/* all operations. The name can be used for logging. 16/* SEE ALSO 17/* dict(3) generic dictionary manager 18/* LICENSE 19/* .ad 20/* .fi 21/* The Secure Mailer license must be distributed with this software. 22/* AUTHOR(S) 23/* Wietse Venema 24/* IBM T.J. Watson Research 25/* P.O. Box 704 26/* Yorktown Heights, NY 10598, USA 27/*--*/ 28 29/* System library. */ 30 31#include <sys_defs.h> 32 33/* Utility library. */ 34 35#include <mymalloc.h> 36#include <msg.h> 37#include <dict.h> 38#include <dict_fail.h> 39 40/* Application-specific. */ 41 42typedef struct { 43 DICT dict; /* generic members */ 44 int dict_errno; /* fixed error result */ 45} DICT_FAIL; 46 47/* dict_fail_sequence - fail lookup */ 48 49static int dict_fail_sequence(DICT *dict, int unused_func, 50 const char **key, const char **value) 51{ 52 DICT_FAIL *dp = (DICT_FAIL *) dict; 53 54 DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR); 55} 56 57/* dict_fail_update - fail lookup */ 58 59static int dict_fail_update(DICT *dict, const char *unused_name, 60 const char *unused_value) 61{ 62 DICT_FAIL *dp = (DICT_FAIL *) dict; 63 64 DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR); 65} 66 67/* dict_fail_lookup - fail lookup */ 68 69static const char *dict_fail_lookup(DICT *dict, const char *unused_name) 70{ 71 DICT_FAIL *dp = (DICT_FAIL *) dict; 72 73 DICT_ERR_VAL_RETURN(dict, dp->dict_errno, (char *) 0); 74} 75 76/* dict_fail_delete - fail delete */ 77 78static int dict_fail_delete(DICT *dict, const char *unused_name) 79{ 80 DICT_FAIL *dp = (DICT_FAIL *) dict; 81 82 DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR); 83} 84 85/* dict_fail_close - close fail dictionary */ 86 87static void dict_fail_close(DICT *dict) 88{ 89 dict_free(dict); 90} 91 92/* dict_fail_open - make association with fail variable */ 93 94DICT *dict_fail_open(const char *name, int open_flags, int dict_flags) 95{ 96 DICT_FAIL *dp; 97 98 dp = (DICT_FAIL *) dict_alloc(DICT_TYPE_FAIL, name, sizeof(*dp)); 99 dp->dict.lookup = dict_fail_lookup; 100 if (open_flags & O_RDWR) { 101 dp->dict.update = dict_fail_update; 102 dp->dict.delete = dict_fail_delete; 103 } 104 dp->dict.sequence = dict_fail_sequence; 105 dp->dict.close = dict_fail_close; 106 dp->dict.flags = dict_flags | DICT_FLAG_PATTERN; 107 dp->dict_errno = DICT_ERR_RETRY; 108 dp->dict.owner.status = DICT_OWNER_TRUSTED; 109 return (DICT_DEBUG (&dp->dict)); 110} 111