Thursday, November 8, 2007

Samba in Java

I have known about this great open-source library for a long time and have utilized it in just about every java application deployed on a windows corporate intranet - and I am always surprised that so few people know about it. I am referring to the JCIFS library that implements the CIFS/SMB networking protocol in 100% Java.

Windows (NTLM) authentication against a domain controller is as simple as specifying a servlet filter and configuring its properties. ( The below is shamefully :-) copied from the FAQ )




Arbitrary java clients (other than webapps) could use something similar to:

UniAddress mydomaincontroller = UniAddress.getByName( "" );
NtlmPasswordAuthentication mycreds = new NtlmPasswordAuthentication( "ntdom", "user", "pass" );
try {
SmbSession.logon( mydomaincontoller, mycreds );
return true;
} catch( SmbAuthException sae ) {
return false;
} catch( SmbException se ) {

Accessing shared files is as simple as:

try {
SmbFile dummy = new SmbFile( "smb://domain;username:password@server/share/path/to/file.txt" );
SmbFile dest = new SmbFile("smb://server/share/path/to/dir/");

} catch( SmbAuthException sae ) {
} catch( SmbException se ) {

Wednesday, November 7, 2007

Quickstart: libcurl and mingw (plain http)

The win32 builds of libcurl available on the Curl download page have way too many library dependencies (openldap/zlib/openssl etc). That makes sense since curl supports fetching resources using any of those those protocols. However, if all you want to do is just use curl for http use in your program, its simply better to compile the libcurl source to get the tiny libcurl library you need.

The below assumes that you have downloaded and installed mingw and you have mingw32-make in your PATH.

  • Grab the libcurl source from the download page. I took

  • Extract to a directory (preferably without spaces). We'll call this LIBCURL_HOME

  • Open LIBCURL_HOME/lib/setup.h. Add a "#define HTTP_ONLY" (minus quotes ofcourse) just before the first line in the file. This disables all protocols except http. Read LIBCURL_HOME/docs/INSTALL for further information.

  • Open a command shell, change to this directory and use command "mingw32-make mingw32". (Read LIBCURL_HOME/docs/INSTALL for more info on this)

  • After compilation is finished, you should have 'libcurldll.a' and 'libcurl.a' present in LIBCURL_HOME/lib

  • Change directory to LIBCURL_HOME/docs/examples. We'll now attempt to compile and run the simples libcurl example program 'simple.c'

  • Run "gcc -DCURL_STATICLIB -I ..\..\include simple.c ..\..\lib\libcurl.a -lws2_32 -lwinmm -o simple" at the command line. Alternatively you can run
    "gcc -DCURL_STATICLIB -I ..\..\include simple.c -L..\..\lib -lcurl -lws2_32 -lwinmm -o simple.exe".(See Curl FAQ)

  • A file 'simple.exe' should be produced. Running this dumps the home page of curl to stdout as shown below

  • ws2_32 is the winsock library (you can also do -lwsock32), winmm is a library for windows multimedia - as far as I can see there is only one time function used from this library

A trip to Bannerghatta National Park

This is one of the VERY few places near to Bangalore that still has some wildlife and greenery left - and as a result is a standard weekend destination.

I work in SAP Labs and some colleagues of mine from Walldorf wanted to see some tigers and ride some elephants. This was the closest place around where they could get to see some wildlife. Unfortunately for them, the elephants were 'tired' and so there were no rides scheduled that day. However, we opted in for the wildlife safari and could see some critters. They were happy. :)

Here is a cute tiger!

The more-or-less full album at Bannerghatta Pics

Non-optimized videos at:
White Tiger
Bengal Tiger
Lazy Lionesses