cb16fe1542f422b8110b94fe2da15f324aec1b9b
[platform/upstream/glibc.git] / nss / nsswitch.h
1 /* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 #ifndef _NSSWITCH_H
20 #define _NSSWITCH_H     1
21
22 /* This is an *internal* header.  */
23
24 #include <arpa/nameser.h>
25 #include <netinet/in.h>
26 #include <nss.h>
27 #include <resolv.h>
28 #include <search.h>
29 #include <elf/ldsodefs.h>
30
31
32 /* Actions performed after lookup finished.  */
33 typedef enum
34 {
35   NSS_ACTION_CONTINUE,
36   NSS_ACTION_RETURN
37 } lookup_actions;
38
39
40 typedef struct service_library
41 {
42   /* Name of service (`files', `dns', `nis', ...).  */
43   const char *name;
44   /* Pointer to the loaded shared library.  */
45   void *lib_handle;
46   /* And the link to the next entry.  */
47   struct service_library *next;
48 } service_library;
49
50
51 /* For mapping a function name to a function pointer.  It is known in
52    nsswitch.c:nss_lookup_function that a string pointer for the lookup key
53    is the first member.  */
54 typedef struct
55 {
56   const char *fct_name;
57   void *fct_ptr;
58 } known_function;
59
60
61 typedef struct service_user
62 {
63   /* Name of the service (`files', `dns', `nis', ...).  */
64   const char *name;
65   /* Action according to result.  */
66   lookup_actions actions[5];
67   /* Link to the underlying library object.  */
68   service_library *library;
69   /* Collection of known functions.  */
70   struct entry *known;
71   /* And the link to the next entry.  */
72   struct service_user *next;
73 } service_user;
74
75 /* To access the action based on the status value use this macro.  */
76 #define nss_next_action(ni, status) ((ni)->actions[2 + status])
77
78
79 typedef struct name_database_entry
80 {
81   /* Name of the database.  */
82   const char *name;
83   /* List of service to be used.  */
84   service_user *service;
85   /* And the link to the next entry.  */
86   struct name_database_entry *next;
87 } name_database_entry;
88
89
90 typedef struct name_database
91 {
92   /* List of all known databases.  */
93   name_database_entry *entry;
94   /* List of libraries with service implementation.  */
95   service_library *library;
96 } name_database;
97
98
99 /* Interface functions for NSS.  */
100
101 /* Get the data structure representing the specified database.
102    If there is no configuration for this database in the file,
103    parse a service list from DEFCONFIG and use that.  More
104    than one function can use the database.  */
105 int __nss_database_lookup (const char *database, const char *alternative_name,
106                            const char *defconfig, service_user **ni);
107
108
109 /* Put first function with name FCT_NAME for SERVICE in FCTP.  The
110    position is remembered in NI.  The function returns a value < 0 if
111    an error occurred or no such function exists.  */
112 int __nss_lookup (service_user **ni, const char *fct_name, void **fctp);
113
114 /* Determine the next step in the lookup process according to the
115    result STATUS of the call to the last function returned by
116    `__nss_lookup' or `__nss_next'.  NI specifies the last function
117    examined.  The function return a value > 0 if the process should
118    stop with the last result of the last function call to be the
119    result of the entire lookup.  The returned value is 0 if there is
120    another function to use and < 0 if an error occurred.
121
122    If ALL_VALUES is nonzero, the return value will not be > 0 as long as
123    there is a possibility the lookup process can ever use following
124    services.  In other words, only if all four lookup results have
125    the action RETURN associated the lookup process stops before the
126    natural end.  */
127 int __nss_next (service_user **ni, const char *fct_name, void **fctp,
128                 int status, int all_values);
129
130 /* Search for the service described in NI for a function named FCT_NAME
131    and return a pointer to this function if successful.  */
132 void *__nss_lookup_function (service_user *ni, const char *fct_name);
133
134 #endif  /* nsswitch.h */