Parrot authentication handlers

jhorwitz on 2004-10-20T18:11:34

You can now write Apache authentication handlers in Parrot (release pending). Behold, a handler that accepts any basic authentication with a password of 'squawk':

In handler.imc: .namespace [ 'MyAuthHandler' ]

.sub _handler .local pmc r .local pmc ap_const .local string pw .local int status

find_global ap_const, 'Apache::Constants', 'ap_constants'

# get the request_rec object find_type $I0, 'Apache::RequestRec' r = new $I0

# decline if not the initial request $I1 = r.'is_initial_req'( ) if $I1 != 1 goto auth_declined

(status, pw) = r.'get_basic_auth_pw'( )

if pw != 'squawk' goto auth_failure $I0 = ap_const['OK'] goto auth_return_status

auth_failure: $I0 = ap_const['HTTP_UNAUTHORIZED'] goto auth_return_status

auth_declined: $I0 = ap_const['DECLINED'] goto auth_return_status

auth_return_status: .pcc_begin_return .return $I0 .pcc_end_return .end
In httpd.conf: ParrotLoad /tmp/handler.pbc ParrotAuthenHandler MyAuthHandler AuthType Basic AuthName "Parrot Test" Require valid-user