* include/rpc/pmap_prot.h: Mark all functions as hidden.
[glibc.git] / nscd / nscd.h
blob8b95630807c4b3de5c0be8419b471599b313e4b6
1 /* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006
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 lastdb
42 } dbtype;
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
53 /* Time before restarting the process in paranoia mode. */
54 #define RESTART_INTERVAL (60 * 60)
57 /* Structure describing dynamic part of one database. */
58 struct database_dyn
60 pthread_rwlock_t lock;
62 int enabled;
63 int check_file;
64 int persistent;
65 int shared;
66 int propagate;
67 const char filename[12];
68 const char *db_filename;
69 time_t file_mtime;
70 size_t suggested_module;
71 size_t max_db_size;
73 unsigned long int postimeout; /* In seconds. */
74 unsigned long int negtimeout; /* In seconds. */
76 int wr_fd; /* Writable file descriptor. */
77 int ro_fd; /* Unwritable file descriptor. */
79 const struct iovec *disabled_iov;
81 struct database_pers_head *head;
82 char *data;
83 size_t memsize;
84 pthread_mutex_t memlock;
85 bool mmap_used;
86 bool last_alloc_failed;
90 /* Paths of the file for the persistent storage. */
91 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
92 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
93 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
95 /* Path used when not using persistent storage. */
96 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
98 /* Maximum alignment requirement we will encounter. */
99 #define BLOCK_ALIGN_LOG 3
100 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
101 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
103 /* Default value for the maximum size of the database files. */
104 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
106 /* Number of bytes of data we initially reserve for each hash table bucket. */
107 #define DEFAULT_DATASIZE_PER_BUCKET 1024
110 /* Global variables. */
111 extern struct database_dyn dbs[lastdb];
112 extern const char *dbnames[lastdb];
113 extern const char *serv2str[LASTREQ];
115 extern const struct iovec pwd_iov_disabled;
116 extern const struct iovec grp_iov_disabled;
117 extern const struct iovec hst_iov_disabled;
120 /* Initial number of threads to run. */
121 extern int nthreads;
122 /* Maximum number of threads to use. */
123 extern int max_nthreads;
125 /* User name to run server processes as. */
126 extern const char *server_user;
128 /* Name and UID of user who is allowed to request statistics. */
129 extern const char *stat_user;
130 extern uid_t stat_uid;
132 /* Time the server was started. */
133 extern time_t start_time;
135 /* Number of times clients had to wait. */
136 extern unsigned long int client_queued;
138 /* Maximum needed alignment. */
139 extern const size_t block_align;
141 /* Number of times a value is reloaded without being used. UINT_MAX
142 means unlimited. */
143 extern unsigned int reload_count;
145 /* Pagesize minus one. */
146 extern uintptr_t pagesize_m1;
148 /* Nonzero if paranoia mode is enabled. */
149 extern int paranoia;
150 /* Time after which the process restarts. */
151 extern time_t restart_time;
152 /* How much time between restarts. */
153 extern time_t restart_interval;
154 /* Old current working directory. */
155 extern const char *oldcwd;
156 /* Old user and group ID. */
157 extern uid_t old_uid;
158 extern gid_t old_gid;
161 /* Prototypes for global functions. */
163 /* nscd.c */
164 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
165 extern int nscd_open_socket (void);
167 /* connections.c */
168 extern void nscd_init (void);
169 extern void close_sockets (void);
170 extern void start_threads (void) __attribute__ ((__noreturn__));
172 /* nscd_conf.c */
173 extern int nscd_parse_file (const char *fname,
174 struct database_dyn dbs[lastdb]);
176 /* nscd_stat.c */
177 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
178 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
180 /* cache.c */
181 extern struct datahead *cache_search (request_type, void *key, size_t len,
182 struct database_dyn *table,
183 uid_t owner);
184 extern int cache_add (int type, const void *key, size_t len,
185 struct datahead *packet, bool first,
186 struct database_dyn *table, uid_t owner);
187 extern void prune_cache (struct database_dyn *table, time_t now);
189 /* pwdcache.c */
190 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
191 void *key, uid_t uid);
192 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
193 void *key, uid_t uid);
194 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
195 struct datahead *dh);
196 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
197 struct datahead *dh);
199 /* grpcache.c */
200 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
201 void *key, uid_t uid);
202 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
203 void *key, uid_t uid);
204 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
205 struct datahead *dh);
206 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
207 struct datahead *dh);
209 /* hstcache.c */
210 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
211 void *key, uid_t uid);
212 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
213 void *key, uid_t uid);
214 extern void addhstbynamev6 (struct database_dyn *db, int fd,
215 request_header *req, void *key, uid_t uid);
216 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
217 request_header *req, void *key, uid_t uid);
218 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
219 struct datahead *dh);
220 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
221 struct datahead *dh);
222 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
223 struct datahead *dh);
224 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
225 struct datahead *dh);
227 /* aicache.c */
228 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
229 void *key, uid_t uid);
230 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
231 struct datahead *dh);
234 /* initgrcache.c */
235 extern void addinitgroups (struct database_dyn *db, int fd,
236 request_header *req, void *key, uid_t uid);
237 extern void readdinitgroups (struct database_dyn *db, struct hashentry *he,
238 struct datahead *dh);
240 /* mem.c */
241 extern void *mempool_alloc (struct database_dyn *db, size_t len);
242 extern void gc (struct database_dyn *db);
245 /* nscd_setup_thread.c */
246 extern void setup_thread (struct database_dyn *db);
249 /* Special version of TEMP_FAILURE_RETRY for functions returning error
250 values. */
251 #define TEMP_FAILURE_RETRY_VAL(expression) \
252 (__extension__ \
253 ({ long int __result; \
254 do __result = (long int) (expression); \
255 while (__result == EINTR); \
256 __result; }))
258 #endif /* nscd.h */