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 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
38 #include <sys/mnttab.h>
39 #include <sys/mount.h>
40 #include <sys/mntent.h>
44 #include <priv_utils.h>
49 static void pr_err(const char *fmt
, ...);
51 static int smbfs_unmount(char *, int);
52 static struct extmnttab
*mnttab_find();
55 static char typename
[64];
58 main(int argc
, char *argv
[])
64 (void) setlocale(LC_ALL
, "");
66 #if !defined(TEXT_DOMAIN)
67 #define TEXT_DOMAIN "SYS_TEST"
69 (void) textdomain(TEXT_DOMAIN
);
72 * Normal users are allowed to umount smbfs mounts they own.
73 * To allow that, this program is installed setuid root, and
74 * it adds SYS_MOUNT privilege here (if needed), and then
75 * restores the user's normal privileges.
77 if (__init_suid_priv(0, PRIV_SYS_MOUNT
, (char *)NULL
) < 0) {
78 (void) fprintf(stderr
,
79 gettext("Insufficient privileges, "
80 "%s must be set-uid root\n"), argv
[0]);
84 myname
= strrchr(argv
[0], '/');
85 myname
= myname
? myname
+1 : argv
[0];
86 (void) sprintf(typename
, "smbfs %s", myname
);
92 while ((c
= getopt(argc
, argv
, "f")) != EOF
) {
95 umnt_flag
|= MS_FORCE
; /* forced unmount is desired */
102 if (argc
- optind
!= 1) {
107 return (smbfs_unmount(argv
[optind
], umnt_flag
));
111 pr_err(const char *fmt
, ...)
116 (void) fprintf(stderr
, "%s: ", typename
);
117 (void) vfprintf(stderr
, fmt
, ap
);
118 (void) fflush(stderr
);
125 (void) fprintf(stderr
,
126 gettext("Usage: smbfs umount [-o opts] {//server/share | dir}\n"));
131 smbfs_unmount(char *pathname
, int umnt_flag
)
133 struct extmnttab
*mntp
;
136 mntp
= mnttab_find(pathname
);
138 pathname
= mntp
->mnt_mountp
;
141 /* Need sys_mount privilege for the umount call. */
142 (void) __priv_bracket(PRIV_ON
);
143 rc
= umount2(pathname
, umnt_flag
);
144 (void) __priv_bracket(PRIV_OFF
);
147 pr_err(gettext("%s: %s\n"), pathname
, strerror(errno
));
155 * Find the mnttab entry that corresponds to "name".
156 * We're not sure what the name represents: either
157 * a mountpoint name, or a special name (server:/path).
158 * Return the last entry in the file that matches.
160 static struct extmnttab
*
165 struct extmnttab mnt
;
166 struct extmnttab
*res
= NULL
;
168 fp
= fopen(MNTTAB
, "r");
170 pr_err("%s: %s\n", MNTTAB
, strerror(errno
));
173 while (getextmntent(fp
, &mnt
, sizeof (struct extmnttab
)) == 0) {
174 if (strcmp(mnt
.mnt_mountp
, dirname
) == 0 ||
175 strcmp(mnt
.mnt_special
, dirname
) == 0) {
178 res
= fsdupmnttab(&mnt
);