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.
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.
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]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
34 #include <sys/param.h>
39 #include <rpcsvc/mount.h>
40 #include <sys/pathconf.h>
41 #include <sys/systeminfo.h>
42 #include <sys/utsname.h>
47 #include <sharefs/share.h>
48 #include <sharefs/sharetab.h>
49 #include "../lib/sharetab.h"
52 static void freeexports(struct exportnode
*);
53 static struct groupnode
**newgroup(char *, struct groupnode
**);
54 static struct exportnode
**newexport(char *, struct groupnode
*,
55 struct exportnode
**);
57 static char *optlist
[] = {
66 * Send current export list to a client
69 export(struct svc_req
*rqstp
)
72 struct exportnode
*exportlist
;
73 struct exportnode
**tail
;
74 struct groupnode
*groups
;
75 struct groupnode
**grtail
;
78 char *gr
, *p
, *opts
, *val
, *lasts
;
80 int export_to_everyone
;
82 transp
= rqstp
->rq_xprt
;
83 if (!svc_getargs(transp
, xdr_void
, NULL
)) {
84 svcerr_decode(transp
);
93 (void) rw_rdlock(&sharetab_lock
);
95 for (shp
= share_list
; shp
; shp
= shp
->shl_next
) {
103 * Check for "ro" or "rw" list without argument values. This
104 * indicates export to everyone. Unfortunately, SunOS 4.x
105 * automounter uses this, and it is indicated indirectly with
108 * If export_to_everyone is 1, then groups should be NULL to
109 * indicate export to everyone.
112 opts
= strdup(sh
->sh_opts
);
116 export_to_everyone
= 0;
118 switch (getsubopt(&p
, optlist
, &val
)) {
122 export_to_everyone
= 1;
129 if (export_to_everyone
== 0) {
131 opts
= strdup(sh
->sh_opts
);
135 * Just concatenate all the hostnames/groups
136 * from the "ro" and "rw" lists for each flavor.
137 * This list is rather meaningless now, but
138 * that's what the protocol demands.
141 switch (getsubopt(&p
, optlist
, &val
)) {
145 while ((gr
= strtok_r(val
, ":", &lasts
))
148 grtail
= newgroup(gr
, grtail
);
156 tail
= newexport(sh
->sh_path
, groups
, tail
);
159 (void) rw_unlock(&sharetab_lock
);
162 if (!svc_sendreply(transp
, xdr_exports
, (char *)&exportlist
))
163 log_cant_reply(transp
);
165 freeexports(exportlist
);
170 freeexports(struct exportnode
*ex
)
172 struct groupnode
*groups
, *tmpgroups
;
173 struct exportnode
*tmpex
;
176 groups
= ex
->ex_groups
;
178 tmpgroups
= groups
->gr_next
;
179 free(groups
->gr_name
);
191 static struct groupnode
**
192 newgroup(char *grname
, struct groupnode
**tail
)
194 struct groupnode
*new;
197 new = exmalloc(sizeof (*new));
198 newname
= exmalloc(strlen(grname
) + 1);
199 (void) strcpy(newname
, grname
);
201 new->gr_name
= newname
;
204 return (&new->gr_next
);
208 static struct exportnode
**
209 newexport(char *grname
, struct groupnode
*grplist
, struct exportnode
**tail
)
211 struct exportnode
*new;
214 new = exmalloc(sizeof (*new));
215 newname
= exmalloc(strlen(grname
) + 1);
216 (void) strcpy(newname
, grname
);
218 new->ex_dir
= newname
;
219 new->ex_groups
= grplist
;
222 return (&new->ex_next
);