106a99fe3SHajimu UMEMOTO /*- 206a99fe3SHajimu UMEMOTO * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 306a99fe3SHajimu UMEMOTO * All rights reserved. 406a99fe3SHajimu UMEMOTO * 506a99fe3SHajimu UMEMOTO * Redistribution and use in source and binary forms, with or without 606a99fe3SHajimu UMEMOTO * modification, are permitted provided that the following conditions 706a99fe3SHajimu UMEMOTO * are met: 806a99fe3SHajimu UMEMOTO * 1. Redistributions of source code must retain the above copyright 906a99fe3SHajimu UMEMOTO * notice, this list of conditions and the following disclaimer. 1006a99fe3SHajimu UMEMOTO * 2. Redistributions in binary form must reproduce the above copyright 1106a99fe3SHajimu UMEMOTO * notice, this list of conditions and the following disclaimer in the 1206a99fe3SHajimu UMEMOTO * documentation and/or other materials provided with the distribution. 1306a99fe3SHajimu UMEMOTO * 1406a99fe3SHajimu UMEMOTO * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1506a99fe3SHajimu UMEMOTO * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1606a99fe3SHajimu UMEMOTO * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1706a99fe3SHajimu UMEMOTO * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1806a99fe3SHajimu UMEMOTO * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1906a99fe3SHajimu UMEMOTO * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2006a99fe3SHajimu UMEMOTO * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2106a99fe3SHajimu UMEMOTO * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2206a99fe3SHajimu UMEMOTO * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2306a99fe3SHajimu UMEMOTO * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2406a99fe3SHajimu UMEMOTO * SUCH DAMAGE. 2506a99fe3SHajimu UMEMOTO */ 2606a99fe3SHajimu UMEMOTO 27db1bdf2bSMichael Bushkov #ifndef __NSCD_CONFIG_H__ 28db1bdf2bSMichael Bushkov #define __NSCD_CONFIG_H__ 2906a99fe3SHajimu UMEMOTO 3006a99fe3SHajimu UMEMOTO #include "cachelib.h" 3106a99fe3SHajimu UMEMOTO 3206a99fe3SHajimu UMEMOTO #define DEFAULT_QUERY_TIMEOUT 8 3306a99fe3SHajimu UMEMOTO #define DEFAULT_THREADS_NUM 8 3406a99fe3SHajimu UMEMOTO 3506a99fe3SHajimu UMEMOTO #define DEFAULT_COMMON_ENTRY_TIMEOUT 10 3606a99fe3SHajimu UMEMOTO #define DEFAULT_MP_ENTRY_TIMEOUT 60 3706a99fe3SHajimu UMEMOTO #define DEFAULT_CACHE_HT_SIZE 257 3806a99fe3SHajimu UMEMOTO 3906a99fe3SHajimu UMEMOTO #define INITIAL_ENTRIES_CAPACITY 8 40db1bdf2bSMichael Bushkov #define DEFAULT_SOCKET_PATH "/var/run/nscd" 41db1bdf2bSMichael Bushkov #define DEFAULT_PIDFILE_PATH "/var/run/nscd.pid" 4206a99fe3SHajimu UMEMOTO 4306a99fe3SHajimu UMEMOTO #define DEFAULT_POSITIVE_ELEMENTS_SIZE (2048) 4406a99fe3SHajimu UMEMOTO #define DEFAULT_POSITIVE_LIFETIME (3600) 45a397989dSStefan Eßer #define DEFAULT_POSITIVE_CONF_THRESH (1) 4606a99fe3SHajimu UMEMOTO 4706a99fe3SHajimu UMEMOTO #define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048) 4806a99fe3SHajimu UMEMOTO #define DEFAULT_NEGATIVE_LIFETIME (60) 49a397989dSStefan Eßer #define DEFAULT_NEGATIVE_CONF_THRESH (1) /* (2) ??? */ 5006a99fe3SHajimu UMEMOTO 5106a99fe3SHajimu UMEMOTO #define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8) 5206a99fe3SHajimu UMEMOTO #define DEFAULT_MULITPART_SESSIONS_SIZE (1024) 5306a99fe3SHajimu UMEMOTO #define DEFAULT_MULITPART_LIFETIME (3600) 5406a99fe3SHajimu UMEMOTO 5506a99fe3SHajimu UMEMOTO extern const char *c_default_entries[6]; 5606a99fe3SHajimu UMEMOTO 5706a99fe3SHajimu UMEMOTO /* 5806a99fe3SHajimu UMEMOTO * Configuration entry represents the details of each cache entry in the 5906a99fe3SHajimu UMEMOTO * config file (i.e. passwd or group). Its purpose also is to acquire locks 6006a99fe3SHajimu UMEMOTO * of three different types (for usual read/write caching, for multipart 6106a99fe3SHajimu UMEMOTO * caching and for caching of the negative results) for that cache entry. 6206a99fe3SHajimu UMEMOTO */ 6306a99fe3SHajimu UMEMOTO struct configuration_entry { 6406a99fe3SHajimu UMEMOTO struct common_cache_entry_params positive_cache_params; 6506a99fe3SHajimu UMEMOTO struct common_cache_entry_params negative_cache_params; 6606a99fe3SHajimu UMEMOTO struct mp_cache_entry_params mp_cache_params; 6706a99fe3SHajimu UMEMOTO 6806a99fe3SHajimu UMEMOTO /* 6906a99fe3SHajimu UMEMOTO * configuration_entry holds pointers for all actual cache_entries, 7006a99fe3SHajimu UMEMOTO * which are used for it. There is one for positive caching, one for 71*ec8a394dSElyes Haouas * negative caching, and several (one per each euid/egid) for 7206a99fe3SHajimu UMEMOTO * multipart caching. 7306a99fe3SHajimu UMEMOTO */ 7406a99fe3SHajimu UMEMOTO cache_entry positive_cache_entry; 7506a99fe3SHajimu UMEMOTO cache_entry negative_cache_entry; 7606a99fe3SHajimu UMEMOTO 7706a99fe3SHajimu UMEMOTO cache_entry *mp_cache_entries; 7806a99fe3SHajimu UMEMOTO size_t mp_cache_entries_size; 7906a99fe3SHajimu UMEMOTO 8006a99fe3SHajimu UMEMOTO struct timeval common_query_timeout; 8106a99fe3SHajimu UMEMOTO struct timeval mp_query_timeout; 8206a99fe3SHajimu UMEMOTO 8306a99fe3SHajimu UMEMOTO char *name; 8406a99fe3SHajimu UMEMOTO pthread_mutex_t positive_cache_lock; 8506a99fe3SHajimu UMEMOTO pthread_mutex_t negative_cache_lock; 8606a99fe3SHajimu UMEMOTO pthread_mutex_t mp_cache_lock; 8706a99fe3SHajimu UMEMOTO 8806a99fe3SHajimu UMEMOTO int perform_actual_lookups; 8906a99fe3SHajimu UMEMOTO int enabled; 9006a99fe3SHajimu UMEMOTO }; 9106a99fe3SHajimu UMEMOTO 9206a99fe3SHajimu UMEMOTO /* 9306a99fe3SHajimu UMEMOTO * Contains global configuration options and array of all configuration entries 9406a99fe3SHajimu UMEMOTO */ 9506a99fe3SHajimu UMEMOTO struct configuration { 9606a99fe3SHajimu UMEMOTO char *pidfile_path; 9706a99fe3SHajimu UMEMOTO char *socket_path; 9806a99fe3SHajimu UMEMOTO 9906a99fe3SHajimu UMEMOTO struct configuration_entry **entries; 10006a99fe3SHajimu UMEMOTO size_t entries_capacity; 10106a99fe3SHajimu UMEMOTO size_t entries_size; 10206a99fe3SHajimu UMEMOTO 10306a99fe3SHajimu UMEMOTO pthread_rwlock_t rwlock; 10406a99fe3SHajimu UMEMOTO 10506a99fe3SHajimu UMEMOTO mode_t socket_mode; 10606a99fe3SHajimu UMEMOTO int force_unlink; 10706a99fe3SHajimu UMEMOTO int query_timeout; 10806a99fe3SHajimu UMEMOTO 10906a99fe3SHajimu UMEMOTO int threads_num; 11006a99fe3SHajimu UMEMOTO }; 11106a99fe3SHajimu UMEMOTO 11206a99fe3SHajimu UMEMOTO enum config_entry_lock_type { 11306a99fe3SHajimu UMEMOTO CELT_POSITIVE, 11406a99fe3SHajimu UMEMOTO CELT_NEGATIVE, 11506a99fe3SHajimu UMEMOTO CELT_MULTIPART 11606a99fe3SHajimu UMEMOTO }; 11706a99fe3SHajimu UMEMOTO 118d2432adbSDag-Erling Smørgrav struct configuration *init_configuration(void); 119d2432adbSDag-Erling Smørgrav void destroy_configuration(struct configuration *); 120d2432adbSDag-Erling Smørgrav void fill_configuration_defaults(struct configuration *); 12106a99fe3SHajimu UMEMOTO 122d2432adbSDag-Erling Smørgrav int add_configuration_entry(struct configuration *, 12306a99fe3SHajimu UMEMOTO struct configuration_entry *); 124d2432adbSDag-Erling Smørgrav struct configuration_entry *create_def_configuration_entry(const char *); 125d2432adbSDag-Erling Smørgrav void destroy_configuration_entry(struct configuration_entry *); 126d2432adbSDag-Erling Smørgrav size_t configuration_get_entries_size(struct configuration *); 127d2432adbSDag-Erling Smørgrav struct configuration_entry *configuration_get_entry(struct configuration *, 128d2432adbSDag-Erling Smørgrav size_t); 129d2432adbSDag-Erling Smørgrav struct configuration_entry *configuration_find_entry(struct configuration *, 13006a99fe3SHajimu UMEMOTO const char *); 13106a99fe3SHajimu UMEMOTO 132d2432adbSDag-Erling Smørgrav int configuration_entry_add_mp_cache_entry(struct configuration_entry *, 13306a99fe3SHajimu UMEMOTO cache_entry); 134d2432adbSDag-Erling Smørgrav cache_entry configuration_entry_find_mp_cache_entry( 135d2432adbSDag-Erling Smørgrav struct configuration_entry *, const char *); 136d2432adbSDag-Erling Smørgrav int configuration_entry_find_mp_cache_entries(struct configuration_entry *, 137d2432adbSDag-Erling Smørgrav const char *, cache_entry **, cache_entry **); 13806a99fe3SHajimu UMEMOTO 139d2432adbSDag-Erling Smørgrav void configuration_lock_rdlock(struct configuration *config); 140d2432adbSDag-Erling Smørgrav void configuration_lock_wrlock(struct configuration *config); 141d2432adbSDag-Erling Smørgrav void configuration_unlock(struct configuration *config); 14206a99fe3SHajimu UMEMOTO 143d2432adbSDag-Erling Smørgrav void configuration_lock_entry(struct configuration_entry *, 14406a99fe3SHajimu UMEMOTO enum config_entry_lock_type); 145d2432adbSDag-Erling Smørgrav void configuration_unlock_entry(struct configuration_entry *, 14606a99fe3SHajimu UMEMOTO enum config_entry_lock_type); 14706a99fe3SHajimu UMEMOTO 14806a99fe3SHajimu UMEMOTO #endif 149