1158115Sume/*-
2158115Sume * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
3158115Sume * All rights reserved.
4158115Sume *
5158115Sume * Redistribution and use in source and binary forms, with or without
6158115Sume * modification, are permitted provided that the following conditions
7158115Sume * are met:
8158115Sume * 1. Redistributions of source code must retain the above copyright
9158115Sume *    notice, this list of conditions and the following disclaimer.
10158115Sume * 2. Redistributions in binary form must reproduce the above copyright
11158115Sume *    notice, this list of conditions and the following disclaimer in the
12158115Sume *    documentation and/or other materials provided with the distribution.
13158115Sume *
14158115Sume * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15158115Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16158115Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17158115Sume * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18158115Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19158115Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20158115Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21158115Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22158115Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23158115Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24158115Sume * SUCH DAMAGE.
25158115Sume *
26158115Sume * $FreeBSD$
27158115Sume */
28158115Sume
29171795Sbushman#ifndef __NSCD_CONFIG_H__
30171795Sbushman#define __NSCD_CONFIG_H__
31158115Sume
32158115Sume#include "cachelib.h"
33158115Sume
34158115Sume#define DEFAULT_QUERY_TIMEOUT		8
35158115Sume#define DEFAULT_THREADS_NUM		8
36158115Sume
37158115Sume#define DEFAULT_COMMON_ENTRY_TIMEOUT	10
38158115Sume#define DEFAULT_MP_ENTRY_TIMEOUT	60
39158115Sume#define DEFAULT_CACHE_HT_SIZE		257
40158115Sume
41158115Sume#define INITIAL_ENTRIES_CAPACITY	8
42171795Sbushman#define DEFAULT_SOCKET_PATH		"/var/run/nscd"
43171795Sbushman#define DEFAULT_PIDFILE_PATH		"/var/run/nscd.pid"
44158115Sume
45158115Sume#define DEFAULT_POSITIVE_ELEMENTS_SIZE	(2048)
46158115Sume#define DEFAULT_POSITIVE_LIFETIME 	(3600)
47158115Sume
48158115Sume#define DEFAULT_NEGATIVE_ELEMENTS_SIZE	(2048)
49158115Sume#define DEFAULT_NEGATIVE_LIFETIME	(60)
50158115Sume
51158115Sume#define DEFAULT_MULTIPART_ELEMENTS_SIZE	(1024 * 8)
52158115Sume#define DEFAULT_MULITPART_SESSIONS_SIZE	(1024)
53158115Sume#define DEFAULT_MULITPART_LIFETIME	(3600)
54158115Sume
55158115Sumeextern const char *c_default_entries[6];
56158115Sume
57158115Sume/*
58158115Sume * Configuration entry represents the details of each cache entry in the
59158115Sume * config file (i.e. passwd or group). Its purpose also is to acquire locks
60158115Sume * of three different types (for usual read/write caching, for multipart
61158115Sume * caching and for caching of the negative results) for that cache entry.
62158115Sume */
63158115Sumestruct configuration_entry {
64158115Sume	struct common_cache_entry_params positive_cache_params;
65158115Sume	struct common_cache_entry_params negative_cache_params;
66158115Sume	struct mp_cache_entry_params mp_cache_params;
67158115Sume
68158115Sume	/*
69158115Sume	 * configuration_entry holds pointers for all actual cache_entries,
70158115Sume	 * which are used for it. There is one for positive caching, one for
71158115Sume	 * for negative caching, and several (one per each euid/egid) for
72158115Sume	 * multipart caching.
73158115Sume	 */
74158115Sume	cache_entry positive_cache_entry;
75158115Sume	cache_entry negative_cache_entry;
76158115Sume
77158115Sume	cache_entry *mp_cache_entries;
78158115Sume	size_t mp_cache_entries_size;
79158115Sume
80158115Sume	struct timeval common_query_timeout;
81158115Sume	struct timeval mp_query_timeout;
82158115Sume
83158115Sume	char	*name;
84158115Sume	pthread_mutex_t positive_cache_lock;
85158115Sume	pthread_mutex_t negative_cache_lock;
86158115Sume	pthread_mutex_t mp_cache_lock;
87158115Sume
88158115Sume	int	perform_actual_lookups;
89158115Sume	int	enabled;
90158115Sume};
91158115Sume
92158115Sume/*
93158115Sume * Contains global configuration options and array of all configuration entries
94158115Sume */
95158115Sumestruct configuration {
96158115Sume	char	*pidfile_path;
97158115Sume	char	*socket_path;
98158115Sume
99158115Sume	struct configuration_entry **entries;
100158115Sume	size_t	entries_capacity;
101158115Sume	size_t	entries_size;
102158115Sume
103158115Sume	pthread_rwlock_t rwlock;
104158115Sume
105158115Sume	mode_t	socket_mode;
106158115Sume	int	force_unlink;
107158115Sume	int	query_timeout;
108158115Sume
109158115Sume	int	threads_num;
110158115Sume};
111158115Sume
112158115Sumeenum config_entry_lock_type {
113158115Sume	CELT_POSITIVE,
114158115Sume	CELT_NEGATIVE,
115158115Sume	CELT_MULTIPART
116158115Sume};
117158115Sume
118194112Sdesstruct configuration *init_configuration(void);
119194112Sdesvoid destroy_configuration(struct configuration *);
120194112Sdesvoid fill_configuration_defaults(struct configuration *);
121158115Sume
122194112Sdesint add_configuration_entry(struct configuration *,
123158115Sume	struct configuration_entry *);
124194112Sdesstruct configuration_entry *create_def_configuration_entry(const char *);
125194112Sdesvoid destroy_configuration_entry(struct configuration_entry *);
126194112Sdessize_t configuration_get_entries_size(struct configuration *);
127194112Sdesstruct configuration_entry *configuration_get_entry(struct configuration *,
128194112Sdes	size_t);
129194112Sdesstruct configuration_entry *configuration_find_entry(struct configuration *,
130158115Sume	const char *);
131158115Sume
132194112Sdesint configuration_entry_add_mp_cache_entry(struct configuration_entry *,
133158115Sume	cache_entry);
134194112Sdescache_entry configuration_entry_find_mp_cache_entry(
135194112Sdes	struct configuration_entry *, const char *);
136194112Sdesint configuration_entry_find_mp_cache_entries(struct configuration_entry *,
137194112Sdes	const char *, cache_entry **, cache_entry **);
138158115Sume
139194112Sdesvoid configuration_lock_rdlock(struct configuration *config);
140194112Sdesvoid configuration_lock_wrlock(struct configuration *config);
141194112Sdesvoid configuration_unlock(struct configuration *config);
142158115Sume
143194112Sdesvoid configuration_lock_entry(struct configuration_entry *,
144158115Sume	enum config_entry_lock_type);
145194112Sdesvoid configuration_unlock_entry(struct configuration_entry *,
146158115Sume	enum config_entry_lock_type);
147158115Sume
148158115Sume#endif
149