1f64ac13c0
Fri Oct 11 19:13:34 1996 Ulrich Drepper <drepper@cygnus.com> * locale/Makefile (CPPFLAGS): Set CHARMAP_PATH to "$(i18ndir)/charmaps". Fri Oct 11 22:12:41 1996 NIIBE Yutaka <gniibe@mri.co.jp> * sysdeps/unix/sysv/linux/sys/procfs.h: Include <asm/user.h> to get definition of FPU description struct. * sysdeps/unix/sysv/linux/Makefile [$(subdir)=socket] (subdir_headers): Add net/if.h, net/if_ppp.h, net/ppp-comp.h, net/ppp_defs.h, net/if_arp.h, and net/route.h. * sysdeps/unix/sysv/linux/net/if_arp.h: New file. * sysdeps/unix/sysv/linux/net/route.h: New file. Fri Oct 11 14:49:13 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/stub/readdir_r.c: New file. We need a stub version. * sysdeps/stub/e_acosl.c: Likewise. * sysdeps/stub/e_asinl.c: Likewise. * sysdeps/stub/e_atan2l.c: Likewise. * sysdeps/stub/e_expl.c: Likewise. * sysdeps/stub/e_fmodl.c: Likewise. * sysdeps/stub/e_log10l.c: Likewise. * sysdeps/stub/e_logl.c: Likewise. * sysdeps/stub/e_sqrtl.c: Likewise. * sysdeps/stub/s_atanl.c: Likewise. * sysdeps/stub/s_log1pl.c: Likewise. * Makefile (distribute): Add nsswitch.h and netgroup.h. * nss/Makefile (generated): db-netgrp.c is not generated. * sysdeps/alpha/Dist: Add stxcpy.S and stxncpy.S. * Make-dist (+out): Add $(dont_distribute). Fri Oct 11 00:27:18 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * stdio-common/Makefile (routines): Add tmpnam_r. Fri Oct 11 05:32:51 1996 Ulrich Drepper <drepper@cygnus.com> * version.h: Bump version to 1.96. Fri Oct 11 18:13:47 1996 Andreas Jaeger <aj@arthur.pfalz.de> * stdio-common/tst-printf.c: Some more cleanups. Fri Oct 11 02:48:02 1996 Ulrich Drepper <drepper@cygnus.com> * resolv/arpa/nameser.h: Update from bind-4.9.5-T6B. * resolv/resolv.h: Likewise. * resolv/gethnamaddr.c: Likewise. * resolv/res_comp.c: Likewise. * resolv/res_debug.c: Likewise. * resolv/res_init.c: Likewise. * resolv/res_send.c: Likewise. * resolv/Banner: Update version number. * nss/nss_dns/dns-host.c: Update according to change in resolv/gethnamaddr.c. Fri Oct 10 20:52:28 1996 Ralph Loader <loader@maths.ox.ac.uk> * crypt/md5.c (md5_stream): When reading the block in several pieces append to instead of replace previously read data. Thu Oct 10 15:53:17 1996 Richard Henderson <rth@tamu.edu> * sysdeps/alpha/stxcpy.S ($unaligned): In single word copy, correct last-byte-written bit for source word misalignment. * sysdeps/alpha/strchr.c: Removed. There is now an assembler version. Thu Oct 10 17:17:23 1996 Ulrich Drepper <drepper@cygnus.com> * sunrpc/Makefile (rpcsvc): Remove yp.x. The corrected version comes with glibc-nis. * sunrpc/rpcsvc/yp.x: Removed. * nss/nss_files/files-netgr.c (_nss_netgroup_parseline): Test for *CURSOR to be NULL and dump a core if yes. Thu Oct 9 20:09:53 1996 Matthew Jacob <mjacob@feral.com> * sysdeps/unix/sysv/linux/alpha/brk.S: Define _ERRNO_H before including <errnos.h> to get error numbers. Thu Oct 10 14:00:01 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/i386/sigcontext.h: Moved file... * sysdeps/unix/sysv/linux/sigcontext.h: ...to here. So the Alpha people find a correct file. * sysdeps/libm-ieee754/w_cabs.c: We cannot make __cabsl simply an alias of __cabs since the structures have different names. * sysdeps/libm-ieee754/w_log10.c: Fix typo in weak_alias. Reported by Matthew Jacob <mjacob@feral.com>. simply a wrapper around the <linux/elfcore.h> file since the
294 lines
6.9 KiB
C
294 lines
6.9 KiB
C
/* Netgroup file parser in nss_files modules.
|
||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||
This file is part of the GNU C Library.
|
||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||
|
||
The GNU C Library is free software; you can redistribute it and/or
|
||
modify it under the terms of the GNU Library General Public License as
|
||
published by the Free Software Foundation; either version 2 of the
|
||
License, or (at your option) any later version.
|
||
|
||
The GNU C Library 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
|
||
Library General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Library General Public
|
||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
Boston, MA 02111-1307, USA. */
|
||
|
||
#include <ctype.h>
|
||
#include <errno.h>
|
||
#include <libc-lock.h>
|
||
#include <netdb.h>
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include "nsswitch.h"
|
||
#include "netgroup.h"
|
||
|
||
#define DATAFILE "/etc/netgroup"
|
||
|
||
|
||
/* Locks the static variables in this file. */
|
||
__libc_lock_define_initialized (static, lock)
|
||
|
||
/* We share a single place where we store the data for the current
|
||
netgroup. This buffer is allocated by `setnetgrent' and freed on
|
||
the next call of this function or when calling `endnetgrent'. */
|
||
static char *data;
|
||
static size_t data_size;
|
||
static char *cursor;
|
||
static int first;
|
||
|
||
|
||
#define EXPAND(needed) \
|
||
do \
|
||
{ \
|
||
size_t old_cursor = cursor - data; \
|
||
\
|
||
data_size += 512 > 2 * needed ? 512 : 2 * needed; \
|
||
data = realloc (data, data_size); \
|
||
\
|
||
if (data == NULL) \
|
||
{ \
|
||
status = NSS_STATUS_UNAVAIL; \
|
||
goto the_end; \
|
||
} \
|
||
\
|
||
cursor = data + old_cursor; \
|
||
} \
|
||
while (0)
|
||
|
||
|
||
enum nss_status
|
||
_nss_files_setnetgrent (const char *group)
|
||
{
|
||
FILE *fp;
|
||
enum nss_status status;
|
||
|
||
if (group[0] == '\0')
|
||
return NSS_STATUS_UNAVAIL;
|
||
|
||
__libc_lock_lock (lock);
|
||
|
||
/* Find the netgroups file and open it. */
|
||
fp = fopen (DATAFILE, "r");
|
||
if (fp == NULL)
|
||
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
|
||
else
|
||
{
|
||
/* Read the file line by line and try to find the description
|
||
GROUP. We must take care for long lines. */
|
||
char *line = NULL;
|
||
size_t line_len = 0;
|
||
const ssize_t group_len = strlen (group);
|
||
|
||
status = NSS_STATUS_NOTFOUND;
|
||
cursor = data;
|
||
|
||
while (!feof (fp))
|
||
{
|
||
ssize_t curlen = getline (&line, &line_len, fp);
|
||
int found;
|
||
|
||
if (curlen < 0)
|
||
{
|
||
status = NSS_STATUS_NOTFOUND;
|
||
break;
|
||
}
|
||
|
||
found = (curlen > group_len && strncmp (line, group, group_len) == 0
|
||
&& isspace (line[group_len]));
|
||
|
||
/* Read the whole line (including continuation) and store it
|
||
if FOUND in nonzero. Otherwise we don't need it. */
|
||
if (found)
|
||
{
|
||
/* Store the data from the first line. */
|
||
EXPAND (curlen - group_len);
|
||
memcpy (cursor, &line[group_len + 1], curlen - group_len);
|
||
cursor += (curlen - group_len) - 1;
|
||
}
|
||
|
||
while (line[curlen - 1] == '\n' && line[curlen - 2] == '\\')
|
||
{
|
||
/* Yes, we have a continuation line. */
|
||
if (found)
|
||
/* Remove these characters from the stored line. */
|
||
cursor -= 2;
|
||
|
||
/* Get netxt line. */
|
||
curlen = getline (&line, &line_len, fp);
|
||
if (curlen <= 0)
|
||
break;
|
||
|
||
if (found)
|
||
{
|
||
/* Make sure we have enough room. */
|
||
EXPAND (1 + curlen + 1);
|
||
|
||
/* Add separator in case next line starts immediately. */
|
||
*cursor++ = ' ';
|
||
|
||
/* Copy new line. */
|
||
memcpy (cursor, line, curlen + 1);
|
||
cursor += curlen;
|
||
}
|
||
}
|
||
|
||
if (found)
|
||
{
|
||
/* Now we have read the line. */
|
||
status = NSS_STATUS_SUCCESS;
|
||
cursor = data;
|
||
first = 1;
|
||
break;
|
||
}
|
||
}
|
||
|
||
the_end:
|
||
/* We don't need the file and the line buffer anymore. */
|
||
free (line);
|
||
fclose (fp);
|
||
}
|
||
|
||
__libc_lock_unlock (lock);
|
||
|
||
return status;
|
||
}
|
||
|
||
|
||
int
|
||
_nss_files_endnetgrent (void)
|
||
{
|
||
__libc_lock_lock (lock);
|
||
|
||
/* Free allocated memory for data if some is present. */
|
||
if (data != NULL)
|
||
{
|
||
free (data);
|
||
data = NULL;
|
||
data_size = 0;
|
||
cursor = NULL;
|
||
}
|
||
|
||
__libc_lock_unlock (lock);
|
||
|
||
return NSS_STATUS_SUCCESS;
|
||
}
|
||
|
||
|
||
enum nss_status
|
||
_nss_netgroup_parseline (char **cursor, struct __netgrent *result,
|
||
char *buffer, int buflen)
|
||
{
|
||
enum nss_status status;
|
||
const char *host, *user, *domain;
|
||
char *cp = *cursor;
|
||
|
||
/* Some sanity checks. */
|
||
if (cp == NULL)
|
||
/* User bug. setnetgrent() wasn't called before. */
|
||
abort ();
|
||
|
||
/* First skip leading spaces. */
|
||
while (isspace (*cp))
|
||
++cp;
|
||
|
||
if (*cp != '(')
|
||
{
|
||
/* We have a list of other netgroups. */
|
||
char *name = cp;
|
||
|
||
while (*cp != '\0' && ! isspace (*cp))
|
||
++cp;
|
||
|
||
if (name != cp)
|
||
{
|
||
/* It is another netgroup name. */
|
||
int last = *cp == '\0';
|
||
|
||
result->type = group_val;
|
||
result->val.group = name;
|
||
*cp = '\0';
|
||
if (! last)
|
||
++cp;
|
||
*cursor = cp;
|
||
first = 0;
|
||
|
||
return NSS_STATUS_SUCCESS;
|
||
}
|
||
|
||
return first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
|
||
}
|
||
|
||
/* Match host name. */
|
||
host = ++cp;
|
||
while (*cp != ',')
|
||
if (*cp++ == '\0')
|
||
return first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
|
||
|
||
/* Match user name. */
|
||
user = ++cp;
|
||
while (*cp != ',')
|
||
if (*cp++ == '\0')
|
||
return first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
|
||
|
||
/* Match domain name. */
|
||
domain = ++cp;
|
||
while (*cp != ')')
|
||
if (*cp++ == '\0')
|
||
return first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN;
|
||
++cp;
|
||
|
||
|
||
/* When we got here we have found an entry. Before we can copy it
|
||
to the private buffer we have to make sure it is big enough. */
|
||
if (cp - host > buflen)
|
||
{
|
||
__set_errno (ERANGE);
|
||
status = NSS_STATUS_UNAVAIL;
|
||
}
|
||
else
|
||
{
|
||
memcpy (buffer, host, cp - host);
|
||
result->type = triple_val;
|
||
|
||
buffer[(user - host) - 1] = '\0';
|
||
result->val.triple.host = *host == ',' ? NULL : buffer;
|
||
|
||
buffer[(domain - host) - 1] = '\0';
|
||
result->val.triple.user = *user == ',' ? NULL : buffer + (user - host);
|
||
|
||
buffer[(cp - host) - 1] = '\0';
|
||
result->val.triple.domain =
|
||
*domain == ')' ? NULL : buffer + (domain - host);
|
||
|
||
status = NSS_STATUS_SUCCESS;
|
||
|
||
/* Rememember where we stopped reading. */
|
||
*cursor = cp;
|
||
|
||
first = 0;
|
||
}
|
||
|
||
return status;
|
||
}
|
||
|
||
|
||
enum nss_status
|
||
_nss_files_getnetgrent_r (struct __netgrent *result, char *buffer, int buflen)
|
||
{
|
||
enum nss_status status;
|
||
|
||
__libc_lock_lock (lock);
|
||
|
||
status = _nss_netgroup_parseline (&cursor, result, buffer, buflen);
|
||
|
||
__libc_lock_unlock (lock);
|
||
|
||
return status;
|
||
}
|