kill tsol ("Trusted Solaris") aka TX ("Trusted Extensions")
[unleashed.git] / usr / src / cmd / fs.d / nfs / mountd / nfs_cmd.c
blobf01e686fbf83f96d19614b883c837eb4b65fe930
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
28 #include <rpc/rpc.h>
29 #include <netconfig.h>
30 #include <netdir.h>
31 #include <netinet/in.h>
32 #include <arpa/inet.h>
33 #include <netdb.h>
34 #include <nfs/nfssys.h>
35 #include <nfs/export.h>
36 #include <nfs/nfs_cmd.h>
37 #include <door.h>
38 #include <syslog.h>
39 #include <locale.h>
40 #include <strings.h>
41 #include <sharefs/share.h>
42 #include <stdlib.h>
43 #include "../lib/sharetab.h"
44 #include "mountd.h"
47 * The following codesets must match what is in libshare_nfs.c until we can
48 * request them from the kernel.
50 char *charopts[] = {
51 "euc-cn",
52 "euc-jp",
53 "euc-jpms",
54 "euc-kr",
55 "euc-tw",
56 "iso8859-1",
57 "iso8859-2",
58 "iso8859-5",
59 "iso8859-6",
60 "iso8859-7",
61 "iso8859-8",
62 "iso8859-9",
63 "iso8859-13",
64 "iso8859-15",
65 "koi8-r",
66 NULL
70 * nfscmd_err(dp, args, err)
71 * Return an error for the door call.
74 static void
75 nfscmd_err(door_desc_t *dp, nfscmd_arg_t *args, int err)
77 nfscmd_res_t res;
79 res.version = NFSCMD_VERS_1;
80 res.cmd = NFSCMD_ERROR;
81 res.error = err;
82 (void) door_return((char *)&res, sizeof (nfscmd_res_t), NULL, 0);
83 (void) door_return(NULL, 0, NULL, 0);
84 /* NOTREACHED */
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
93 * name if found.
96 static char *
97 charmap_search(struct netbuf *nbuf, char *opts)
99 char *copts;
100 char *next;
101 char *name;
102 char *result = NULL;
103 char *netid;
104 struct sockaddr *sa;
106 struct cln cln;
108 sa = (struct sockaddr *)nbuf->buf;
110 switch (sa->sa_family) {
111 case AF_INET:
112 netid = "tcp";
113 break;
114 case AF_INET6:
115 netid = "tcp6";
116 break;
117 default:
118 return (NULL);
121 copts = strdup(opts);
122 if (copts == NULL)
123 return (NULL);
125 cln_init_lazy(&cln, netid, nbuf);
127 next = copts;
128 while (*next != '\0') {
129 char *val;
130 name = next;
131 if (getsubopt(&next, charopts, &val) >= 0) {
132 char *cp;
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, '=');
139 if (cp != NULL)
140 *cp = '\0';
141 if (in_access_list(&cln, val) > 0) {
142 result = name;
143 break;
148 if (result != NULL)
149 result = strdup(result);
151 cln_fini(&cln);
152 free(copts);
154 return (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.
164 static void
165 nfscmd_charmap_lookup(door_desc_t *dp, nfscmd_arg_t *args)
167 nfscmd_res_t res;
168 struct netbuf nb;
169 struct sockaddr sa;
170 struct share *sh = NULL;
171 char *name;
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);
179 if (sh != NULL) {
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);
186 if (name != NULL) {
187 strcpy(res.result.charmap.codeset, name);
188 res.result.charmap.apply = B_TRUE;
189 res.error = NFSCMD_ERR_SUCCESS;
190 free(name);
191 } else {
192 res.result.charmap.apply = B_FALSE;
193 res.error = NFSCMD_ERR_NOTFOUND;
195 sharefree(sh);
196 } else {
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);
202 /* NOTREACHED */
206 * nfscmd_ver_1(door, args, size)
208 * Version 1 of the door command processor for nfs cmds.
211 static void
212 nfscmd_vers_1(door_desc_t *dp, nfscmd_arg_t *args, size_t size)
214 switch (args->cmd) {
215 case NFSCMD_CHARMAP_LOOKUP:
216 nfscmd_charmap_lookup(dp, args);
217 break;
218 default:
219 nfscmd_err(dp, args, NFSCMD_ERR_BADCMD);
220 break;
225 * nfscmd_func(cookie, dataptr, size, door, ndesc)
227 * The function called by the door thread for processing
228 * nfscmd type commands.
231 void
232 nfscmd_func(void *cookie, char *dataptr, size_t arg_size,
233 door_desc_t *dp, uint_t n_desc)
235 nfscmd_arg_t *args;
237 args = (nfscmd_arg_t *)dataptr;
239 switch (args->version) {
240 case NFSCMD_VERS_1:
241 nfscmd_vers_1(dp, args, arg_size);
242 break;
243 default:
244 syslog(LOG_ERR, gettext("Invalid nfscmd version"));
245 break;
248 (void) door_return((caddr_t)args, sizeof (nfscmd_res_t), NULL, 0);
249 (void) door_return(NULL, 0, NULL, 0);
250 /* NOTREACHED */