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 )


<filter>
<filter-name>NtlmHttpFilter</filter-name>
<filter-class>jcifs.http.NtlmHttpFilter</filter-class>

<init-param>
<param-name>jcifs.http.domainController</param-name>
<param-value>192.168.2.15</param-value>
</init-param>
<init-param>
<param-name>jcifs.smb.client.logonShare</param-name>
<param-value>JCIFSACL</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>NtlmHttpFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


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

UniAddress mydomaincontroller = UniAddress.getByName( "192.168.1.15" );
NtlmPasswordAuthentication mycreds = new NtlmPasswordAuthentication( "ntdom", "user", "pass" );
try {
SmbSession.logon( mydomaincontoller, mycreds );
// SUCCESS
return true;
} catch( SmbAuthException sae ) {
// AUTHENTICATION FAILURE
return false;
} catch( SmbException se ) {
// NETWORK PROBLEMS?
se.printStackTrace();
}


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/");
dummy.copyTo(dest);

} catch( SmbAuthException sae ) {
sae.printStackTrace();
} catch( SmbException se ) {
// NETWORK PROBLEMS?
se.printStackTrace();
}

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 curl-7.17.1.zip.


  • 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

Thursday, November 16, 2006

Elune Evensong/Moonsong - Avatar of Elune, Moon Goddess (Fantasy)


Anybody
who has played Warcraft / World of Warcraft knows who is Elune. For the un-initiated, please do refer WoW or Wikipedia!

I do doubt however, that any male is so terminally affected with fantasy that he would day-dream about a goddess's avatar - and an imaginary one at that! I do have the small saving grace that her picture in my mind is not the conventional one of a beautiful Night Elf. No, not at all.. it's one of a spectacular High Elf - one whom I keep dreaming about.

Goddess, Hear my call ! (thats one of the game character voice bites)

Her mane is spun from fair moonlight,
Her eyes are a mirror to the artic sky!
Her voice - a blend of crystal chimes,
Her smile can melt the Sun to cry!

Her verve - the vigor of monsoon wind,
Her art - the height of arcane skill!
Her sight can make any pain rescind!
Her love - the promise of trust fulfilled!
...and her kiss can cause burns on skin!.. :-)

(to be filled in)

Limerick of Inauguration



I have been an on-off blogger for quite some time now, but of the, um.. academic kind using services such as what jRoller , et al offer. I never felt comfortable making posts of a personal nature using those services - I always felt that was the privilege of , ah , rather more accomplished professionals.

And hence this very late blogspot registration, where I can comfortably sink into mass mediocrity without even the slightest twinge of guilt or sentiment.

A toast imaginary readers! A toast to yet more wasted bytes 'an bandwidth ...so please do chant this limerick with me! (which like nearly every other limerick has been begot by reality)

There once was a techie in the city,
Who blogged every little itty-bitty,
He posted thrice every day,
Even with nothing to say,
Till he was hired by a union committee!