Print this page
7126 NSS_XbyY_FINI has too much logic for a function-like macro
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/head/nss_dbdefs.h
+++ new/usr/src/head/nss_dbdefs.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23 23 *
24 24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 *
27 27 * Database-specific definitions for the getXXXbyYYY routines
28 28 * (e.g getpwuid_r(), ether_ntohost()) that use the name-service switch.
29 29 * Database-independent definitions are in <nss_common.h>
30 30 *
31 31 * Ideally, this is the only switch header file one would add things
32 32 * to in order to support a new database.
33 33 *
34 34 * NOTE: The interfaces documented in this file may change in a minor
35 35 * release. It is intended that in the future a stronger committment
36 36 * will be made to these interface definitions which will guarantee
37 37 * them across minor releases.
38 38 */
39 39
40 40 #ifndef _NSS_DBDEFS_H
41 41 #define _NSS_DBDEFS_H
42 42
43 43 #include <sys/types.h>
44 44 #include <unistd.h>
45 45 #include <errno.h>
46 46 #include <netdb.h> /* MAXALIASES, MAXADDRS */
47 47 #include <limits.h> /* LOGNAME_MAX */
48 48 #include <nss_common.h>
49 49
50 50 #ifdef __cplusplus
51 51 extern "C" {
52 52 #endif
53 53
54 54 #ifndef NSS_INCLUDE_UNSAFE
55 55 #define NSS_INCLUDE_UNSAFE 1 /* Build old, MT-unsafe interfaces, */
56 56 #endif /* NSS_INCLUDE_UNSAFE */ /* e.g. getpwnam (c.f. getpwnam_r) */
57 57
58 58 /*
59 59 * Names of the well-known databases.
60 60 */
61 61
62 62 #define NSS_DBNAM_ALIASES "aliases" /* E-mail aliases, that is */
63 63 #define NSS_DBNAM_AUTOMOUNT "automount"
64 64 #define NSS_DBNAM_BOOTPARAMS "bootparams"
65 65 #define NSS_DBNAM_ETHERS "ethers"
66 66 #define NSS_DBNAM_GROUP "group"
67 67 #define NSS_DBNAM_HOSTS "hosts"
68 68 #define NSS_DBNAM_IPNODES "ipnodes"
69 69 #define NSS_DBNAM_NETGROUP "netgroup"
70 70 #define NSS_DBNAM_NETMASKS "netmasks"
71 71 #define NSS_DBNAM_NETWORKS "networks"
72 72 #define NSS_DBNAM_PASSWD "passwd"
73 73 #define NSS_DBNAM_PRINTERS "printers"
74 74 #define NSS_DBNAM_PROJECT "project"
75 75 #define NSS_DBNAM_PROTOCOLS "protocols"
76 76 #define NSS_DBNAM_PUBLICKEY "publickey"
77 77 #define NSS_DBNAM_RPC "rpc"
78 78 #define NSS_DBNAM_SERVICES "services"
79 79 #define NSS_DBNAM_AUDITUSER "audit_user"
80 80 #define NSS_DBNAM_AUTHATTR "auth_attr"
81 81 #define NSS_DBNAM_EXECATTR "exec_attr"
82 82 #define NSS_DBNAM_PROFATTR "prof_attr"
83 83 #define NSS_DBNAM_USERATTR "user_attr"
84 84
85 85 #define NSS_DBNAM_TSOL_TP "tnrhtp"
86 86 #define NSS_DBNAM_TSOL_RH "tnrhdb"
87 87 #define NSS_DBNAM_TSOL_ZC "tnzonecfg"
88 88
89 89 /* getspnam() et al use the "passwd" config entry but the "shadow" backend */
90 90 #define NSS_DBNAM_SHADOW "shadow"
91 91
92 92 /* The "compat" backend gets config entries for these pseudo-databases */
93 93 #define NSS_DBNAM_PASSWD_COMPAT "passwd_compat"
94 94 #define NSS_DBNAM_GROUP_COMPAT "group_compat"
95 95
96 96 /*
97 97 * Default switch configuration, compiled into the front-ends.
98 98 *
99 99 * Absent good reasons to the contrary, this should be compatible with the
100 100 * default /etc/nsswitch.conf file.
101 101 */
102 102 #define NSS_FILES_ONLY "files"
103 103 #define NSS_FILES_NS "files nis"
104 104 #define NSS_NS_FALLBACK "nis [NOTFOUND=return] files"
105 105 #define NSS_NS_ONLY "nis"
106 106 #define NSS_TSOL_FALLBACK "files ldap"
107 107
108 108 #define NSS_DEFCONF_ALIASES NSS_FILES_NS
109 109 #define NSS_DEFCONF_AUTOMOUNT NSS_FILES_NS
110 110 #define NSS_DEFCONF_BOOTPARAMS NSS_NS_FALLBACK
111 111 #define NSS_DEFCONF_ETHERS NSS_NS_FALLBACK
112 112 #define NSS_DEFCONF_GROUP NSS_FILES_NS
113 113 #define NSS_DEFCONF_HOSTS NSS_NS_FALLBACK
114 114 #define NSS_DEFCONF_IPNODES NSS_NS_FALLBACK
115 115 #define NSS_DEFCONF_NETGROUP NSS_NS_ONLY
116 116 #define NSS_DEFCONF_NETMASKS NSS_NS_FALLBACK
117 117 #define NSS_DEFCONF_NETWORKS NSS_NS_FALLBACK
118 118 #define NSS_DEFCONF_PASSWD NSS_FILES_NS
119 119 #define NSS_DEFCONF_PRINTERS "user files nis"
120 120 #define NSS_DEFCONF_PROJECT NSS_FILES_NS
121 121 #define NSS_DEFCONF_PROTOCOLS NSS_NS_FALLBACK
122 122 #define NSS_DEFCONF_PUBLICKEY NSS_FILES_NS
123 123 #define NSS_DEFCONF_RPC NSS_NS_FALLBACK
124 124 #define NSS_DEFCONF_SERVICES NSS_FILES_NS /* speeds up byname() */
125 125
126 126 #define NSS_DEFCONF_GROUP_COMPAT NSS_NS_ONLY
127 127 #define NSS_DEFCONF_PASSWD_COMPAT NSS_NS_ONLY
128 128
129 129 #define NSS_DEFCONF_ATTRDB NSS_FILES_NS
130 130
131 131 #define NSS_DEFCONF_AUDITUSER NSS_DEFCONF_PASSWD
132 132 #define NSS_DEFCONF_USERATTR NSS_DEFCONF_PASSWD
133 133 #define NSS_DEFCONF_AUTHATTR NSS_DEFCONF_ATTRDB
134 134 #define NSS_DEFCONF_PROFATTR NSS_DEFCONF_ATTRDB
135 135 #define NSS_DEFCONF_EXECATTR NSS_DEFCONF_PROFATTR
136 136
137 137 #define NSS_DEFCONF_TSOL_TP NSS_TSOL_FALLBACK
138 138 #define NSS_DEFCONF_TSOL_RH NSS_TSOL_FALLBACK
139 139 #define NSS_DEFCONF_TSOL_ZC NSS_TSOL_FALLBACK
140 140
141 141 /*
142 142 * Line-lengths that the "files" and "compat" backends will try to support.
143 143 * It may be reasonable (even advisable) to use smaller values than these.
144 144 */
145 145
146 146 #define NSS_BUFSIZ 1024
147 147
148 148 #define NSS_LINELEN_GROUP ((NSS_BUFSIZ) * 8)
149 149 #define NSS_LINELEN_HOSTS ((NSS_BUFSIZ) * 8)
150 150 #define NSS_LINELEN_IPNODES ((NSS_BUFSIZ) * 8)
151 151 #define NSS_LINELEN_NETMASKS NSS_BUFSIZ
152 152 #define NSS_LINELEN_NETWORKS NSS_BUFSIZ
153 153 #define NSS_LINELEN_PASSWD NSS_BUFSIZ
154 154 #define NSS_LINELEN_PRINTERS NSS_BUFSIZ
155 155 #define NSS_LINELEN_PROJECT ((NSS_BUFSIZ) * 4)
156 156 #define NSS_LINELEN_PROTOCOLS NSS_BUFSIZ
157 157 #define NSS_LINELEN_PUBLICKEY NSS_BUFSIZ
158 158 #define NSS_LINELEN_RPC NSS_BUFSIZ
159 159 #define NSS_LINELEN_SERVICES NSS_BUFSIZ
160 160 #define NSS_LINELEN_SHADOW NSS_BUFSIZ
161 161 #define NSS_LINELEN_ETHERS NSS_BUFSIZ
162 162 #define NSS_LINELEN_BOOTPARAMS NSS_BUFSIZ
163 163
164 164 #define NSS_LINELEN_ATTRDB NSS_BUFSIZ
165 165
166 166 #define NSS_LINELEN_AUDITUSER NSS_LINELEN_ATTRDB
167 167 #define NSS_LINELEN_AUTHATTR NSS_LINELEN_ATTRDB
168 168 #define NSS_LINELEN_EXECATTR NSS_LINELEN_ATTRDB
169 169 #define NSS_LINELEN_PROFATTR NSS_LINELEN_ATTRDB
170 170 #define NSS_LINELEN_USERATTR NSS_LINELEN_ATTRDB
171 171
172 172 #define NSS_MMAPLEN_EXECATTR NSS_LINELEN_EXECATTR * 8
173 173
174 174 #define NSS_LINELEN_TSOL NSS_BUFSIZ
175 175
176 176 #define NSS_LINELEN_TSOL_TP NSS_LINELEN_TSOL
177 177 #define NSS_LINELEN_TSOL_RH NSS_LINELEN_TSOL
178 178 #define NSS_LINELEN_TSOL_ZC NSS_LINELEN_TSOL
179 179
180 180 /*
181 181 * Reasonable defaults for 'buflen' values passed to _r functions. The BSD
182 182 * and SunOS 4.x implementations of the getXXXbyYYY() functions used hard-
183 183 * coded array sizes; the values here are meant to handle anything that
184 184 * those implementations handled.
185 185 * === These might more reasonably go in <pwd.h>, <netdb.h> et al
186 186 */
187 187
188 188 #define NSS_BUFLEN_GROUP NSS_LINELEN_GROUP
189 189 #define NSS_BUFLEN_HOSTS \
190 190 (NSS_LINELEN_HOSTS + (MAXALIASES + MAXADDRS + 2) * sizeof (char *))
191 191 #define NSS_BUFLEN_IPNODES \
192 192 (NSS_LINELEN_IPNODES + (MAXALIASES + MAXADDRS + 2) * sizeof (char *))
193 193 #define NSS_BUFLEN_NETGROUP (MAXHOSTNAMELEN * 2 + LOGNAME_MAX + 3)
194 194 #define NSS_BUFLEN_NETWORKS NSS_LINELEN_NETWORKS /* === ? + 35 * 4 */
195 195 #define NSS_BUFLEN_PASSWD NSS_LINELEN_PASSWD
196 196 #define NSS_BUFLEN_PROJECT (NSS_LINELEN_PROJECT + 800 * sizeof (char *))
197 197 #define NSS_BUFLEN_PROTOCOLS NSS_LINELEN_PROTOCOLS /* === ? + 35 * 4 */
198 198 #define NSS_BUFLEN_PUBLICKEY NSS_LINELEN_PUBLICKEY
199 199 #define NSS_BUFLEN_RPC NSS_LINELEN_RPC /* === ? + 35 * 4 */
200 200 #define NSS_BUFLEN_SERVICES NSS_LINELEN_SERVICES /* === ? + 35 * 4 */
201 201 #define NSS_BUFLEN_SHADOW NSS_LINELEN_SHADOW
202 202 #define NSS_BUFLEN_ETHERS NSS_LINELEN_ETHERS
203 203 #define NSS_BUFLEN_BOOTPARAMS NSS_LINELEN_BOOTPARAMS
204 204
205 205 #define NSS_BUFLEN_ATTRDB NSS_LINELEN_ATTRDB
206 206
207 207 #define NSS_BUFLEN_AUDITUSER NSS_BUFLEN_ATTRDB
208 208 #define NSS_BUFLEN_AUTHATTR NSS_BUFLEN_ATTRDB
209 209 #define NSS_BUFLEN_EXECATTR NSS_BUFLEN_ATTRDB
210 210 #define NSS_BUFLEN_PROFATTR NSS_BUFLEN_ATTRDB
211 211 #define NSS_BUFLEN_USERATTR ((NSS_BUFLEN_ATTRDB) * 8)
212 212
213 213 #define NSS_BUFLEN_TSOL NSS_LINELEN_TSOL
214 214 #define NSS_BUFLEN_TSOL_TP NSS_BUFLEN_TSOL
215 215 #define NSS_BUFLEN_TSOL_RH NSS_BUFLEN_TSOL
216 216 #define NSS_BUFLEN_TSOL_ZC NSS_BUFLEN_TSOL
217 217
218 218 /*
219 219 * Default cache door buffer size (2x largest buffer)
220 220 */
221 221
222 222 #define NSS_BUFLEN_DOOR ((NSS_BUFSIZ) * 16)
223 223
224 224 /*
225 225 * Arguments and results, passed between the frontends and backends for
226 226 * the well-known databases. The getXbyY_r() and getXent_r() routines
227 227 * use a common format that is further described below; other routines
228 228 * use their own formats.
229 229 */
230 230
231 231 /*
232 232 * The nss_str2ent_t routine is the data marshaller for the nsswitch.
233 233 * it converts 'native files' format into 'entry' format as part of the
234 234 * return processing for a getXbyY interface.
235 235 *
236 236 * The nss_groupstr_t routine does the real work for any backend
237 237 * that can supply a netgroup entry as a string in /etc/group format
238 238 */
239 239 typedef int (*nss_str2ent_t)(const char *in, int inlen,
240 240 void *ent, char *buf, int buflen);
241 241
242 242 struct nss_groupsbymem; /* forward definition */
243 243 typedef nss_status_t (*nss_groupstr_t)(const char *instr, int inlen,
244 244 struct nss_groupsbymem *);
245 245
246 246 /*
247 247 * The initgroups() function [see initgroups(3c)] needs to find all the
248 248 * groups to which a given user belongs. To do this it calls
249 249 * _getgroupsbymember(), which is part of the frontend for the "group"
250 250 * database.
251 251 * We want the same effect as if we used getgrent_r() to enumerate the
252 252 * entire groups database (possibly from multiple sources), but getgrent_r()
253 253 * is too inefficient. Most backends can do better if they know they're
254 254 * meant to scan all groups; hence there's a separate backend operation,
255 255 * NSS_DBOP_GROUP_BYMEMBER, which uses the nss_groupsbymem struct.
256 256 * Note that the normal return-value from such a backend, even when it
257 257 * successfully finds matching group entries, is NSS_NOTFOUND, because
258 258 * this tells the switch engine to keep searching in any more sources.
259 259 * In fact, the backends only return NSS_SUCCESS if they find enough
260 260 * matching entries that the gid_array is completely filled, in which
261 261 * case the switch engine should stop searching.
262 262 * If the force_slow_way field is set, the backend should eschew any cached
263 263 * information (e.g. the YP netid.byname map or the NIS+ cred.org_dir table)
264 264 * and should instead grind its way through the group map/table/whatever.
265 265 */
266 266
267 267 struct nss_groupsbymem { /* For _getgroupsbymember() */
268 268 /* in: */
269 269 const char *username;
270 270 gid_t *gid_array;
271 271 int maxgids;
272 272 int force_slow_way;
273 273 nss_str2ent_t str2ent;
274 274 nss_groupstr_t process_cstr;
275 275
276 276 /* in_out: */
277 277 int numgids;
278 278 };
279 279
280 280 /*
281 281 * The netgroup routines are handled as follows:
282 282 *
283 283 * Policy decision:
284 284 * If netgroup A refers to netgroup B, both must occur in the same
285 285 * source (other choices give very confusing semantics). This
286 286 * assumption is deeply embedded in the frontend and backends.
287 287 *
288 288 * - setnetgrent(), despite its name, is really a getXXXbyYYY operation:
289 289 * it takes a name and finds a netgroup with that name (see the
290 290 * nss_setnetgrent_args struct below). The "result" that it returns
291 291 * to the frontend is an nss_backend_t for a pseudo-backend that allows
292 292 * one to enumerate the members of that netgroup.
293 293 *
294 294 * - getnetgrent() calls the 'getXXXent' function in the pseudo-backend;
295 295 * it doesn't go through the switch engine at all. It uses the
296 296 * nss_getnetgrent_args struct below.
297 297 *
298 298 * - innetgr() is implemented on top of __multi_innetgr(), which replaces
299 299 * each (char *) argument of innetgr() with a counted vector of (char *).
300 300 * The semantics are the same as an OR of the results of innetgr()
301 301 * operations on each possible 4-tuple picked from the arguments, but
302 302 * it's possible to implement some cases more efficiently. This is
303 303 * important for mountd, which used to read YP netgroup.byhost directly
304 304 * in order to determine efficiently whether a given host belonged to any
305 305 * one of a long list of netgroups. Wildcarded arguments are indicated
306 306 * by a count of zero.
307 307 *
308 308 * - __multi_innetgr() uses the nss_innetgr_args struct. A backend whose
309 309 * source contains at least one of the groups listed in the 'groups'
310 310 * vector will return NSS_SUCCESS and will set the 'status' field to
311 311 * indicate whether any 4-tuple was satisfied. A backend will only
312 312 * return NSS_NOTFOUND if the source contained none of the groups
313 313 * listed in the 'groups' vector.
314 314 */
315 315
316 316 enum nss_netgr_argn { /* We need (machine, user, domain) triples */
317 317 NSS_NETGR_MACHINE = 0,
318 318 NSS_NETGR_USER = 1,
319 319 NSS_NETGR_DOMAIN = 2,
320 320 NSS_NETGR_N = 3
321 321 };
322 322
323 323 enum nss_netgr_status { /* Status from setnetgrent, multi_innetgr */
324 324 NSS_NETGR_FOUND = 0,
325 325 NSS_NETGR_NO = 1,
326 326 NSS_NETGR_NOMEM = 2
327 327 };
328 328
329 329 struct nss_setnetgrent_args {
330 330 /* in: */
331 331 const char *netgroup;
332 332 /* out: */
333 333 nss_backend_t *iterator; /* <==== Explain */
334 334 };
335 335
336 336 struct nss_getnetgrent_args {
337 337 /* in: */
338 338 char *buffer;
339 339 int buflen;
340 340 /* out: */
341 341 enum nss_netgr_status status;
342 342 char *retp[NSS_NETGR_N];
343 343 };
344 344
345 345 typedef unsigned nss_innetgr_argc; /* 0 means wildcard */
346 346 typedef char ** nss_innetgr_argv; /* === Do we really need these? */
347 347
348 348 struct nss_innetgr_1arg {
349 349 nss_innetgr_argc argc;
350 350 nss_innetgr_argv argv;
351 351 };
352 352
353 353 struct nss_innetgr_args {
354 354 /* in: */
355 355 struct nss_innetgr_1arg arg[NSS_NETGR_N];
356 356 struct nss_innetgr_1arg groups;
357 357 /* out: */
358 358 enum nss_netgr_status status;
359 359 };
360 360
361 361 /*
362 362 * nss_XbyY_buf_t -- structure containing the generic arguments passwd to
363 363 * getXXXbyYYY_r() and getXXXent_r() routines. The (void *) value points to
364 364 * a struct of the appropriate type, e.g. struct passwd or struct hostent.
365 365 *
366 366 * The functions that allocate and free these structures do no locking at
367 367 * all, since the routines that use them are inherently MT-unsafe anyway.
368 368 */
369 369
370 370 typedef struct {
371 371 void *result; /* "result" parameter to getXbyY_r() */
372 372 char *buffer; /* "buffer" " " */
373 373 int buflen; /* "buflen" " " */
374 374 } nss_XbyY_buf_t;
375 375
376 376 extern nss_XbyY_buf_t *_nss_XbyY_buf_alloc(int struct_size, int buffer_size);
377 377 extern void _nss_XbyY_buf_free(nss_XbyY_buf_t *);
378 378
379 379 #define NSS_XbyY_ALLOC(bufpp, str_size, buf_size) (\
380 380 (*bufpp) == 0 \
381 381 ? (*bufpp) = _nss_XbyY_buf_alloc(str_size, buf_size) \
382 382 : (*bufpp))
383 383
384 384 #define NSS_XbyY_FREE(bufpp) (_nss_XbyY_buf_free(*bufpp), (*bufpp) = 0)
385 385
386 386 /*
387 387 * The nss_XbyY_args_t struct contains all the information passed between
388 388 * frontends and backends for the getXbyY_r() and getXent() routines,
389 389 * including an nss_XbyY_buf_t and the lookup key (unused for getXXXent_r).
390 390 *
391 391 * The (*str2ent)() member converts a single XXXent from ASCII text to the
392 392 * appropriate struct, storing any pointer data (strings, in_addrs, arrays
393 393 * of these) in the buffer. The ASCII text is a counted string (*not* a
394 394 * zero-terminated string) whose length is specified by the instr_len
395 395 * parameter. The text is found at the address specified by instr and
396 396 * the string is treated as readonly. buffer and instr must be non-
397 397 * intersecting memory areas.
398 398 *
399 399 * With the exception of passwd, shadow and group, the text form for these
400 400 * databases allows trailing comments and arbitrary whitespace. The
401 401 * corresponding str2ent routine assumes that comments, leading whitespace
402 402 * and trailing whitespace have been stripped (and thus assumes that entries
403 403 * consisting only of these have been discarded).
404 404 *
405 405 * The text entries for "rpc" and for the databases described in <netdb.h>
406 406 * follow a common format (a canonical name with a possibly empty list
407 407 * of aliases, and some other value), albeit with minor variations.
408 408 * The function _nss_netdb_aliases() does most of the generic work involved
409 409 * in parsing and marshalling these into the buffer.
410 410 */
411 411
412 412 typedef union nss_XbyY_key { /* No tag; backend should know what to expect */
413 413 uid_t uid;
414 414 gid_t gid;
415 415 projid_t projid;
416 416 const char *name;
417 417 int number;
418 418 struct {
419 419 int net;
420 420 int type;
421 421 } netaddr;
422 422 struct {
423 423 const char *addr;
424 424 int len;
425 425 int type;
426 426 } hostaddr;
427 427 struct {
428 428 union {
429 429 const char *name;
430 430 int port;
431 431 } serv;
432 432 const char *proto;
433 433 } serv;
434 434 void *ether;
435 435 struct {
436 436 const char *name;
437 437 const char *keytype;
438 438 } pkey;
439 439 struct {
440 440 const char *name;
441 441 int af_family;
442 442 int flags;
443 443 } ipnode;
444 444 void *attrp; /* for the new attr databases */
445 445 } nss_XbyY_key_t;
446 446
447 447
448 448 typedef int (*nss_key2str_t)(void *buffer, size_t buflen,
449 449 nss_XbyY_key_t *key, size_t *len);
450 450
451 451
452 452 typedef struct nss_XbyY_args {
453 453
454 454 /* IN */
455 455 nss_XbyY_buf_t buf;
456 456 int stayopen;
457 457 /*
458 458 * Support for setXXXent(stayopen)
459 459 * Used only in hosts, protocols,
460 460 * networks, rpc, and services.
461 461 */
462 462 nss_str2ent_t str2ent;
463 463 union nss_XbyY_key key;
464 464
465 465 /* OUT */
466 466 void *returnval;
467 467 int erange;
468 468 int h_errno; /* For gethost*_r() */
469 469 nss_status_t status; /* from the backend last called */
470 470 /* NSS2 */
471 471 nss_key2str_t key2str; /* IN */
472 472 size_t returnlen; /* OUT */
473 473
474 474 /* NSCD/DOOR data */
475 475
476 476 /* ... buffer arena follows... */
477 477 } nss_XbyY_args_t;
478 478
479 479
480 480
481 481 /*
482 482 * nss/nscd v2 interface, packed buffer format
483 483 *
484 484 * A key component of the v2 name service switch is the redirection
485 485 * of all activity to nscd for actual processing. In the original
486 486 * switch most activity took place in each application, and the nscd
487 487 * cache component was an add-on optional interface.
488 488 *
489 489 * The nscd v1 format was a completely private interface that
490 490 * implemented specific bufferiing formats on a per getXbyY API basis.
491 491 *
492 492 * The nss/nscd v2 interface uses a common header and commonalizes
493 493 * the buffering format as consistently as possible. The general rule
494 494 * of thumb is that backends are required to assemble their results in
495 495 * "files based" format [IE the format used on a per result basis as
496 496 * returned by the files backend] and then call the standard str2ent
497 497 * interface. This is the original intended design as used in the files
498 498 * and nis backends.
499 499 *
500 500 * The benefit of this is that the application side library can assemble
501 501 * a request and provide a header and a variable length result buffer via
502 502 * a doors API, and then the nscd side switch can assemble a a getXbyY
503 503 * request providing the result buffer and a str2ent function that copies
504 504 * but does not unpack the result.
505 505 *
506 506 * This results is returned back via the door, and unpacked using the
507 507 * native library side str2ent interface.
508 508 *
509 509 * Additionally, the common header allows extensibility to add new
510 510 * getXbyYs, putXbyYs or other maintenance APIs to/from nscd without
511 511 * changing the existing "old style" backend interfaces.
512 512 *
513 513 * Finally new style getXbyY, putXbyY and backend interfaces can be
514 514 * by adding new operation requests to the header, while old style
515 515 * backwards compatability.
516 516 */
517 517
518 518 /*
519 519 * nss/nscd v2 callnumber definitions
520 520 */
521 521
522 522 /*
523 523 * callnumbers are separated by categories, such as:
524 524 * application to nscd requests, nscd to nscd requests,
525 525 * smf to nscd requests, etc.
526 526 */
527 527
528 528 #define NSCDV2CATMASK (0xFF000000)
529 529 #define NSCDV2CALLMASK (0x00FFFFFF)
530 530
531 531 /*
532 532 * nss/nscd v2 categories
533 533 */
534 534
535 535 #define NSCD_CALLCAT_APP ('a'<<24)
536 536 #define NSCD_CALLCAT_N2N ('n'<<24)
537 537
538 538 /* nscd v2 app-> nscd callnumbers */
539 539
540 540 #define NSCD_SEARCH (NSCD_CALLCAT_APP|0x01)
541 541 #define NSCD_SETENT (NSCD_CALLCAT_APP|0x02)
542 542 #define NSCD_GETENT (NSCD_CALLCAT_APP|0x03)
543 543 #define NSCD_ENDENT (NSCD_CALLCAT_APP|0x04)
544 544 #define NSCD_PUT (NSCD_CALLCAT_APP|0x05)
545 545 #define NSCD_GETHINTS (NSCD_CALLCAT_APP|0x06)
546 546
547 547 /* nscd v2 SETENT cookie markers */
548 548
549 549 #define NSCD_NEW_COOKIE 0
550 550 #define NSCD_LOCAL_COOKIE 1
551 551
552 552 /* nscd v2 header revision */
553 553 /* treated as 0xMMMMmmmm MMMM - Major Rev, mmmm - Minor Rev */
554 554
555 555 #define NSCD_HEADER_REV 0x00020000
556 556
557 557 /*
558 558 * ptr/uint data type used to calculate shared nscd buffer struct sizes
559 559 * sizes/offsets are arbitrarily limited to 32 bits for 32/64 compatibility
560 560 * datatype is 64 bits for possible pointer storage and future use
561 561 */
562 562
563 563 typedef uint64_t nssuint_t;
564 564
565 565 /*
566 566 * nscd v2 buffer layout overview
567 567 *
568 568 * The key interface to nscd moving forward is the doors interface
569 569 * between applications and nscd (NSCD_CALLCAT_APP), and nscd and
570 570 * it's children (NSCD_CALLCAT_N2N).
571 571 *
572 572 * Regardless of the interface used, the buffer layout is consistent.
573 573 * The General Layout is:
574 574 * [nss_pheader_t][IN key][OUT data results]{extend results}
575 575 *
576 576 * The header (nss_pheader_t) remains constant.
577 577 * Keys and key layouts vary between call numbers/requests
578 578 * NSCD_CALLCAT_APP use key layouts mimics/defines in nss_dbdefs.h
579 579 * NSCD_CALLCAT_NSN use layouts defined by nscd headers
580 580 * Data and data results vary between results
581 581 * NSCD_CALLCAT_APP return "file standard format" output buffers
582 582 * NSCD_CALLCAT_NSN return data defined by nscd headers
583 583 * extended results are optional and vary
584 584 *
585 585 */
586 586
587 587 /*
588 588 * nss_pheader_t -- buffer header structure that contains switch data
589 589 * "packed" by the client into a buffer suitable for transport over
590 590 * nscd's door, and that can be unpacked into a native form within
591 591 * nscd's switch. Capable of packing and unpacking data ans results.
592 592 *
593 593 * NSCD_HEADER_REV: 0x00020000 16 x uint64 = (128 byte header)
594 594 */
595 595
596 596 typedef struct {
597 597 uint32_t nsc_callnumber; /* packed buffer request */
598 598 uint32_t nss_dbop; /* old nss dbop */
599 599 uint32_t p_ruid; /* real uid */
600 600 uint32_t p_euid; /* effective uid */
601 601 uint32_t p_version; /* 0xMMMMmmmm Major/minor */
602 602 uint32_t p_status; /* nss_status_t */
603 603 uint32_t p_errno; /* errno */
604 604 uint32_t p_herrno; /* h_errno */
605 605 nssuint_t libpriv; /* reserved (for lib/client) */
606 606 nssuint_t pbufsiz; /* buffer size */
607 607 nssuint_t dbd_off; /* IN: db desc off */
608 608 nssuint_t dbd_len; /* IN: db desc len */
609 609 nssuint_t key_off; /* IN: key off */
610 610 nssuint_t key_len; /* IN: key len */
611 611 nssuint_t data_off; /* OUT: data off */
612 612 nssuint_t data_len; /* OUT: data len */
613 613 nssuint_t ext_off; /* OUT: extended results off */
614 614 nssuint_t ext_len; /* OUT: extended results len */
615 615 nssuint_t nscdpriv; /* reserved (for nscd) */
616 616 nssuint_t reserved1; /* reserved (TBD) */
617 617 } nss_pheader_t;
618 618
619 619 /*
620 620 * nss_pnetgr_t -- packed offset structure for holding keys used
621 621 * by innetgr (__multi_innetgr) key
622 622 * Key format is:
623 623 * nss_pnetgr_t
624 624 * (nssuint_t)[machine_argc] offsets to strings
625 625 * (nssuint_t)[user_argc] offsets to strings
626 626 * (nssuint_t)[domain_argc] offsets to strings
627 627 * (nssuint_t)[groups_argc] offsets to strings
628 628 * machine,user,domain,groups strings
629 629 */
630 630
631 631 typedef struct {
632 632 uint32_t machine_argc;
633 633 uint32_t user_argc;
634 634 uint32_t domain_argc;
635 635 uint32_t groups_argc;
636 636 nssuint_t machine_offv;
637 637 nssuint_t user_offv;
638 638 nssuint_t domain_offv;
639 639 nssuint_t groups_offv;
640 640 } nss_pnetgr_t;
641 641
642 642
643 643 /* status returned by the str2ent parsing routines */
644 644 #define NSS_STR_PARSE_SUCCESS 0
645 645 #define NSS_STR_PARSE_PARSE 1
646 646 #define NSS_STR_PARSE_ERANGE 2
647 647
648 648 #define NSS_XbyY_INIT(str, res, bufp, len, func) (\
649 649 (str)->buf.result = (res), \
650 650 (str)->buf.buffer = (bufp), \
651 651 (str)->buf.buflen = (len), \
652 652 (str)->stayopen = 0, \
653 653 (str)->str2ent = (func), \
654 654 (str)->key2str = NULL, \
655 655 (str)->returnval = 0, \
656 656 (str)->returnlen = 0, \
657 657 (str)->h_errno = 0, \
658 658 (str)->erange = 0)
659 659
660 660 #define NSS_XbyY_INIT_EXT(str, res, bufp, len, func, kfunc) (\
661 661 (str)->buf.result = (res), \
↓ open down ↓ |
661 lines elided |
↑ open up ↑ |
662 662 (str)->buf.buffer = (bufp), \
663 663 (str)->buf.buflen = (len), \
664 664 (str)->stayopen = 0, \
665 665 (str)->str2ent = (func), \
666 666 (str)->key2str = (kfunc), \
667 667 (str)->returnval = 0, \
668 668 (str)->returnlen = 0, \
669 669 (str)->h_errno = 0, \
670 670 (str)->erange = 0)
671 671
672 -#define NSS_XbyY_FINI(str) (\
673 - (str)->returnval == 0 && (str)->erange && (errno = ERANGE), \
674 - (str)->returnval)
672 +#define NSS_XbyY_FINI(str) _nss_XbyY_fini(str)
675 673
676 674 #define NSS_PACKED_CRED_CHECK(buf, ruid, euid) (\
677 675 ((nss_pheader_t *)(buf))->p_ruid == (ruid) && \
678 676 ((nss_pheader_t *)(buf))->p_euid == (euid))
679 677
678 +extern void *_nss_XbyY_fini(nss_XbyY_args_t *);
680 679 extern char **_nss_netdb_aliases(const char *, int, char *, int);
681 680 extern nss_status_t nss_default_key2str(void *, size_t, nss_XbyY_args_t *,
682 681 const char *, int, size_t *);
683 682 extern nss_status_t nss_packed_arg_init(void *, size_t, nss_db_root_t *,
684 683 nss_db_initf_t *, int *,
685 684 nss_XbyY_args_t *);
686 685 extern nss_status_t nss_packed_context_init(void *, size_t, nss_db_root_t *,
687 686 nss_db_initf_t *, nss_getent_t **,
688 687 nss_XbyY_args_t *);
689 688 extern void nss_packed_set_status(void *, size_t, nss_status_t,
690 689 nss_XbyY_args_t *);
691 690 extern nss_status_t nss_packed_getkey(void *, size_t, char **, int *,
692 691 nss_XbyY_args_t *);
693 692
694 693 /*
695 694 * nss_dbop_t values for searches with various keys; values for
696 695 * destructor/endent/setent/getent are defined in <nss_common.h>
697 696 */
698 697
699 698 /*
700 699 * These are part of the "Over the wire" IE app->nscd getXbyY
701 700 * op for well known getXbyY's. Cannot use NSS_DBOP_X_Y directly
702 701 * because NSS_DBOP_next_iter is NOT an incrementing counter value
703 702 * it's a starting offset into an array value.
704 703 */
705 704
706 705 #define NSS_DBOP_X(x) ((x)<<16)
707 706 #define NSS_DBOP_XY(x, y) ((x)|(y))
708 707
709 708 #define NSS_DBOP_ALIASES NSS_DBOP_X(1)
710 709 #define NSS_DBOP_AUTOMOUNT NSS_DBOP_X(2)
711 710 #define NSS_DBOP_BOOTPARAMS NSS_DBOP_X(3)
712 711 #define NSS_DBOP_ETHERS NSS_DBOP_X(4)
713 712 #define NSS_DBOP_GROUP NSS_DBOP_X(5)
714 713 #define NSS_DBOP_HOSTS NSS_DBOP_X(6)
715 714 #define NSS_DBOP_IPNODES NSS_DBOP_X(7)
716 715 #define NSS_DBOP_NETGROUP NSS_DBOP_X(8)
717 716 #define NSS_DBOP_NETMASKS NSS_DBOP_X(9)
718 717 #define NSS_DBOP_NETWORKS NSS_DBOP_X(10)
719 718 #define NSS_DBOP_PASSWD NSS_DBOP_X(11)
720 719 #define NSS_DBOP_PRINTERS NSS_DBOP_X(12)
721 720 #define NSS_DBOP_PROJECT NSS_DBOP_X(13)
722 721 #define NSS_DBOP_PROTOCOLS NSS_DBOP_X(14)
723 722 #define NSS_DBOP_PUBLICKEY NSS_DBOP_X(15)
724 723 #define NSS_DBOP_RPC NSS_DBOP_X(16)
725 724 #define NSS_DBOP_SERVICES NSS_DBOP_X(17)
726 725 #define NSS_DBOP_AUDITUSER NSS_DBOP_X(18)
727 726 #define NSS_DBOP_AUTHATTR NSS_DBOP_X(19)
728 727 #define NSS_DBOP_EXECATTR NSS_DBOP_X(20)
729 728 #define NSS_DBOP_PROFATTR NSS_DBOP_X(21)
730 729 #define NSS_DBOP_USERATTR NSS_DBOP_X(22)
731 730
732 731 #define NSS_DBOP_GROUP_BYNAME (NSS_DBOP_next_iter)
733 732 #define NSS_DBOP_GROUP_BYGID (NSS_DBOP_GROUP_BYNAME + 1)
734 733 #define NSS_DBOP_GROUP_BYMEMBER (NSS_DBOP_GROUP_BYGID + 1)
735 734
736 735 #define NSS_DBOP_PASSWD_BYNAME (NSS_DBOP_next_iter)
737 736 #define NSS_DBOP_PASSWD_BYUID (NSS_DBOP_PASSWD_BYNAME + 1)
738 737
739 738 /* The "compat" backend requires that PASSWD_BYNAME == SHADOW_BYNAME */
740 739 /* (it also requires that both use key.name to pass the username). */
741 740 #define NSS_DBOP_SHADOW_BYNAME (NSS_DBOP_PASSWD_BYNAME)
742 741
743 742 #define NSS_DBOP_PROJECT_BYNAME (NSS_DBOP_next_iter)
744 743 #define NSS_DBOP_PROJECT_BYID (NSS_DBOP_PROJECT_BYNAME + 1)
745 744
746 745 #define NSS_DBOP_HOSTS_BYNAME (NSS_DBOP_next_iter)
747 746 #define NSS_DBOP_HOSTS_BYADDR (NSS_DBOP_HOSTS_BYNAME + 1)
748 747
749 748 #define NSS_DBOP_IPNODES_BYNAME (NSS_DBOP_next_iter)
750 749 #define NSS_DBOP_IPNODES_BYADDR (NSS_DBOP_IPNODES_BYNAME + 1)
751 750
752 751 /*
753 752 * NSS_DBOP_NAME_2ADDR
754 753 * NSS_DBOP_ADDR_2NAME
755 754 * : are defines for ipv6 api's
756 755 */
757 756
758 757 #define NSS_DBOP_NAME_2ADDR (NSS_DBOP_next_ipv6_iter)
759 758 #define NSS_DBOP_ADDR_2NAME (NSS_DBOP_NAME_2ADDR + 1)
760 759
761 760 #define NSS_DBOP_RPC_BYNAME (NSS_DBOP_next_iter)
762 761 #define NSS_DBOP_RPC_BYNUMBER (NSS_DBOP_RPC_BYNAME + 1)
763 762
764 763 #define NSS_DBOP_NETWORKS_BYNAME (NSS_DBOP_next_iter)
765 764 #define NSS_DBOP_NETWORKS_BYADDR (NSS_DBOP_NETWORKS_BYNAME + 1)
766 765
767 766 #define NSS_DBOP_SERVICES_BYNAME (NSS_DBOP_next_iter)
768 767 #define NSS_DBOP_SERVICES_BYPORT (NSS_DBOP_SERVICES_BYNAME + 1)
769 768
770 769 #define NSS_DBOP_PROTOCOLS_BYNAME (NSS_DBOP_next_iter)
771 770 #define NSS_DBOP_PROTOCOLS_BYNUMBER (NSS_DBOP_PROTOCOLS_BYNAME + 1)
772 771
773 772 #define NSS_DBOP_ETHERS_HOSTTON (NSS_DBOP_next_noiter)
774 773 #define NSS_DBOP_ETHERS_NTOHOST (NSS_DBOP_ETHERS_HOSTTON + 1)
775 774
776 775 #define NSS_DBOP_BOOTPARAMS_BYNAME (NSS_DBOP_next_noiter)
777 776 #define NSS_DBOP_NETMASKS_BYNET (NSS_DBOP_next_noiter)
778 777
779 778 #define NSS_DBOP_PRINTERS_BYNAME (NSS_DBOP_next_iter)
780 779
781 780 /*
782 781 * The "real" backend for netgroup (__multi_innetgr, setnetgrent)
783 782 */
784 783 #define NSS_DBOP_NETGROUP_IN (NSS_DBOP_next_iter)
785 784 #define NSS_DBOP_NETGROUP_SET (NSS_DBOP_NETGROUP_IN + 1)
786 785
787 786 /*
788 787 * The backend for getpublickey and getsecretkey (getkeys)
789 788 */
790 789 #define NSS_DBOP_KEYS_BYNAME (NSS_DBOP_next_iter)
791 790
792 791 /*
793 792 * The pseudo-backend for netgroup (returned by setnetgrent) doesn't have
794 793 * any getXXXbyYYY operations, just the usual destr/end/set/get ops,
795 794 * so needs no definitions here.
796 795 */
797 796
798 797 #define NSS_DBOP_ATTRDB_BYNAME (NSS_DBOP_next_iter)
799 798
800 799 #define NSS_DBOP_AUDITUSER_BYNAME NSS_DBOP_ATTRDB_BYNAME
801 800 #define NSS_DBOP_AUTHATTR_BYNAME NSS_DBOP_ATTRDB_BYNAME
802 801 #define NSS_DBOP_EXECATTR_BYNAME NSS_DBOP_ATTRDB_BYNAME
803 802 #define NSS_DBOP_EXECATTR_BYID (NSS_DBOP_EXECATTR_BYNAME + 1)
804 803 #define NSS_DBOP_EXECATTR_BYNAMEID (NSS_DBOP_EXECATTR_BYID + 1)
805 804 #define NSS_DBOP_PROFATTR_BYNAME NSS_DBOP_ATTRDB_BYNAME
806 805 #define NSS_DBOP_USERATTR_BYNAME NSS_DBOP_ATTRDB_BYNAME
807 806
808 807 #define NSS_DBOP_TSOL_TP_BYNAME (NSS_DBOP_next_iter)
809 808 #define NSS_DBOP_TSOL_RH_BYADDR (NSS_DBOP_next_iter)
810 809 #define NSS_DBOP_TSOL_ZC_BYNAME (NSS_DBOP_next_iter)
811 810
812 811 /*
813 812 * Used all over in the switch code. The best home for it I can think of.
814 813 * Power-of-two alignments only.
815 814 */
816 815 #define ROUND_DOWN(n, align) (((uintptr_t)n) & ~((align) - 1l))
817 816 #define ROUND_UP(n, align) ROUND_DOWN(((uintptr_t)n) + (align) - 1l, \
818 817 (align))
819 818
820 819 #ifdef __cplusplus
821 820 }
822 821 #endif
823 822
824 823 #endif /* _NSS_DBDEFS_H */
↓ open down ↓ |
135 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX