From owner-svn-src-all@freebsd.org Mon Feb 5 19:06:35 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4AA31EE79CF; Mon, 5 Feb 2018 19:06:35 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 000BA8441A; Mon, 5 Feb 2018 19:06:34 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA89D4F58; Mon, 5 Feb 2018 19:06:34 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w15J6YwM015008; Mon, 5 Feb 2018 19:06:34 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w15J6YgE015007; Mon, 5 Feb 2018 19:06:34 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <201802051906.w15J6YgE015007@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Mon, 5 Feb 2018 19:06:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328899 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 328899 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Feb 2018 19:06:35 -0000 Author: brooks Date: Mon Feb 5 19:06:34 2018 New Revision: 328899 URL: https://svnweb.freebsd.org/changeset/base/328899 Log: Reduce duplication in extattr_*_(file|link) syscalls. Reviewed by: rwatson Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14173 Modified: head/sys/kern/vfs_extattr.c Modified: head/sys/kern/vfs_extattr.c ============================================================================== --- head/sys/kern/vfs_extattr.c Mon Feb 5 18:58:55 2018 (r328898) +++ head/sys/kern/vfs_extattr.c Mon Feb 5 19:06:34 2018 (r328899) @@ -49,6 +49,17 @@ __FBSDID("$FreeBSD$"); #include #include +static int kern_extattr_set_path(struct thread *td, const char *path, + int attrnamespace, const char *attrname, void *data, + size_t nbytes, int follow); +static int kern_extattr_get_path(struct thread *td, const char *path, + int attrnamespace, const char *attrname, void *data, + size_t nbytes, int follow); +static int kern_extattr_delete_path(struct thread *td, const char *path, + int attrnamespace, const char *attrname, int follow); +static int kern_extattr_list_path(struct thread *td, const char *path, + int attrnamespace, void *data, size_t nbytes, int follow); + /* * Syscall to push extended attribute configuration information into the VFS. * Accepts a path, which it converts to a mountpoint, as well as a command @@ -255,28 +266,9 @@ struct extattr_set_file_args { int sys_extattr_set_file(struct thread *td, struct extattr_set_file_args *uap) { - struct nameidata nd; - char attrname[EXTATTR_MAXNAMELEN]; - int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); - if (error) - return (error); - AUDIT_ARG_TEXT(attrname); - - NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); - error = namei(&nd); - if (error) - return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); - - error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname, - uap->data, uap->nbytes, td); - - vrele(nd.ni_vp); - return (error); + return (kern_extattr_set_path(td, uap->path, uap->attrnamespace, + uap->attrname, uap->data, uap->nbytes, FOLLOW)); } #ifndef _SYS_SYSPROTO_H_ @@ -291,25 +283,33 @@ struct extattr_set_link_args { int sys_extattr_set_link(struct thread *td, struct extattr_set_link_args *uap) { + + return (kern_extattr_set_path(td, uap->path, uap->attrnamespace, + uap->attrname, uap->data, uap->nbytes, NOFOLLOW)); +} + +static int +kern_extattr_set_path(struct thread *td, const char *path, int attrnamespace, + const char *uattrname, void *data, size_t nbytes, int follow) +{ struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); + AUDIT_ARG_VALUE(attrnamespace); + error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); if (error) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname, - uap->data, uap->nbytes, td); + error = extattr_set_vp(nd.ni_vp, attrnamespace, attrname, data, + nbytes, td); vrele(nd.ni_vp); return (error); @@ -433,27 +433,8 @@ struct extattr_get_file_args { int sys_extattr_get_file(struct thread *td, struct extattr_get_file_args *uap) { - struct nameidata nd; - char attrname[EXTATTR_MAXNAMELEN]; - int error; - - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); - if (error) - return (error); - AUDIT_ARG_TEXT(attrname); - - NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - if (error) - return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); - - error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname, - uap->data, uap->nbytes, td); - - vrele(nd.ni_vp); - return (error); + return (kern_extattr_get_path(td, uap->path, uap->attrnamespace, + uap->attrname, uap->data, uap->nbytes, FOLLOW)); } #ifndef _SYS_SYSPROTO_H_ @@ -468,25 +449,32 @@ struct extattr_get_link_args { int sys_extattr_get_link(struct thread *td, struct extattr_get_link_args *uap) { + return (kern_extattr_get_path(td, uap->path, uap->attrnamespace, + uap->attrname, uap->data, uap->nbytes, NOFOLLOW)); +} + +static int +kern_extattr_get_path(struct thread *td, const char *path, int attrnamespace, + const char *uattrname, void *data, size_t nbytes, int follow) +{ struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); + AUDIT_ARG_VALUE(attrnamespace); + error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); if (error) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, - td); + NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname, - uap->data, uap->nbytes, td); + error = extattr_get_vp(nd.ni_vp, attrnamespace, attrname, data, + nbytes, td); vrele(nd.ni_vp); return (error); @@ -577,25 +565,9 @@ struct extattr_delete_file_args { int sys_extattr_delete_file(struct thread *td, struct extattr_delete_file_args *uap) { - struct nameidata nd; - char attrname[EXTATTR_MAXNAMELEN]; - int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); - if (error) - return(error); - AUDIT_ARG_TEXT(attrname); - - NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - if (error) - return(error); - NDFREE(&nd, NDF_ONLY_PNBUF); - - error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td); - vrele(nd.ni_vp); - return(error); + return (kern_extattr_delete_path(td, uap->path, uap->attrnamespace, + uap->attrname, FOLLOW)); } #ifndef _SYS_SYSPROTO_H_ @@ -608,23 +580,32 @@ struct extattr_delete_link_args { int sys_extattr_delete_link(struct thread *td, struct extattr_delete_link_args *uap) { + + return (kern_extattr_delete_path(td, uap->path, uap->attrnamespace, + uap->attrname, NOFOLLOW)); +} + +static int +kern_extattr_delete_path(struct thread *td, const char *path, int attrnamespace, + const char *uattrname, int follow) +{ struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); + AUDIT_ARG_VALUE(attrnamespace); + error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL); if (error) return(error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td); error = namei(&nd); if (error) return(error); NDFREE(&nd, NDF_ONLY_PNBUF); - error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td); + error = extattr_delete_vp(nd.ni_vp, attrnamespace, attrname, td); vrele(nd.ni_vp); return(error); } @@ -734,21 +715,9 @@ struct extattr_list_file_args { int sys_extattr_list_file(struct thread *td, struct extattr_list_file_args *uap) { - struct nameidata nd; - int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); - error = namei(&nd); - if (error) - return (error); - NDFREE(&nd, NDF_ONLY_PNBUF); - - error = extattr_list_vp(nd.ni_vp, uap->attrnamespace, uap->data, - uap->nbytes, td); - - vrele(nd.ni_vp); - return (error); + return (kern_extattr_list_path(td, uap->path, uap->attrnamespace, + uap->data, uap->nbytes, FOLLOW)); } #ifndef _SYS_SYSPROTO_H_ @@ -762,19 +731,26 @@ struct extattr_list_link_args { int sys_extattr_list_link(struct thread *td, struct extattr_list_link_args *uap) { + + return (kern_extattr_list_path(td, uap->path, uap->attrnamespace, + uap->data, uap->nbytes, NOFOLLOW)); +} + +static int +kern_extattr_list_path(struct thread *td, const char *path, int attrnamespace, + void *data, size_t nbytes, int follow) +{ struct nameidata nd; int error; - AUDIT_ARG_VALUE(uap->attrnamespace); - NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, - td); + AUDIT_ARG_VALUE(attrnamespace); + NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - error = extattr_list_vp(nd.ni_vp, uap->attrnamespace, uap->data, - uap->nbytes, td); + error = extattr_list_vp(nd.ni_vp, attrnamespace, data, nbytes, td); vrele(nd.ni_vp); return (error);