]> git.ipfire.org Git - thirdparty/glibc.git/blob - nscd/nscd.h
Generalize framework to register monitoring of files in nscd
[thirdparty/glibc.git] / nscd / nscd.h
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.
4
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.
9
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.
14
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. */
19
20 #ifndef _NSCD_H
21 #define _NSCD_H 1
22
23 #include <pthread.h>
24 #include <stdbool.h>
25 #include <time.h>
26 #include <sys/uio.h>
27
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"
32
33
34 /* Handle databases. */
35 typedef enum
36 {
37 pwddb,
38 grpdb,
39 hstdb,
40 servdb,
41 lastdb
42 } dbtype;
43
44
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
51
52
53 /* Time before restarting the process in paranoia mode. */
54 #define RESTART_INTERVAL (60 * 60)
55
56
57 /* Stack size for worker threads. */
58 #define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
59
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)
63
64
65 /* Registered filename used to fill database. */
66 struct traced_file
67 {
68 time_t mtime;
69 struct traced_file *next;
70 int call_res_init;
71 int inotify_descr;
72 char fname[];
73 };
74
75
76 /* Structure describing dynamic part of one database. */
77 struct database_dyn
78 {
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;
84
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;
96
97 unsigned long int postimeout; /* In seconds. */
98 unsigned long int negtimeout; /* In seconds. */
99
100 int wr_fd; /* Writable file descriptor. */
101 int ro_fd; /* Unwritable file descriptor. */
102
103 const struct iovec *disabled_iov;
104
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;
111 };
112
113
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
120 /* Path used when not using persistent storage. */
121 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
122
123 /* Maximum alignment requirement we will encounter. */
124 #define BLOCK_ALIGN_LOG 3
125 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
126 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
127
128 /* Default value for the maximum size of the database files. */
129 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
130
131 /* Number of bytes of data we initially reserve for each hash table bucket. */
132 #define DEFAULT_DATASIZE_PER_BUCKET 1024
133
134 /* Default module of hash table. */
135 #define DEFAULT_SUGGESTED_MODULE 211
136
137
138 /* Number of seconds between two cache pruning runs if we do not have
139 better information when it is really needed. */
140 #define CACHE_PRUNE_INTERVAL 15
141
142
143 /* Global variables. */
144 extern struct database_dyn dbs[lastdb] attribute_hidden;
145 extern const char *const dbnames[lastdb];
146 extern const char *const serv2str[LASTREQ];
147
148 extern const struct iovec pwd_iov_disabled;
149 extern const struct iovec grp_iov_disabled;
150 extern const struct iovec hst_iov_disabled;
151 extern const struct iovec serv_iov_disabled;
152
153
154 /* Initial number of threads to run. */
155 extern int nthreads;
156 /* Maximum number of threads to use. */
157 extern int max_nthreads;
158
159 /* Inotify descriptor. */
160 extern int inotify_fd;
161
162 /* User name to run server processes as. */
163 extern const char *server_user;
164
165 /* Name and UID of user who is allowed to request statistics. */
166 extern const char *stat_user;
167 extern uid_t stat_uid;
168
169 /* Time the server was started. */
170 extern time_t start_time;
171
172 /* Number of times clients had to wait. */
173 extern unsigned long int client_queued;
174
175 /* Maximum needed alignment. */
176 extern const size_t block_align;
177
178 /* Number of times a value is reloaded without being used. UINT_MAX
179 means unlimited. */
180 extern unsigned int reload_count;
181
182 /* Pagesize minus one. */
183 extern uintptr_t pagesize_m1;
184
185 /* Nonzero if paranoia mode is enabled. */
186 extern int paranoia;
187 /* Time after which the process restarts. */
188 extern time_t restart_time;
189 /* How much time between restarts. */
190 extern time_t restart_interval;
191 /* Old current working directory. */
192 extern const char *oldcwd;
193 /* Old user and group ID. */
194 extern uid_t old_uid;
195 extern gid_t old_gid;
196
197
198 /* Prototypes for global functions. */
199
200 /* nscd.c */
201 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
202 extern int nscd_open_socket (void);
203
204 /* connections.c */
205 extern void nscd_init (void);
206 extern void register_traced_file (size_t dbidx, struct traced_file *finfo);
207 extern void close_sockets (void);
208 extern void start_threads (void) __attribute__ ((__noreturn__));
209
210 /* nscd_conf.c */
211 extern int nscd_parse_file (const char *fname,
212 struct database_dyn dbs[lastdb]);
213
214 /* nscd_stat.c */
215 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
216 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
217
218 /* cache.c */
219 extern struct datahead *cache_search (request_type, void *key, size_t len,
220 struct database_dyn *table,
221 uid_t owner);
222 extern int cache_add (int type, const void *key, size_t len,
223 struct datahead *packet, bool first,
224 struct database_dyn *table, uid_t owner,
225 bool prune_wakeup);
226 extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
227
228 /* pwdcache.c */
229 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
230 void *key, uid_t uid);
231 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
232 void *key, uid_t uid);
233 extern time_t readdpwbyname (struct database_dyn *db, struct hashentry *he,
234 struct datahead *dh);
235 extern time_t readdpwbyuid (struct database_dyn *db, struct hashentry *he,
236 struct datahead *dh);
237
238 /* grpcache.c */
239 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
240 void *key, uid_t uid);
241 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
242 void *key, uid_t uid);
243 extern time_t readdgrbyname (struct database_dyn *db, struct hashentry *he,
244 struct datahead *dh);
245 extern time_t readdgrbygid (struct database_dyn *db, struct hashentry *he,
246 struct datahead *dh);
247
248 /* hstcache.c */
249 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
250 void *key, uid_t uid);
251 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
252 void *key, uid_t uid);
253 extern void addhstbynamev6 (struct database_dyn *db, int fd,
254 request_header *req, void *key, uid_t uid);
255 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
256 request_header *req, void *key, uid_t uid);
257 extern time_t readdhstbyname (struct database_dyn *db, struct hashentry *he,
258 struct datahead *dh);
259 extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
260 struct datahead *dh);
261 extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
262 struct datahead *dh);
263 extern time_t readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
264 struct datahead *dh);
265
266 /* aicache.c */
267 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
268 void *key, uid_t uid);
269 extern time_t readdhstai (struct database_dyn *db, struct hashentry *he,
270 struct datahead *dh);
271
272
273 /* initgrcache.c */
274 extern void addinitgroups (struct database_dyn *db, int fd,
275 request_header *req, void *key, uid_t uid);
276 extern time_t readdinitgroups (struct database_dyn *db, struct hashentry *he,
277 struct datahead *dh);
278
279 /* servicecache.c */
280 extern void addservbyname (struct database_dyn *db, int fd,
281 request_header *req, void *key, uid_t uid);
282 extern time_t readdservbyname (struct database_dyn *db, struct hashentry *he,
283 struct datahead *dh);
284 extern void addservbyport (struct database_dyn *db, int fd,
285 request_header *req, void *key, uid_t uid);
286 extern time_t readdservbyport (struct database_dyn *db, struct hashentry *he,
287 struct datahead *dh);
288
289 /* mem.c */
290 extern void *mempool_alloc (struct database_dyn *db, size_t len,
291 int data_alloc);
292 extern void gc (struct database_dyn *db);
293
294
295 /* nscd_setup_thread.c */
296 extern int setup_thread (struct database_dyn *db);
297
298
299 /* Special version of TEMP_FAILURE_RETRY for functions returning error
300 values. */
301 #define TEMP_FAILURE_RETRY_VAL(expression) \
302 (__extension__ \
303 ({ long int __result; \
304 do __result = (long int) (expression); \
305 while (__result == EINTR); \
306 __result; }))
307
308 #endif /* nscd.h */