* locales/en_GB: Set first weekday and workday to 2.
[glibc.git] / nscd / nscd-client.h
blob3c9688fd30f48278ff14ac6d1915e3e37f746fe6
1 /* Copyright (c) 1998, 1999, 2000, 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 /* This file defines everything that client code should need to
22 know to talk to the nscd daemon. */
24 #ifndef _NSCD_CLIENT_H
25 #define _NSCD_CLIENT_H 1
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <sys/types.h>
30 #include <atomic.h>
31 #include <nscd-types.h>
32 #include <sys/uio.h>
35 /* Version number of the daemon interface */
36 #define NSCD_VERSION 2
38 /* Path of the file where the PID of the running system is stored. */
39 #define _PATH_NSCDPID "/var/run/nscd/nscd.pid"
41 /* Path for the Unix domain socket. */
42 #define _PATH_NSCDSOCKET "/var/run/nscd/socket"
44 /* Path for the configuration file. */
45 #define _PATH_NSCDCONF "/etc/nscd.conf"
47 /* Maximu allowed length for the key. */
48 #define MAXKEYLEN 1024
51 /* Available services. */
52 typedef enum
54 GETPWBYNAME,
55 GETPWBYUID,
56 GETGRBYNAME,
57 GETGRBYGID,
58 GETHOSTBYNAME,
59 GETHOSTBYNAMEv6,
60 GETHOSTBYADDR,
61 GETHOSTBYADDRv6,
62 SHUTDOWN, /* Shut the server down. */
63 GETSTAT, /* Get the server statistic. */
64 INVALIDATE, /* Invalidate one special cache. */
65 GETFDPW,
66 GETFDGR,
67 GETFDHST,
68 GETAI,
69 INITGROUPS,
70 GETSERVBYNAME,
71 GETSERVBYPORT,
72 GETFDSERV,
73 LASTREQ
74 } request_type;
77 /* Header common to all requests */
78 typedef struct
80 int32_t version; /* Version number of the daemon interface. */
81 request_type type; /* Service requested. */
82 int32_t key_len; /* Key length. */
83 } request_header;
86 /* Structure sent in reply to password query. Note that this struct is
87 sent also if the service is disabled or there is no record found. */
88 typedef struct
90 int32_t version;
91 int32_t found;
92 nscd_ssize_t pw_name_len;
93 nscd_ssize_t pw_passwd_len;
94 uid_t pw_uid;
95 gid_t pw_gid;
96 nscd_ssize_t pw_gecos_len;
97 nscd_ssize_t pw_dir_len;
98 nscd_ssize_t pw_shell_len;
99 } pw_response_header;
102 /* Structure sent in reply to group query. Note that this struct is
103 sent also if the service is disabled or there is no record found. */
104 typedef struct
106 int32_t version;
107 int32_t found;
108 nscd_ssize_t gr_name_len;
109 nscd_ssize_t gr_passwd_len;
110 gid_t gr_gid;
111 nscd_ssize_t gr_mem_cnt;
112 } gr_response_header;
115 /* Structure sent in reply to host query. Note that this struct is
116 sent also if the service is disabled or there is no record found. */
117 typedef struct
119 int32_t version;
120 int32_t found;
121 nscd_ssize_t h_name_len;
122 nscd_ssize_t h_aliases_cnt;
123 int32_t h_addrtype;
124 int32_t h_length;
125 nscd_ssize_t h_addr_list_cnt;
126 int32_t error;
127 } hst_response_header;
130 /* Structure sent in reply to addrinfo query. Note that this struct is
131 sent also if the service is disabled or there is no record found. */
132 typedef struct
134 int32_t version;
135 int32_t found;
136 nscd_ssize_t naddrs;
137 nscd_ssize_t addrslen;
138 nscd_ssize_t canonlen;
139 int32_t error;
140 } ai_response_header;
142 /* Structure filled in by __nscd_getai. */
143 struct nscd_ai_result
145 int naddrs;
146 char *canon;
147 uint8_t *family;
148 char *addrs;
151 /* Structure sent in reply to initgroups query. Note that this struct is
152 sent also if the service is disabled or there is no record found. */
153 typedef struct
155 int32_t version;
156 int32_t found;
157 nscd_ssize_t ngrps;
158 } initgr_response_header;
161 /* Structure sent in reply to services query. Note that this struct is
162 sent also if the service is disabled or there is no record found. */
163 typedef struct
165 int32_t version;
166 int32_t found;
167 nscd_ssize_t s_name_len;
168 nscd_ssize_t s_proto_len;
169 nscd_ssize_t s_aliases_cnt;
170 int32_t s_port;
171 } serv_response_header;
174 /* Type for offsets in data part of database. */
175 typedef uint32_t ref_t;
176 /* Value for invalid/no reference. */
177 #define ENDREF UINT32_MAX
179 /* Timestamp type. */
180 typedef uint64_t nscd_time_t;
182 /* Alignment requirement of the beginning of the data region. */
183 #define ALIGN 16
186 /* Head of record in data part of database. */
187 struct datahead
189 nscd_ssize_t allocsize; /* Allocated Bytes. */
190 nscd_ssize_t recsize; /* Size of the record. */
191 nscd_time_t timeout; /* Time when this entry becomes invalid. */
192 uint8_t notfound; /* Nonzero if data has not been found. */
193 uint8_t nreloads; /* Reloads without use. */
194 uint8_t usable; /* False if the entry must be ignored. */
195 uint64_t :40; /* Alignment. */
197 /* We need to have the following element aligned for the response
198 header data types and their use in the 'struct dataset' types
199 defined in the XXXcache.c files. */
200 union
202 pw_response_header pwdata;
203 gr_response_header grdata;
204 hst_response_header hstdata;
205 ai_response_header aidata;
206 initgr_response_header initgrdata;
207 serv_response_header servdata;
208 nscd_ssize_t align1;
209 nscd_time_t align2;
210 } data[0];
214 /* Structure for one hash table entry. */
215 struct hashentry
217 request_type type:8; /* Which type of dataset. */
218 bool first; /* True if this was the original key. */
219 nscd_ssize_t len; /* Length of key. */
220 ref_t key; /* Pointer to key. */
221 int32_t owner; /* If secure table, this is the owner. */
222 ref_t next; /* Next entry in this hash bucket list. */
223 ref_t packet; /* Records for the result. */
224 union
226 struct hashentry *dellist; /* Next record to be deleted. This can be a
227 pointer since only nscd uses this field. */
228 ref_t *prevp; /* Pointer to field containing forward
229 reference. */
234 /* Current persistent database version. */
235 #define DB_VERSION 1
237 /* Maximum time allowed between updates of the timestamp. */
238 #define MAPPING_TIMEOUT (5 * 60)
241 /* Header of persistent database file. */
242 struct database_pers_head
244 int32_t version;
245 int32_t header_size;
246 volatile int32_t gc_cycle;
247 volatile int32_t nscd_certainly_running;
248 volatile nscd_time_t timestamp;
250 nscd_ssize_t module;
251 nscd_ssize_t data_size;
253 nscd_ssize_t first_free; /* Offset of first free byte in data area. */
255 nscd_ssize_t nentries;
256 nscd_ssize_t maxnentries;
257 nscd_ssize_t maxnsearched;
259 uint64_t poshit;
260 uint64_t neghit;
261 uint64_t posmiss;
262 uint64_t negmiss;
264 uint64_t rdlockdelayed;
265 uint64_t wrlockdelayed;
267 uint64_t addfailed;
269 ref_t array[0];
273 /* Mapped database record. */
274 struct mapped_database
276 const struct database_pers_head *head;
277 const char *data;
278 size_t mapsize;
279 int counter; /* > 0 indicates it is usable. */
280 size_t datasize;
282 #define NO_MAPPING ((struct mapped_database *) -1l)
284 struct locked_map_ptr
286 int lock;
287 struct mapped_database *mapped;
289 #define libc_locked_map_ptr(class, name) class struct locked_map_ptr name
292 /* Open socket connection to nscd server. */
293 extern int __nscd_open_socket (const char *key, size_t keylen,
294 request_type type, void *response,
295 size_t responselen) attribute_hidden;
297 /* Get reference of mapping. */
298 extern struct mapped_database *__nscd_get_map_ref (request_type type,
299 const char *name,
300 volatile struct locked_map_ptr *mapptr,
301 int *gc_cyclep);
303 /* Unmap database. */
304 extern void __nscd_unmap (struct mapped_database *mapped);
306 /* Drop reference of mapping. */
307 static inline int __nscd_drop_map_ref (struct mapped_database *map,
308 int *gc_cycle)
310 if (map != NO_MAPPING)
312 int now_cycle = map->head->gc_cycle;
313 if (__builtin_expect (now_cycle != *gc_cycle, 0))
315 /* We might have read inconsistent data. */
316 *gc_cycle = now_cycle;
317 return -1;
320 if (atomic_decrement_val (&map->counter) == 0)
321 __nscd_unmap (map);
324 return 0;
328 /* Search the mapped database. */
329 extern struct datahead *__nscd_cache_search (request_type type,
330 const char *key,
331 size_t keylen,
332 const struct mapped_database *mapped);
334 /* Wrappers around read, readv and write that only read/write less than LEN
335 bytes on error or EOF. */
336 extern ssize_t __readall (int fd, void *buf, size_t len)
337 attribute_hidden;
338 extern ssize_t __readvall (int fd, const struct iovec *iov, int iovcnt)
339 attribute_hidden;
340 extern ssize_t writeall (int fd, const void *buf, size_t len)
341 attribute_hidden;
342 extern ssize_t sendfileall (int tofd, int fromfd, off_t off, size_t len)
343 attribute_hidden;
345 #endif /* nscd.h */