1*f875b4ebSrica /*
2*f875b4ebSrica  * CDDL HEADER START
3*f875b4ebSrica  *
4*f875b4ebSrica  * The contents of this file are subject to the terms of the
5*f875b4ebSrica  * Common Development and Distribution License (the "License").
6*f875b4ebSrica  * You may not use this file except in compliance with the License.
7*f875b4ebSrica  *
8*f875b4ebSrica  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*f875b4ebSrica  * or http://www.opensolaris.org/os/licensing.
10*f875b4ebSrica  * See the License for the specific language governing permissions
11*f875b4ebSrica  * and limitations under the License.
12*f875b4ebSrica  *
13*f875b4ebSrica  * When distributing Covered Code, include this CDDL HEADER in each
14*f875b4ebSrica  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*f875b4ebSrica  * If applicable, add the following below this CDDL HEADER, with the
16*f875b4ebSrica  * fields enclosed by brackets "[]" replaced with your own identifying
17*f875b4ebSrica  * information: Portions Copyright [yyyy] [name of copyright owner]
18*f875b4ebSrica  *
19*f875b4ebSrica  * CDDL HEADER END
20*f875b4ebSrica  */
21*f875b4ebSrica 
22*f875b4ebSrica /*
23*f875b4ebSrica  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*f875b4ebSrica  * Use is subject to license terms.
25*f875b4ebSrica  */
26*f875b4ebSrica 
27*f875b4ebSrica /*
28*f875b4ebSrica  *	Name:		getzonepath.c
29*f875b4ebSrica  *
30*f875b4ebSrica  *	Description:	Get the zone pathname associated with a label.
31*f875b4ebSrica  *
32*f875b4ebSrica  *	Usage:		getzonepath sensitivity_label
33*f875b4ebSrica  */
34*f875b4ebSrica 
35*f875b4ebSrica #include <errno.h>
36*f875b4ebSrica #include <locale.h>
37*f875b4ebSrica #include <stdio.h>
38*f875b4ebSrica #include <stdlib.h>
39*f875b4ebSrica #include <string.h>
40*f875b4ebSrica 
41*f875b4ebSrica #include <tsol/label.h>
42*f875b4ebSrica 
43*f875b4ebSrica static char	*prog;
44*f875b4ebSrica 
45*f875b4ebSrica static void
label_error(const char * label,const int err)46*f875b4ebSrica label_error(const char *label, const int err)
47*f875b4ebSrica {
48*f875b4ebSrica 	if (errno == EINVAL) {
49*f875b4ebSrica 		switch (err) {
50*f875b4ebSrica 		case M_BAD_STRING:
51*f875b4ebSrica 			(void) fprintf(stderr,
52*f875b4ebSrica 			    gettext("%s: bad string %s\n"), prog, label);
53*f875b4ebSrica 		break;
54*f875b4ebSrica 		case M_BAD_LABEL:
55*f875b4ebSrica 			(void) fprintf(stderr,
56*f875b4ebSrica 			    gettext("%s: bad previous label\n"), prog);
57*f875b4ebSrica 		break;
58*f875b4ebSrica 		default:
59*f875b4ebSrica 			(void) fprintf(stderr,
60*f875b4ebSrica 			    gettext("%s: parsing error found in "
61*f875b4ebSrica 			    "\"%s\" at position %d\n"), prog, label, err);
62*f875b4ebSrica 		break;
63*f875b4ebSrica 		}
64*f875b4ebSrica 	} else {
65*f875b4ebSrica 		perror(prog);
66*f875b4ebSrica 	}
67*f875b4ebSrica 	exit(1);
68*f875b4ebSrica }
69*f875b4ebSrica 
70*f875b4ebSrica int
main(int argc,char ** argv)71*f875b4ebSrica main(int argc, char **argv)
72*f875b4ebSrica {
73*f875b4ebSrica 	int		err = 0;
74*f875b4ebSrica 	m_label_t	*label = NULL;
75*f875b4ebSrica 	char		*zone_root;
76*f875b4ebSrica 
77*f875b4ebSrica 	(void) setlocale(LC_ALL, "");
78*f875b4ebSrica #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
79*f875b4ebSrica #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it were'nt */
80*f875b4ebSrica #endif
81*f875b4ebSrica 	(void) textdomain(TEXT_DOMAIN);
82*f875b4ebSrica 
83*f875b4ebSrica 	if ((prog = strrchr(argv[0], '/')) == NULL)
84*f875b4ebSrica 		prog = argv[0];
85*f875b4ebSrica 	else
86*f875b4ebSrica 		prog++;
87*f875b4ebSrica 
88*f875b4ebSrica 	if (argc != 2) {
89*f875b4ebSrica 		(void) fprintf(stderr, gettext(
90*f875b4ebSrica 		    "Usage: %s label\n"), prog);
91*f875b4ebSrica 		return (1);
92*f875b4ebSrica 	}
93*f875b4ebSrica 
94*f875b4ebSrica 	if (str_to_label(argv[1], &label, MAC_LABEL, L_NO_CORRECTION,
95*f875b4ebSrica 	    &err) == -1) {
96*f875b4ebSrica 		label_error(argv[1], err);
97*f875b4ebSrica 	}
98*f875b4ebSrica 
99*f875b4ebSrica 	if ((zone_root = getzonerootbylabel(label)) == NULL) {
100*f875b4ebSrica 		(void) fprintf(stderr,
101*f875b4ebSrica 		    gettext("%s: cannot get path for label: %s.\n"), prog,
102*f875b4ebSrica 		    strerror(errno));
103*f875b4ebSrica 		return (3);
104*f875b4ebSrica 	}
105*f875b4ebSrica 
106*f875b4ebSrica 	(void) printf("%s\n", zone_root);
107*f875b4ebSrica 
108*f875b4ebSrica 	return (0);
109*f875b4ebSrica } /* end main() */
110