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 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 #include <sys/types.h>
33 #include <sys/errno.h>
35 #include <libnvpair.h>
38 #include <rp_plugin.h>
40 #include <uuid/uuid.h>
41 #include <rpc/types.h>
45 #include <rpc/rpc_msg.h>
46 #include <sys/param.h>
48 #include <rpcsvc/nfs4_prot.h>
51 * str_to_utf8 - converts a null-terminated C string to a utf8 string
54 str_to_utf8(char *nm
, utf8string
*str
)
61 if (nm
== NULL
|| *nm
== '\0') {
62 str
->utf8string_len
= 0;
63 str
->utf8string_val
= NULL
;
69 str
->utf8string_val
= malloc(len
);
70 if (str
->utf8string_val
== NULL
) {
71 str
->utf8string_len
= 0;
74 str
->utf8string_len
= len
;
75 bcopy(nm
, str
->utf8string_val
, len
);
81 * Converts a utf8 string to a C string.
82 * kmem_allocs a new string if not supplied
85 utf8_to_str(utf8string
*str
, uint_t
*lenp
, char *s
)
95 u8p
= str
->utf8string_val
;
96 len
= str
->utf8string_len
;
97 if (len
<= 0 || u8p
== NULL
) {
105 sp
= malloc(len
+ 1);
110 * At least check for embedded nulls
112 for (i
= 0; i
< len
; i
++) {
114 if (u8p
[i
] == '\0') {
127 print_referral_summary(fs_locations4
*fsl
)
139 for (i
= 0; i
< fsl
->locations
.locations_len
; i
++) {
142 fs
= &fsl
->locations
.locations_val
[i
];
143 for (j
= 0; j
< fs
->server
.server_len
; j
++) {
144 s
= utf8_to_str(&fs
->server
.server_val
[j
], &l
, NULL
);
147 printf("%s", s
? s
: "");
151 for (j
= 0; j
< fs
->rootpath
.pathname4_len
; j
++) {
152 s
= utf8_to_str(&fs
->rootpath
.pathname4_val
[j
],
154 printf("/%s", s
? s
: "");
157 if (fs
->rootpath
.pathname4_len
== 0)
164 * There is a kernel copy of this routine in nfs4_srv.c.
165 * Changes should be kept in sync.
168 nfs4_create_components(char *path
, component4
*comp4
)
170 int slen
, plen
, ncomp
;
171 char *ori_path
, *nxtc
, buf
[MAXNAMELEN
];
176 plen
= strlen(path
) + 1; /* include the terminator */
180 /* count number of components in the path */
181 for (nxtc
= path
; nxtc
< ori_path
+ plen
; nxtc
++) {
182 if (*nxtc
== '/' || *nxtc
== '\0' || *nxtc
== '\n') {
183 if ((slen
= nxtc
- path
) == 0) {
189 bcopy(path
, buf
, slen
);
191 if (str_to_utf8(buf
, &comp4
[ncomp
]) == NULL
)
195 ncomp
++; /* 1 valid component */
198 if (*nxtc
== '\0' || *nxtc
== '\n')
206 * There is a kernel copy of this routine in nfs4_srv.c.
207 * Changes should be kept in sync.
210 make_pathname4(char *path
, pathname4
*pathname
)
215 if (pathname
== NULL
)
219 pathname
->pathname4_val
= NULL
;
220 pathname
->pathname4_len
= 0;
224 /* count number of components to alloc buffer */
225 if ((ncomp
= nfs4_create_components(path
, NULL
)) == 0) {
226 pathname
->pathname4_val
= NULL
;
227 pathname
->pathname4_len
= 0;
230 comp4
= calloc(ncomp
* sizeof (component4
), 1);
232 pathname
->pathname4_val
= NULL
;
233 pathname
->pathname4_len
= 0;
237 /* copy components into allocated buffer */
238 ncomp
= nfs4_create_components(path
, comp4
);
240 pathname
->pathname4_val
= comp4
;
241 pathname
->pathname4_len
= ncomp
;
247 xdr_component4(register XDR
*xdrs
, component4
*objp
)
250 if (!xdr_utf8string(xdrs
, objp
))
256 xdr_utf8string(register XDR
*xdrs
, utf8string
*objp
)
259 if (xdrs
->x_op
!= XDR_FREE
)
260 return (xdr_bytes(xdrs
, (char **)&objp
->utf8string_val
,
261 (uint_t
*)&objp
->utf8string_len
, NFS4_MAX_UTF8STRING
));
266 xdr_pathname4(register XDR
*xdrs
, pathname4
*objp
)
269 if (!xdr_array(xdrs
, (char **)&objp
->pathname4_val
,
270 (uint_t
*)&objp
->pathname4_len
, NFS4_MAX_PATHNAME4
,
271 sizeof (component4
), (xdrproc_t
)xdr_component4
))
277 xdr_fs_location4(register XDR
*xdrs
, fs_location4
*objp
)
280 if (xdrs
->x_op
== XDR_DECODE
) {
281 objp
->server
.server_val
= NULL
;
282 objp
->rootpath
.pathname4_val
= NULL
;
284 if (!xdr_array(xdrs
, (char **)&objp
->server
.server_val
,
285 (uint_t
*)&objp
->server
.server_len
, ~0,
286 sizeof (utf8string
), (xdrproc_t
)xdr_utf8string
))
288 if (!xdr_pathname4(xdrs
, &objp
->rootpath
))
294 xdr_fs_locations4(register XDR
*xdrs
, fs_locations4
*objp
)
297 if (xdrs
->x_op
== XDR_DECODE
) {
298 objp
->fs_root
.pathname4_len
= 0;
299 objp
->fs_root
.pathname4_val
= NULL
;
300 objp
->locations
.locations_val
= NULL
;
302 if (!xdr_pathname4(xdrs
, &objp
->fs_root
))
304 if (!xdr_array(xdrs
, (char **)&objp
->locations
.locations_val
,
305 (uint_t
*)&objp
->locations
.locations_len
, ~0,
306 sizeof (fs_location4
), (xdrproc_t
)xdr_fs_location4
))