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