Print this page
12288 getfacl and setfacl could stand improvement

*** 18,27 **** --- 18,28 ---- * * CDDL HEADER END */ /* * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2020 Peter Tribble. */ /* * setfacl [-r] -f aclfile file ... * setfacl [-r] -d acl_entries file ...
*** 39,48 **** --- 40,50 ---- #include <locale.h> #include <sys/acl.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> + #include <ctype.h> #define ADD 1 #define MODIFY 2 #define DELETE 3 #define SET 4
*** 68,78 **** int sflag = 0; int fflag = 0; int errflag = 0; int aclcnt; /* used by -m -d */ aclent_t *aclp; /* used by -m -d */ ! char *aclfilep; /* acl file argument */ char *d_entryp = NULL; /* ptr to del entry list */ char *m_entryp = NULL; /* ptr to mod entry list */ char *s_entryp = NULL; /* ptr to set entry list */ char *work_dp = NULL; /* working ptrs for the above */ char *work_mp = NULL; --- 70,80 ---- int sflag = 0; int fflag = 0; int errflag = 0; int aclcnt; /* used by -m -d */ aclent_t *aclp; /* used by -m -d */ ! char *aclfilep = NULL; /* acl file argument */ char *d_entryp = NULL; /* ptr to del entry list */ char *m_entryp = NULL; /* ptr to mod entry list */ char *s_entryp = NULL; /* ptr to set entry list */ char *work_dp = NULL; /* working ptrs for the above */ char *work_mp = NULL;
*** 197,207 **** if (errno == ENOSYS) { (void) fprintf(stderr, gettext("File system doesn't support aclent_t " "style ACL's.\n" "See acl(5) for more information on" ! " ACL styles support by Solaris.\n")); return (-1); } (void) fprintf(stderr, gettext("%s: failed to get acl count\n"), filep); perror("get acl count error"); --- 199,209 ---- if (errno == ENOSYS) { (void) fprintf(stderr, gettext("File system doesn't support aclent_t " "style ACL's.\n" "See acl(5) for more information on" ! "POSIX-draft ACL support.\n")); return (-1); } (void) fprintf(stderr, gettext("%s: failed to get acl count\n"), filep); perror("get acl count error");
*** 237,248 **** */ static int mod_entries(aclent_t *aclp, int cnt, char *modp, char *delp, char *fnamep, int rfg) { - int rc; /* return code */ - /* modify and add: from -m option */ if (parse_entry_list(&aclp, &cnt, modp, MODIFY) == -1) return (-1); /* deletion: from -d option */ --- 239,248 ----
*** 340,350 **** * Finally it sets ACL to the file (fnamep). */ static int set_online_entries(char *setp, char *fnamep, int rflag) { - char *commap; aclent_t *aclp; int aclcnt = 0; if (parse_entry_list(&aclp, &aclcnt, setp, SET) == -1) return (-1); --- 340,349 ----
*** 412,432 **** int is_obj; if (entryp == NULL) return (0); - if (*cntp > 1) - new_aclp = (aclent_t *)realloc(*aclpp, - sizeof (aclent_t) * (*cntp)); - else - new_aclp = (aclent_t *) malloc(sizeof (aclent_t) * (*cntp)); - if (new_aclp == NULL) { - fprintf(stderr, - gettext("Insufficient memory for acl %d\n"), *cntp); - return (-1); - } - tmpacl.a_id = 0; /* id field needs to be initialized */ if (entryp[0] == 'u') tmpacl.a_id = getuid(); /* id field for user */ if (entryp[0] == 'g') tmpacl.a_id = getgid(); /* id field for group */ --- 411,420 ----
*** 440,449 **** --- 428,448 ---- (tmpacl.a_type == CLASS_OBJ) || (tmpacl.a_type == DEF_USER_OBJ) || (tmpacl.a_type == DEF_GROUP_OBJ) || (tmpacl.a_type == DEF_OTHER_OBJ)); + if (*cntp > 1) + new_aclp = (aclent_t *)realloc(*aclpp, + sizeof (aclent_t) * (*cntp)); + else + new_aclp = (aclent_t *) malloc(sizeof (aclent_t) * (*cntp)); + if (new_aclp == NULL) { + fprintf(stderr, + gettext("Insufficient memory for acl %d\n"), *cntp); + return (-1); + } + cur_cnt = *cntp - 1; switch (mode) { case MODIFY: /* and add */ for (taclp = new_aclp; cur_cnt-- > 0; taclp++) { if (taclp->a_type == tmpacl.a_type &&