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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 *
28 * NOTE: The interfaces documented in this file may change in a minor
29 * release. It is intended that in the future a stronger committment
30 * will be made to these interface definitions which will guarantee
31 * them across minor releases.
32 */
33
34 #ifndef _NSS_COMMON_H
35 #define _NSS_COMMON_H
36
37 #pragma ident "%Z%%M% %I% %E% SMI"
38
39 #include <synch.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*
46 * The name-service switch
47 * -----------------------
48 *
49 * From nsswitch.conf(4):
50 *
51 * The operating system uses a number of "databases" of information
52 * about hosts, users (passwd/shadow), groups and so forth. Data for
53 * these can come from a variety of "sources": host-names and
54 * -addresses, for example, may be found in /etc/hosts, NIS, NIS+ or
55 * DNS. One or more sources may be used for each database; the
56 * sources and their lookup order are specified in the
57 * /etc/nsswitch.conf file.
58 *
231 * may use this as a status flag and maintain additional error or status
232 * information elsewhere in other private nscd data. This status value
233 * is for nscd private/internal use only.
234 */
235
236 typedef enum {
237 NSS_SUCCESS = 0,
238 NSS_NOTFOUND = 1,
239 NSS_UNAVAIL = 2,
240 NSS_TRYAGAIN = 3,
241 NSS_NISSERVDNS_TRYAGAIN = 4,
242 NSS_TRYLOCAL = 5,
243 NSS_ERROR = 6,
244 NSS_ALTRETRY = 7,
245 NSS_ALTRESET = 8,
246 NSS_NSCD_PRIV = 9
247 } nss_status_t;
248
249 struct nss_backend;
250
251 #if defined(__STDC__)
252 typedef nss_status_t (*nss_backend_op_t)(struct nss_backend *, void *args);
253 #else
254 typedef nss_status_t (*nss_backend_op_t)();
255 #endif
256
257 struct nss_backend {
258 nss_backend_op_t *ops;
259 int n_ops;
260 };
261 typedef struct nss_backend nss_backend_t;
262 typedef int nss_dbop_t;
263
264 #define NSS_DBOP_DESTRUCTOR 0
265 #define NSS_DBOP_ENDENT 1
266 #define NSS_DBOP_SETENT 2
267 #define NSS_DBOP_GETENT 3
268 #define NSS_DBOP_next_iter (NSS_DBOP_GETENT + 1)
269 #define NSS_DBOP_next_noiter (NSS_DBOP_DESTRUCTOR + 1)
270 #define NSS_DBOP_next_ipv6_iter (NSS_DBOP_GETENT + 3)
271
272 #define NSS_LOOKUP_DBOP(instp, n) \
273 (((n) >= 0 && (n) < (instp)->n_ops) ? (instp)->ops[n] : 0)
274
275 #define NSS_INVOKE_DBOP(instp, n, argp) (\
278 : NSS_UNAVAIL)
279
280 /*
281 * Locating and instantiating backends
282 * -----------------------------------
283 *
284 * To perform step (a), the switch consults a list of backend-finder routines,
285 * passing a <database, source> pair.
286 *
287 * There is a standard backend-finder; frontends may augment or replace this
288 * in order to, say, indicate that some backends are "compiled in" with the
289 * frontend.
290 *
291 * Backend-finders return a pointer to a constructor function for the backend.
292 * (or NULL if they can't find the backend). The switch engine caches these
293 * function pointers; when it needs to perform step (b), it calls the
294 * constructor function, which returns a pointer to a new instance of the
295 * backend, properly initialized (or returns NULL).
296 */
297
298 #if defined(__STDC__)
299 typedef nss_backend_t *(*nss_backend_constr_t)(const char *db_name,
300 const char *src_name,
301 /* Hook for (unimplemented) args in nsswitch.conf */ const char *cfg_args);
302 #else
303 typedef nss_backend_t *(*nss_backend_constr_t)();
304 #endif
305
306 struct nss_backend_finder {
307 #if defined(__STDC__)
308 nss_backend_constr_t (*lookup)
309 (void *lkp_priv, const char *, const char *, void **del_privp);
310 void (*delete)
311 (void *del_priv, nss_backend_constr_t);
312 #else
313 nss_backend_constr_t (*lookup)();
314 void (*delete)();
315 #endif
316 struct nss_backend_finder *next;
317 void *lookup_priv;
318 };
319
320 typedef struct nss_backend_finder nss_backend_finder_t;
321
322 extern nss_backend_finder_t *nss_default_finders;
323
324 /*
325 * Frontend parameters
326 * -------------------
327 *
328 * The frontend must tell the switch engine:
329 * - the database name,
330 * - the compiled-in default configuration entry.
331 * It may also override default values for:
332 * - the database name to use when looking up the configuration
333 * information (e.g. "shadow" uses the config entry for "passwd"),
334 * - a limit on the number of instances of each backend that are
335 * simultaneously active,
358 */
359
360 enum nss_dbp_flags {
361 NSS_USE_DEFAULT_CONFIG = 0x1
362 };
363
364 struct nss_db_params {
365 const char *name; /* Mandatory: database name */
366 const char *config_name; /* config-file database name */
367 const char *default_config; /* Mandatory: default config */
368 unsigned max_active_per_src;
369 unsigned max_dormant_per_src;
370 enum nss_dbp_flags flags;
371 nss_backend_finder_t *finders;
372 void *private; /* Not used by switch */
373 void (*cleanup)(struct nss_db_params *);
374 };
375
376 typedef struct nss_db_params nss_db_params_t;
377
378 #if defined(__STDC__)
379 typedef void (*nss_db_initf_t)(nss_db_params_t *);
380 #else
381 typedef void (*nss_db_initf_t)();
382 #endif
383
384 /*
385 * DBD param offsets in NSS2 nscd header.
386 * Offsets are relative to beginning of dbd section.
387 * 32 bit offsets should be sufficient, forever.
388 * 0 offset == NULL
389 * flags == nss_dbp_flags
390 */
391 typedef struct nss_dbd {
392 uint32_t o_name;
393 uint32_t o_config_name;
394 uint32_t o_default_config;
395 uint32_t flags;
396 } nss_dbd_t;
397
398 /*
399 * These structures are defined inside the implementation of the switch
400 * engine; the interface just holds pointers to them.
401 */
402 struct nss_db_state;
434 */
435
436 typedef enum {
437 NSS_CONFIG_GET,
438 NSS_CONFIG_PUT,
439 NSS_CONFIG_ADD,
440 NSS_CONFIG_DELETE,
441 NSS_CONFIG_LIST
442 } nss_config_op_t;
443
444 struct nss_config {
445 char *name;
446 nss_config_op_t cop;
447 mutex_t *lock;
448 void *buffer;
449 size_t length;
450 };
451 typedef struct nss_config nss_config_t;
452
453
454 #if defined(__STDC__)
455 extern nss_status_t nss_config(nss_config_t **, int);
456
457 extern nss_status_t nss_search(nss_db_root_t *, nss_db_initf_t,
458 int search_fnum, void *search_args);
459 extern nss_status_t nss_getent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *,
460 void *getent_args);
461 extern void nss_setent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
462 extern void nss_endent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
463 extern void nss_delete(nss_db_root_t *);
464
465 extern nss_status_t nss_pack(void *, size_t, nss_db_root_t *,
466 nss_db_initf_t, int, void *);
467 extern nss_status_t nss_pack_ent(void *, size_t, nss_db_root_t *,
468 nss_db_initf_t, nss_getent_t *);
469 extern nss_status_t nss_unpack(void *, size_t, nss_db_root_t *,
470 nss_db_initf_t, int, void *);
471 extern nss_status_t nss_unpack_ent(void *, size_t, nss_db_root_t *,
472 nss_db_initf_t, nss_getent_t *, void *);
473
474 extern nss_status_t _nsc_search(nss_db_root_t *, nss_db_initf_t,
475 int search_fnum, void *search_args);
476 extern nss_status_t _nsc_getent_u(nss_db_root_t *, nss_db_initf_t,
477 nss_getent_t *, void *getent_args);
478 extern nss_status_t _nsc_setent_u(nss_db_root_t *, nss_db_initf_t,
479 nss_getent_t *);
480 extern nss_status_t _nsc_endent_u(nss_db_root_t *, nss_db_initf_t,
481 nss_getent_t *);
482
483 #else
484 extern nss_status_t nss_config();
485
486 extern nss_status_t nss_search();
487 extern nss_status_t nss_getent();
488 extern void nss_setent();
489 extern void nss_endent();
490 extern void nss_delete();
491
492 extern int nss_pack();
493 extern int nss_pack_ent();
494 extern int nss_unpack();
495 extern int nss_unpack_ent();
496
497 extern nss_status_t _nsc_search();
498 extern nss_status_t _nsc_getent_u();
499 extern nss_status_t _nsc_setent_u();
500 extern nss_status_t _nsc_endent_u();
501 #endif
502
503 #ifdef __cplusplus
504 }
505 #endif
506
507 #endif /* _NSS_COMMON_H */
|
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 2014 Garrett D'Amore <garrett@damore.org>
23 *
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /*
29 *
30 * NOTE: The interfaces documented in this file may change in a minor
31 * release. It is intended that in the future a stronger committment
32 * will be made to these interface definitions which will guarantee
33 * them across minor releases.
34 */
35
36 #ifndef _NSS_COMMON_H
37 #define _NSS_COMMON_H
38
39 #include <synch.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*
46 * The name-service switch
47 * -----------------------
48 *
49 * From nsswitch.conf(4):
50 *
51 * The operating system uses a number of "databases" of information
52 * about hosts, users (passwd/shadow), groups and so forth. Data for
53 * these can come from a variety of "sources": host-names and
54 * -addresses, for example, may be found in /etc/hosts, NIS, NIS+ or
55 * DNS. One or more sources may be used for each database; the
56 * sources and their lookup order are specified in the
57 * /etc/nsswitch.conf file.
58 *
231 * may use this as a status flag and maintain additional error or status
232 * information elsewhere in other private nscd data. This status value
233 * is for nscd private/internal use only.
234 */
235
236 typedef enum {
237 NSS_SUCCESS = 0,
238 NSS_NOTFOUND = 1,
239 NSS_UNAVAIL = 2,
240 NSS_TRYAGAIN = 3,
241 NSS_NISSERVDNS_TRYAGAIN = 4,
242 NSS_TRYLOCAL = 5,
243 NSS_ERROR = 6,
244 NSS_ALTRETRY = 7,
245 NSS_ALTRESET = 8,
246 NSS_NSCD_PRIV = 9
247 } nss_status_t;
248
249 struct nss_backend;
250
251 typedef nss_status_t (*nss_backend_op_t)(struct nss_backend *, void *args);
252
253 struct nss_backend {
254 nss_backend_op_t *ops;
255 int n_ops;
256 };
257 typedef struct nss_backend nss_backend_t;
258 typedef int nss_dbop_t;
259
260 #define NSS_DBOP_DESTRUCTOR 0
261 #define NSS_DBOP_ENDENT 1
262 #define NSS_DBOP_SETENT 2
263 #define NSS_DBOP_GETENT 3
264 #define NSS_DBOP_next_iter (NSS_DBOP_GETENT + 1)
265 #define NSS_DBOP_next_noiter (NSS_DBOP_DESTRUCTOR + 1)
266 #define NSS_DBOP_next_ipv6_iter (NSS_DBOP_GETENT + 3)
267
268 #define NSS_LOOKUP_DBOP(instp, n) \
269 (((n) >= 0 && (n) < (instp)->n_ops) ? (instp)->ops[n] : 0)
270
271 #define NSS_INVOKE_DBOP(instp, n, argp) (\
274 : NSS_UNAVAIL)
275
276 /*
277 * Locating and instantiating backends
278 * -----------------------------------
279 *
280 * To perform step (a), the switch consults a list of backend-finder routines,
281 * passing a <database, source> pair.
282 *
283 * There is a standard backend-finder; frontends may augment or replace this
284 * in order to, say, indicate that some backends are "compiled in" with the
285 * frontend.
286 *
287 * Backend-finders return a pointer to a constructor function for the backend.
288 * (or NULL if they can't find the backend). The switch engine caches these
289 * function pointers; when it needs to perform step (b), it calls the
290 * constructor function, which returns a pointer to a new instance of the
291 * backend, properly initialized (or returns NULL).
292 */
293
294 typedef nss_backend_t *(*nss_backend_constr_t)(const char *db_name,
295 const char *src_name,
296 /* Hook for (unimplemented) args in nsswitch.conf */ const char *cfg_args);
297
298 struct nss_backend_finder {
299 nss_backend_constr_t (*lookup)
300 (void *lkp_priv, const char *, const char *, void **del_privp);
301 void (*delete)
302 (void *del_priv, nss_backend_constr_t);
303 struct nss_backend_finder *next;
304 void *lookup_priv;
305 };
306
307 typedef struct nss_backend_finder nss_backend_finder_t;
308
309 extern nss_backend_finder_t *nss_default_finders;
310
311 /*
312 * Frontend parameters
313 * -------------------
314 *
315 * The frontend must tell the switch engine:
316 * - the database name,
317 * - the compiled-in default configuration entry.
318 * It may also override default values for:
319 * - the database name to use when looking up the configuration
320 * information (e.g. "shadow" uses the config entry for "passwd"),
321 * - a limit on the number of instances of each backend that are
322 * simultaneously active,
345 */
346
347 enum nss_dbp_flags {
348 NSS_USE_DEFAULT_CONFIG = 0x1
349 };
350
351 struct nss_db_params {
352 const char *name; /* Mandatory: database name */
353 const char *config_name; /* config-file database name */
354 const char *default_config; /* Mandatory: default config */
355 unsigned max_active_per_src;
356 unsigned max_dormant_per_src;
357 enum nss_dbp_flags flags;
358 nss_backend_finder_t *finders;
359 void *private; /* Not used by switch */
360 void (*cleanup)(struct nss_db_params *);
361 };
362
363 typedef struct nss_db_params nss_db_params_t;
364
365 typedef void (*nss_db_initf_t)(nss_db_params_t *);
366
367 /*
368 * DBD param offsets in NSS2 nscd header.
369 * Offsets are relative to beginning of dbd section.
370 * 32 bit offsets should be sufficient, forever.
371 * 0 offset == NULL
372 * flags == nss_dbp_flags
373 */
374 typedef struct nss_dbd {
375 uint32_t o_name;
376 uint32_t o_config_name;
377 uint32_t o_default_config;
378 uint32_t flags;
379 } nss_dbd_t;
380
381 /*
382 * These structures are defined inside the implementation of the switch
383 * engine; the interface just holds pointers to them.
384 */
385 struct nss_db_state;
417 */
418
419 typedef enum {
420 NSS_CONFIG_GET,
421 NSS_CONFIG_PUT,
422 NSS_CONFIG_ADD,
423 NSS_CONFIG_DELETE,
424 NSS_CONFIG_LIST
425 } nss_config_op_t;
426
427 struct nss_config {
428 char *name;
429 nss_config_op_t cop;
430 mutex_t *lock;
431 void *buffer;
432 size_t length;
433 };
434 typedef struct nss_config nss_config_t;
435
436
437 extern nss_status_t nss_config(nss_config_t **, int);
438
439 extern nss_status_t nss_search(nss_db_root_t *, nss_db_initf_t,
440 int search_fnum, void *search_args);
441 extern nss_status_t nss_getent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *,
442 void *getent_args);
443 extern void nss_setent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
444 extern void nss_endent(nss_db_root_t *, nss_db_initf_t, nss_getent_t *);
445 extern void nss_delete(nss_db_root_t *);
446
447 extern nss_status_t nss_pack(void *, size_t, nss_db_root_t *,
448 nss_db_initf_t, int, void *);
449 extern nss_status_t nss_pack_ent(void *, size_t, nss_db_root_t *,
450 nss_db_initf_t, nss_getent_t *);
451 extern nss_status_t nss_unpack(void *, size_t, nss_db_root_t *,
452 nss_db_initf_t, int, void *);
453 extern nss_status_t nss_unpack_ent(void *, size_t, nss_db_root_t *,
454 nss_db_initf_t, nss_getent_t *, void *);
455
456 extern nss_status_t _nsc_search(nss_db_root_t *, nss_db_initf_t,
457 int search_fnum, void *search_args);
458 extern nss_status_t _nsc_getent_u(nss_db_root_t *, nss_db_initf_t,
459 nss_getent_t *, void *getent_args);
460 extern nss_status_t _nsc_setent_u(nss_db_root_t *, nss_db_initf_t,
461 nss_getent_t *);
462 extern nss_status_t _nsc_endent_u(nss_db_root_t *, nss_db_initf_t,
463 nss_getent_t *);
464
465
466 #ifdef __cplusplus
467 }
468 #endif
469
470 #endif /* _NSS_COMMON_H */
|