Posts Tagged ‘subversion’

When you set up a subversion server you can integrate SSPI to use your domain usernames and passwords.

Set up Apache and SSPI

First you need to download the SSPI Module here. Copy the file mod_auth_sspi.so into the Apache modules folder (should be something like C:\Program Files\CollabNet Subversion Server\httpd\modules).

Edit the http.conf file (should be at C:\Program Files\CollabNet Subversion Server\httpd\conf) and add the line

LoadModule sspi_auth_module modules/mod_auth_sspi.so

to the LoadModule’s section. Make sure you insert this line before the line

LoadModule auth_module modules/mod_auth.so

Change the line

AuthType Basic

TO

AuthType SSPI

also replace everything inside “Location /svn” block with this:

DAV svn
SVNParentPath "[REPOPATH]"
 # authentication
AuthName "Subversion Authentication"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIDomain [DOMAINNAME]
SSPIOfferBasic On
Require valid-user
 # authorization
AuthzSVNAccessFile "[REPOPATH]\authorization.conf"

Replace [REPOPATH] with your root repository location (eg. c:\svn_repository) and replace [DOMAINNAME] with your domain controller. If you have no domain name use “domaincontroller”.

Almost done!

The last thing we need to do is add a file authorization.conf in the root of the repository and add these lines…

[groups]
admin = DOMAIN\username, username, DOMAIN\username2, username2
[/]
@admin= rw

You will notice we add an entry with the domain prefix and an entry without. This is because apache authenticates differently and we need both. You can make new groups etc. If you need security for specific repositories you can read further here


When you are in a big team of developers and using continuous integration, it really helps to receive an email when someone adds code to the repository. One way to do this is to create a ‘post-commit’ hook in your subversion repository.

Locate your repository on the server and find the folder ‘hooks’. Here you can create a .bat file which will contain the necessary script to send the email.
Lets go ahead and create a file called ‘post-commit.bat’. All you need to put in this file is the following:

C:\[PATH-TO-REPOSITORY]\sendmail.bat %1 %2

We will create another batch file that will, in this case, read a list of comma seperated email addresses from a file called ‘email.txt’. You may also just add the emails directly in the batch file, but I find it easier to manage with a simple txt file. (note that ‘Blat’ is being used as email tool, but you can use any command line email tool you prefer)

Below is the contents of the sendmail.bat file:

SET REPOS=%1
SET REV=%2
SET LPath=C:\svn_repository\

ECHO Repo: %REPOS% >> %LPath%log.txt
ECHO Rev: %REV% >> %LPath%log.txt

SET LOG_FILE=%LPath%svnfileR-%REV%.txt
SET LOG_FILE1=%LPath%svnfileR1-%REV%.txt
SET LOG_FILE2=%LPath%svnfileR2-%REV%.txt
SET AUT_FILE=%LPath%svnfileA-%REV%.txt

"C:Program FilesCollabNet Subversion Server"\svnlook info -r %REV% %REPOS% > %LOG_FILE1%
"C:Program FilesCollabNet Subversion Server"\svnlook changed -r %REV% %REPOS% > %LOG_FILE2%
copy %LOG_FILE1%+%LPath%spacer.txt+%LOG_FILE2%+%LPath%spacer.txt+%LOG_FILE%

"C:Program FilesCollabNet Subversion Server"\svnlook author -r %REV% %REPOS% > %AUT_FILE%

REM SET THE AUTHOR FROM THE FILE.
FOR /F %%A IN (%AUT_FILE%) DO SET AUTHOR=%%A

SET EMAILFILE=%LPath%emails.txt
FOR /F %%A IN (%EMAILFILE%) DO SET EMAILS=%%A

ECHO Executing: %LPath%blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% New Revision: %REV%" >> %LPath%log.txt
%LPath%blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% on %REPOS% @ %REV%" >> %LPath%log.txt -server L060 -f BuildMaster@someplace.com

del %LOG_FILE%
del %LOG_FILE1%
del %LOG_FILE2%
del %AUT_FILE%