From a235f7bb7840e0be3ee4270743e201876ffbc856 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 13 Oct 2003 21:15:48 +0000 Subject: [PATCH] Fix miscellanious kern_fp.c bugs. --- sys/kern/kern_descrip.c | 15 +++++++++++++-- sys/kern/kern_fp.c | 13 ++++++++++--- sys/sys/fcntl.h | 6 +++++- sys/sys/filedesc.h | 3 ++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 490c516329..acc3c7b6e8 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -37,7 +37,7 @@ * * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 * $FreeBSD: src/sys/kern/kern_descrip.c,v 1.81.2.17 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/kern/kern_descrip.c,v 1.14 2003/10/13 18:01:25 dillon Exp $ + * $DragonFly: src/sys/kern/kern_descrip.c,v 1.15 2003/10/13 21:15:43 dillon Exp $ */ #include "opt_compat.h" @@ -892,16 +892,19 @@ falloc(struct proc *p, struct file **resultfp, int *resultfd) return (error); } fp->f_count = 1; - fp->f_cred = crhold(p->p_ucred); fp->f_ops = &badfileops; fp->f_seqcount = 1; if (p) { + fp->f_cred = crhold(p->p_ucred); if ((fq = p->p_fd->fd_ofiles[0]) != NULL) { LIST_INSERT_AFTER(fq, fp, f_list); } else { LIST_INSERT_HEAD(&filehead, fp, f_list); } p->p_fd->fd_ofiles[i] = fp; + } else { + fp->f_cred = crhold(proc0.p_ucred); + LIST_INSERT_HEAD(&filehead, fp, f_list); } if (resultfp) *resultfp = fp; @@ -910,6 +913,14 @@ falloc(struct proc *p, struct file **resultfp, int *resultfd) return (0); } +void +fsetcred(struct file *fp, struct ucred *cr) +{ + crhold(cr); + crfree(fp->f_cred); + fp->f_cred = cr; +} + /* * Free a file descriptor. */ diff --git a/sys/kern/kern_fp.c b/sys/kern/kern_fp.c index 00341b4afc..7a24dafd60 100644 --- a/sys/kern/kern_fp.c +++ b/sys/kern/kern_fp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_fp.c,v 1.1 2003/10/13 18:01:25 dillon Exp $ + * $DragonFly: src/sys/kern/kern_fp.c,v 1.2 2003/10/13 21:15:43 dillon Exp $ */ /* @@ -79,6 +79,8 @@ typedef struct file *file_t; * * Open a file as specified. Use O_* flags for flags. * + * NOTE! O_ROOTCRED not quite working yet, vn_open() asserts that the + * cred must match the process's cred. */ int fp_open(const char *path, int flags, int mode, file_t *fpp) @@ -92,9 +94,13 @@ fp_open(const char *path, int flags, int mode, file_t *fpp) return (error); fp = *fpp; td = curthread; - NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td); + if ((flags & O_ROOTCRED) == 0 && td->td_proc) + fsetcred(fp, td->td_proc->p_ucred); + + NDINIT(&nd, NAMEI_LOOKUP, 0, UIO_SYSSPACE, path, td); flags = FFLAGS(flags); - if ((error = vn_open(&nd, flags, 0)) == 0) { + printf("%08x\n", flags); + if ((error = vn_open(&nd, flags, mode)) == 0) { NDFREE(&nd, NDF_ONLY_PNBUF); fp->f_data = (caddr_t)nd.ni_vp; fp->f_flag = flags; @@ -103,6 +109,7 @@ fp_open(const char *path, int flags, int mode, file_t *fpp) VOP_UNLOCK(nd.ni_vp, 0, td); } else { fdrop(fp, td); + *fpp = NULL; } return(error); } diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index 46365a243a..c55ece4127 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -37,7 +37,7 @@ * * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/sys/fcntl.h,v 1.9.2.2 2001/06/03 05:00:10 dillon Exp $ - * $DragonFly: src/sys/sys/fcntl.h,v 1.3 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/fcntl.h,v 1.4 2003/10/13 21:15:48 dillon Exp $ */ #ifndef _SYS_FCNTL_H_ @@ -102,6 +102,10 @@ /* Attempt to bypass buffer cache */ #define O_DIRECT 0x00010000 +#ifdef _KERNEL +#define O_ROOTCRED 0x00020000 /* fp_open */ +#endif + #ifdef _KERNEL /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ #define FFLAGS(oflags) ((oflags) + 1) diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index d47c16a8a6..20cd4ff99f 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -32,7 +32,7 @@ * * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 * $FreeBSD: src/sys/sys/filedesc.h,v 1.19.2.5 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/sys/filedesc.h,v 1.6 2003/10/09 22:27:20 dillon Exp $ + * $DragonFly: src/sys/sys/filedesc.h,v 1.7 2003/10/13 21:15:48 dillon Exp $ */ #ifndef _SYS_FILEDESC_H_ @@ -165,6 +165,7 @@ int dupfdopen (struct filedesc *, int, int, int, int); int fdalloc (struct proc *p, int want, int *result); int fdavail (struct proc *p, int n); int falloc (struct proc *p, struct file **resultfp, int *resultfd); +void fsetcred(struct file *fp, struct ucred *cr); void ffree (struct file *); struct filedesc *fdinit (struct proc *p); struct filedesc *fdshare (struct proc *p); -- 2.41.0