nss_netgroup.c revision c89589fa349f38214c9cb8d9389c0fd557e5dca2
/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2010 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nss.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "sss_cli.h"
#include "nss_compat.h"
#define MAX_NETGR_NAME_LENGTH 2048
#define CLEAR_NETGRENT_DATA(netgrent) do { \
} while (0);
/*
* Replies:
*
* 0-3: 32bit unsigned number of results N
* For each result:
* 8-11: 32bit unsigned type of result
* 12-X: \0 terminated string representing a tuple
* (host, user, domain)
* or a netgroup, depending on the type indicator
* ... repeated N times
*/
struct sss_nss_netgr_rep {
struct __netgrent *result;
char *buffer;
};
{
char *sbuf;
if (*len < 6) {
/* Not enough space for data, bad packet */
return EBADMSG;
}
i = 0;
switch (type) {
case SSS_NETGR_REP_TRIPLE:
/* Host value */
i++;
dlen--;
}
if (slen <= i) { /* premature end of buf */
return EBADMSG;
}
if (dlen <= 0) { /* not enough memory */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
i++;
dlen--;
/* libc expects NULL instead of empty string */
}
/* User value */
i++;
dlen--;
}
if (slen <= i) { /* premature end of buf */
return EBADMSG;
}
if (dlen <= 0) { /* not enough memory */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
i++;
dlen--;
/* libc expects NULL instead of empty string */
}
/* Domain value */
i++;
dlen--;
}
if (slen <= i) { /* premature end of buf */
return EBADMSG;
}
if (dlen <= 0) { /* not enough memory */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
i++;
dlen--;
/* libc expects NULL instead of empty string */
}
break;
case SSS_NETGR_REP_GROUP:
i++;
dlen--;
}
if (slen <= i) { /* premature end of buf */
return EBADMSG;
}
if (dlen <= 0) { /* not enough memory */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
i++;
dlen--;
break;
default:
return EBADMSG;
}
return 0;
}
struct __netgrent *result)
{
enum nss_status nret;
struct sss_cli_req_data rd;
int errnop;
char *name;
if (!netgroup) return NSS_STATUS_NOTFOUND;
sss_nss_lock();
/* make sure we do not have leftovers, and release memory */
if (ret != 0) {
goto out;
}
goto out;
}
if (nret != NSS_STATUS_SUCCESS) {
goto out;
}
/* no results if not found */
goto out;
}
out:
return nret;
}
int *errnop)
{
struct sss_cli_req_data rd;
struct sss_nss_netgr_rep netgrrep;
enum nss_status nret;
int ret;
/* Caught once glibc passing in buffer == 0x0 */
/* If we're already processing result data, continue to
* return it.
*/
if (ret != 0) {
return NSS_STATUS_TRYAGAIN;
}
return NSS_STATUS_SUCCESS;
}
/* Release memory, if any */
/* retrieve no more than SSS_NSS_MAX_ENTRIES at a time */
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
/* no results if not found */
return NSS_STATUS_RETURN;
}
/* skip metadata fields */
/* call again ourselves, this will return the first result */
}
int *errnop)
{
enum nss_status nret;
sss_nss_lock();
return nret;
}
{
enum nss_status nret;
int errnop;
sss_nss_lock();
/* make sure we do not have leftovers, and release memory */
if (nret != NSS_STATUS_SUCCESS) {
}
return nret;
}