Bug 809

Summary: mount doesn't work with cifs
Product: Busybox Reporter: Christof Kaser <c.kaser>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P4    
Version: 1.15.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Christof Kaser 2009-12-13 19:11:04 UTC
For the mount command I have enabled the "Support mounting CIFS/SMB file systems" and therefor I assumed that the command "mount //server/share /dir -o user=xy,pass=yz" would mount a CIFS-share, as it was possible in previous versions. But unfortunately this support has been disabled:

util-linux/mount.c

	if (ENABLE_FEATURE_MOUNT_CIFS
	 && (!mp->mnt_type || strcmp(mp->mnt_type, "cifs") == 0)
	 && (mp->mnt_fsname[0] == '/' || mp->mnt_fsname[0] == '\\')
	 && mp->mnt_fsname[0] == mp->mnt_fsname[1]
	) {
#if 0 /* reported to break things */
		len_and_sockaddr *lsa;

There was a problem with a 2.4 kernel, which led to the deactivating of that code:

http://lists.busybox.net/pipermail/busybox/2009-April/068758.html

This "#if 0" breaks things with kernel 2.6.32.
Comment 1 Denys Vlasenko 2009-12-14 00:45:43 UTC
What command exactly do you run?
Comment 2 Christof Kaser 2009-12-14 18:04:36 UTC
(In reply to comment #1)
> What command exactly do you run?
> 

~ # strace -e mount mount //k3/ki /mnt -o user=u01,pass=u 
mount("//k3/ki", "/mnt", "cifs", MS_MANDLOCK|MS_SILENT, "user=u01,pass=u") = -1 EINVAL (Invalid argument)
mount: mounting //k3/ki on /mnt failed: Invalid argument
~ # 
~ # cat /proc/version
Linux version 2.6.32 .....
~ # 
~ # busybox
BusyBox v1.15.2 .....


After enabling the code, which build the cifs mount options:

~ # strace -e mount mount //k3/ki /mnt -o user=u01,pass=u 
mount("\\\\10.8.0.3\\ki", "/mnt", "cifs", MS_MANDLOCK|MS_SILENT, "user=u01,pass=u,ip=10.8.0.3") = 0

Comment 3 Denys Vlasenko 2009-12-14 19:06:41 UTC
I wonder what was breaking for those "other people". I definitely remember that for someone it was working without that code, and broke with it. Had to document it better... oh well.

Maybe converting hostname to ip (\\10.8.0.3\ki thing) is not such a good idea, we lose information this way - textual host name is lost. And we already pass ip=N.N.N.N in options.

Can you try what happens if we DONT mangle //k3/ki and only add ip=N.N.N.N to options?
Comment 4 Christof Kaser 2009-12-14 20:03:46 UTC
That works.

.
#if 0 /* reported to break things */
.
.
#else
		len_and_sockaddr *lsa;
		char *ip, *dotted;
		char *s;

		// Get server IP
		s = strrchr(mp->mnt_fsname, '/');
		if (s <= mp->mnt_fsname+1)
			goto report_error;
		*s = '\0';
		lsa = host2sockaddr(mp->mnt_fsname+2, 0);
		*s = '/';
		if (!lsa)
			goto report_error;

		// Insert ip=... option into string flags.
		dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
		ip = xasprintf("ip=%s", dotted);
		parse_mount_options(ip, &filteropts);
#endif
.

~ # strace -e mount mount //k3/ki /mnt -o user=u01,pass=u      
mount("//k3/ki", "/mnt", "cifs", MS_MANDLOCK|MS_SILENT, "user=u01,pass=u,ip=10.8.0.3") = 0
~ # 
~ # mount | grep k3
//k3/ki on /mnt type cifs (rw,mand,relatime,unc=\\k3\ki,username=u01,uid=0,noforceuid,gid=0,noforcegid,addr=10.8.0.3,posixpaths,serverino,acl,rsize=16384,wsize=57344)


Comment 5 Denys Vlasenko 2009-12-15 00:30:49 UTC
Thanks! Fixed in git. Please test and confirm that current git works for you.
Comment 6 Christof Kaser 2009-12-15 12:01:33 UTC
It works with that change:

//		lsa = host2sockaddr(s, 0);
		lsa = host2sockaddr(mp->mnt_fsname + 2, 0);
Comment 7 Denys Vlasenko 2009-12-15 15:37:48 UTC
Sorry... fixed, please try git again.
Comment 8 Christof Kaser 2009-12-15 17:35:59 UTC
Now it works :)
Comment 9 Denys Vlasenko 2009-12-18 11:43:59 UTC
Fixed, will be in 1.16.x