* setfacl.c (action_t): Add DeleteDef value.

(delacl): Take new parameter to differe between DeleteAll and DeleteDef.
	Extend conditional to handle DefaultDef.  Change comment accordingly.
	(setfacl): Call delacl in DefaultDef case as well.
	(usage): Add and describe -k option.  Add -k to require options.
	(longopts): Add --remove-default option.
	(opts): Add -k option.
	(main): Handle -k option.
This commit is contained in:
Corinna Vinschen 2014-12-15 20:29:43 +00:00
parent ab42ec30e6
commit e7ead873a8
2 changed files with 37 additions and 7 deletions

View File

@ -1,3 +1,14 @@
2014-12-15 Corinna Vinschen <corinna@vinschen.de>
* setfacl.c (action_t): Add DeleteDef value.
(delacl): Take new parameter to differe between DeleteAll and DeleteDef.
Extend conditional to handle DefaultDef. Change comment accordingly.
(setfacl): Call delacl in DefaultDef case as well.
(usage): Add and describe -k option. Add -k to require options.
(longopts): Add --remove-default option.
(opts): Add -k option.
(main): Handle -k option.
2014-12-05 Václav Zeman <vhaisman@gmail.com> 2014-12-05 Václav Zeman <vhaisman@gmail.com>
* tzmap-from-unicode.org: Create tzmap as const. * tzmap-from-unicode.org: Create tzmap as const.

View File

@ -49,6 +49,7 @@ typedef enum {
Delete, Delete,
ModNDel, ModNDel,
DeleteAll, DeleteAll,
DeleteDef,
SetFromFile SetFromFile
} action_t; } action_t;
@ -332,13 +333,15 @@ addmissing (aclent_t *tgt, int tcnt)
} }
int int
delacl (aclent_t *tgt, int tcnt) delacl (aclent_t *tgt, int tcnt, action_t action)
{ {
int t; int t;
/* Remove all extended ACL entries. */
for (t = 0; t < tcnt; ++t) for (t = 0; t < tcnt; ++t)
if (tgt[t].a_type & (USER | GROUP | CLASS_OBJ)) /* -b (DeleteAll): Remove all extended ACL entries.
-k (DeleteDef): Remove all default ACL entries. */
if ((action == DeleteAll && (tgt[t].a_type & (USER | GROUP | CLASS_OBJ)))
|| (action == DeleteDef && (tgt[t].a_type & ACL_DEFAULT)))
{ {
--tcnt; --tcnt;
if (t < tcnt) if (t < tcnt)
@ -374,8 +377,9 @@ setfacl (action_t action, const char *path, aclent_t *acls, int cnt)
} }
break; break;
case DeleteAll: case DeleteAll:
case DeleteDef:
if ((lcnt = acl (path, GETACL, MAX_ACL_ENTRIES, lacl)) < 0 if ((lcnt = acl (path, GETACL, MAX_ACL_ENTRIES, lacl)) < 0
|| (lcnt = delacl (lacl, lcnt)) < 0 || (lcnt = delacl (lacl, lcnt, action)) < 0
|| (lcnt = acl (path, SETACL, lcnt, lacl)) < 0) || (lcnt = acl (path, SETACL, lcnt, lacl)) < 0)
{ {
perror (prog_name); perror (prog_name);
@ -397,7 +401,7 @@ setfacl (action_t action, const char *path, aclent_t *acls, int cnt)
} }
static void static void
usage (FILE * stream) usage (FILE *stream)
{ {
fprintf (stream, "" fprintf (stream, ""
"Usage: %s [-r] {-f ACL_FILE | -s acl_entries} FILE...\n" "Usage: %s [-r] {-f ACL_FILE | -s acl_entries} FILE...\n"
@ -409,6 +413,8 @@ usage (FILE * stream)
" -d, --delete delete one or more specified ACL entries\n" " -d, --delete delete one or more specified ACL entries\n"
" -f, --file set ACL entries for FILE to ACL entries read\n" " -f, --file set ACL entries for FILE to ACL entries read\n"
" from a ACL_FILE\n" " from a ACL_FILE\n"
" -k, --remove-default\n"
" remove all default ACL entries\n"
" -m, --modify modify one or more specified ACL entries\n" " -m, --modify modify one or more specified ACL entries\n"
" -r, --replace replace mask entry with maximum permissions\n" " -r, --replace replace mask entry with maximum permissions\n"
" needed for the file group class\n" " needed for the file group class\n"
@ -417,7 +423,7 @@ usage (FILE * stream)
" -h, --help output usage information and exit\n" " -h, --help output usage information and exit\n"
" -V, --version output version information and exit\n" " -V, --version output version information and exit\n"
"\n" "\n"
"At least one of (-b, -d, -f, -m, -s) must be specified\n" "At least one of (-b, -d, -f, -k, -m, -s) must be specified\n"
"\n", prog_name, prog_name); "\n", prog_name, prog_name);
if (stream == stdout) if (stream == stdout)
{ {
@ -484,6 +490,9 @@ usage (FILE * stream)
" - One default mask entry for the file group class.\n" " - One default mask entry for the file group class.\n"
" - One default other entry.\n" " - One default other entry.\n"
"\n" "\n"
"-k Remove all default ACL entries. If no default ACL entries\n"
" exist, no warnings are issued.\n"
"\n"
"-m Add or modify one or more specified ACL entries.\n" "-m Add or modify one or more specified ACL entries.\n"
" Acl_entries is a comma-separated list of entries from the \n" " Acl_entries is a comma-separated list of entries from the \n"
" same list as above.\n" " same list as above.\n"
@ -512,6 +521,7 @@ struct option longopts[] = {
{"remove-all", no_argument, NULL, 'b'}, {"remove-all", no_argument, NULL, 'b'},
{"delete", required_argument, NULL, 'd'}, {"delete", required_argument, NULL, 'd'},
{"file", required_argument, NULL, 'f'}, {"file", required_argument, NULL, 'f'},
{"remove-default", no_argument, NULL, 'k'},
{"modify", required_argument, NULL, 'm'}, {"modify", required_argument, NULL, 'm'},
{"replace", no_argument, NULL, 'r'}, {"replace", no_argument, NULL, 'r'},
{"substitute", required_argument, NULL, 's'}, {"substitute", required_argument, NULL, 's'},
@ -519,7 +529,7 @@ struct option longopts[] = {
{"version", no_argument, NULL, 'V'}, {"version", no_argument, NULL, 'V'},
{0, no_argument, NULL, 0} {0, no_argument, NULL, 0}
}; };
const char *opts = "bd:f:hm:rs:V"; const char *opts = "bd:f:hkm:rs:V";
static void static void
print_version () print_version ()
@ -593,6 +603,15 @@ main (int argc, char **argv)
case 'h': case 'h':
usage (stdout); usage (stdout);
return 0; return 0;
case 'k':
if (action == NoAction)
action = DeleteDef;
else
{
usage (stderr);
return 1;
}
break;
case 'm': case 'm':
if (action == NoAction) if (action == NoAction)
action = Modify; action = Modify;