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 #pragma ident "%Z%%M% %I% %E% SMI"
28*f875b4ebSrica
29*f875b4ebSrica /*
30*f875b4ebSrica * Name: getzonepath.c
31*f875b4ebSrica *
32*f875b4ebSrica * Description: Get the zone pathname associated with a label.
33*f875b4ebSrica *
34*f875b4ebSrica * Usage: getzonepath sensitivity_label
35*f875b4ebSrica */
36*f875b4ebSrica
37*f875b4ebSrica #include <errno.h>
38*f875b4ebSrica #include <locale.h>
39*f875b4ebSrica #include <stdio.h>
40*f875b4ebSrica #include <stdlib.h>
41*f875b4ebSrica #include <string.h>
42*f875b4ebSrica
43*f875b4ebSrica #include <tsol/label.h>
44*f875b4ebSrica
45*f875b4ebSrica static char *prog;
46*f875b4ebSrica
47*f875b4ebSrica static void
label_error(const char * label,const int err)48*f875b4ebSrica label_error(const char *label, const int err)
49*f875b4ebSrica {
50*f875b4ebSrica if (errno == EINVAL) {
51*f875b4ebSrica switch (err) {
52*f875b4ebSrica case M_BAD_STRING:
53*f875b4ebSrica (void) fprintf(stderr,
54*f875b4ebSrica gettext("%s: bad string %s\n"), prog, label);
55*f875b4ebSrica break;
56*f875b4ebSrica case M_BAD_LABEL:
57*f875b4ebSrica (void) fprintf(stderr,
58*f875b4ebSrica gettext("%s: bad previous label\n"), prog);
59*f875b4ebSrica break;
60*f875b4ebSrica default:
61*f875b4ebSrica (void) fprintf(stderr,
62*f875b4ebSrica gettext("%s: parsing error found in "
63*f875b4ebSrica "\"%s\" at position %d\n"), prog, label, err);
64*f875b4ebSrica break;
65*f875b4ebSrica }
66*f875b4ebSrica } else {
67*f875b4ebSrica perror(prog);
68*f875b4ebSrica }
69*f875b4ebSrica exit(1);
70*f875b4ebSrica }
71*f875b4ebSrica
72*f875b4ebSrica int
main(int argc,char ** argv)73*f875b4ebSrica main(int argc, char **argv)
74*f875b4ebSrica {
75*f875b4ebSrica int err = 0;
76*f875b4ebSrica m_label_t *label = NULL;
77*f875b4ebSrica char *zone_root;
78*f875b4ebSrica
79*f875b4ebSrica (void) setlocale(LC_ALL, "");
80*f875b4ebSrica #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
81*f875b4ebSrica #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it were'nt */
82*f875b4ebSrica #endif
83*f875b4ebSrica (void) textdomain(TEXT_DOMAIN);
84*f875b4ebSrica
85*f875b4ebSrica if ((prog = strrchr(argv[0], '/')) == NULL)
86*f875b4ebSrica prog = argv[0];
87*f875b4ebSrica else
88*f875b4ebSrica prog++;
89*f875b4ebSrica
90*f875b4ebSrica if (argc != 2) {
91*f875b4ebSrica (void) fprintf(stderr, gettext(
92*f875b4ebSrica "Usage: %s label\n"), prog);
93*f875b4ebSrica return (1);
94*f875b4ebSrica }
95*f875b4ebSrica
96*f875b4ebSrica if (str_to_label(argv[1], &label, MAC_LABEL, L_NO_CORRECTION,
97*f875b4ebSrica &err) == -1) {
98*f875b4ebSrica label_error(argv[1], err);
99*f875b4ebSrica }
100*f875b4ebSrica
101*f875b4ebSrica if ((zone_root = getzonerootbylabel(label)) == NULL) {
102*f875b4ebSrica (void) fprintf(stderr,
103*f875b4ebSrica gettext("%s: cannot get path for label: %s.\n"), prog,
104*f875b4ebSrica strerror(errno));
105*f875b4ebSrica return (3);
106*f875b4ebSrica }
107*f875b4ebSrica
108*f875b4ebSrica (void) printf("%s\n", zone_root);
109*f875b4ebSrica
110*f875b4ebSrica return (0);
111*f875b4ebSrica } /* end main() */
112