Ever wanted to rebuild a RedHat RPM from source? I had an issue where I wanted to include one of the new features offered by SAMBA that enables logging to utmp in RedHat 7.1 and RedHat 6.2. Since RedHat's supplied binary RPM's did not include this support, I had two choices: one was to download the SAMBA source, and compile the feature in from there, and my other choice was to possibly use the RPM source that RedHat supplies with their RPM's. I like the idea of a package management system, since when you install from source, you don't get nice features like easily removing the package, upgrading it, or listing where all the files are currently installed to. Sure, you can do that manually, but you have to be careful of where the program gets installed, or keep records of where you are installing things. By default, most source code gets installed somewhere in the /usr/local tree, versus the /usr tree (a simple configure option or Makefile change can take care of that). Usually most RPM binaries from RedHat get installed to /usr, and the configuration files get placed in /etc, which makes things like system upgrades easier, since everything is usually in one place. So how do you get a source RPM to compile with the options you want, plus get all the features of the RPM system?
Before we begin, I *strongly* recommend you backup your SAMBA configuration files, especially /etc/samba/smb.conf file, before proceeding. I did not have any trouble, but your mileage may vary. It's always nice to have the original SAMBA binary RPM's around, in case you need to reinstall SAMBA.
Step One is of course, to grab the source RPM from Redhat. I use their ftp site to do this: ftp://updates.redhat.com The RPM in question here is: /7.1/en/os/SRPMS/samba-2.0.8-1.7.1.src.rpm
Step Two we install the rpm - don't worry, it does not install over your current SAMBA install, but the source RPM is installed to /usr/src/redhat
rpm -ivh samba-2.0.8-1.7.1.src.rpm
A directory of the /usr/src/redhat tree looks like this:
[root@linux redhat]# l total 28 drwxr-xr-x 7 root root 4096 May 19 04:23 . drwxr-xr-x 6 root root 4096 Jun 4 20:20 .. drwxr-xr-x 5 root root 4096 Jun 6 21:08 BUILD drwxr-xr-x 8 root root 4096 May 19 04:23 RPMS drwxr-xr-x 2 root root 4096 Jun 4 19:46 SOURCES drwxr-xr-x 2 root root 4096 Jun 6 21:07 SPECS drwxr-xr-x 2 root root 4096 Apr 8 18:43 SRPMS
Step Three now we have the source to SAMBA "installed" and we are ready to go to work. In this case, I went in to /usr/src/redhat/SOURCES/samba-2.0.8 and saw where all the sources are installed. RedHat also installed various patches to the "RedHat Version" of SAMBA in this directory. Now lets figure out what compile time options are available to us, by copying the source (samba-2.0.8.tar.bz2) file to a temporary directory, extracting it, and running the configure script with the --help option. Here is where I got some needed information for compiling in the option I wanted. I simply ran the configure script, with the help option, and saw what option I needed. ./configure --help . Since I wanted utmp support, I saw that I needed to add --with-utmp to my configure options. Don't run that now, but we need to make sure to note this, so it can be included in our RPM build.
Step Four Now that we have our needed compile option, we have to tell the RPM spec, to include this when we build our "custom" RPM binary. To do that, change into the /usr/src/redhat/SPECS directory, and do a listing. You should see a file called: samba.spec This is the file we need to modify with our compile option. The beginning of this file includes the various patches that are located in /usr/src/redhat/SOURCES. If you go a down a little bit further in the file, you will see the area where all the compile options are assigned. The area begins with: %configure. Now we just need to add our option to all the other options RedHat uses with their SAMBA, and save the new spec file. I simply added --with-utmp after the last option, which in this case was --without-smbwrapper.
Step Five Now we are ready to build our custom binary of SAMBA, with our new option compiled in. Simply run rpm -bb samba.spec and grab a cup of coffee. Depending on the speed of your system, this could take a few minutes. You should now see SAMBA being rebuilt from source, with our new option.
Step Six Once SAMBA is done being rebuilt, the resulting binary(s) are placed in /usr/src/redhat/RPMS/i386. You should now see the following binaries:
-rw-rw-r-- 1 root root 2596787 Jun 6 21:15 samba-2.0.8-1.7.1.i386.rpm -rw-rw-r-- 1 root root 776776 Jun 6 21:15 samba-client-2.0.8-1.7.1.i386.rpm -rw-rw-r-- 1 root root 968786 Jun 6 21:15 samba-common-2.0.8-1.7.1.i386
We are now ready to upgrade our SAMBA with the new option ready to go! I usually issue a: rpm -Uvh samba*.rpm --force
We now have a "new" version of SAMBA with the option of logging SAMBA users to utmp. This is a nice feature so we can audit when users logged into a particular share. You must also enable this feature in your /etc/samba/smb.conf file before the logging takes place. For more information on this new feature, read the man page man smb.conf