17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*00277c9eSGary Mills * Copyright (c) 2014 Gary Mills 2454719d5eSth160488 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 2854719d5eSth160488 #include <stdlib.h> 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <string.h> 317c478bd9Sstevel@tonic-gate #include <locale.h> 327c478bd9Sstevel@tonic-gate #include <unistd.h> 337c478bd9Sstevel@tonic-gate #include "getent.h" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate static const char *cmdname; 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate struct table { 387c478bd9Sstevel@tonic-gate char *name; /* name of the table */ 397c478bd9Sstevel@tonic-gate int (*func)(const char **); /* function to do the lookup */ 407c478bd9Sstevel@tonic-gate }; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate static struct table t[] = { 437c478bd9Sstevel@tonic-gate { "passwd", dogetpw }, 44*00277c9eSGary Mills { "shadow", dogetsp }, 457c478bd9Sstevel@tonic-gate { "group", dogetgr }, 467c478bd9Sstevel@tonic-gate { "hosts", dogethost }, 477c478bd9Sstevel@tonic-gate { "ipnodes", dogetipnodes }, 487c478bd9Sstevel@tonic-gate { "services", dogetserv }, 497c478bd9Sstevel@tonic-gate { "protocols", dogetproto }, 507c478bd9Sstevel@tonic-gate { "ethers", dogetethers }, 517c478bd9Sstevel@tonic-gate { "networks", dogetnet }, 527c478bd9Sstevel@tonic-gate { "netmasks", dogetnetmask }, 537c478bd9Sstevel@tonic-gate { "project", dogetproject }, 547c478bd9Sstevel@tonic-gate { NULL, NULL } 557c478bd9Sstevel@tonic-gate }; 567c478bd9Sstevel@tonic-gate 5754719d5eSth160488 static void usage(void) __NORETURN; 587c478bd9Sstevel@tonic-gate 5954719d5eSth160488 int 607c478bd9Sstevel@tonic-gate main(int argc, const char **argv) 617c478bd9Sstevel@tonic-gate { 627c478bd9Sstevel@tonic-gate struct table *p; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 677c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEXT" 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate cmdname = argv[0]; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate if (argc < 2) 757c478bd9Sstevel@tonic-gate usage(); 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate for (p = t; p->name != NULL; p++) { 787c478bd9Sstevel@tonic-gate if (strcmp(argv[1], p->name) == 0) { 797c478bd9Sstevel@tonic-gate int rc; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate rc = (*p->func)(&argv[2]); 827c478bd9Sstevel@tonic-gate switch (rc) { 837c478bd9Sstevel@tonic-gate case EXC_SYNTAX: 847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 857c478bd9Sstevel@tonic-gate gettext("Syntax error\n")); 867c478bd9Sstevel@tonic-gate break; 877c478bd9Sstevel@tonic-gate case EXC_ENUM_NOT_SUPPORTED: 887c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 897c478bd9Sstevel@tonic-gate gettext("Enumeration not supported on %s\n"), argv[1]); 907c478bd9Sstevel@tonic-gate break; 917c478bd9Sstevel@tonic-gate case EXC_NAME_NOT_FOUND: 927c478bd9Sstevel@tonic-gate break; 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate exit(rc); 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Unknown database: %s\n"), argv[1]); 987c478bd9Sstevel@tonic-gate usage(); 997c478bd9Sstevel@tonic-gate /* NOTREACHED */ 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate static void 1037c478bd9Sstevel@tonic-gate usage(void) 1047c478bd9Sstevel@tonic-gate { 1057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1067c478bd9Sstevel@tonic-gate gettext("usage: %s database [ key ... ]\n"), cmdname); 1077c478bd9Sstevel@tonic-gate exit(EXC_SYNTAX); 1087c478bd9Sstevel@tonic-gate } 109