Search code examples
linux-kernelfilesystemsmountsmbcifs

SMB mount fails with execl()


To mount CIFS presently I use system() call in source, this works. If I try to run command manually on shell it works too.

$ mount -t cifs //IP/dir /mnt -o user=name,pass=PASS,domain=mydomain,nounix
$ mount.cifs //IP/dir /mnt -o user=name,pass=PASS,domain=mydomain,nounix

But if i replace the same command with exec() family i see errors.

if(fork() == 0) 
{
  if (execl("/bin/mount", "/bin/mount", "-t", "cifs", "//IP/dir",  "/mnt", 
  "-o user=name,pass=PASS,domain=mydomain,nounix", (char*) NULL) < 0)
  ...
}
else
  ...

Error: mount: mounting cifs on //IP/dir /mnt failed: No such file or directory. It looks like mount directory "/mnt" is not recognized or not seen by mount process.

Tried below things but no luck:

  • as suggested in forums tried using sec=ntlmv2 and other options
  • with mount.cifs
  • combined arguments "//IP/dir" and "/mnt" as "//ipaddr/dir /mnt"

What would be the cause here? How to see the command line parameters of the exec()'ed program ?

Version of mount:

mount.cifs version: 1.14-x

Regards, - AK


Solution

  • Used strace() to find the arguments passed to execl(). Solved my issue by using system calls mount() and umount().