Updated to fedora-glibc-20040929T0821
[glibc.git] / nscd / nscd.h
blob01c8ca11e0b0edf394eb29598bf1ebc660c53992
1 /* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004
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 /* Structure describing dynamic part of one database. */
54 struct database_dyn
56 pthread_rwlock_t lock;
58 int enabled;
59 int check_file;
60 int persistent;
61 int shared;
62 const char *filename;
63 const char *db_filename;
64 time_t file_mtime;
65 size_t suggested_module;
66 int secure;
68 unsigned long int postimeout; /* In seconds. */
69 unsigned long int negtimeout; /* In seconds. */
71 int wr_fd; /* Writable file descriptor. */
72 int ro_fd; /* Unwritable file descriptor. */
74 const struct iovec *disabled_iov;
76 struct database_pers_head *head;
77 char *data;
78 size_t memsize;
79 pthread_mutex_t memlock;
80 bool mmap_used;
81 bool last_alloc_failed;
85 /* Paths of the file for the persistent storage. */
86 #define _PATH_NSCD_PASSWD_DB "/var/run/nscd/passwd"
87 #define _PATH_NSCD_GROUP_DB "/var/run/nscd/group"
88 #define _PATH_NSCD_HOSTS_DB "/var/run/nscd/hosts"
91 /* Global variables. */
92 extern struct database_dyn dbs[lastdb];
93 extern const char *dbnames[lastdb];
94 extern const char *serv2str[LASTREQ];
96 extern const struct iovec pwd_iov_disabled;
97 extern const struct iovec grp_iov_disabled;
98 extern const struct iovec hst_iov_disabled;
101 /* Number of threads to run. */
102 extern int nthreads;
104 /* Tables for which we cache data with uid. */
105 extern int secure_in_use; /* Is one of the above 1? */
107 /* User name to run server processes as. */
108 extern const char *server_user;
110 /* Name and UID of user who is allowed to request statistics. */
111 extern const char *stat_user;
112 extern uid_t stat_uid;
114 /* Time the server was started. */
115 extern time_t start_time;
117 /* Number of times clients had to wait. */
118 extern unsigned long int client_queued;
120 /* Maximum needed alignment. */
121 extern const size_t block_align;
123 /* Number of times a value is reloaded without being used. UINT_MAX
124 means unlimited. */
125 extern unsigned int reload_count;
127 /* Pagesize minus one. */
128 extern uintptr_t pagesize_m1;
130 /* Prototypes for global functions. */
132 /* nscd.c */
133 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
134 extern int nscd_open_socket (void);
136 /* connections.c */
137 extern void nscd_init (void);
138 extern void close_sockets (void);
139 extern void start_threads (void) __attribute__ ((__noreturn__));
141 /* nscd_conf.c */
142 extern int nscd_parse_file (const char *fname,
143 struct database_dyn dbs[lastdb]);
145 /* nscd_stat.c */
146 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
147 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
149 /* cache.c */
150 extern struct datahead *cache_search (request_type, void *key, size_t len,
151 struct database_dyn *table,
152 uid_t owner);
153 extern int cache_add (int type, const void *key, size_t len,
154 struct datahead *packet, bool first,
155 struct database_dyn *table, uid_t owner);
156 extern void prune_cache (struct database_dyn *table, time_t now);
158 /* pwdcache.c */
159 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
160 void *key, uid_t uid);
161 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
162 void *key, uid_t uid);
163 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
164 struct datahead *dh);
165 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
166 struct datahead *dh);
168 /* grpcache.c */
169 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
170 void *key, uid_t uid);
171 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
172 void *key, uid_t uid);
173 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
174 struct datahead *dh);
175 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
176 struct datahead *dh);
178 /* hstcache.c */
179 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
180 void *key, uid_t uid);
181 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
182 void *key, uid_t uid);
183 extern void addhstbynamev6 (struct database_dyn *db, int fd,
184 request_header *req, void *key, uid_t uid);
185 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
186 request_header *req, void *key, uid_t uid);
187 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
188 struct datahead *dh);
189 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
190 struct datahead *dh);
191 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
192 struct datahead *dh);
193 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
194 struct datahead *dh);
196 /* aicache.c */
197 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
198 void *key, uid_t uid);
199 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
200 struct datahead *dh);
202 /* mem.c */
203 extern void *mempool_alloc (struct database_dyn *db, size_t len);
204 extern void gc (struct database_dyn *db);
207 /* nscd_setup_thread.c */
208 extern void setup_thread (struct database_dyn *db);
210 #endif /* nscd.h */