Produced by Araxis Merge on 3/29/2017 4:53:20 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | CTT-DM CIF Submission.zip\code\apache_extensions\perl\modules\Prisme | ValidateHeader.pm | Fri Mar 3 16:22:14 2017 UTC |
| 2 | CTT-DM CIF Submission.zip\code\apache_extensions\perl\modules\Prisme | ValidateHeader.pm | Tue Mar 28 17:52:01 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 336 |
| Changed | 2 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | #must be i n a direct ory named 'Prisme' | |
| 2 | package Pr isme::Vali dateHeader ; | |
| 3 | ||
| 4 | use strict ; | |
| 5 | use warnin gs; | |
| 6 | use Apache 2::Const q w(FORBIDDE N OK); | |
| 7 | use Apache 2::Log; | |
| 8 | use Apache 2::Request Rec; | |
| 9 | use APR::T able; | |
| 10 | #require ' constants. pl';# done in http.c onf | |
| 11 | use LWP::U serAgent; | |
| 12 | use URI; | |
| 13 | my $ua = L WP::UserAg ent->new( ssl_opts = > { verify _hostname => 0 } ); | |
| 14 | use JSON; | |
| 15 | ||
| 16 | #print "My lease wil l last for $CONST::S ECONDS_CAC HE seconds !\n"; | |
| 17 | my %cache_ hash; | |
| 18 | $cache_has h{'lease'} = {}; | |
| 19 | $cache_has h{'roles'} = {}; | |
| 20 | my $json_d ecoder_rin g = JSON-> new; | |
| 21 | ||
| 22 | sub allowe d($$) { | |
| 23 | my $roles = shift ; | |
| 24 | my $logger = shift; | |
| 25 | my @role_nam es = @$rol es; | |
| 26 | ||
| 27 | my %union = my %isect = (); | |
| 28 | no warnings; | |
| 29 | fo reach my $ e ( @role_ names, @$C ONST::REQU IRED_ROLES ) { | |
| 30 | $uni on{$e}++ & & $isect{$ e}++; | |
| 31 | } | |
| 32 | us e warnings ; | |
| 33 | my @isect = keys %isec t; | |
| 34 | if ( scalar @isect ) { | |
| 35 | #we have at le ast one ro le we need . | |
| 36 | #sen d OK | |
| 37 | #pri nt "All is good!!!\n "; | |
| 38 | $log ger->info( "Returning OK!"); | |
| 39 | retu rn OK; | |
| 40 | } | |
| 41 | el se { | |
| 42 | #we have none of the rol es we need | |
| 43 | #sen d forbidde n | |
| 44 | #war n "You are a hacker! \n"; | |
| 45 | $log ger->info( "Returning FORBIDDEN !"); | |
| 46 | retu rn FORBIDD EN; | |
| 47 | } | |
| 48 | } | |
| 49 | ||
| 50 | sub rest_c all($$) { | |
| 51 | my $user_nam e = shift; | |
| 52 | my $logger = shift; | |
| 53 | my $return_c ode; | |
| 54 | $l ogger->inf o("Rest ca ll for $us er_name"); | |
| 55 | un less ( def ined $cach e_hash{'le ase'}->{$u ser_name} ) { | |
| 56 | $cac he_hash{'l ease'}->{$ user_name} = 0; | |
| 57 | #pri nt $cache_ hash{'leas e'}->{$use r_name} . "\n"; | |
| 58 | my $ last_check = $CACHE: :cache_has h{'lease'} ->{$user_n ame}; | |
| 59 | $log ger->info( "Last chec k for user $user_nam e was at $ last_check "); | |
| 60 | } | |
| 61 | if ( ( time - $cache_h ash{'lease '}->{$user _name} ) > $CONST::S ECONDS_CAC HE ) | |
| 62 | { | |
| 63 | $log ger->info( "Rerunnin g role fet ch for use r $user_na me"); | |
| 64 | ||
| 65 | no w arnings; | |
| 66 | my $ url = URI- >new($CONS T::PRISME_ ROLES_URL) ; | |
| 67 | $url ->query_fo rm( $CONST ::CGI_USER _NAME => $ user_name ); | |
| 68 | $log ger->info( "Prisme UR L is: $url "); # s o we can s ee it | |
| 69 | # C reate a re quest | |
| 70 | my $ req = HTTP ::Request- >new( GET => $url ); | |
| 71 | ||
| 72 | # Pa ss request to the us er agent a nd get a r esponse ba ck | |
| 73 | my $ res = 0; | |
| 74 | my $ roles = 0; | |
| 75 | my $ content = 0; | |
| 76 | eval { | |
| 77 | #w e will tra p any erro rs during the fetch and parse. | |
| 78 | #p arsing wil l fail if we cannot cannect to Prisme or | |
| 79 | #i f we get i nvalid JSO N. We wil l log the error, and send a fo rbidden. | |
| 80 | $res = $ua-> request($r eq); | |
| 81 | $conte nt = $res- >content; | |
| 82 | $logge r->info("T he roles f rom prisme are: $con tent"); | |
| 83 | $roles = $json _decoder_r ing->decod e($content )->{'roles '}; | |
| 84 | }; | |
| 85 | unle ss ($roles ) { | |
| 86 | $logge r->error(" Failed to get Prisme roles!"); | |
| 87 | $logge r->error(" Prisme ret urned: $co ntent") if $content; | |
| 88 | $logge r->error(" $@"); | |
| 89 | $logge r->error(" $!"); | |
| 90 | $logge r->error(" Returning forbidden due to fai lure!"); | |
| 91 | return FORBIDDEN ; #retu rn FORBIDD EN code | |
| 92 | } | |
| 93 | my @ role_names = @$role s; #map { $_->{$CONS T::JSON_RO LE_NAME_KE Y} } @$rol es; | |
| 94 | $cac he_hash{'r oles'}->{$ user_name} = \@role_ names; | |
| 95 | $ret urn_code = allowed( \@role_nam es,$logger ); | |
| 96 | use warnings; | |
| 97 | my $ current_ti me = time; | |
| 98 | $cac he_hash{'l ease'}->{$ user_name} = time; | |
| 99 | $l ogger->inf o("Setting time for $user_name to $curre nt_time"); | |
| 100 | } | |
| 101 | el se { | |
| 102 | $log ger->info( "Using rol e cache fo r user $us er_name"); | |
| 103 | $ret urn_code = allowed( $cache_has h{'roles'} ->{$user_n ame}, $log ger ); | |
| 104 | } | |
| 105 | $r eturn_code ; | |
| 106 | } | |
| 107 | ||
| 108 | sub apr_it erator($$) { | |
| 109 | my $he aders = sh ift; | |
| 110 | my $lo gger = shi ft; | |
| 111 | wh ile (my ($ key, $valu e) = each %$headers) { | |
| 112 | $log ger->info( "PID: $$ D ATA: $key => $value" ); #goe s to /var /log/httpd /error_log | |
| 113 | } | |
| 114 | re turn 1; | |
| 115 | } | |
| 116 | ||
| 117 | sub handle r { | |
| 118 | my $r = shif t; | |
| 119 | if ($CONST:: LOG_HEADER S) { | |
| 120 | $r ->log->inf o("PID: DA TA: ------ ---------- ---------- ---------- ---------- ---------- ---------" ); | |
| 121 | #$ r->headers _in()->do( "apr_itera tor"); | |
| 122 | ap r_iterator ($r->heade rs_in(), $ r->log); | |
| 123 | $r ->log->inf o("PID: : ---------- ---------- ---------- ---------- ---------- ---------- -----"); | |
| 124 | } | |
| 125 | ||
| 126 | if ($CONST:: ACCEPT_ALL _REQUESTS) { | |
| 127 | $r->log->w arn("In ac cept all r equests mo de! $$"); | |
| 128 | return OK; | |
| 129 | } | |
| 130 | my $accept = $r->heade rs_in->get ('Accept') ; | |
| 131 | my $user = $ r->headers _in->get(' ADSAMACCOU NTNAME'); | |
| 132 | $r ->log->inf o("Request start on pid $$: Th e user for this requ est is $us er"); | |
| 133 | ||
| 134 | if ($user) { | |
| 135 | my $ val = rest _call($use r,$r->log) ; | |
| 136 | $r ->log->inf o("Request end on pi d $$: The user for t his reques t is $user "); | |
| 137 | re turn $val; #OK or FO RBIDDEN | |
| 138 | } | |
| 139 | el se { | |
| 140 | if ($ac cept =~ /i mage\/png/ ) { | |
| 141 | # we accept if the req uest is st rictly an image requ est. | |
| 142 | #A ccept => i mage/png, | |
| 143 | $r ->log->inf o("Request end on pi d $$: Just an image request OK ."); | |
| 144 | re turn OK; | |
| 145 | } else { | |
| 146 | re turn FORBI DDEN; | |
| 147 | $r ->log->inf o("Request end on pi d $$: Ther e is no us er. Forbid den."); | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | } | |
| 152 | #$ r->log_err or("--->re quest: log _error"); | |
| 153 | #$ r->log("re quest: reg ular log") ; | |
| 154 | #w arn "DATA: --------- ---------- ---------- ---------- ---------- ---------- ------"; | |
| 155 | #$ r->headers _in()->do( "apr_itera tor"); | |
| 156 | #w arn "DATA: --------- ---------- ---------- ---------- ---------- ---------- ------"; | |
| 157 | ||
| 158 | #note, the HTTP_ por tion shoul d not be i ncluded. | |
| 159 | #return OK unless $r ->headers_ in->EXISTS ('SM_UNIVE RSALID');# Shouldn't need this line in Pe rlFixupHan dler lifec ycle phase | |
| 160 | # in a mee ting with: | |
| 161 | #Ray Shapo uri | |
| 162 | PII | |
| 163 | #We have b een advise d to switc h to: | |
| 164 | #HTTP_ADSA MACCOUNTNA ME | |
| 165 | #$ r->log->in fo("CRIS 1 --->reques t: log_inf o"); | |
| 166 | #$ r->log_err or("The us er is $use r"); | |
| 167 | #r eturn OK i f (($user eq ' DNS ') || ($us er eq ' DNS DN S
|
|
| 168 | #r eturn FORB IDDEN; | |
| 169 | ||
| 170 | 1; |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.