group.c revision fcef1231eea30ee9cdc75f3f39f4b9207a84ea1d
/*
* System Security Services Daemon. NSS client interface
*
* Copyright (C) Simo Sorce 2007
*
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* GROUP database NSS interface */
#include <nss.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "sss_cli.h"
static struct sss_nss_getgrent_data {
static void sss_nss_getgrent_data_clean(void) {
}
sss_nss_getgrent_data.len = 0;
sss_nss_getgrent_data.ptr = 0;
}
/* GETGRNAM Request:
*
* 0-X: string with name
*
* GERTGRGID Request:
*
* 0-7: 64bit number with gid
*
* INITGROUPS Request:
*
* 0-7: 64bit number with gid
* 8-11: 32bit unsigned with max num of entries
*
* Replies:
*
* 0-3: 32bit unsigned number of results
* For each result (64bit padded ?):
* 0-7: 64bit number gid
* 8-11: 32bit unsigned number of members
* 12-X: sequence of 0 terminated strings (name, passwd, mem..)
*/
struct sss_nss_gr_rep {
char *buffer;
};
{
char *sbuf;
int err;
return EBADMSG;
}
i = 0;
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--;
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--;
/* now members */
if (0 > dlen) { /* not enough mem in buffer */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
ptmem += i;
for (l = 0; l < mem_num; l++) {
i++;
dlen--;
ptmem++;
}
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 */
}
}
ptmem++;
}
return 0;
}
/* INITGROUP Reply:
*
* 0-3: 32bit unsigned number of results
* For each result:
* 0-7: 64bit number with gid
*/
int *errnop)
{
struct sss_cli_req_data rd;
enum nss_status nret;
long int l, max_ret;
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
/* no results if not found */
if (num_ret == 0) {
return NSS_STATUS_NOTFOUND;
}
/* check we have enough space in the buffer */
long int newsize;
}
if (!newgroups) {
return NSS_STATUS_TRYAGAIN;
}
}
for (l = 0; l < max_ret; l++) {
*start += 1;
}
return NSS_STATUS_SUCCESS;
}
{
struct sss_cli_req_data rd;
struct sss_nss_gr_rep grrep;
enum nss_status nret;
int ret;
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
/* no results if not found */
return NSS_STATUS_NOTFOUND;
}
/* only 1 result is accepted for this function */
return NSS_STATUS_TRYAGAIN;
}
if (ret) {
return NSS_STATUS_TRYAGAIN;
}
return NSS_STATUS_SUCCESS;
}
{
struct sss_cli_req_data rd;
struct sss_nss_gr_rep grrep;
enum nss_status nret;
int ret;
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
/* no results if not found */
return NSS_STATUS_NOTFOUND;
}
/* only 1 result is accepted for this function */
return NSS_STATUS_TRYAGAIN;
}
if (ret) {
return NSS_STATUS_TRYAGAIN;
}
return NSS_STATUS_SUCCESS;
}
enum nss_status _nss_sss_setgrent(void)
{
enum nss_status nret;
int errnop;
/* make sure we do not have leftovers, and release memory */
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
return NSS_STATUS_SUCCESS;
}
{
struct sss_cli_req_data rd;
struct sss_nss_gr_rep grrep;
enum nss_status nret;
int ret;
/* if there are leftovers return the next one */
if (ret) {
return NSS_STATUS_TRYAGAIN;
}
/* advance buffer pointer */
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_NOTFOUND;
}
/* call again ourselves, this will return the first result */
}
enum nss_status _nss_sss_endgrent(void)
{
enum nss_status nret;
int errnop;
/* make sure we do not have leftovers, and release memory */
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
return NSS_STATUS_SUCCESS;
}