8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / userattr / userattr.c
blob1b5e078a0edd933b43f9c78a5f74930e8df7b93c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <errno.h>
27 #include <locale.h>
28 #include <pwd.h>
29 #include <secdb.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
35 #include <sys/types.h>
37 boolean_t verbose = B_FALSE;
38 char *attr_name = NULL;
40 #if !defined(TEXT_DOMAIN)
41 #define TEXT_DOMAIN "SYS_TEST"
42 #endif /* !TEXT_DOMAIN */
45 * userattr [-v] attr_name [user]
48 /* ARGSUSED */
49 static int
50 attr(const char *name, kva_t *kva, void *ctxt, void *pres)
52 char *val;
54 if ((val = kva_match(kva, attr_name)) != NULL) {
55 if (verbose) {
56 char *prof_name = "user_attr";
58 if (name != NULL) {
59 prof_name = (char *)name;
61 (void) printf("%s : %s\n", prof_name, val);
62 } else {
63 (void) printf("%s\n", val);
65 exit(0);
68 return (0); /* no match */
71 int
72 main(int argc, char *argv[])
74 int opt = 1;
75 char *user = NULL;
76 struct passwd *pwd;
78 (void) setlocale(LC_ALL, "");
79 (void) textdomain(TEXT_DOMAIN);
81 if ((argc >= 2) &&
82 (strncmp(argv[opt], "-v", sizeof ("-v")) == 0)) {
83 verbose = B_TRUE;
84 opt++;
85 argc--;
87 if (argc >= 2) {
88 attr_name = argv[opt++];
90 if (argc >= 3) {
91 user = argv[opt++];
94 if ((attr_name == NULL) || (opt < argc)) {
95 (void) fprintf(stderr,
96 gettext("Usage: %s [-v] attribute_name [user]\n"), argv[0]);
97 exit(1);
100 if (user == NULL) {
101 uid_t uid = getuid();
103 if ((pwd = getpwuid(uid)) == NULL) {
104 (void) fprintf(stderr,
105 gettext("Cannot find user for uid %d\n"), uid);
106 exit(1);
108 user = pwd->pw_name;
109 } else {
110 if ((pwd = getpwnam(user)) == NULL) {
111 (void) fprintf(stderr,
112 gettext("No such user %s\n"), user);
113 exit(1);
117 (void) _enum_attrs(user, attr, NULL, NULL);
119 if (verbose) {
120 (void) fprintf(stderr,
121 gettext("attribute \"%s\" not found for %s\n"), attr_name,
122 user);
125 return (1);