xref: /freebsd/usr.sbin/nscd/config.h (revision 73577bf01de5c4677dc54d97f93310286c254780)
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  * $FreeBSD$
27  */
28 
29 #ifndef __NSCD_CONFIG_H__
30 #define __NSCD_CONFIG_H__
31 
32 #include "cachelib.h"
33 
34 #define DEFAULT_QUERY_TIMEOUT		8
35 #define DEFAULT_THREADS_NUM		8
36 
37 #define DEFAULT_COMMON_ENTRY_TIMEOUT	10
38 #define DEFAULT_MP_ENTRY_TIMEOUT	60
39 #define DEFAULT_CACHE_HT_SIZE		257
40 
41 #define INITIAL_ENTRIES_CAPACITY	8
42 #define DEFAULT_SOCKET_PATH		"/var/run/nscd"
43 #define DEFAULT_PIDFILE_PATH		"/var/run/nscd.pid"
44 
45 #define DEFAULT_POSITIVE_ELEMENTS_SIZE	(2048)
46 #define DEFAULT_POSITIVE_LIFETIME 	(3600)
47 #define DEFAULT_POSITIVE_CONF_THRESH 	(1)
48 
49 #define DEFAULT_NEGATIVE_ELEMENTS_SIZE	(2048)
50 #define DEFAULT_NEGATIVE_LIFETIME	(60)
51 #define DEFAULT_NEGATIVE_CONF_THRESH 	(1) /* (2) ??? */
52 
53 #define DEFAULT_MULTIPART_ELEMENTS_SIZE	(1024 * 8)
54 #define DEFAULT_MULITPART_SESSIONS_SIZE	(1024)
55 #define DEFAULT_MULITPART_LIFETIME	(3600)
56 
57 extern const char *c_default_entries[6];
58 
59 /*
60  * Configuration entry represents the details of each cache entry in the
61  * config file (i.e. passwd or group). Its purpose also is to acquire locks
62  * of three different types (for usual read/write caching, for multipart
63  * caching and for caching of the negative results) for that cache entry.
64  */
65 struct configuration_entry {
66 	struct common_cache_entry_params positive_cache_params;
67 	struct common_cache_entry_params negative_cache_params;
68 	struct mp_cache_entry_params mp_cache_params;
69 
70 	/*
71 	 * configuration_entry holds pointers for all actual cache_entries,
72 	 * which are used for it. There is one for positive caching, one for
73 	 * for negative caching, and several (one per each euid/egid) for
74 	 * multipart caching.
75 	 */
76 	cache_entry positive_cache_entry;
77 	cache_entry negative_cache_entry;
78 
79 	cache_entry *mp_cache_entries;
80 	size_t mp_cache_entries_size;
81 
82 	struct timeval common_query_timeout;
83 	struct timeval mp_query_timeout;
84 
85 	char	*name;
86 	pthread_mutex_t positive_cache_lock;
87 	pthread_mutex_t negative_cache_lock;
88 	pthread_mutex_t mp_cache_lock;
89 
90 	int	perform_actual_lookups;
91 	int	enabled;
92 };
93 
94 /*
95  * Contains global configuration options and array of all configuration entries
96  */
97 struct configuration {
98 	char	*pidfile_path;
99 	char	*socket_path;
100 
101 	struct configuration_entry **entries;
102 	size_t	entries_capacity;
103 	size_t	entries_size;
104 
105 	pthread_rwlock_t rwlock;
106 
107 	mode_t	socket_mode;
108 	int	force_unlink;
109 	int	query_timeout;
110 
111 	int	threads_num;
112 };
113 
114 enum config_entry_lock_type {
115 	CELT_POSITIVE,
116 	CELT_NEGATIVE,
117 	CELT_MULTIPART
118 };
119 
120 struct configuration *init_configuration(void);
121 void destroy_configuration(struct configuration *);
122 void fill_configuration_defaults(struct configuration *);
123 
124 int add_configuration_entry(struct configuration *,
125 	struct configuration_entry *);
126 struct configuration_entry *create_def_configuration_entry(const char *);
127 void destroy_configuration_entry(struct configuration_entry *);
128 size_t configuration_get_entries_size(struct configuration *);
129 struct configuration_entry *configuration_get_entry(struct configuration *,
130 	size_t);
131 struct configuration_entry *configuration_find_entry(struct configuration *,
132 	const char *);
133 
134 int configuration_entry_add_mp_cache_entry(struct configuration_entry *,
135 	cache_entry);
136 cache_entry configuration_entry_find_mp_cache_entry(
137 	struct configuration_entry *, const char *);
138 int configuration_entry_find_mp_cache_entries(struct configuration_entry *,
139 	const char *, cache_entry **, cache_entry **);
140 
141 void configuration_lock_rdlock(struct configuration *config);
142 void configuration_lock_wrlock(struct configuration *config);
143 void configuration_unlock(struct configuration *config);
144 
145 void configuration_lock_entry(struct configuration_entry *,
146 	enum config_entry_lock_type);
147 void configuration_unlock_entry(struct configuration_entry *,
148 	enum config_entry_lock_type);
149 
150 #endif
151