2 Solaris NSS wrapper for winbind
5 Based on Luke Howard's ldap_nss module for Solaris
9 Copyright (C) 1997-2003 Luke Howard.
10 This file is part of the nss_ldap library.
12 The nss_ldap library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The nss_ldap library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
22 You should have received a copy of the GNU Library General Public
23 License along with the nss_ldap library; see the file COPYING.LIB. If not,
24 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
30 #include <sys/param.h>
36 #include <sys/syslog.h>
38 #include "winbind_nss_config.h"
40 #if defined(HAVE_NSS_COMMON_H) || defined(HPUX)
45 #define NSS_DEBUG(str) syslog(LOG_DEBUG, "nss_winbind: %s", str);
47 #define NSS_DEBUG(str) ;
50 #define NSS_ARGS(args) ((nss_XbyY_args_t *)args)
55 * HP-UX 11 has no definiton of the nss_groupsbymem structure. This
56 * definition is taken from the nss_ldap project at:
57 * http://www.padl.com/OSS/nss_ldap.html
60 struct nss_groupsbymem
{
65 int (*str2ent
)(const char *instr
, int instr_len
, void *ent
,
66 char *buffer
, int buflen
);
67 nss_status_t (*process_cstr
)(const char *instr
, int instr_len
,
68 struct nss_groupsbymem
*);
74 #define make_pwent_str(dest, src) \
76 if((dest = get_static(buffer, buflen, strlen(src)+1)) == NULL) \
79 NSS_DEBUG("ERANGE error"); \
80 return NSS_STATUS_TRYAGAIN; \
85 static NSS_STATUS
_nss_winbind_setpwent_solwrap (nss_backend_t
* be
, void* args
)
87 NSS_DEBUG("_nss_winbind_setpwent_solwrap");
88 return _nss_winbind_setpwent();
92 _nss_winbind_endpwent_solwrap (nss_backend_t
* be
, void *args
)
94 NSS_DEBUG("_nss_winbind_endpwent_solwrap");
95 return _nss_winbind_endpwent();
99 _nss_winbind_getpwent_solwrap (nss_backend_t
* be
, void *args
)
102 char* buffer
= NSS_ARGS(args
)->buf
.buffer
;
103 int buflen
= NSS_ARGS(args
)->buf
.buflen
;
104 struct passwd
* result
= (struct passwd
*) NSS_ARGS(args
)->buf
.result
;
105 int* errnop
= &NSS_ARGS(args
)->erange
;
108 ret
= _nss_winbind_getpwent_r(result
, buffer
,
111 if(ret
== NSS_STATUS_SUCCESS
)
113 snprintf(logmsg
, 79, "_nss_winbind_getpwent_solwrap: Returning user: %s\n",
116 NSS_ARGS(args
)->returnval
= (void*) result
;
118 snprintf(logmsg
, 79, "_nss_winbind_getpwent_solwrap: Returning error: %d.\n",ret
);
126 _nss_winbind_getpwnam_solwrap (nss_backend_t
* be
, void* args
)
129 struct passwd
* result
= (struct passwd
*) NSS_ARGS(args
)->buf
.result
;
131 NSS_DEBUG("_nss_winbind_getpwnam_solwrap");
133 ret
= _nss_winbind_getpwnam_r (NSS_ARGS(args
)->key
.name
,
135 NSS_ARGS(args
)->buf
.buffer
,
136 NSS_ARGS(args
)->buf
.buflen
,
137 &NSS_ARGS(args
)->erange
);
138 if(ret
== NSS_STATUS_SUCCESS
)
139 NSS_ARGS(args
)->returnval
= (void*) result
;
145 _nss_winbind_getpwuid_solwrap(nss_backend_t
* be
, void* args
)
148 struct passwd
* result
= (struct passwd
*) NSS_ARGS(args
)->buf
.result
;
150 NSS_DEBUG("_nss_winbind_getpwuid_solwrap");
151 ret
= _nss_winbind_getpwuid_r (NSS_ARGS(args
)->key
.uid
,
153 NSS_ARGS(args
)->buf
.buffer
,
154 NSS_ARGS(args
)->buf
.buflen
,
155 &NSS_ARGS(args
)->erange
);
156 if(ret
== NSS_STATUS_SUCCESS
)
157 NSS_ARGS(args
)->returnval
= (void*) result
;
162 static NSS_STATUS
_nss_winbind_passwd_destr (nss_backend_t
* be
, void *args
)
165 NSS_DEBUG("_nss_winbind_passwd_destr");
166 return NSS_STATUS_SUCCESS
;
169 static nss_backend_op_t passwd_ops
[] =
171 _nss_winbind_passwd_destr
,
172 _nss_winbind_endpwent_solwrap
, /* NSS_DBOP_ENDENT */
173 _nss_winbind_setpwent_solwrap
, /* NSS_DBOP_SETENT */
174 _nss_winbind_getpwent_solwrap
, /* NSS_DBOP_GETENT */
175 _nss_winbind_getpwnam_solwrap
, /* NSS_DBOP_PASSWD_BYNAME */
176 _nss_winbind_getpwuid_solwrap
/* NSS_DBOP_PASSWD_BYUID */
180 _nss_winbind_passwd_constr (const char* db_name
,
181 const char* src_name
,
182 const char* cfg_args
)
186 if(!(be
= (nss_backend_t
*) malloc(sizeof(nss_backend_t
))) )
189 be
->ops
= passwd_ops
;
190 be
->n_ops
= sizeof(passwd_ops
) / sizeof(nss_backend_op_t
);
192 NSS_DEBUG("Initialized nss_winbind passwd backend");
196 /*****************************************************************
197 GROUP database backend
198 *****************************************************************/
200 static NSS_STATUS
_nss_winbind_setgrent_solwrap (nss_backend_t
* be
, void* args
)
202 NSS_DEBUG("_nss_winbind_setgrent_solwrap");
203 return _nss_winbind_setgrent();
207 _nss_winbind_endgrent_solwrap (nss_backend_t
* be
, void *args
)
209 NSS_DEBUG("_nss_winbind_endgrent_solwrap");
210 return _nss_winbind_endgrent();
214 _nss_winbind_getgrent_solwrap(nss_backend_t
* be
, void* args
)
217 char* buffer
= NSS_ARGS(args
)->buf
.buffer
;
218 int buflen
= NSS_ARGS(args
)->buf
.buflen
;
219 struct group
* result
= (struct group
*) NSS_ARGS(args
)->buf
.result
;
220 int* errnop
= &NSS_ARGS(args
)->erange
;
223 ret
= _nss_winbind_getgrent_r(result
, buffer
,
226 if(ret
== NSS_STATUS_SUCCESS
)
228 snprintf(logmsg
, 79, "_nss_winbind_getgrent_solwrap: Returning group: %s\n", result
->gr_name
);
230 NSS_ARGS(args
)->returnval
= (void*) result
;
232 snprintf(logmsg
, 79, "_nss_winbind_getgrent_solwrap: Returning error: %d.\n", ret
);
241 _nss_winbind_getgrnam_solwrap(nss_backend_t
* be
, void* args
)
244 struct group
* result
= (struct group
*) NSS_ARGS(args
)->buf
.result
;
246 NSS_DEBUG("_nss_winbind_getgrnam_solwrap");
247 ret
= _nss_winbind_getgrnam_r(NSS_ARGS(args
)->key
.name
,
249 NSS_ARGS(args
)->buf
.buffer
,
250 NSS_ARGS(args
)->buf
.buflen
,
251 &NSS_ARGS(args
)->erange
);
253 if(ret
== NSS_STATUS_SUCCESS
)
254 NSS_ARGS(args
)->returnval
= (void*) result
;
260 _nss_winbind_getgrgid_solwrap(nss_backend_t
* be
, void* args
)
263 struct group
* result
= (struct group
*) NSS_ARGS(args
)->buf
.result
;
265 NSS_DEBUG("_nss_winbind_getgrgid_solwrap");
266 ret
= _nss_winbind_getgrgid_r (NSS_ARGS(args
)->key
.gid
,
268 NSS_ARGS(args
)->buf
.buffer
,
269 NSS_ARGS(args
)->buf
.buflen
,
270 &NSS_ARGS(args
)->erange
);
272 if(ret
== NSS_STATUS_SUCCESS
)
273 NSS_ARGS(args
)->returnval
= (void*) result
;
279 _nss_winbind_getgroupsbymember_solwrap(nss_backend_t
* be
, void* args
)
282 struct nss_groupsbymem
*gmem
= (struct nss_groupsbymem
*)args
;
284 NSS_DEBUG("_nss_winbind_getgroupsbymember");
286 _nss_winbind_initgroups_dyn(gmem
->username
,
287 gmem
->gid_array
[0], /* Primary Group */
295 * If the maximum number of gids have been found, return
296 * SUCCESS so the switch engine will stop searching. Otherwise
297 * return NOTFOUND so nsswitch will continue to get groups
298 * from the remaining database backends specified in the
299 * nsswitch.conf file.
301 return (gmem
->numgids
== gmem
->maxgids
? NSS_STATUS_SUCCESS
: NSS_STATUS_NOTFOUND
);
305 _nss_winbind_group_destr (nss_backend_t
* be
, void* args
)
308 NSS_DEBUG("_nss_winbind_group_destr");
309 return NSS_STATUS_SUCCESS
;
312 static nss_backend_op_t group_ops
[] =
314 _nss_winbind_group_destr
,
315 _nss_winbind_endgrent_solwrap
,
316 _nss_winbind_setgrent_solwrap
,
317 _nss_winbind_getgrent_solwrap
,
318 _nss_winbind_getgrnam_solwrap
,
319 _nss_winbind_getgrgid_solwrap
,
320 _nss_winbind_getgroupsbymember_solwrap
324 _nss_winbind_group_constr (const char* db_name
,
325 const char* src_name
,
326 const char* cfg_args
)
330 if(!(be
= (nss_backend_t
*) malloc(sizeof(nss_backend_t
))) )
334 be
->n_ops
= sizeof(group_ops
) / sizeof(nss_backend_op_t
);
336 NSS_DEBUG("Initialized nss_winbind group backend");