Critical Section

Archive: August 24, 2015

performing HTTP authentication in CGI

Monday,  08/24/15  05:13 PM

Pardon this nerdy post, but here is how you can do HTTP authentication processing in a CGI program.  The Internet doesn't know how to do this, and I do.  So here you go, Internet.

Here's how HTTP authentication works.  A request is sent to a server, and if there is no authentication the server responds with a 401 status.  This causes the client (browser) to prompt the user for a username and password.  When entered, the username and password are combined and sent to the server in the Authorization: header, like this:

Authorization: basic <username:password>

The <username:password> part is base-64 encoded, which is *not* encryption, so to avoid sniffing this should only be done on an SSL-encrypted (HTTPS) connection.

The server validates the username and password, and if there's a problem, it sends back a 401 status again.  If everything is okay, it processes the request, such as executing a CGI program.  So far so good.

Now ... what if you don't want the server to perform authentication for you, and instead, want to perform the authentication inside the CGI program itself?  Aha, glad you asked!

You have to modify the Apache [webserver] configuration, as follows:

... in modules section, if not already enabled:
LoadModule authn_anon_module modules/

... in server section, or in <VirtualHost>:
SetEnvIf Authorization (.*) HTTP_AUTHORIZATION=$1

... in appropriate <Directory>:
AuthName "My auth realm"     (required; default if realm not set)
AuthType Basic               (username:password, base64-encoded)
AuthBasicProvider anon       (use anonymous auth)
Anonymous *                  (allow any username)
Anonymous_NoUserID on        (optional, ok if username blank)
Anonymous_MustGiveEmail off  (optional, ok if password blank)
Require valid-user           (optional, forces auth processing)

Here's what's happening.  Loading mod_authn_anon enables the use of a "AuthBasicProvider anon " directive.  That's the secret sauce.  The "Anonymous * " directive allows any user through the server checking.  Once through the server checking, the SetEnvIf directive sets an environment variable named HTTP_AUTHORIZATION with the value of the Authorization: header, from where it can be accessed by the CGI program.

You can tune the way this works a bit.  The "Require valid-user " directive means the initial 401 will be sent (because there is no Authorization: header), so you will always prompt for entry of a username and password.  That's probably what you want, but if not, you can omit this directive in which case no Authorization: at all is okay and a blank value will be passed through to the CGI.  The "Anonymous_NoUserID on " directive allows a blank username; if omitted, a blank username will be treated like a missing Authorization: header, and a 401 will be returned by the server.  The "Anonymous_MustGiveEmail off " directive allows a blank password; if omitted, a blank password will result in the server returning a 401 directly.  (The anon mechanism was initially devised for anonymous FTP, where an email address is often supplied as the password.)

Note that in all cases the CGI can return a 401 itself by writing a "Status: 401 " header, which will cause the client (browser) to prompt for a username and password again.

Trust me, this works, and I tried just about everything else.  You are welcome!


Archive: August 27, 2014


Archive: September 1, 2013


Archive: September 1, 2012


Archive: September 1, 2011

on the horizon (New Yorker 8/29/11)

Thursday,  09/01/11  10:34 AM


"on the horizon"

a perfect end-of-summer cover



Archive: September 1, 2010


Wednesday,  09/01/10  10:35 PM

Dodger Stadium - the Center of the UniverseIn the middle of the world's longest week, sitting in on a sales training class at Aperio, and doing a few hundred other things in parallel :)  but of course I have time to make a filter pass...

Last night we took our sales team to Dodger Stadium - aka the Center of the Universe - to watch the Phillies beat the Dodgers.  Final score hot dogs 3 beers 5.  A great time was had by all.

And so Apple announced:

  • They have shipped 120M iOS devices.  Wow.
  • iOS 4.1.  Bug fixes (!), HDR photos, HD upload, TV rentals, Game Center.  Yawn.
  • iOS 4.2 (for iPad).  iOS 4.1 stuff + Airplay media streaming.  So be it.
  • new iPod ShuffleRedesigned iPod Shuffle.  Cute.  So be it.
  • new iPod NanoNew iPod Nano.  Touchscreen!  But no camera, and no video.  And it is *not* an iOS device.  Huh.
  • New iPod Touch.  Retina display, front and back cameras, Facetime, HD video recording.  An iPhone4 without the phone.  Expected, but nice.
  • iTunes 10... new logo :)iTunes 10 with "Ping" social network.  Interesting, this I could see using myself... what are my friends listening to, and how do they like it?  Also interesting, they changed the logo to get rid of the CD.  Hah.
  • new AppleTV...and one more thing... A new AppleTV!  Teeny, cheep ($99), no internal disk, rental only.  New UI but not an iOS device, no apps.  Interesting.

A classic Jobsnote, enjoyed watching/listening to the master :)  it was notable that he alluded to some failures or non-successes too; the bug fixes in iOS, bringing buttons back on the shuffle, AppleTV being a "hobby".  It worked.

ArsTechnica posted their usual nice overview of the announcements.

[Update: Ping is a big disappointment.  It might get better, but right now I have no friends, and there's no there there.]

In the real world, worst August for stocks since 2001, not to mention problem bank list climbs to 829.  So much for that "Summer of Recovery", huh?


Archive: September 1, 2009


Tuesday,  09/01/09  09:20 PM

I have to agree with Dick Cheney on this one: "We had a track record of eight years of defending the nation against any further mass casualty attacks from Al Qaeda.  The approach of the Obama administration should be to come to those people who were involved in that policy and say, how did you do it?"  Yeah, but...

L.A.'s Station FireI won't do much news-blogging here, but the fires surrounding L.A. are pretty horrible.  The Station Fire is the worst, and seems to be getting worse :(  Whenever we have these fires, I have to say I am so grateful to the firefighters; we are fortunate there are people who are willing to do those risky jobs.

supertanker - a firefighting 747One of the weapons used by the firefighters is this supertanker 747, which can drop 20,000 gallons of fire retardant chemicals in one shot.  Excellent...

Martin Mars flying tankerBut even more excellent is this Martin Mars, a WWII-vintage flying boat converted into a tanker which can scoop up and deliver 7,000 gallons of water at a time. How cool is that?

Apple event: it's only rock and roll (but we like it)Apple are planning one of their famous "events" on 09/09/09: It's only rock and roll (but we like it).  Fueling speculation about what will they announce.  Not their oft-rumored tablet, surely, not with that tagline...  actually the big rumor is that Steve Jobs himself will preside!

imaginary concertsThis is really cool: the New Yorker's music critic Alex Ross considers Imaginary Concerts.  "Some authors have accomplished the rare feat of inventing musical works that seem nearly as real as those we have heard."  And so now we have to ask, what makes them beautiful?  It can't be anything happening at the ear level, since this music doesn't even exist.  Somewhere in your brain you can synthesize the same sort of signal stream that results from sensory input.  I'm listening to Metallica's Enter Sandman just now...  in my head.

Hyundai Equus - a would-be Lexus competitor?So, is the Hyundai Equus a genuine Lexus competitor?  I don't know about that... it might be a fine car and seems to be not-hideous-looking, but the branding isn't there for Hyundai.  Very hard to live that "low-end" reputation down.  Although I guess it is worth noting, Toyota had it at one time, and they've successfully gotten rid of it...

Tesla Model S - the real competition for Lexus and EquusHere's the real competition, the Tesla Model S.  Beautiful and all-electric, and coming in for about the same price as the Equus.  Or so they say...

The New Yorker has a fascinating article about Elon Musk, Tesla's co-founder and CEO, and the quest to make a business out of selling electric cars.  They really seem to have a chance.

Space Shuttle blasts off (at night!)Boing Boing: Why the Space Shuttle should always take off at night.  It's those beautiful pictures, stunning, as the Discovery blasts off into space...

...but SpaceX has won a contract to resupply the ISS, replacing space shuttles for that purpose.  Congratulations to them, and to us taxpayers, that will save a ton of money.

An interesting concept: things that are better than a New York City hot dog.  I could think of a few, starting with an L.A. City hot dog :)  Actually it is a good list; I particularly like "Prince Edward Island", for sheer randomness.

Woman fired for using upper-case only in email.  AS SHE SHOULD BE.

George Hincapie wins U.S. Pro Road Race championshipDave Zabriske wins U.S. Pro Time Trial championshipCongratulations to George Hincapie, who won the U.S. Pro Road Racing championship (his third), and Dave Zabriske, who won the U.S. Time Trial Racing championship (his fourth).  They will represent us well as they wear the stars and stripes next year!

The ZooBorn of the day: An adorable newborn Zebra
Looks a little like George and Dave, doesn't it :)
ZooBorn: newborn Zebra


televisions everywhere (and it sucks!)

Tuesday,  09/01/09  10:19 PM

our future is BrazilHave you noticed, as I have, that TVs are sprouting up everywhere?  I guess you could hardly miss it, but what a horrible trend.  Just as everyone is bemoaning the death of mainstream media and how there's 600 channels and nothing on, we are slowly but surely turning into Brazil (the movie, not the country).

I've noticed this for a while now - flatscreen technology has made it easy to stick TVs everywhere, and somehow because something is possible it is considered desirable.  I hated it when airports filled up with CNN (still do).  I hated it when restaurants filled up with sports (still do).  Note: restaurants, not sports bars, we must keep the distinction clear, although what with TVs everywhere, soon there won't be a distinction.

TVs everywhere! - not a good trend...The other day I found TVs in my supermarket.  Time to change markets, but it won't help; soon every market will have them.  The other day I found TVs next to my gas station's pumps.  Time to change gas stations, but it won't help; soon every gas station will have them.  The other day I found TVs in my favorite breakfast dive, the Denny's in San Juan Capistrano.  Time to change places to eat breakfast, but it won't help; soon every breakfast place will have them.

The worst part of this trend is when the sound is on.  There's a little boutique hotel in Carlsbad called the West Inn, I stay there often, it's a nice place.  But in the breakfast room they have not one not two but three TVs, each tuned to a different channel, with the sound on!  And not a remote control to be found.  How anyone can eat breakfast with CNN, a reality show, and kids cartoons blaring at you is beyond me.  I shall no longer eat breakfast there, even though it's good and included with the room; it is a lousy way to start the day.

There's a TV in my company's lunchroom, always on, usually surrounded by people watching.  The new opiate of the masses, to be sure.  Anyway I hate this trend, I hate it.  I hate it a lot.  It's enough to make me carry one of those remote controls that turn off every TV.  Which will probably not work, just make me unpopular.  I must tell you, I regard this as a leading indicator of Unnatural Selection...


Archive: September 1, 2008

(New Yorker 09/1/08 - McCain, PO'W')

Monday,  09/01/08  07:40 PM


McCain, PO'W'


Monday,  09/01/08  07:43 PM

Woo hoo, September!  And...  Labor Day.  I labored at doing nothing today, did a little coding, a little football watching, a little hanging out.  Today is traditionally our last day of heating the pool for the summer, after this, the weather cools down, the kids are in school, and no swimming takes place.  I'm heading into a busy week with a lot going on and travel to Boston and New York at the end of it, so I rested up.

My server continues to labor, yesterday I mentioned I served over 4,800 pages (ended up over 5,000), today, over 2,400 so far...  and a ton of hits, too, mostly images (thar be hotlinkin' goin' on out thar).  So be it...  I don't have the energy or inclination to figure out what's going on, but I like it.  Welcome!

So it's curtains for Gustav, and now we await Hanna, Ike, and Josephine.  Welcome to the hurricane season, whew.  Not to trivialize the damage caused along the Gulf Coast, but the longest-lasting impact of Gustav was that it kept George Bush from speaking at the GOP convention in Minneapolis.  As noted in the New Yorker cartoon I just posted, he remains McCain's biggest liability, and although it would have been weird not to have the sitting President speak, it was fine that [because of Gustav] he didn't.  The GOP can now resume the convention with speakers like Giulani...

Google Chrome logoThe big news today was Google's Chrome, a new browser.  Or a new Web Operating System, if you prefer.  The idea that Google would do something like this has a pretty long history, as noted by Jason Kottke, why do it now, when Firefox has taken off so nicely?  Looking through comic book in which Google explains the plan, it seems the main reason is to have an architecture with separate processes for each tab / window, in order to get more parallelism for background tasks.  I guess that makes sense.  In conjunction with various client-side web applications (written in JavaScript), over time this could end up being a major threat to Windows.  We'll have to see how it plays out...

nested Klein bottlesCheck out these amazing nested Klein bottles...  3D equivalents to the 2D Mobius strip (Klein bottles have only one surface, Mobius strips have only one edge).  Beautiful, on two levels.

sabot on WestlakeThis is cool: Yacht Club prepares children for sailing, an article about the Westlake Yacht Club's summer sailing academy.  My kids are all happy graduates :)

As a veteran C++ programmer, I look over into the Objective-C world with curiosity and confusion.  Although superficially similar, they aren't really, and the difference is illustrated by the new blocks feature being added to Objective-C.  It is clearly more "dynamic" than statically compiled C++...

A great rant from ex-uncov-er Ted Dzuiba: OpenID is why I hate the Internet.  The real subject is "why I dislike OpenID", and the observations are accurate and compelling.  There is no way this is going to succeed, he's right.



Archive: September 1, 2007


Archive: September 1, 2006


Archive: August 14, 2005

losing something

Sunday,  08/14/05  09:08 AM

I had a random thought last night which I thought I'd share.  There is a visceral human reaction to losing something.  People never ever want to give up something they feel they already have.  This is not a cold logical calculation, even if you give people something which is way more valuable than the thing you're taking away, they hesitate.  (This is why FREE is the most powerful word in marketing :)

The idea of accumulating "stuff" must have hit early on in the evolution of humans.  Anthropologists tell us we were herders, and [probably] harem-based, and both of these imply possession.  Intelligence may have evolved so we could evaluate trades.  Anyway however it happened, it is now true; we are materialistic.  Any human society which has attempted to deny this has failed, and the human society which is most successful is the United States, which celebrates materialism and features it as a core value.  One of the first things that must happen to transform a failed state is some sort of rule of law, including some rights to personal possession.

Losing something doesn't only mean losing an object, it can also mean losing a right, such as freedom.  And losing rights provokes even more of a reaction than losing objects.  Tell someone they can't do something, especially something they could do yesterday, and you are going to get strong resistance.

The implications of this for businesses are significant, especially those targeting consumers.  Any product or service which trades one thing for another is going to have tough sledding compared to a product or service which gives you something for nothing.

Media companies are finding this out the hard way.  Consumers do not want products with strings attached.  They are used to buying something, and owning it, and having complete freedom to do with it what they want.  Any kind of restriction is taking that freedom away, and is going to piss people off.  It isn't just that they won't buy the product or service - although they won't - it's that they're actually going to be insulted and angry.  Look at the way consumers have reacted to DRM.  ("You mean I buy it, but then I can't do what I want with it?")

Consumers don't do a logical calculation and say, okay, I get it, I pay you $X and get Y product with Z strings attached.  No.  They say, no way, if I give you $X for Y product I expect zero strings attached.  Don't take my freedom!  I hate losing something!


175 505s!

Sunday,  08/14/05  10:12 AM

From Sailing Anarchy, a great blog (which unfortunately does not have permalinks):

Is this the largest fleet for a World Championship?  175 505's are registered for the CSC 2005 505 World Championship in Warnemunde, Germany!  And yes, they will all be racing on the same course, at the same time.  Team USA is 10 boats strong, and I think it's noteworthy that Howie Hamlin and Cam Lewis are sailing together again, with a combined age of about 100!  On the other side of the spectrum, California high school sailing phenom, Parker Shim, has bought a boat and will also be competing.

Can you even imagine 175 505s on one start line?  Good thing they use a rabbit start.  I would not bet against Howard and Cam, man, what an all-star team!

505 start - watch the rabbit!

A 505 start
The boat on port tack is "the rabbit", everyone else starts on starboard and must duck the rabbit.
Typically the rabbit is the boat which finished 10th in the previous race.

I sailed in the 505 worlds at Kingston, Ontario, back in 1990.  "Only" about 100 boats.  We sailed our asses off and finished about 40th.  I really think boat-for-boat the 505 fleet is the strongest in the world.  If you win the 505 worlds, you're my hero.


Archive: September 1, 2004


Archive: September 1, 2003

Blind Watchmakings

Monday,  09/01/03  09:33 PM

long-horned beetles
from the Insect Company
(click for larger view)

blind watchmakings
Blind Watchmakings
from Richard Dawkins
(click for larger view)

I recently discovered The Insect Company website, which has fascinating photo galleries of beautiful and interesting insects.  [ via Boing Boing ]  An example is shown at right; Cerambycidae are long-horned beetles, and this gallery shows the variations from different countries.  I was awestruck by these wonderful examples of Darwinism in action; for me this was a religious experience.

In paging through these photos, I was reminded of the amazing software Richard Dawkins wrote to accompany his 1986 classic, "The Blind Watchmaker".  (If you have not read this book, then STOP, do not pass go, and immediately order it.  You will thank me.)

Chapter 3, Accumulating Small Change, is an in-depth exploration of a synthetic organism-producer Dawkins developed to try out the ideas behind the book.  This is a Macintosh application which generated "biomorphs", 2D black and white organism-like configurations of pixels which were generated algorithmically from a set of variables ("genes").  From any biomorph "children" are generated by mutating the variables.  You then select which children survive to generate children themselves, and thereby "breed" generation after generation of evolving biomorphs.

BTW, I just ran the Mac application again.  This 17-year-old program still runs!  (OSX emulating OSn and PowerPC emulating 68000.)  Pretty nice GUI, despite being black and white, and awesome functionality.

An example of biomorphic evolution is shown at right.  Each of these "organisms" differs from the previous by a single mutation in one of the "genes".  The visual similarity to the beetles is profound, and to my mind not coincidental.

There is one big qualitative difference between the beetles and the biomorphs; the beetles are naturally selected, while the biomorphs are not.  In each generation of beetles the fittest survive to have offspring.  The variation among beetles from different countries presumably reflects different environments (food, predators, habitat, weather, etc.).  In each generation of biomorphs the program user performs the selection, using morphological similarity to actual organisms as a measure of "fitness".

Or based on visual similarity to some other target; when the book was first published Dawkins offered a $1,000 prize for anyone who could "breed" an image of a chalice, "the Holy Grail".  To his surprise, a Caltech student claimed the prize within a year.  Subsequently a new prize of $1,000 was offered for breeding an image of a human, but this has not to my knowledge been claimed.

Biomorphs are generated from sixteen variables ("genes"), each with a range of 20 values ("alleles").  There are thus 16^20 possible biomorphs.  Mimicking biology, one of the genes controls the magnitude of mutation which can occur in one generation (variation in alleles), and another the range (number of genes which mutate).  These genes can of course themselves mutate, so that some biomorph populations are relatively stable from one generation to the next, while another might vary wildly.  The capacity of the program to surprise you from one generation to the next will, er, surprise you.  Fans of Stephen Gould will also note the "hopeful monster" mode, in which an entirely new biomorph is randomly generated!

Great stuff.  What is most amazing is that evolution has resulted in creatures sophisticated enough to generate algorithmic models that mimic evolution!


Monday,  09/01/03  11:31 PM

International Space StationI kind of forgot about this, but the International Space Station is still up there, and still manned with one U.S. and one Russian Astronaut.  Since we're not flying shuttles right now, the Russians have been flying up supplies.  Amazing how this went from big news to no news.

Wired: Why Apple is so Tempting.  "Why doesn't some ambitious company with deep pockets and distribution muscle adopt Apple and hold it aloft as the trophy it really is?"  I sure hope someone doesn't buy Apple, despite the temptations; it is a great company the way it is, profitable, innovative, and fun!

Magink billboard"Digital ink" is getting real.  Magink billboards can hold their images for up to 12 years without power.  Wow.  And the mechanism sounds like something from science fiction, "Magink uses tiny helix structures, which don't actually contain any color.  Instead, the helixes, functioning like microscopic machines, can be controlled with electrical currents to make them longer or shorter, acting like tiny prisms, reflecting the bands of the spectrum needed to render the required colors.  When black is needed, the helix is instructed to change its pitch and lie down, allowing light to enter it and reflect the black backing of the display."  Great time to be alive, eh?  [ via Gizmodo ]

Panasonic camcorderCheck out this new camcorder from Panasonic.  Man, is that tiny!  (Perfect for putting in a backpack, and recording from a helmet-cam while mountain biking!)  [ via Gizmodo ]

New Scientist reports Origami Helps Cellphone Camera to Focus.  Great, now we'll have zoomed blurry pictures on everyone's blogs :)

Toyota self-parking PriusOh, and this is cool - Toyota has come out with a self-parking car!  This sounds like science fiction.  "Toyota's new hybrid gasoline-electric Prius sedan uses electrically operated power steering and sensors that help guide the car when reversing into parking spaces."  So if they can do that, they could certainly build a caravan feature, right?

This looks like a great book:  In the Blink of an Eye, by Dr. Andrew Parker.  The Age published an article which reviews the book.  The main idea seems to be that the evolution of the eye triggered the Cambrian explosion.  I've ordered it, stay tuned for my review...  [ via razib ]

Interestingly, the development of the eye is often cited by critics of evolution by natural selection; the argument being, essentially, "of what use is half an eye".  (Richard Dawkins answers this objection convincingly in Climbing Mount Improbable.)  So here we have another good answer - any light sensitivity at all would have been such a selective advantage in the early Cambrian period that it was immediately adopted!  (Literally "in the blink of an eye"; less than 400,000 generations.)

TidBITS notes:

"Virtual PC 6.1 for Mac will not work on Apple's new Power Mac G5.  Unlike the PowerPC G3 and G4 chips, the PowerPC G5 processor does not support a feature known as pseudo little-endian mode, which Virtual PC uses to emulate a Pentium processor. Microsoft is reportedly working on a fix, but it requires significant engineering work, and no time frame has been given."

Ha!  Back in a previous life I coded a simulator for the IBM Series/1, which was big-endian, to run on the DEC VAX, a little-endian machine.  Handling the cross-endian data representation was a major difficulty which we finally evolved an elegant solution to handle.  Ironically the simulator ended up running on the IBM PowerPC, which was also big-endian, but the simulator could have been compiled to run on anything.  Perhaps I should offer my services to Microsoft :)

P.S. Somehow a version I compiled for the Mac got out onto the 'net.  I love the description :)

Can you image the reaction someone from fifty years ago would have to reading my 'blog?  Every day there's all this amazing stuff, and it all feels like stuff from the future, but it is here now!  Heck, even someone from ten years ago would be amazed!  (Makes you wonder what a 'blog from ten years into the future would look like :)


'14   '13   '12
'11   '10   '09
'08   '07   '06
'05   '04   '03
flight  X
About Me

Greatest Hits
Correlation vs. Causality
The Tyranny of Email
Unnatural Selection
Aperio's Mission = Automating Pathology
On Blame
Try, or Try Not
Books and Wine
Emergent Properties
God and Beauty
Moving Mount Fuji The Nest Rock 'n Roll
IQ and Populations
Are You a Bright?
Adding Value
The Joy of Craftsmanship
The Emperor's New Code
Toy Story
The Return of the King
Religion vs IQ
In the Wet
the big day
solving bongard problems
visiting Titan
unintelligent design
the nuclear option
estimating in meatspace
second gear
On the Persistence of Bad Design...
Texas chili cookoff
almost famous design and stochastic debugging
may I take your order?
universal healthcare
triple double
New Yorker covers
Death Rider! (da da dum)
how did I get here (Mt.Whitney)?
the Law of Significance
Holiday Inn
Daniel Jacoby's photographs
the first bird
Gödel Escher Bach: Birthday Cantatatata
Father's Day (in pictures)
your cat for my car
Jobsnotes of note
world population map
no joy in Baker
vote smart
exact nonsense
introducing eyesFinder
to space
where are the desktop apps?