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