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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/cpuvar.h>
44 #include <sys/errno.h>
45 #include <sys/cred.h>
46 #include <sys/user.h>
47 #include <sys/uio.h>
48 #include <sys/vfs.h>
49 #include <sys/vnode.h>
50 #include <sys/pathname.h>
51 #include <sys/proc.h>
52 #include <sys/vtrace.h>
53 #include <sys/sysmacros.h>
54 #include <sys/debug.h>
55 #include <sys/dirent.h>
56 #include <c2/audit.h>
57 #include <sys/zone.h>
58 #include <sys/dnlc.h>
59 #include <sys/fs/snode.h>
60
61 /* Controls whether paths are stored with vnodes. */
62 int vfs_vnode_path = 1;
63
64 int
65 lookupname(
66 char *fnamep,
67 enum uio_seg seg,
68 int followlink,
69 vnode_t **dirvpp,
70 vnode_t **compvpp)
71 {
72 return (lookupnameatcred(fnamep, seg, followlink, dirvpp, compvpp, NULL,
73 CRED()));
74 }
75
76 /*
77 * Lookup the user file name,
78 * Handle allocation and freeing of pathname buffer, return error.
79 */
1391
1392 bcopy(rpn.pn_path, buf, rpn.pn_pathlen + 1);
1393 pn_free(&pn);
1394 pn_free(&rpn);
1395 VN_RELE(vrootp);
1396 if (doclose) {
1397 (void) VOP_CLOSE(vp, FREAD, 1, 0, cr, NULL);
1398 VN_RELE(vp);
1399 }
1400 return (0);
1401 }
1402
1403 notcached:
1404 pn_free(&rpn);
1405 } else {
1406 mutex_exit(&vp->v_lock);
1407 }
1408
1409 pn_free(&pn);
1410
1411 if (vp->v_type != VDIR) {
1412 /*
1413 * If we don't have a directory, try to find it in the dnlc via
1414 * reverse lookup. Once this is found, we can use the regular
1415 * directory search to find the full path.
1416 */
1417 if ((pvp = dnlc_reverse_lookup(vp, path, MAXNAMELEN)) != NULL) {
1418 /*
1419 * Check if we have read privilege so, that
1420 * we can lookup the path in the directory
1421 */
1422 ret = 0;
1423 if ((flags & LOOKUP_CHECKREAD)) {
1424 ret = VOP_ACCESS(pvp, VREAD, 0, cr, NULL);
1425 }
1426 if (ret == 0) {
1427 ret = dirtopath(vrootp, pvp, buf, buflen,
1428 flags, cr);
1429 }
1430 if (ret == 0) {
1431 len = strlen(buf);
1432 if (len + strlen(path) + 1 >= buflen) {
|
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
25 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
26 */
27
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/cpuvar.h>
45 #include <sys/errno.h>
46 #include <sys/cred.h>
47 #include <sys/user.h>
48 #include <sys/uio.h>
49 #include <sys/vfs.h>
50 #include <sys/vnode.h>
51 #include <sys/pathname.h>
52 #include <sys/proc.h>
53 #include <sys/vtrace.h>
54 #include <sys/sysmacros.h>
55 #include <sys/debug.h>
56 #include <sys/dirent.h>
57 #include <c2/audit.h>
58 #include <sys/zone.h>
59 #include <sys/dnlc.h>
60 #include <sys/fs/snode.h>
61 #include <sys/brand.h>
62
63 /* Controls whether paths are stored with vnodes. */
64 int vfs_vnode_path = 1;
65
66 int
67 lookupname(
68 char *fnamep,
69 enum uio_seg seg,
70 int followlink,
71 vnode_t **dirvpp,
72 vnode_t **compvpp)
73 {
74 return (lookupnameatcred(fnamep, seg, followlink, dirvpp, compvpp, NULL,
75 CRED()));
76 }
77
78 /*
79 * Lookup the user file name,
80 * Handle allocation and freeing of pathname buffer, return error.
81 */
1393
1394 bcopy(rpn.pn_path, buf, rpn.pn_pathlen + 1);
1395 pn_free(&pn);
1396 pn_free(&rpn);
1397 VN_RELE(vrootp);
1398 if (doclose) {
1399 (void) VOP_CLOSE(vp, FREAD, 1, 0, cr, NULL);
1400 VN_RELE(vp);
1401 }
1402 return (0);
1403 }
1404
1405 notcached:
1406 pn_free(&rpn);
1407 } else {
1408 mutex_exit(&vp->v_lock);
1409 }
1410
1411 pn_free(&pn);
1412
1413 if (PROC_IS_BRANDED(curproc)) {
1414 /*
1415 * If v_path doesn't work out and we're in a branded zone,
1416 * we're not going to bother doing more work here: because
1417 * directories from the global can be lofs mounted into odd
1418 * locations (e.g., /native in an lx zone), it is likely that
1419 * the DNLC reverse lookup will yield nothing. Indeed, the
1420 * only certainty is that the DNLC reverse lookup will be
1421 * exceedingly painful; we save ourselves the substantial
1422 * grief of scanning the entire DNLC and kick out with ENOENT
1423 * in this case.
1424 */
1425 ret = ENOENT;
1426 } else if (vp->v_type != VDIR) {
1427 /*
1428 * If we don't have a directory, try to find it in the dnlc via
1429 * reverse lookup. Once this is found, we can use the regular
1430 * directory search to find the full path.
1431 */
1432 if ((pvp = dnlc_reverse_lookup(vp, path, MAXNAMELEN)) != NULL) {
1433 /*
1434 * Check if we have read privilege so, that
1435 * we can lookup the path in the directory
1436 */
1437 ret = 0;
1438 if ((flags & LOOKUP_CHECKREAD)) {
1439 ret = VOP_ACCESS(pvp, VREAD, 0, cr, NULL);
1440 }
1441 if (ret == 0) {
1442 ret = dirtopath(vrootp, pvp, buf, buflen,
1443 flags, cr);
1444 }
1445 if (ret == 0) {
1446 len = strlen(buf);
1447 if (len + strlen(path) + 1 >= buflen) {
|