xref: /freebsd/lib/libc/posix1e/acl_copy.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1d915a14eSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3d915a14eSPedro F. Giffuni  *
4e76872c1SChris D. Faulhaber  * Copyright (c) 2001-2002 Chris D. Faulhaber
54bf60dfaSChris D. Faulhaber  * All rights reserved.
64bf60dfaSChris D. Faulhaber  *
74bf60dfaSChris D. Faulhaber  * Redistribution and use in source and binary forms, with or without
84bf60dfaSChris D. Faulhaber  * modification, are permitted provided that the following conditions
94bf60dfaSChris D. Faulhaber  * are met:
104bf60dfaSChris D. Faulhaber  * 1. Redistributions of source code must retain the above copyright
114bf60dfaSChris D. Faulhaber  *    notice, this list of conditions and the following disclaimer.
124bf60dfaSChris D. Faulhaber  * 2. Redistributions in binary form must reproduce the above copyright
134bf60dfaSChris D. Faulhaber  *    notice, this list of conditions and the following disclaimer in the
144bf60dfaSChris D. Faulhaber  *    documentation and/or other materials provided with the distribution.
154bf60dfaSChris D. Faulhaber  *
164bf60dfaSChris D. Faulhaber  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174bf60dfaSChris D. Faulhaber  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184bf60dfaSChris D. Faulhaber  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1968b23992SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
2068b23992SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2168b23992SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2268b23992SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2368b23992SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2468b23992SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2568b23992SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2668b23992SWarner Losh  * SUCH DAMAGE.
274bf60dfaSChris D. Faulhaber  */
284bf60dfaSChris D. Faulhaber 
294bf60dfaSChris D. Faulhaber #include <sys/types.h>
307bd44e92SThomas Moestl #include "namespace.h"
314bf60dfaSChris D. Faulhaber #include <sys/acl.h>
327bd44e92SThomas Moestl #include "un-namespace.h"
334bf60dfaSChris D. Faulhaber 
344bf60dfaSChris D. Faulhaber #include <errno.h>
354bf60dfaSChris D. Faulhaber #include <string.h>
364bf60dfaSChris D. Faulhaber 
37aa015c8eSEdward Tomasz Napierala #include "acl_support.h"
38aa015c8eSEdward Tomasz Napierala 
394bf60dfaSChris D. Faulhaber /*
400f626307SChris D. Faulhaber  * acl_copy_entry() (23.4.4): copy the contents of ACL entry src_d to
414bf60dfaSChris D. Faulhaber  * ACL entry dest_d
424bf60dfaSChris D. Faulhaber  */
434bf60dfaSChris D. Faulhaber int
acl_copy_entry(acl_entry_t dest_d,acl_entry_t src_d)444bf60dfaSChris D. Faulhaber acl_copy_entry(acl_entry_t dest_d, acl_entry_t src_d)
454bf60dfaSChris D. Faulhaber {
464bf60dfaSChris D. Faulhaber 
47e76872c1SChris D. Faulhaber 	if (src_d == NULL || dest_d == NULL || src_d == dest_d) {
484bf60dfaSChris D. Faulhaber 		errno = EINVAL;
49e76872c1SChris D. Faulhaber 		return (-1);
504bf60dfaSChris D. Faulhaber 	}
514bf60dfaSChris D. Faulhaber 
52aa015c8eSEdward Tomasz Napierala 	/*
53aa015c8eSEdward Tomasz Napierala 	 * Can we brand the new entry the same as the source entry?
54aa015c8eSEdward Tomasz Napierala 	 */
55aa015c8eSEdward Tomasz Napierala 	if (!_entry_brand_may_be(dest_d, _entry_brand(src_d))) {
56aa015c8eSEdward Tomasz Napierala 		errno = EINVAL;
57aa015c8eSEdward Tomasz Napierala 		return (-1);
58aa015c8eSEdward Tomasz Napierala 	}
59aa015c8eSEdward Tomasz Napierala 
60aa015c8eSEdward Tomasz Napierala 	_entry_brand_as(dest_d, _entry_brand(src_d));
61aa015c8eSEdward Tomasz Napierala 
624bf60dfaSChris D. Faulhaber 	dest_d->ae_tag = src_d->ae_tag;
634bf60dfaSChris D. Faulhaber 	dest_d->ae_id = src_d->ae_id;
644bf60dfaSChris D. Faulhaber 	dest_d->ae_perm = src_d->ae_perm;
65aa015c8eSEdward Tomasz Napierala 	dest_d->ae_entry_type = src_d->ae_entry_type;
66aa015c8eSEdward Tomasz Napierala 	dest_d->ae_flags = src_d->ae_flags;
674bf60dfaSChris D. Faulhaber 
68e76872c1SChris D. Faulhaber 	return (0);
694bf60dfaSChris D. Faulhaber }
704bf60dfaSChris D. Faulhaber 
714bf60dfaSChris D. Faulhaber ssize_t
acl_copy_ext(void * buf_p,acl_t acl,ssize_t size)724bf60dfaSChris D. Faulhaber acl_copy_ext(void *buf_p, acl_t acl, ssize_t size)
734bf60dfaSChris D. Faulhaber {
744bf60dfaSChris D. Faulhaber 
754bf60dfaSChris D. Faulhaber 	errno = ENOSYS;
76e76872c1SChris D. Faulhaber 	return (-1);
774bf60dfaSChris D. Faulhaber }
784bf60dfaSChris D. Faulhaber 
794bf60dfaSChris D. Faulhaber acl_t
acl_copy_int(const void * buf_p)804bf60dfaSChris D. Faulhaber acl_copy_int(const void *buf_p)
814bf60dfaSChris D. Faulhaber {
824bf60dfaSChris D. Faulhaber 
834bf60dfaSChris D. Faulhaber 	errno = ENOSYS;
84e76872c1SChris D. Faulhaber 	return (NULL);
854bf60dfaSChris D. Faulhaber }
86