From owner-p4-projects@FreeBSD.ORG Tue Jul 29 12:02:06 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B9DCE106567A; Tue, 29 Jul 2008 12:02:06 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7A2501065679 for ; Tue, 29 Jul 2008 12:02:06 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6AE8D8FC34 for ; Tue, 29 Jul 2008 12:02:06 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m6TC26T9005712 for ; Tue, 29 Jul 2008 12:02:06 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6TC26a9005710 for perforce@freebsd.org; Tue, 29 Jul 2008 12:02:06 GMT (envelope-from trasz@freebsd.org) Date: Tue, 29 Jul 2008 12:02:06 GMT Message-Id: <200807291202.m6TC26a9005710@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Cc: Subject: PERFORCE change 146200 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jul 2008 12:02:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=146200 Change 146200 by trasz@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 */