2005-01-10 08:39:26 +00:00
|
|
|
/*-
|
2001-03-19 18:09:25 +00:00
|
|
|
* Copyright (c) 2001 Chris D. Faulhaber
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2010-03-07 07:59:05 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2001-03-19 18:09:25 +00:00
|
|
|
*/
|
|
|
|
|
2002-06-30 05:15:05 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-03-19 18:09:25 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
|
|
|
|
#include "setfacl.h"
|
|
|
|
|
2001-12-03 00:51:36 +00:00
|
|
|
/*
|
|
|
|
* remove ACL entries from an ACL
|
|
|
|
*/
|
2001-03-19 18:09:25 +00:00
|
|
|
int
|
2009-09-07 16:19:32 +00:00
|
|
|
remove_acl(acl_t acl, acl_t *prev_acl, const char *filename)
|
2001-03-19 18:09:25 +00:00
|
|
|
{
|
2001-04-24 22:45:41 +00:00
|
|
|
acl_entry_t entry;
|
|
|
|
acl_t acl_new;
|
|
|
|
acl_tag_t tag;
|
2009-09-07 16:19:32 +00:00
|
|
|
int carried_error, entry_id, acl_brand, prev_acl_brand;
|
|
|
|
|
|
|
|
carried_error = 0;
|
|
|
|
|
|
|
|
acl_get_brand_np(acl, &acl_brand);
|
|
|
|
acl_get_brand_np(*prev_acl, &prev_acl_brand);
|
|
|
|
|
2009-12-26 10:06:45 +00:00
|
|
|
if (branding_mismatch(acl_brand, prev_acl_brand)) {
|
2009-09-07 16:19:32 +00:00
|
|
|
warnx("%s: branding mismatch; existing ACL is %s, "
|
|
|
|
"entry to be removed is %s", filename,
|
2009-12-26 10:06:45 +00:00
|
|
|
brand_name(prev_acl_brand), brand_name(acl_brand));
|
2009-09-07 16:19:32 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2001-03-19 18:09:25 +00:00
|
|
|
|
|
|
|
carried_error = 0;
|
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_new = acl_dup(*prev_acl);
|
2001-12-03 00:51:36 +00:00
|
|
|
if (acl_new == NULL)
|
2009-09-07 16:19:32 +00:00
|
|
|
err(1, "%s: acl_dup() failed", filename);
|
2001-03-19 18:09:25 +00:00
|
|
|
|
2001-04-24 22:45:41 +00:00
|
|
|
tag = ACL_UNDEFINED_TAG;
|
|
|
|
|
2001-03-19 18:09:25 +00:00
|
|
|
/* find and delete the entry */
|
2001-04-24 22:45:41 +00:00
|
|
|
entry_id = ACL_FIRST_ENTRY;
|
|
|
|
while (acl_get_entry(acl, entry_id, &entry) == 1) {
|
|
|
|
entry_id = ACL_NEXT_ENTRY;
|
|
|
|
if (acl_get_tag_type(entry, &tag) == -1)
|
2009-09-07 16:19:32 +00:00
|
|
|
err(1, "%s: acl_get_tag_type() failed", filename);
|
2001-04-24 22:45:41 +00:00
|
|
|
if (tag == ACL_MASK)
|
2018-04-27 15:25:24 +00:00
|
|
|
have_mask = true;
|
2001-04-24 22:45:41 +00:00
|
|
|
if (acl_delete_entry(acl_new, entry) == -1) {
|
2001-03-19 18:09:25 +00:00
|
|
|
carried_error++;
|
2009-09-07 16:19:32 +00:00
|
|
|
warnx("%s: cannot remove non-existent ACL entry",
|
|
|
|
filename);
|
2001-03-19 18:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_free(*prev_acl);
|
|
|
|
*prev_acl = acl_new;
|
|
|
|
|
|
|
|
if (carried_error)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
remove_by_number(uint entry_number, acl_t *prev_acl, const char *filename)
|
|
|
|
{
|
|
|
|
acl_entry_t entry;
|
|
|
|
acl_t acl_new;
|
|
|
|
acl_tag_t tag;
|
|
|
|
int carried_error, entry_id;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
carried_error = 0;
|
|
|
|
|
|
|
|
acl_new = acl_dup(*prev_acl);
|
|
|
|
if (acl_new == NULL)
|
|
|
|
err(1, "%s: acl_dup() failed", filename);
|
|
|
|
|
|
|
|
tag = ACL_UNDEFINED_TAG;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out whether we're removing the mask entry,
|
|
|
|
* to behave the same as the routine above.
|
|
|
|
*
|
|
|
|
* XXX: Is this loop actually needed?
|
|
|
|
*/
|
|
|
|
entry_id = ACL_FIRST_ENTRY;
|
|
|
|
i = 0;
|
|
|
|
while (acl_get_entry(acl_new, entry_id, &entry) == 1) {
|
|
|
|
entry_id = ACL_NEXT_ENTRY;
|
|
|
|
if (i != entry_number)
|
|
|
|
continue;
|
|
|
|
if (acl_get_tag_type(entry, &tag) == -1)
|
|
|
|
err(1, "%s: acl_get_tag_type() failed", filename);
|
|
|
|
if (tag == ACL_MASK)
|
2018-04-27 15:25:24 +00:00
|
|
|
have_mask = true;
|
2009-09-07 16:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (acl_delete_entry_np(acl_new, entry_number) == -1) {
|
|
|
|
carried_error++;
|
|
|
|
warn("%s: acl_delete_entry_np() failed", filename);
|
2001-03-19 18:09:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_free(*prev_acl);
|
|
|
|
*prev_acl = acl_new;
|
|
|
|
|
2001-03-19 18:09:25 +00:00
|
|
|
if (carried_error)
|
2001-12-03 00:51:36 +00:00
|
|
|
return (-1);
|
2001-03-19 18:09:25 +00:00
|
|
|
|
2001-12-03 00:51:36 +00:00
|
|
|
return (0);
|
2001-03-19 18:09:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-03 00:51:36 +00:00
|
|
|
/*
|
|
|
|
* remove default entries
|
|
|
|
*/
|
2001-03-19 18:09:25 +00:00
|
|
|
int
|
2009-09-07 16:19:32 +00:00
|
|
|
remove_default(acl_t *prev_acl, const char *filename)
|
2001-03-19 18:09:25 +00:00
|
|
|
{
|
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_free(*prev_acl);
|
|
|
|
*prev_acl = acl_init(ACL_MAX_ENTRIES);
|
|
|
|
if (*prev_acl == NULL)
|
|
|
|
err(1, "%s: acl_init() failed", filename);
|
|
|
|
|
2001-12-03 00:51:36 +00:00
|
|
|
return (0);
|
2001-03-19 18:09:25 +00:00
|
|
|
}
|
|
|
|
|
2001-12-03 00:51:36 +00:00
|
|
|
/*
|
|
|
|
* remove extended entries
|
|
|
|
*/
|
2001-03-19 18:09:25 +00:00
|
|
|
void
|
2009-09-07 16:19:32 +00:00
|
|
|
remove_ext(acl_t *prev_acl, const char *filename)
|
2001-03-19 18:09:25 +00:00
|
|
|
{
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_t acl_new;
|
2001-04-24 22:45:41 +00:00
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_new = acl_strip_np(*prev_acl, !n_flag);
|
|
|
|
if (acl_new == NULL)
|
|
|
|
err(1, "%s: acl_strip_np() failed", filename);
|
2001-03-19 18:09:25 +00:00
|
|
|
|
2009-09-07 16:19:32 +00:00
|
|
|
acl_free(*prev_acl);
|
|
|
|
*prev_acl = acl_new;
|
2001-03-19 18:09:25 +00:00
|
|
|
}
|