* nis/nss-default.c (init): Rewrite parse to get the variables

from a table.
This commit is contained in:
Ulrich Drepper 2006-04-28 19:07:15 +00:00
parent 4718026de2
commit ee821689eb
2 changed files with 26 additions and 17 deletions

View File

@ -1,5 +1,8 @@
2006-04-28 Ulrich Drepper <drepper@redhat.com> 2006-04-28 Ulrich Drepper <drepper@redhat.com>
* nis/nss-default.c (init): Rewrite parse to get the variables
from a table.
* nis/nss_nis/nis-service.c: Avoid passing pointer to static * nis/nss_nis/nis-service.c: Avoid passing pointer to static
variable around. Reduce number of memory allocations by creating variable around. Reduce number of memory allocations by creating
list of memory pools. list of memory pools.

View File

@ -35,6 +35,20 @@ static int default_nss_flags;
/* Code to make sure we call 'init' once. */ /* Code to make sure we call 'init' once. */
__libc_once_define (static, once); __libc_once_define (static, once);
/* Table of the recognized variables. */
static const struct
{
char name[23];
unsigned int len;
int flag;
} vars[] =
{
#define STRNLEN(s) s, sizeof (s) - 1
{ STRNLEN ("NETID_AUTHORITATIVE"), NSS_FLAG_NETID_AUTHORITATIVE },
{ STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE }
};
#define nvars (sizeof (vars) / sizeof (vars[0]))
static void static void
init (void) init (void)
@ -53,11 +67,9 @@ init (void)
if (n <= 0) if (n <= 0)
break; break;
/* There currently are only two variables we expect, so /* Recognize only
simplify the parsing. Recognize only
NETID_AUTHORITATIVE = TRUE <THE-VARIABLE> = TRUE
SERVICES_AUTHORITATIVE = TRUE
with arbitrary white spaces. */ with arbitrary white spaces. */
char *cp = line; char *cp = line;
@ -68,18 +80,14 @@ init (void)
if (*cp == '#') if (*cp == '#')
continue; continue;
static const char netid_authoritative[] = "NETID_AUTHORITATIVE"; int idx;
static const char services_authoritative[] for (idx = 0; idx < nvars; ++idx)
= "SERVICES_AUTHORITATIVE"; if (strncmp (cp, vars[idx].name, vars[idx].len) == 0)
size_t flag_len; break;
if (strncmp (cp, netid_authoritative, if (idx == nvars)
flag_len = sizeof (netid_authoritative) - 1) != 0
&& strncmp (cp, services_authoritative,
flag_len = sizeof (services_authoritative) - 1)
!= 0)
continue; continue;
cp += flag_len; cp += vars[idx].len;
while (isspace (*cp)) while (isspace (*cp))
++cp; ++cp;
if (*cp++ != '=') if (*cp++ != '=')
@ -95,9 +103,7 @@ init (void)
++cp; ++cp;
if (*cp == '\0') if (*cp == '\0')
default_nss_flags |= (flag_len == sizeof (netid_authoritative) - 1 default_nss_flags |= vars[idx].flag;
? NSS_FLAG_NETID_AUTHORITATIVE
: NSS_FLAG_SERVICES_AUTHORITATIVE);
} }
free (line); free (line);