3 * shadow database for nss_nonlocal proxy.
5 * Copyright © 2007 Anders Kaseorg <andersk@mit.edu>
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <sys/types.h>
40 #include "nsswitch-internal.h"
45 nss_shadow_nonlocal_database(void)
47 static service_user *nip = NULL;
49 __nss_database_lookup("shadow_nonlocal", NULL, "", &nip);
55 static service_user *spent_nip = NULL;
56 static void *spent_fct_start;
58 enum nss_status (*l)(struct spwd *pwd, char *buffer, size_t buflen,
62 static const char *spent_fct_name = "getspent_r";
65 _nss_nonlocal_setspent(int stayopen)
67 static const char *fct_name = "setspent";
68 static void *fct_start = NULL;
69 enum nss_status status;
72 enum nss_status (*l)(int stayopen);
76 nip = nss_shadow_nonlocal_database();
78 return NSS_STATUS_UNAVAIL;
79 if (fct_start == NULL)
80 fct_start = __nss_lookup_function(nip, fct_name);
84 status = NSS_STATUS_UNAVAIL;
86 status = DL_CALL_FCT(fct.l, (stayopen));
87 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);
88 if (status != NSS_STATUS_SUCCESS)
92 if (spent_fct_start == NULL)
93 spent_fct_start = __nss_lookup_function(nip, spent_fct_name);
94 spent_fct.ptr = spent_fct_start;
95 return NSS_STATUS_SUCCESS;
99 _nss_nonlocal_endspent(void)
101 static const char *fct_name = "endspent";
102 static void *fct_start = NULL;
103 enum nss_status status;
106 enum nss_status (*l)(void);
112 nip = nss_shadow_nonlocal_database();
114 return NSS_STATUS_UNAVAIL;
115 if (fct_start == NULL)
116 fct_start = __nss_lookup_function(nip, fct_name);
120 status = NSS_STATUS_UNAVAIL;
122 status = DL_CALL_FCT(fct.l, ());
123 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);
128 _nss_nonlocal_getspent_r(struct spwd *pwd, char *buffer, size_t buflen,
131 enum nss_status status;
132 if (spent_nip == NULL) {
133 status = _nss_nonlocal_setspent(0);
134 if (status != NSS_STATUS_SUCCESS)
138 if (spent_fct.ptr == NULL)
139 status = NSS_STATUS_UNAVAIL;
141 status = DL_CALL_FCT(spent_fct.l, (pwd, buffer, buflen, errnop));
142 if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
145 if (status == NSS_STATUS_SUCCESS)
146 return NSS_STATUS_SUCCESS;
147 } while (__nss_next(&spent_nip, spent_fct_name, &spent_fct.ptr, status, 0) == 0);
150 return NSS_STATUS_NOTFOUND;
155 _nss_nonlocal_getspnam_r(const char *name, struct spwd *pwd,
156 char *buffer, size_t buflen, int *errnop)
158 static const char *fct_name = "getspnam_r";
159 static void *fct_start = NULL;
160 enum nss_status status;
163 enum nss_status (*l)(const char *name, struct spwd *pwd,
164 char *buffer, size_t buflen, int *errnop);
168 nip = nss_shadow_nonlocal_database();
170 return NSS_STATUS_UNAVAIL;
171 if (fct_start == NULL)
172 fct_start = __nss_lookup_function(nip, fct_name);
176 status = NSS_STATUS_UNAVAIL;
178 status = DL_CALL_FCT(fct.l, (name, pwd, buffer, buflen, errnop));
179 if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
181 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);