Skip to contentSkip to conversation

slirp: Ensure smbd and shared directory exist when enable smb

PATCH Superseded Dunrong Huang 2 participants 3 messages Jul 3, 2012 – Jul 6, 2012 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 exists or not when QEMU's "built-in" SMB server is enabled.

---
 net/slirp.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
net/slirp.c +14 -0
index 37b6ccf..a672cff 100644
@@ -489,6 +489,20 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     char smb_cmdline[128];
     FILE *f;
 
+    if (access(CONFIG_SMBD_COMMAND, F_OK)) {
+        slirp_smb_cleanup(s);
+        error_report("could not find '%s', please install it",
+                     CONFIG_SMBD_COMMAND);
+        return -1;
+    }
+
+    if (access(exported_dir, F_OK)) {
+        slirp_smb_cleanup(s);
+        error_report("no such shared directory '%s', 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
#1 lore raw

Sorry for the late review. Two comments below.

Quoted 22 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 exists or not when QEMU's "built-in" SMB server is enabled.

---
 net/slirp.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
net/slirp.c +0 -0
index 37b6ccf..a672cff 100644

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

Quoted 5 lines
net/slirp.c +2 -0
@@ -489,6 +489,20 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     char smb_cmdline[128];
     FILE *f;
 
+    if (access(CONFIG_SMBD_COMMAND, F_OK)) {
+        slirp_smb_cleanup(s);

Both slirp_smb_cleanup are redundant at this point, please remove them.

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

Quoted 6 lines
net/slirp.c +6 -0
+        error_report("could not find '%s', please install it",
+                     CONFIG_SMBD_COMMAND);
+        return -1;
+    }
+
+    if (access(exported_dir, F_OK)) {

What about checking for R_OK | X_OK to avoid that we run into lacking permissions later on?

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

Quoted 10 lines
net/slirp.c +6 -0
+        slirp_smb_cleanup(s);
+        error_report("no such shared directory '%s', 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) {

Jan

#2 lore raw

Thanks for your reply.

2012/7/6 Jan Kiszka <[email protected]>:

Quoted 8 lines
Quoted 8 lines
net/slirp.c +0 -0
index 37b6ccf..a672cff 100644
@@ -489,6 +489,20 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
     char smb_cmdline[128];
     FILE *f;
 
Quoted 4 lines

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

Quoted 2 lines
net/slirp.c +2 -0
+    if (access(CONFIG_SMBD_COMMAND, F_OK)) {
+        slirp_smb_cleanup(s);

Both slirp_smb_cleanup are redundant at this point, please remove them.

You are right, i will fix it

Quoted 11 lines

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

Quoted 7 lines
net/slirp.c +6 -0
+        error_report("could not find '%s', please install it",
+                     CONFIG_SMBD_COMMAND);
+        return -1;
+    }
+
+    if (access(exported_dir, F_OK)) {

What about checking for R_OK | X_OK to avoid that we run into lacking permissions later on?

I agree with you, I will send a v2 patch

Signature · 3 lines
Best Regards,

Dunrong Huang