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>
34 #include <nfs/nfssys.h>
35 #include <nfs/export.h>
36 #include <nfs/nfs_cmd.h>
41 #include <sharefs/share.h>
43 #include "../lib/sharetab.h"
47 * The following codesets must match what is in libshare_nfs.c until we can
48 * request them from the kernel.
70 * nfscmd_err(dp, args, err)
71 * Return an error for the door call.
75 nfscmd_err(door_desc_t
*dp
, nfscmd_arg_t
*args
, int err
)
79 res
.version
= NFSCMD_VERS_1
;
80 res
.cmd
= NFSCMD_ERROR
;
82 (void) door_return((char *)&res
, sizeof (nfscmd_res_t
), NULL
, 0);
83 (void) door_return(NULL
, 0, NULL
, 0);
89 * charmap_search(netbuf, opts)
91 * Check to see if the address in the netbuf is found in
92 * a character map spec in the opts option string. Returns the charset
97 charmap_search(struct netbuf
*nbuf
, char *opts
)
108 sa
= (struct sockaddr
*)nbuf
->buf
;
110 switch (sa
->sa_family
) {
121 copts
= strdup(opts
);
125 cln_init_lazy(&cln
, netid
, nbuf
);
128 while (*next
!= '\0') {
131 if (getsubopt(&next
, charopts
, &val
) >= 0) {
134 * name will have the whole opt and val the value. Set
135 * the '=' to '\0' and we have the charmap in name and
136 * the access list in val.
138 cp
= strchr(name
, '=');
141 if (in_access_list(&cln
, val
) > 0) {
149 result
= strdup(result
);
158 * nfscmd_charmap_lookup(door, args)
160 * Check to see if there is a translation requested for the path
161 * specified in the request. If there is, return the charset name.
165 nfscmd_charmap_lookup(door_desc_t
*dp
, nfscmd_arg_t
*args
)
170 struct share
*sh
= NULL
;
173 memset(&res
, '\0', sizeof (res
));
174 res
.version
= NFSCMD_VERS_1
;
175 res
.cmd
= NFSCMD_CHARMAP_LOOKUP
;
177 sh
= findentry(args
->arg
.charmap
.path
);
180 nb
.len
= nb
.maxlen
= sizeof (struct sockaddr
);
181 nb
.buf
= (char *)&sa
;
183 sa
= args
->arg
.charmap
.addr
;
185 name
= charmap_search(&nb
, sh
->sh_opts
);
187 strcpy(res
.result
.charmap
.codeset
, name
);
188 res
.result
.charmap
.apply
= B_TRUE
;
189 res
.error
= NFSCMD_ERR_SUCCESS
;
192 res
.result
.charmap
.apply
= B_FALSE
;
193 res
.error
= NFSCMD_ERR_NOTFOUND
;
197 res
.error
= NFSCMD_ERR_NOTFOUND
;
200 (void) door_return((char *)&res
, sizeof (nfscmd_res_t
), NULL
, 0);
201 (void) door_return(NULL
, 0, NULL
, 0);
206 * nfscmd_ver_1(door, args, size)
208 * Version 1 of the door command processor for nfs cmds.
212 nfscmd_vers_1(door_desc_t
*dp
, nfscmd_arg_t
*args
, size_t size
)
215 case NFSCMD_CHARMAP_LOOKUP
:
216 nfscmd_charmap_lookup(dp
, args
);
219 nfscmd_err(dp
, args
, NFSCMD_ERR_BADCMD
);
225 * nfscmd_func(cookie, dataptr, size, door, ndesc)
227 * The function called by the door thread for processing
228 * nfscmd type commands.
232 nfscmd_func(void *cookie
, char *dataptr
, size_t arg_size
,
233 door_desc_t
*dp
, uint_t n_desc
)
237 args
= (nfscmd_arg_t
*)dataptr
;
239 switch (args
->version
) {
241 nfscmd_vers_1(dp
, args
, arg_size
);
244 syslog(LOG_ERR
, gettext("Invalid nfscmd version"));
248 (void) door_return((caddr_t
)args
, sizeof (nfscmd_res_t
), NULL
, 0);
249 (void) door_return(NULL
, 0, NULL
, 0);