]>
Commit | Line | Data |
---|---|---|
20e498bd | 1 | /* Copyright (c) 1998-2001, 2003-2008, 2009 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 AJ |
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. */ | |
d67281a7 UD |
19 | |
20 | #ifndef _NSCD_H | |
67479a70 UD |
21 | #define _NSCD_H 1 |
22 | ||
23 | #include <pthread.h> | |
a95a08b4 | 24 | #include <stdbool.h> |
67479a70 UD |
25 | #include <time.h> |
26 | #include <sys/uio.h> | |
d67281a7 | 27 | |
4f6bfa80 RM |
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" | |
67479a70 | 32 | |
d67281a7 | 33 | |
67479a70 UD |
34 | /* Handle databases. */ |
35 | typedef enum | |
36 | { | |
37 | pwddb, | |
38 | grpdb, | |
39 | hstdb, | |
b21fa963 | 40 | servdb, |
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 | |
a95a08b4 UD |
65 | /* Structure describing dynamic part of one database. */ |
66 | struct database_dyn | |
67479a70 UD |
67 | { |
68 | pthread_rwlock_t lock; | |
ffb1b882 UD |
69 | pthread_cond_t prune_cond; |
70 | pthread_mutex_t prune_lock; | |
cd72adeb | 71 | pthread_mutex_t prune_run_lock; |
ffb1b882 | 72 | time_t wakeup_time; |
67479a70 UD |
73 | |
74 | int enabled; | |
75 | int check_file; | |
5228ba2f UD |
76 | int inotify_descr; |
77 | int clear_cache; | |
a95a08b4 | 78 | int persistent; |
c207f23b | 79 | int shared; |
797ed6f7 | 80 | int propagate; |
b21fa963 UD |
81 | int reset_res; |
82 | const char filename[16]; | |
a95a08b4 | 83 | const char *db_filename; |
67479a70 | 84 | time_t file_mtime; |
a95a08b4 | 85 | size_t suggested_module; |
eaa27aca | 86 | size_t max_db_size; |
67479a70 | 87 | |
a95a08b4 UD |
88 | unsigned long int postimeout; /* In seconds. */ |
89 | unsigned long int negtimeout; /* In seconds. */ | |
67479a70 | 90 | |
a95a08b4 UD |
91 | int wr_fd; /* Writable file descriptor. */ |
92 | int ro_fd; /* Unwritable file descriptor. */ | |
67479a70 | 93 | |
a95a08b4 | 94 | const struct iovec *disabled_iov; |
67479a70 | 95 | |
a95a08b4 UD |
96 | struct database_pers_head *head; |
97 | char *data; | |
98 | size_t memsize; | |
99 | pthread_mutex_t memlock; | |
100 | bool mmap_used; | |
101 | bool last_alloc_failed; | |
102 | }; | |
c86e6aec | 103 | |
c86e6aec | 104 | |
a95a08b4 | 105 | /* Paths of the file for the persistent storage. */ |
457962e5 UD |
106 | #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd" |
107 | #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group" | |
108 | #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts" | |
b21fa963 | 109 | #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services" |
457962e5 UD |
110 | |
111 | /* Path used when not using persistent storage. */ | |
112 | #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX" | |
67479a70 | 113 | |
2c210d1e UD |
114 | /* Default value for the maximum size of the database files. */ |
115 | #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024) | |
116 | ||
117 | /* Number of bytes of data we initially reserve for each hash table bucket. */ | |
118 | #define DEFAULT_DATASIZE_PER_BUCKET 1024 | |
119 | ||
27c377dd UD |
120 | /* Default module of hash table. */ |
121 | #define DEFAULT_SUGGESTED_MODULE 211 | |
122 | ||
67479a70 | 123 | |
ffb1b882 UD |
124 | /* Number of seconds between two cache pruning runs if we do not have |
125 | better information when it is really needed. */ | |
126 | #define CACHE_PRUNE_INTERVAL 15 | |
127 | ||
128 | ||
67479a70 | 129 | /* Global variables. */ |
7eb5e6c9 | 130 | extern struct database_dyn dbs[lastdb] attribute_hidden; |
b21fa963 UD |
131 | extern const char *const dbnames[lastdb]; |
132 | extern const char *const serv2str[LASTREQ]; | |
67479a70 UD |
133 | |
134 | extern const struct iovec pwd_iov_disabled; | |
135 | extern const struct iovec grp_iov_disabled; | |
136 | extern const struct iovec hst_iov_disabled; | |
b21fa963 | 137 | extern const struct iovec serv_iov_disabled; |
67479a70 | 138 | |
a95a08b4 | 139 | |
27e82856 | 140 | /* Initial number of threads to run. */ |
67479a70 | 141 | extern int nthreads; |
27e82856 UD |
142 | /* Maximum number of threads to use. */ |
143 | extern int max_nthreads; | |
67479a70 | 144 | |
a12ce44f | 145 | /* User name to run server processes as. */ |
adcf0e4a UD |
146 | extern const char *server_user; |
147 | ||
a12ce44f UD |
148 | /* Name and UID of user who is allowed to request statistics. */ |
149 | extern const char *stat_user; | |
150 | extern uid_t stat_uid; | |
151 | ||
c86e6aec UD |
152 | /* Time the server was started. */ |
153 | extern time_t start_time; | |
154 | ||
a16e3585 UD |
155 | /* Number of times clients had to wait. */ |
156 | extern unsigned long int client_queued; | |
157 | ||
a95a08b4 UD |
158 | /* Maximum needed alignment. */ |
159 | extern const size_t block_align; | |
160 | ||
161 | /* Number of times a value is reloaded without being used. UINT_MAX | |
162 | means unlimited. */ | |
163 | extern unsigned int reload_count; | |
164 | ||
3418007e UD |
165 | /* Pagesize minus one. */ |
166 | extern uintptr_t pagesize_m1; | |
167 | ||
4401d759 UD |
168 | /* Nonzero if paranoia mode is enabled. */ |
169 | extern int paranoia; | |
170 | /* Time after which the process restarts. */ | |
171 | extern time_t restart_time; | |
172 | /* How much time between restarts. */ | |
173 | extern time_t restart_interval; | |
174 | /* Old current working directory. */ | |
175 | extern const char *oldcwd; | |
176 | /* Old user and group ID. */ | |
177 | extern uid_t old_uid; | |
178 | extern gid_t old_gid; | |
179 | ||
180 | ||
67479a70 UD |
181 | /* Prototypes for global functions. */ |
182 | ||
183 | /* nscd.c */ | |
59553897 | 184 | extern void termination_handler (int signum) __attribute__ ((__noreturn__)); |
67479a70 UD |
185 | extern int nscd_open_socket (void); |
186 | ||
187 | /* connections.c */ | |
a12ce44f | 188 | extern void nscd_init (void); |
67479a70 | 189 | extern void close_sockets (void); |
8f11d6f9 | 190 | extern void start_threads (void) __attribute__ ((__noreturn__)); |
67479a70 UD |
191 | |
192 | /* nscd_conf.c */ | |
a95a08b4 UD |
193 | extern int nscd_parse_file (const char *fname, |
194 | struct database_dyn dbs[lastdb]); | |
67479a70 UD |
195 | |
196 | /* nscd_stat.c */ | |
a95a08b4 | 197 | extern void send_stats (int fd, struct database_dyn dbs[lastdb]); |
59553897 | 198 | extern int receive_print_stats (void) __attribute__ ((__noreturn__)); |
67479a70 UD |
199 | |
200 | /* cache.c */ | |
a95a08b4 UD |
201 | extern struct datahead *cache_search (request_type, void *key, size_t len, |
202 | struct database_dyn *table, | |
203 | uid_t owner); | |
204 | extern int cache_add (int type, const void *key, size_t len, | |
205 | struct datahead *packet, bool first, | |
528741cb UD |
206 | struct database_dyn *table, uid_t owner, |
207 | bool prune_wakeup); | |
ffb1b882 | 208 | extern time_t prune_cache (struct database_dyn *table, time_t now, int fd); |
67479a70 UD |
209 | |
210 | /* pwdcache.c */ | |
a95a08b4 | 211 | extern void addpwbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 212 | void *key, uid_t uid); |
a95a08b4 | 213 | extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 214 | void *key, uid_t uid); |
a95a08b4 UD |
215 | extern void readdpwbyname (struct database_dyn *db, struct hashentry *he, |
216 | struct datahead *dh); | |
217 | extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he, | |
218 | struct datahead *dh); | |
67479a70 UD |
219 | |
220 | /* grpcache.c */ | |
a95a08b4 | 221 | extern void addgrbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 222 | void *key, uid_t uid); |
a95a08b4 | 223 | extern void addgrbygid (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 224 | void *key, uid_t uid); |
a95a08b4 UD |
225 | extern void readdgrbyname (struct database_dyn *db, struct hashentry *he, |
226 | struct datahead *dh); | |
227 | extern void readdgrbygid (struct database_dyn *db, struct hashentry *he, | |
228 | struct datahead *dh); | |
67479a70 UD |
229 | |
230 | /* hstcache.c */ | |
a95a08b4 | 231 | extern void addhstbyname (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 232 | void *key, uid_t uid); |
a95a08b4 | 233 | extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req, |
a1c542bf | 234 | void *key, uid_t uid); |
a95a08b4 UD |
235 | extern void addhstbynamev6 (struct database_dyn *db, int fd, |
236 | request_header *req, void *key, uid_t uid); | |
237 | extern void addhstbyaddrv6 (struct database_dyn *db, int fd, | |
238 | request_header *req, void *key, uid_t uid); | |
239 | extern void readdhstbyname (struct database_dyn *db, struct hashentry *he, | |
240 | struct datahead *dh); | |
241 | extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he, | |
242 | struct datahead *dh); | |
243 | extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he, | |
244 | struct datahead *dh); | |
245 | extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he, | |
246 | struct datahead *dh); | |
247 | ||
d19687d6 UD |
248 | /* aicache.c */ |
249 | extern void addhstai (struct database_dyn *db, int fd, request_header *req, | |
250 | void *key, uid_t uid); | |
251 | extern void readdhstai (struct database_dyn *db, struct hashentry *he, | |
252 | struct datahead *dh); | |
a95a08b4 | 253 | |
26235c7c UD |
254 | |
255 | /* initgrcache.c */ | |
256 | extern void addinitgroups (struct database_dyn *db, int fd, | |
257 | request_header *req, void *key, uid_t uid); | |
258 | extern void readdinitgroups (struct database_dyn *db, struct hashentry *he, | |
259 | struct datahead *dh); | |
260 | ||
b21fa963 UD |
261 | /* servicecache.c */ |
262 | extern void addservbyname (struct database_dyn *db, int fd, | |
263 | request_header *req, void *key, uid_t uid); | |
264 | extern void readdservbyname (struct database_dyn *db, struct hashentry *he, | |
265 | struct datahead *dh); | |
266 | extern void addservbyport (struct database_dyn *db, int fd, | |
267 | request_header *req, void *key, uid_t uid); | |
268 | extern void readdservbyport (struct database_dyn *db, struct hashentry *he, | |
269 | struct datahead *dh); | |
270 | ||
a95a08b4 | 271 | /* mem.c */ |
c52137d3 | 272 | extern void *mempool_alloc (struct database_dyn *db, size_t len, |
20e498bd | 273 | int data_alloc); |
a95a08b4 | 274 | extern void gc (struct database_dyn *db); |
4f6bfa80 | 275 | |
081fc592 UD |
276 | |
277 | /* nscd_setup_thread.c */ | |
ffb1b882 | 278 | extern int setup_thread (struct database_dyn *db); |
081fc592 | 279 | |
2c210d1e UD |
280 | |
281 | /* Special version of TEMP_FAILURE_RETRY for functions returning error | |
282 | values. */ | |
283 | #define TEMP_FAILURE_RETRY_VAL(expression) \ | |
284 | (__extension__ \ | |
285 | ({ long int __result; \ | |
286 | do __result = (long int) (expression); \ | |
287 | while (__result == EINTR); \ | |
288 | __result; })) | |
289 | ||
67479a70 | 290 | #endif /* nscd.h */ |