1 /* Copyright (C) 1997, 2003, 2004, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <rpcsvc/nis.h>
28 #include "nss-nisplus.h"
30 #define NISENTRYVAL(idx,col,res) \
31 ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
33 #define NISENTRYLEN(idx,col,res) \
34 ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
37 _nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer,
38 size_t buflen, int *errnop)
40 enum nss_status status;
42 /* Some sanity checks. */
43 if (result->data == NULL || result->data_size == 0)
44 return NSS_STATUS_NOTFOUND;
46 if (result->position == result->data_size)
47 return result->first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
50 = NISENTRYLEN (result->position, 1, (nis_result *) result->data);
53 /* We have a list of other netgroups. */
55 result->type = group_val;
56 if (entrylen >= buflen)
59 return NSS_STATUS_TRYAGAIN;
61 strncpy (buffer, NISENTRYVAL (result->position, 1,
62 (nis_result *) result->data),
64 buffer[entrylen] = '\0';
65 result->val.group = buffer;
69 return NSS_STATUS_SUCCESS;
72 /* Before we can copy the entry to the private buffer we have to make
73 sure it is big enough. */
75 = NISENTRYLEN (result->position, 2, (nis_result *) result->data);
77 = NISENTRYLEN (result->position, 3, (nis_result *) result->data);
78 unsigned int domainlen
79 = NISENTRYLEN (result->position, 4, (nis_result *) result->data);
80 if (hostlen + userlen + domainlen + 6 > buflen)
83 status = NSS_STATUS_TRYAGAIN;
89 result->type = triple_val;
92 NISENTRYVAL (result->position, 2,
93 (nis_result *) result->data)[0] == '\0')
94 result->val.triple.host = NULL;
97 result->val.triple.host = cp;
98 cp = __stpncpy (cp, NISENTRYVAL (result->position, 2,
99 (nis_result *) result->data),
105 NISENTRYVAL (result->position, 3,
106 (nis_result *) result->data)[0] == '\0')
107 result->val.triple.user = NULL;
110 result->val.triple.user = cp;
111 cp = __stpncpy (cp, NISENTRYVAL (result->position, 3,
112 (nis_result *) result->data),
117 if (domainlen == 0 ||
118 NISENTRYVAL (result->position, 4,
119 (nis_result *) result->data)[0] == '\0')
120 result->val.triple.domain = NULL;
123 result->val.triple.domain = cp;
124 cp = __stpncpy (cp, NISENTRYVAL (result->position, 4,
125 (nis_result *) result->data),
130 status = NSS_STATUS_SUCCESS;
132 /* Remember where we stopped reading. */
142 internal_endnetgrent (struct __netgrent *netgrp)
144 nis_freeresult ((nis_result *) netgrp->data);
146 netgrp->data_size = 0;
147 netgrp->position = 0;
151 _nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp)
153 enum nss_status status;
154 char buf[strlen (group) + 30];
156 if (group == NULL || group[0] == '\0')
157 return NSS_STATUS_UNAVAIL;
159 status = NSS_STATUS_SUCCESS;
161 sprintf (buf, "[name=%s],netgroup.org_dir", group);
163 netgrp->data = (char *) nis_list (buf, EXPAND_NAME, NULL, NULL);
165 if (netgrp->data == NULL)
167 __set_errno (ENOMEM);
168 status = NSS_STATUS_TRYAGAIN;
170 else if (niserr2nss (((nis_result *) netgrp->data)->status)
171 != NSS_STATUS_SUCCESS)
173 status = niserr2nss (((nis_result *) netgrp->data)->status);
175 internal_endnetgrent (netgrp);
179 netgrp->data_size = ((nis_result *) netgrp->data)->objects.objects_len;
180 netgrp->position = 0;
188 _nss_nisplus_endnetgrent (struct __netgrent *netgrp)
190 internal_endnetgrent (netgrp);
192 return NSS_STATUS_SUCCESS;