/*
* 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
*/
/*
*/
#include "lint.h"
#include "file64.h"
#include "mtlib.h"
#include "libc.h"
#include <synch.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio_ext.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <dlfcn.h>
#include <errno.h>
#include "stdiom.h"
#define __NSS_PRIVATE_INTERFACE
#include "nsswitch_priv.h"
#include <syslog.h>
dup_fail = 1; \
goto barf_line; \
}
/*
* This file has all the routines that access the configuration
* information.
*/
};
};
/*
* Local routines
*/
static char *skip(char **, char);
static char *labelskip(char *);
static char *spaceskip(char *);
static struct __nsw_switchconfig_v1 *scrounge_cache_v1(const char *);
static struct __nsw_switchconfig *scrounge_cache(const char *);
static int add_concell_v1(struct __nsw_switchconfig_v1 *);
static int add_concell(struct __nsw_switchconfig *);
static void freeconf_v1(struct __nsw_switchconfig_v1 *);
static void freeconf(struct __nsw_switchconfig *);
static int alldigits(char *);
/*
*
* With the "lookup control" feature, the default criteria for NIS and any
* new services (e.g. ldap) will be:
* [SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=forever]
*
* For backward compat, NIS via NIS server in DNS forwarding mode will be:
* [SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=continue]
*
* And also for backward compat, the default criteria for DNS will be:
* [SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=continue]
*/
/*
* The BIND resolver normally will retry several times on server non-response.
* But now with the "lookup control" feature, we don't want the resolver doing
* many retries, rather we want it to return control (reasonably) quickly back
* to the switch engine. However, when TRYAGAIN=N or TRYAGAIN=forever is
* not explicitly set by the admin in the conf file, we want the old "resolver
* retry a few times" rather than no retries at all.
*/
/*
* For backward compat (pre "lookup control"), the dns default behavior is
* soft lookup.
*/
static void
{
}
}
/*
* Private interface used by nss_common.c, hence this function is not static
*/
struct __nsw_switchconfig_v1 *
/* linep Nota Bene: not const char * */
/* errp Meanings are abused a bit */
{
char *p, *tokenp;
== NULL) {
return (NULL);
}
/* linep points to a naming service name */
for (;;) {
int i;
/* white space following the last service */
return (cfp);
}
== NULL) {
return (NULL);
}
for (i = 0; i < __NSW_STD_ERRS_V1; i++)
if (i == __NSW_SUCCESS)
else if (i == __NSW_TRYAGAIN)
else
/* get criteria for the naming service */
/* premature end, illegal char following [ */
goto barf_line;
cfp->num_lookups++;
end_crit = 0;
/* linep points to a switch_err */
for (;;) {
int dns_continue = 0;
goto barf_line;
}
/* premature end, ill char following = */
goto barf_line;
/* linep points to the string following '=' */
if (*p == ']')
end_crit = 1;
else if (*p != ' ' && *p != '\t')
goto barf_line;
*p++ = '\0'; /* null terminate linep */
p = spaceskip(p);
if (!end_crit) {
if (*p == ']') {
end_crit = 1;
*p++ = '\0';
} else if (*p == '\0' || *p == '\n') {
return (cfp);
} else if (!islabel(*p))
/* p better be the next switch_err */
goto barf_line;
}
act = __NSW_RETURN;
else if (strcasecmp(linep,
__NSW_STR_CONTINUE) == 0) {
"dns") == 0 &&
== 0) {
/*
* Add one more condition
* so it retries only if it's
* "dns [TRYAGAIN=continue]"
*/
dns_continue = 1;
} else
} else if (strcasecmp(linep,
__NSW_STR_FOREVER) == 0)
ntimes = 0;
}
else
goto barf_line;
if (__NSW_SUCCESS_ACTION(act) &&
__NSW_STR_SUCCESS) == 0) {
} else if (__NSW_NOTFOUND_ACTION(act) &&
__NSW_STR_NOTFOUND) == 0) {
} else if (__NSW_UNAVAIL_ACTION(act) &&
__NSW_STR_UNAVAIL) == 0) {
} else if (__NSW_TRYAGAIN_ACTION(act) &&
__NSW_STR_TRYAGAIN) == 0) {
"nis") == 0)
= act;
if (act == __NSW_TRYAGAIN_NTIMES)
lkp->max_retries =
} else {
/*EMPTY*/
/*
* convert string tokenp to integer
* and put in long_errs
*/
}
if (end_crit) {
return (cfp);
break; /* process next naming service */
}
linep = p;
} /* end of while loop for a name service's criteria */
} else {
/*
* no criteria for this naming service.
* linep points to name service, but not null
* terminated.
*/
if (*p == '\0' || *p == '\n') {
*p = '\0';
cfp->num_lookups++;
return (cfp);
}
if (*p != ' ' && *p != '\t')
goto barf_line;
*p++ = '\0';
cfp->num_lookups++;
}
} /* end of while(1) loop for a name service */
return (NULL);
}
/*
* Private interface used by nss_common.c, hence this function is not static
*/
struct __nsw_switchconfig *
/* linep Nota Bene: not const char * */
/* errp Meanings are abused a bit */
{
char *p, *tokenp;
== NULL) {
return (NULL);
}
/* linep points to a naming service name */
for (;;) {
int i;
/* white space following the last service */
return (cfp);
}
== NULL) {
return (NULL);
}
for (i = 0; i < __NSW_STD_ERRS; i++)
if (i == __NSW_SUCCESS)
else
/* get criteria for the naming service */
/* premature end, illegal char following [ */
goto barf_line;
cfp->num_lookups++;
end_crit = 0;
/* linep points to a switch_err */
for (;;) {
goto barf_line;
}
/* premature end, ill char following = */
goto barf_line;
/* linep points to the string following '=' */
if (*p == ']')
end_crit = 1;
else if (*p != ' ' && *p != '\t')
goto barf_line;
*p++ = '\0'; /* null terminate linep */
p = spaceskip(p);
if (!end_crit) {
if (*p == ']') {
end_crit = 1;
*p++ = '\0';
} else if (*p == '\0' || *p == '\n')
return (cfp);
else if (!islabel(*p))
/* p better be the next switch_err */
goto barf_line;
}
act = __NSW_RETURN;
else if (strcasecmp(linep,
__NSW_STR_CONTINUE) == 0)
else if (strcasecmp(linep,
__NSW_STR_FOREVER) == 0)
/*
* =forever or =N might be in conf file
* but old progs won't expect it.
*/
act = __NSW_RETURN;
else
goto barf_line;
if (strcasecmp(tokenp,
__NSW_STR_SUCCESS) == 0) {
} else if (strcasecmp(tokenp,
__NSW_STR_NOTFOUND) == 0) {
} else if (strcasecmp(tokenp,
__NSW_STR_UNAVAIL) == 0) {
} else if (strcasecmp(tokenp,
__NSW_STR_TRYAGAIN) == 0) {
} else {
/*EMPTY*/
/*
* convert string tokenp to integer
* and put in long_errs
*/
}
if (end_crit) {
return (cfp);
break; /* process next naming service */
}
linep = p;
} /* end of while loop for a name service's criteria */
} else {
/*
* no criteria for this naming service.
* linep points to name service, but not null
* terminated.
*/
if (*p == '\0' || *p == '\n') {
*p = '\0';
cfp->num_lookups++;
return (cfp);
}
if (*p != ' ' && *p != '\t')
goto barf_line;
*p++ = '\0';
cfp->num_lookups++;
}
} /* end of while(1) loop for a name service */
return (NULL);
}
static void
{
"libc: bad lookup policy for %s in %s, using defaults..\n",
}
/*
* Since we cannot call malloc() or lock any of the ordinary mutexes
* while we hold an lmutex_lock(), we open the file outside the lock
* and disable locking on the file; the latter is fine because we're
* reading the fp only from a single thread.
*/
static FILE *
open_conf(void)
{
return (NULL);
}
}
return (fp);
}
struct __nsw_switchconfig_v1 *
{
int syslog_error = 0;
char *linep;
top:
return (cfp);
}
/* open_conf() must be called w/o locks held */
return (NULL);
}
/* Cache changed? */
if (cp != concell_list_v1)
goto top;
}
/*
* Ignore portion of line following the comment character '#'.
*/
*comment = '\0';
}
/*
* skip past blank lines.
* otherwise, cache as a struct switchconfig.
*/
continue;
}
continue; /* ignore this line */
}
continue; /* ? somehow this database is in the cache */
}
(void) add_concell_v1(cfp);
}
} else {
/*
* Got an error on this line, if it is a system
* error we might as well give right now. If it
* is a parse error on the second entry of the
* database we are looking for and the first one
* was a good entry we end up logging the following
* syslog message and using a default policy instead.
*/
if (line_err == __NSW_CONF_PARSE_SYSERR) {
break;
} else if (line_err == __NSW_CONF_PARSE_NOPOLICY &&
syslog_error = 1;
break;
}
/*
* Else blithely ignore problems on this line and
* go ahead with the next line.
*/
}
}
/*
* We have to drop the lock before calling fclose()/syslog().
*/
if (syslog_error)
return (retp);
}
struct __nsw_switchconfig *
{
int syslog_error = 0;
char *linep;
top:
return (cfp);
}
/* open_conf() must be called w/o locks held */
return (NULL);
}
/* Cache changed? */
if (cp != concell_list)
goto top;
}
/*
* Ignore portion of line following the comment character '#'.
*/
*comment = '\0';
}
/*
* skip past blank lines.
* otherwise, cache as a struct switchconfig.
*/
continue;
}
continue; /* ignore this line */
}
continue; /* ? somehow this database is in the cache */
}
(void) add_concell(cfp);
}
} else {
/*
* Got an error on this line, if it is a system
* error we might as well give right now. If it
* is a parse error on the second entry of the
* database we are looking for and the first one
* was a good entry we end up logging the following
* syslog message and using a default policy instead.
*/
if (line_err == __NSW_CONF_PARSE_SYSERR) {
break;
} else if (line_err == __NSW_CONF_PARSE_NOPOLICY &&
syslog_error = 1;
break;
}
/*
* Else blithely ignore problems on this line and
* go ahead with the next line.
*/
}
}
/*
* We have to drop the lock before calling fclose()/syslog().
*/
if (syslog_error)
return (retp);
}
static struct __nsw_switchconfig_v1 *
{
return (NULL);
}
static struct __nsw_switchconfig *
{
return (NULL);
}
static void
{
if (cfp) {
}
}
}
}
static void
{
if (cfp) {
}
}
}
}
{
}
return (__NSW_CONTINUE);
}
{
}
return (__NSW_CONTINUE);
}
/* give the next non-alpha character */
static char *
{
char *p = cur;
while (islabel(*p))
++p;
return (p);
}
/* give the next non-space character */
static char *
{
char *p = cur;
while (*p == ' ' || *p == '\t')
++p;
return (p);
}
/*
* terminate the *cur pointed string by null only if it is
* followed by "key" surrounded by zero or more spaces and
* return value is the same as the original *cur pointer and
* *cur pointer is advanced to the first non {space, key} char
* followed by the key. Otherwise, return NULL and keep
* *cur unchanged.
*/
static char *
{
char *p, *tmp;
char *q = *cur;
p = tmp;
if (found) {
*p++ = '\0'; /* overwrite the key */
p = spaceskip(p);
} else {
while (*p == ' ' || *p == '\t') {
if (tmpfound) {
/* null terminate the return token */
*tmp = '\0';
p++; /* skip the key */
}
}
}
if (!found)
return (NULL); /* *cur unchanged */
*cur = p;
return (q);
}
/* add to the front: LRU */
static int
{
return (1);
return (1);
return (0);
}
/* add to the front: LRU */
static int
{
return (1);
return (1);
concell_list = cp;
return (0);
}
int
{
return (-1);
}
/*
* Hacked to make life easy for the code in nss_common.c. Free conf
* iff it was created by calling _nsw_getoneconfig() directly
* rather than by calling nsw_getconfig.
*/
break;
}
}
/* Not in the cache; free it */
return (1);
} else {
/* In the cache; don't free it */
return (0);
}
}
int
{
return (-1);
}
/*
* Hacked to make life easy for the code in nss_common.c. Free conf
* iff it was created by calling _nsw_getoneconfig() directly
* rather than by calling nsw_getconfig.
*/
break;
}
}
/* Not in the cache; free it */
return (1);
} else {
/* In the cache; don't free it */
return (0);
}
}
/* Return 1 if the string contains all digits, else return 0. */
static int
alldigits(char *s)
{
for (; *s; s++)
if (!isdigit(*s))
return (0);
return (1);
}