1 /* Copyright (C) 1996-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
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 <https://www.gnu.org/licenses/>. */
29 #include <rpcsvc/yp.h>
30 #include <rpcsvc/ypclnt.h>
34 extern enum nss_status
35 _nss_netgroup_parseline (char **cursor, struct __netgrent *netgrp,
36 char *buffer, size_t buflen, int *errnop);
40 internal_nis_endnetgrent (struct __netgrent *netgrp)
44 netgrp->data_size = 0;
45 netgrp->cursor = NULL;
50 _nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
53 enum nss_status status;
55 status = NSS_STATUS_SUCCESS;
57 if (__glibc_unlikely (group == NULL || group[0] == '\0'))
58 return NSS_STATUS_UNAVAIL;
61 if (__glibc_unlikely (yp_get_default_domain (&domain)))
62 return NSS_STATUS_UNAVAIL;
64 status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
65 &netgrp->data, &len));
66 if (__glibc_likely (status == NSS_STATUS_SUCCESS))
68 /* Our implementation of yp_match already allocates a buffer
69 which is one byte larger than the value in LEN specifies
70 and the last byte is filled with NUL. So we can simply
73 assert (netgrp->data[len] == '\0');
75 netgrp->data_size = len;
76 netgrp->cursor = netgrp->data;
84 _nss_nis_endnetgrent (struct __netgrent *netgrp)
86 internal_nis_endnetgrent (netgrp);
88 return NSS_STATUS_SUCCESS;
93 _nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
96 return _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,