getgrnam_r.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "synonyms.h"
#include <mtlib.h>
#include <grp.h>
#include <memory.h>
#include <nsswitch.h>
#include <nss_dbdefs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <synch.h>
#define __NSS_PRIVATE_INTERFACE
#include "nsswitch_priv.h"
extern int _getgroupsbymember(const char *, gid_t[], int, int);
int str2group(const char *, int, void *,
char *, int);
static DEFINE_NSS_DB_ROOT(db_root);
static DEFINE_NSS_GETENT(context);
#define USE_NETID_STR "NETID_AUTHORITATIVE=TRUE"
void
{
p->name = NSS_DBNAM_GROUP;
}
#include <getxby_door.h>
static struct group *
struct group *
int buflen);
struct group *
/*
* POSIX.1c Draft-6 version of the function getgrnam_r.
* It was implemented by Solaris 2.3.
*/
struct group *
{
/*
* allocate room on the stack for the nscd to return
* group and group member information
*/
union {
char s_b[8192];
} space;
int ndata;
int adata;
return (NULL);
}
case SUCCESS: /* positive cache hit */
break;
case NOTFOUND: /* negative cache hit */
return (NULL);
default:
}
/*
* check to see if doors reallocated memory underneath us
* if they did munmap the memory or suffer a memory leak
*/
return (resptr);
}
/*
* POSIX.1c Draft-6 version of the function getgrgid_r.
* It was implemented by Solaris 2.3.
*/
struct group *
{
/*
* allocate room on the stack for the nscd to return
* group and group member information
*/
union {
char s_b[8192];
} space;
int ndata;
int adata;
case SUCCESS: /* positive cache hit */
break;
case NOTFOUND: /* negative cache hit */
return (NULL);
default:
}
/*
* check to see if doors reallocated memory underneath us
* if they did munmap the memory or suffer a memory leak
*/
return (resptr);
}
/*
* This routine should be rewritten - there's no reason it
* cannot be the same code for 32 and 64 bit w/ a bit of care.
*/
/* ARGSUSED4 */
static struct group *
{
int i;
char *fixed;
#ifdef _LP64
char *buffer32;
char **gr_mem32;
#endif /* _LP64 */
/* align buffer on a pointer boundry 4bytes in 32bits and 8 bytes in 64bits */
#ifdef _LP64
#else
#endif /* _LP64 */
return (NULL);
}
#ifdef _LP64
/*
* this is just a rationality check; we need to make
* sure that there's enough space for the gr_mem array
* as well... easiest place to do that is when we copy
* them in place.
*/
/*
* ^^^ number of bytes from nscd
*/
(sizeof (char **)) +
/*
* ^^^ we need 8 bytes for gr_mem
*/
(sizeof (char *) - 1) -
/*
* ^^^ plus space for pssibly fixing aligment of gr_mem
*/
sizeof (group32_t)
/*
* ^^^ because we don't put this in the usr buffer
*/
> buflen) {
#else
> buflen) {
#endif /* _LP64 */
return (NULL);
}
return (NULL);
/*
* ncsd is a 32bit application, so use 32bit data items if we are in 64bit mode
*/
#ifdef _LP64
for (i = 0; ; i++) {
/*
* make sure there's enough space to copy the pointer...
*/
return (NULL);
}
if (index == 0)
break;
}
#else
i = 0;
i++;
}
#endif /* _LP64 */
return (result);
}
struct group *
int buflen)
{
}
/*
* POSIX.1c standard version of the function getgrgid_r.
* User gets it via static getgrgid_r from the header file.
*/
int
{
int nerrno = 0;
errno = 0;
== NULL) {
}
return (nerrno);
}
extern struct group *
int buflen);
struct group *
int buflen)
{
}
/*
* POSIX.1c standard version of the function getgrnam_r.
* User gets it via static getgrnam_r from the header file.
*/
int
{
int nerrno = 0;
== NULL) {
}
return (nerrno);
}
void
setgrent(void)
{
}
void
endgrent(void)
{
}
struct group *
{
char *nam;
/* In getXXent_r(), protect the unsuspecting caller from +/- entries */
do {
/* No key to fill in */
}
struct group *
{
/* ... but in fgetXXent_r, the caller deserves any +/- entry he gets */
/* No key to fill in */
_nss_XbyY_fgets(f, &arg);
}
/*
* _getgroupsbymember(uname, gid_array, maxgids, numgids):
* Private interface for initgroups(). It returns the group ids of
* groups of which the specified user is a member.
*
* Arguments:
* username Username of the putative member
* gid_array Space in which to return the gids. The first [numgids]
* elements are assumed to already contain valid gids.
* maxgids Maximum number of elements in gid_array.
* numgids Number of elements (normally 0 or 1) that already contain
* valid gids.
* Return value:
* number of valid gids in gid_array (may be zero)
* or
* -1 (and errno set appropriately) on errors (none currently defined)
*/
int
{
struct nss_groupsbymem arg;
/*
* The old value being provided here was 0, ie do the quick
* way. Given that this was never actually used under NIS
* and had the wrong (now corrected) meaning for NIS+ we need
* to change the default to be 1 (TRUE) as we now need the
* admin to decided to use netid, setting NETID_AUTHORITATIVE
* force_slow_way - don't you just love double negatives ;-)
*
* We need to do this to preserve the behaviour seen when the
* admin makes no changes.
*/
/*
* stuff from libcmd, but since we are in libc we don't want to
* link ourselfs against libcmd, so instead we just do it by hand
*/
sizeof (USE_NETID_STR) - 1) == 0) {
arg.force_slow_way = 0;
break;
}
}
(void) __nsl_c_fclose(defl);
}
#ifdef undef
/*
* Only do this if there's existing code somewhere that relies on
* initgroups() doing an endgrent() -- most unlikely.
*/
endgrent();
#endif /* undef */
}
static char *
{
char *p = *nextpp;
char *q = p;
char c;
if (p == 0)
return (0);
while ((c = *q) != '\0' && c != sep)
q++;
if (c == '\0')
*nextpp = 0;
else {
*q++ = '\0';
*nextpp = q;
}
return (p);
}
/*
* Return values: 0 = success, 1 = parse error, 2 = erange ...
* The structure pointer passed in is a structure in the caller's space
* wherein the field pointers would be set to areas in the buffer if
* need be. instring and buffer should be separate areas.
*/
int
{
char *p, *next;
int black_magic; /* "+" or "-" entry */
return (NSS_STR_PARSE_ERANGE);
/*
* We copy the input string into the output buffer and
* operate on it in place.
*/
/*
* Parsers for passwd and group have always been pretty rigid;
* we wouldn't want to buck a Unix tradition
*/
if (*p == '\0') {
/* Empty group-name; not allowed */
return (NSS_STR_PARSE_PARSE);
}
/* Always return at least an empty gr_mem list */
*memlist = 0;
if (black_magic) {
/* Then the rest of the group entry is optional */
}
if (p == 0) {
if (black_magic)
return (NSS_STR_PARSE_SUCCESS);
else
return (NSS_STR_PARSE_PARSE);
}
p = next; /* gid */
if (p == 0 || *p == '\0') {
if (black_magic)
return (NSS_STR_PARSE_SUCCESS);
else
return (NSS_STR_PARSE_PARSE);
}
if (!black_magic) {
if (next == p) {
/* gid field should be nonempty */
return (NSS_STR_PARSE_PARSE);
}
/*
* gids should be non-negative; anything else
* is administrative policy.
*/
}
if (*next++ != ':') {
/* Parse error, even for a '+' entry (which should have */
/* an empty gid field, since it's always overridden) */
return (NSS_STR_PARSE_PARSE);
}
/* === Could check and complain if there are any extra colons */
if (p == 0 || *p == '\0') {
*memlist = 0;
/* Successfully parsed and stored */
return (NSS_STR_PARSE_SUCCESS);
}
*memlist++ = p;
}
/* Out of space; error even for black_magic */
return (NSS_STR_PARSE_ERANGE);
}
static nss_status_t
{
/*
* It's possible to do a much less inefficient version of this by
* selectively duplicating code from str2group(). For now,
* however, we'll take the easy way out and implement this on
* top of str2group().
*/
char **memp;
char *mem;
int parsestat;
if (buf == 0)
return (NSS_UNAVAIL);
if (parsestat != NSS_STR_PARSE_SUCCESS) {
return (NSS_NOTFOUND); /* === ? */
}
memp++) {
int i;
gidp++) {
;
}
if (i >= numgids) {
/* Filled the array; stop searching */
return (NSS_SUCCESS);
}
}
return (NSS_NOTFOUND); /* Explained in */
/* <nss_dbdefs.h> */
}
}
}
return (NSS_NOTFOUND);
}