xref: /netbsd-src/lib/libc/posix1e/acl_copy.c (revision ace5b9b5feb0e7608bd2da7a617428d2e1cf8aa3)
19aa2a9c3Schristos /*-
29aa2a9c3Schristos  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
39aa2a9c3Schristos  *
49aa2a9c3Schristos  * Copyright (c) 2001-2002 Chris D. Faulhaber
59aa2a9c3Schristos  * All rights reserved.
69aa2a9c3Schristos  *
79aa2a9c3Schristos  * Redistribution and use in source and binary forms, with or without
89aa2a9c3Schristos  * modification, are permitted provided that the following conditions
99aa2a9c3Schristos  * are met:
109aa2a9c3Schristos  * 1. Redistributions of source code must retain the above copyright
119aa2a9c3Schristos  *    notice, this list of conditions and the following disclaimer.
129aa2a9c3Schristos  * 2. Redistributions in binary form must reproduce the above copyright
139aa2a9c3Schristos  *    notice, this list of conditions and the following disclaimer in the
149aa2a9c3Schristos  *    documentation and/or other materials provided with the distribution.
159aa2a9c3Schristos  *
169aa2a9c3Schristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179aa2a9c3Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189aa2a9c3Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199aa2a9c3Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
209aa2a9c3Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219aa2a9c3Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229aa2a9c3Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239aa2a9c3Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249aa2a9c3Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259aa2a9c3Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269aa2a9c3Schristos  * SUCH DAMAGE.
279aa2a9c3Schristos  */
289aa2a9c3Schristos 
299aa2a9c3Schristos #include <sys/cdefs.h>
309aa2a9c3Schristos #if 0
319aa2a9c3Schristos __FBSDID("$FreeBSD: head/lib/libc/posix1e/acl_copy.c 326193 2017-11-25 17:12:48Z pfg $");
329aa2a9c3Schristos #else
33*ace5b9b5Schristos __RCSID("$NetBSD: acl_copy.c,v 1.2 2024/01/20 14:52:48 christos Exp $");
349aa2a9c3Schristos #endif
359aa2a9c3Schristos 
369aa2a9c3Schristos #include "namespace.h"
379aa2a9c3Schristos #include <sys/types.h>
389aa2a9c3Schristos #include <sys/acl.h>
399aa2a9c3Schristos 
409aa2a9c3Schristos #include <errno.h>
419aa2a9c3Schristos #include <string.h>
429aa2a9c3Schristos 
439aa2a9c3Schristos #include "acl_support.h"
449aa2a9c3Schristos 
459aa2a9c3Schristos /*
469aa2a9c3Schristos  * acl_copy_entry() (23.4.4): copy the contents of ACL entry src_d to
479aa2a9c3Schristos  * ACL entry dest_d
489aa2a9c3Schristos  */
499aa2a9c3Schristos int
acl_copy_entry(acl_entry_t dest_d,acl_entry_t src_d)509aa2a9c3Schristos acl_copy_entry(acl_entry_t dest_d, acl_entry_t src_d)
519aa2a9c3Schristos {
529aa2a9c3Schristos 
539aa2a9c3Schristos 	if (src_d == NULL || dest_d == NULL || src_d == dest_d) {
549aa2a9c3Schristos 		errno = EINVAL;
559aa2a9c3Schristos 		return (-1);
569aa2a9c3Schristos 	}
579aa2a9c3Schristos 
589aa2a9c3Schristos 	/*
599aa2a9c3Schristos 	 * Can we brand the new entry the same as the source entry?
609aa2a9c3Schristos 	 */
619aa2a9c3Schristos 	if (!_entry_brand_may_be(dest_d, _entry_brand(src_d))) {
629aa2a9c3Schristos 		errno = EINVAL;
639aa2a9c3Schristos 		return (-1);
649aa2a9c3Schristos 	}
659aa2a9c3Schristos 
669aa2a9c3Schristos 	_entry_brand_as(dest_d, _entry_brand(src_d));
679aa2a9c3Schristos 
689aa2a9c3Schristos 	dest_d->ae_tag = src_d->ae_tag;
699aa2a9c3Schristos 	dest_d->ae_id = src_d->ae_id;
709aa2a9c3Schristos 	dest_d->ae_perm = src_d->ae_perm;
719aa2a9c3Schristos 	dest_d->ae_entry_type = src_d->ae_entry_type;
729aa2a9c3Schristos 	dest_d->ae_flags = src_d->ae_flags;
739aa2a9c3Schristos 
749aa2a9c3Schristos 	return (0);
759aa2a9c3Schristos }
769aa2a9c3Schristos 
779aa2a9c3Schristos ssize_t
78*ace5b9b5Schristos /*ARGSUSED*/
acl_copy_ext(void * buf_p,acl_t acl,ssize_t size)799aa2a9c3Schristos acl_copy_ext(void *buf_p, acl_t acl, ssize_t size)
809aa2a9c3Schristos {
819aa2a9c3Schristos 
829aa2a9c3Schristos 	errno = ENOSYS;
839aa2a9c3Schristos 	return (-1);
849aa2a9c3Schristos }
859aa2a9c3Schristos 
869aa2a9c3Schristos acl_t
87*ace5b9b5Schristos /*ARGSUSED*/
acl_copy_int(const void * buf_p)889aa2a9c3Schristos acl_copy_int(const void *buf_p)
899aa2a9c3Schristos {
909aa2a9c3Schristos 
919aa2a9c3Schristos 	errno = ENOSYS;
929aa2a9c3Schristos 	return (NULL);
939aa2a9c3Schristos }
94