Deleted Added
full compact
nfs_srvsubs.c (91406) nfs_srvsubs.c (92783)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
37 * $FreeBSD: head/sys/nfsserver/nfs_srvsubs.c 91406 2002-02-27 18:32:23Z jhb $
37 * $FreeBSD: head/sys/nfsserver/nfs_srvsubs.c 92783 2002-03-20 10:07:52Z jeff $
38 */
39
40#include <sys/cdefs.h>
38 */
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/sys/nfsserver/nfs_srvsubs.c 91406 2002-02-27 18:32:23Z jhb $");
41__FBSDID("$FreeBSD: head/sys/nfsserver/nfs_srvsubs.c 92783 2002-03-20 10:07:52Z jeff $");
42
43/*
44 * These functions support the macros and help fiddle mbuf chains for
45 * the nfs op functions. They do things like create the rpc header and
46 * copy data between mbuf chains and uio lists.
47 */
48
49#include <sys/param.h>

--- 12 unchanged lines hidden (view full) ---

62#include <sys/module.h>
63#include <sys/sysent.h>
64#include <sys/syscall.h>
65#include <sys/sysproto.h>
66
67#include <vm/vm.h>
68#include <vm/vm_object.h>
69#include <vm/vm_extern.h>
42
43/*
44 * These functions support the macros and help fiddle mbuf chains for
45 * the nfs op functions. They do things like create the rpc header and
46 * copy data between mbuf chains and uio lists.
47 */
48
49#include <sys/param.h>

--- 12 unchanged lines hidden (view full) ---

62#include <sys/module.h>
63#include <sys/sysent.h>
64#include <sys/syscall.h>
65#include <sys/sysproto.h>
66
67#include <vm/vm.h>
68#include <vm/vm_object.h>
69#include <vm/vm_extern.h>
70#include <vm/vm_zone.h>
70#include <vm/uma.h>
71
72#include <nfs/rpcv2.h>
73#include <nfs/nfsproto.h>
74#include <nfsserver/nfs.h>
75#include <nfs/xdr_subs.h>
76#include <nfsserver/nfsm_subs.h>
77
78#include <netinet/in.h>

--- 521 unchanged lines hidden (view full) ---

600 char *fromcp, *tocp, *cp;
601 struct iovec aiov;
602 struct uio auio;
603 struct vnode *dp;
604 int error, rdonly, linklen;
605 struct componentname *cnp = &ndp->ni_cnd;
606
607 *retdirp = (struct vnode *)0;
71
72#include <nfs/rpcv2.h>
73#include <nfs/nfsproto.h>
74#include <nfsserver/nfs.h>
75#include <nfs/xdr_subs.h>
76#include <nfsserver/nfsm_subs.h>
77
78#include <netinet/in.h>

--- 521 unchanged lines hidden (view full) ---

600 char *fromcp, *tocp, *cp;
601 struct iovec aiov;
602 struct uio auio;
603 struct vnode *dp;
604 int error, rdonly, linklen;
605 struct componentname *cnp = &ndp->ni_cnd;
606
607 *retdirp = (struct vnode *)0;
608 cnp->cn_pnbuf = zalloc(namei_zone);
608 cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK);
609
610 /*
611 * Copy the name from the mbuf list to ndp->ni_pnbuf
612 * and set the various ndp fields appropriately.
613 */
614 fromcp = *dposp;
615 tocp = cnp->cn_pnbuf;
616 md = *mdp;

--- 48 unchanged lines hidden (view full) ---

665 */
666 *retdirp = dp;
667
668 if (pubflag) {
669 /*
670 * Oh joy. For WebNFS, handle those pesky '%' escapes,
671 * and the 'native path' indicator.
672 */
609
610 /*
611 * Copy the name from the mbuf list to ndp->ni_pnbuf
612 * and set the various ndp fields appropriately.
613 */
614 fromcp = *dposp;
615 tocp = cnp->cn_pnbuf;
616 md = *mdp;

--- 48 unchanged lines hidden (view full) ---

665 */
666 *retdirp = dp;
667
668 if (pubflag) {
669 /*
670 * Oh joy. For WebNFS, handle those pesky '%' escapes,
671 * and the 'native path' indicator.
672 */
673 cp = zalloc(namei_zone);
673 cp = uma_zalloc(namei_zone, M_WAITOK);
674 fromcp = cnp->cn_pnbuf;
675 tocp = cp;
676 if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) {
677 switch ((unsigned char)*fromcp) {
678 case WEBNFS_NATIVE_CHAR:
679 /*
680 * 'Native' path for us is the same
681 * as a path according to the NFS spec,
682 * just skip the escape char.
683 */
684 fromcp++;
685 break;
686 /*
687 * More may be added in the future, range 0x80-0xff
688 */
689 default:
690 error = EIO;
674 fromcp = cnp->cn_pnbuf;
675 tocp = cp;
676 if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) {
677 switch ((unsigned char)*fromcp) {
678 case WEBNFS_NATIVE_CHAR:
679 /*
680 * 'Native' path for us is the same
681 * as a path according to the NFS spec,
682 * just skip the escape char.
683 */
684 fromcp++;
685 break;
686 /*
687 * More may be added in the future, range 0x80-0xff
688 */
689 default:
690 error = EIO;
691 zfree(namei_zone, cp);
691 uma_zfree(namei_zone, cp);
692 goto out;
693 }
694 }
695 /*
696 * Translate the '%' escapes, URL-style.
697 */
698 while (*fromcp != '\0') {
699 if (*fromcp == WEBNFS_ESC_CHAR) {
700 if (fromcp[1] != '\0' && fromcp[2] != '\0') {
701 fromcp++;
702 *tocp++ = HEXSTRTOI(fromcp);
703 fromcp += 2;
704 continue;
705 } else {
706 error = ENOENT;
692 goto out;
693 }
694 }
695 /*
696 * Translate the '%' escapes, URL-style.
697 */
698 while (*fromcp != '\0') {
699 if (*fromcp == WEBNFS_ESC_CHAR) {
700 if (fromcp[1] != '\0' && fromcp[2] != '\0') {
701 fromcp++;
702 *tocp++ = HEXSTRTOI(fromcp);
703 fromcp += 2;
704 continue;
705 } else {
706 error = ENOENT;
707 zfree(namei_zone, cp);
707 uma_zfree(namei_zone, cp);
708 goto out;
709 }
710 } else
711 *tocp++ = *fromcp++;
712 }
713 *tocp = '\0';
708 goto out;
709 }
710 } else
711 *tocp++ = *fromcp++;
712 }
713 *tocp = '\0';
714 zfree(namei_zone, cnp->cn_pnbuf);
714 uma_zfree(namei_zone, cnp->cn_pnbuf);
715 cnp->cn_pnbuf = cp;
716 }
717
718 ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
719 ndp->ni_segflg = UIO_SYSSPACE;
720
721 if (pubflag) {
722 ndp->ni_rootdir = rootvnode;

--- 32 unchanged lines hidden (view full) ---

755 * Note: zfree is safe because error is 0, so we will
756 * not zfree it again when we break.
757 */
758 if ((cnp->cn_flags & ISSYMLINK) == 0) {
759 nfsrv_object_create(ndp->ni_vp);
760 if (cnp->cn_flags & (SAVENAME | SAVESTART))
761 cnp->cn_flags |= HASBUF;
762 else
715 cnp->cn_pnbuf = cp;
716 }
717
718 ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
719 ndp->ni_segflg = UIO_SYSSPACE;
720
721 if (pubflag) {
722 ndp->ni_rootdir = rootvnode;

--- 32 unchanged lines hidden (view full) ---

755 * Note: zfree is safe because error is 0, so we will
756 * not zfree it again when we break.
757 */
758 if ((cnp->cn_flags & ISSYMLINK) == 0) {
759 nfsrv_object_create(ndp->ni_vp);
760 if (cnp->cn_flags & (SAVENAME | SAVESTART))
761 cnp->cn_flags |= HASBUF;
762 else
763 zfree(namei_zone, cnp->cn_pnbuf);
763 uma_zfree(namei_zone, cnp->cn_pnbuf);
764 break;
765 }
766
767 /*
768 * Validate symlink
769 */
770 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
771 VOP_UNLOCK(ndp->ni_dvp, 0, td);
772 if (!pubflag) {
773 error = EINVAL;
774 goto badlink2;
775 }
776
777 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
778 error = ELOOP;
779 goto badlink2;
780 }
781 if (ndp->ni_pathlen > 1)
764 break;
765 }
766
767 /*
768 * Validate symlink
769 */
770 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
771 VOP_UNLOCK(ndp->ni_dvp, 0, td);
772 if (!pubflag) {
773 error = EINVAL;
774 goto badlink2;
775 }
776
777 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
778 error = ELOOP;
779 goto badlink2;
780 }
781 if (ndp->ni_pathlen > 1)
782 cp = zalloc(namei_zone);
782 cp = uma_zalloc(namei_zone, M_WAITOK);
783 else
784 cp = cnp->cn_pnbuf;
785 aiov.iov_base = cp;
786 aiov.iov_len = MAXPATHLEN;
787 auio.uio_iov = &aiov;
788 auio.uio_iovcnt = 1;
789 auio.uio_offset = 0;
790 auio.uio_rw = UIO_READ;
791 auio.uio_segflg = UIO_SYSSPACE;
792 auio.uio_td = (struct thread *)0;
793 auio.uio_resid = MAXPATHLEN;
794 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
795 if (error) {
796 badlink1:
797 if (ndp->ni_pathlen > 1)
783 else
784 cp = cnp->cn_pnbuf;
785 aiov.iov_base = cp;
786 aiov.iov_len = MAXPATHLEN;
787 auio.uio_iov = &aiov;
788 auio.uio_iovcnt = 1;
789 auio.uio_offset = 0;
790 auio.uio_rw = UIO_READ;
791 auio.uio_segflg = UIO_SYSSPACE;
792 auio.uio_td = (struct thread *)0;
793 auio.uio_resid = MAXPATHLEN;
794 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
795 if (error) {
796 badlink1:
797 if (ndp->ni_pathlen > 1)
798 zfree(namei_zone, cp);
798 uma_zfree(namei_zone, cp);
799 badlink2:
800 vrele(ndp->ni_dvp);
801 vput(ndp->ni_vp);
802 break;
803 }
804 linklen = MAXPATHLEN - auio.uio_resid;
805 if (linklen == 0) {
806 error = ENOENT;

--- 4 unchanged lines hidden (view full) ---

811 goto badlink1;
812 }
813
814 /*
815 * Adjust or replace path
816 */
817 if (ndp->ni_pathlen > 1) {
818 bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
799 badlink2:
800 vrele(ndp->ni_dvp);
801 vput(ndp->ni_vp);
802 break;
803 }
804 linklen = MAXPATHLEN - auio.uio_resid;
805 if (linklen == 0) {
806 error = ENOENT;

--- 4 unchanged lines hidden (view full) ---

811 goto badlink1;
812 }
813
814 /*
815 * Adjust or replace path
816 */
817 if (ndp->ni_pathlen > 1) {
818 bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
819 zfree(namei_zone, cnp->cn_pnbuf);
819 uma_zfree(namei_zone, cnp->cn_pnbuf);
820 cnp->cn_pnbuf = cp;
821 } else
822 cnp->cn_pnbuf[linklen] = '\0';
823 ndp->ni_pathlen += linklen;
824
825 /*
826 * Cleanup refs for next loop and check if root directory
827 * should replace current directory. Normally ni_dvp

--- 15 unchanged lines hidden (view full) ---

843
844 /*
845 * nfs_namei() guarentees that fields will not contain garbage
846 * whether an error occurs or not. This allows the caller to track
847 * cleanup state trivially.
848 */
849out:
850 if (error) {
820 cnp->cn_pnbuf = cp;
821 } else
822 cnp->cn_pnbuf[linklen] = '\0';
823 ndp->ni_pathlen += linklen;
824
825 /*
826 * Cleanup refs for next loop and check if root directory
827 * should replace current directory. Normally ni_dvp

--- 15 unchanged lines hidden (view full) ---

843
844 /*
845 * nfs_namei() guarentees that fields will not contain garbage
846 * whether an error occurs or not. This allows the caller to track
847 * cleanup state trivially.
848 */
849out:
850 if (error) {
851 zfree(namei_zone, cnp->cn_pnbuf);
851 uma_zfree(namei_zone, cnp->cn_pnbuf);
852 ndp->ni_vp = NULL;
853 ndp->ni_dvp = NULL;
854 ndp->ni_startdir = NULL;
855 cnp->cn_flags &= ~HASBUF;
856 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
857 ndp->ni_dvp = NULL;
858 }
859 return (error);

--- 519 unchanged lines hidden ---
852 ndp->ni_vp = NULL;
853 ndp->ni_dvp = NULL;
854 ndp->ni_startdir = NULL;
855 cnp->cn_flags &= ~HASBUF;
856 } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
857 ndp->ni_dvp = NULL;
858 }
859 return (error);

--- 519 unchanged lines hidden ---