OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [net/] [nscd/] [nscd-client.h] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Copyright (c) 1998, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
   Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
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
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
/* This file defines everything that client code should need to
21
   know to talk to the nscd daemon.  */
22
 
23
#ifndef _NSCD_CLIENT_H
24
#define _NSCD_CLIENT_H  1
25
 
26
#include <stdbool.h>
27
#include <stdint.h>
28
#include <sys/types.h>
29
#include <machine/atomic.h>
30
#include <nscd-types.h>
31
 
32
 
33
/* Version number of the daemon interface */
34
#define NSCD_VERSION 2
35
 
36
/* Path of the file where the PID of the running system is stored.  */
37
#define _PATH_NSCDPID    "/var/run/nscd/nscd.pid"
38
 
39
/* Path for the Unix domain socket.  */
40
#define _PATH_NSCDSOCKET "/var/run/nscd/socket"
41
 
42
/* Path for the configuration file.  */
43
#define _PATH_NSCDCONF   "/etc/nscd.conf"
44
 
45
 
46
/* Available services.  */
47
typedef enum
48
{
49
  GETPWBYNAME,
50
  GETPWBYUID,
51
  GETGRBYNAME,
52
  GETGRBYGID,
53
  GETHOSTBYNAME,
54
  GETHOSTBYNAMEv6,
55
  GETHOSTBYADDR,
56
  GETHOSTBYADDRv6,
57
  LASTDBREQ = GETHOSTBYADDRv6,
58
  SHUTDOWN,             /* Shut the server down.  */
59
  GETSTAT,              /* Get the server statistic.  */
60
  INVALIDATE,           /* Invalidate one special cache.  */
61
  GETFDPW,
62
  GETFDGR,
63
  GETFDHST,
64
  GETAI,
65
  INITGROUPS,
66
  LASTREQ
67
} request_type;
68
 
69
 
70
/* Header common to all requests */
71
typedef struct
72
{
73
  int32_t version;      /* Version number of the daemon interface.  */
74
  request_type type;    /* Service requested.  */
75
  int32_t key_len;      /* Key length.  */
76
} request_header;
77
 
78
 
79
/* Structure sent in reply to password query.  Note that this struct is
80
   sent also if the service is disabled or there is no record found.  */
81
typedef struct
82
{
83
  int32_t version;
84
  int32_t found;
85
  nscd_ssize_t pw_name_len;
86
  nscd_ssize_t pw_passwd_len;
87
  uid_t pw_uid;
88
  gid_t pw_gid;
89
  nscd_ssize_t pw_gecos_len;
90
  nscd_ssize_t pw_dir_len;
91
  nscd_ssize_t pw_shell_len;
92
} pw_response_header;
93
 
94
 
95
/* Structure sent in reply to group query.  Note that this struct is
96
   sent also if the service is disabled or there is no record found.  */
97
typedef struct
98
{
99
  int32_t version;
100
  int32_t found;
101
  nscd_ssize_t gr_name_len;
102
  nscd_ssize_t gr_passwd_len;
103
  gid_t gr_gid;
104
  nscd_ssize_t gr_mem_cnt;
105
} gr_response_header;
106
 
107
 
108
/* Structure sent in reply to host query.  Note that this struct is
109
   sent also if the service is disabled or there is no record found.  */
110
typedef struct
111
{
112
  int32_t version;
113
  int32_t found;
114
  nscd_ssize_t h_name_len;
115
  nscd_ssize_t h_aliases_cnt;
116
  int32_t h_addrtype;
117
  int32_t h_length;
118
  nscd_ssize_t h_addr_list_cnt;
119
  int32_t error;
120
} hst_response_header;
121
 
122
 
123
/* Structure sent in reply to addrinfo query.  Note that this struct is
124
   sent also if the service is disabled or there is no record found.  */
125
typedef struct
126
{
127
  int32_t version;
128
  int32_t found;
129
  nscd_ssize_t naddrs;
130
  nscd_ssize_t addrslen;
131
  nscd_ssize_t canonlen;
132
  int32_t error;
133
} ai_response_header;
134
 
135
/* Structure filled in by __nscd_getai.  */
136
struct nscd_ai_result
137
{
138
  int naddrs;
139
  char *canon;
140
  uint8_t *family;
141
  char *addrs;
142
};
143
 
144
/* Structure sent in reply to initgroups query.  Note that this struct is
145
   sent also if the service is disabled or there is no record found.  */
146
typedef struct
147
{
148
  int32_t version;
149
  int32_t found;
150
  nscd_ssize_t ngrps;
151
} initgr_response_header;
152
 
153
 
154
/* Type for offsets in data part of database.  */
155
typedef uint32_t ref_t;
156
/* Value for invalid/no reference.  */
157
#define ENDREF  UINT32_MAX
158
 
159
/* Timestamp type.  */
160
typedef uint64_t nscd_time_t;
161
 
162
/* Alignment requirement of the beginning of the data region.  */
163
#define ALIGN 16
164
 
165
 
166
/* Head of record in data part of database.  */
167
struct datahead
168
{
169
  nscd_ssize_t allocsize;       /* Allocated Bytes.  */
170
  nscd_ssize_t recsize;         /* Size of the record.  */
171
  nscd_time_t timeout;          /* Time when this entry becomes invalid.  */
172
  uint8_t notfound;             /* Nonzero if data has not been found.  */
173
  uint8_t nreloads;             /* Reloads without use.  */
174
  uint8_t usable;               /* False if the entry must be ignored.  */
175
  uint64_t :40;                 /* Alignment.  */
176
 
177
  /* We need to have the following element aligned for the response
178
     header data types and their use in the 'struct dataset' types
179
     defined in the XXXcache.c files.  */
180
  union
181
  {
182
    pw_response_header pwdata;
183
    gr_response_header grdata;
184
    hst_response_header hstdata;
185
    ai_response_header aidata;
186
    initgr_response_header initgrdata;
187
    nscd_ssize_t align1;
188
    nscd_time_t align2;
189
  } data[0];
190
};
191
 
192
 
193
/* Structure for one hash table entry.  */
194
struct hashentry
195
{
196
  request_type type:8;          /* Which type of dataset.  */
197
  bool first;                   /* True if this was the original key.  */
198
  nscd_ssize_t len;             /* Length of key.  */
199
  ref_t key;                    /* Pointer to key.  */
200
  int32_t owner;                /* If secure table, this is the owner.  */
201
  ref_t next;                   /* Next entry in this hash bucket list.  */
202
  ref_t packet;                 /* Records for the result.  */
203
  union
204
  {
205
    struct hashentry *dellist;  /* Next record to be deleted.  This can be a
206
                                   pointer since only nscd uses this field.  */
207
    ref_t *prevp;               /* Pointer to field containing forward
208
                                   reference.  */
209
  };
210
};
211
 
212
 
213
/* Current persistent database version.  */
214
#define DB_VERSION      1
215
 
216
/* Maximum time allowed between updates of the timestamp.  */
217
#define MAPPING_TIMEOUT (5 * 60)
218
 
219
 
220
/* Header of persistent database file.  */
221
struct database_pers_head
222
{
223
  int32_t version;
224
  int32_t header_size;
225
  volatile int32_t gc_cycle;
226
  volatile int32_t nscd_certainly_running;
227
  volatile nscd_time_t timestamp;
228
 
229
  nscd_ssize_t module;
230
  nscd_ssize_t data_size;
231
 
232
  nscd_ssize_t first_free;      /* Offset of first free byte in data area.  */
233
 
234
  nscd_ssize_t nentries;
235
  nscd_ssize_t maxnentries;
236
  nscd_ssize_t maxnsearched;
237
 
238
  uint64_t poshit;
239
  uint64_t neghit;
240
  uint64_t posmiss;
241
  uint64_t negmiss;
242
 
243
  uint64_t rdlockdelayed;
244
  uint64_t wrlockdelayed;
245
 
246
  uint64_t addfailed;
247
 
248
  ref_t array[0];
249
};
250
 
251
 
252
/* Mapped database record.  */
253
struct mapped_database
254
{
255
  const struct database_pers_head *head;
256
  const char *data;
257
  size_t mapsize;
258
  int counter;          /* > 0 indicates it is usable.  */
259
};
260
#define NO_MAPPING ((struct mapped_database *) -1l)
261
 
262
struct locked_map_ptr
263
{
264
  int lock;
265
  struct mapped_database *mapped;
266
};
267
#define libc_locked_map_ptr(class, name) class struct locked_map_ptr name
268
 
269
 
270
/* Open socket connection to nscd server.  */
271
extern int __nscd_open_socket (const char *key, size_t keylen,
272
                               request_type type, void *response,
273
                               size_t responselen) attribute_hidden;
274
 
275
/* Get reference of mapping.  */
276
extern struct mapped_database *__nscd_get_map_ref (request_type type,
277
                                                   const char *name,
278
                                                   struct locked_map_ptr *mapptr,
279
                                                   int *gc_cyclep);
280
 
281
/* Unmap database.  */
282
extern void __nscd_unmap (struct mapped_database *mapped);
283
 
284
/* Drop reference of mapping.  */
285
static inline int __nscd_drop_map_ref (struct mapped_database *map,
286
                                       int *gc_cycle)
287
{
288
  if (map != NO_MAPPING)
289
    {
290
      int now_cycle = map->head->gc_cycle;
291
      if (__builtin_expect (now_cycle != *gc_cycle, 0))
292
        {
293
          /* We might have read inconsistent data.  */
294
          *gc_cycle = now_cycle;
295
          return -1;
296
        }
297
 
298
      if (atomic_decrement_and_test (&map->counter) == 0)
299
        __nscd_unmap (map);
300
    }
301
 
302
  return 0;
303
}
304
 
305
 
306
/* Search the mapped database.  */
307
extern const struct datahead *__nscd_cache_search (request_type type,
308
                                                   const char *key,
309
                                                   size_t keylen,
310
                                                   const struct mapped_database *mapped);
311
 
312
#endif /* nscd.h */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.