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