Cast to uint64_t for 64-bit store
[glibc.git] / nscd / nscd.h
blob86ac27855a4617549ef09511c663306d21e4f3d7
1 /* Copyright (c) 1998-2001, 2003-2009, 2011, 2012 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _NSCD_H
20 #define _NSCD_H 1
22 #include <pthread.h>
23 #include <stdbool.h>
24 #include <time.h>
25 #include <sys/uio.h>
27 /* The declarations for the request and response types are in the file
28 "nscd-client.h", which should contain everything needed by client
29 functions. */
30 #include "nscd-client.h"
33 /* Handle databases. */
34 typedef enum
36 pwddb,
37 grpdb,
38 hstdb,
39 servdb,
40 netgrdb,
41 lastdb
42 } dbtype;
45 /* Default limit on the number of times a value gets reloaded without
46 being used in the meantime. NSCD does not throw a value out as
47 soon as it times out. It tries to reload the value from the
48 server. Only if the value has not been used for so many rounds it
49 is removed. */
50 #define DEFAULT_RELOAD_LIMIT 5
53 /* Time before restarting the process in paranoia mode. */
54 #define RESTART_INTERVAL (60 * 60)
57 /* Stack size for worker threads. */
58 #define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
60 /* Maximum size of stack frames we allow the thread to use. We use
61 80% of the thread stack size. */
62 #define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10)
65 /* Registered filename used to fill database. */
66 struct traced_file
68 time_t mtime;
69 struct traced_file *next;
70 int call_res_init;
71 int inotify_descr;
72 char fname[];
76 /* Structure describing dynamic part of one database. */
77 struct database_dyn
79 pthread_rwlock_t lock;
80 pthread_cond_t prune_cond;
81 pthread_mutex_t prune_lock;
82 pthread_mutex_t prune_run_lock;
83 time_t wakeup_time;
85 int enabled;
86 int check_file;
87 int clear_cache;
88 int persistent;
89 int shared;
90 int propagate;
91 struct traced_file *traced_files;
92 const char *db_filename;
93 time_t file_mtime;
94 size_t suggested_module;
95 size_t max_db_size;
97 unsigned long int postimeout; /* In seconds. */
98 unsigned long int negtimeout; /* In seconds. */
100 int wr_fd; /* Writable file descriptor. */
101 int ro_fd; /* Unwritable file descriptor. */
103 const struct iovec *disabled_iov;
105 struct database_pers_head *head;
106 char *data;
107 size_t memsize;
108 pthread_mutex_t memlock;
109 bool mmap_used;
110 bool last_alloc_failed;
114 /* Paths of the file for the persistent storage. */
115 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
116 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
117 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
118 #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services"
119 #define _PATH_NSCD_NETGROUP_DB "/var/db/nscd/netgroup"
121 /* Path used when not using persistent storage. */
122 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
124 /* Maximum alignment requirement we will encounter. */
125 #define BLOCK_ALIGN_LOG 3
126 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
127 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
129 /* Default value for the maximum size of the database files. */
130 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
132 /* Number of bytes of data we initially reserve for each hash table bucket. */
133 #define DEFAULT_DATASIZE_PER_BUCKET 1024
135 /* Default module of hash table. */
136 #define DEFAULT_SUGGESTED_MODULE 211
139 /* Number of seconds between two cache pruning runs if we do not have
140 better information when it is really needed. */
141 #define CACHE_PRUNE_INTERVAL 15
144 /* Global variables. */
145 extern struct database_dyn dbs[lastdb] attribute_hidden;
146 extern const char *const dbnames[lastdb];
147 extern const char *const serv2str[LASTREQ];
149 extern const struct iovec pwd_iov_disabled;
150 extern const struct iovec grp_iov_disabled;
151 extern const struct iovec hst_iov_disabled;
152 extern const struct iovec serv_iov_disabled;
153 extern const struct iovec netgroup_iov_disabled;
156 /* Initial number of threads to run. */
157 extern int nthreads;
158 /* Maximum number of threads to use. */
159 extern int max_nthreads;
161 /* Inotify descriptor. */
162 extern int inotify_fd;
164 /* User name to run server processes as. */
165 extern const char *server_user;
167 /* Name and UID of user who is allowed to request statistics. */
168 extern const char *stat_user;
169 extern uid_t stat_uid;
171 /* Time the server was started. */
172 extern time_t start_time;
174 /* Number of times clients had to wait. */
175 extern unsigned long int client_queued;
177 /* Maximum needed alignment. */
178 extern const size_t block_align;
180 /* Number of times a value is reloaded without being used. UINT_MAX
181 means unlimited. */
182 extern unsigned int reload_count;
184 /* Pagesize minus one. */
185 extern uintptr_t pagesize_m1;
187 /* Nonzero if paranoia mode is enabled. */
188 extern int paranoia;
189 /* Time after which the process restarts. */
190 extern time_t restart_time;
191 /* How much time between restarts. */
192 extern time_t restart_interval;
193 /* Old current working directory. */
194 extern const char *oldcwd;
195 /* Old user and group ID. */
196 extern uid_t old_uid;
197 extern gid_t old_gid;
200 /* Prototypes for global functions. */
202 /* Wrapper functions with error checking for standard functions. */
203 extern void *xmalloc (size_t n)
204 __attribute_malloc__ __attribute_alloc_size (1);
205 extern void *xcalloc (size_t n, size_t s)
206 __attribute_malloc__ __attribute_alloc_size (1, 2);
207 extern void *xrealloc (void *o, size_t n)
208 __attribute_malloc__ __attribute_alloc_size (2);
210 /* nscd.c */
211 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
212 extern int nscd_open_socket (void);
214 /* connections.c */
215 extern void nscd_init (void);
216 extern void register_traced_file (size_t dbidx, struct traced_file *finfo);
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, const void *key,
230 size_t len, 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 time_t readdpwbyname (struct database_dyn *db, struct hashentry *he,
244 struct datahead *dh);
245 extern time_t 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 time_t readdgrbyname (struct database_dyn *db, struct hashentry *he,
254 struct datahead *dh);
255 extern time_t 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 time_t readdhstbyname (struct database_dyn *db, struct hashentry *he,
268 struct datahead *dh);
269 extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
270 struct datahead *dh);
271 extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
272 struct datahead *dh);
273 extern time_t 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 time_t 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 time_t 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 time_t 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 time_t readdservbyport (struct database_dyn *db, struct hashentry *he,
297 struct datahead *dh);
299 /* netgroupcache.c */
300 extern void addinnetgr (struct database_dyn *db, int fd, request_header *req,
301 void *key, uid_t uid);
302 extern time_t readdinnetgr (struct database_dyn *db, struct hashentry *he,
303 struct datahead *dh);
304 extern void addgetnetgrent (struct database_dyn *db, int fd,
305 request_header *req, void *key, uid_t uid);
306 extern time_t readdgetnetgrent (struct database_dyn *db, struct hashentry *he,
307 struct datahead *dh);
309 /* mem.c */
310 extern void *mempool_alloc (struct database_dyn *db, size_t len,
311 int data_alloc);
312 extern void gc (struct database_dyn *db);
315 /* nscd_setup_thread.c */
316 extern int setup_thread (struct database_dyn *db);
319 /* Special version of TEMP_FAILURE_RETRY for functions returning error
320 values. */
321 #define TEMP_FAILURE_RETRY_VAL(expression) \
322 (__extension__ \
323 ({ long int __result; \
324 do __result = (long int) (expression); \
325 while (__result == EINTR); \
326 __result; }))
328 #endif /* nscd.h */