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 2015 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
27 #include <sys/types.h>
29 #include <netconfig.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
35 #include <nfs/nfssys.h>
36 #include <nfs/export.h>
37 #include <nfs/nfs_cmd.h>
42 #include <sharefs/share.h>
44 #include "../lib/sharetab.h"
48 * The following codesets must match what is in libshare_nfs.c until we can
49 * request them from the kernel.
71 * nfscmd_err(dp, args, err)
72 * Return an error for the door call.
76 nfscmd_err(door_desc_t
*dp
, nfscmd_arg_t
*args
, int err
)
80 res
.version
= NFSCMD_VERS_1
;
81 res
.cmd
= NFSCMD_ERROR
;
83 (void) door_return((char *)&res
, sizeof (nfscmd_res_t
), NULL
, 0);
84 (void) door_return(NULL
, 0, NULL
, 0);
90 * charmap_search(netbuf, opts)
92 * Check to see if the address in the netbuf is found in
93 * a character map spec in the opts option string. Returns the charset
98 charmap_search(struct netbuf
*nbuf
, char *opts
)
109 sa
= (struct sockaddr
*)nbuf
->buf
;
111 switch (sa
->sa_family
) {
122 copts
= strdup(opts
);
126 cln_init_lazy(&cln
, netid
, nbuf
);
129 while (*next
!= '\0') {
132 if (getsubopt(&next
, charopts
, &val
) >= 0) {
135 * name will have the whole opt and val the value. Set
136 * the '=' to '\0' and we have the charmap in name and
137 * the access list in val.
139 cp
= strchr(name
, '=');
142 if (in_access_list(&cln
, val
) > 0) {
150 result
= strdup(result
);
159 * nfscmd_charmap_lookup(door, args)
161 * Check to see if there is a translation requested for the path
162 * specified in the request. If there is, return the charset name.
166 nfscmd_charmap_lookup(door_desc_t
*dp
, nfscmd_arg_t
*args
)
171 struct share
*sh
= NULL
;
174 memset(&res
, '\0', sizeof (res
));
175 res
.version
= NFSCMD_VERS_1
;
176 res
.cmd
= NFSCMD_CHARMAP_LOOKUP
;
178 sh
= findentry(args
->arg
.charmap
.path
);
181 nb
.len
= nb
.maxlen
= sizeof (struct sockaddr
);
182 nb
.buf
= (char *)&sa
;
184 sa
= args
->arg
.charmap
.addr
;
186 name
= charmap_search(&nb
, sh
->sh_opts
);
188 strcpy(res
.result
.charmap
.codeset
, name
);
189 res
.result
.charmap
.apply
= B_TRUE
;
190 res
.error
= NFSCMD_ERR_SUCCESS
;
193 res
.result
.charmap
.apply
= B_FALSE
;
194 res
.error
= NFSCMD_ERR_NOTFOUND
;
198 res
.error
= NFSCMD_ERR_NOTFOUND
;
201 (void) door_return((char *)&res
, sizeof (nfscmd_res_t
), NULL
, 0);
202 (void) door_return(NULL
, 0, NULL
, 0);
207 * nfscmd_ver_1(door, args, size)
209 * Version 1 of the door command processor for nfs cmds.
213 nfscmd_vers_1(door_desc_t
*dp
, nfscmd_arg_t
*args
, size_t size
)
216 case NFSCMD_CHARMAP_LOOKUP
:
217 nfscmd_charmap_lookup(dp
, args
);
220 nfscmd_err(dp
, args
, NFSCMD_ERR_BADCMD
);
226 * nfscmd_func(cookie, dataptr, size, door, ndesc)
228 * The function called by the door thread for processing
229 * nfscmd type commands.
233 nfscmd_func(void *cookie
, char *dataptr
, size_t arg_size
,
234 door_desc_t
*dp
, uint_t n_desc
)
238 args
= (nfscmd_arg_t
*)dataptr
;
240 switch (args
->version
) {
242 nfscmd_vers_1(dp
, args
, arg_size
);
245 syslog(LOG_ERR
, gettext("Invalid nfscmd version"));
249 (void) door_return((caddr_t
)args
, sizeof (nfscmd_res_t
), NULL
, 0);
250 (void) door_return(NULL
, 0, NULL
, 0);