• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/samba-3.5.8/examples/scripts/mount/
1#!/bin/bash
2# Debian mount.smbfs compatibility wrapper
3# Copyright 2007, Steve Langasek <vorlon at debian.org>
4# Licensed under the GNU General Public License, version 2.  See the
5# file /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
6
7# This script accepts all documented mount options for mount.smbfs,
8# passing through those that are also recognized by mount.cifs,
9# converting those that are not recognized but map to available cifs
10# options, and warning about the use of options for which no equivalent
11# exists.
12
13# known bugs: quoted spaces in arguments are not passed intact
14
15set -e
16
17# reverse the order of username and password in a "username" parameter,
18# taking care to leave any "%password" bit intact
19
20reverse_username_workgroup() {
21	local workgroup password username
22
23	username="$1"
24	case "$username" in
25	*%*)	password="${username#*%}"
26		username="${username%%%*}"
27		;;
28	*) ;;
29	esac
30	case "$username" in
31	*/*)	workgroup="${username#*/}"
32		username="${username%%/*}"
33		;;
34	*) ;;
35	esac
36	if [ -n "$workgroup" ]; then
37		username="$workgroup\\$username"
38	fi
39	if [ -n "$password" ]; then
40		username="$username%$password"
41	fi
42	echo "$username"
43}
44
45
46# parse out the mount options that have been specified using -o, and if
47# necessary, convert them for use by mount.cifs
48
49parse_mount_options () {
50	local OLD_IFS IFS options option username
51	OLD_IFS="$IFS"
52	IFS=","
53	options=""
54	workgroup=""
55	password=""
56
57	for option in $@; do
58		case "$option" in
59		sockopt=* | scope=* | codepage=* | ttl=* | debug=*)
60			echo "Warning: ignoring deprecated smbfs option '$option'" >&2
61			;;
62
63		krb)
64			options="$options${options:+,}sec=krb5"
65			;;
66
67		guest)
68			echo "Warning: mapping 'guest' to 'guest,sec=none'" >&2
69			options="$options${options:+,}guest,sec=none"
70			;;
71
72		# username and workgroup are reversed in username= arguments,
73		# so need to be parsed out
74		username=*/*)
75			IFS="$OLD_IFS"
76			username="${option#username=}"
77			username="$(reverse_username_workgroup "$username")"
78			IFS=","
79			options="$options${options:+,}username=$username"
80			;;
81
82		*)
83			options="$options${options:+,}$option"
84			;;
85		esac
86	done
87	IFS="$OLD_IFS"
88	echo $options
89}
90
91args=()
92while [ "$#" -gt 0 ]; do
93	case "$1" in
94	-o*)
95		arg=${1#-o}
96		shift
97		if [ -z "$arg" ]; then
98			arg=$1
99			shift
100		fi
101		arg="$(parse_mount_options "$arg")"
102		if [ -n "$arg" ]; then
103			args=("${args[@]}" "-o" "$arg")
104		fi
105		;;
106	*)
107		args=("${args[@]}" "$1")
108		shift
109		;;
110	esac
111done
112
113USER="$(reverse_username_workgroup "$USER")"
114
115exec /sbin/mount.cifs "${args[@]}"
116