xref: /freebsd/usr.sbin/nscd/config.h (revision 783d3ff6d7fae619db8a7990b8a6387de0c677b5)
1 /*-
2  * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef __NSCD_CONFIG_H__
28 #define __NSCD_CONFIG_H__
29 
30 #include "cachelib.h"
31 
32 #define DEFAULT_QUERY_TIMEOUT		8
33 #define DEFAULT_THREADS_NUM		8
34 
35 #define DEFAULT_COMMON_ENTRY_TIMEOUT	10
36 #define DEFAULT_MP_ENTRY_TIMEOUT	60
37 #define DEFAULT_CACHE_HT_SIZE		257
38 
39 #define INITIAL_ENTRIES_CAPACITY	8
40 #define DEFAULT_SOCKET_PATH		"/var/run/nscd"
41 #define DEFAULT_PIDFILE_PATH		"/var/run/nscd.pid"
42 
43 #define DEFAULT_POSITIVE_ELEMENTS_SIZE	(2048)
44 #define DEFAULT_POSITIVE_LIFETIME 	(3600)
45 #define DEFAULT_POSITIVE_CONF_THRESH 	(1)
46 
47 #define DEFAULT_NEGATIVE_ELEMENTS_SIZE	(2048)
48 #define DEFAULT_NEGATIVE_LIFETIME	(60)
49 #define DEFAULT_NEGATIVE_CONF_THRESH 	(1) /* (2) ??? */
50 
51 #define DEFAULT_MULTIPART_ELEMENTS_SIZE	(1024 * 8)
52 #define DEFAULT_MULITPART_SESSIONS_SIZE	(1024)
53 #define DEFAULT_MULITPART_LIFETIME	(3600)
54 
55 extern const char *c_default_entries[6];
56 
57 /*
58  * Configuration entry represents the details of each cache entry in the
59  * config file (i.e. passwd or group). Its purpose also is to acquire locks
60  * of three different types (for usual read/write caching, for multipart
61  * caching and for caching of the negative results) for that cache entry.
62  */
63 struct configuration_entry {
64 	struct common_cache_entry_params positive_cache_params;
65 	struct common_cache_entry_params negative_cache_params;
66 	struct mp_cache_entry_params mp_cache_params;
67 
68 	/*
69 	 * configuration_entry holds pointers for all actual cache_entries,
70 	 * which are used for it. There is one for positive caching, one for
71 	 * for negative caching, and several (one per each euid/egid) for
72 	 * multipart caching.
73 	 */
74 	cache_entry positive_cache_entry;
75 	cache_entry negative_cache_entry;
76 
77 	cache_entry *mp_cache_entries;
78 	size_t mp_cache_entries_size;
79 
80 	struct timeval common_query_timeout;
81 	struct timeval mp_query_timeout;
82 
83 	char	*name;
84 	pthread_mutex_t positive_cache_lock;
85 	pthread_mutex_t negative_cache_lock;
86 	pthread_mutex_t mp_cache_lock;
87 
88 	int	perform_actual_lookups;
89 	int	enabled;
90 };
91 
92 /*
93  * Contains global configuration options and array of all configuration entries
94  */
95 struct configuration {
96 	char	*pidfile_path;
97 	char	*socket_path;
98 
99 	struct configuration_entry **entries;
100 	size_t	entries_capacity;
101 	size_t	entries_size;
102 
103 	pthread_rwlock_t rwlock;
104 
105 	mode_t	socket_mode;
106 	int	force_unlink;
107 	int	query_timeout;
108 
109 	int	threads_num;
110 };
111 
112 enum config_entry_lock_type {
113 	CELT_POSITIVE,
114 	CELT_NEGATIVE,
115 	CELT_MULTIPART
116 };
117 
118 struct configuration *init_configuration(void);
119 void destroy_configuration(struct configuration *);
120 void fill_configuration_defaults(struct configuration *);
121 
122 int add_configuration_entry(struct configuration *,
123 	struct configuration_entry *);
124 struct configuration_entry *create_def_configuration_entry(const char *);
125 void destroy_configuration_entry(struct configuration_entry *);
126 size_t configuration_get_entries_size(struct configuration *);
127 struct configuration_entry *configuration_get_entry(struct configuration *,
128 	size_t);
129 struct configuration_entry *configuration_find_entry(struct configuration *,
130 	const char *);
131 
132 int configuration_entry_add_mp_cache_entry(struct configuration_entry *,
133 	cache_entry);
134 cache_entry configuration_entry_find_mp_cache_entry(
135 	struct configuration_entry *, const char *);
136 int configuration_entry_find_mp_cache_entries(struct configuration_entry *,
137 	const char *, cache_entry **, cache_entry **);
138 
139 void configuration_lock_rdlock(struct configuration *config);
140 void configuration_lock_wrlock(struct configuration *config);
141 void configuration_unlock(struct configuration *config);
142 
143 void configuration_lock_entry(struct configuration_entry *,
144 	enum config_entry_lock_type);
145 void configuration_unlock_entry(struct configuration_entry *,
146 	enum config_entry_lock_type);
147 
148 #endif
149