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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <user_attr.h>
41 #ifndef TEXT_DOMAIN /* Should be defined by cc -D */
42 #define TEXT_DOMAIN "SYS_TEST"
45 static int show_roles(char *, int);
47 static char *progname
= "roles";
50 main(int argc
, char *argv
[])
55 (void) setlocale(LC_ALL
, "");
56 (void) textdomain(TEXT_DOMAIN
);
62 errs
= show_roles(NULL
, 0);
65 errs
+= show_roles(*argv
, print_name
);
68 return ((errs
== 0) ? EXIT_OK
: EXIT_FATAL
);
73 show_roles(char *username
, int print_name
)
75 register char *rolelist
= NULL
;
76 register struct passwd
*pw
;
77 register userattr_t
*user
;
79 if (username
== NULL
) {
80 if ((pw
= getpwuid(getuid())) == NULL
) {
81 (void) fprintf(stderr
, "%s: ", progname
);
82 (void) fprintf(stderr
, gettext("No passwd entry\n"));
85 username
= pw
->pw_name
;
86 } else if (getpwnam(username
) == NULL
) {
87 (void) fprintf(stderr
, "%s: %s : ", progname
, username
);
88 (void) fprintf(stderr
, gettext("No such user\n"));
92 if ((user
= getusernam(username
)) != NULL
) {
93 rolelist
= kva_match(user
->attr
, USERATTR_ROLES_KW
);
95 rolelist
= gettext("No roles");
96 if (print_name
&& username
!= NULL
)
97 (void) printf("%s : ", username
);
98 (void) printf("%s\n", rolelist
);
101 if (print_name
&& username
!= NULL
)
102 (void) printf("%s : ", username
);
103 (void) printf("%s\n", gettext("No roles"));