Updated to fedora-glibc-20080305T0857
[glibc.git] / nscd / nscd.h
blobec2d9454cad8789ab24aae4c20ddb26f337277d0
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];
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 /* Prototypes for global functions. */
186 /* nscd.c */
187 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
188 extern int nscd_open_socket (void);
190 /* connections.c */
191 extern void nscd_init (void);
192 extern void close_sockets (void);
193 extern void start_threads (void) __attribute__ ((__noreturn__));
195 /* nscd_conf.c */
196 extern int nscd_parse_file (const char *fname,
197 struct database_dyn dbs[lastdb]);
199 /* nscd_stat.c */
200 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
201 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
203 /* cache.c */
204 extern struct datahead *cache_search (request_type, void *key, size_t len,
205 struct database_dyn *table,
206 uid_t owner);
207 extern int cache_add (int type, const void *key, size_t len,
208 struct datahead *packet, bool first,
209 struct database_dyn *table, uid_t owner);
210 extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
212 /* pwdcache.c */
213 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
214 void *key, uid_t uid);
215 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
216 void *key, uid_t uid);
217 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
218 struct datahead *dh);
219 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
220 struct datahead *dh);
222 /* grpcache.c */
223 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
224 void *key, uid_t uid);
225 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
226 void *key, uid_t uid);
227 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
228 struct datahead *dh);
229 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
230 struct datahead *dh);
232 /* hstcache.c */
233 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
234 void *key, uid_t uid);
235 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
236 void *key, uid_t uid);
237 extern void addhstbynamev6 (struct database_dyn *db, int fd,
238 request_header *req, void *key, uid_t uid);
239 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
240 request_header *req, void *key, uid_t uid);
241 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
242 struct datahead *dh);
243 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
244 struct datahead *dh);
245 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
246 struct datahead *dh);
247 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
248 struct datahead *dh);
250 /* aicache.c */
251 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
252 void *key, uid_t uid);
253 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
254 struct datahead *dh);
257 /* initgrcache.c */
258 extern void addinitgroups (struct database_dyn *db, int fd,
259 request_header *req, void *key, uid_t uid);
260 extern void readdinitgroups (struct database_dyn *db, struct hashentry *he,
261 struct datahead *dh);
263 /* servicecache.c */
264 extern void addservbyname (struct database_dyn *db, int fd,
265 request_header *req, void *key, uid_t uid);
266 extern void readdservbyname (struct database_dyn *db, struct hashentry *he,
267 struct datahead *dh);
268 extern void addservbyport (struct database_dyn *db, int fd,
269 request_header *req, void *key, uid_t uid);
270 extern void readdservbyport (struct database_dyn *db, struct hashentry *he,
271 struct datahead *dh);
273 /* mem.c */
274 extern void *mempool_alloc (struct database_dyn *db, size_t len);
275 extern void gc (struct database_dyn *db);
278 /* nscd_setup_thread.c */
279 extern int setup_thread (struct database_dyn *db);
282 /* Special version of TEMP_FAILURE_RETRY for functions returning error
283 values. */
284 #define TEMP_FAILURE_RETRY_VAL(expression) \
285 (__extension__ \
286 ({ long int __result; \
287 do __result = (long int) (expression); \
288 while (__result == EINTR); \
289 __result; }))
291 #endif /* nscd.h */