ns_nis.c revision 39d3e1694f93ce0809fd2a99dd7fc32257c14da9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
*/
/*
* ns_nis.c
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <ctype.h>
#include <nsswitch.h>
#include <sys/systeminfo.h>
#include <rpcsvc/nfs_prot.h>
#include "automount.h"
#define KEY 0
#define CONTENTS 1
static int replace_undscr_by_dot(char *);
static int nis_err(int);
static char nis_mydomain[YPMAXDOMAIN];
struct dir_cbdata {
int error;
};
static int readdir_callback(int, char *, int, const char *,
int, struct dir_cbdata *);
void
{
#ifdef lint
#endif /* lint */
(void) __nis_reset_state(); /* XXX temporary hack for csh bug */
}
/*ARGSUSED*/
int
char **stack;
char ***stkptr;
{
int nserr;
if (iswildcard)
*iswildcard = FALSE;
"getmapent_nis: memory alloc failed: %m");
return (__NSW_UNAVAIL);
}
if (replace_undscr_by_dot(my_map))
}
if (nserr) {
/*
* Try the default entry "*"
*/
else
if (!nserr && iswildcard)
*iswildcard = TRUE;
} else {
if (verbose)
nserr = 1;
}
}
if (nserr)
goto done;
/*
* at this point we are sure that yp_match succeeded
* so massage the entry by
* 1. ignoring # and beyond
* 2. trim the trailing whitespace
*/
*lp = '\0';
if (len == 0) {
goto done;
}
*lp-- = '\0';
goto done;
}
/* now we have the correct line */
done:
if (nisline)
return (nserr);
}
int
char **stack;
char ***stkptr;
{
int count = 0;
first = 1;
/*
* need a private copy of mapname, because we may change
* the underscores by dots. We however do not want the
* orignal to be changed, as we may want to use the
* original name in some other name service
*/
if (my_mapname == NULL) {
/* not the name svc's fault but ... */
return (__NSW_UNAVAIL);
}
for (;;) {
if (first) {
first = 0;
"can't read nis map %s: %s - retrying",
while ((err == YPERR_DOMAIN) ||
(err == YPERR_YPBIND)) {
(void) sleep(20);
}
"nis map %s: read OK.", my_mapname);
}
} else {
}
if (err) {
if (verbose)
break;
}
if (key)
break;
break;
break;
"%s in NIS map %s: entry too long (max %d chars)",
break;
}
"%s in NIS map %s: entry too long (max %d chars)",
break;
}
pmap++; /* skip blanks in front of map */
opts++;
if (*opts) {
*opts++ = '\0';
opts++;
if (*opts == '-')
opts++;
else
}
/*
* Check for no embedded blanks.
*/
count++;
} else {
}
}
if (my_mapname)
/*
* In the context of a master map, if no entry is
* found, it is like NOTFOUND
*/
return (__NSW_SUCCESS);
else {
if (err)
else
/*
* This case will happen if map is empty
* or none of the entries is valid
*/
return (__NSW_NOTFOUND);
}
}
int
char **stack;
char ***stkptr;
{
char dir[100];
first = 1;
count = 0;
return (__NSW_UNAVAIL);
}
for (;;) {
if (first) {
first = 0;
"can't read nis map %s: %s - retrying",
while ((err == YPERR_DOMAIN) ||
(err == YPERR_YPBIND)) {
(void) sleep(20);
}
"nis map %s: read OK.", my_nismap);
}
} else {
}
if (err) {
break;
}
if (key)
continue;
continue;
count++;
}
if (my_nismap)
return (__NSW_SUCCESS);
else
}
static int
char *map;
{
int ret_val = 0;
while (*map) {
if (*map == '_') {
ret_val = 1;
*map = '.';
}
map++;
}
return (ret_val);
}
static int
int err;
{
switch (err) {
case 0:
return (__NSW_SUCCESS);
case YPERR_KEY:
return (__NSW_NOTFOUND);
case YPERR_MAP:
return (__NSW_UNAVAIL);
default:
return (__NSW_UNAVAIL);
}
}
int
char *nsmap;
int *error;
int *cache_time;
char **stack;
char ***stkptr;
{
int nserr;
struct dir_cbdata readdir_cbdata;
struct ypall_callback cback;
#ifdef lint
#endif /* lint */
/*
* XXX Hack to determine if we need to replace '_' with '.'
* Have to use yp_first() since yp_all() simply fails if
* the map is not present
*/
"getmapkeys_nis: memory alloc failed: %m");
return (__NSW_UNAVAIL);
}
if (replace_undscr_by_dot(my_map)) {
}
/*
* map not found
*/
*error = 0; /* return an empty list */
if (verbose) {
}
}
}
if (key)
if (val)
readdir_cbdata.error = 0;
/*
* after all this song and dance we finally
* ask for the list of entries
*/
if (nserr) {
if (verbose)
nserr = 1;
if (*error == 0)
}
return (__NSW_SUCCESS);
}
static int
int instatus;
char *inkey;
int inkeylen;
const char *inval;
int invallen;
struct dir_cbdata *indata;
{
char key[MAXPATHLEN];
#ifdef lint
#endif
return (0); /* next entry. yp_all may decide otherwise... */
return (0);
/*
* yp_all allocates inkey with two extra bytes which contain
* NEWLINE and null but these two bytes are not reflected in
* inkeylen.
*/
/*
* Wildcard entry should be ignored - following entries should continue
* to be read to corroborate with the way we search for entries in yp,
* i.e., first for an exact key match and then a wildcard, if there's
* no exact key match.
*/
return (0);
return (1); /* get no more entries */
}
return (0);
}