Fix grouping and reuse other locales in various locales
[glibc.git] / nscd / nscd.h
blobfdaf01bfbeab835cf8585e1b3a64ac21bf05bbf4
1 /* Copyright (c) 1998-2001, 2003-2009, 2011 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _NSCD_H
21 #define _NSCD_H 1
23 #include <pthread.h>
24 #include <stdbool.h>
25 #include <time.h>
26 #include <sys/uio.h>
28 /* The declarations for the request and response types are in the file
29 "nscd-client.h", which should contain everything needed by client
30 functions. */
31 #include "nscd-client.h"
34 /* Handle databases. */
35 typedef enum
37 pwddb,
38 grpdb,
39 hstdb,
40 servdb,
41 netgrdb,
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 /* Registered filename used to fill database. */
67 struct traced_file
69 time_t mtime;
70 struct traced_file *next;
71 int call_res_init;
72 int inotify_descr;
73 char fname[];
77 /* Structure describing dynamic part of one database. */
78 struct database_dyn
80 pthread_rwlock_t lock;
81 pthread_cond_t prune_cond;
82 pthread_mutex_t prune_lock;
83 pthread_mutex_t prune_run_lock;
84 time_t wakeup_time;
86 int enabled;
87 int check_file;
88 int clear_cache;
89 int persistent;
90 int shared;
91 int propagate;
92 struct traced_file *traced_files;
93 const char *db_filename;
94 time_t file_mtime;
95 size_t suggested_module;
96 size_t max_db_size;
98 unsigned long int postimeout; /* In seconds. */
99 unsigned long int negtimeout; /* In seconds. */
101 int wr_fd; /* Writable file descriptor. */
102 int ro_fd; /* Unwritable file descriptor. */
104 const struct iovec *disabled_iov;
106 struct database_pers_head *head;
107 char *data;
108 size_t memsize;
109 pthread_mutex_t memlock;
110 bool mmap_used;
111 bool last_alloc_failed;
115 /* Paths of the file for the persistent storage. */
116 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
117 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
118 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
119 #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services"
120 #define _PATH_NSCD_NETGROUP_DB "/var/db/nscd/netgroup"
122 /* Path used when not using persistent storage. */
123 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
125 /* Maximum alignment requirement we will encounter. */
126 #define BLOCK_ALIGN_LOG 3
127 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
128 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
130 /* Default value for the maximum size of the database files. */
131 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
133 /* Number of bytes of data we initially reserve for each hash table bucket. */
134 #define DEFAULT_DATASIZE_PER_BUCKET 1024
136 /* Default module of hash table. */
137 #define DEFAULT_SUGGESTED_MODULE 211
140 /* Number of seconds between two cache pruning runs if we do not have
141 better information when it is really needed. */
142 #define CACHE_PRUNE_INTERVAL 15
145 /* Global variables. */
146 extern struct database_dyn dbs[lastdb] attribute_hidden;
147 extern const char *const dbnames[lastdb];
148 extern const char *const serv2str[LASTREQ];
150 extern const struct iovec pwd_iov_disabled;
151 extern const struct iovec grp_iov_disabled;
152 extern const struct iovec hst_iov_disabled;
153 extern const struct iovec serv_iov_disabled;
154 extern const struct iovec netgroup_iov_disabled;
157 /* Initial number of threads to run. */
158 extern int nthreads;
159 /* Maximum number of threads to use. */
160 extern int max_nthreads;
162 /* Inotify descriptor. */
163 extern int inotify_fd;
165 /* User name to run server processes as. */
166 extern const char *server_user;
168 /* Name and UID of user who is allowed to request statistics. */
169 extern const char *stat_user;
170 extern uid_t stat_uid;
172 /* Time the server was started. */
173 extern time_t start_time;
175 /* Number of times clients had to wait. */
176 extern unsigned long int client_queued;
178 /* Maximum needed alignment. */
179 extern const size_t block_align;
181 /* Number of times a value is reloaded without being used. UINT_MAX
182 means unlimited. */
183 extern unsigned int reload_count;
185 /* Pagesize minus one. */
186 extern uintptr_t pagesize_m1;
188 /* Nonzero if paranoia mode is enabled. */
189 extern int paranoia;
190 /* Time after which the process restarts. */
191 extern time_t restart_time;
192 /* How much time between restarts. */
193 extern time_t restart_interval;
194 /* Old current working directory. */
195 extern const char *oldcwd;
196 /* Old user and group ID. */
197 extern uid_t old_uid;
198 extern gid_t old_gid;
201 /* Prototypes for global functions. */
203 /* Wrapper functions with error checking for standard functions. */
204 extern void *xmalloc (size_t n);
205 extern void *xcalloc (size_t n, size_t s);
206 extern void *xrealloc (void *o, size_t n);
208 /* nscd.c */
209 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
210 extern int nscd_open_socket (void);
212 /* connections.c */
213 extern void nscd_init (void);
214 extern void register_traced_file (size_t dbidx, struct traced_file *finfo);
215 extern void close_sockets (void);
216 extern void start_threads (void) __attribute__ ((__noreturn__));
218 /* nscd_conf.c */
219 extern int nscd_parse_file (const char *fname,
220 struct database_dyn dbs[lastdb]);
222 /* nscd_stat.c */
223 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
224 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
226 /* cache.c */
227 extern struct datahead *cache_search (request_type, const void *key,
228 size_t len, struct database_dyn *table,
229 uid_t owner);
230 extern int cache_add (int type, const void *key, size_t len,
231 struct datahead *packet, bool first,
232 struct database_dyn *table, uid_t owner,
233 bool prune_wakeup);
234 extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
236 /* pwdcache.c */
237 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
238 void *key, uid_t uid);
239 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
240 void *key, uid_t uid);
241 extern time_t readdpwbyname (struct database_dyn *db, struct hashentry *he,
242 struct datahead *dh);
243 extern time_t readdpwbyuid (struct database_dyn *db, struct hashentry *he,
244 struct datahead *dh);
246 /* grpcache.c */
247 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
248 void *key, uid_t uid);
249 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
250 void *key, uid_t uid);
251 extern time_t readdgrbyname (struct database_dyn *db, struct hashentry *he,
252 struct datahead *dh);
253 extern time_t readdgrbygid (struct database_dyn *db, struct hashentry *he,
254 struct datahead *dh);
256 /* hstcache.c */
257 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
258 void *key, uid_t uid);
259 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
260 void *key, uid_t uid);
261 extern void addhstbynamev6 (struct database_dyn *db, int fd,
262 request_header *req, void *key, uid_t uid);
263 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
264 request_header *req, void *key, uid_t uid);
265 extern time_t readdhstbyname (struct database_dyn *db, struct hashentry *he,
266 struct datahead *dh);
267 extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
268 struct datahead *dh);
269 extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
270 struct datahead *dh);
271 extern time_t readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
272 struct datahead *dh);
274 /* aicache.c */
275 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
276 void *key, uid_t uid);
277 extern time_t readdhstai (struct database_dyn *db, struct hashentry *he,
278 struct datahead *dh);
281 /* initgrcache.c */
282 extern void addinitgroups (struct database_dyn *db, int fd,
283 request_header *req, void *key, uid_t uid);
284 extern time_t readdinitgroups (struct database_dyn *db, struct hashentry *he,
285 struct datahead *dh);
287 /* servicecache.c */
288 extern void addservbyname (struct database_dyn *db, int fd,
289 request_header *req, void *key, uid_t uid);
290 extern time_t readdservbyname (struct database_dyn *db, struct hashentry *he,
291 struct datahead *dh);
292 extern void addservbyport (struct database_dyn *db, int fd,
293 request_header *req, void *key, uid_t uid);
294 extern time_t readdservbyport (struct database_dyn *db, struct hashentry *he,
295 struct datahead *dh);
297 /* netgroupcache.c */
298 extern void addinnetgr (struct database_dyn *db, int fd, request_header *req,
299 void *key, uid_t uid);
300 extern time_t readdinnetgr (struct database_dyn *db, struct hashentry *he,
301 struct datahead *dh);
302 extern void addgetnetgrent (struct database_dyn *db, int fd,
303 request_header *req, void *key, uid_t uid);
304 extern time_t readdgetnetgrent (struct database_dyn *db, struct hashentry *he,
305 struct datahead *dh);
307 /* mem.c */
308 extern void *mempool_alloc (struct database_dyn *db, size_t len,
309 int data_alloc);
310 extern void gc (struct database_dyn *db);
313 /* nscd_setup_thread.c */
314 extern int setup_thread (struct database_dyn *db);
317 /* Special version of TEMP_FAILURE_RETRY for functions returning error
318 values. */
319 #define TEMP_FAILURE_RETRY_VAL(expression) \
320 (__extension__ \
321 ({ long int __result; \
322 do __result = (long int) (expression); \
323 while (__result == EINTR); \
324 __result; }))
326 #endif /* nscd.h */