PERFORCE change 146200 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Tue Jul 29 12:02:07 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=146200
Change 146200 by trasz at trasz_traszkan on 2008/07/29 12:01:56
Implement removing entries by number.
Affected files ...
.. //depot/projects/soc2008/trasz_nfs4acl/TODO#19 edit
.. //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/remove.c#3 edit
.. //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/setfacl.c#4 edit
.. //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/setfacl.h#2 edit
Differences ...
==== //depot/projects/soc2008/trasz_nfs4acl/TODO#19 (text+ko) ====
@@ -1,7 +1,5 @@
Things to do, in no particular order:
-- Add the ability to remove ACE by number to setfacl(1),
-
- Add the ability to add ACE at a given position in ACL to setfacl(1),
- Add the ability to parse ACLs in verbose form, e.g. instead of
==== //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/remove.c#3 (text+ko) ====
@@ -87,6 +87,63 @@
return (0);
}
+int
+remove_by_number(uint entry_number, acl_t *prev_acl)
+{
+ acl_entry_t entry;
+ acl_t acl_new;
+ acl_tag_t tag;
+ int carried_error, entry_id;
+ uint i;
+
+ carried_error = 0;
+
+ if (acl_type == ACL_TYPE_ACCESS || acl_type == ACL_TYPE_NFS4)
+ acl_new = acl_dup(prev_acl[ACCESS_ACL]);
+ else
+ acl_new = acl_dup(prev_acl[DEFAULT_ACL]);
+ if (acl_new == NULL)
+ err(1, "acl_dup() failed");
+
+ 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, "acl_get_tag_type() failed");
+ if (tag == ACL_MASK)
+ have_mask++;
+ }
+
+ if (acl_delete_entry_np(acl_new, entry_number) == -1) {
+ carried_error++;
+ warnx("cannot remove non-existent acl entry");
+ }
+
+ if (acl_type == ACL_TYPE_ACCESS || acl_type == ACL_TYPE_NFS4) {
+ acl_free(prev_acl[ACCESS_ACL]);
+ prev_acl[ACCESS_ACL] = acl_new;
+ } else {
+ acl_free(prev_acl[DEFAULT_ACL]);
+ prev_acl[DEFAULT_ACL] = acl_new;
+ }
+
+ if (carried_error)
+ return (-1);
+
+ return (0);
+}
+
/*
* remove default entries
*/
==== //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/setfacl.c#4 (text+ko) ====
@@ -112,10 +112,11 @@
{
acl_t *acl, final_acl;
char filename[PATH_MAX];
- int local_error, carried_error, ch, i;
+ int local_error, carried_error, ch, i, entry_number;
struct sf_file *file;
struct sf_entry *entry;
const char *fn_dup;
+ char *end;
acl_type = ACL_TYPE_ACCESS;
carried_error = local_error = 0;
@@ -169,10 +170,18 @@
break;
case 'x':
entry = zmalloc(sizeof(struct sf_entry));
- entry->acl = acl_from_text(optarg);
- if (entry->acl == NULL)
- err(1, "%s", optarg);
- entry->op = OP_REMOVE_ACL;
+ entry_number = strtol(optarg, &end, 10);
+ if (end - optarg == (int)strlen(optarg)) {
+ if (entry_number < 0)
+ errx(1, "Entry number cannot be less than zero");
+ entry->entry_number = entry_number;
+ entry->op = OP_REMOVE_BY_NUMBER;
+ } else {
+ entry->acl = acl_from_text(optarg);
+ if (entry->acl == NULL)
+ err(1, "%s", optarg);
+ entry->op = OP_REMOVE_ACL;
+ }
TAILQ_INSERT_TAIL(&entrylist, entry, next);
break;
default:
@@ -247,6 +256,10 @@
local_error += remove_acl(entry->acl, acl);
need_mask = 1;
break;
+ case OP_REMOVE_BY_NUMBER:
+ local_error += remove_by_number(entry->entry_number, acl);
+ need_mask = 1;
+ break;
}
}
==== //depot/projects/soc2008/trasz_nfs4acl/bin/setfacl/setfacl.h#2 (text+ko) ====
@@ -38,6 +38,7 @@
#define OP_REMOVE_DEF 0x01 /* remove default acl's (-k) */
#define OP_REMOVE_EXT 0x02 /* remove extended acl's (-b) */
#define OP_REMOVE_ACL 0x03 /* remove acl's (-xX) */
+#define OP_REMOVE_BY_NUMBER 0x04 /* remove acl's (-xX) by acl entry number */
/* ACL types for the acl array */
#define ACCESS_ACL 0
@@ -47,6 +48,7 @@
struct sf_entry {
uint op;
acl_t acl;
+ uint entry_number;
TAILQ_ENTRY(sf_entry) next;
};
TAILQ_HEAD(, sf_entry) entrylist;
@@ -64,6 +66,7 @@
int merge_acl(acl_t acl, acl_t *prev_acl);
/* remove.c */
int remove_acl(acl_t acl, acl_t *prev_acl);
+int remove_by_number(uint entry_number, acl_t *prev_acl);
int remove_default(acl_t *prev_acl);
void remove_ext(acl_t *prev_acl);
/* mask.c */
More information about the p4-projects
mailing list