From patchwork Fri Jul 6 06:04:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dunrong huang X-Patchwork-Id: 169326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3FAC92C0205 for ; Fri, 6 Jul 2012 16:04:31 +1000 (EST) Received: from localhost ([::1]:45440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn1eX-0003Kd-3A for incoming@patchwork.ozlabs.org; Fri, 06 Jul 2012 02:04:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn1eP-0003KM-Rc for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:04:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sn1eO-0007Jc-4U for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:04:21 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:49667) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn1eN-0007JN-Mn for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:04:20 -0400 Received: by pbbro12 with SMTP id ro12so15266462pbb.4 for ; Thu, 05 Jul 2012 23:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=ZDMdXW295GwkQR3fr/MDz6kBcMKMQ+yWWP0qDGHsSdg=; b=wYvUnlDRrSeI5g/l1SbY5CvlJky8RDTYtoHR2ZcTHzA1OQsTd7mUnkGtfbwLaHb7Iw yylrXvmtR+Ue+M0EuPoe3HpVelEOQOoaVaemZ5cR74rq3NEaWbWjRAkBO5tdeUmwRZuU FZMLBr/179+g4L6PkWFSMaUf233phlif+/5hosWHTAy+etVAAW7LOWkUysm83SsZxEZJ Q/eINjHuiS/F2U+ySzHqwVu1YyrzHAFuz2+h1r9CeJ5aEcClLKApOe8TjxOyvZHV5vXe tBTpzt1T4h5SKuIP+oXNdtfJajDhn73Ls2j98YRJhMlE8T8DbdkDamOOMitwVzj7astE 1NWg== Received: by 10.68.227.198 with SMTP id sc6mr34096293pbc.138.1341554657260; Thu, 05 Jul 2012 23:04:17 -0700 (PDT) Received: from riegamaths@gmail.com ([119.255.44.227]) by mx.google.com with ESMTPS id pe2sm21218935pbc.59.2012.07.05.23.04.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jul 2012 23:04:16 -0700 (PDT) Received: by riegamaths@gmail.com (sSMTP sendmail emulation); Fri, 06 Jul 2012 14:04:43 +0800 From: Dunrong Huang To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2012 14:04:43 +0800 Message-Id: <1341554683-20116-1-git-send-email-riegamaths@gmail.com> X-Mailer: git-send-email 1.7.8.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Mark McLoughlin , Anthony Liguori , Jan Kiszka Subject: [Qemu-devel] [PATCH v2] slirp: Ensure smbd and shared directory exist when enable smb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Dunrong Huang --- net/slirp.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 37b6ccf..ff36fa2 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -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) {