xref: /netbsd-src/external/ibm-public/postfix/dist/src/util/dict_fail.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: dict_fail.c,v 1.1.1.1 2013/01/02 18:59:12 tron 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 
35 /* Utility library. */
36 
37 #include <mymalloc.h>
38 #include <msg.h>
39 #include <dict.h>
40 #include <dict_fail.h>
41 
42 /* Application-specific. */
43 
44 typedef struct {
45     DICT    dict;			/* generic members */
46     int     dict_errno;			/* fixed error result */
47 } DICT_FAIL;
48 
49 /* dict_fail_sequence - fail lookup */
50 
51 static int dict_fail_sequence(DICT *dict, int unused_func,
52 			              const char **key, const char **value)
53 {
54     DICT_FAIL *dp = (DICT_FAIL *) dict;
55 
56     DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
57 }
58 
59 /* dict_fail_update - fail lookup */
60 
61 static int dict_fail_update(DICT *dict, const char *unused_name,
62 			            const char *unused_value)
63 {
64     DICT_FAIL *dp = (DICT_FAIL *) dict;
65 
66     DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
67 }
68 
69 /* dict_fail_lookup - fail lookup */
70 
71 static const char *dict_fail_lookup(DICT *dict, const char *unused_name)
72 {
73     DICT_FAIL *dp = (DICT_FAIL *) dict;
74 
75     DICT_ERR_VAL_RETURN(dict, dp->dict_errno, (char *) 0);
76 }
77 
78 /* dict_fail_delete - fail delete */
79 
80 static int dict_fail_delete(DICT *dict, const char *unused_name)
81 {
82     DICT_FAIL *dp = (DICT_FAIL *) dict;
83 
84     DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
85 }
86 
87 /* dict_fail_close - close fail dictionary */
88 
89 static void dict_fail_close(DICT *dict)
90 {
91     dict_free(dict);
92 }
93 
94 /* dict_fail_open - make association with fail variable */
95 
96 DICT   *dict_fail_open(const char *name, int open_flags, int dict_flags)
97 {
98     DICT_FAIL *dp;
99 
100     dp = (DICT_FAIL *) dict_alloc(DICT_TYPE_FAIL, name, sizeof(*dp));
101     dp->dict.lookup = dict_fail_lookup;
102     if (open_flags & O_RDWR) {
103 	dp->dict.update = dict_fail_update;
104 	dp->dict.delete = dict_fail_delete;
105     }
106     dp->dict.sequence = dict_fail_sequence;
107     dp->dict.close = dict_fail_close;
108     dp->dict.flags = dict_flags | DICT_FLAG_PATTERN;
109     dp->dict_errno = DICT_ERR_RETRY;
110     dp->dict.owner.status = DICT_OWNER_TRUSTED;
111     return (DICT_DEBUG (&dp->dict));
112 }
113