1 /* Copyright (C) 1997-2015 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, see
17 <http://www.gnu.org/licenses/>. */
25 #include <rpcsvc/nis.h>
27 #include "nss-nisplus.h"
29 #define NISENTRYVAL(idx, col, res) \
30 (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
32 #define NISENTRYLEN(idx, col, res) \
33 (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
36 _nss_nisplus_getnetgrent_r (struct __netgrent
*result
, char *buffer
,
37 size_t buflen
, int *errnop
)
39 enum nss_status status
;
41 /* Some sanity checks. */
42 if (result
->data
== NULL
|| result
->data_size
== 0)
43 return NSS_STATUS_NOTFOUND
;
45 if (result
->position
== result
->data_size
)
46 return result
->first
? NSS_STATUS_NOTFOUND
: NSS_STATUS_RETURN
;
49 = NISENTRYLEN (result
->position
, 1, (nis_result
*) result
->data
);
52 /* We have a list of other netgroups. */
54 result
->type
= group_val
;
55 if (entrylen
>= buflen
)
58 return NSS_STATUS_TRYAGAIN
;
60 strncpy (buffer
, NISENTRYVAL (result
->position
, 1,
61 (nis_result
*) result
->data
),
63 buffer
[entrylen
] = '\0';
64 result
->val
.group
= buffer
;
68 return NSS_STATUS_SUCCESS
;
71 /* Before we can copy the entry to the private buffer we have to make
72 sure it is big enough. */
74 = NISENTRYLEN (result
->position
, 2, (nis_result
*) result
->data
);
76 = NISENTRYLEN (result
->position
, 3, (nis_result
*) result
->data
);
77 unsigned int domainlen
78 = NISENTRYLEN (result
->position
, 4, (nis_result
*) result
->data
);
79 if (hostlen
+ userlen
+ domainlen
+ 6 > buflen
)
82 status
= NSS_STATUS_TRYAGAIN
;
88 result
->type
= triple_val
;
91 NISENTRYVAL (result
->position
, 2,
92 (nis_result
*) result
->data
)[0] == '\0')
93 result
->val
.triple
.host
= NULL
;
96 result
->val
.triple
.host
= cp
;
97 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 2,
98 (nis_result
*) result
->data
),
104 NISENTRYVAL (result
->position
, 3,
105 (nis_result
*) result
->data
)[0] == '\0')
106 result
->val
.triple
.user
= NULL
;
109 result
->val
.triple
.user
= cp
;
110 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 3,
111 (nis_result
*) result
->data
),
116 if (domainlen
== 0 ||
117 NISENTRYVAL (result
->position
, 4,
118 (nis_result
*) result
->data
)[0] == '\0')
119 result
->val
.triple
.domain
= NULL
;
122 result
->val
.triple
.domain
= cp
;
123 cp
= __stpncpy (cp
, NISENTRYVAL (result
->position
, 4,
124 (nis_result
*) result
->data
),
129 status
= NSS_STATUS_SUCCESS
;
131 /* Remember where we stopped reading. */
141 internal_endnetgrent (struct __netgrent
*netgrp
)
143 nis_freeresult ((nis_result
*) netgrp
->data
);
145 netgrp
->data_size
= 0;
146 netgrp
->position
= 0;
150 _nss_nisplus_setnetgrent (const char *group
, struct __netgrent
*netgrp
)
152 char buf
[strlen (group
) + 25];
154 if (group
== NULL
|| group
[0] == '\0')
155 return NSS_STATUS_UNAVAIL
;
157 enum nss_status status
= NSS_STATUS_SUCCESS
;
159 snprintf (buf
, sizeof (buf
), "[name=%s],netgroup.org_dir", group
);
161 netgrp
->data
= (char *) nis_list (buf
, EXPAND_NAME
, NULL
, NULL
);
163 if (netgrp
->data
== NULL
)
165 __set_errno (ENOMEM
);
166 status
= NSS_STATUS_TRYAGAIN
;
168 else if (niserr2nss (((nis_result
*) netgrp
->data
)->status
)
169 != NSS_STATUS_SUCCESS
)
171 status
= niserr2nss (((nis_result
*) netgrp
->data
)->status
);
173 internal_endnetgrent (netgrp
);
177 netgrp
->data_size
= ((nis_result
*) netgrp
->data
)->objects
.objects_len
;
178 netgrp
->position
= 0;
186 _nss_nisplus_endnetgrent (struct __netgrent
*netgrp
)
188 internal_endnetgrent (netgrp
);
190 return NSS_STATUS_SUCCESS
;