Unleashed v1.4
[unleashed.git] / usr / src / cmd / getent / getent.c
blob782034d95645ebe728a28e2c945e31c09e19bb58
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
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.
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <locale.h>
33 #include <unistd.h>
34 #include "getent.h"
36 static const char *cmdname;
38 struct table {
39 char *name; /* name of the table */
40 int (*func)(const char **); /* function to do the lookup */
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 }
62 static void usage(void) __NORETURN;
64 int
65 main(int argc, const char **argv)
67 struct table *p;
69 (void) setlocale(LC_ALL, "");
71 #if !defined(TEXT_DOMAIN)
72 #define TEXT_DOMAIN "SYS_TEXT"
73 #endif
75 (void) textdomain(TEXT_DOMAIN);
77 cmdname = argv[0];
79 if (argc < 2)
80 usage();
82 for (p = t; p->name != NULL; p++) {
83 if (strcmp(argv[1], p->name) == 0) {
84 int rc;
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;
99 exit(rc);
102 (void) fprintf(stderr, gettext("Unknown database: %s\n"), argv[1]);
103 usage();
104 /* NOTREACHED */
107 static void
108 usage(void)
110 (void) fprintf(stderr,
111 gettext("usage: %s database [ key ... ]\n"), cmdname);
112 exit(EXC_SYNTAX);