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 * $FreeBSD$ 2706a99fe3SHajimu UMEMOTO */ 2806a99fe3SHajimu UMEMOTO 2906a99fe3SHajimu UMEMOTO #ifndef __CACHED_CONFIG_H__ 3006a99fe3SHajimu UMEMOTO #define __CACHED_CONFIG_H__ 3106a99fe3SHajimu UMEMOTO 3206a99fe3SHajimu UMEMOTO #include <sys/stat.h> 3306a99fe3SHajimu UMEMOTO #include <sys/types.h> 3406a99fe3SHajimu UMEMOTO #include <pthread.h> 3506a99fe3SHajimu UMEMOTO #include <nsswitch.h> 3606a99fe3SHajimu UMEMOTO #include <unistd.h> 3706a99fe3SHajimu UMEMOTO #include "cachelib.h" 3806a99fe3SHajimu UMEMOTO 3906a99fe3SHajimu UMEMOTO #define DEFAULT_QUERY_TIMEOUT 8 4006a99fe3SHajimu UMEMOTO #define DEFAULT_THREADS_NUM 8 4106a99fe3SHajimu UMEMOTO 4206a99fe3SHajimu UMEMOTO #define DEFAULT_COMMON_ENTRY_TIMEOUT 10 4306a99fe3SHajimu UMEMOTO #define DEFAULT_MP_ENTRY_TIMEOUT 60 4406a99fe3SHajimu UMEMOTO #define DEFAULT_CACHE_HT_SIZE 257 4506a99fe3SHajimu UMEMOTO 4606a99fe3SHajimu UMEMOTO #define INITIAL_ENTRIES_CAPACITY 8 4706a99fe3SHajimu UMEMOTO #define DEFAULT_SOCKET_PATH "/var/run/cached" 4806a99fe3SHajimu UMEMOTO #define DEFAULT_PIDFILE_PATH "/var/run/cached.pid" 4906a99fe3SHajimu UMEMOTO 5006a99fe3SHajimu UMEMOTO #define DEFAULT_POSITIVE_ELEMENTS_SIZE (2048) 5106a99fe3SHajimu UMEMOTO #define DEFAULT_POSITIVE_LIFETIME (3600) 5206a99fe3SHajimu UMEMOTO 5306a99fe3SHajimu UMEMOTO #define DEFAULT_NEGATIVE_ELEMENTS_SIZE (2048) 5406a99fe3SHajimu UMEMOTO #define DEFAULT_NEGATIVE_LIFETIME (60) 5506a99fe3SHajimu UMEMOTO 5606a99fe3SHajimu UMEMOTO #define DEFAULT_MULTIPART_ELEMENTS_SIZE (1024 * 8) 5706a99fe3SHajimu UMEMOTO #define DEFAULT_MULITPART_SESSIONS_SIZE (1024) 5806a99fe3SHajimu UMEMOTO #define DEFAULT_MULITPART_LIFETIME (3600) 5906a99fe3SHajimu UMEMOTO 6006a99fe3SHajimu UMEMOTO extern const char *c_default_entries[6]; 6106a99fe3SHajimu UMEMOTO 6206a99fe3SHajimu UMEMOTO /* 6306a99fe3SHajimu UMEMOTO * Configuration entry represents the details of each cache entry in the 6406a99fe3SHajimu UMEMOTO * config file (i.e. passwd or group). Its purpose also is to acquire locks 6506a99fe3SHajimu UMEMOTO * of three different types (for usual read/write caching, for multipart 6606a99fe3SHajimu UMEMOTO * caching and for caching of the negative results) for that cache entry. 6706a99fe3SHajimu UMEMOTO */ 6806a99fe3SHajimu UMEMOTO struct configuration_entry { 6906a99fe3SHajimu UMEMOTO struct common_cache_entry_params positive_cache_params; 7006a99fe3SHajimu UMEMOTO struct common_cache_entry_params negative_cache_params; 7106a99fe3SHajimu UMEMOTO struct mp_cache_entry_params mp_cache_params; 7206a99fe3SHajimu UMEMOTO 7306a99fe3SHajimu UMEMOTO /* 7406a99fe3SHajimu UMEMOTO * configuration_entry holds pointers for all actual cache_entries, 7506a99fe3SHajimu UMEMOTO * which are used for it. There is one for positive caching, one for 7606a99fe3SHajimu UMEMOTO * for negative caching, and several (one per each euid/egid) for 7706a99fe3SHajimu UMEMOTO * multipart caching. 7806a99fe3SHajimu UMEMOTO */ 7906a99fe3SHajimu UMEMOTO cache_entry positive_cache_entry; 8006a99fe3SHajimu UMEMOTO cache_entry negative_cache_entry; 8106a99fe3SHajimu UMEMOTO 8206a99fe3SHajimu UMEMOTO cache_entry *mp_cache_entries; 8306a99fe3SHajimu UMEMOTO size_t mp_cache_entries_size; 8406a99fe3SHajimu UMEMOTO 8506a99fe3SHajimu UMEMOTO struct timeval common_query_timeout; 8606a99fe3SHajimu UMEMOTO struct timeval mp_query_timeout; 8706a99fe3SHajimu UMEMOTO 8806a99fe3SHajimu UMEMOTO char *name; 8906a99fe3SHajimu UMEMOTO pthread_mutex_t positive_cache_lock; 9006a99fe3SHajimu UMEMOTO pthread_mutex_t negative_cache_lock; 9106a99fe3SHajimu UMEMOTO pthread_mutex_t mp_cache_lock; 9206a99fe3SHajimu UMEMOTO 9306a99fe3SHajimu UMEMOTO int perform_actual_lookups; 9406a99fe3SHajimu UMEMOTO int enabled; 9506a99fe3SHajimu UMEMOTO }; 9606a99fe3SHajimu UMEMOTO 9706a99fe3SHajimu UMEMOTO /* 9806a99fe3SHajimu UMEMOTO * Contains global configuration options and array of all configuration entries 9906a99fe3SHajimu UMEMOTO */ 10006a99fe3SHajimu UMEMOTO struct configuration { 10106a99fe3SHajimu UMEMOTO char *pidfile_path; 10206a99fe3SHajimu UMEMOTO char *socket_path; 10306a99fe3SHajimu UMEMOTO 10406a99fe3SHajimu UMEMOTO struct configuration_entry **entries; 10506a99fe3SHajimu UMEMOTO size_t entries_capacity; 10606a99fe3SHajimu UMEMOTO size_t entries_size; 10706a99fe3SHajimu UMEMOTO 10806a99fe3SHajimu UMEMOTO pthread_rwlock_t rwlock; 10906a99fe3SHajimu UMEMOTO 11006a99fe3SHajimu UMEMOTO mode_t socket_mode; 11106a99fe3SHajimu UMEMOTO int force_unlink; 11206a99fe3SHajimu UMEMOTO int query_timeout; 11306a99fe3SHajimu UMEMOTO 11406a99fe3SHajimu UMEMOTO int threads_num; 11506a99fe3SHajimu UMEMOTO }; 11606a99fe3SHajimu UMEMOTO 11706a99fe3SHajimu UMEMOTO enum config_entry_lock_type { 11806a99fe3SHajimu UMEMOTO CELT_POSITIVE, 11906a99fe3SHajimu UMEMOTO CELT_NEGATIVE, 12006a99fe3SHajimu UMEMOTO CELT_MULTIPART 12106a99fe3SHajimu UMEMOTO }; 12206a99fe3SHajimu UMEMOTO 12306a99fe3SHajimu UMEMOTO extern struct configuration *init_configuration(void); 12406a99fe3SHajimu UMEMOTO extern void destroy_configuration(struct configuration *); 12506a99fe3SHajimu UMEMOTO extern void fill_configuration_defaults(struct configuration *); 12606a99fe3SHajimu UMEMOTO 12706a99fe3SHajimu UMEMOTO extern int add_configuration_entry(struct configuration *, 12806a99fe3SHajimu UMEMOTO struct configuration_entry *); 12906a99fe3SHajimu UMEMOTO extern struct configuration_entry *create_def_configuration_entry( 13006a99fe3SHajimu UMEMOTO const char *); 13106a99fe3SHajimu UMEMOTO extern void destroy_configuration_entry(struct configuration_entry *); 13206a99fe3SHajimu UMEMOTO extern size_t configuration_get_entries_size(struct configuration *); 13306a99fe3SHajimu UMEMOTO extern struct configuration_entry *configuration_get_entry( 13406a99fe3SHajimu UMEMOTO struct configuration *, size_t); 13506a99fe3SHajimu UMEMOTO extern struct configuration_entry *configuration_find_entry( 13606a99fe3SHajimu UMEMOTO struct configuration *, const char *); 13706a99fe3SHajimu UMEMOTO 13806a99fe3SHajimu UMEMOTO extern int configuration_entry_add_mp_cache_entry(struct configuration_entry *, 13906a99fe3SHajimu UMEMOTO cache_entry); 14006a99fe3SHajimu UMEMOTO extern cache_entry configuration_entry_find_mp_cache_entry( 14106a99fe3SHajimu UMEMOTO struct configuration_entry *, 14206a99fe3SHajimu UMEMOTO const char *); 14306a99fe3SHajimu UMEMOTO extern int configuration_entry_find_mp_cache_entries( 14406a99fe3SHajimu UMEMOTO struct configuration_entry *, const char *, cache_entry **, 14506a99fe3SHajimu UMEMOTO cache_entry **); 14606a99fe3SHajimu UMEMOTO 14706a99fe3SHajimu UMEMOTO extern void configuration_lock_rdlock(struct configuration *config); 14806a99fe3SHajimu UMEMOTO extern void configuration_lock_wrlock(struct configuration *config); 14906a99fe3SHajimu UMEMOTO extern void configuration_unlock(struct configuration *config); 15006a99fe3SHajimu UMEMOTO 15106a99fe3SHajimu UMEMOTO extern void configuration_lock_entry(struct configuration_entry *, 15206a99fe3SHajimu UMEMOTO enum config_entry_lock_type); 15306a99fe3SHajimu UMEMOTO extern void configuration_unlock_entry(struct configuration_entry *, 15406a99fe3SHajimu UMEMOTO enum config_entry_lock_type); 15506a99fe3SHajimu UMEMOTO 15606a99fe3SHajimu UMEMOTO #endif 157