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