Date: Mon, 5 Feb 2018 19:06:34 +0000 (UTC) From: Brooks Davis <brooks@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328899 - head/sys/kern Message-ID: <201802051906.w15J6YgE015007@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <security/audit/audit.h> #include <security/mac/mac_framework.h> +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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802051906.w15J6YgE015007>