"Fossies" - the Fresh Open Source Software Archive 
Member "nss_ldap-265/irs-netgrp.c" (6 Nov 2009, 4483 Bytes) of package /linux/privat/old/nss_ldap-265.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* Copyright (C) 2004 Luke Howard.
2 This file is part of the nss_ldap library.
3 Contributed by Luke Howard, <lukeh@padl.com>, 2004.
4
5 The nss_ldap library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The nss_ldap library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the nss_ldap library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21 #ifdef HAVE_IRS_H
22
23 #include <errno.h>
24 #include "irs-nss.h"
25
26 /* $Id: irs-netgrp.c,v 2.7 2009/11/06 10:15:26 lukeh Exp $ */
27
28 #ifdef HAVE_USERSEC_H
29 void *ng_pvtinit (void);
30 #endif
31 IRS_EXPORT void ng_close (struct irs_ng *);
32 IRS_EXPORT int ng_next (struct irs_ng *, char **, char **, char **);
33 IRS_EXPORT int ng_test (struct irs_ng *, const char *, const char *,
34 const char *, const char *);
35 IRS_EXPORT void ng_rewind (struct irs_ng *, const char *);
36 IRS_EXPORT void ng_minimize (struct irs_ng *);
37
38 IRS_EXPORT int
39 ng_test (struct irs_ng *this,
40 const char *name, const char *host,
41 const char *user, const char *domain)
42 {
43 NSS_STATUS parseStat;
44 ldap_innetgr_args_t li_args;
45
46 li_args.lia_netgroup = name;
47 li_args.lia_netgr_status = NSS_NETGR_NO;
48 li_args.lia_depth = 0;
49 li_args.lia_erange = 0;
50
51 _nss_ldap_enter ();
52
53 /* fall through to NSS implementation */
54 parseStat = do_innetgr (&li_args, host, user, domain);
55 if (parseStat != NSS_SUCCESS && parseStat != NSS_NOTFOUND)
56 {
57 if (li_args.lia_erange)
58 errno = ERANGE;
59 _nss_ldap_leave ();
60
61 return 0;
62 }
63
64 _nss_ldap_leave ();
65
66 return (li_args.lia_netgr_status == NSS_NETGR_FOUND);
67 }
68
69 IRS_EXPORT void
70 ng_rewind (struct irs_ng *this, const char *group)
71 {
72 nss_ldap_netgr_backend_t *ngbe;
73 ldap_args_t a;
74 NSS_STATUS stat;
75
76 ngbe = (nss_ldap_netgr_backend_t *) this->private;
77
78 /* clear out old state */
79 _nss_ldap_namelist_destroy (&ngbe->known_groups);
80 _nss_ldap_namelist_destroy (&ngbe->needed_groups);
81
82 LA_INIT (a);
83 LA_TYPE (a) = LA_TYPE_STRING;
84 LA_STRING (a) = group;
85
86 if (_nss_ldap_ent_context_init (&ngbe->state) == NULL)
87 return;
88
89 _nss_ldap_enter ();
90 stat = _nss_ldap_search_s (&a, _nss_ldap_filt_getgrent,
91 LM_NETGROUP, NULL, 1, &ngbe->state->ec_res);
92
93 if (stat == NSS_SUCCESS)
94 _nss_ldap_namelist_push (&ngbe->known_groups, group);
95
96 if (stat != NSS_SUCCESS)
97 _nss_ldap_ent_context_release (&(ngbe->state));
98
99 _nss_ldap_leave ();
100 }
101
102 IRS_EXPORT int
103 ng_next (struct irs_ng *this, char **machine, char **user, char **domain)
104 {
105 nss_ldap_netgr_backend_t *ngbe = (nss_ldap_netgr_backend_t *) this->private;
106 enum nss_netgr_status netgr_stat;
107 NSS_STATUS stat;
108
109 if (ngbe->state == NULL)
110 return 0;
111
112 _nss_ldap_enter ();
113
114 stat = do_getnetgrent (ngbe,
115 ngbe->buffer,
116 NSS_BUFLEN_NETGROUP,
117 &netgr_stat,
118 machine,
119 user,
120 domain);
121
122 _nss_ldap_leave ();
123
124 return (stat == NSS_SUCCESS);
125 }
126
127 IRS_EXPORT void
128 ng_minimize (struct irs_ng *this)
129 {
130 }
131
132 IRS_EXPORT void
133 ng_close (struct irs_ng *this)
134 {
135 #ifdef HAVE_USERSEC_H
136 nss_ldap_netgr_backend_t *ngbe;
137
138 ngbe = (nss_ldap_netgr_backend_t *) this->private;
139 if (ngbe != NULL)
140 {
141 if (ngbe->state != NULL)
142 {
143 _nss_ldap_enter ();
144 _nss_ldap_ent_context_release (&(ngbe->state));
145 _nss_ldap_leave ();
146 }
147
148 _nss_ldap_namelist_destroy (&ngbe->known_groups);
149 _nss_ldap_namelist_destroy (&ngbe->needed_groups);
150
151 free (ngbe);
152 }
153
154 free (this);
155 #endif /* HAVE_USERSEC_H */
156 }
157
158 #ifdef HAVE_USERSEC_H
159 void *
160 ng_pvtinit (void)
161 #else
162 struct irs_ng *
163 irs_ldap_ng (struct irs_acc *this)
164 #endif
165 {
166 struct irs_ng *ng;
167 nss_ldap_netgr_backend_t *pvt;
168
169 ng = calloc (1, sizeof (*ng));
170 if (ng == NULL)
171 return NULL;
172
173 pvt = calloc (1, sizeof (*pvt));
174 if (pvt == NULL)
175 {
176 free (ng);
177 return NULL;
178 }
179
180 pvt->state = NULL;
181 ng->private = pvt;
182 ng->close = ng_close;
183 ng->next = ng_next;
184 ng->test = ng_test;
185 ng->rewind = ng_rewind;
186 ng->minimize = ng_minimize;
187 return ng;
188 }
189
190 #endif /*HAVE_IRS_H */