1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <stdlib.h>
  30 #include <stdio.h>
  31 #include <string.h>
  32 #include <locale.h>
  33 #include <unistd.h>
  34 #include "getent.h"
  35 
  36 static const char *cmdname;
  37 
  38 struct table {
  39         char    *name;                  /* name of the table */
  40         int     (*func)(const char **); /* function to do the lookup */
  41 };
  42 
  43 static struct table t[] = {
  44         { "passwd",     dogetpw },
  45         { "shadow",     dogetsp },
  46         { "group",      dogetgr },
  47         { "hosts",      dogethost },
  48         { "ipnodes",    dogetipnodes },
  49         { "services",   dogetserv },
  50         { "protocols",  dogetproto },
  51         { "ethers",     dogetethers },
  52         { "networks",   dogetnet },
  53         { "netmasks",   dogetnetmask },
  54         { "project",    dogetproject },
  55         { NULL,         NULL }
  56 };
  57 
  58 static  void usage(void) __NORETURN;
  59 
  60 int
  61 main(int argc, const char **argv)
  62 {
  63         struct table *p;
  64 
  65         (void) setlocale(LC_ALL, "");
  66 
  67 #if !defined(TEXT_DOMAIN)
  68 #define TEXT_DOMAIN     "SYS_TEXT"
  69 #endif
  70 
  71         (void) textdomain(TEXT_DOMAIN);
  72 
  73         cmdname = argv[0];
  74 
  75         if (argc < 2)
  76                 usage();
  77 
  78         for (p = t; p->name != NULL; p++) {
  79                 if (strcmp(argv[1], p->name) == 0) {
  80                         int rc;
  81 
  82                         rc = (*p->func)(&argv[2]);
  83                         switch (rc) {
  84                         case EXC_SYNTAX:
  85                                 (void) fprintf(stderr,
  86                                         gettext("Syntax error\n"));
  87                                 break;
  88                         case EXC_ENUM_NOT_SUPPORTED:
  89                                 (void) fprintf(stderr,
  90         gettext("Enumeration not supported on %s\n"), argv[1]);
  91                                 break;
  92                         case EXC_NAME_NOT_FOUND:
  93                                 break;
  94                         }
  95                         exit(rc);
  96                 }
  97         }
  98         (void) fprintf(stderr, gettext("Unknown database: %s\n"), argv[1]);
  99         usage();
 100         /* NOTREACHED */
 101 }
 102 
 103 static void
 104 usage(void)
 105 {
 106         (void) fprintf(stderr,
 107             gettext("usage: %s database [ key ... ]\n"), cmdname);
 108         exit(EXC_SYNTAX);
 109 }