149c13cfgww/*
249c13cfgww * CDDL HEADER START
349c13cfgww *
449c13cfgww * The contents of this file are subject to the terms of the
549c13cfgww * Common Development and Distribution License (the "License").
649c13cfgww * You may not use this file except in compliance with the License.
749c13cfgww *
849c13cfgww * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
949c13cfgww * or http://www.opensolaris.org/os/licensing.
1049c13cfgww * See the License for the specific language governing permissions
1149c13cfgww * and limitations under the License.
1249c13cfgww *
1349c13cfgww * When distributing Covered Code, include this CDDL HEADER in each
1449c13cfgww * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1549c13cfgww * If applicable, add the following below this CDDL HEADER, with the
1649c13cfgww * fields enclosed by brackets "[]" replaced with your own identifying
1749c13cfgww * information: Portions Copyright [yyyy] [name of copyright owner]
1849c13cfgww *
1949c13cfgww * CDDL HEADER END
2049c13cfgww */
2149c13cfgww
2249c13cfgww/*
2349c13cfgww * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2449c13cfgww */
2549c13cfgww
2649c13cfgww#include <errno.h>
2749c13cfgww#include <locale.h>
2849c13cfgww#include <pwd.h>
2949c13cfgww#include <secdb.h>
3049c13cfgww#include <stdio.h>
3149c13cfgww#include <stdlib.h>
3249c13cfgww#include <string.h>
3349c13cfgww#include <unistd.h>
3449c13cfgww
3549c13cfgww#include <sys/types.h>
3649c13cfgww
3749c13cfgwwboolean_t	verbose = B_FALSE;
3849c13cfgwwchar		*attr_name = NULL;
3949c13cfgww
4049c13cfgww#if	!defined(TEXT_DOMAIN)
4149c13cfgww#define	TEXT_DOMAIN "SYS_TEST"
4249c13cfgww#endif	/* !TEXT_DOMAIN */
4349c13cfgww
4449c13cfgww/*
4549c13cfgww *	userattr [-v] attr_name [user]
4649c13cfgww */
4749c13cfgww
4849c13cfgww/* ARGSUSED */
4949c13cfgwwstatic int
5049c13cfgwwattr(const char *name, kva_t *kva, void *ctxt, void *pres)
5149c13cfgww{
5249c13cfgww	char 	*val;
5349c13cfgww
5449c13cfgww	if ((val = kva_match(kva, attr_name)) != NULL) {
5549c13cfgww		if (verbose) {
5649c13cfgww			char *prof_name = "user_attr";
5749c13cfgww
5849c13cfgww			if (name != NULL) {
5949c13cfgww				prof_name = (char *)name;
6049c13cfgww			}
6149c13cfgww			(void) printf("%s : %s\n", prof_name, val);
6249c13cfgww		} else {
6349c13cfgww			(void) printf("%s\n", val);
6449c13cfgww		}
6549c13cfgww		exit(0);
6649c13cfgww	}
6749c13cfgww
6849c13cfgww	return (0);	/* no match */
6949c13cfgww}
7049c13cfgww
7149c13cfgwwint
7249c13cfgwwmain(int argc, char *argv[])
7349c13cfgww{
7449c13cfgww	int	opt = 1;
7549c13cfgww	char	*user = NULL;
7649c13cfgww	struct passwd *pwd;
7749c13cfgww
7849c13cfgww	(void) setlocale(LC_ALL, "");
7949c13cfgww	(void) textdomain(TEXT_DOMAIN);
8049c13cfgww
8149c13cfgww	if ((argc >= 2) &&
8249c13cfgww	    (strncmp(argv[opt], "-v", sizeof ("-v")) == 0)) {
8349c13cfgww		verbose = B_TRUE;
8449c13cfgww		opt++;
8549c13cfgww		argc--;
8649c13cfgww	}
8749c13cfgww	if (argc >= 2) {
8849c13cfgww		attr_name = argv[opt++];
8949c13cfgww	}
9049c13cfgww	if (argc >= 3) {
9149c13cfgww		user = argv[opt++];
9249c13cfgww	}
9349c13cfgww
9449c13cfgww	if ((attr_name == NULL) || (opt < argc)) {
9549c13cfgww		(void) fprintf(stderr,
9649c13cfgww		    gettext("Usage: %s [-v] attribute_name [user]\n"), argv[0]);
9749c13cfgww		exit(1);
9849c13cfgww	}
9949c13cfgww
10049c13cfgww	if (user == NULL) {
10149c13cfgww		uid_t	uid = getuid();
10249c13cfgww
10349c13cfgww		if ((pwd = getpwuid(uid)) == NULL) {
10449c13cfgww			(void) fprintf(stderr,
10549c13cfgww			    gettext("Cannot find user for uid %d\n"), uid);
10649c13cfgww			exit(1);
10749c13cfgww		}
10849c13cfgww		user = pwd->pw_name;
10949c13cfgww	} else {
11049c13cfgww		if ((pwd = getpwnam(user)) == NULL) {
11149c13cfgww			(void) fprintf(stderr,
11249c13cfgww			    gettext("No such user %s\n"), user);
11349c13cfgww			exit(1);
11449c13cfgww		}
11549c13cfgww	}
11649c13cfgww
11749c13cfgww	(void) _enum_attrs(user, attr, NULL, NULL);
11849c13cfgww
11949c13cfgww	if (verbose) {
12049c13cfgww		(void) fprintf(stderr,
12149c13cfgww		    gettext("attribute \"%s\" not found for %s\n"), attr_name,
12249c13cfgww		    user);
12349c13cfgww	}
12449c13cfgww
12549c13cfgww	return (1);
12649c13cfgww}
127