Updated to fedora-glibc-20050808T2126
[glibc.git] / nscd / nscd_nischeck.c
blob20f7bb062078a0e3f07c27481e0967dfc9d57e8a
1 /* Copyright (c) 1999, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1999.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 /* nscd_nischeck: Check, if everybody has read permissions for NIS+ table.
21 Return value:
22 0: Everybody can read the NIS+ table
23 1: Only authenticated users could read the NIS+ table */
25 #include <argp.h>
26 #include <error.h>
27 #include <stdlib.h>
28 #include <libintl.h>
29 #include <locale.h>
30 #include <rpcsvc/nis.h>
32 /* Get libc version number. */
33 #include <version.h>
35 #define PACKAGE _libc_intl_domainname
37 /* Name and version of program. */
38 static void print_version (FILE *stream, struct argp_state *state);
39 void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version;
41 /* Data structure to communicate with argp functions. */
42 static struct argp argp =
44 NULL, NULL, NULL, NULL,
47 int
48 main (int argc, char **argv)
50 int remaining;
51 nis_result *res;
52 char *tablename, *cp;
54 /* Set locale via LC_ALL. */
55 setlocale (LC_ALL, "");
56 /* Set the text message domain. */
57 textdomain (PACKAGE);
59 /* Parse and process arguments. */
60 argp_parse (&argp, argc, argv, 0, &remaining, NULL);
62 if (remaining + 1 != argc)
64 error (0, 0, gettext ("wrong number of arguments"));
65 argp_help (&argp, stdout, ARGP_HELP_SEE, program_invocation_short_name);
66 exit (EXIT_FAILURE);
69 tablename = alloca (strlen (argv[1]) + 10);
70 cp = stpcpy (tablename, argv[1]);
71 strcpy (cp, ".org_dir");
73 res = nis_lookup (tablename, EXPAND_NAME|FOLLOW_LINKS);
75 if (res == NULL ||
76 (res->status != NIS_SUCCESS && res->status != NIS_S_SUCCESS))
77 return 0;
79 if (NIS_NOBODY(NIS_RES_OBJECT(res)->zo_access, NIS_READ_ACC))
80 return 0;
81 else
82 return 1;
85 /* Print the version information. */
86 static void
87 print_version (FILE *stream, struct argp_state *state)
89 fprintf (stream, "nscd_nischeck (GNU %s) %s\n", PACKAGE, VERSION);
90 fprintf (stream, gettext ("\
91 Copyright (C) %s Free Software Foundation, Inc.\n\
92 This is free software; see the source for copying conditions. There is NO\n\
93 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
94 "), "2005");
95 fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk");