View | Details | Raw Unified | Return to bug 27571
Collapse All | Expand All

(-)sbin/mount_union/mount_union.c (-1 / +4 lines)
Lines 85-91 Link Here
85
85
86
	mntflags = 0;
86
	mntflags = 0;
87
	args.mntflags = UNMNT_ABOVE;
87
	args.mntflags = UNMNT_ABOVE;
88
	while ((ch = getopt(argc, argv, "bo:r")) != -1)
88
	while ((ch = getopt(argc, argv, "abo:r")) != -1)
89
		switch (ch) {
89
		switch (ch) {
90
		case 'b':
90
		case 'b':
91
			args.mntflags &= ~UNMNT_OPMASK;
91
			args.mntflags &= ~UNMNT_OPMASK;
Lines 97-102 Link Here
97
		case 'r':
97
		case 'r':
98
			args.mntflags &= ~UNMNT_OPMASK;
98
			args.mntflags &= ~UNMNT_OPMASK;
99
			args.mntflags |= UNMNT_REPLACE;
99
			args.mntflags |= UNMNT_REPLACE;
100
			break;
101
		case 'a':
102
                        args.mntflags |= UNMNT_CPATTR;
100
			break;
103
			break;
101
		case '?':
104
		case '?':
102
		default:
105
		default:
(-)sbin/mount_union/mount_union.8 Wed May 23 14:05:21 2001 (-1 / +6 lines)
Lines 43-49 Link Here
43
.Nd mount union filesystems
43
.Nd mount union filesystems
44
.Sh SYNOPSIS
44
.Sh SYNOPSIS
45
.Nm
45
.Nm
46
.Op Fl br
46
.Op Fl bra
47
.Op Fl o Ar options
47
.Op Fl o Ar options
48
.Ar directory
48
.Ar directory
49
.Ar uniondir
49
.Ar uniondir
Lines 87-92 Link Here
87
.It Fl r
87
.It Fl r
88
Hide the lower layer completely in the same way as mounting with
88
Hide the lower layer completely in the same way as mounting with
89
.Xr mount_null 8 .
89
.Xr mount_null 8 .
90
.It Fl a
91
Changes the policy of attributes set up during the creation of a new 
92
upper-layer shadow file or directory.
90
.El
93
.El
91
.Pp
94
.Pp
92
To enforce filesystem security, the user mounting the filesystem
95
To enforce filesystem security, the user mounting the filesystem
Lines 103-108 Link Here
103
with mode
106
with mode
104
.Dq rwxrwxrwx
107
.Dq rwxrwxrwx
105
(0777) modified by the umask in effect at that time.
108
(0777) modified by the umask in effect at that time.
109
In case of the -a option the newly created upper-layer directory will have  
110
the same attributes as the lower-layer directory.
106
.Pp
111
.Pp
107
If a file exists in the upper layer then there is no way to access
112
If a file exists in the upper layer then there is no way to access
108
a file with the same name in the lower layer.
113
a file with the same name in the lower layer.
(-)sys/miscfs/union/union.h (+3 lines)
Lines 48-59 Link Here
48
#define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
48
#define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
49
#define UNMNT_OPMASK	0x0003
49
#define UNMNT_OPMASK	0x0003
50
50
51
#define UNMNT_CPATTR    0x0004
52
51
struct union_mount {
53
struct union_mount {
52
	struct vnode	*um_uppervp;	/* UN_ULOCK holds locking state */
54
	struct vnode	*um_uppervp;	/* UN_ULOCK holds locking state */
53
	struct vnode	*um_lowervp;	/* Left unlocked */
55
	struct vnode	*um_lowervp;	/* Left unlocked */
54
	struct ucred	*um_cred;	/* Credentials of user calling mount */
56
	struct ucred	*um_cred;	/* Credentials of user calling mount */
55
	int		um_cmode;	/* cmask from mount process */
57
	int		um_cmode;	/* cmask from mount process */
56
	int		um_op;		/* Operation mode */
58
	int		um_op;		/* Operation mode */
59
	int             um_flag;
57
};
60
};
58
61
59
#ifdef _KERNEL
62
#ifdef _KERNEL
(-)sys/miscfs/union/union_subr.c (+23 lines)
Lines 749-754 Link Here
749
	int error;
756
	int error;
750
	struct vnode *lvp, *uvp;
757
	struct vnode *lvp, *uvp;
751
758
759
        struct union_mount *um;
760
761
        um = MOUNTTOUNIONMOUNT(UNIONTOV(un)->v_mount);
752
	/*
762
	/*
753
	 * If the user does not have read permission, the vnode should not
763
	 * If the user does not have read permission, the vnode should not
754
	 * be copied to upper layer.
764
	 * be copied to upper layer.
Lines 784-789 Link Here
784
			UDEBUG(("union: copied up %s\n", un->un_path));
794
			UDEBUG(("union: copied up %s\n", un->un_path));
785
795
786
	}
796
	}
797
        if(error == 0 && um->um_flag & UNMNT_CPATTR){
798
                  struct vattr loattr, newattr;
799
                  int aerror;
800
                  struct ucred cred;
801
802
                  VATTR_NULL(&loattr);
803
                  cred.cr_ref = 1;
804
                  cred.cr_uid = 0;
805
                  cred.cr_ngroups = 1;
806
                  cred.cr_groups[0] = 0;
807
                  cred.cr_uidinfo = 0;
808
                  aerror = VOP_GETATTR(lvp, &loattr, &cred, p);
809
                  if(aerror == 0) {
810
                          VATTR_NULL(&newattr);
811
                          newattr.va_uid = loattr.va_uid;
812
                          newattr.va_gid = loattr.va_gid;
813
                          aerror = VOP_SETATTR(uvp, &newattr, &cred, p);
814
                  }
815
        }
816
out:;
787
	VOP_UNLOCK(uvp, 0, p);
817
	VOP_UNLOCK(uvp, 0, p);
788
	union_newupper(un, uvp);
818
	union_newupper(un, uvp);
789
	KASSERT(uvp->v_usecount > 0, ("copy: uvp refcount 0: %d", uvp->v_usecount));
819
	KASSERT(uvp->v_usecount > 0, ("copy: uvp refcount 0: %d", uvp->v_usecount));
(-)sys/miscfs/union/union_vfsops.c (+1 lines)
Lines 185-190 Link Here
185
	bzero(um, sizeof(struct union_mount));
185
	bzero(um, sizeof(struct union_mount));
186
186
187
	um->um_op = args.mntflags & UNMNT_OPMASK;
187
	um->um_op = args.mntflags & UNMNT_OPMASK;
188
	um->um_flag = args.mntflags;
188
189
189
	switch (um->um_op) {
190
	switch (um->um_op) {
190
	case UNMNT_ABOVE:
191
	case UNMNT_ABOVE:
(-)sys/miscfs/union/union_vnops.c (+19 lines)
Lines 506-511 Link Here
506
	/* case 2. */
516
	/* case 2. */
507
	if (uerror != 0 /* && (lerror == 0) */ ) {
517
	if (uerror != 0 /* && (lerror == 0) */ ) {
508
		if (lowervp->v_type == VDIR) { /* case 2b. */
518
		if (lowervp->v_type == VDIR) { /* case 2b. */
519
			struct vattr loattr, newattr;
520
                        int aerror;
521
                        struct ucred cred;
522
509
			KASSERT(uppervp == NULL, ("uppervp unexpectedly non-NULL"));
523
			KASSERT(uppervp == NULL, ("uppervp unexpectedly non-NULL"));
510
			/*
524
			/*
511
			 * oops, uppervp has a problem, we may have to shadow.
525
			 * oops, uppervp has a problem, we may have to shadow.
Lines 515-520 Link Here
515
				error = uerror;
529
				error = uerror;
516
				goto out;
530
				goto out;
517
			}
531
			}
532
                        if(um->um_flag & UNMNT_CPATTR) {
533
                                VATTR_NULL(&loattr);
534
                                cred.cr_ref = 1;
535
                                cred.cr_uid = 0;
536
                                cred.cr_ngroups = 1;
537
                                cred.cr_groups[0] = 0;
538
                                cred.cr_uidinfo = 0;
539
                                aerror = VOP_GETATTR(lowervp, &loattr, &cred, cnp->cn_proc);
540
                                if(aerror == 0) {
541
                                        VATTR_NULL(&newattr);
542
                                        newattr.va_uid = loattr.va_uid;
543
                                        newattr.va_gid = loattr.va_gid;
544
                                        aerror = VOP_SETATTR(uppervp, &newattr, &cred, p);
545
                                }
546
                        }
518
		}
547
		}
519
	}
548
	}

Return to bug 27571