Print this page
12288 getfacl and setfacl could stand improvement


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #ifndef lint
  29 static char sccsid[] = "%Z%%M%  %I%     %E% SMI";
  30 #endif
  31 
  32 /*
  33  * getfacl [-ad] file ...
  34  * This command displays discretionary information for a file or files.
  35  * display format:
  36  *      # file: filename
  37  *      # owner: uid
  38  *      # group: gid
  39  *      user::perm
  40  *      user:uid:perm
  41  *      group::perm
  42  *      group:gid:perm
  43  *      mask:perm
  44  *      other:perm
  45  *      default:user::perm
  46  *      default:user:uid:perm
  47  *      default:group::perm
  48  *      default:group:gid:perm
  49  *      default:mask:perm
  50  *      default:other:perm
  51  */


  56 #include <grp.h>
  57 #include <locale.h>
  58 #include <sys/acl.h>
  59 #include <errno.h>
  60 
  61 static char     *pruname(uid_t);
  62 static char     *prgname(gid_t);
  63 static char     *display(int);
  64 static void     usage();
  65 
  66 
  67 int
  68 main(int argc, char *argv[])
  69 {
  70         int             c;
  71         int             aflag = 0;
  72         int             dflag = 0;
  73         int             errflag = 0;
  74         int             savecnt;
  75         int             aclcnt;
  76         int             mask;
  77         aclent_t        *aclp;
  78         aclent_t        *tp;
  79         char            *permp;
  80 
  81         (void) setlocale(LC_ALL, "");
  82         (void) textdomain(TEXT_DOMAIN);
  83 
  84         if (argc < 2)
  85                 usage();
  86 
  87         while ((c = getopt(argc, argv, "ad")) != EOF) {
  88                 switch (c) {
  89                 case 'a':
  90                         aflag++;
  91                         break;
  92                 case 'd':
  93                         dflag++;
  94                         break;
  95                 case '?':
  96                         errflag++;


  99         }
 100         if (errflag)
 101                 usage();
 102 
 103         if (optind >= argc)
 104                 usage();
 105 
 106         for (; optind < argc; optind++) {
 107                 register char *filep;
 108 
 109                 filep = argv[optind];
 110 
 111                 /* Get ACL info of the files */
 112                 errno = 0;
 113                 if ((aclcnt = acl(filep, GETACLCNT, 0, NULL)) < 0) {
 114                         if (errno == ENOSYS) {
 115                                 (void) fprintf(stderr,
 116                                     gettext("File system doesn't support "
 117                                     "aclent_t style ACL's.\n"
 118                                     "See acl(5) for more information on "
 119                                     "Solaris ACL support.\n"));
 120                                 exit(2);
 121                         }
 122                         perror(filep);
 123                         exit(2);
 124                 }
 125                 if (aclcnt < MIN_ACL_ENTRIES) {
 126                         (void) fprintf(stderr,
 127                             gettext("%d: acl count too small from %s\n"),
 128                             aclcnt, filep);
 129                         exit(2);
 130                 }
 131 
 132                 if ((aclp = (aclent_t *)malloc(sizeof (aclent_t) * aclcnt))
 133                     == NULL) {
 134                         (void) fprintf(stderr,
 135                             gettext("Insufficient memory\n"));
 136                         exit(1);
 137                 }
 138 
 139                 errno = 0;




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2020 Peter Tribble.
  25  */
  26 






  27 /*
  28  * getfacl [-ad] file ...
  29  * This command displays discretionary information for a file or files.
  30  * display format:
  31  *      # file: filename
  32  *      # owner: uid
  33  *      # group: gid
  34  *      user::perm
  35  *      user:uid:perm
  36  *      group::perm
  37  *      group:gid:perm
  38  *      mask:perm
  39  *      other:perm
  40  *      default:user::perm
  41  *      default:user:uid:perm
  42  *      default:group::perm
  43  *      default:group:gid:perm
  44  *      default:mask:perm
  45  *      default:other:perm
  46  */


  51 #include <grp.h>
  52 #include <locale.h>
  53 #include <sys/acl.h>
  54 #include <errno.h>
  55 
  56 static char     *pruname(uid_t);
  57 static char     *prgname(gid_t);
  58 static char     *display(int);
  59 static void     usage();
  60 
  61 
  62 int
  63 main(int argc, char *argv[])
  64 {
  65         int             c;
  66         int             aflag = 0;
  67         int             dflag = 0;
  68         int             errflag = 0;
  69         int             savecnt;
  70         int             aclcnt;
  71         int             mask = 0;
  72         aclent_t        *aclp;
  73         aclent_t        *tp;
  74         char            *permp;
  75 
  76         (void) setlocale(LC_ALL, "");
  77         (void) textdomain(TEXT_DOMAIN);
  78 
  79         if (argc < 2)
  80                 usage();
  81 
  82         while ((c = getopt(argc, argv, "ad")) != EOF) {
  83                 switch (c) {
  84                 case 'a':
  85                         aflag++;
  86                         break;
  87                 case 'd':
  88                         dflag++;
  89                         break;
  90                 case '?':
  91                         errflag++;


  94         }
  95         if (errflag)
  96                 usage();
  97 
  98         if (optind >= argc)
  99                 usage();
 100 
 101         for (; optind < argc; optind++) {
 102                 register char *filep;
 103 
 104                 filep = argv[optind];
 105 
 106                 /* Get ACL info of the files */
 107                 errno = 0;
 108                 if ((aclcnt = acl(filep, GETACLCNT, 0, NULL)) < 0) {
 109                         if (errno == ENOSYS) {
 110                                 (void) fprintf(stderr,
 111                                     gettext("File system doesn't support "
 112                                     "aclent_t style ACL's.\n"
 113                                     "See acl(5) for more information on "
 114                                     "POSIX-draft ACL support.\n"));
 115                                 exit(2);
 116                         }
 117                         perror(filep);
 118                         exit(2);
 119                 }
 120                 if (aclcnt < MIN_ACL_ENTRIES) {
 121                         (void) fprintf(stderr,
 122                             gettext("%d: acl count too small from %s\n"),
 123                             aclcnt, filep);
 124                         exit(2);
 125                 }
 126 
 127                 if ((aclp = (aclent_t *)malloc(sizeof (aclent_t) * aclcnt))
 128                     == NULL) {
 129                         (void) fprintf(stderr,
 130                             gettext("Insufficient memory\n"));
 131                         exit(1);
 132                 }
 133 
 134                 errno = 0;