Attempting to mount network volumes in Lion

Hi all,

I’m forced to revise a script I wrote to mount network volumes shared on our Windows servers because Lion changes the way smb works. You can no longer mount folders in subdirectories of a Windows share without having at least read privileges on the folders containing the subdirectory you hope to mount as a volume on your desktop.

The workaround Apple recommends is to use mount_smbfs which still behaves the old (pre-Lion) way. So here I am trying to write a script that uses a shell command to mount the drive.

I got it to work fairly well, have managed to prompt for a password, save it in an application keychain, and then use it the user account and password info from the keychain on subsequent tries (at least that’s the plan.)

But. When it comes time to actually mount the drive, I hit a "permissions error’ that appears to be related to the folder I’m trying to mount the share to. If I use “with administrator privileges” to mount the volume, it no longer reports that error, but the server returns an “authentication error.” It’s almost as though it’s trying to pass “root” credentials to the server instead of the user name and password.

Anyway, here’s the code in question:


set varString to false
set AcctName to to do shell script "whoami"
set AcctPassword to "" 

if varString is false then
    set AcctPassword to text returned of ¬
        (display dialog "Please enter password for " & AcctName ¬
            default answer "" buttons {"Continue"} default button 1 with hidden answer)
    do shell script "mkdir /Volumes/" & AcctName -- create folder to mount share to
    do shell script "chmod 775 /Volumes/" & AcctName user name AcctName password AcctPassword -- try to give user rights to mount to this folder
    do shell script "mount -v -t smbfs //server.domain.tld/vRoot/MP02_V006/HQ-ITS_Users/" & AcctName & " /Volumes/" & AcctName & " >2$1" user name AcctName password AcctPassword with administrator privileges

Without the “with administrator privileges” it returns:

error "sh: 2: Permission denied" number 1

with it, it returns an authentication error from the server.

Here’s a handler I use to mount a drive using smb. It’s not exactly what you need because you want to mount a folder and not a drive. However I’m showing you this because the commands I’m using are different than yours. Hopefully this will give you some additional ideas on how to get your script working.

For example I use the command line tool “mount_smbfs”. Also, in my smb command I use the form “smb://user_name:pass_word@ip_address/path”. So you can try that with and without administrator privileges.

Good luck! :smiley:

on mountSMB(remoteDiskName, remoteIPAddress, user_name, pass_word)
	if remoteDiskName is in (do shell script "/bin/ls /Volumes") then
		return true
	else
		set theAddress to quoted form of ("smb://" & user_name & ":" & pass_word & "@" & remoteIPAddress & "/" & remoteDiskName)
		set mountpoint to quoted form of ("/Volumes/" & remoteDiskName)
		try
			do shell script "/bin/mkdir " & mountpoint & "; /sbin/mount_smbfs " & theAddress & space & mountpoint
			return true
		on error
			try
				do shell script "/bin/rm -r " & mountpoint
			end try
			return false
		end try
	end if
end mountSMB

Thanks, I’ll try that.

The man for mount_smbfs said not to use it directly, so…

but I did try adding the user name and password as part of the connect string, that didn’t work with the mount command. Perhaps I’ll have better luck using mount_smbfs directly.

Tried:

mount_smbfs //<user>:<passwd>@server.doman.tld/share

Still got the permission denied error. Ran same code from terminal, and volume mounted without issue. So I have some kind of issue with the account/environment running the script.

Will have to hit tutorials on how to ensure Applescript editor uses local credentials to run shell scripts…