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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * updatehome - Update the current label's $HOME copy and link files.
30 * Update home reads the user's minimum label copy and link
31 * control files (.copy_files and .link_files) which contain a list
32 * of files to be copied and symbolically linked from the user's minimum
33 * label $HOME to the user's current label's $HOME.
35 * This is done by the Trusted Solaris dtsession whenever a
36 * newly labeled workspace is created so that the user's favorite
37 * files are available for use. For example the user probably
38 * wants a symlink to .profile, .login, .cshrc, .exrc, .mailrc, ~/bin,
39 * ... . updatehome provides a convient mechanism for accomplishing
40 * this. The user may add any set of files either to be copied
41 * (.copy_files), or symbolically linked (.link_files).
43 * Files should not include embedded MLDs.
45 * Entry options = c, if replace existing current label $HOME copies
46 * (default is to ignore existing).
47 * d, if to print debug trace msgs (internal use only).
48 * i, if to ignore errors encountered (default is to
50 * m, if to suppress error diagnostics -- perror
51 * (internal use only).
52 * r, if replace existing current label $HOME copies or
53 * symbolic links -- implies c and s (default is to
55 * s, if replace existing current label $HOME symbolic
56 * links (default is to ignore existing).
58 * Exit stderr = diagnostic messages.
59 * exis status = 0, no errors noted.
62 * Calls __setupfiles (which does all the real work).
67 * There is a private contract between __setupfiles in this
68 * directory and login. Changes made to __setupfiles may need to be
69 * reflected in the source for login.
81 #include <sys/types.h>
83 #include <tsol/label.h>
84 #include <sys/tsol/label_macro.h>
85 #include <user_attr.h>
87 #include "setupfiles.h"
89 #if !defined(TEXT_DOMAIN)
90 #define TEXT_DOMAIN "SYS_TEST"
91 #endif /* !defined(TEXT_DOMAIN) */
94 main(int argc
, char **argv
)
96 int opt
; /* option switch value */
97 int flags
; /* setupfiles flags */
99 extern int opterr
; /* getopt error flag */
101 struct passwd
*pwd
; /* current user's password file entry */
102 userattr_t
*userp
= NULL
; /* current user's user_attr entry */
104 m_label_t
*clearance
;
106 (void) setlocale(LC_ALL
, "");
107 (void) textdomain(TEXT_DOMAIN
);
110 opterr
= 0; /* handle errors here */
112 while ((opt
= getopt(argc
, argv
, "cdimrs")) != EOF
) {
114 case 'c': /* replace existing copy */
118 case 'd': /* debug */
122 case 'i': /* ignore copy/link errors */
126 case 'm': /* suppress error diagnostic (perror) */
131 case 'r': /* replace existing */
132 flags
|= (REPC
| REPL
);
135 case 's': /* replace existing symbolic links */
139 case '?': /* switch error */
140 (void) fprintf(stderr
, gettext("Bad option -%c.\n"),
144 (void) fprintf(stderr
, gettext("usage: %s [-cirs].\n"),
149 } /* while ((opt = getopt()) */
153 if ((pwd
= getpwuid(uid
)) == (struct passwd
*)0) {
155 (void) fprintf(stderr
,
156 gettext("Unable to get password entry for uid %d.\n"), uid
);
160 min_sl
= m_label_alloc(MAC_LABEL
);
161 clearance
= m_label_alloc(USER_CLEAR
);
163 if (((userp
= getusernam(pwd
->pw_name
)) == NULL
) ||
164 ((kv_str
= kva_match(userp
->attr
, USERATTR_MINLABEL
)) == NULL
)) {
166 if (userdefs(min_sl
, clearance
) == -1) {
167 (void) fprintf(stderr
,
168 gettext("Unable to get default user labels.\n"));
173 if (kv_str
!= NULL
) {
174 if (str_to_label(kv_str
, &min_sl
, MAC_LABEL
, L_NO_CORRECTION
,
176 (void) fprintf(stderr
,
177 gettext("str_to_label failure on min_label for"
178 " user %s.\n"), pwd
->pw_name
);
183 if (__setupfiles(pwd
, min_sl
, flags
) != 0) {
185 (void) fprintf(stderr
, gettext("%s failed.\n"), argv
[0]);