f128b7b865062da662127712935dcc58bd022384Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher Copyright (C) 2010 Red Hat
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher This program is free software; you can redistribute it and/or modify
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher it under the terms of the GNU General Public License as published by
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher (at your option) any later version.
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher This program is distributed in the hope that it will be useful,
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher GNU General Public License for more details.
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher You should have received a copy of the GNU General Public License
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * 0-3: 32bit unsigned number of results N
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher * 4-7: 32bit unsigned (reserved/padding)
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher * For each result:
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * 8-11: 32bit unsigned type of result
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * 12-X: \0 terminated string representing a tuple
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * (host, user, domain)
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * or a netgroup, depending on the type indicator
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose * ... repeated N times
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher#define NETGR_METADATA_COUNT 2 * sizeof(uint32_t)
f128b7b865062da662127712935dcc58bd022384Stephen Gallagherstatic int sss_nss_getnetgr_readrep(struct sss_nss_netgr_rep *pr,
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* Not enough space for data, bad packet */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* Host value */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* libc expects NULL instead of empty string */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* User value */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* libc expects NULL instead of empty string */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* Domain value */
36fc83f3f64bb16db7bef3e1cebe829424edacd1Sumit Bose /* libc expects NULL instead of empty string */
f128b7b865062da662127712935dcc58bd022384Stephen Gallagherenum nss_status _nss_sss_setnetgrent(const char *netgroup,
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher if (!netgroup) return NSS_STATUS_NOTFOUND;
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* make sure we do not have leftovers, and release memory */
22c7230dc0c8d41a189eb758be78991d183de1f7Stephen Gallagher ret = sss_strnlen(netgroup, SSS_NAME_MAX, &name_len);
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher nret = sss_nss_make_request(SSS_NSS_SETNETGRENT, &rd,
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek /* Get number of results from repbuf */
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek SAFEALIGN_COPY_UINT32(&num_results, repbuf, NULL);
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* no results if not found */
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek if ((num_results == 0) || (replen < NETGR_METADATA_COUNT)) {
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorcestatic enum nss_status internal_getnetgrent_r(struct __netgrent *result,
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* Caught once glibc passing in buffer == 0x0 */
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* If we're already processing result data, continue to
60dceaee2014822717a3f22e1b65b228e20cc5f0Sumit Bose repbuf = (uint8_t *) result->data + result->idx.position;
60dceaee2014822717a3f22e1b65b228e20cc5f0Sumit Bose replen = result->data_size - result->idx.position;
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher ret = sss_nss_getnetgr_readrep(&netgrrep, repbuf, &replen);
60dceaee2014822717a3f22e1b65b228e20cc5f0Sumit Bose result->idx.position = result->data_size - replen;
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* Release memory, if any */
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* retrieve no more than SSS_NSS_MAX_ENTRIES at a time */
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher nret = sss_nss_make_request(SSS_NSS_GETNETGRENT, &rd,
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek /* Get number of results from repbuf. */
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek SAFEALIGN_COPY_UINT32(&num_results, repbuf, NULL);
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* no results if not found */
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek if ((num_results == 0) || (replen <= NETGR_METADATA_COUNT)) {
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* skip metadata fields */
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* call again ourselves, this will return the first result */
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce return internal_getnetgrent_r(result, buffer, buflen, errnop);
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorceenum nss_status _nss_sss_getnetgrent_r(struct __netgrent *result,
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce nret = internal_getnetgrent_r(result, buffer, buflen, errnop);
60dceaee2014822717a3f22e1b65b228e20cc5f0Sumit Boseenum nss_status _nss_sss_endnetgrent(struct __netgrent *result)
f128b7b865062da662127712935dcc58bd022384Stephen Gallagher /* make sure we do not have leftovers, and release memory */