Update.
[glibc.git] / nscd / nscd.h
blobbc8150aca12726a9be9cb85b7dd8267b0cab570e
1 /* Copyright (c) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #ifndef _NSCD_H
21 #define _NSCD_H 1
23 #include <pthread.h>
24 #include <time.h>
25 #include <sys/uio.h>
28 /* Version number of the daemon interface */
29 #define NSCD_VERSION 2
31 /* Path of the file where the PID of the running system is stored. */
32 #define _PATH_NSCDPID "/var/run/nscd.pid"
34 /* Path for the Unix domain socket. */
35 #define _PATH_NSCDSOCKET "/var/run/.nscd_socket"
37 /* Path for the configuration file. */
38 #define _PATH_NSCDCONF "/etc/nscd.conf"
41 /* Handle databases. */
42 typedef enum
44 pwddb,
45 grpdb,
46 hstdb,
47 lastdb
48 } dbtype;
51 /* Available services. */
52 typedef enum
54 GETPWBYNAME,
55 GETPWBYUID,
56 GETGRBYNAME,
57 GETGRBYGID,
58 GETHOSTBYNAME,
59 GETHOSTBYNAMEv6,
60 GETHOSTBYADDR,
61 GETHOSTBYADDRv6,
62 LASTDBREQ = GETHOSTBYADDRv6,
63 SHUTDOWN, /* Shut the server down. */
64 GETSTAT, /* Get the server statistic. */
65 LASTREQ,
66 } request_type;
69 /* Structure for one hash table entry. */
70 struct hashentry
72 request_type type; /* Which type of dataset. */
73 size_t len; /* Length of key. */
74 void *key; /* Pointer to key. */
75 struct hashentry *next; /* Next entry in this hash bucket list. */
76 time_t timeout; /* Time when this entry becomes invalid. */
77 ssize_t total; /* Number of bytes in PACKET. */
78 const void *packet; /* Records for the result. */
79 void *data; /* The malloc()ed respond record. */
80 int last; /* Nonzero if DATA should be free()d. */
81 struct hashentry *dellist; /* Next record to be deleted. */
84 /* Structure describing one database. */
85 struct database
87 pthread_rwlock_t lock;
89 int enabled;
90 int check_file;
91 const char *filename;
92 time_t file_mtime;
93 size_t module;
95 const struct iovec *disabled_iov;
97 unsigned long int postimeout;
98 unsigned long int negtimeout;
100 unsigned long int poshit;
101 unsigned long int neghit;
102 unsigned long int posmiss;
103 unsigned long int negmiss;
105 struct hashentry **array;
109 /* Header common to all requests */
110 typedef struct
112 int version; /* Version number of the daemon interface. */
113 request_type type; /* Service requested. */
114 ssize_t key_len; /* Key length. */
115 } request_header;
118 /* Structure sent in reply to password query. Note that this struct is
119 sent also if the service is disabled or there is no record found. */
120 typedef struct
122 int version;
123 int found;
124 ssize_t pw_name_len;
125 ssize_t pw_passwd_len;
126 uid_t pw_uid;
127 gid_t pw_gid;
128 ssize_t pw_gecos_len;
129 ssize_t pw_dir_len;
130 ssize_t pw_shell_len;
131 } pw_response_header;
134 /* Structure sent in reply to group query. Note that this struct is
135 sent also if the service is disabled or there is no record found. */
136 typedef struct
138 int version;
139 int found;
140 ssize_t gr_name_len;
141 ssize_t gr_passwd_len;
142 gid_t gr_gid;
143 ssize_t gr_mem_cnt;
144 } gr_response_header;
147 /* Structure sent in reply to host query. Note that this struct is
148 sent also if the service is disabled or there is no record found. */
149 typedef struct
151 int version;
152 int found;
153 ssize_t h_name_len;
154 ssize_t h_aliases_cnt;
155 int h_addrtype;
156 int h_length;
157 ssize_t h_addr_list_cnt;
158 int error;
159 } hst_response_header;
161 /* Global variables. */
162 extern const char *dbnames[lastdb];
163 extern const char *serv2str[LASTREQ];
165 extern const struct iovec pwd_iov_disabled;
166 extern const struct iovec grp_iov_disabled;
167 extern const struct iovec hst_iov_disabled;
169 /* Number of threads to run. */
170 extern int nthreads;
173 /* Prototypes for global functions. */
175 /* nscd.c */
176 extern void termination_handler (int signum);
177 extern int nscd_open_socket (void);
179 /* connections.c */
180 extern void nscd_init (const char *conffile);
181 extern void close_sockets (void);
182 extern void start_threads (void);
184 /* nscd_conf.c */
185 extern int nscd_parse_file (const char *fname, struct database dbs[lastdb]);
187 /* nscd_stat.c */
188 extern void send_stats (int fd, struct database dbs[lastdb]);
189 extern int receive_print_stats (void);
191 /* cache.c */
192 extern struct hashentry *cache_search (int type, void *key, size_t len,
193 struct database *table);
194 extern void cache_add (int type, void *key, size_t len,
195 const void *packet, size_t iovtotal, void *data,
196 int last, time_t t, struct database *table);
197 extern void prune_cache (struct database *table, time_t now);
199 /* pwdcache.c */
200 extern void addpwbyname (struct database *db, int fd, request_header *req,
201 void *key);
202 extern void addpwbyuid (struct database *db, int fd, request_header *req,
203 void *key);
205 /* grpcache.c */
206 extern void addgrbyname (struct database *db, int fd, request_header *req,
207 void *key);
208 extern void addgrbygid (struct database *db, int fd, request_header *req,
209 void *key);
211 /* hstcache.c */
212 extern void addhstbyname (struct database *db, int fd, request_header *req,
213 void *key);
214 extern void addhstbyaddr (struct database *db, int fd, request_header *req,
215 void *key);
216 extern void addhstbynamev6 (struct database *db, int fd, request_header *req,
217 void *key);
218 extern void addhstbyaddrv6 (struct database *db, int fd, request_header *req,
219 void *key);
221 #endif /* nscd.h */