1 /* Copyright (C) 1997, 2003, 2004 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 result
->val
.triple
.host
= NULL
;
95 result
->val
.triple
.host
= cp
;
96 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 2,
97 (nis_result
*) result
->data
),
103 result
->val
.triple
.user
= NULL
;
106 result
->val
.triple
.user
= cp
;
107 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 3,
108 (nis_result
*) result
->data
),
114 result
->val
.triple
.domain
= NULL
;
117 result
->val
.triple
.domain
= cp
;
118 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 4,
119 (nis_result
*) result
->data
),
124 status
= NSS_STATUS_SUCCESS
;
126 /* Remember where we stopped reading. */
136 internal_endnetgrent (struct __netgrent
*netgrp
)
138 if (netgrp
->data
!= NULL
)
140 nis_freeresult ((nis_result
*) netgrp
->data
);
142 netgrp
->data_size
= 0;
143 netgrp
->position
= 0;
148 _nss_nisplus_setnetgrent (const char *group
, struct __netgrent
*netgrp
)
150 enum nss_status status
;
151 char buf
[strlen (group
) + 30];
153 if (group
== NULL
|| group
[0] == '\0')
154 return NSS_STATUS_UNAVAIL
;
156 status
= NSS_STATUS_SUCCESS
;
158 internal_endnetgrent (netgrp
);
160 sprintf (buf
, "[name=%s],netgroup.org_dir", group
);
162 netgrp
->data
= (char *) nis_list (buf
, EXPAND_NAME
, NULL
, NULL
);
164 if (netgrp
->data
== NULL
)
166 __set_errno (ENOMEM
);
167 status
= NSS_STATUS_TRYAGAIN
;
169 else if (niserr2nss (((nis_result
*) netgrp
->data
)->status
)
170 != NSS_STATUS_SUCCESS
)
172 status
= niserr2nss (((nis_result
*) netgrp
->data
)->status
);
174 internal_endnetgrent (netgrp
);
178 netgrp
->data_size
= ((nis_result
*) netgrp
->data
)->objects
.objects_len
;
179 netgrp
->position
= 0;
187 _nss_nisplus_endnetgrent (struct __netgrent
*netgrp
)
189 internal_endnetgrent (netgrp
);
191 return NSS_STATUS_SUCCESS
;