Skip to contentSkip to conversation

slirp: Ensure smbd and shared directory exist when enable smb

PATCH Applied Dunrong Huang 2 participants 2 messages Jul 6, 2012 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 slirp: Ensure smbd and shared directory exist when enable smb

Users may pass the following parameters to qemu:

    $ qemu-kvm -net nic -net user,smb= ...
    $ qemu-kvm -net nic -net user,smb ...
    $ qemu-kvm -net nic -net user,smb=bad_directory ...

In these cases, qemu started successfully while samba server failed to start. Users will confuse since samba server failed silently without any indication of what it did wrong.

To avoid it, we check whether the shared directory exist and if users have permission to access this directory when QEMU's "built-in" SMB server is enabled.

---
 net/slirp.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
net/slirp.c +12 -0
index 37b6ccf..ff36fa2 100644
@@ -489,6 +489,18 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     char smb_cmdline[128];
     FILE *f;
 
+    if (access(CONFIG_SMBD_COMMAND, F_OK)) {
+        error_report("could not find '%s', please install it",
+                     CONFIG_SMBD_COMMAND);
+        return -1;
+    }
+
+    if (access(exported_dir, R_OK | X_OK)) {
+        error_report("no such directory '%s', or you do not have permission "
+                     "to access it, please check it", exported_dir);
+        return -1;
+    }
+
     snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d",
              (long)getpid(), instance++);
     if (mkdir(s->smb_dir, 0700) < 0) {
Signature · 1 line
1.7.8.4
Applied
#1 lore raw
Quoted 32 lines · Dunrong Huang

Users may pass the following parameters to qemu:

    $ qemu-kvm -net nic -net user,smb= ...
    $ qemu-kvm -net nic -net user,smb ...
    $ qemu-kvm -net nic -net user,smb=bad_directory ...

In these cases, qemu started successfully while samba server failed to start. Users will confuse since samba server failed silently without any indication of what it did wrong.

To avoid it, we check whether the shared directory exist and if users have permission to access this directory when QEMU's "built-in" SMB server is enabled.

---
 net/slirp.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
net/slirp.c +5 -0
index 37b6ccf..ff36fa2 100644
@@ -489,6 +489,18 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     char smb_cmdline[128];
     FILE *f;
 
+    if (access(CONFIG_SMBD_COMMAND, F_OK)) {
+        error_report("could not find '%s', please install it",
+                     CONFIG_SMBD_COMMAND);
+        return -1;
+    }

net/slirp.c static int slirp_smb(SlirpState* s, const char *exported_dir, · line 506

Quoted 10 lines
net/slirp.c +7 -0
+
+    if (access(exported_dir, R_OK | X_OK)) {
+        error_report("no such directory '%s', or you do not have permission "
+                     "to access it, please check it", exported_dir);
+        return -1;
+    }
+
     snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d",
              (long)getpid(), instance++);
     if (mkdir(s->smb_dir, 0700) < 0) {

Thanks, applied to slirp queue.

I added a tiny patch on top that reports the exact error returned by access():

net/slirp.c +2 -2
index eb80889..b82eab0 100644
@@ -504,8 +504,8 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     }
 
     if (access(exported_dir, R_OK | X_OK)) {
-        error_report("no such directory '%s', or you do not have permission "
-                     "to access it, please check it", exported_dir);
+        error_report("error accessing shared directory '%s': %s",
+                     exported_dir, strerror(errno));
         return -1;
     }
 

Jan