1155408Srwatson/*- 2155408Srwatson * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 3188315Srwatson * All rights reserved. 4155408Srwatson * 5155408Srwatson * Redistribution and use in source and binary forms, with or without 6155408Srwatson * modification, are permitted provided that the following conditions 7155408Srwatson * are met: 8155408Srwatson * 1. Redistributions of source code must retain the above copyright 9155408Srwatson * notice, this list of conditions and the following disclaimer. 10155408Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11155408Srwatson * notice, this list of conditions and the following disclaimer in the 12155408Srwatson * documentation and/or other materials provided with the distribution. 13155408Srwatson * 14155408Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15155408Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16155408Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17155408Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18155408Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19155408Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20155408Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21155408Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22155408Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23155408Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24155408Srwatson * SUCH DAMAGE. 25155408Srwatson * 26155408Srwatson * $FreeBSD: releng/11.0/usr.sbin/nscd/config.h 238094 2012-07-04 09:02:12Z se $ 27155408Srwatson */ 28155408Srwatson 29155408Srwatson#ifndef __NSCD_CONFIG_H__ 30178186Srwatson#define __NSCD_CONFIG_H__ 31178186Srwatson 32178186Srwatson#include "cachelib.h" 33155408Srwatson 34155408Srwatson#define DEFAULT_QUERY_TIMEOUT 8 35155408Srwatson#define DEFAULT_THREADS_NUM 8 36155408Srwatson 37155408Srwatson#define DEFAULT_COMMON_ENTRY_TIMEOUT 10 38155408Srwatson#define DEFAULT_MP_ENTRY_TIMEOUT 60 39155408Srwatson#define DEFAULT_CACHE_HT_SIZE 257 40155408Srwatson 41155408Srwatson#define INITIAL_ENTRIES_CAPACITY 8 42155408Srwatson#define DEFAULT_SOCKET_PATH "/var/run/nscd" 43155408Srwatson#define DEFAULT_PIDFILE_PATH "/var/run/nscd.pid" 44155408Srwatson 45184488Srwatson#define DEFAULT_POSITIVE_ELEMENTS_SIZE (2048) 46155408Srwatson#define DEFAULT_POSITIVE_LIFETIME (3600) 47155408Srwatson#define DEFAULT_POSITIVE_CONF_THRESH (1) 48155408Srwatson 49155408Srwatson#define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048) 50184508Srwatson#define DEFAULT_NEGATIVE_LIFETIME (60) 51155408Srwatson#define DEFAULT_NEGATIVE_CONF_THRESH (1) /* (2) ??? */ 52155408Srwatson 53155408Srwatson#define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8) 54155408Srwatson#define DEFAULT_MULITPART_SESSIONS_SIZE (1024) 55156880Srwatson#define DEFAULT_MULITPART_LIFETIME (3600) 56155408Srwatson 57155408Srwatsonextern const char *c_default_entries[6]; 58155408Srwatson 59155408Srwatson/* 60184545Srwatson * Configuration entry represents the details of each cache entry in the 61184545Srwatson * config file (i.e. passwd or group). Its purpose also is to acquire locks 62184545Srwatson * of three different types (for usual read/write caching, for multipart 63184545Srwatson * caching and for caching of the negative results) for that cache entry. 64155408Srwatson */ 65155408Srwatsonstruct configuration_entry { 66155408Srwatson struct common_cache_entry_params positive_cache_params; 67155408Srwatson struct common_cache_entry_params negative_cache_params; 68155408Srwatson struct mp_cache_entry_params mp_cache_params; 69155408Srwatson 70155408Srwatson /* 71155408Srwatson * configuration_entry holds pointers for all actual cache_entries, 72174894Swkoszek * which are used for it. There is one for positive caching, one for 73159269Srwatson * for negative caching, and several (one per each euid/egid) for 74155408Srwatson * multipart caching. 75155408Srwatson */ 76155408Srwatson cache_entry positive_cache_entry; 77155408Srwatson cache_entry negative_cache_entry; 78156883Srwatson 79188315Srwatson cache_entry *mp_cache_entries; 80155408Srwatson size_t mp_cache_entries_size; 81155408Srwatson 82155408Srwatson struct timeval common_query_timeout; 83155408Srwatson struct timeval mp_query_timeout; 84155408Srwatson 85155408Srwatson char *name; 86155408Srwatson pthread_mutex_t positive_cache_lock; 87155408Srwatson pthread_mutex_t negative_cache_lock; 88155408Srwatson pthread_mutex_t mp_cache_lock; 89155408Srwatson 90155408Srwatson int perform_actual_lookups; 91155408Srwatson int enabled; 92159269Srwatson}; 93159269Srwatson 94159269Srwatson/* 95159269Srwatson * Contains global configuration options and array of all configuration entries 96159269Srwatson */ 97159269Srwatsonstruct configuration { 98159269Srwatson char *pidfile_path; 99159269Srwatson char *socket_path; 100159269Srwatson 101159269Srwatson struct configuration_entry **entries; 102159269Srwatson size_t entries_capacity; 103159269Srwatson size_t entries_size; 104159269Srwatson 105159269Srwatson pthread_rwlock_t rwlock; 106159269Srwatson 107159269Srwatson mode_t socket_mode; 108159269Srwatson int force_unlink; 109155408Srwatson int query_timeout; 110155408Srwatson 111155408Srwatson int threads_num; 112155408Srwatson}; 113155408Srwatson 114155408Srwatsonenum config_entry_lock_type { 115155408Srwatson CELT_POSITIVE, 116155408Srwatson CELT_NEGATIVE, 117155408Srwatson CELT_MULTIPART 118155408Srwatson}; 119155408Srwatson 120184488Srwatsonstruct configuration *init_configuration(void); 121184488Srwatsonvoid destroy_configuration(struct configuration *); 122184488Srwatsonvoid fill_configuration_defaults(struct configuration *); 123184508Srwatson 124184488Srwatsonint add_configuration_entry(struct configuration *, 125184488Srwatson struct configuration_entry *); 126184508Srwatsonstruct configuration_entry *create_def_configuration_entry(const char *); 127184508Srwatsonvoid destroy_configuration_entry(struct configuration_entry *); 128184508Srwatsonsize_t configuration_get_entries_size(struct configuration *); 129184508Srwatsonstruct configuration_entry *configuration_get_entry(struct configuration *, 130184508Srwatson size_t); 131184508Srwatsonstruct configuration_entry *configuration_find_entry(struct configuration *, 132184508Srwatson const char *); 133184508Srwatson 134184488Srwatsonint configuration_entry_add_mp_cache_entry(struct configuration_entry *, 135184488Srwatson cache_entry); 136184488Srwatsoncache_entry configuration_entry_find_mp_cache_entry( 137184488Srwatson struct configuration_entry *, const char *); 138184488Srwatsonint configuration_entry_find_mp_cache_entries(struct configuration_entry *, 139184536Srwatson const char *, cache_entry **, cache_entry **); 140184536Srwatson 141184536Srwatsonvoid configuration_lock_rdlock(struct configuration *config); 142184536Srwatsonvoid configuration_lock_wrlock(struct configuration *config); 143184536Srwatsonvoid configuration_unlock(struct configuration *config); 144184536Srwatson 145184536Srwatsonvoid configuration_lock_entry(struct configuration_entry *, 146155408Srwatson enum config_entry_lock_type); 147155408Srwatsonvoid configuration_unlock_entry(struct configuration_entry *, 148184536Srwatson enum config_entry_lock_type); 149184536Srwatson 150155408Srwatson#endif 151184540Srwatson