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]
24 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #pragma ident "%Z%%M% %I% %E% SMI"
39 #include "automount.h"
50 autofs_action_t
*action
,
54 struct mapent
*mapents
= NULL
;
56 struct autofs_rddir_cache
*rdcp
;
58 bool_t iswildcard
= FALSE
;
59 bool_t isrestricted
= hasrestrictopt(mapopts
);
60 char *stack
[STACKSIZ
];
61 char **stkptr
= stack
;
64 * Default action is for no work to be done by kernel AUTOFS.
66 *action
= AUTOFS_NONE
;
69 * Is there a cache for this map?
71 rw_rdlock(&autofs_rddir_cache_lock
);
72 err
= autofs_rddir_cache_lookup(mapname
, &rdcp
);
73 if (!err
&& rdcp
->full
) {
74 rw_unlock(&autofs_rddir_cache_lock
);
76 * Try to lock readdir cache entry for reading, if
77 * the entry can not be locked, then avoid blocking
78 * and go to the name service. I'm assuming it is
79 * faster to go to the name service than to wait for
80 * the cache to be populated.
82 if (rw_tryrdlock(&rdcp
->rwlock
) == 0) {
83 found
= (rddir_entry_lookup(key
, rdcp
->entp
) != NULL
);
84 rw_unlock(&rdcp
->rwlock
);
87 rw_unlock(&autofs_rddir_cache_lock
);
91 * release reference on cache entry
93 mutex_lock(&rdcp
->lock
);
95 assert(rdcp
->in_use
>= 0);
96 mutex_unlock(&rdcp
->lock
);
103 * entry not found in cache, try the name service now
107 /* initialize the stack of open files for this thread */
108 stack_op(INIT
, NULL
, stack
, &stkptr
);
110 err
= getmapent(key
, mapname
, &ml
, stack
, &stkptr
, &iswildcard
,
112 if (err
== 0) /* call parser w default mount_access = TRUE */
113 mapents
= parse_entry(key
, mapname
, mapopts
, &ml
,
114 subdir
, isdirect
, TRUE
);
117 * Now we indulge in a bit of hanky-panky.
118 * If the entry isn't found in the map and the
119 * name begins with an "=" then we assume that
120 * the name is an undocumented control message
121 * for the daemon. This is accessible only
124 if (mapents
== NULL
&& *action
== AUTOFS_NONE
) {
125 if (*key
== '=' && uid
== 0) {
126 if (isdigit(*(key
+1))) {
128 * If next character is a digit
129 * then set the trace level.
132 trace_prt(1, "Automountd: trace level = %d\n",
134 } else if (*(key
+1) == 'v') {
137 * toggle verbose mode.
140 trace_prt(1, "Automountd: verbose %s\n",
141 verbose
? "on" : "off");
150 * Each mapent in the list describes a mount to be done.
151 * Since I'm only doing a lookup, I only care whether a mapentry
152 * was found or not. The mount will be done on a later RPC to
155 if (mapents
== NULL
&& *action
== AUTOFS_NONE
)
159 free_mapent(mapents
);
161 if (*action
== AUTOFS_NONE
&& (iswildcard
== TRUE
)) {
162 *action
= AUTOFS_MOUNT_RQ
;
165 trace_prt(1, " do_lookup1: action=%d wildcard=%s error=%d\n",
166 *action
, iswildcard
? "TRUE" : "FALSE", err
);