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. */
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. */
51 /* Available services. */
62 LASTDBREQ
= GETHOSTBYADDRv6
,
63 SHUTDOWN
, /* Shut the server down. */
64 GETSTAT
, /* Get the server statistic. */
69 /* Structure for one hash table entry. */
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. */
87 pthread_rwlock_t lock
;
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 */
112 int version
; /* Version number of the daemon interface. */
113 request_type type
; /* Service requested. */
114 ssize_t key_len
; /* Key length. */
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. */
125 ssize_t pw_passwd_len
;
128 ssize_t pw_gecos_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. */
141 ssize_t gr_passwd_len
;
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. */
154 ssize_t h_aliases_cnt
;
157 ssize_t h_addr_list_cnt
;
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. */
173 /* Prototypes for global functions. */
176 extern void termination_handler (int signum
);
177 extern int nscd_open_socket (void);
180 extern void nscd_init (const char *conffile
);
181 extern void close_sockets (void);
182 extern void start_threads (void);
185 extern int nscd_parse_file (const char *fname
, struct database dbs
[lastdb
]);
188 extern void send_stats (int fd
, struct database dbs
[lastdb
]);
189 extern int receive_print_stats (void);
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
);
200 extern void addpwbyname (struct database
*db
, int fd
, request_header
*req
,
202 extern void addpwbyuid (struct database
*db
, int fd
, request_header
*req
,
206 extern void addgrbyname (struct database
*db
, int fd
, request_header
*req
,
208 extern void addgrbygid (struct database
*db
, int fd
, request_header
*req
,
212 extern void addhstbyname (struct database
*db
, int fd
, request_header
*req
,
214 extern void addhstbyaddr (struct database
*db
, int fd
, request_header
*req
,
216 extern void addhstbynamev6 (struct database
*db
, int fd
, request_header
*req
,
218 extern void addhstbyaddrv6 (struct database
*db
, int fd
, request_header
*req
,