Updated to fedora-glibc-20080524T2218
[glibc.git] / nscd / nscd.h
blobb07256de80a1ba3157e4442cde320bc869602eaa
1 /* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _NSCD_H
22 #define _NSCD_H 1
24 #include <pthread.h>
25 #include <stdbool.h>
26 #include <time.h>
27 #include <sys/uio.h>
29 /* The declarations for the request and response types are in the file
30 "nscd-client.h", which should contain everything needed by client
31 functions. */
32 #include "nscd-client.h"
35 /* Handle databases. */
36 typedef enum
38 pwddb,
39 grpdb,
40 hstdb,
41 servdb,
42 lastdb
43 } dbtype;
46 /* Default limit on the number of times a value gets reloaded without
47 being used in the meantime. NSCD does not throw a value out as
48 soon as it times out. It tries to reload the value from the
49 server. Only if the value has not been used for so many rounds it
50 is removed. */
51 #define DEFAULT_RELOAD_LIMIT 5
54 /* Time before restarting the process in paranoia mode. */
55 #define RESTART_INTERVAL (60 * 60)
58 /* Stack size for worker threads. */
59 #define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
61 /* Maximum size of stack frames we allow the thread to use. We use
62 80% of the thread stack size. */
63 #define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10)
66 /* Structure describing dynamic part of one database. */
67 struct database_dyn
69 pthread_rwlock_t lock;
70 pthread_cond_t prune_cond;
71 pthread_mutex_t prune_lock;
72 time_t wakeup_time;
74 int enabled;
75 int check_file;
76 int persistent;
77 int shared;
78 int propagate;
79 int reset_res;
80 const char filename[16];
81 const char *db_filename;
82 time_t file_mtime;
83 size_t suggested_module;
84 size_t max_db_size;
86 unsigned long int postimeout; /* In seconds. */
87 unsigned long int negtimeout; /* In seconds. */
89 int wr_fd; /* Writable file descriptor. */
90 int ro_fd; /* Unwritable file descriptor. */
92 const struct iovec *disabled_iov;
94 struct database_pers_head *head;
95 char *data;
96 size_t memsize;
97 pthread_mutex_t memlock;
98 bool mmap_used;
99 bool last_alloc_failed;
103 /* Paths of the file for the persistent storage. */
104 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
105 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
106 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
107 #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services"
109 /* Path used when not using persistent storage. */
110 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
112 /* Maximum alignment requirement we will encounter. */
113 #define BLOCK_ALIGN_LOG 3
114 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
115 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
117 /* Default value for the maximum size of the database files. */
118 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
120 /* Number of bytes of data we initially reserve for each hash table bucket. */
121 #define DEFAULT_DATASIZE_PER_BUCKET 1024
123 /* Default module of hash table. */
124 #define DEFAULT_SUGGESTED_MODULE 211
127 /* Number of seconds between two cache pruning runs if we do not have
128 better information when it is really needed. */
129 #define CACHE_PRUNE_INTERVAL 15
132 /* Global variables. */
133 extern struct database_dyn dbs[lastdb] attribute_hidden;
134 extern const char *const dbnames[lastdb];
135 extern const char *const serv2str[LASTREQ];
137 extern const struct iovec pwd_iov_disabled;
138 extern const struct iovec grp_iov_disabled;
139 extern const struct iovec hst_iov_disabled;
140 extern const struct iovec serv_iov_disabled;
143 /* Initial number of threads to run. */
144 extern int nthreads;
145 /* Maximum number of threads to use. */
146 extern int max_nthreads;
148 /* User name to run server processes as. */
149 extern const char *server_user;
151 /* Name and UID of user who is allowed to request statistics. */
152 extern const char *stat_user;
153 extern uid_t stat_uid;
155 /* Time the server was started. */
156 extern time_t start_time;
158 /* Number of times clients had to wait. */
159 extern unsigned long int client_queued;
161 /* Maximum needed alignment. */
162 extern const size_t block_align;
164 /* Number of times a value is reloaded without being used. UINT_MAX
165 means unlimited. */
166 extern unsigned int reload_count;
168 /* Pagesize minus one. */
169 extern uintptr_t pagesize_m1;
171 /* Nonzero if paranoia mode is enabled. */
172 extern int paranoia;
173 /* Time after which the process restarts. */
174 extern time_t restart_time;
175 /* How much time between restarts. */
176 extern time_t restart_interval;
177 /* Old current working directory. */
178 extern const char *oldcwd;
179 /* Old user and group ID. */
180 extern uid_t old_uid;
181 extern gid_t old_gid;
184 /* Memory allocation in flight. Each thread can have a limited number
185 of allocation in flight. No need to create dynamic data
186 structures. We use fixed indices. */
187 enum in_flight
189 IDX_result_data = 0,
190 /* Keep the IDX_record_data entry last at all times. */
191 IDX_record_data = 1,
192 IDX_last
194 extern __thread struct mem_in_flight
196 struct
198 int dbidx;
199 nscd_ssize_t blocklen;
200 nscd_ssize_t blockoff;
201 } block[IDX_last];
203 struct mem_in_flight *next;
204 } mem_in_flight attribute_tls_model_ie;
205 /* Global list of the mem_in_flight variables of all the threads. */
206 extern struct mem_in_flight *mem_in_flight_list;
209 /* Prototypes for global functions. */
211 /* nscd.c */
212 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
213 extern int nscd_open_socket (void);
215 /* connections.c */
216 extern void nscd_init (void);
217 extern void close_sockets (void);
218 extern void start_threads (void) __attribute__ ((__noreturn__));
220 /* nscd_conf.c */
221 extern int nscd_parse_file (const char *fname,
222 struct database_dyn dbs[lastdb]);
224 /* nscd_stat.c */
225 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
226 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
228 /* cache.c */
229 extern struct datahead *cache_search (request_type, void *key, size_t len,
230 struct database_dyn *table,
231 uid_t owner);
232 extern int cache_add (int type, const void *key, size_t len,
233 struct datahead *packet, bool first,
234 struct database_dyn *table, uid_t owner,
235 bool prune_wakeup);
236 extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
238 /* pwdcache.c */
239 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
240 void *key, uid_t uid);
241 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
242 void *key, uid_t uid);
243 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
244 struct datahead *dh);
245 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
246 struct datahead *dh);
248 /* grpcache.c */
249 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
250 void *key, uid_t uid);
251 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
252 void *key, uid_t uid);
253 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
254 struct datahead *dh);
255 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
256 struct datahead *dh);
258 /* hstcache.c */
259 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
260 void *key, uid_t uid);
261 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
262 void *key, uid_t uid);
263 extern void addhstbynamev6 (struct database_dyn *db, int fd,
264 request_header *req, void *key, uid_t uid);
265 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
266 request_header *req, void *key, uid_t uid);
267 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
268 struct datahead *dh);
269 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
270 struct datahead *dh);
271 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
272 struct datahead *dh);
273 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
274 struct datahead *dh);
276 /* aicache.c */
277 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
278 void *key, uid_t uid);
279 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
280 struct datahead *dh);
283 /* initgrcache.c */
284 extern void addinitgroups (struct database_dyn *db, int fd,
285 request_header *req, void *key, uid_t uid);
286 extern void readdinitgroups (struct database_dyn *db, struct hashentry *he,
287 struct datahead *dh);
289 /* servicecache.c */
290 extern void addservbyname (struct database_dyn *db, int fd,
291 request_header *req, void *key, uid_t uid);
292 extern void readdservbyname (struct database_dyn *db, struct hashentry *he,
293 struct datahead *dh);
294 extern void addservbyport (struct database_dyn *db, int fd,
295 request_header *req, void *key, uid_t uid);
296 extern void readdservbyport (struct database_dyn *db, struct hashentry *he,
297 struct datahead *dh);
299 /* mem.c */
300 extern void *mempool_alloc (struct database_dyn *db, size_t len,
301 enum in_flight idx);
302 extern void gc (struct database_dyn *db);
305 /* nscd_setup_thread.c */
306 extern int setup_thread (struct database_dyn *db);
309 /* Special version of TEMP_FAILURE_RETRY for functions returning error
310 values. */
311 #define TEMP_FAILURE_RETRY_VAL(expression) \
312 (__extension__ \
313 ({ long int __result; \
314 do __result = (long int) (expression); \
315 while (__result == EINTR); \
316 __result; }))
318 #endif /* nscd.h */