From ceb48e8857671ee86c080532ea625fb8393377bb Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 28 Jun 2021 15:53:51 +0900 Subject: [PATCH] samba 4.14.5 (new formula) samba 4.14.5 Samba (v3) was removed from Homebrew in 2016 due to technical issues, however, Samba v4 seems actively supporting macOS recently, and worth including again in Homebrew. Samba v4 is already included in MacPorts. Further discussion in Homebrew/discussions 1736 . The formula is based on Alexander Richardson (arichardson)'s PR 32031 . Example usage with qemu: ``` qemu-system-x86_64 \ -accel hvf \ -m 4096 \ -cdrom ubuntu-21.04-desktop-amd64.iso \ -net nic \ -net user,smb=/tmp/foo ``` The shared folder can be mounted with `mount.cifs //10.0.2.4/qemu /mnt` in the guest. Closes #80171. Co-authored-by: Alex Richardson Signed-off-by: Akihiro Suda Signed-off-by: Sean Molenaar <1484494+SMillerDev@users.noreply.github.com> Signed-off-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Signed-off-by: BrewTestBot <1589480+BrewTestBot@users.noreply.github.com> --- Formula/samba.rb | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Formula/samba.rb diff --git a/Formula/samba.rb b/Formula/samba.rb new file mode 100644 index 0000000000000..01155afc31fbe --- /dev/null +++ b/Formula/samba.rb @@ -0,0 +1,123 @@ +class Samba < Formula + # Samba can be used to share directories with the guest in QEMU user-mode (SLIRP) networking + # with the `-net nic -net user,smb=/share/this/with/guest` option. + # The shared folder appears in the guest as "\\10.0.2.4\qemu". + desc "SMB/CIFS file, print, and login server for UNIX" + homepage "https://samba.org/" + url "https://download.samba.org/pub/samba/stable/samba-4.14.5.tar.gz" + sha256 "bb6ef5d2f16b85288d823578abc453d9a80514c42e5a2ea2c4e3c60dc42335c3" + license "GPL-3.0-or-later" + + # configure requires python3 binary to be present, even when --disable-python is set. + depends_on "python@3.9" => :build + depends_on "gnutls" + + uses_from_macos "perl" => :build + + resource "Parse::Yapp" do + url "https://cpan.metacpan.org/authors/id/W/WB/WBRASWELL/Parse-Yapp-1.21.tar.gz" + sha256 "3810e998308fba2e0f4f26043035032b027ce51ce5c8a52a8b8e340ca65f13e5" + end + + def install + # avoid `perl module "Parse::Yapp::Driver" not found` error on macOS 10.xx (not required on 11) + if MacOS.version < :big_sur + ENV.prepend_create_path "PERL5LIB", buildpath/"lib/perl5" + ENV.prepend_path "PATH", buildpath/"bin" + resource("Parse::Yapp").stage do + system "perl", "Makefile.PL", "INSTALL_BASE=#{buildpath}" + system "make" + system "make", "install" + end + end + # CFLAGS is for avoiding hitting https://bugzilla.samba.org/show_bug.cgi?id=14680 . + # Remove this CFLAGS when the patch ( https://attachments.samba.org/attachment.cgi?id=16579 ) gets merged. + ENV.append "CFLAGS", "-include #{buildpath}/lib/util/debug.h" + system "./configure", + "--disable-cephfs", + "--disable-cups", + "--disable-iprint", + "--disable-glusterfs", + "--disable-python", + "--without-acl-support", + "--without-ad-dc", + "--without-ads", + "--without-dnsupdate", + "--without-ldap", + "--without-libarchive", + "--without-json", + "--without-ntvfs-fileserver", + "--without-pam", + "--without-regedit", + "--without-syslog", + "--without-utmp", + "--without-winbind", + "--prefix=#{prefix}" + system "make" + system "make", "install" + on_macos do + # macOS has its own SMB daemon as /usr/sbin/smbd, so rename our smbd to samba-dot-org-smbd to avoid conflict. + # samba-dot-org-smbd is used by qemu.rb . + mv "#{sbin}/smbd", "#{sbin}/samba-dot-org-smbd" + end + end + + def caveats + on_macos do + <<~EOS + macOS has its own SMB daemon as /usr/sbin/smbd, so Samba version of smbd is installed as "#{HOMEBREW_PREFIX}/sbin/samba-dot-org-smbd" + + On macOS, Samba should be executed as a non-root user: https://bugzilla.samba.org/show_bug.cgi?id=8773 + EOS + end + end + + test do + smbd = "#{sbin}/smbd" + on_macos do + smbd = "#{sbin}/samba-dot-org-smbd" + end + + system smbd, "--build-options" + system smbd, "--version" + + mkdir_p "samba/state" + mkdir_p "samba/data" + (testpath/"samba/data/hello").write "hello" + + # mimic smb.conf generated by qemu + # https://github.com/qemu/qemu/blob/v6.0.0/net/slirp.c#L862 + (testpath/"smb.conf").write <<~EOS + [global] + private dir=#{testpath}/samba/state + interfaces=127.0.0.1 + bind interfaces only=yes + pid directory=#{testpath}/samba/state + lock directory=#{testpath}/samba/state + state directory=#{testpath}/samba/state + cache directory=#{testpath}/samba/state + ncalrpc dir=#{testpath}/samba/state/ncalrpc + log file=#{testpath}/samba/state/log.smbd + smb passwd file=#{testpath}/samba/state/smbpasswd + security = user + map to guest = Bad User + load printers = no + printing = bsd + disable spoolss = yes + usershare max shares = 0 + [test] + path=#{testpath}/samba/data + read only=no + guest ok=yes + force user=#{ENV["USER"]} + EOS + + port = free_port + spawn smbd, "-S", "-F", "--configfile=smb.conf", "--port=#{port}", "--debuglevel=4", in: "/dev/null" + + sleep 5 + mkdir_p "got" + system "smbclient", "-p", port.to_s, "-N", "//127.0.0.1/test", "-c", "get hello #{testpath}/got/hello" + assert_equal "hello", (testpath/"got/hello").read + end +end