* locales/as_IN: Fix currency_symbol, abday for Sunday, abmon for
[glibc/pb-stable.git] / nscd / nscd.h
blobe8199b8009987c05aa49cf7f84be1cd325e8e521
1 /* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _NSCD_H
22 #define _NSCD_H 1
24 #include <pthread.h>
25 #include <stdbool.h>
26 #include <time.h>
27 #include <sys/uio.h>
29 /* The declarations for the request and response types are in the file
30 "nscd-client.h", which should contain everything needed by client
31 functions. */
32 #include "nscd-client.h"
35 /* Handle databases. */
36 typedef enum
38 pwddb,
39 grpdb,
40 hstdb,
41 servdb,
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 /* Structure describing dynamic part of one database. */
59 struct database_dyn
61 pthread_rwlock_t lock;
62 pthread_mutex_t prunelock;
64 int enabled;
65 int check_file;
66 int persistent;
67 int shared;
68 int propagate;
69 int reset_res;
70 const char filename[16];
71 const char *db_filename;
72 time_t file_mtime;
73 size_t suggested_module;
74 size_t max_db_size;
76 unsigned long int postimeout; /* In seconds. */
77 unsigned long int negtimeout; /* In seconds. */
79 int wr_fd; /* Writable file descriptor. */
80 int ro_fd; /* Unwritable file descriptor. */
82 const struct iovec *disabled_iov;
84 struct database_pers_head *head;
85 char *data;
86 size_t memsize;
87 pthread_mutex_t memlock;
88 bool mmap_used;
89 bool last_alloc_failed;
93 /* Paths of the file for the persistent storage. */
94 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
95 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
96 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
97 #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services"
99 /* Path used when not using persistent storage. */
100 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
102 /* Maximum alignment requirement we will encounter. */
103 #define BLOCK_ALIGN_LOG 3
104 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
105 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
107 /* Default value for the maximum size of the database files. */
108 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
110 /* Number of bytes of data we initially reserve for each hash table bucket. */
111 #define DEFAULT_DATASIZE_PER_BUCKET 1024
114 /* Global variables. */
115 extern struct database_dyn dbs[lastdb];
116 extern const char *const dbnames[lastdb];
117 extern const char *const serv2str[LASTREQ];
119 extern const struct iovec pwd_iov_disabled;
120 extern const struct iovec grp_iov_disabled;
121 extern const struct iovec hst_iov_disabled;
122 extern const struct iovec serv_iov_disabled;
125 /* Initial number of threads to run. */
126 extern int nthreads;
127 /* Maximum number of threads to use. */
128 extern int max_nthreads;
130 /* User name to run server processes as. */
131 extern const char *server_user;
133 /* Name and UID of user who is allowed to request statistics. */
134 extern const char *stat_user;
135 extern uid_t stat_uid;
137 /* Time the server was started. */
138 extern time_t start_time;
140 /* Number of times clients had to wait. */
141 extern unsigned long int client_queued;
143 /* Maximum needed alignment. */
144 extern const size_t block_align;
146 /* Number of times a value is reloaded without being used. UINT_MAX
147 means unlimited. */
148 extern unsigned int reload_count;
150 /* Pagesize minus one. */
151 extern uintptr_t pagesize_m1;
153 /* Nonzero if paranoia mode is enabled. */
154 extern int paranoia;
155 /* Time after which the process restarts. */
156 extern time_t restart_time;
157 /* How much time between restarts. */
158 extern time_t restart_interval;
159 /* Old current working directory. */
160 extern const char *oldcwd;
161 /* Old user and group ID. */
162 extern uid_t old_uid;
163 extern gid_t old_gid;
166 /* Prototypes for global functions. */
168 /* nscd.c */
169 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
170 extern int nscd_open_socket (void);
172 /* connections.c */
173 extern void nscd_init (void);
174 extern void close_sockets (void);
175 extern void start_threads (void) __attribute__ ((__noreturn__));
177 /* nscd_conf.c */
178 extern int nscd_parse_file (const char *fname,
179 struct database_dyn dbs[lastdb]);
181 /* nscd_stat.c */
182 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
183 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
185 /* cache.c */
186 extern struct datahead *cache_search (request_type, void *key, size_t len,
187 struct database_dyn *table,
188 uid_t owner);
189 extern int cache_add (int type, const void *key, size_t len,
190 struct datahead *packet, bool first,
191 struct database_dyn *table, uid_t owner);
192 extern void prune_cache (struct database_dyn *table, time_t now, int fd);
194 /* pwdcache.c */
195 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
196 void *key, uid_t uid);
197 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
198 void *key, uid_t uid);
199 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
200 struct datahead *dh);
201 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
202 struct datahead *dh);
204 /* grpcache.c */
205 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
206 void *key, uid_t uid);
207 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
208 void *key, uid_t uid);
209 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
210 struct datahead *dh);
211 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
212 struct datahead *dh);
214 /* hstcache.c */
215 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
216 void *key, uid_t uid);
217 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
218 void *key, uid_t uid);
219 extern void addhstbynamev6 (struct database_dyn *db, int fd,
220 request_header *req, void *key, uid_t uid);
221 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
222 request_header *req, void *key, uid_t uid);
223 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
224 struct datahead *dh);
225 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
226 struct datahead *dh);
227 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
228 struct datahead *dh);
229 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
230 struct datahead *dh);
232 /* aicache.c */
233 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
234 void *key, uid_t uid);
235 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
236 struct datahead *dh);
239 /* initgrcache.c */
240 extern void addinitgroups (struct database_dyn *db, int fd,
241 request_header *req, void *key, uid_t uid);
242 extern void readdinitgroups (struct database_dyn *db, struct hashentry *he,
243 struct datahead *dh);
245 /* servicecache.c */
246 extern void addservbyname (struct database_dyn *db, int fd,
247 request_header *req, void *key, uid_t uid);
248 extern void readdservbyname (struct database_dyn *db, struct hashentry *he,
249 struct datahead *dh);
250 extern void addservbyport (struct database_dyn *db, int fd,
251 request_header *req, void *key, uid_t uid);
252 extern void readdservbyport (struct database_dyn *db, struct hashentry *he,
253 struct datahead *dh);
255 /* mem.c */
256 extern void *mempool_alloc (struct database_dyn *db, size_t len);
257 extern void gc (struct database_dyn *db);
260 /* nscd_setup_thread.c */
261 extern void setup_thread (struct database_dyn *db);
264 /* Special version of TEMP_FAILURE_RETRY for functions returning error
265 values. */
266 #define TEMP_FAILURE_RETRY_VAL(expression) \
267 (__extension__ \
268 ({ long int __result; \
269 do __result = (long int) (expression); \
270 while (__result == EINTR); \
271 __result; }))
273 #endif /* nscd.h */