Home » tech

Category: tech

Wait…but why? Postfix edition.

While reading some postfix documentation I came across this passage:

New queue files are created with names such as 3Pt2mN2VXxznjll.
These are encoded in a 52-character alphabet that contains digits
(0-9), upper-case letters (B-Z) and lower-case letters (b-z).
For safety reasons the vowels (AEIOUaeiou)  are  excluded from
the  alphabet. The  name  format is: 6 or more characters for
the time in seconds, 4 characters for the time in microseconds,
the 'z'; the remainder is the file inode number encoded in the
first 51 characters of the 52-character alphabet.

First off, thank you to whoever took the time to write this down.

But why?

Let’s step through this:

We know what the queue IDs will look like: New queue files are created with names such as 3Pt2mN2VXxznjll so far so good.

We know their encoding These are encoded in a 52-character alphabet. Hm, a 52 character alphabet is a bit weird is it just upper and lowercase letters? As we see next, it’s digits (0-9), upper-case letters (B-Z) and lower-case letters (b-z). Starting from B is slightly weird too. And now we see why For safety reasons the vowels (AEIOUaeiou) are excluded from the alphabet.

For safety reasons the vowels AEIOUaeiou are excluded from the alphabet.

Aside from being the same alphabet as an early 2000s startup name generator why are these vowels unsafe? Why can we can keep Y and y? Is it the part time vowel status?

Moving on to the rules for encoding a message:

  • 6 or more characters for the time in seconds
  • 4 characters for the time in microseconds
  • the remainder is the file inode number encoded in the first 51 characters of the 52-character alphabet

What time? Unix time? System time? Just calling gettimeofday()? It’s gettimeofday. A quick aside: Postfix doesn’t maintain any sort of source control repository and just distributes code via tarball o_O.

On to the best part the remainder is the file inode number encoded in the first 51 characters of the 52-character alphabet.

And now we throw out another one of the characters from our 52 character alphabet and only use the first 51 for whatever is left after getting the time. The reason for this is that the time/inode separator is ‘z’.

After digging through all of the configuration references and source code I’m left wondering, wait…but why?

Where did the kernel.org git archives go after the hack?

I’ve been building and rebuilding an RPM for git since the RPMs that are published by pbone are full of junk that I don’t want with it i.e., Gitweb, or missing pieces that I do want. The original RPM was built before Kernel.org was hacked (the full story can be found at [TheRegister](http://www.theregister.co.uk/2011/08/31/linux_kernel_security_breach/)) so the sources were pulled from [kernel.org](http://kernel.org/pub/software/scm/git/).

After the hack, the git sources are no longer stored in the same place. There are only a couple of old builds listed in the directory. WHAT THE FUCK? How can all of the sources for git just be gone with no explanation? I asked the same question, there’s not even a note, a bullet, a text file, or anything anywhere explaining why.

Building the manpages for git is a notorious bitch, I’ve tried building them ~10 times and each time fails with some error…after fixing 9 different problems I was pretty much done with it so I thought I’d just download the git-manapages-N.tar.(gz|bz2).

That was the second mistake. Those files were gone too. I know, I’ll just go to the Google Code [git-core downloads page](http://code.google.com/p/git-core/downloads/list)! Any release before 1.7.6 isn’t there. After a couple of hours searching Google, Blekko, and Bing I finally found a couple mirror sites:

[http://distfiles.exherbo.org/distfiles/](http://distfiles.exherbo.org/distfiles/)

[http://ftp.sh.cvut.cz/MIRRORS/sourcemage/mirror/?C=M;O=A](http://ftp.sh.cvut.cz/MIRRORS/sourcemage/mirror/?C=M;O=A)

Those are the only sites I’ve been able to find that have a full set of Git archives including the manpages! Hopefully, the next time someone needs a git archive that was released after 12 September 2011 his/her search will land them here where the links are readily available.

The packages I was looking for were: git-manpages-1.7.4.1.tar.bz2, git-1.7.4.1.tar.bz2, and git-htmldocs-1.7.4.1.tar.bz2. All of which are found there with a quick search.

PostgreSQL CREATE LANGUAGE statements.

Over the last week, as part of my work, I needed to install, enable, and test 3 different procedural modules for PostgreSQL: PL/Tcl, Pl/Perl, and PL/pgSQL. By far the easiest was PL/pgSQL since it comes enabled by default on the database, a user simply needs to run:
CREATE LANGUAGE plpgsql;
After connecting to the database that you want it installed in, e.g., psql -U user.

This doesn’t work if your other languages aren’t installed into the database, you’ll get this error:

Same with PL/Tcl.
At this point you can spend a couple hours reading through this:

http://www.postgresql.org/docs/8.3/interactive/xplang-install.html

And this:

http://www.postgresql.org/docs/8.3/static/sql-createlanguage.html

You’ll get pretty much no where since the only information about installing a procedural language is one that is already installed (very helpful, thanks).

The documentation does allude to some of the helpful pieces in getting the procedural language installed but it doesn’t explicitly state what you are supposed to do. I’m going to do that now. You need to run this command:

From this command you can see that we currently have 3 languages installed PL/pgSQL, PL/C, and an internal language. Note: PL/Tcl and PL/Perl are not installed here, so they can’t be used with the CREATE LANGUAGE command. As long as you’ve installed the correct RPMs or .deb files you will be able to see them here:

This is a list of all of the languages available as a template in your database. Here’s where the docs stop being helpful at all: There is nothing telling you how to manually install pl/tcl or how to manually install pl/perl into a postgres database. Sure, the docs say, if you are installing PL/pgSQL then you can do x…but x doesn’t work the same for PL/Tcl or PL/Perl. There are pages of docs on the handler calls and validator information (this plus a couple thousand lines of C and you’ll have a great validator).

Here’s really how to do it:

CREATE LANGUAGE pltcl;
CREATE LANGUAGE plperl;

That’s it. Because these languages are installed in the pg_pltemplate they only require the create language command so after logging into your database and running the 2 commands above you’ll be able to add them to databases as the user like this:

So, now, look through the docs again – yes _all_ of them. I’ll wait. OK, back? Good, you may say “All of these steps are there; you should have just read more carefully”. True maybe I should have read more carefully, I spent hours going over the documentation and searching, BUT it was on different pages and scattered throughout the entire documentation set for PL and each of the different PLs.

A quick recap of what you need to do to install PL/Tcl manually:

1. Run: select * from pg_language;
2. See if your language is already installed.
3. If not, then you need to make sure it is installed in the system.
4. To see if it is installed in the system run: select * from pg_pltemplate;
5. If your modules are there run: CREATE LANGUAGE pltcl;
6. Log in as the database user and run create language pltcl; to install it for that database.

A quick recap of what you need to do to install PL/Perl manually:

1. Run: select * from pg_language;
2. See if your language is already installed.
3. If not, then you need to make sure it is installed in the system.
4. To see if it is installed in the system run: select * from pg_pltemplate;
5. If your modules are there run: CREATE LANGUAGE plperl;
6. Log in as the database user and run create language plperl; to install it for that database.

That’s it. You’re done. You can go about your business.

A Month of Java Class

Technically it has been more than a month but for the last month, while I’ve been recovering from my surgery and getting sick every 2 weeks I’ve been stuck on a Java program that we were assigned. So it is technically really late, however, medical needs, yadda yadda means it’s not. I’ve finally got it working and I want to, now, share the solution so that if anyone else runs into trouble they can at least use my code for a reference since the rest of the code out there is utter shit.

Here’s the program I wrote, it includes the prompt for the question and a note from my Professor. The book is How to Program Java, Late Objects Version by Deitel:

So that’s my solution for printing a hollow box in Java when you want the perimeter of the box to be a specific size. Here’s some SEO nonsense so people actually find this, print a square in java, print a hollow square in java, java print a square, java print a hollow square. (I don’t normally do that nonsense but rather than someone else spending a bunch of time on this they can get here.)

Here’s a sample of the program output:

![Program output](http://cl.ly/1g082h3X2q280V2S0y3U/iTerm.png)