17568150aSgwr /* 27568150aSgwr * CDDL HEADER START 37568150aSgwr * 47568150aSgwr * The contents of this file are subject to the terms of the 57568150aSgwr * Common Development and Distribution License (the "License"). 67568150aSgwr * You may not use this file except in compliance with the License. 77568150aSgwr * 87568150aSgwr * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97568150aSgwr * or http://www.opensolaris.org/os/licensing. 107568150aSgwr * See the License for the specific language governing permissions 117568150aSgwr * and limitations under the License. 127568150aSgwr * 137568150aSgwr * When distributing Covered Code, include this CDDL HEADER in each 147568150aSgwr * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157568150aSgwr * If applicable, add the following below this CDDL HEADER, with the 167568150aSgwr * fields enclosed by brackets "[]" replaced with your own identifying 177568150aSgwr * information: Portions Copyright [yyyy] [name of copyright owner] 187568150aSgwr * 197568150aSgwr * CDDL HEADER END 207568150aSgwr */ 217568150aSgwr 227568150aSgwr /* 23*bd7c6f51SGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247568150aSgwr * Use is subject to license terms. 257568150aSgwr */ 267568150aSgwr 277568150aSgwr /* 287568150aSgwr * This is the smbfs/lsacl command. 297568150aSgwr * (just for testing - not installed) 307568150aSgwr */ 317568150aSgwr 327568150aSgwr #include <sys/types.h> 337568150aSgwr #include <sys/errno.h> 347568150aSgwr #include <sys/stat.h> 357568150aSgwr #include <sys/acl.h> 36*bd7c6f51SGordon Ross #include <sys/acl_impl.h> 377568150aSgwr 387568150aSgwr #include <fcntl.h> 397568150aSgwr #include <stdio.h> 407568150aSgwr #include <stdlib.h> 417568150aSgwr #include <unistd.h> 427568150aSgwr #include <string.h> 43*bd7c6f51SGordon Ross #include <aclutils.h> 447568150aSgwr 457568150aSgwr #include <netsmb/smbfs_acl.h> 467568150aSgwr 47*bd7c6f51SGordon Ross extern acl_t *acl_alloc(acl_type_t); 48*bd7c6f51SGordon Ross 497568150aSgwr char *progname; 50*bd7c6f51SGordon Ross int Vflag; 517568150aSgwr 52*bd7c6f51SGordon Ross uint32_t selector = DACL_SECURITY_INFORMATION | 53*bd7c6f51SGordon Ross OWNER_SECURITY_INFORMATION | 54*bd7c6f51SGordon Ross GROUP_SECURITY_INFORMATION; 557568150aSgwr 56*bd7c6f51SGordon Ross void lsacl(char *); 577568150aSgwr 587568150aSgwr void 597568150aSgwr usage(void) 607568150aSgwr { 61*bd7c6f51SGordon Ross fprintf(stderr, "Usage: %s [-v] file ...\n", progname); 627568150aSgwr exit(1); 637568150aSgwr } 647568150aSgwr 657568150aSgwr int 667568150aSgwr main(int argc, char **argv) 677568150aSgwr { 68*bd7c6f51SGordon Ross int c; 697568150aSgwr 707568150aSgwr progname = argv[0]; 717568150aSgwr 72*bd7c6f51SGordon Ross while ((c = getopt(argc, argv, "v")) != -1) { 73*bd7c6f51SGordon Ross switch (c) { 74*bd7c6f51SGordon Ross case 'v': 75*bd7c6f51SGordon Ross Vflag++; 76*bd7c6f51SGordon Ross break; 77*bd7c6f51SGordon Ross 78*bd7c6f51SGordon Ross badopt: 79*bd7c6f51SGordon Ross default: 80*bd7c6f51SGordon Ross fprintf(stderr, "%s: bad option: %c\n", 81*bd7c6f51SGordon Ross progname, c); 827568150aSgwr usage(); 83*bd7c6f51SGordon Ross break; 84*bd7c6f51SGordon Ross } 85*bd7c6f51SGordon Ross } 867568150aSgwr 87*bd7c6f51SGordon Ross if (optind == argc) 88*bd7c6f51SGordon Ross usage(); 89*bd7c6f51SGordon Ross for (; optind < argc; optind++) 90*bd7c6f51SGordon Ross lsacl(argv[optind]); 91*bd7c6f51SGordon Ross 92*bd7c6f51SGordon Ross return (0); 93*bd7c6f51SGordon Ross } 94*bd7c6f51SGordon Ross 95*bd7c6f51SGordon Ross void 96*bd7c6f51SGordon Ross lsacl(char *file) 97*bd7c6f51SGordon Ross { 98*bd7c6f51SGordon Ross struct i_ntsd *sd; 99*bd7c6f51SGordon Ross acl_t *acl; 100*bd7c6f51SGordon Ross uid_t uid; 101*bd7c6f51SGordon Ross gid_t gid; 102*bd7c6f51SGordon Ross int error, fd; 103*bd7c6f51SGordon Ross 104*bd7c6f51SGordon Ross fd = open(file, O_RDONLY, 0); 1057568150aSgwr if (fd < 0) { 106*bd7c6f51SGordon Ross perror(file); 1077568150aSgwr exit(1); 1087568150aSgwr } 1097568150aSgwr 110*bd7c6f51SGordon Ross /* First, get the SD in internal form. */ 111*bd7c6f51SGordon Ross error = smbfs_acl_getsd(fd, selector, &sd); 112*bd7c6f51SGordon Ross (void) close(fd); 113*bd7c6f51SGordon Ross 1147568150aSgwr if (error) { 115*bd7c6f51SGordon Ross fprintf(stderr, "%s: getsd, %s\n", 116*bd7c6f51SGordon Ross progname, strerror(error)); 1177568150aSgwr exit(1); 1187568150aSgwr } 1197568150aSgwr 120*bd7c6f51SGordon Ross if (Vflag) { 1217568150aSgwr /* 1227568150aSgwr * Print it first in Windows form. This way, 1237568150aSgwr * if any of the conversion has problems, 1247568150aSgwr * one can try mapping each SID by hand, i.e.: 1257568150aSgwr * idmap show sid:S-1-xxx-yyy-zzz 1267568150aSgwr */ 1277568150aSgwr printf("CIFS security data:\n"); 1287568150aSgwr smbfs_acl_print_sd(stdout, sd); 1297568150aSgwr printf("\n"); 130*bd7c6f51SGordon Ross } 1317568150aSgwr 1327568150aSgwr /* 133*bd7c6f51SGordon Ross * Convert the internal SD to a ZFS ACL. 1347568150aSgwr */ 135*bd7c6f51SGordon Ross acl = acl_alloc(ACE_T); 136*bd7c6f51SGordon Ross error = smbfs_acl_sd2zfs(sd, acl, &uid, &gid); 1377568150aSgwr if (error) { 138*bd7c6f51SGordon Ross fprintf(stderr, "%s: sd2zfs, %s\n", 139*bd7c6f51SGordon Ross progname, strerror(error)); 1407568150aSgwr exit(1); 1417568150aSgwr } 142*bd7c6f51SGordon Ross smbfs_acl_free_sd(sd); 143*bd7c6f51SGordon Ross 144*bd7c6f51SGordon Ross /* 145*bd7c6f51SGordon Ross * Print it as a ZFS-style ACL (ACE_T) 146*bd7c6f51SGordon Ross */ 1477568150aSgwr printf("Solaris security data:\n"); 1487568150aSgwr if (uid == (uid_t)-1) 1497568150aSgwr printf("owner: -1\n"); 1507568150aSgwr else 1517568150aSgwr printf("owner: %u\n", uid); 1527568150aSgwr if (gid == (gid_t)-1) 1537568150aSgwr printf("group: -1\n"); 1547568150aSgwr else 1557568150aSgwr printf("group: %u\n", gid); 156*bd7c6f51SGordon Ross acl_printacl(acl, 80, 1); 1577568150aSgwr printf("\n"); 1587568150aSgwr 159*bd7c6f51SGordon Ross acl_free(acl); 1607568150aSgwr } 161