2 * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #ifndef __NSCD_CONFIG_H__
30 #define __NSCD_CONFIG_H__
34 #define DEFAULT_QUERY_TIMEOUT 8
35 #define DEFAULT_THREADS_NUM 8
37 #define DEFAULT_COMMON_ENTRY_TIMEOUT 10
38 #define DEFAULT_MP_ENTRY_TIMEOUT 60
39 #define DEFAULT_CACHE_HT_SIZE 257
41 #define INITIAL_ENTRIES_CAPACITY 8
42 #define DEFAULT_SOCKET_PATH "/var/run/nscd"
43 #define DEFAULT_PIDFILE_PATH "/var/run/nscd.pid"
45 #define DEFAULT_POSITIVE_ELEMENTS_SIZE (2048)
46 #define DEFAULT_POSITIVE_LIFETIME (3600)
48 #define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048)
49 #define DEFAULT_NEGATIVE_LIFETIME (60)
51 #define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8)
52 #define DEFAULT_MULITPART_SESSIONS_SIZE (1024)
53 #define DEFAULT_MULITPART_LIFETIME (3600)
55 extern const char *c_default_entries[6];
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.
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;
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
74 cache_entry positive_cache_entry;
75 cache_entry negative_cache_entry;
77 cache_entry *mp_cache_entries;
78 size_t mp_cache_entries_size;
80 struct timeval common_query_timeout;
81 struct timeval mp_query_timeout;
84 pthread_mutex_t positive_cache_lock;
85 pthread_mutex_t negative_cache_lock;
86 pthread_mutex_t mp_cache_lock;
88 int perform_actual_lookups;
93 * Contains global configuration options and array of all configuration entries
95 struct configuration {
99 struct configuration_entry **entries;
100 size_t entries_capacity;
103 pthread_rwlock_t rwlock;
112 enum config_entry_lock_type {
118 struct configuration *init_configuration(void);
119 void destroy_configuration(struct configuration *);
120 void fill_configuration_defaults(struct configuration *);
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 *,
129 struct configuration_entry *configuration_find_entry(struct configuration *,
132 int configuration_entry_add_mp_cache_entry(struct configuration_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 **);
139 void configuration_lock_rdlock(struct configuration *config);
140 void configuration_lock_wrlock(struct configuration *config);
141 void configuration_unlock(struct configuration *config);
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);