NET::LDAP Active Directory SID Unpack

I was searching high and low for a way to unpack what NET::LDAP was returning for an objectSID. When dumped, it was just a bunch of line noise garbage. Trying to figure out what format it was in I came across this:

Re: Getting Active Directory objectsid value using Net::LDAP - Help!

c. church says:

Looking on MSN, which describes the SID structure (urL :http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/Security/sid_components.asp) it seems to say this:

the for…

Strawberry Perl uninstall / Active Perl install Issues on Windows

I have had a little problem getting a working Perl on Windows over the past few days. I was having a lot of trouble somehow getting a working dmake and mingw to compile code, among other things.

Here's what happened in my latest attempt, for your benefit:

  1. Created a clean Amazon EC2 Windows 2008 server.
  2. Installed Strawberry Perl 5.12. Had issues compiling modules with cpan. Uninstalled Strawberry Perl.
  3. Installed ActivePerl 5.16.3. Ran cpan, dmake and mingw downloaded and installed properly. Rebooted so %PATH% would be updated.
  4. Tried installi…

Initself's Retarded Guide to Building a Package

To build a package, use Module::Install, ya turkey!

cpan Module::Install


Make a directory for your package to reside:

mkdir /home/you/My-Package


Put your module in the 'lib' directory. This is where all your code is going to live.

mkdir lib
mkdir My
touch My/Package.pm


Put your code in My/Package.pm, or copy the file you already wrote here.

Then, create a Makefile.PL in /home/you/My-Package:

use inc::Module::Install;

# Define metadata
name           'My-Package';
perl_version   '5.006';
version        '0.01';
license        'perl';

# Specific dependencies
test_requires  'Test::More'  => '0.42';

WriteAll;


Then, just run your new shiny file, pal!

perl Makefile.PL && make && make install && make clean && rm Makefile.old


While your at it, put that in a file called 'install.sh' so you can execute that each time you install it. You've gotta be root to run this sucker!

sudo sh install.sh


Afterwards, your directory will looks like this:

inc/  install.sh*  lib/ Makefile.PL  META.yml


You're installed!

Initself's Retarded Guide to Creating a Package

Here's my definitive guide to creating a Perl package (non-OO) for retards.

# where package is My/Package.pm
package My::Package;

# You can put it in the root directory if you wish
# and refer to it just as Package.pm, but try create your own namespace 
# if you can
#
# package Package;

use warnings;
use strict;
use base 'Exporter';

# you will have your sub automatically accessible
our @EXPORT = qw(your_sub); 

# Or, you can choose to explicitly import your subroutine name like
# this in your calling code: use My::Package qw/your_sub/
#
# our @EXPORT_OK = qw(your_sub);  

sub your_sub {
  return "foo";
}

1; # return a true value at the end of your module to keep things happy

Here's how you use it.

use My::Package;
my $bar = your_sub(); # $bar is now 'foo'

Listing All Installed Programs in Windows XP

I wanted to get a list of all the programs installed on my computer listed in 'Add or Remove Programs' in the Control Panel in Windows XP. Win32::TieRegistry provided a nice way to do this.

#!perl
use warnings;
use strict;
use Data::Dumper;

my $Registry;

use Win32::TieRegistry (
  Delimiter   => "/",
  ArrayValues => 1,
  TiedRef     => \$Registry,
 );

my $regkey = 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Uninstall/';

my @install_names;
foreach my $software ( values %{$Registry->{$regkey}} ) {
  next unless my $software = $software->{DisplayName};
  next unless $software->[0];
  push @install_names, $software->[0];
}

print "$_\n" for sort {lc $a cmp lc $b} @install_names;

Win32::TieRegistry installs along with Strawberry Perl.