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/audit/audit.h>
|
||||||
#include <security/mac/mac_framework.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.
|
* Syscall to push extended attribute configuration information into the VFS.
|
||||||
* Accepts a path, which it converts to a mountpoint, as well as a command
|
* Accepts a path, which it converts to a mountpoint, as well as a command
|
||||||
@ -255,28 +266,9 @@ struct extattr_set_file_args {
|
|||||||
int
|
int
|
||||||
sys_extattr_set_file(struct thread *td, struct extattr_set_file_args *uap)
|
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);
|
return (kern_extattr_set_path(td, uap->path, uap->attrnamespace,
|
||||||
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
uap->attrname, uap->data, uap->nbytes, FOLLOW));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _SYS_SYSPROTO_H_
|
#ifndef _SYS_SYSPROTO_H_
|
||||||
@ -290,26 +282,34 @@ struct extattr_set_link_args {
|
|||||||
#endif
|
#endif
|
||||||
int
|
int
|
||||||
sys_extattr_set_link(struct thread *td, struct extattr_set_link_args *uap)
|
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;
|
struct nameidata nd;
|
||||||
char attrname[EXTATTR_MAXNAMELEN];
|
char attrname[EXTATTR_MAXNAMELEN];
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
AUDIT_ARG_VALUE(uap->attrnamespace);
|
AUDIT_ARG_VALUE(attrnamespace);
|
||||||
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
AUDIT_ARG_TEXT(attrname);
|
AUDIT_ARG_TEXT(attrname);
|
||||||
|
|
||||||
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE,
|
NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td);
|
||||||
uap->path, td);
|
|
||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
||||||
|
|
||||||
error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname,
|
error = extattr_set_vp(nd.ni_vp, attrnamespace, attrname, data,
|
||||||
uap->data, uap->nbytes, td);
|
nbytes, td);
|
||||||
|
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -433,27 +433,8 @@ struct extattr_get_file_args {
|
|||||||
int
|
int
|
||||||
sys_extattr_get_file(struct thread *td, struct extattr_get_file_args *uap)
|
sys_extattr_get_file(struct thread *td, struct extattr_get_file_args *uap)
|
||||||
{
|
{
|
||||||
struct nameidata nd;
|
return (kern_extattr_get_path(td, uap->path, uap->attrnamespace,
|
||||||
char attrname[EXTATTR_MAXNAMELEN];
|
uap->attrname, uap->data, uap->nbytes, FOLLOW));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _SYS_SYSPROTO_H_
|
#ifndef _SYS_SYSPROTO_H_
|
||||||
@ -467,26 +448,33 @@ struct extattr_get_link_args {
|
|||||||
#endif
|
#endif
|
||||||
int
|
int
|
||||||
sys_extattr_get_link(struct thread *td, struct extattr_get_link_args *uap)
|
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;
|
struct nameidata nd;
|
||||||
char attrname[EXTATTR_MAXNAMELEN];
|
char attrname[EXTATTR_MAXNAMELEN];
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
AUDIT_ARG_VALUE(uap->attrnamespace);
|
AUDIT_ARG_VALUE(attrnamespace);
|
||||||
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
AUDIT_ARG_TEXT(attrname);
|
AUDIT_ARG_TEXT(attrname);
|
||||||
|
|
||||||
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path,
|
NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td);
|
||||||
td);
|
|
||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
||||||
|
|
||||||
error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname,
|
error = extattr_get_vp(nd.ni_vp, attrnamespace, attrname, data,
|
||||||
uap->data, uap->nbytes, td);
|
nbytes, td);
|
||||||
|
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
@ -577,25 +565,9 @@ struct extattr_delete_file_args {
|
|||||||
int
|
int
|
||||||
sys_extattr_delete_file(struct thread *td, struct extattr_delete_file_args *uap)
|
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);
|
return (kern_extattr_delete_path(td, uap->path, uap->attrnamespace,
|
||||||
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
uap->attrname, FOLLOW));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _SYS_SYSPROTO_H_
|
#ifndef _SYS_SYSPROTO_H_
|
||||||
@ -607,24 +579,33 @@ struct extattr_delete_link_args {
|
|||||||
#endif
|
#endif
|
||||||
int
|
int
|
||||||
sys_extattr_delete_link(struct thread *td, struct extattr_delete_link_args *uap)
|
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;
|
struct nameidata nd;
|
||||||
char attrname[EXTATTR_MAXNAMELEN];
|
char attrname[EXTATTR_MAXNAMELEN];
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
AUDIT_ARG_VALUE(uap->attrnamespace);
|
AUDIT_ARG_VALUE(attrnamespace);
|
||||||
error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
error = copyinstr(uattrname, attrname, EXTATTR_MAXNAMELEN, NULL);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return(error);
|
||||||
AUDIT_ARG_TEXT(attrname);
|
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);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return(error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
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);
|
vrele(nd.ni_vp);
|
||||||
return(error);
|
return(error);
|
||||||
}
|
}
|
||||||
@ -734,21 +715,9 @@ struct extattr_list_file_args {
|
|||||||
int
|
int
|
||||||
sys_extattr_list_file(struct thread *td, struct extattr_list_file_args *uap)
|
sys_extattr_list_file(struct thread *td, struct extattr_list_file_args *uap)
|
||||||
{
|
{
|
||||||
struct nameidata nd;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
AUDIT_ARG_VALUE(uap->attrnamespace);
|
return (kern_extattr_list_path(td, uap->path, uap->attrnamespace,
|
||||||
NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td);
|
uap->data, uap->nbytes, FOLLOW));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _SYS_SYSPROTO_H_
|
#ifndef _SYS_SYSPROTO_H_
|
||||||
@ -761,20 +730,27 @@ struct extattr_list_link_args {
|
|||||||
#endif
|
#endif
|
||||||
int
|
int
|
||||||
sys_extattr_list_link(struct thread *td, struct extattr_list_link_args *uap)
|
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;
|
struct nameidata nd;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
AUDIT_ARG_VALUE(uap->attrnamespace);
|
AUDIT_ARG_VALUE(attrnamespace);
|
||||||
NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path,
|
NDINIT(&nd, LOOKUP, follow | AUDITVNODE1, UIO_USERSPACE, path, td);
|
||||||
td);
|
|
||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
return (error);
|
return (error);
|
||||||
NDFREE(&nd, NDF_ONLY_PNBUF);
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
||||||
|
|
||||||
error = extattr_list_vp(nd.ni_vp, uap->attrnamespace, uap->data,
|
error = extattr_list_vp(nd.ni_vp, attrnamespace, data, nbytes, td);
|
||||||
uap->nbytes, td);
|
|
||||||
|
|
||||||
vrele(nd.ni_vp);
|
vrele(nd.ni_vp);
|
||||||
return (error);
|
return (error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user