From 397d46fdbe0dd55a8d3aee931a32d744cdf6ad27 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 13 Jun 1999 09:36:39 +0000 Subject: Enable use of nscd_nischeck and secure tables. --- nscd/Makefile | 11 +++--- nscd/connections.c | 2 +- nscd/nscd.init | 16 ++++----- nscd/nscd_nischeck.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 nscd/nscd_nischeck.c (limited to 'nscd') diff --git a/nscd/Makefile b/nscd/Makefile index d915aa70f4..b37f77781e 100644 --- a/nscd/Makefile +++ b/nscd/Makefile @@ -31,10 +31,10 @@ nscd-modules := nscd connections pwdcache getpwnam_r getpwuid_r grpcache \ ifeq ($(have-thread-library),yes) -others := nscd -install-sbin := nscd +others := nscd nscd_nischeck +install-sbin := nscd nscd_nischeck -extra-objs := $(nscd-modules:=.o) +extra-objs := $(nscd-modules:=.o) nscd_nischeck.o endif @@ -44,15 +44,18 @@ otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \ endif distribute := nscd.h nscd-client.h dbg_log.h \ - $(nscd-modules:=.c) TODO nscd.conf nscd.init \ + $(nscd-modules:=.c) nscd_nischeck.c TODO nscd.conf nscd.init \ nscd_proto.h include ../Rules $(objpfx)nscd: $(nscd-modules:%=$(objpfx)%.o) +$(objpfx)nscd_nischeck: $(objpfx)nscd_nischeck.o ifeq ($(build-shared),yes) $(objpfx)nscd: $(shared-thread-library) $(common-objpfx)nis/libnsl.so +$(objpfx)nscd_nischeck: $(common-objpfx)nis/libnsl.so else $(objpfx)nscd: $(static-thread-library) $(common-objpfx)nis/libnsl.a +$(objpfx)nscd_nischeck: $(common-objpfx)nis/libnsl.a endif diff --git a/nscd/connections.c b/nscd/connections.c index 3f05d685ef..4daa09926d 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -412,7 +412,7 @@ nscd_run (void *p) continue; } - if (req.type < GETPWBYNAME || req.type >= LASTREQ + if (req.type < GETPWBYNAME || req.type > LASTDBREQ || secure[serv2db[req.type]]) uid = caller.uid; } diff --git a/nscd/nscd.init b/nscd/nscd.init index 63172a0d1a..6dc9d76b33 100644 --- a/nscd/nscd.init +++ b/nscd/nscd.init @@ -22,14 +22,14 @@ case "$1" in start) secure="" -# for table in passwd group -# do -# if egrep '^'$table':.*nisplus' /etc/nsswitch.conf >/dev/null -# then -# /usr/lib/nscd_nischeck $table || -# secure="$secure -S $table,yes" -# fi -# done + for table in passwd group hosts + do + if egrep '^'$table':.*nisplus' /etc/nsswitch.conf >/dev/null + then + /usr/sbin/nscd_nischeck $table || + secure="$secure -S $table,yes" + fi + done echo -n "Starting Name Switch Cache Daemon: " daemon nscd $secure echo diff --git a/nscd/nscd_nischeck.c b/nscd/nscd_nischeck.c new file mode 100644 index 0000000000..aeb165ed4e --- /dev/null +++ b/nscd/nscd_nischeck.c @@ -0,0 +1,96 @@ +/* Copyright (c) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Thorsten Kukuk , 1999. + + 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. */ + +/* nscd_nischeck: Check, if everybody has read permissions for NIS+ table. + Return value: + 0: Everybody can read the NIS+ table + 1: Only authenticated Users could read the NIS+ table */ + +#include +#include +#include +#include +#include +#include + +/* Get libc version number. */ +#include + +#define PACKAGE _libc_intl_domainname + +/* Name and version of program. */ +static void print_version (FILE *stream, struct argp_state *state); +void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; + +/* Data structure to communicate with argp functions. */ +static struct argp argp = +{ + NULL, NULL, NULL, NULL, +}; + +int +main (int argc, char **argv) +{ + int remaining; + nis_result *res; + char *tablename, *cp; + + /* Set locale via LC_ALL. */ + setlocale (LC_ALL, ""); + /* Set the text message domain. */ + textdomain (PACKAGE); + + /* Parse and process arguments. */ + argp_parse (&argp, argc, argv, 0, &remaining, NULL); + + if (remaining + 1 != argc) + { + error (0, 0, gettext ("wrong number of arguments")); + argp_help (&argp, stdout, ARGP_HELP_SEE, program_invocation_short_name); + exit (EXIT_FAILURE); + } + + tablename = alloca (strlen (argv[1]) + 10); + cp = stpcpy (tablename, argv[1]); + strcpy (cp, ".org_dir"); + + res = nis_lookup (tablename, EXPAND_NAME|FOLLOW_LINKS); + + if (res == NULL || + (res->status != NIS_SUCCESS && res->status != NIS_S_SUCCESS)) + return 0; + + if (NIS_NOBODY(NIS_RES_OBJECT(res)->zo_access, NIS_READ_ACC)) + return 0; + else + return 1; +} + +/* Print the version information. */ +static void +print_version (FILE *stream, struct argp_state *state) +{ + fprintf (stream, "nscd_checknis (GNU %s) %s\n", PACKAGE, VERSION); + fprintf (stream, gettext ("\ +Copyright (C) %s Free Software Foundation, Inc.\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ +"), "1999"); + fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk"); +} -- cgit v1.2.3