home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Access.pm < prev    next >
Encoding:
Perl POD Document  |  2004-09-23  |  13.8 KB  |  682 lines

  1. # /*
  2. #  * *********** WARNING **************
  3. #  * This file generated by ModPerl::WrapXS/0.01
  4. #  * Any changes made here will be lost
  5. #  * ***********************************
  6. #  * 01: lib/ModPerl/Code.pm:701
  7. #  * 02: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:584
  8. #  * 03: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:1100
  9. #  * 04: Makefile.PL:335
  10. #  * 05: Makefile.PL:283
  11. #  * 06: Makefile.PL:51
  12. #  */
  13.  
  14.  
  15. package Apache::Access;
  16.  
  17. use strict;
  18. use warnings FATAL => 'all';
  19.  
  20.  
  21.  
  22. use Apache::XSLoader ();
  23. our $VERSION = '0.01';
  24. Apache::XSLoader::load __PACKAGE__;
  25.  
  26.  
  27.  
  28. 1;
  29. __END__
  30.  
  31. =head1 NAME
  32.  
  33. Apache::Access - A Perl API for Apache request object: Access,
  34. Authentication and Authorization.
  35.  
  36.  
  37.  
  38.  
  39.  
  40. =head1 Synopsis
  41.  
  42.   use Apache::Access ();
  43.   
  44.   # allow only GET method
  45.   $r->allow_methods(1, qw(GET));
  46.   
  47.   # Apache Options value
  48.   $options = $r->allow_options();
  49.   
  50.   # Apache AllowOverride value
  51.   $allow_override = $r->allow_overrides();
  52.   
  53.   # auth name ("foo bar")
  54.   $auth_name = $r->auth_name();
  55.   
  56.   # auth type
  57.   $auth_type = $r->auth_type();
  58.   $r->auth_type("Digest");
  59.   
  60.   # Basic authentication process
  61.   my($rc, $passwd) = $r->get_basic_auth_pw();
  62.   
  63.   # the login name of the remote user (RFC1413)
  64.   $remote_logname = $r->get_remote_logname();
  65.   
  66.   # dynamically figure out which auth has failed
  67.   $r->note_auth_failure();
  68.   
  69.   # note Basic auth failure
  70.   $r->note_basic_auth_failure();
  71.   
  72.   # note Digest auth failure
  73.   $r->note_digest_auth_failure();
  74.   
  75.   # Apache Request value(s)
  76.   $requires = $r->requires();
  77.   
  78.   # Apache Satisfy value (as a number)
  79.   $satisfy = $r->satisfies();
  80.   
  81.   # check whether some auth is configured
  82.   $need_auth = $r->some_auth_required();
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. =head1 Description
  91.  
  92. The API provided by this module deals with access, authentication and
  93. authorization phases.
  94.  
  95. C<Apache::Access> extends
  96. C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec|/Description>>.
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. =head1 API
  106.  
  107. C<Apache::Access> provides the following functions and/or methods:
  108.  
  109.  
  110.  
  111.  
  112.  
  113. =head2 C<allow_methods>
  114.  
  115. Specify which HTTP methods are allowed
  116.  
  117.   $r->allow_methods($reset);
  118.   $r->allow_methods($reset, @methods);
  119.  
  120. =over 4
  121.  
  122. =item obj: C<$r>
  123. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  124.  
  125. The current request
  126.  
  127. =item arg1: C<$reset> ( boolean )
  128.  
  129. If a true value is passed all the previously allowed methods are
  130. removed. Otherwise the list is left intact.
  131.  
  132. =item opt arg2: C<@methods> ( array of strings )
  133.  
  134. a list of HTTP methods to be allowed (e.g. C<GET> and C<POST>)
  135.  
  136. =item ret: no return value
  137.  
  138. =item since: 1.99_12
  139.  
  140. =back
  141.  
  142. For example: here is how to allow only C<GET> and C<POST> methods,
  143. regardless to what was the previous setting:
  144.  
  145.   $r->allow_methods(1, qw(GET POST));
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. =head2 C<allow_options>
  153.  
  154. Retrieve the value of C<Options> for this request
  155.  
  156.   $options = $r->allow_options();
  157.  
  158. =over 4
  159.  
  160. =item obj: C<$r>
  161. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  162.  
  163. The current request
  164.  
  165. =item ret: C<$options> ( integer )
  166.  
  167. the C<Options> bitmask. Normally used with bitlogic operators against
  168. C<L<Apache::Const :options
  169. constants|docs::2.0::api::Apache::Const/C__options_>>.
  170.  
  171. =item since: 1.99_12
  172.  
  173. =back
  174.  
  175. For example if the configuration for the current request was:
  176.  
  177.   Options None
  178.   Options Indexes FollowSymLinks
  179.  
  180. The following applies:
  181.  
  182.   use Apache::Const -compile => qw(:options);
  183.   $r->allow_options & Apache::OPT_INDEXES;   # TRUE
  184.   $r->allow_options & Apache::OPT_SYM_LINKS; # TRUE
  185.   $r->allow_options & Apache::OPT_EXECCGI;   # FALSE
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. =head2 C<allow_overrides>
  195.  
  196. Retrieve the value of C<AllowOverride> for this request
  197.  
  198.   $allow_override = $r->allow_overrides();
  199.  
  200. =over 4
  201.  
  202. =item obj: C<$r>
  203. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  204.  
  205. The current request
  206.  
  207. =item ret: C<$allow_override> ( integer )
  208.  
  209. the C<AllowOverride> bitmask. Normally used with bitlogic operators
  210. against C<L<Apache::Const :override
  211. constants|docs::2.0::api::Apache::Const/C__override_>>.
  212.  
  213. =item since: 1.99_12
  214.  
  215. =back
  216.  
  217. For example if the configuration for the current request was:
  218.  
  219.   AllowOverride AuthConfig
  220.  
  221. The following applies:
  222.  
  223.   use Apache::Const -compile => qw(:override);
  224.   $r->allow_overrides & Apache::OR_AUTHCFG; # TRUE
  225.   $r->allow_overrides & Apache::OR_LIMIT; # FALSE
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. =head2 C<auth_name>
  233.  
  234. Get/set the current Authorization realm (the per directory
  235. configuration directive C<AuthName>):
  236.  
  237.   $auth_name = $r->auth_name();
  238.   $auth_name = $r->auth_name($new_auth_name);
  239.  
  240. =over 4
  241.  
  242. =item obj: C<$r>
  243. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  244.  
  245. The current request
  246.  
  247. =item opt arg1: C<$new_auth_name> ( string )
  248.  
  249. If C<$new_auth_name> is passed a new C<AuthName> value is set
  250.  
  251. =item ret: C<$> ( integer )
  252.  
  253. The current value of C<AuthName>
  254.  
  255. =item since: 1.99_12
  256.  
  257. =back
  258.  
  259. The C<AuthName> directive creates protection realm within the server
  260. document space. To quote RFC 1945 "These realms allow the protected
  261. resources on a server to be partitioned into a set of protection
  262. spaces, each with its own authentication scheme and/or authorization
  263. database." The client uses the root URL of the server to determine
  264. which authentication credentials to send with each HTTP request. These
  265. credentials are tagged with the name of the authentication realm that
  266. created them.  Then during the authentication stage the server uses
  267. the current authentication realm, from C<$r-E<gt>auth_name>, to
  268. determine which set of credentials to authenticate.
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277. =head2 C<auth_type>
  278.  
  279. Get/set the type of authorization required for this request (the per
  280. directory configuration directive C<AuthType>):
  281.  
  282.   $auth_type = $r->auth_type();
  283.   $auth_type = $r->auth_type($new_auth_type);
  284.  
  285. =over 4
  286.  
  287. =item obj: C<$r>
  288. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  289.  
  290. The current request
  291.  
  292. =item opt arg1: C<$new_auth_type> ( string )
  293.  
  294. If C<$new_auth_type> is passed a new C<AuthType> value is set
  295.  
  296. =item ret: C<$> ( integer )
  297.  
  298. The current value of C<AuthType>
  299.  
  300. =item since: 1.99_12
  301.  
  302. =back
  303.  
  304. Normally C<AuthType> would be set to C<Basic> to use the basic
  305. authentication scheme defined in RFC 1945, I<Hypertext Transfer
  306. Protocol -- HTTP/1.0>. However, you could set to something else and
  307. implement your own authentication scheme.
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317. =head2 C<get_basic_auth_pw>
  318.  
  319. Get the password from the request headers
  320.  
  321.   my($rc, $passwd) = $r->get_basic_auth_pw();
  322.  
  323. =over 4
  324.  
  325. =item obj: C<$r>
  326. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  327.  
  328. The current request
  329.  
  330. =item ret1: C<$rc>
  331. ( C<L<Apache::Const constant|docs::2.0::api::Apache::Const>> )
  332.  
  333. C<Apache::OK> if the C<$passwd> value is set (and assured a correct
  334. value in
  335. C<L<$r-E<gt>user|docs::2.0::api::Apache::RequestRec/C_user_>>);
  336. otherwise it returns an error code, either
  337. C<Apache::HTTP_INTERNAL_SERVER_ERROR> if things are really confused,
  338. C<Apache::HTTP_UNAUTHORIZED> if no authentication at all seemed to be
  339. in use, or C<Apache::DECLINED> if there was authentication, but it
  340. wasn't C<Basic> (in which case, the caller should presumably decline
  341. as well).
  342.  
  343. =item ret2: C<$ret> (string)
  344.  
  345. The password as set in the headers (decoded)
  346.  
  347. =item since: 1.99_12
  348.  
  349. =back
  350.  
  351. If C<L<AuthType|/C_auth_type_>> is not set, this handler first sets it
  352. to C<Basic>.
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. =head2 C<get_remote_logname>
  362.  
  363. Retrieve the login name of the remote user (RFC1413)
  364.  
  365.   $remote_logname = $r->get_remote_logname();
  366.  
  367. =over 4
  368.  
  369. =item obj: C<$r>
  370. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  371.  
  372. The current request
  373.  
  374. =item ret: C<$remote_logname> ( string )
  375.  
  376. The username of the user logged in to the client machine, or an empty
  377. string if it could not be determined via RFC1413, which involves
  378. querying the client's identd or auth daemon.
  379.  
  380. =item since: 1.99_12
  381.  
  382. =back
  383.  
  384. Do not confuse this method with
  385. C<L<$r-E<gt>user|docs::2.0::api::Apache::RequestRec/C_user_>>, which
  386. provides the username provided by the user during the server
  387. authentication.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396. =head2 C<note_auth_failure>
  397.  
  398. Setup the output headers so that the client knows how to authenticate
  399. itself the next time, if an authentication request failed.  This
  400. function works for both basic and digest authentication
  401.  
  402.   $r->note_auth_failure();
  403.  
  404. =over 4
  405.  
  406. =item obj: C<$r>
  407. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  408.  
  409. The current request
  410.  
  411. =item ret: no return value
  412.  
  413. =item since: 1.99_12
  414.  
  415. =back
  416.  
  417. This method requires C<AuthType> to be set to C<Basic> or
  418. C<Digest>. Depending on the setting it'll call either
  419. C<L<$r-E<gt>note_basic_auth_failure|/C_note_basic_auth_failure_>> or
  420. C<L<$r-E<gt>note_digest_auth_failure|/C_note_digest_auth_failure_>>.
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430. =head2 C<note_basic_auth_failure>
  431.  
  432. Setup the output headers so that the client knows how to authenticate
  433. itself the next time, if an authentication request failed.  This
  434. function works only for basic authentication
  435.  
  436.   $r->note_basic_auth_failure();
  437.  
  438. =over 4
  439.  
  440. =item obj: C<$r>
  441. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  442.  
  443. The current request
  444.  
  445. =item ret: no return value
  446.  
  447. =item since: 1.99_12
  448.  
  449. =back
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459. =head2 C<note_digest_auth_failure>
  460.  
  461. Setup the output headers so that the client knows how to authenticate
  462. itself the next time, if an authentication request failed.  This
  463. function works only for digest authentication.
  464.  
  465.   $r->note_digest_auth_failure();
  466.  
  467. =over 4
  468.  
  469. =item obj: C<$r>
  470. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  471.  
  472. The current request
  473.  
  474. =item ret: no return value
  475.  
  476. =item since: 1.99_12
  477.  
  478. =back
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486. =head2 C<requires>
  487.  
  488. Retrieve information about all of the requires directives for this request
  489.  
  490.   $requires = $r->requires
  491.  
  492. =over 4
  493.  
  494. =item obj: C<$r>
  495. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  496.  
  497. The current request
  498.  
  499. =item ret: C<$requires> ( ARRAY ref )
  500.  
  501. Returns an array reference of hash references, containing information
  502. related to the C<require> directive.
  503.  
  504. =item since: 1.99_12
  505.  
  506. =back
  507.  
  508. This is normally used for access control.
  509.  
  510. For example if the configuration had the following require directives:
  511.  
  512.     Require user  goo bar
  513.     Require group bar tar
  514.  
  515. this method will return the following datastructure:
  516.  
  517.   [
  518.     {
  519.       'method_mask' => -1,
  520.       'requirement' => 'user goo bar'
  521.     },
  522.     {
  523.       'method_mask' => -1,
  524.       'requirement' => 'group bar tar'
  525.     }
  526.   ];
  527.  
  528. The I<requirement> field is what was passed to the C<Require>
  529. directive.  The I<method_mask> field is a bitmask which can be
  530. modified by the C<Limit> directive, but normally it can be safely
  531. ignored as it's mostly used internally. For example if the
  532. configuration was:
  533.  
  534.     Require user goo bar
  535.     Require group bar tar
  536.     <Limit POST>
  537.        Require valid-user
  538.     </Limit>
  539.  
  540. and the request method was C<POST>, C<$r-E<gt>requires> will return:
  541.  
  542.   [
  543.     {
  544.       'method_mask' => -1,
  545.       'requirement' => 'user goo bar'
  546.     },
  547.     {
  548.       'method_mask' => -1,
  549.       'requirement' => 'group bar tar'
  550.     }
  551.     {
  552.       'method_mask' => 4,
  553.       'requirement' => 'valid-user'
  554.     }
  555.   ];
  556.  
  557. But if the request method was C<GET>, it will return only:
  558.  
  559.   [
  560.     {
  561.       'method_mask' => -1,
  562.       'requirement' => 'user goo bar'
  563.     },
  564.     {
  565.       'method_mask' => -1,
  566.       'requirement' => 'group bar tar'
  567.     }
  568.   ];
  569.  
  570. As you can see Apache gives you the requirements relevant for the
  571. current request, so the I<method_mask> is irrelevant.
  572.  
  573. It is also a good time to remind that in the general case, access
  574. control directives should not be placed within a E<lt>LimitE<gt>
  575. section.  Refer to the Apache documentation for more information.
  576.  
  577. Using the same configuration and assuming that the request was of type
  578. POST, the following code inside an Auth handler:
  579.  
  580.   my %require =
  581.       map { my($k, $v) = split /\s+/, $_->{requirement}, 2; ($k, $v||'') }
  582.       @{ $r->requires };
  583.  
  584. will populate C<%require> with the following pairs:
  585.  
  586.   'group' => 'bar tar',
  587.   'user' => 'goo bar',
  588.   'valid-user' => '',
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. =head2 C<satisfies>
  599.  
  600. How the requires lines must be met. What's the applicable value of the
  601. C<Satisfy> directive:
  602.  
  603.   $satisfy = $r->satisfies();
  604.  
  605. =over 4
  606.  
  607. =item obj: C<$r>
  608. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  609.  
  610. The current request
  611.  
  612. =item ret: C<$satisfy> ( integer )
  613.  
  614. How the requirements must be met.  One of the C<L<Apache::Const
  615. :satisfy constants|docs::2.0::api::Apache::Const/C__satisfy_>>:
  616.  
  617. C<L<Apache::SATISFY_ANY|docs::2.0::api::Apache::Const/C_Apache::SATISFY_ANY_>>,
  618. C<L<Apache::SATISFY_ALL|docs::2.0::api::Apache::Const/C_Apache::SATISFY_ALL_>>
  619. and
  620. C<L<Apache::SATISFY_NOSPEC|docs::2.0::api::Apache::Const/C_Apache::SATISFY_NOSPEC_>>.
  621.  
  622. =item since: 1.99_12
  623.  
  624. =back
  625.  
  626. See the documentation for the C<Satisfy> directive in the Apache
  627. documentation.
  628.  
  629.  
  630.  
  631.  
  632.  
  633. =head2 C<some_auth_required>
  634.  
  635. Can be used within any handler to determine if any authentication is
  636. required for the current request:
  637.  
  638.   $need_auth = $r->some_auth_required();
  639.  
  640. =over 4
  641.  
  642. =item obj: C<$r>
  643. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  644.  
  645. The current request
  646.  
  647. =item ret: C<$need_auth> ( boolean )
  648.  
  649. TRUE if authentication is required, FALSE otherwise
  650.  
  651. =item since: 1.99_12
  652.  
  653. =back
  654.  
  655.  
  656.  
  657.  
  658. =head1 See Also
  659.  
  660. L<mod_perl 2.0 documentation|docs::2.0::index>.
  661.  
  662.  
  663.  
  664.  
  665. =head1 Copyright
  666.  
  667. mod_perl 2.0 and its core modules are copyrighted under
  668. The Apache Software License, Version 2.0.
  669.  
  670.  
  671.  
  672.  
  673. =head1 Authors
  674.  
  675. L<The mod_perl development team and numerous
  676. contributors|about::contributors::people>.
  677.  
  678. =cut
  679.  
  680.