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 (c) 2018 Peter Tribble. 24 * Copyright (c) 2014 Gary Mills 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 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 { "auth_attr", dogetauthattr }, 56 { "exec_attr", dogetexecattr }, 57 { "prof_attr", dogetprofattr }, 58 { "user_attr", dogetuserattr }, 59 { NULL, NULL } 60 }; 61 62 static void usage(void) __NORETURN; 63 64 int 65 main(int argc, const char **argv) 66 { 67 struct table *p; 68 69 (void) setlocale(LC_ALL, ""); 70 71 #if !defined(TEXT_DOMAIN) 72 #define TEXT_DOMAIN "SYS_TEXT" 73 #endif 74 75 (void) textdomain(TEXT_DOMAIN); 76 77 cmdname = argv[0]; 78 79 if (argc < 2) 80 usage(); 81 82 for (p = t; p->name != NULL; p++) { 83 if (strcmp(argv[1], p->name) == 0) { 84 int rc; 85 86 rc = (*p->func)(&argv[2]); 87 switch (rc) { 88 case EXC_SYNTAX: 89 (void) fprintf(stderr, 90 gettext("Syntax error\n")); 91 break; 92 case EXC_ENUM_NOT_SUPPORTED: 93 (void) fprintf(stderr, 94 gettext("Enumeration not supported on %s\n"), argv[1]); 95 break; 96 case EXC_NAME_NOT_FOUND: 97 break; 98 } 99 exit(rc); 100 } 101 } 102 (void) fprintf(stderr, gettext("Unknown database: %s\n"), argv[1]); 103 usage(); 104 /* NOTREACHED */ 105 } 106 107 static void 108 usage(void) 109 { 110 (void) fprintf(stderr, 111 gettext("usage: %s database [ key ... ]\n"), cmdname); 112 exit(EXC_SYNTAX); 113 } 114