Lines 1-9
Link Here
|
1 |
#include <errno.h> |
1 |
#include <errno.h> |
|
|
2 |
#include <stdlib.h> |
2 |
#include <sys/param.h> |
3 |
#include <sys/param.h> |
3 |
#include <netinet/in.h> |
4 |
#include <netinet/in.h> |
4 |
#include <pwd.h> |
5 |
#include <pwd.h> |
5 |
#include <grp.h> |
6 |
#include <grp.h> |
6 |
#include <nss.h> |
7 |
#include <nss.h> |
|
|
8 |
#include <nsswitch.h> |
7 |
#include <netdb.h> |
9 |
#include <netdb.h> |
8 |
|
10 |
|
9 |
extern enum nss_status _nss_ldap_getgrent_r(struct group *, char *, size_t, |
11 |
extern enum nss_status _nss_ldap_getgrent_r(struct group *, char *, size_t, |
Lines 14-19
Link Here
|
14 |
size_t, int *); |
16 |
size_t, int *); |
15 |
extern enum nss_status _nss_ldap_setgrent(void); |
17 |
extern enum nss_status _nss_ldap_setgrent(void); |
16 |
extern enum nss_status _nss_ldap_endgrent(void); |
18 |
extern enum nss_status _nss_ldap_endgrent(void); |
|
|
19 |
extern enum nss_status _nss_ldap_initgroups_dyn(const char *, gid_t, long int *, |
20 |
long int *, gid_t **, long int, int *); |
17 |
|
21 |
|
18 |
extern enum nss_status _nss_ldap_getpwent_r(struct passwd *, char *, size_t, |
22 |
extern enum nss_status _nss_ldap_getpwent_r(struct passwd *, char *, size_t, |
19 |
int *); |
23 |
int *); |
Lines 40-45
Link Here
|
40 |
NSS_METHOD_PROTOTYPE(__nss_compat_getgrent_r); |
44 |
NSS_METHOD_PROTOTYPE(__nss_compat_getgrent_r); |
41 |
NSS_METHOD_PROTOTYPE(__nss_compat_setgrent); |
45 |
NSS_METHOD_PROTOTYPE(__nss_compat_setgrent); |
42 |
NSS_METHOD_PROTOTYPE(__nss_compat_endgrent); |
46 |
NSS_METHOD_PROTOTYPE(__nss_compat_endgrent); |
|
|
47 |
static NSS_METHOD_PROTOTYPE(__freebsd_getgroupmembership); |
43 |
|
48 |
|
44 |
NSS_METHOD_PROTOTYPE(__nss_compat_getpwnam_r); |
49 |
NSS_METHOD_PROTOTYPE(__nss_compat_getpwnam_r); |
45 |
NSS_METHOD_PROTOTYPE(__nss_compat_getpwuid_r); |
50 |
NSS_METHOD_PROTOTYPE(__nss_compat_getpwuid_r); |
Lines 57-62
Link Here
|
57 |
{ NSDB_GROUP, "getgrent_r", __nss_compat_getgrent_r, _nss_ldap_getgrent_r }, |
62 |
{ NSDB_GROUP, "getgrent_r", __nss_compat_getgrent_r, _nss_ldap_getgrent_r }, |
58 |
{ NSDB_GROUP, "setgrent", __nss_compat_setgrent, _nss_ldap_setgrent }, |
63 |
{ NSDB_GROUP, "setgrent", __nss_compat_setgrent, _nss_ldap_setgrent }, |
59 |
{ NSDB_GROUP, "endgrent", __nss_compat_endgrent, _nss_ldap_endgrent }, |
64 |
{ NSDB_GROUP, "endgrent", __nss_compat_endgrent, _nss_ldap_endgrent }, |
|
|
65 |
{ NSDB_GROUP, "getgroupmembership", __freebsd_getgroupmembership, NULL }, |
60 |
|
66 |
|
61 |
{ NSDB_PASSWD, "getpwnam_r", __nss_compat_getpwnam_r, _nss_ldap_getpwnam_r }, |
67 |
{ NSDB_PASSWD, "getpwnam_r", __nss_compat_getpwnam_r, _nss_ldap_getpwnam_r }, |
62 |
{ NSDB_PASSWD, "getpwuid_r", __nss_compat_getpwuid_r, _nss_ldap_getpwuid_r }, |
68 |
{ NSDB_PASSWD, "getpwuid_r", __nss_compat_getpwuid_r, _nss_ldap_getpwuid_r }, |
Lines 156-158
Link Here
|
156 |
h_errno = h_errnop; |
162 |
h_errno = h_errnop; |
157 |
return (status); |
163 |
return (status); |
158 |
} |
164 |
} |
|
|
165 |
|
166 |
static int |
167 |
__gr_addgid(gid_t gid, gid_t *groups, int maxgrp, int *groupc) |
168 |
{ |
169 |
int ret, dupc; |
170 |
|
171 |
/* skip duplicates */ |
172 |
for (dupc = 0; dupc < MIN(maxgrp, *groupc); dupc++) { |
173 |
if (groups[dupc] == gid) |
174 |
return 1; |
175 |
} |
176 |
|
177 |
ret = 1; |
178 |
if (*groupc < maxgrp) /* add this gid */ |
179 |
groups[*groupc] = gid; |
180 |
else |
181 |
ret = 0; |
182 |
(*groupc)++; |
183 |
return ret; |
184 |
} |
185 |
|
186 |
static int __freebsd_getgroupmembership(void *retval, void *mdata, va_list ap) |
187 |
{ |
188 |
int err; |
189 |
enum nss_status s; |
190 |
const char *user = va_arg(ap, const char *); |
191 |
gid_t group = va_arg(ap, gid_t); |
192 |
gid_t *groups = va_arg(ap, gid_t *); |
193 |
int limit = va_arg(ap, int); |
194 |
int *size = va_arg(ap, int*); |
195 |
gid_t *tmpgroups; |
196 |
long int lstart, lsize; |
197 |
int i; |
198 |
|
199 |
tmpgroups = malloc(limit * sizeof(gid_t)); |
200 |
if (tmpgroups == NULL) |
201 |
return NS_TRYAGAIN; |
202 |
|
203 |
/* insert primary membership */ |
204 |
__gr_addgid(group, groups, limit, size); |
205 |
|
206 |
lstart = 0; |
207 |
lsize = limit; |
208 |
s = _nss_ldap_initgroups_dyn(user, group, &lstart, &lsize, |
209 |
&tmpgroups, 0, &err); |
210 |
if (s == NSS_STATUS_SUCCESS) { |
211 |
for (i = 0; i < lstart; i++) |
212 |
__gr_addgid(tmpgroups[i], groups, limit, size); |
213 |
s = NSS_STATUS_NOTFOUND; |
214 |
} |
215 |
|
216 |
free(tmpgroups); |
217 |
|
218 |
return __nss_compat_result(s, err); |
219 |
} |