summaryrefslogtreecommitdiffstats
path: root/src/util/dict_fail.c
blob: c8d9a195fd9cb624b95f2cf6fb0ca482d8fe78b3 (plain)
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
/*++
/* NAME
/*	dict_fail 3
/* SUMMARY
/*	dictionary manager interface to 'always fail' table
/* SYNOPSIS
/*	#include <dict_fail.h>
/*
/*	DICT	*dict_fail_open(name, open_flags, dict_flags)
/*	const char *name;
/*	int	open_flags;
/*	int	dict_flags;
/* DESCRIPTION
/*	dict_fail_open() implements a dummy dictionary that fails
/*	all operations. The name can be used for logging.
/* SEE ALSO
/*	dict(3) generic dictionary manager
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*--*/

/* System library. */

#include <sys_defs.h>
#include <errno.h>

/* Utility library. */

#include <mymalloc.h>
#include <msg.h>
#include <dict.h>
#include <dict_fail.h>

/* Application-specific. */

typedef struct {
    DICT    dict;			/* generic members */
    int     dict_errno;			/* fixed error result */
} DICT_FAIL;

/* dict_fail_sequence - fail lookup */

static int dict_fail_sequence(DICT *dict, int unused_func,
			              const char **key, const char **value)
{
    DICT_FAIL *dp = (DICT_FAIL *) dict;

    errno = 0;
    DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
}

/* dict_fail_update - fail lookup */

static int dict_fail_update(DICT *dict, const char *unused_name,
			            const char *unused_value)
{
    DICT_FAIL *dp = (DICT_FAIL *) dict;

    errno = 0;
    DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
}

/* dict_fail_lookup - fail lookup */

static const char *dict_fail_lookup(DICT *dict, const char *unused_name)
{
    DICT_FAIL *dp = (DICT_FAIL *) dict;

    errno = 0;
    DICT_ERR_VAL_RETURN(dict, dp->dict_errno, (char *) 0);
}

/* dict_fail_delete - fail delete */

static int dict_fail_delete(DICT *dict, const char *unused_name)
{
    DICT_FAIL *dp = (DICT_FAIL *) dict;

    errno = 0;
    DICT_ERR_VAL_RETURN(dict, dp->dict_errno, DICT_STAT_ERROR);
}

/* dict_fail_close - close fail dictionary */

static void dict_fail_close(DICT *dict)
{
    dict_free(dict);
}

/* dict_fail_open - make association with fail variable */

DICT   *dict_fail_open(const char *name, int open_flags, int dict_flags)
{
    DICT_FAIL *dp;

    dp = (DICT_FAIL *) dict_alloc(DICT_TYPE_FAIL, name, sizeof(*dp));
    dp->dict.lookup = dict_fail_lookup;
    if (open_flags & O_RDWR) {
	dp->dict.update = dict_fail_update;
	dp->dict.delete = dict_fail_delete;
    }
    dp->dict.sequence = dict_fail_sequence;
    dp->dict.close = dict_fail_close;
    dp->dict.flags = dict_flags | DICT_FLAG_PATTERN;
    dp->dict_errno = DICT_ERR_RETRY;
    dp->dict.owner.status = DICT_OWNER_TRUSTED;
    return (DICT_DEBUG (&dp->dict));
}