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)
47 #define DEFAULT_POSITIVE_CONF_THRESH (1)
49 #define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048)
50 #define DEFAULT_NEGATIVE_LIFETIME (60)
51 #define DEFAULT_NEGATIVE_CONF_THRESH (1) /* (2) ??? */
53 #define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8)
54 #define DEFAULT_MULITPART_SESSIONS_SIZE (1024)
55 #define DEFAULT_MULITPART_LIFETIME (3600)
57 extern const char *c_default_entries[6];
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.
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;
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
76 cache_entry positive_cache_entry;
77 cache_entry negative_cache_entry;
79 cache_entry *mp_cache_entries;
80 size_t mp_cache_entries_size;
82 struct timeval common_query_timeout;
83 struct timeval mp_query_timeout;
86 pthread_mutex_t positive_cache_lock;
87 pthread_mutex_t negative_cache_lock;
88 pthread_mutex_t mp_cache_lock;
90 int perform_actual_lookups;
95 * Contains global configuration options and array of all configuration entries
97 struct configuration {
101 struct configuration_entry **entries;
102 size_t entries_capacity;
105 pthread_rwlock_t rwlock;
114 enum config_entry_lock_type {
120 struct configuration *init_configuration(void);
121 void destroy_configuration(struct configuration *);
122 void fill_configuration_defaults(struct configuration *);
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 *,
131 struct configuration_entry *configuration_find_entry(struct configuration *,
134 int configuration_entry_add_mp_cache_entry(struct configuration_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 **);
141 void configuration_lock_rdlock(struct configuration *config);
142 void configuration_lock_wrlock(struct configuration *config);
143 void configuration_unlock(struct configuration *config);
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);