1f875b4ebSrica /*
2f875b4ebSrica * CDDL HEADER START
3f875b4ebSrica *
4f875b4ebSrica * The contents of this file are subject to the terms of the
5f875b4ebSrica * Common Development and Distribution License (the "License").
6f875b4ebSrica * You may not use this file except in compliance with the License.
7f875b4ebSrica *
8f875b4ebSrica * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f875b4ebSrica * or http://www.opensolaris.org/os/licensing.
10f875b4ebSrica * See the License for the specific language governing permissions
11f875b4ebSrica * and limitations under the License.
12f875b4ebSrica *
13f875b4ebSrica * When distributing Covered Code, include this CDDL HEADER in each
14f875b4ebSrica * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f875b4ebSrica * If applicable, add the following below this CDDL HEADER, with the
16f875b4ebSrica * fields enclosed by brackets "[]" replaced with your own identifying
17f875b4ebSrica * information: Portions Copyright [yyyy] [name of copyright owner]
18f875b4ebSrica *
19f875b4ebSrica * CDDL HEADER END
20f875b4ebSrica */
21f875b4ebSrica
22f875b4ebSrica /*
237b0bedd4SRic Aleshire * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24f875b4ebSrica * Use is subject to license terms.
25f875b4ebSrica */
26f875b4ebSrica
27f875b4ebSrica /*
28f875b4ebSrica * updatehome - Update the current label's $HOME copy and link files.
29f875b4ebSrica *
30f875b4ebSrica * Update home reads the user's minimum label copy and link
31f875b4ebSrica * control files (.copy_files and .link_files) which contain a list
32f875b4ebSrica * of files to be copied and symbolically linked from the user's minimum
33f875b4ebSrica * label $HOME to the user's current label's $HOME.
34f875b4ebSrica *
35f875b4ebSrica * This is done by the Trusted Solaris dtsession whenever a
36f875b4ebSrica * newly labeled workspace is created so that the user's favorite
37f875b4ebSrica * files are available for use. For example the user probably
38f875b4ebSrica * wants a symlink to .profile, .login, .cshrc, .exrc, .mailrc, ~/bin,
39f875b4ebSrica * ... . updatehome provides a convient mechanism for accomplishing
40f875b4ebSrica * this. The user may add any set of files either to be copied
41f875b4ebSrica * (.copy_files), or symbolically linked (.link_files).
42f875b4ebSrica *
43f875b4ebSrica * Files should not include embedded MLDs.
44f875b4ebSrica *
45f875b4ebSrica * Entry options = c, if replace existing current label $HOME copies
46f875b4ebSrica * (default is to ignore existing).
47f875b4ebSrica * d, if to print debug trace msgs (internal use only).
48f875b4ebSrica * i, if to ignore errors encountered (default is to
49f875b4ebSrica * abort).
50f875b4ebSrica * m, if to suppress error diagnostics -- perror
51f875b4ebSrica * (internal use only).
52f875b4ebSrica * r, if replace existing current label $HOME copies or
53f875b4ebSrica * symbolic links -- implies c and s (default is to
54f875b4ebSrica * ignore existing).
55f875b4ebSrica * s, if replace existing current label $HOME symbolic
56f875b4ebSrica * links (default is to ignore existing).
57f875b4ebSrica *
58f875b4ebSrica * Exit stderr = diagnostic messages.
59f875b4ebSrica * exis status = 0, no errors noted.
60f875b4ebSrica * 1, if errors noted.
61f875b4ebSrica *
62f875b4ebSrica * Calls __setupfiles (which does all the real work).
63f875b4ebSrica */
64f875b4ebSrica
65f875b4ebSrica
66f875b4ebSrica /*
67f875b4ebSrica * There is a private contract between __setupfiles in this
68f875b4ebSrica * directory and login. Changes made to __setupfiles may need to be
69f875b4ebSrica * reflected in the source for login.
70f875b4ebSrica *
71f875b4ebSrica * G.Winiger 96/11/03
72f875b4ebSrica */
73f875b4ebSrica
74f875b4ebSrica
75f875b4ebSrica #include <locale.h>
76f875b4ebSrica #include <pwd.h>
77f875b4ebSrica #include <stdio.h>
78f875b4ebSrica #include <stdlib.h>
79f875b4ebSrica #include <unistd.h>
80f875b4ebSrica
81f875b4ebSrica #include <sys/types.h>
82f875b4ebSrica
83f875b4ebSrica #include <tsol/label.h>
84f875b4ebSrica #include <sys/tsol/label_macro.h>
85f875b4ebSrica #include <user_attr.h>
86f875b4ebSrica
87f875b4ebSrica #include "setupfiles.h"
88f875b4ebSrica
89f875b4ebSrica #if !defined(TEXT_DOMAIN)
90f875b4ebSrica #define TEXT_DOMAIN "SYS_TEST"
91f875b4ebSrica #endif /* !defined(TEXT_DOMAIN) */
92f875b4ebSrica
93f875b4ebSrica int
main(int argc,char ** argv)94f875b4ebSrica main(int argc, char **argv)
95f875b4ebSrica {
96f875b4ebSrica int opt; /* option switch value */
97f875b4ebSrica int flags; /* setupfiles flags */
98f875b4ebSrica uid_t uid;
99f875b4ebSrica extern int opterr; /* getopt error flag */
100f875b4ebSrica char *kv_str = NULL;
101f875b4ebSrica struct passwd *pwd; /* current user's password file entry */
102f875b4ebSrica userattr_t *userp = NULL; /* current user's user_attr entry */
103f875b4ebSrica m_label_t *min_sl;
104f875b4ebSrica m_label_t *clearance;
105f875b4ebSrica
106f875b4ebSrica (void) setlocale(LC_ALL, "");
107f875b4ebSrica (void) textdomain(TEXT_DOMAIN);
108f875b4ebSrica
109f875b4ebSrica flags = DIAG;
110f875b4ebSrica opterr = 0; /* handle errors here */
111f875b4ebSrica
112f875b4ebSrica while ((opt = getopt(argc, argv, "cdimrs")) != EOF) {
113f875b4ebSrica switch (opt) {
114f875b4ebSrica case 'c': /* replace existing copy */
115f875b4ebSrica flags |= REPC;
116f875b4ebSrica break;
117f875b4ebSrica
118f875b4ebSrica case 'd': /* debug */
119f875b4ebSrica flags |= DBUG;
120f875b4ebSrica break;
121f875b4ebSrica
122f875b4ebSrica case 'i': /* ignore copy/link errors */
123f875b4ebSrica flags |= IGNE;
124f875b4ebSrica break;
125f875b4ebSrica
126f875b4ebSrica case 'm': /* suppress error diagnostic (perror) */
127f875b4ebSrica /* prints */
128f875b4ebSrica flags &= ~DIAG;
129f875b4ebSrica break;
130f875b4ebSrica
131f875b4ebSrica case 'r': /* replace existing */
132f875b4ebSrica flags |= (REPC | REPL);
133f875b4ebSrica break;
134f875b4ebSrica
135f875b4ebSrica case 's': /* replace existing symbolic links */
136f875b4ebSrica flags |= REPL;
137f875b4ebSrica break;
138f875b4ebSrica
139f875b4ebSrica case '?': /* switch error */
140f875b4ebSrica (void) fprintf(stderr, gettext("Bad option -%c.\n"),
141f875b4ebSrica (char)optopt);
142*a8337c62SToomas Soome /* FALLTHROUGH */
143f875b4ebSrica
144f875b4ebSrica default:
145f875b4ebSrica (void) fprintf(stderr, gettext("usage: %s [-cirs].\n"),
146f875b4ebSrica argv[0]);
147f875b4ebSrica exit(1);
148f875b4ebSrica /*NOTREACHED*/
149f875b4ebSrica } /* switch (opt) */
150f875b4ebSrica } /* while ((opt = getopt()) */
151f875b4ebSrica
152f875b4ebSrica uid = getuid();
153f875b4ebSrica
154f875b4ebSrica if ((pwd = getpwuid(uid)) == (struct passwd *)0) {
155f875b4ebSrica
156f875b4ebSrica (void) fprintf(stderr,
157f875b4ebSrica gettext("Unable to get password entry for uid %d.\n"), uid);
158f875b4ebSrica exit(1);
159f875b4ebSrica }
160f875b4ebSrica
161f875b4ebSrica min_sl = m_label_alloc(MAC_LABEL);
162f875b4ebSrica clearance = m_label_alloc(USER_CLEAR);
163f875b4ebSrica
164f875b4ebSrica if (((userp = getusernam(pwd->pw_name)) == NULL) ||
165f875b4ebSrica ((kv_str = kva_match(userp->attr, USERATTR_MINLABEL)) == NULL)) {
166f875b4ebSrica
167f875b4ebSrica if (userdefs(min_sl, clearance) == -1) {
168f875b4ebSrica (void) fprintf(stderr,
169f875b4ebSrica gettext("Unable to get default user labels.\n"));
170f875b4ebSrica exit(1);
171f875b4ebSrica }
172f875b4ebSrica }
173f875b4ebSrica
174f875b4ebSrica if (kv_str != NULL) {
175f875b4ebSrica if (str_to_label(kv_str, &min_sl, MAC_LABEL, L_NO_CORRECTION,
176f875b4ebSrica NULL) == -1) {
177f875b4ebSrica (void) fprintf(stderr,
1787b0bedd4SRic Aleshire gettext("str_to_label failure on min_label for"
1797b0bedd4SRic Aleshire " user %s.\n"), pwd->pw_name);
180f875b4ebSrica exit(1);
181f875b4ebSrica }
182f875b4ebSrica }
183f875b4ebSrica
184f875b4ebSrica if (__setupfiles(pwd, min_sl, flags) != 0) {
185f875b4ebSrica
186f875b4ebSrica (void) fprintf(stderr, gettext("%s failed.\n"), argv[0]);
187f875b4ebSrica exit(1);
188f875b4ebSrica }
189f875b4ebSrica
190f875b4ebSrica return (0);
191f875b4ebSrica } /* update home */
192