7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * CDDL HEADER START
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * The contents of this file are subject to the terms of the
7568150a58e78021968b6c22bc28e9787b33496agwr * Common Development and Distribution License (the "License").
7568150a58e78021968b6c22bc28e9787b33496agwr * You may not use this file except in compliance with the License.
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7568150a58e78021968b6c22bc28e9787b33496agwr * or http://www.opensolaris.org/os/licensing.
7568150a58e78021968b6c22bc28e9787b33496agwr * See the License for the specific language governing permissions
7568150a58e78021968b6c22bc28e9787b33496agwr * and limitations under the License.
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * When distributing Covered Code, include this CDDL HEADER in each
7568150a58e78021968b6c22bc28e9787b33496agwr * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7568150a58e78021968b6c22bc28e9787b33496agwr * If applicable, add the following below this CDDL HEADER, with the
7568150a58e78021968b6c22bc28e9787b33496agwr * fields enclosed by brackets "[]" replaced with your own identifying
7568150a58e78021968b6c22bc28e9787b33496agwr * information: Portions Copyright [yyyy] [name of copyright owner]
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * CDDL HEADER END
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
7568150a58e78021968b6c22bc28e9787b33496agwr * Use is subject to license terms.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * This is the smbfs/lsacl command.
7568150a58e78021968b6c22bc28e9787b33496agwr * (just for testing - not installed)
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/types.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/errno.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/stat.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/acl.h>
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross#include <sys/acl_impl.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <fcntl.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <stdio.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <stdlib.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <unistd.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <string.h>
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross#include <aclutils.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <netsmb/smbfs_acl.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rossextern acl_t *acl_alloc(acl_type_t);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
7568150a58e78021968b6c22bc28e9787b33496agwrchar *progname;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rossint Vflag;
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rossuint32_t selector = DACL_SECURITY_INFORMATION |
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross OWNER_SECURITY_INFORMATION |
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross GROUP_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rossvoid lsacl(char *);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrvoid
7568150a58e78021968b6c22bc28e9787b33496agwrusage(void)
7568150a58e78021968b6c22bc28e9787b33496agwr{
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fprintf(stderr, "Usage: %s [-v] file ...\n", progname);
7568150a58e78021968b6c22bc28e9787b33496agwr exit(1);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrmain(int argc, char **argv)
7568150a58e78021968b6c22bc28e9787b33496agwr{
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross int c;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr progname = argv[0];
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross while ((c = getopt(argc, argv, "v")) != -1) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross switch (c) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross case 'v':
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross Vflag++;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross break;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross badopt:
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross default:
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fprintf(stderr, "%s: bad option: %c\n",
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross progname, c);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross usage();
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross break;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross }
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross }
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (optind == argc)
7568150a58e78021968b6c22bc28e9787b33496agwr usage();
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross for (; optind < argc; optind++)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross lsacl(argv[optind]);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross return (0);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross}
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rossvoid
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Rosslsacl(char *file)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross{
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross struct i_ntsd *sd;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross acl_t *acl;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross uid_t uid;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross gid_t gid;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross int error, fd;
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fd = open(file, O_RDONLY, 0);
7568150a58e78021968b6c22bc28e9787b33496agwr if (fd < 0) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross perror(file);
7568150a58e78021968b6c22bc28e9787b33496agwr exit(1);
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross /* First, get the SD in internal form. */
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross error = smbfs_acl_getsd(fd, selector, &sd);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross (void) close(fd);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
7568150a58e78021968b6c22bc28e9787b33496agwr if (error) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fprintf(stderr, "%s: getsd, %s\n",
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross progname, strerror(error));
7568150a58e78021968b6c22bc28e9787b33496agwr exit(1);
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (Vflag) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross /*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * Print it first in Windows form. This way,
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * if any of the conversion has problems,
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * one can try mapping each SID by hand, i.e.:
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * idmap show sid:S-1-xxx-yyy-zzz
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross */
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross printf("CIFS security data:\n");
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross smbfs_acl_print_sd(stdout, sd);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross printf("\n");
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * Convert the internal SD to a ZFS ACL.
7568150a58e78021968b6c22bc28e9787b33496agwr */
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross acl = acl_alloc(ACE_T);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross error = smbfs_acl_sd2zfs(sd, acl, &uid, &gid);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fprintf(stderr, "%s: sd2zfs, %s\n",
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross progname, strerror(error));
7568150a58e78021968b6c22bc28e9787b33496agwr exit(1);
7568150a58e78021968b6c22bc28e9787b33496agwr }
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross smbfs_acl_free_sd(sd);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross /*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * Print it as a ZFS-style ACL (ACE_T)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross */
7568150a58e78021968b6c22bc28e9787b33496agwr printf("Solaris security data:\n");
7568150a58e78021968b6c22bc28e9787b33496agwr if (uid == (uid_t)-1)
7568150a58e78021968b6c22bc28e9787b33496agwr printf("owner: -1\n");
7568150a58e78021968b6c22bc28e9787b33496agwr else
7568150a58e78021968b6c22bc28e9787b33496agwr printf("owner: %u\n", uid);
7568150a58e78021968b6c22bc28e9787b33496agwr if (gid == (gid_t)-1)
7568150a58e78021968b6c22bc28e9787b33496agwr printf("group: -1\n");
7568150a58e78021968b6c22bc28e9787b33496agwr else
7568150a58e78021968b6c22bc28e9787b33496agwr printf("group: %u\n", gid);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross acl_printacl(acl, 80, 1);
7568150a58e78021968b6c22bc28e9787b33496agwr printf("\n");
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross acl_free(acl);
7568150a58e78021968b6c22bc28e9787b33496agwr}