]>
Commit | Line | Data |
---|---|---|
d4697bc9 | 1 | /* Copyright (c) 1998-2014 Free Software Foundation, Inc. |
d67281a7 | 2 | This file is part of the GNU C Library. |
a1c542bf | 3 | Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998. |
d67281a7 UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
d67281a7 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
d67281a7 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
d67281a7 UD |
18 | |
19 | #ifndef _NSCD_H | |
67479a70 UD |
20 | #define _NSCD_H 1 |
21 | ||
22 | #include <pthread.h> | |
a95a08b4 | 23 | #include <stdbool.h> |
67479a70 UD |
24 | #include <time.h> |
25 | #include <sys/uio.h> | |
d67281a7 | 26 | |
4f6bfa80 RM |
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" | |
67479a70 | 31 | |
d67281a7 | 32 | |
67479a70 UD |
33 | /* Handle databases. */ |
34 | typedef enum | |
35 | { | |
36 | pwddb, | |
37 | grpdb, | |
38 | hstdb, | |
b21fa963 | 39 | servdb, |
684ae515 | 40 | netgrdb, |
67479a70 UD |
41 | lastdb |
42 | } dbtype; | |
d67281a7 | 43 | |
67479a70 | 44 | |
a95a08b4 UD |
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 | ||
4401d759 UD |
53 | /* Time before restarting the process in paranoia mode. */ |
54 | #define RESTART_INTERVAL (60 * 60) | |
55 | ||
56 | ||
7ea8eb02 UD |
57 | /* Stack size for worker threads. */ |
58 | #define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4) | |
59 | ||
30294ea4 UD |
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 | ||
7ea8eb02 | 64 | |
319b9ad4 UD |
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 | ||
a95a08b4 UD |
76 | /* Structure describing dynamic part of one database. */ |
77 | struct database_dyn | |
67479a70 UD |
78 | { |
79 | pthread_rwlock_t lock; | |
ffb1b882 UD |
80 | pthread_cond_t prune_cond; |
81 | pthread_mutex_t prune_lock; | |
cd72adeb | 82 | pthread_mutex_t prune_run_lock; |
ffb1b882 | 83 | time_t wakeup_time; |
67479a70 UD |
84 | |
85 | int enabled; | |
86 | int check_file; | |
5228ba2f | 87 | int clear_cache; |
a95a08b4 | 88 | int persistent; |
c207f23b | 89 | int shared; |
797ed6f7 | 90 | int propagate; |
319b9ad4 | 91 | struct traced_file *traced_files; |
a95a08b4 | 92 | const char *db_filename; |
67479a70 | 93 | time_t file_mtime; |
a95a08b4 | 94 | size_t suggested_module; |
eaa27aca | 95 | size_t max_db_size; |
67479a70 | 96 | |
a95a08b4 UD |
97 | unsigned long int postimeout; /* In seconds. */ |
98 | unsigned long int negtimeout; /* In seconds. */ | |
67479a70 | 99 | |
a95a08b4 UD |
100 | int wr_fd; /* Writable file descriptor. */ |
101 | int ro_fd; /* Unwritable file descriptor. */ | |
67479a70 | 102 | |
a95a08b4 | 103 | const struct iovec *disabled_iov; |
67479a70 | 104 | |
a95a08b4 UD |
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 | }; | |
c86e6aec | 112 | |
c86e6aec | 113 | |
a95a08b4 | 114 | /* Paths of the file for the persistent storage. */ |
67881f5e AS |
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" | |
457962e5 UD |
120 | |
121 | /* Path used when not using persistent storage. */ | |
122 | #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX" | |
67479a70 | 123 | |
fa546abe UD |
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) | |
128 | ||
2c210d1e UD |
129 | /* Default value for the maximum size of the database files. */ |
130 | #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024) | |
131 | ||
132 | /* Number of bytes of data we initially reserve for each hash table bucket. */ | |
133 | #define DEFAULT_DATASIZE_PER_BUCKET 1024 | |
134 | ||
27c377dd UD |
135 | /* Default module of hash table. */ |
136 | #define DEFAULT_SUGGESTED_MODULE 211 | |
137 | ||
67479a70 | 138 | |
ffb1b882 UD |
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 | |
142 | ||
143 | ||
67479a70 | 144 | /* Global variables. */ |
7eb5e6c9 | 145 | extern struct database_dyn dbs[lastdb] attribute_hidden; |
b21fa963 UD |
146 | extern const char *const dbnames[lastdb]; |
147 | extern const char *const serv2str[LASTREQ]; | |
67479a70 UD |
148 | |
149 | extern const struct iovec pwd_iov_disabled; | |
150 | extern const struct iovec grp_iov_disabled; | |
151 | extern const struct iovec hst_iov_disabled; | |
b21fa963 | 152 | extern const struct iovec serv_iov_disabled; |
684ae515 | 153 | extern const struct iovec netgroup_iov_disabled; |
67479a70 | 154 | |
a95a08b4 | 155 | |
27e82856 | 156 | /* Initial number of threads to run. */ |
67479a70 | 157 | extern int nthreads; |
27e82856 UD |
158 | /* Maximum number of threads to use. */ |
159 | extern int max_nthreads; | |
67479a70 | 160 | |
319b9ad4 UD |
161 | /* Inotify descriptor. */ |
162 | extern int inotify_fd; | |
163 | ||
a12ce44f | 164 | /* User name to run server processes as. */ |
adcf0e4a UD |
165 | extern const char *server_user; |
166 | ||
a12ce44f UD |
167 | /* Name and UID of user who is allowed to request statistics. */ |
168 | extern const char *stat_user; | |
169 | extern uid_t stat_uid; | |
170 | ||
c86e6aec UD |
171 | /* Time the server was started. */ |
172 | extern time_t start_time; | |
173 | ||
a16e3585 UD |
174 | /* Number of times clients had to wait. */ |
175 | extern unsigned long int client_queued; | |
176 | ||
a95a08b4 UD |
177 | /* Maximum needed alignment. */ |
178 | extern const size_t block_align; | |
179 | ||
180 | /* Number of times a value is reloaded without being used. UINT_MAX | |
181 | means unlimited. */ | |
182 | extern unsigned int reload_count; | |
183 | ||
3418007e UD |
184 | /* Pagesize minus one. */ |
185 | extern uintptr_t pagesize_m1; | |
186 | ||
4401d759 UD |
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; | |
198 | ||
199 | ||
67479a70 UD |
200 | /* Prototypes for global functions. */ |
201 | ||
684ae515 | 202 | /* Wrapper functions with error checking for standard functions. */ |
6ff444c4 | 203 | #include <programs/xmalloc.h> |
684ae515 | 204 | |
67479a70 | 205 | /* nscd.c */ |
59553897 | 206 | extern void termination_handler (int signum) __attribute__ ((__noreturn__)); |
67479a70 | 207 | extern int nscd_open_socket (void); |
532a6035 SP |
208 | void notify_parent (int child_ret); |
209 | void do_exit (int child_ret, int errnum, const char *format, ...); | |
67479a70 UD |
210 | |
211 | /* connections.c */ | |
a12ce44f | 212 | extern void nscd_init (void); |
319b9ad4 | 213 | extern void register_traced_file (size_t dbidx, struct traced_file *finfo); |
67479a70 | 214 | extern void close_sockets (void); |
8f11d6f9 | 215 | extern void start_threads (void) __attribute__ ((__noreturn__)); |
67479a70 UD |
216 | |
217 | /* nscd_conf.c */ | |
a95a08b4 UD |
218 | extern int nscd_parse_file (const char *fname, |
219 | struct database_dyn dbs[lastdb]); | |
67479a70 UD |
220 | |
221 | /* nscd_stat.c */ | |
a95a08b4 | 222 | extern void send_stats (int fd, struct database_dyn dbs[lastdb]); |
59553897 | 223 | extern int receive_print_stats (void) __attribute__ ((__noreturn__)); |
67479a70 UD |
224 | |
225 | /* cache.c */ | |
684ae515 UD |
226 | extern struct datahead *cache_search (request_type, const void *key, |
227 | size_t len, struct database_dyn *table, | |
a95a08b4 UD |
228 | uid_t owner); |
229 | extern int cache_add (int type, const void *key, size_t len, | |
230 | struct datahead *packet, bool first, | |
528741cb UD |
231 | struct database_dyn *table, uid_t owner, |
232 | bool prune_wakeup); | |
ffb1b882 | 233 | extern time_t prune_cache (struct database_dyn *table, time_t now, int fd); |
67479a70 UD |
234 | |
235 | /* pwdcache.c */ | |
a95a08b4 | 236 | extern void addpwbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 237 | void *key, uid_t uid); |
a95a08b4 | 238 | extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 239 | void *key, uid_t uid); |
a4c7ea7b UD |
240 | extern time_t readdpwbyname (struct database_dyn *db, struct hashentry *he, |
241 | struct datahead *dh); | |
242 | extern time_t readdpwbyuid (struct database_dyn *db, struct hashentry *he, | |
243 | struct datahead *dh); | |
67479a70 UD |
244 | |
245 | /* grpcache.c */ | |
a95a08b4 | 246 | extern void addgrbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 247 | void *key, uid_t uid); |
a95a08b4 | 248 | extern void addgrbygid (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 249 | void *key, uid_t uid); |
a4c7ea7b UD |
250 | extern time_t readdgrbyname (struct database_dyn *db, struct hashentry *he, |
251 | struct datahead *dh); | |
252 | extern time_t readdgrbygid (struct database_dyn *db, struct hashentry *he, | |
253 | struct datahead *dh); | |
67479a70 UD |
254 | |
255 | /* hstcache.c */ | |
a95a08b4 | 256 | extern void addhstbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 257 | void *key, uid_t uid); |
a95a08b4 | 258 | extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 259 | void *key, uid_t uid); |
a95a08b4 UD |
260 | extern void addhstbynamev6 (struct database_dyn *db, int fd, |
261 | request_header *req, void *key, uid_t uid); | |
262 | extern void addhstbyaddrv6 (struct database_dyn *db, int fd, | |
263 | request_header *req, void *key, uid_t uid); | |
a4c7ea7b | 264 | extern time_t readdhstbyname (struct database_dyn *db, struct hashentry *he, |
a95a08b4 | 265 | struct datahead *dh); |
a4c7ea7b | 266 | extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he, |
a95a08b4 | 267 | struct datahead *dh); |
a4c7ea7b UD |
268 | extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he, |
269 | struct datahead *dh); | |
270 | extern time_t readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he, | |
271 | struct datahead *dh); | |
a95a08b4 | 272 | |
d19687d6 UD |
273 | /* aicache.c */ |
274 | extern void addhstai (struct database_dyn *db, int fd, request_header *req, | |
275 | void *key, uid_t uid); | |
a4c7ea7b UD |
276 | extern time_t readdhstai (struct database_dyn *db, struct hashentry *he, |
277 | struct datahead *dh); | |
a95a08b4 | 278 | |
26235c7c UD |
279 | |
280 | /* initgrcache.c */ | |
281 | extern void addinitgroups (struct database_dyn *db, int fd, | |
282 | request_header *req, void *key, uid_t uid); | |
a4c7ea7b UD |
283 | extern time_t readdinitgroups (struct database_dyn *db, struct hashentry *he, |
284 | struct datahead *dh); | |
26235c7c | 285 | |
b21fa963 UD |
286 | /* servicecache.c */ |
287 | extern void addservbyname (struct database_dyn *db, int fd, | |
288 | request_header *req, void *key, uid_t uid); | |
a4c7ea7b UD |
289 | extern time_t readdservbyname (struct database_dyn *db, struct hashentry *he, |
290 | struct datahead *dh); | |
b21fa963 UD |
291 | extern void addservbyport (struct database_dyn *db, int fd, |
292 | request_header *req, void *key, uid_t uid); | |
a4c7ea7b UD |
293 | extern time_t readdservbyport (struct database_dyn *db, struct hashentry *he, |
294 | struct datahead *dh); | |
b21fa963 | 295 | |
684ae515 UD |
296 | /* netgroupcache.c */ |
297 | extern void addinnetgr (struct database_dyn *db, int fd, request_header *req, | |
298 | void *key, uid_t uid); | |
299 | extern time_t readdinnetgr (struct database_dyn *db, struct hashentry *he, | |
300 | struct datahead *dh); | |
301 | extern void addgetnetgrent (struct database_dyn *db, int fd, | |
302 | request_header *req, void *key, uid_t uid); | |
303 | extern time_t readdgetnetgrent (struct database_dyn *db, struct hashentry *he, | |
304 | struct datahead *dh); | |
305 | ||
a95a08b4 | 306 | /* mem.c */ |
c52137d3 | 307 | extern void *mempool_alloc (struct database_dyn *db, size_t len, |
20e498bd | 308 | int data_alloc); |
a95a08b4 | 309 | extern void gc (struct database_dyn *db); |
4f6bfa80 | 310 | |
081fc592 UD |
311 | |
312 | /* nscd_setup_thread.c */ | |
ffb1b882 | 313 | extern int setup_thread (struct database_dyn *db); |
081fc592 | 314 | |
2c210d1e UD |
315 | |
316 | /* Special version of TEMP_FAILURE_RETRY for functions returning error | |
317 | values. */ | |
318 | #define TEMP_FAILURE_RETRY_VAL(expression) \ | |
319 | (__extension__ \ | |
320 | ({ long int __result; \ | |
321 | do __result = (long int) (expression); \ | |
322 | while (__result == EINTR); \ | |
323 | __result; })) | |
324 | ||
67479a70 | 325 | #endif /* nscd.h */ |