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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/types.h>
31 #include <rpcsvc/nlm_prot.h>
32 #include <sys/utsname.h>
38 #include <nfs/nfssys.h>
39 extern int _nfssys(enum nfssys_op
, void *);
42 * This function is added to detect compatibility problem with SunOS4.x.
43 * The compatibility problem exists when fshost cannot decode the request
44 * arguments for NLM_GRANTED procedure.
45 * Only in this case we use local locking.
46 * In any other case we use fshost's lockd for remote file locking.
47 * Return value: 1 if we should use local locking, 0 if not.
50 remote_lock(char *fshost
, caddr_t fh
)
52 nlm_testargs rlm_args
;
54 struct timeval timeout
= { 5, 0};
56 enum clnt_stat rpc_stat
;
59 (void) memset((char *)&rlm_args
, 0, sizeof (nlm_testargs
));
60 (void) memset((char *)&rlm_res
, 0, sizeof (nlm_res
));
62 * Assign the hostname and the file handle for the
63 * NLM_GRANTED request below. If for some reason the uname call fails,
64 * list the server as the caller so that caller_name has some
67 if (uname(&myid
) == -1) {
68 rlm_args
.alock
.caller_name
= fshost
;
70 rlm_args
.alock
.caller_name
= myid
.nodename
;
72 rlm_args
.alock
.fh
.n_len
= sizeof (fhandle_t
);
73 rlm_args
.alock
.fh
.n_bytes
= fh
;
75 cl
= clnt_create(fshost
, NLM_PROG
, NLM_VERS
, "datagram_v");
79 rpc_stat
= clnt_call(cl
, NLM_GRANTED
,
80 xdr_nlm_testargs
, (caddr_t
)&rlm_args
,
81 xdr_nlm_res
, (caddr_t
)&rlm_res
, timeout
);
84 return (rpc_stat
== RPC_CANTDECODEARGS
);
87 #define fromhex(c) ((c >= '0' && c <= '9') ? (c - '0') : \
88 ((c >= 'A' && c <= 'F') ? (c - 'A' + 10) :\
89 ((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : 0)))
92 * The implementation of URLparse guarantees that the final string will
93 * fit in the original one. Replaces '%' occurrences followed by 2 characters
94 * with its corresponding hexadecimal character.
106 *q
= fromhex(*p
) * 16;
120 * Convert from URL syntax to host:path syntax.
123 convert_special(char **specialp
, char *host
, char *oldpath
, char *newpath
,
133 * Rebuild the URL. This is necessary because parse replica
134 * assumes that nfs: is the host name.
136 url
= malloc(strlen("nfs:") + strlen(oldpath
) + 1);
142 strcat(url
, oldpath
);
145 * If we haven't done any conversion yet, allocate a buffer for it.
147 if (*specialp
== NULL
) {
148 newspec
= *specialp
= strdup(cur_special
);
149 if (newspec
== NULL
) {
159 * Now find the first occurence of the URL in the special string.
161 p
= strstr(newspec
, url
);
172 * Overwrite the URL in the special.
174 * Begin with the host name.
178 * Sine URL's take more room than host:path, there is
179 * no way we should hit a null byte in the original special.
198 * Add the : separator.
204 * Now over write into special the path portion of host:path in
223 * Now shift the rest of original special into the gap created
224 * by replacing nfs://host[:port]/path with host:path.
226 p2
= p
+ strlen(url
);
249 * Solaris autofs configuration file location
251 #define AUTOFSADMIN "/etc/default/autofs"
252 #define AUTOFS_MOUNT_TIMEOUT 600 /* default min time mount will */
255 set_nfsv4_ephemeral_mount_to(void)
259 uint_t mount_to
= AUTOFS_MOUNT_TIMEOUT
;
262 * Get the value from /etc/default/autofs
264 if ((defopen(AUTOFSADMIN
)) == 0) {
265 if ((defval
= defread("AUTOMOUNT_TIMEOUT=")) != NULL
) {
267 mount_to
= strtoul(defval
, (char **)NULL
, 10);
269 mount_to
= AUTOFS_MOUNT_TIMEOUT
;
272 /* close defaults file */
276 (void) _nfssys(NFS4_EPHEMERAL_MOUNT_TO
, &mount_to
);