Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This is needed since samba 4.14 and newer no longer let us read symlinks
from the FreeBSD kernel smb client.
See https://bugzilla.samba.org/show_bug.cgi?id=15024
  • Loading branch information
arichardson committed Mar 23, 2022
1 parent c62e626 commit 9ba9863
Showing 1 changed file with 163 additions and 0 deletions.
163 changes: 163 additions & 0 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
class SambaAT413 < 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://www.samba.org/"
url "https://download.samba.org/pub/samba/stable/samba-4.13.17.tar.gz"
sha256 "17bdb9ea60d30af22851c8e134d67b43a22fb1e20f159152a647c69dc2a58a68"
license "GPL-3.0-or-later"

livecheck do
url "https://www.samba.org/samba/download/"
regex(/href=.*?samba[._-]v?(\d+(?:\.\d+)+)\.t/i)
end

keg_only :versioned_formula

# configure requires python3 binary to be present, even when --disable-python is set.
depends_on "[email protected]" => :build
depends_on "gnutls"

uses_from_macos "bison" => :build
uses_from_macos "flex" => :build
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

# charset_macosxfs.c: fix compilation on macOS
patch do
url "https://github.com/samba-team/samba/commit/2564e96e8319b4cb4c987dd2a03cf8a293db985a.patch?full_index=1"
sha256 "2428106941f61dba0060e258612d2eda07a96f4e233b239dd2e125361ec18985"
end

# s3: lib: Fix unneeded relative path in #include.
patch do
url "https://github.com/samba-team/samba/commit/9f7ef21e008f15e2ad8049230aeede1f72fe45a3.patch?full_index=1"
sha256 "95ca1f98f8679192c6c76119eb689f129adf89ccf7be682fdbbdecfcf6d131a2"
end

# lib/util: Standardize use of st_[acm]time ns
patch do
url "https://github.com/samba-team/samba/commit/53a1d034f3e47ed3c5ec4f9b6ca0d2d695e8d873.patch?full_index=1"
sha256 "a3ab90745e2fd2699162fe2255e61b00771ea213070a406f8b71c109b6587e12"
end

# Don't use sysconf(_SC_NGROUPS_MAX) on macOS for getgroups()
patch do
url "https://github.com/samba-team/samba/commit/2c18a982537ea1a62e4d802c9ae0ef06b36158dc.patch?full_index=1"
sha256 "7f8ce05676d859e096972a831fa985e6d9160783fe314c0182e8d315782b156e"
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
ENV.append "LDFLAGS", "-Wl,-rpath,#{lib}/private" if OS.linux?
system "./configure",
"--disable-cephfs",
"--disable-cups",
"--disable-iprint",
"--disable-glusterfs",
"--disable-python",
"--without-acl-support",
"--without-ad-dc",
"--without-ads",
"--without-ldap",
"--without-libarchive",
"--without-json",
"--without-pam",
"--without-regedit",
"--without-syslog",
"--without-utmp",
"--without-winbind",
"--prefix=#{prefix}",
"--sysconfdir=#{etc}",
"--localstatedir=#{var}",
"--with-privatelibdir=#{lib}/private",
"--private-libraries=ALL",
"--with-shared-modules=!vfs_snapper",
"--disable-rpath"
system "make"
system "make", "install"
if OS.mac?
# 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 .
# Rename mdfind and profiles as well to avoid conflicting with /usr/bin/{mdfind,profiles}
{ sbin => "smbd", bin => "mdfind", bin => "profiles" }.each do |dir, cmd|
mv dir/cmd, dir/"samba-dot-org-#{cmd}"
end
end
end

def caveats
on_macos do
<<~EOS
To avoid conflicting with macOS system binaries, some files were installed with non-standard name:
- smbd: #{HOMEBREW_PREFIX}/sbin/samba-dot-org-smbd
- mdfind: #{HOMEBREW_PREFIX}/bin/samba-dot-org-mdfind
- profiles: #{HOMEBREW_PREFIX}/bin/samba-dot-org-profiles
EOS
end
end

test do
smbd = "#{sbin}/smbd"
on_macos do
smbd = "#{sbin}/samba-dot-org-smbd"
end

system smbd, "--build-options", "--configfile=/dev/null"
# 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, "--log-stdout", "-F", "--configfile=smb.conf", "--port=#{port}", "--debuglevel=4", in: "/dev/null"

sleep 5
mkdir_p "got"
# FIXME: not working for some reason
# 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

0 comments on commit 9ba9863

Please sign in to comment.