gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

72 lines
6.5KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>44.5. Trusted and Untrusted PL/Perl</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="plperl-global.html" title="44.4. Global Values in PL/Perl" /><link rel="next" href="plperl-triggers.html" title="44.6. PL/Perl Triggers" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">44.5. Trusted and Untrusted PL/Perl</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="plperl-global.html" title="44.4. Global Values in PL/Perl">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="plperl.html" title="Chapter 44. PL/Perl - Perl Procedural Language">Up</a></td><th width="60%" align="center">Chapter 44. PL/Perl - Perl Procedural Language</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="plperl-triggers.html" title="44.6. PL/Perl Triggers">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PLPERL-TRUSTED"><div class="titlepage"><div><div><h2 class="title" style="clear: both">44.5. Trusted and Untrusted PL/Perl</h2></div></div></div><a id="id-1.8.10.13.2" class="indexterm"></a><p>
  3. Normally, PL/Perl is installed as a <span class="quote">“<span class="quote">trusted</span>”</span> programming
  4. language named <code class="literal">plperl</code>. In this setup, certain Perl
  5. operations are disabled to preserve security. In general, the
  6. operations that are restricted are those that interact with the
  7. environment. This includes file handle operations,
  8. <code class="literal">require</code>, and <code class="literal">use</code> (for
  9. external modules). There is no way to access internals of the
  10. database server process or to gain OS-level access with the
  11. permissions of the server process,
  12. as a C function can do. Thus, any unprivileged database user can
  13. be permitted to use this language.
  14. </p><p>
  15. Here is an example of a function that will not work because file
  16. system operations are not allowed for security reasons:
  17. </p><pre class="programlisting">
  18. CREATE FUNCTION badfunc() RETURNS integer AS $$
  19. my $tmpfile = "/tmp/badfile";
  20. open my $fh, '&gt;', $tmpfile
  21. or elog(ERROR, qq{could not open the file "$tmpfile": $!});
  22. print $fh "Testing writing to a file\n";
  23. close $fh or elog(ERROR, qq{could not close the file "$tmpfile": $!});
  24. return 1;
  25. $$ LANGUAGE plperl;
  26. </pre><p>
  27. The creation of this function will fail as its use of a forbidden
  28. operation will be caught by the validator.
  29. </p><p>
  30. Sometimes it is desirable to write Perl functions that are not
  31. restricted. For example, one might want a Perl function that sends
  32. mail. To handle these cases, PL/Perl can also be installed as an
  33. <span class="quote">“<span class="quote">untrusted</span>”</span> language (usually called
  34. <span class="application">PL/PerlU</span><a id="id-1.8.10.13.5.3" class="indexterm"></a>).
  35. In this case the full Perl language is available. When installing the
  36. language, the language name <code class="literal">plperlu</code> will select
  37. the untrusted PL/Perl variant.
  38. </p><p>
  39. The writer of a <span class="application">PL/PerlU</span> function must take care that the function
  40. cannot be used to do anything unwanted, since it will be able to do
  41. anything that could be done by a user logged in as the database
  42. administrator. Note that the database system allows only database
  43. superusers to create functions in untrusted languages.
  44. </p><p>
  45. If the above function was created by a superuser using the language
  46. <code class="literal">plperlu</code>, execution would succeed.
  47. </p><p>
  48. In the same way, anonymous code blocks written in Perl can use
  49. restricted operations if the language is specified as
  50. <code class="literal">plperlu</code> rather than <code class="literal">plperl</code>, but the caller
  51. must be a superuser.
  52. </p><div class="note"><h3 class="title">Note</h3><p>
  53. While <span class="application">PL/Perl</span> functions run in a separate Perl
  54. interpreter for each SQL role, all <span class="application">PL/PerlU</span> functions
  55. executed in a given session run in a single Perl interpreter (which is
  56. not any of the ones used for <span class="application">PL/Perl</span> functions).
  57. This allows <span class="application">PL/PerlU</span> functions to share data freely,
  58. but no communication can occur between <span class="application">PL/Perl</span> and
  59. <span class="application">PL/PerlU</span> functions.
  60. </p></div><div class="note"><h3 class="title">Note</h3><p>
  61. Perl cannot support multiple interpreters within one process unless
  62. it was built with the appropriate flags, namely either
  63. <code class="literal">usemultiplicity</code> or <code class="literal">useithreads</code>.
  64. (<code class="literal">usemultiplicity</code> is preferred unless you actually need
  65. to use threads. For more details, see the
  66. <span class="citerefentry"><span class="refentrytitle">perlembed</span></span> man page.)
  67. If <span class="application">PL/Perl</span> is used with a copy of Perl that was not built
  68. this way, then it is only possible to have one Perl interpreter per
  69. session, and so any one session can only execute either
  70. <span class="application">PL/PerlU</span> functions, or <span class="application">PL/Perl</span> functions
  71. that are all called by the same SQL role.
  72. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="plperl-global.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="plperl.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="plperl-triggers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">44.4. Global Values in PL/Perl </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 44.6. PL/Perl Triggers</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1