1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
FSTYPE= smbfs
LIBPROG= lsacl
ROOTFS_PROG= $(LIBPROG)
include ../../Makefile.fstype
OBJS= $(LIBPROG).o
LDLIBS += -lsmbfs -lsec
# Hammerhead: GNU ld needs rpath-link to resolve mech_krb5.so.1 (transitive dep of libsmbfs)
LDFLAGS += -Wl,-rpath-link,$(ROOT)/usr/lib/gss
CFLAGS += $(CCVERBOSE)
CLOBBERFILES += $(LIBPROG)
all: $(ROOTFS_PROG)
install: $(ROOTLIBFSTYPEPROG)
clean:
$(RM) $(OBJS)
.KEEP_STATE:
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This is the smbfs/lsacl command.
* (just for testing - not installed)
*/
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/acl.h>
#include <sys/acl_impl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <aclutils.h>
#include <netsmb/smbfs_acl.h>
extern acl_t *acl_alloc(acl_type_t);
char *progname;
int Vflag;
uint32_t selector = DACL_SECURITY_INFORMATION |
OWNER_SECURITY_INFORMATION |
GROUP_SECURITY_INFORMATION;
void lsacl(char *);
void
usage(void)
{
fprintf(stderr, "Usage: %s [-v] file ...\n", progname);
exit(1);
}
int
main(int argc, char **argv)
{
int c;
progname = argv[0];
while ((c = getopt(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
Vflag++;
break;
default:
fprintf(stderr, "%s: bad option: %c\n",
progname, c);
usage();
break;
}
}
if (optind == argc)
usage();
for (; optind < argc; optind++)
lsacl(argv[optind]);
return (0);
}
void
lsacl(char *file)
{
struct i_ntsd *sd;
acl_t *acl;
uid_t uid;
gid_t gid;
int error, fd;
fd = open(file, O_RDONLY, 0);
if (fd < 0) {
perror(file);
exit(1);
}
/* First, get the SD in internal form. */
error = smbfs_acl_getsd(fd, selector, &sd);
(void) close(fd);
if (error) {
fprintf(stderr, "%s: getsd, %s\n",
progname, strerror(error));
exit(1);
}
if (Vflag) {
/*
* Print it first in Windows form. This way,
* if any of the conversion has problems,
* one can try mapping each SID by hand, i.e.:
* idmap show sid:S-1-xxx-yyy-zzz
*/
printf("CIFS security data:\n");
smbfs_acl_print_sd(stdout, sd);
printf("\n");
}
/*
* Convert the internal SD to a ZFS ACL.
*/
acl = acl_alloc(ACE_T);
error = smbfs_acl_sd2zfs(sd, acl, &uid, &gid);
if (error) {
fprintf(stderr, "%s: sd2zfs, %s\n",
progname, strerror(error));
exit(1);
}
smbfs_acl_free_sd(sd);
/*
* Print it as a ZFS-style ACL (ACE_T)
*/
printf("Solaris security data:\n");
if (uid == (uid_t)-1)
printf("owner: -1\n");
else
printf("owner: %u\n", uid);
if (gid == (gid_t)-1)
printf("group: -1\n");
else
printf("group: %u\n", gid);
acl_printacl(acl, 80, 1);
printf("\n");
acl_free(acl);
}
|