3 *
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 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 #include <ctype.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <unistd.h>
30 #include <sys/fcntl.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <stdlib.h>
34 #include <pthread.h>
35 #include <sys/varargs.h>
36 #include <sys/types.h>
37 #include <sys/mnttab.h>
38 #include <tiuser.h>
39 #include <netconfig.h>
40 #include <netdir.h>
41 #include <sys/systeminfo.h>
42 #include <sys/utsname.h>
43 #include <libzfs.h>
610 */
611 for (j = 0; j < nhosts && !belong; j++) {
612 host = clnames->h_hostservs[j].h_host;
613 if (__multi_innetgr(n, grl, 1, &host, 0, NULL,
614 1, &domain))
615 belong = B_TRUE;
616 }
617 }
618
619 free(grl);
620 return (belong ? response : B_FALSE);
621 }
622
623 /*
624 * Resolve the ZFS dataset from a path.
625 * Returns,
626 * 0 = On success.
627 * -1 = Failure to open /etc/mnttab file or to get ZFS dataset.
628 */
629 int
630 smb_getdataset(const char *path, char *dataset, size_t len)
631 {
632 char tmppath[MAXPATHLEN];
633 char *cp;
634 FILE *fp;
635 struct mnttab mnttab;
636 struct mnttab mntpref;
637 int rc = -1;
638
639 if ((fp = fopen(MNTTAB, "r")) == NULL)
640 return (-1);
641
642 (void) memset(&mnttab, '\0', sizeof (mnttab));
643 (void) strlcpy(tmppath, path, MAXPATHLEN);
644 cp = tmppath;
645
646 while (*cp != '\0') {
647 resetmnttab(fp);
648 (void) memset(&mntpref, '\0', sizeof (mntpref));
649 mntpref.mnt_mountp = tmppath;
650
651 if (getmntany(fp, &mnttab, &mntpref) == 0) {
652 if (mnttab.mnt_fstype == NULL)
653 break;
654
655 if (strcmp(mnttab.mnt_fstype, "zfs") != 0)
656 break;
657 /*
658 * Ensure that there are no leading slashes
|
3 *
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 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 #include <ctype.h>
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include <unistd.h>
30 #include <sys/fcntl.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <stdlib.h>
34 #include <pthread.h>
35 #include <sys/varargs.h>
36 #include <sys/types.h>
37 #include <sys/mnttab.h>
38 #include <tiuser.h>
39 #include <netconfig.h>
40 #include <netdir.h>
41 #include <sys/systeminfo.h>
42 #include <sys/utsname.h>
43 #include <libzfs.h>
610 */
611 for (j = 0; j < nhosts && !belong; j++) {
612 host = clnames->h_hostservs[j].h_host;
613 if (__multi_innetgr(n, grl, 1, &host, 0, NULL,
614 1, &domain))
615 belong = B_TRUE;
616 }
617 }
618
619 free(grl);
620 return (belong ? response : B_FALSE);
621 }
622
623 /*
624 * Resolve the ZFS dataset from a path.
625 * Returns,
626 * 0 = On success.
627 * -1 = Failure to open /etc/mnttab file or to get ZFS dataset.
628 */
629 int
630 smb_getdataset(libzfs_handle_t *libhdl, const char *path, char *dataset,
631 size_t len)
632 {
633 char tmppath[MAXPATHLEN];
634 char *cp;
635 FILE *fp;
636 struct mnttab mnttab;
637 struct mnttab mntpref;
638 int rc = -1;
639
640 /*
641 * Optimisation: if the path is the default mountpoint then
642 * the dataset name can be determined from path.
643 * Attempt to open dataset by derived name and, if successful,
644 * check if its mountpoint matches path.
645 */
646 if (libhdl != NULL) {
647 zfs_handle_t *hdl;
648 char mountpnt[ZFS_MAXPROPLEN];
649 char *dsname = (char *)path + strspn(path, "/");
650
651 hdl = zfs_open(libhdl, dsname, ZFS_TYPE_FILESYSTEM);
652 if (hdl != NULL) {
653 if ((zfs_prop_get(hdl, ZFS_PROP_MOUNTPOINT, mountpnt,
654 sizeof (mountpnt), NULL, NULL, 0, B_FALSE) == 0) &&
655 (strcmp(mountpnt, path) == 0)) {
656 zfs_close(hdl);
657 (void) strlcpy(dataset, dsname, len);
658 return (0);
659 }
660 zfs_close(hdl);
661 }
662 }
663
664 /*
665 * Couldn't find a filesystem optimistically, use mnttab
666 */
667 if ((fp = fopen(MNTTAB, "r")) == NULL)
668 return (-1);
669
670 (void) memset(&mnttab, '\0', sizeof (mnttab));
671 (void) strlcpy(tmppath, path, MAXPATHLEN);
672 cp = tmppath;
673
674 while (*cp != '\0') {
675 resetmnttab(fp);
676 (void) memset(&mntpref, '\0', sizeof (mntpref));
677 mntpref.mnt_mountp = tmppath;
678
679 if (getmntany(fp, &mnttab, &mntpref) == 0) {
680 if (mnttab.mnt_fstype == NULL)
681 break;
682
683 if (strcmp(mnttab.mnt_fstype, "zfs") != 0)
684 break;
685 /*
686 * Ensure that there are no leading slashes
|