Using perl to access CIFS

camel

This perl module allows for the connection and maniputlation of windows CIFS shares using samba’s smbclient.

Installing using CPAN

installing Filesys-SmbClientParser using cpan fails upon make test. Not good.

Manual install

Download file from cpan.org and run perl Makefile.PL. You will be prompted if you want to test the build with server, username and password information. It still fails.

Correct bad makefile

The make tests fail because the author of the module has hard-coded the paths of where to find the smbclient binary: /usr/bin, /usr/local/bin, /opt/bin or /usr/local/samba/bin/. Smbclient was installed using blastwave csw, ‘/opt/csw/bin/smbclient’.

Create a symbolic link in one of the expected paths:

cd /usr/local/bin
ln -s /opt/csw/bin/smbclient .

Running ‘make test’ will now be successful.

Copy certificate revocation lists to public webserver

In order for our certificate server to work properly, we need to periodically update the directory http://www.gemini.edu/repository/” with two certicate revocation list files.

Since the server that creates the files is Windows based, the following perl script was used and run every hour in cron:

#!/opt/csw/bin/perl -w

#Use smbclient to copy certification revocation files to
#http://www.gemini.edu/repository diretory
#from windows CIFS share
#Jason Kalawe, 5/24/2007

  use Filesys::SmbClientParser;
  my $smb = new Filesys::SmbClientParser
  ('/opt/csw/bin/smbclient',
   (
    user     => 'user',
    password => 'pass',
    workgroup => 'GEMINI',
    host => 'host',
    share => 'CertConfig',
    debug => '0'
   ));

  #Change local directory to /repository directory
  chdir('/export/web/docs/gemini/repository');


  #Copy specific files from share root directory
  $smb->get('file1');
  $smb->get('file2');

  #Depecrated due to sensitive files in directory
  #Need to only copy specific files listed above
  #Copy all files in remote directory, recursively on 1 level
  #$smb->mget('*',1);

# Test Code to List content of current directory
#  my @l = $smb->dir;
#  foreach (@l) {print $_->{name},"n";}