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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * setlabel - sets a file label.
43 #include <tsol/label.h>
45 static int set_label(char *, char *);
46 static int setlabel(char *, bslabel_t
*);
47 static void usage(void);
48 static void m_label_err(const char *, const int);
50 static char *prog
= NULL
;
53 main(int argc
, char **argv
)
58 (void) setlocale(LC_ALL
, "");
59 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
60 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
62 (void) textdomain(TEXT_DOMAIN
);
64 if ((prog
= strrchr(argv
[0], '/')) == NULL
)
81 if (set_label(*argv
++, label
) != 0)
89 set_label(char *filename
, char *label
)
95 if ((blabel
= m_label_alloc(MAC_LABEL
)) == NULL
) {
96 (void) fprintf(stderr
, "setlabel: ");
100 rval
= getlabel(filename
, blabel
);
102 (void) fprintf(stderr
, "setlabel: ");
106 if (!bslvalid(blabel
)) {
107 (void) fprintf(stderr
,
108 gettext("%s: Current label is invalid\n"),
112 if (str_to_label(label
, &blabel
, MAC_LABEL
, L_DEFAULT
, &err
) == -1) {
113 m_label_err(label
, err
);
116 rval
= setlabel(filename
, blabel
);
118 m_label_free(blabel
);
123 setlabel(char *filename
, bslabel_t
*label
)
127 rval
= setflabel(filename
, label
);
130 (void) fprintf(stderr
, "setlabel: ");
137 m_label_err(const char *ascii
, const int err
)
139 if (errno
== EINVAL
) {
142 (void) fprintf(stderr
,
143 gettext("setlabel: bad string %s\n"), ascii
);
146 (void) fprintf(stderr
,
147 gettext("setlabel: bad previous label\n"));
150 (void) fprintf(stderr
,
151 gettext("setlabel: parsing error found in "
152 "\"%s\" at position %d\n"), ascii
, err
);
163 * This routine is called whenever there is a usage type of error has
164 * occured. For example, when a invalid option has has been specified.
171 (void) fprintf(stderr
, gettext("Usage: \n"));
172 (void) fprintf(stderr
, gettext(
173 " %s newlabel filename [...] \n"), prog
);