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