"Fossies" - the Fresh Open Source Software Archive 
Member "nss_ldap-265/irs-service.c" (6 Nov 2009, 3920 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) 1997-2005 Luke Howard.
2 This file is part of the nss_ldap library.
3 Contributed by Luke Howard, <lukeh@padl.com>, 1997.
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-service.c,v 2.26 2005/05/20 05:30:40 lukeh Exp $ */
27
28 #ifdef HAVE_USERSEC_H
29 void *sv_pvtinit (void);
30 #endif
31 IRS_EXPORT void sv_close (struct irs_sv *);
32 IRS_EXPORT struct servent *sv_next (struct irs_sv *);
33 IRS_EXPORT struct servent *sv_byname (struct irs_sv *, const char *,
34 const char *);
35 IRS_EXPORT struct servent *sv_byport (struct irs_sv *, int, const char *);
36 IRS_EXPORT void sv_rewind (struct irs_sv *);
37 IRS_EXPORT void sv_minimize (struct irs_sv *);
38
39 struct pvt
40 {
41 struct servent result;
42 char buffer[NSS_BUFLEN_SERVICES];
43 ent_context_t *state;
44 };
45
46 IRS_EXPORT struct servent *
47 sv_byname (struct irs_sv *this, const char *name, const char *proto)
48 {
49 ldap_args_t a;
50 struct pvt *pvt = (struct pvt *) this->private;
51 NSS_STATUS s;
52
53 LA_INIT (a);
54 LA_STRING (a) = name;
55 LA_TYPE (a) = (proto == NULL) ? LA_TYPE_STRING : LA_TYPE_STRING_AND_STRING;
56 LA_STRING2 (a) = proto;
57 s =
58 _nss_ldap_getbyname (&a, &pvt->result, pvt->buffer, sizeof (pvt->buffer),
59 &errno,
60 (proto ==
61 NULL) ? _nss_ldap_filt_getservbyname :
62 _nss_ldap_filt_getservbynameproto,
63 LM_SERVICES, _nss_ldap_parse_serv);
64
65 if (s != NSS_SUCCESS)
66 {
67 MAP_ERRNO (s, errno);
68 return NULL;
69 }
70 return &pvt->result;
71 }
72
73 IRS_EXPORT struct servent *
74 sv_byport (struct irs_sv *this, int port, const char *proto)
75 {
76 ldap_args_t a;
77 struct pvt *pvt = (struct pvt *) this->private;
78 NSS_STATUS s;
79
80 LA_INIT (a);
81 LA_NUMBER (a) = port;
82 LA_TYPE (a) = (proto == NULL) ? LA_TYPE_NUMBER : LA_TYPE_NUMBER_AND_STRING;
83 LA_STRING2 (a) = proto;
84 s =
85 _nss_ldap_getbyname (&a, &pvt->result, pvt->buffer, sizeof (pvt->buffer),
86 &errno,
87 (proto ==
88 NULL) ? _nss_ldap_filt_getservbyport :
89 _nss_ldap_filt_getservbyportproto,
90 LM_SERVICES, _nss_ldap_parse_serv);
91
92 if (s != NSS_SUCCESS)
93 {
94 MAP_ERRNO (s, errno);
95 return NULL;
96 }
97 return &pvt->result;
98 }
99
100 IRS_EXPORT void
101 sv_close (struct irs_sv *this)
102 {
103 LOOKUP_ENDENT (this);
104 #ifdef HAVE_USERSEC_H
105 free (this->private);
106 free (this);
107 #endif
108 }
109
110 IRS_EXPORT struct servent *
111 sv_next (struct irs_sv *this)
112 {
113 LOOKUP_GETENT (this, _nss_ldap_filt_getservent, LM_SERVICES,
114 _nss_ldap_parse_serv, LDAP_NSS_BUFLEN_DEFAULT);
115 }
116
117 IRS_EXPORT void
118 sv_rewind (struct irs_sv *this)
119 {
120 LOOKUP_SETENT (this);
121 }
122
123 IRS_EXPORT void
124 sv_minimize (struct irs_sv *this)
125 {
126 }
127
128 #ifdef HAVE_USERSEC_H
129 void *
130 sv_pvtinit (void)
131 #else
132 struct irs_sv *
133 irs_ldap_sv (struct irs_acc *this)
134 #endif
135 {
136 struct irs_sv *sv;
137 struct pvt *pvt;
138
139 sv = calloc (1, sizeof (*sv));
140 if (sv == NULL)
141 return NULL;
142
143 pvt = calloc (1, sizeof (*pvt));
144 if (pvt == NULL)
145 {
146 free (sv);
147 return NULL;
148 }
149
150 pvt->state = NULL;
151 sv->private = pvt;
152 sv->close = sv_close;
153 sv->next = sv_next;
154 sv->byname = sv_byname;
155 sv->byport = sv_byport;
156 sv->rewind = sv_rewind;
157 sv->minimize = sv_minimize;
158 return sv;
159 }
160
161 #endif /*HAVE_IRS_H */