xref: /onnv-gate/usr/src/cmd/getent/getent.c (revision 727:b3c37d16ae6c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*727Sth160488  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*727Sth160488 #include <stdlib.h>
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <string.h>
320Sstevel@tonic-gate #include <locale.h>
330Sstevel@tonic-gate #include <unistd.h>
340Sstevel@tonic-gate #include "getent.h"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate static const char *cmdname;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate struct table {
390Sstevel@tonic-gate 	char	*name;			/* name of the table */
400Sstevel@tonic-gate 	int	(*func)(const char **);	/* function to do the lookup */
410Sstevel@tonic-gate };
420Sstevel@tonic-gate 
430Sstevel@tonic-gate static struct table t[] = {
440Sstevel@tonic-gate 	{ "passwd",	dogetpw },
450Sstevel@tonic-gate 	{ "group",	dogetgr },
460Sstevel@tonic-gate 	{ "hosts",	dogethost },
470Sstevel@tonic-gate 	{ "ipnodes",	dogetipnodes },
480Sstevel@tonic-gate 	{ "services",	dogetserv },
490Sstevel@tonic-gate 	{ "protocols",	dogetproto },
500Sstevel@tonic-gate 	{ "ethers",	dogetethers },
510Sstevel@tonic-gate 	{ "networks",	dogetnet },
520Sstevel@tonic-gate 	{ "netmasks",	dogetnetmask },
530Sstevel@tonic-gate 	{ "project",	dogetproject },
540Sstevel@tonic-gate 	{ NULL,		NULL }
550Sstevel@tonic-gate };
560Sstevel@tonic-gate 
57*727Sth160488 static	void usage(void) __NORETURN;
580Sstevel@tonic-gate 
59*727Sth160488 int
main(int argc,const char ** argv)600Sstevel@tonic-gate main(int argc, const char **argv)
610Sstevel@tonic-gate {
620Sstevel@tonic-gate 	struct table *p;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
670Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEXT"
680Sstevel@tonic-gate #endif
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	cmdname = argv[0];
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	if (argc < 2)
750Sstevel@tonic-gate 		usage();
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	for (p = t; p->name != NULL; p++) {
780Sstevel@tonic-gate 		if (strcmp(argv[1], p->name) == 0) {
790Sstevel@tonic-gate 			int rc;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 			rc = (*p->func)(&argv[2]);
820Sstevel@tonic-gate 			switch (rc) {
830Sstevel@tonic-gate 			case EXC_SYNTAX:
840Sstevel@tonic-gate 				(void) fprintf(stderr,
850Sstevel@tonic-gate 					gettext("Syntax error\n"));
860Sstevel@tonic-gate 				break;
870Sstevel@tonic-gate 			case EXC_ENUM_NOT_SUPPORTED:
880Sstevel@tonic-gate 				(void) fprintf(stderr,
890Sstevel@tonic-gate 	gettext("Enumeration not supported on %s\n"), argv[1]);
900Sstevel@tonic-gate 				break;
910Sstevel@tonic-gate 			case EXC_NAME_NOT_FOUND:
920Sstevel@tonic-gate 				break;
930Sstevel@tonic-gate 			}
940Sstevel@tonic-gate 			exit(rc);
950Sstevel@tonic-gate 		}
960Sstevel@tonic-gate 	}
970Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("Unknown database: %s\n"), argv[1]);
980Sstevel@tonic-gate 	usage();
990Sstevel@tonic-gate 	/* NOTREACHED */
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate static void
usage(void)1030Sstevel@tonic-gate usage(void)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	(void) fprintf(stderr,
1060Sstevel@tonic-gate 	    gettext("usage: %s database [ key ... ]\n"), cmdname);
1070Sstevel@tonic-gate 	exit(EXC_SYNTAX);
1080Sstevel@tonic-gate }
109