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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <syslog.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/time.h>
#include <errno.h>
#include <rpcsvc/mount.h>
#include <sys/pathconf.h>
#include <sys/systeminfo.h>
#include <sys/utsname.h>
#include <signal.h>
#include <locale.h>
#include <unistd.h>
#include <thread.h>
#include <sharefs/share.h>
#include <sharefs/sharetab.h>
#include "../lib/sharetab.h"
#include "mountd.h"
static void freeexports(struct exportnode *);
static struct groupnode **newgroup(char *, struct groupnode **);
static struct exportnode **newexport(char *, struct groupnode *,
struct exportnode **);
static char *optlist[] = {
#define OPT_RO 0
SHOPT_RO,
#define OPT_RW 1
SHOPT_RW,
NULL
};
/*
* Send current export list to a client
*/
void
export(struct svc_req *rqstp)
{
SVCXPRT *transp;
struct exportnode *exportlist;
struct exportnode **tail;
struct groupnode *groups;
struct groupnode **grtail;
struct share *sh;
struct sh_list *shp;
char *gr, *p, *opts, *val, *lasts;
int export_to_everyone;
transp = rqstp->rq_xprt;
if (!svc_getargs(transp, xdr_void, NULL)) {
svcerr_decode(transp);
return;
}
check_sharetab();
exportlist = NULL;
tail = &exportlist;
(void) rw_rdlock(&sharetab_lock);
for (shp = share_list; shp; shp = shp->shl_next) {
groups = NULL;
grtail = &groups;
sh = shp->shl_sh;
/*
* Check for "ro" or "rw" list without argument values. This
* indicates export to everyone. Unfortunately, SunOS 4.x
* automounter uses this, and it is indicated indirectly with
* 'showmount -e'.
*
* If export_to_everyone is 1, then groups should be NULL to
* indicate export to everyone.
*/
opts = strdup(sh->sh_opts);
p = opts;
export_to_everyone = 0;
while (*p) {
switch (getsubopt(&p, optlist, &val)) {
case OPT_RO:
case OPT_RW:
if (val == NULL)
export_to_everyone = 1;
break;
}
}
free(opts);
if (export_to_everyone == 0) {
opts = strdup(sh->sh_opts);
p = opts;
/*
* Just concatenate all the hostnames/groups
* from the "ro" and "rw" lists for each flavor.
* This list is rather meaningless now, but
* that's what the protocol demands.
*/
while (*p) {
switch (getsubopt(&p, optlist, &val)) {
case OPT_RO:
case OPT_RW:
while ((gr = strtok_r(val, ":", &lasts))
!= NULL) {
val = NULL;
grtail = newgroup(gr, grtail);
}
break;
}
}
free(opts);
}
tail = newexport(sh->sh_path, groups, tail);
}
(void) rw_unlock(&sharetab_lock);
errno = 0;
if (!svc_sendreply(transp, xdr_exports, (char *)&exportlist))
log_cant_reply(transp);
freeexports(exportlist);
}
static void
freeexports(struct exportnode *ex)
{
struct groupnode *groups, *tmpgroups;
struct exportnode *tmpex;
while (ex) {
groups = ex->ex_groups;
while (groups) {
tmpgroups = groups->gr_next;
free(groups->gr_name);
free(groups);
groups = tmpgroups;
}
tmpex = ex->ex_next;
free(ex->ex_dir);
free(ex);
ex = tmpex;
}
}
static struct groupnode **
newgroup(char *grname, struct groupnode **tail)
{
struct groupnode *new;
char *newname;
new = exmalloc(sizeof (*new));
newname = exmalloc(strlen(grname) + 1);
(void) strcpy(newname, grname);
new->gr_name = newname;
new->gr_next = NULL;
*tail = new;
return (&new->gr_next);
}
static struct exportnode **
newexport(char *grname, struct groupnode *grplist, struct exportnode **tail)
{
struct exportnode *new;
char *newname;
new = exmalloc(sizeof (*new));
newname = exmalloc(strlen(grname) + 1);
(void) strcpy(newname, grname);
new->ex_dir = newname;
new->ex_groups = grplist;
new->ex_next = NULL;
*tail = new;
return (&new->ex_next);
}
|