Reduce duplication in extattr_*_(file|link) syscalls.
Reviewed by: rwatson Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14173
This commit is contained in:
parent
44d1111709
commit
dc50858dea
@ -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_
|
||||
@ -290,26 +282,34 @@ struct extattr_set_link_args {
|
||||
#endif
|
||||
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_
|
||||
@ -467,26 +448,33 @@ struct extattr_get_link_args {
|
||||
#endif
|
||||
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_
|
||||
@ -607,24 +579,33 @@ struct extattr_delete_link_args {
|
||||
#endif
|
||||
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_
|
||||
@ -761,20 +730,27 @@ struct extattr_list_link_args {
|
||||
#endif
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user