3 * shadow database for nss_nonlocal proxy.
5 * Copyright © 2007–2010 Anders Kaseorg <andersk@mit.edu>
7 * This file is part of nss_nonlocal.
9 * nss_nonlocal is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * nss_nonlocal is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with nss_nonlocal; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include <sys/types.h>
38 #include "nsswitch-internal.h"
43 nss_shadow_nonlocal_database(void)
45 static service_user *nip = NULL;
47 __nss_database_lookup("shadow_nonlocal", NULL, "", &nip);
53 static service_user *spent_nip = NULL;
54 static void *spent_fct_start;
56 enum nss_status (*l)(struct spwd *pwd, char *buffer, size_t buflen,
60 static const char *spent_fct_name = "getspent_r";
63 _nss_nonlocal_setspent(int stayopen)
65 static const char *fct_name = "setspent";
66 static void *fct_start = NULL;
67 enum nss_status status;
70 enum nss_status (*l)(int stayopen);
74 nip = nss_shadow_nonlocal_database();
76 return NSS_STATUS_UNAVAIL;
77 if (fct_start == NULL)
78 fct_start = __nss_lookup_function(nip, fct_name);
82 status = NSS_STATUS_UNAVAIL;
84 status = DL_CALL_FCT(fct.l, (stayopen));
85 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);
86 if (status != NSS_STATUS_SUCCESS)
90 if (spent_fct_start == NULL)
91 spent_fct_start = __nss_lookup_function(nip, spent_fct_name);
92 spent_fct.ptr = spent_fct_start;
93 return NSS_STATUS_SUCCESS;
97 _nss_nonlocal_endspent(void)
99 static const char *fct_name = "endspent";
100 static void *fct_start = NULL;
101 enum nss_status status;
104 enum nss_status (*l)(void);
110 nip = nss_shadow_nonlocal_database();
112 return NSS_STATUS_UNAVAIL;
113 if (fct_start == NULL)
114 fct_start = __nss_lookup_function(nip, fct_name);
118 status = NSS_STATUS_UNAVAIL;
120 status = DL_CALL_FCT(fct.l, ());
121 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);
126 _nss_nonlocal_getspent_r(struct spwd *pwd, char *buffer, size_t buflen,
129 enum nss_status status;
130 if (spent_nip == NULL) {
131 status = _nss_nonlocal_setspent(0);
132 if (status != NSS_STATUS_SUCCESS)
136 if (spent_fct.ptr == NULL)
137 status = NSS_STATUS_UNAVAIL;
139 status = DL_CALL_FCT(spent_fct.l, (pwd, buffer, buflen, errnop));
140 if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
143 if (status == NSS_STATUS_SUCCESS)
144 return NSS_STATUS_SUCCESS;
145 } while (__nss_next(&spent_nip, spent_fct_name, &spent_fct.ptr, status, 0) == 0);
148 return NSS_STATUS_NOTFOUND;
153 _nss_nonlocal_getspnam_r(const char *name, struct spwd *pwd,
154 char *buffer, size_t buflen, int *errnop)
156 static const char *fct_name = "getspnam_r";
157 static void *fct_start = NULL;
158 enum nss_status status;
161 enum nss_status (*l)(const char *name, struct spwd *pwd,
162 char *buffer, size_t buflen, int *errnop);
166 nip = nss_shadow_nonlocal_database();
168 return NSS_STATUS_UNAVAIL;
169 if (fct_start == NULL)
170 fct_start = __nss_lookup_function(nip, fct_name);
174 status = NSS_STATUS_UNAVAIL;
176 status = DL_CALL_FCT(fct.l, (name, pwd, buffer, buflen, errnop));
177 if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
179 } while (__nss_next(&nip, fct_name, &fct.ptr, status, 0) == 0);
180 if (status != NSS_STATUS_SUCCESS)
183 if (strcmp(name, pwd->sp_namp) != 0) {
184 syslog(LOG_ERR, "nss_nonlocal: discarding shadow %s from lookup for shadow %s\n", pwd->sp_namp, name);
185 return NSS_STATUS_NOTFOUND;
188 return NSS_STATUS_SUCCESS;