|
root / base / usr / src / cmd / tsol / updatehome
updatehome Plain Text 813 lines 19.8 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# cmd/tsol/updatehome
#
PROG= updatehome

include ../../Makefile.cmd

OBJS= setupfiles.o updatehome.o
SRCS= $(OBJS:%.o=%.c)

LDLIBS += -ltsol -lsecdb
CERRWARN += -Wno-parentheses

.KEEP_STATE:

all: $(PROG)

$(PROG): $(OBJS)
	$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
	$(POST_PROCESS)

install: all $(ROOTPROG)

clean:
	$(RM) $(OBJS)

lint:	lint_SRCS

include ../Makefile.targ
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <tsol/label.h>
#include <zone.h>
#include <sys/stat.h>

#include "setupfiles.h"

#define	dperror(s) if (flags & DIAG) perror(s)
#define	dprintf(s, v) if (flags & DBUG) (void) printf(s, v)
#define	dprintf2(s, v1, v2) if (flags & DBUG) (void) printf(s, v1, v2)

static int mkdirs(const char *dir, const char *target, int flags);
static int copyfile(const char *min_home, const char *home, const char *target,
    int flags);
static int linkfile(const char *min_home, const char *home, const char *target,
    int flags);


/*
 *	__setupfiles - Process copy and link files directions in min $HOME.
 *
 *	Entry	pwd = user's password file entry.
 *		min_sl = user's minimum SL.
 *		flags = DBUG, if print debug messages.
 *			DIAG, if print diagnostics (perrors).
 *			IGNE, continue rather than abort on failures.
 *			REPC, if replace existing file.
 *			REPL, if replace existing symbolic link.
 *		process is running as user at correct label.
 *
 *	Exit	None.
 *
 *	Returns	0, if success.
 *		errno, if failure.
 *
 *	Uses	COPY, CP, LINK, MAXPATHLEN.
 *
 *	Calls	blequal, copyfile, feof, fgets, fopen,
 *		mkdirs, getzoneid, getzonelabelbyid, linkfile, strcat, strcpy,
 *		strlen.
 *
 *	This program assumes the /zone is the autofs mountpoint for
 *	cross-zone mounts.
 *
 *	It also assumes that the user's home directory path is the
 *	the same in each zone, relative to the zone's root.
 *
 *	At this point, the cross-zone automounter only supports home
 * 	directories starting with /home
 */

int
__setupfiles(const struct passwd *pwd, const m_label_t *min_sl, int flags)
{
	m_label_t *plabel;		/* process label */
	char	home[MAXPATHLEN];	/* real path to current $HOME */
	char	min_home[MAXPATHLEN];	/* real path to min $HOME */
	char	cl_file[MAXPATHLEN];	/* real path to .copy/.link_files */
	char	file[MAXPATHLEN];	/* file to copy/link */
	FILE	*clf;			/* .copy/.link_file stream */
	char	zoneroot[MAXPATHLEN];
	zoneid_t zoneid;
	zoneid_t min_zoneid;

	zoneid = getzoneid();
	if ((plabel = getzonelabelbyid(zoneid)) == NULL) {

		dperror("setupfiles can't get process label");
		return (errno);
	}

	if (blequal(plabel, min_sl)) {
		/* at min SL no files to setup */

		return (0);
	}

	/* get current home real path */

	(void) strlcpy(home, pwd->pw_dir, MAXPATHLEN);

	/* Get zone id from min_sl */

	if ((min_zoneid = getzoneidbylabel(min_sl)) == -1) {

		dperror("setupfiles can't get zoneid for min sl");
		return (errno);
	}

	/*
	 * Since the global zone home directories aren't public
	 * information, we don't support copy and link files there.
	 */
	if (min_zoneid == GLOBAL_ZONEID)
		return (0);

	/*
	 * Get zone root path from zone id
	 *
	 * Could have used getzonenamebyid() but this assumes that /etc/zones
	 * directory is available, which is not true in labeled zones
	 */

	if (zone_getattr(min_zoneid, ZONE_ATTR_ROOT, zoneroot,
	    sizeof (zoneroot)) == -1) {
		dperror("setupfiles can't get zone root path for min sl");
		return (errno);
	}

	(void) snprintf(min_home, MAXPATHLEN, "%s%s",
	    zoneroot, pwd->pw_dir);

	/* process copy files */

	if ((strlen(min_home) + strlen(COPY)) > (MAXPATHLEN - 1)) {

		dprintf("setupfiles copy path %s", min_home);
		dprintf("%s ", COPY);
		dprintf("greater than %d\n", MAXPATHLEN);
		errno = ENAMETOOLONG;
		dperror("setupfiles copy path");
		return (errno);
	}

	(void) strcpy(cl_file, min_home);
	(void) strcat(cl_file, COPY);

	if ((clf = fopen(cl_file, "r")) != NULL) {

		while (fgets(file, MAXPATHLEN, clf) != NULL) {

			if (!feof(clf))		/* remove trailing \n */
				file[strlen(file) - 1] = '\0';

			dprintf("copy file %s requested\n", file);

			/* make any needed subdirectories */

			if (mkdirs(home, file, flags) != 0) {

				if ((flags & IGNE) == 0)
					return (errno);
				else
					continue;
			}

			/* copy the file */

			if (copyfile(min_home, home, file, flags) != 0) {

				if ((flags & IGNE) == 0)
					return (errno);
				else
					continue;

			}

		}  /* while (fgets( ... ) != NULL) */
	} else {
		if (errno != ENOENT)
			dperror("setupfiles copy file open");
		dprintf("setupfiles no copyfile %s\n", cl_file);
	}  /* process copy files */


	/* process link files */

	if ((strlen(min_home) + strlen(LINK)) > (MAXPATHLEN - 1)) {

		dprintf("setupfiles link path %s", min_home);
		dprintf("%s ", LINK);
		dprintf("greater than %d\n", MAXPATHLEN);
		errno = ENAMETOOLONG;
		dperror("setupfiles link path");
		return (errno);
	}

	(void) strcpy(cl_file, min_home);
	(void) strcat(cl_file, LINK);

	if ((clf = fopen(cl_file, "r")) != NULL) {

		while (fgets(file, MAXPATHLEN, clf) != NULL) {

			if (!feof(clf))		/* remove trailing \n */
				file[strlen(file) - 1] = '\0';

			dprintf("link file %s requested\n", file);

			/* make any needed subdirectories */

			if (mkdirs(home, file, flags) != 0) {

				if ((flags & IGNE) == 0)
					return (errno);
				else
					continue;
			}

			/* link the file */

			if (linkfile(min_home, home, file, flags) != 0) {

				if ((flags & IGNE) == 0)
					return (errno);
				else
					continue;
			}

		}  /* while (fgets ... ) != NULL) */
	} else {
		if (errno != ENOENT)
			dperror("setupfiles link file open");
		dprintf("setupfiles no linkfile %s\n", cl_file);
	}  /* process link files */

	return (0);
}  /* setupfiles() */


/*
 *	mkdirs - Make any needed subdirectories in target's path.
 *
 *	Entry	home = base directory.
 *		file = file to create with intermediate subdirectories.
 *		flags = from __setupfiles -- for dprintf and dperror.
 *
 *	Exit	Needed subdirectories made.
 *
 *	Returns	0, if success.
 *		errno, if failure.
 *
 *	Uses	MAXPATHLEN.
 *
 *	Calls	mkdir, strcat, strcpy, strlen, strtok.
 */

static int
mkdirs(const char *home, const char *file, int flags)
{
	char	path[MAXPATHLEN];
	char	dir[MAXPATHLEN];
	char	*tok;

	if ((strlen(home) + strlen(file)) > (MAXPATHLEN - 2)) {

		dprintf("setupfiles mkdirs path %s", home);
		dprintf("/%s ", file);
		dprintf("greater than %d\n", MAXPATHLEN);
		errno = ENAMETOOLONG;
		dperror("setupfiles mkdirs");
		return (errno);
	}

	(void) strcpy(dir, file);

	if ((tok = strrchr(dir, '/')) == NULL) {

		dprintf("setupfiles no dirs to make in %s\n", dir);
		return (0);
	}

	*tok = '\000';		/* drop last component, it's the target */

	(void) strcpy(path, home);

	for (tok = dir; tok = strtok(tok, "/"); tok = NULL) {

		(void) strcat(path, "/");
		(void) strcat(path, tok);

		if ((mkdir(path, 0777) != 0) && (errno != EEXIST)) {

			dperror("setupfiles mkdir");
			dprintf("setupfiles mkdir path %s\n", path);
			return (errno);
		}

		dprintf("setupfiles dir %s made or already exists\n", path);
	}

	return (0);
}  /* mkdirs() */


/*
 *	copyfile - Copy a file from the base home directory to the current.
 *
 *	Entry	min_home = from home directory.
 *		home = current (to) home directory.
 *		target = file to copy.
 *		flags = from __setupfiles.
 *			REPC, if replace existing file.
 *
 *	Exit	File copied.
 *
 *	Returns	0, if success.
 *		errno, if failure.
 *
 *	Uses	CP, MAXPATHLEN.
 *
 *	Calls	access, execlp, exit, lstat, strcat, strcpy, strlen, unlink,
 *		vfork, waitpid.
 */

static int
copyfile(const char *min_home, const char *home, const char *target, int flags)
{
	char	src[MAXPATHLEN];
	char	dest[MAXPATHLEN];
	struct stat	buf;
	pid_t	child;

	/* prepare target */

	if (snprintf(dest, sizeof (dest), "%s/%s", home, target) >
	    sizeof (dest) - 1) {
		dprintf("setupfiles copy dest %s", dest);
		dprintf("greater than %d\n", sizeof (dest));
		errno = ENAMETOOLONG;
		dperror("setupfiles copy to home");
		return (errno);
	}

	if (lstat(dest, &buf) == 0) {
		/* target exists */

		if (flags & REPC) {
			/* unlink and replace */

			if (unlink(dest) != 0) {

				dperror("setupfiles copy unlink");
				dprintf("setupfiles copy unable to unlink %s\n",
				    dest);
				return (errno);
			}
		} else {
			/* target exists and is not to be replaced */

			return (0);
		}
	} else if (errno != ENOENT) {
		/* error on target */

		dperror("setupfiles copy");
		dprintf("setupfiles copy lstat %s\n", dest);
		return (errno);
	}

	/* prepare source */

	if (snprintf(src, sizeof (src), "%s/%s", min_home, target) >
	    sizeof (src) - 1) {
		dprintf("setupfiles copy path %s", src);
		dprintf("greater than %d\n", sizeof (src));
		errno = ENAMETOOLONG;
		dperror("setupfiles copy from home");
		return (errno);
	}

	if (access(src, R_OK) != 0) {
		/* can't access source */

		dperror("setupfiles copy source access");
		dprintf("setupfiles copy unable to access %s\n", src);
		return (errno);
	}

	/* attempt the copy */

	dprintf("setupfiles attempting to copy %s\n", src);
	dprintf("\tto %s\n", dest);

	if ((child = vfork()) != 0) {	/* parent, wait for child status */
		int	status;	/* child status */

		(void) waitpid(child, &status, 0);  /* wait for child */
		dprintf("setupfiles copy child returned %x\n", status);
	} else {
		/* execute "cp -p min_home home" */

		if (execlp(CP, CP, "-p", src, dest, 0) != 0) {
			/* can't execute cp */

			dperror("setupfiles copy exec");
			dprintf("setupfiles copy couldn't exec \"%s  -p\"\n",
			    CP);
			exit(2);
		}
	}

	return (0);
}  /* copyfile() */


/*
 *	linkfile - Make a symlink from the the current directory to the base
 *			home directory.
 *
 *	Entry	min_home = from home directory.
 *		home = current (to) home directory.
 *		target = file to copy.
 *		flags = from __setupfiles.
 *			REPL, if replace existing symlink.
 *
 *	Exit	File symlinked.
 *
 *	Returns	0, if success.
 *		errno, if failure.
 *
 *	Uses	MAXPATHLEN.
 *
 *	Calls	lstat, symlink, strcat, strcpy, strlen, unlink.
 */

static int
linkfile(const char *min_home, const char *home, const char *target, int flags)
{
	char	src[MAXPATHLEN];
	char	dest[MAXPATHLEN];
	struct stat	buf;

	/* prepare target */

	if (snprintf(dest, sizeof (dest), "%s/%s", home, target) >
	    sizeof (dest) - 1) {
		dprintf("setupfiles link dest %s", dest);
		dprintf("greater than %d\n", sizeof (dest));
		errno = ENAMETOOLONG;
		dperror("setupfiles link to home");
		return (errno);
	}

	if (lstat(dest, &buf) == 0) {
		/* target exists */

		if (flags & REPL) {
			/* unlink and replace */
			if (unlink(dest) != 0) {
				dperror("setupfiles link unlink");
				dprintf("setupfiles link unable to unlink %s\n",
				    dest);
				return (errno);
			}
		} else {
			/* target exists and is not to be replaced */
			return (0);
		}
	} else if (errno != ENOENT) {
		/* error on target */
		dperror("setupfiles link");
		dprintf("setupfiles link lstat %s\n", dest);
		return (errno);
	}

	if (snprintf(src, sizeof (src), "%s/%s", min_home, target) >
	    sizeof (src) - 1) {
		dprintf("setupfiles link path %s", src);
		dprintf("greater than %d\n", sizeof (src));
		errno = ENAMETOOLONG;
		dperror("setupfiles link from home");
		return (errno);
	}

	/* attempt the copy */

	dprintf("setupfiles attempting to link %s\n", dest);
	dprintf("\tto %s\n", src);

	if (symlink(src, dest) != 0) {
		dperror("setupfiles link symlink");
		dprintf("setupfiles link unable to symlink%s\n", "");
		return (errno);
	}

	return (0);
}  /* linkfile */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SETUPFILES_H
#define	_SETUPFILES_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <pwd.h>
#include <tsol/label.h>

#define	COPY "/.copy_files"
#define	LINK "/.link_files"
#define	CP "/bin/cp"

#define	DBUG	0x001		/* print debug */
#define	DIAG	0x002		/* print diagnostics */
#define	IGNE	0x004		/* ignore copy/link errors */
#define	REPC	0x008		/* replace existing copies */
#define	REPL	0x010		/* replace existing links */

extern int __setupfiles(const struct passwd *pwd, const m_label_t *, int flags);

#ifdef	__cplusplus
}
#endif

#endif	/* !_SETUPFILES_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 *	updatehome - Update the current label's $HOME copy and link files.
 *
 *		Update home reads the user's minimum label copy and link
 *	control files (.copy_files and .link_files) which contain a list
 *	of files to be copied and symbolically linked from the user's minimum
 *	label $HOME to the user's current label's $HOME.
 *
 *		This is done by the Trusted Solaris dtsession whenever a
 *	newly labeled workspace is created so that the user's favorite
 *	files are available for use.  For example the user probably
 *	wants a symlink to .profile, .login, .cshrc, .exrc, .mailrc, ~/bin,
 *	... .  updatehome provides a convient mechanism for accomplishing
 *	this.  The user may add any set of files either to be copied
 *	(.copy_files), or symbolically linked (.link_files).
 *
 *		Files should not include embedded MLDs.
 *
 *	Entry	options = c, if replace existing current label $HOME copies
 *			     (default is to ignore existing).
 *			  d, if to print debug trace msgs (internal use only).
 *			  i, if to ignore errors encountered (default is to
 *			     abort).
 *			  m, if to suppress error diagnostics -- perror
 *			     (internal use only).
 *			  r, if replace existing current label $HOME copies or
 *			     symbolic links  -- implies c and s (default is to
 *			     ignore existing).
 *			  s, if replace existing current label $HOME symbolic
 *			     links (default is to ignore existing).
 *
 *	Exit	stderr = diagnostic messages.
 *		exis status = 0, no errors noted.
 *			      1, if errors noted.
 *
 *	Calls	__setupfiles (which does all the real work).
 */


/*
 *		There is a private contract between __setupfiles in this
 *	directory and login.  Changes made to __setupfiles may need to be
 *	reflected in the source for login.
 *
 *	G.Winiger 96/11/03
 */


#include <locale.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/types.h>

#include <tsol/label.h>
#include <sys/tsol/label_macro.h>
#include <user_attr.h>

#include "setupfiles.h"

#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN	"SYS_TEST"
#endif	/* !defined(TEXT_DOMAIN) */

int
main(int argc, char **argv)
{
	int		opt;		/* option switch value */
	int		flags;		/* setupfiles flags */
	uid_t		uid;
	extern int	opterr;		/* getopt error flag */
	char		*kv_str = NULL;
	struct passwd	*pwd;		/* current user's password file entry */
	userattr_t	*userp = NULL;	/* current user's user_attr entry */
	m_label_t	*min_sl;
	m_label_t	*clearance;

	(void) setlocale(LC_ALL, "");
	(void) textdomain(TEXT_DOMAIN);

	flags = DIAG;
	opterr = 0;	/* handle errors here */

	while ((opt = getopt(argc, argv, "cdimrs")) != EOF) {
		switch (opt) {
		case 'c':	/* replace existing copy */
			flags |= REPC;
			break;

		case 'd':	/* debug */
			flags |= DBUG;
			break;

		case 'i':	/* ignore copy/link errors */
			flags |= IGNE;
			break;

		case 'm':	/* suppress error diagnostic (perror) */
				/* prints */
			flags &= ~DIAG;
			break;

		case 'r':		/* replace existing */
			flags |= (REPC | REPL);
			break;

		case 's':	/* replace existing symbolic links */
			flags |= REPL;
			break;

		case '?':		/* switch error */
			(void) fprintf(stderr, gettext("Bad option -%c.\n"),
			    (char)optopt);
			/* FALLTHROUGH */

		default:
			(void) fprintf(stderr, gettext("usage: %s [-cirs].\n"),
			    argv[0]);
			exit(1);
			/*NOTREACHED*/
		}  /* switch (opt) */
	}  /* while ((opt = getopt()) */

	uid = getuid();

	if ((pwd = getpwuid(uid)) == (struct passwd *)0) {

		(void) fprintf(stderr,
		    gettext("Unable to get password entry for uid %d.\n"), uid);
		exit(1);
	}

	min_sl = m_label_alloc(MAC_LABEL);
	clearance = m_label_alloc(USER_CLEAR);

	if (((userp = getusernam(pwd->pw_name)) == NULL) ||
	    ((kv_str = kva_match(userp->attr, USERATTR_MINLABEL)) == NULL)) {

		if (userdefs(min_sl, clearance) == -1) {
			(void) fprintf(stderr,
			    gettext("Unable to get default user labels.\n"));
			exit(1);
		}
	}

	if (kv_str != NULL) {
		if (str_to_label(kv_str, &min_sl, MAC_LABEL, L_NO_CORRECTION,
		    NULL) == -1) {
			(void) fprintf(stderr,
			    gettext("str_to_label failure on min_label for"
			    " user %s.\n"), pwd->pw_name);
			exit(1);
		}
	}

	if (__setupfiles(pwd, min_sl, flags) != 0) {

		(void) fprintf(stderr, gettext("%s failed.\n"), argv[0]);
		exit(1);
	}

	return (0);
}  /* update home */