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