1158115Sume/*- 2158115Sume * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 3158115Sume * All rights reserved. 4158115Sume * 5158115Sume * Redistribution and use in source and binary forms, with or without 6158115Sume * modification, are permitted provided that the following conditions 7158115Sume * are met: 8158115Sume * 1. Redistributions of source code must retain the above copyright 9158115Sume * notice, this list of conditions and the following disclaimer. 10158115Sume * 2. Redistributions in binary form must reproduce the above copyright 11158115Sume * notice, this list of conditions and the following disclaimer in the 12158115Sume * documentation and/or other materials provided with the distribution. 13158115Sume * 14158115Sume * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15158115Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16158115Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17158115Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18158115Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19158115Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20158115Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21158115Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22158115Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23158115Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24158115Sume * SUCH DAMAGE. 25158115Sume * 26158115Sume * $FreeBSD$ 27158115Sume */ 28158115Sume 29171795Sbushman#ifndef __NSCD_CONFIG_H__ 30171795Sbushman#define __NSCD_CONFIG_H__ 31158115Sume 32158115Sume#include "cachelib.h" 33158115Sume 34158115Sume#define DEFAULT_QUERY_TIMEOUT 8 35158115Sume#define DEFAULT_THREADS_NUM 8 36158115Sume 37158115Sume#define DEFAULT_COMMON_ENTRY_TIMEOUT 10 38158115Sume#define DEFAULT_MP_ENTRY_TIMEOUT 60 39158115Sume#define DEFAULT_CACHE_HT_SIZE 257 40158115Sume 41158115Sume#define INITIAL_ENTRIES_CAPACITY 8 42171795Sbushman#define DEFAULT_SOCKET_PATH "/var/run/nscd" 43171795Sbushman#define DEFAULT_PIDFILE_PATH "/var/run/nscd.pid" 44158115Sume 45158115Sume#define DEFAULT_POSITIVE_ELEMENTS_SIZE (2048) 46158115Sume#define DEFAULT_POSITIVE_LIFETIME (3600) 47238094Sse#define DEFAULT_POSITIVE_CONF_THRESH (1) 48158115Sume 49158115Sume#define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048) 50158115Sume#define DEFAULT_NEGATIVE_LIFETIME (60) 51238094Sse#define DEFAULT_NEGATIVE_CONF_THRESH (1) /* (2) ??? */ 52158115Sume 53158115Sume#define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8) 54158115Sume#define DEFAULT_MULITPART_SESSIONS_SIZE (1024) 55158115Sume#define DEFAULT_MULITPART_LIFETIME (3600) 56158115Sume 57158115Sumeextern const char *c_default_entries[6]; 58158115Sume 59158115Sume/* 60158115Sume * Configuration entry represents the details of each cache entry in the 61158115Sume * config file (i.e. passwd or group). Its purpose also is to acquire locks 62158115Sume * of three different types (for usual read/write caching, for multipart 63158115Sume * caching and for caching of the negative results) for that cache entry. 64158115Sume */ 65158115Sumestruct configuration_entry { 66158115Sume struct common_cache_entry_params positive_cache_params; 67158115Sume struct common_cache_entry_params negative_cache_params; 68158115Sume struct mp_cache_entry_params mp_cache_params; 69158115Sume 70158115Sume /* 71158115Sume * configuration_entry holds pointers for all actual cache_entries, 72158115Sume * which are used for it. There is one for positive caching, one for 73158115Sume * for negative caching, and several (one per each euid/egid) for 74158115Sume * multipart caching. 75158115Sume */ 76158115Sume cache_entry positive_cache_entry; 77158115Sume cache_entry negative_cache_entry; 78158115Sume 79158115Sume cache_entry *mp_cache_entries; 80158115Sume size_t mp_cache_entries_size; 81158115Sume 82158115Sume struct timeval common_query_timeout; 83158115Sume struct timeval mp_query_timeout; 84158115Sume 85158115Sume char *name; 86158115Sume pthread_mutex_t positive_cache_lock; 87158115Sume pthread_mutex_t negative_cache_lock; 88158115Sume pthread_mutex_t mp_cache_lock; 89158115Sume 90158115Sume int perform_actual_lookups; 91158115Sume int enabled; 92158115Sume}; 93158115Sume 94158115Sume/* 95158115Sume * Contains global configuration options and array of all configuration entries 96158115Sume */ 97158115Sumestruct configuration { 98158115Sume char *pidfile_path; 99158115Sume char *socket_path; 100158115Sume 101158115Sume struct configuration_entry **entries; 102158115Sume size_t entries_capacity; 103158115Sume size_t entries_size; 104158115Sume 105158115Sume pthread_rwlock_t rwlock; 106158115Sume 107158115Sume mode_t socket_mode; 108158115Sume int force_unlink; 109158115Sume int query_timeout; 110158115Sume 111158115Sume int threads_num; 112158115Sume}; 113158115Sume 114158115Sumeenum config_entry_lock_type { 115158115Sume CELT_POSITIVE, 116158115Sume CELT_NEGATIVE, 117158115Sume CELT_MULTIPART 118158115Sume}; 119158115Sume 120194112Sdesstruct configuration *init_configuration(void); 121194112Sdesvoid destroy_configuration(struct configuration *); 122194112Sdesvoid fill_configuration_defaults(struct configuration *); 123158115Sume 124194112Sdesint add_configuration_entry(struct configuration *, 125158115Sume struct configuration_entry *); 126194112Sdesstruct configuration_entry *create_def_configuration_entry(const char *); 127194112Sdesvoid destroy_configuration_entry(struct configuration_entry *); 128194112Sdessize_t configuration_get_entries_size(struct configuration *); 129194112Sdesstruct configuration_entry *configuration_get_entry(struct configuration *, 130194112Sdes size_t); 131194112Sdesstruct configuration_entry *configuration_find_entry(struct configuration *, 132158115Sume const char *); 133158115Sume 134194112Sdesint configuration_entry_add_mp_cache_entry(struct configuration_entry *, 135158115Sume cache_entry); 136194112Sdescache_entry configuration_entry_find_mp_cache_entry( 137194112Sdes struct configuration_entry *, const char *); 138194112Sdesint configuration_entry_find_mp_cache_entries(struct configuration_entry *, 139194112Sdes const char *, cache_entry **, cache_entry **); 140158115Sume 141194112Sdesvoid configuration_lock_rdlock(struct configuration *config); 142194112Sdesvoid configuration_lock_wrlock(struct configuration *config); 143194112Sdesvoid configuration_unlock(struct configuration *config); 144158115Sume 145194112Sdesvoid configuration_lock_entry(struct configuration_entry *, 146158115Sume enum config_entry_lock_type); 147194112Sdesvoid configuration_unlock_entry(struct configuration_entry *, 148158115Sume enum config_entry_lock_type); 149158115Sume 150158115Sume#endif 151