mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
66c029c842
In general, datatype I/O functions are supposed to be immutable or at worst stable. Some contrib I/O functions were, through oversight, not marked with any volatility property at all, which made them VOLATILE. Since (most of) these functions actually behave immutably, the erroneous marking isn't terribly harmful; but it can be user-visible in certain circumstances, as per a recent bug report from Joe Van Dyk in which a cast to text was disallowed in an expression index definition. To fix, just adjust the declarations in the extension SQL scripts. If we were being very fussy about this, we'd bump the extension version numbers, but that seems like more trouble (for both developers and users) than the problem is worth. A fly in the ointment is that chkpass_in actually is volatile, because of its use of random() to generate a fresh salt when presented with a not-yet-encrypted password. This is bad because of the general assumption that I/O functions aren't volatile: the consequence is that records or arrays containing chkpass elements may have input behavior a bit different from a bare chkpass column. But there seems no way to fix this without breaking existing usage patterns for chkpass, and the consequences of the inconsistency don't seem bad enough to justify that. So for the moment, just document it in a comment. Since we're not bumping version numbers, there seems no harm in back-patching these fixes; at least future installations will get the functions marked correctly.
71 lines
1.3 KiB
SQL
71 lines
1.3 KiB
SQL
/* contrib/chkpass/chkpass--1.0.sql */
|
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
\echo Use "CREATE EXTENSION chkpass" to load this file. \quit
|
|
|
|
--
|
|
-- Input and output functions and the type itself:
|
|
--
|
|
|
|
CREATE FUNCTION chkpass_in(cstring)
|
|
RETURNS chkpass
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT VOLATILE;
|
|
-- Note: chkpass_in actually is volatile, because of its use of random().
|
|
-- In hindsight that was a bad idea, but there's no way to change it without
|
|
-- breaking some usage patterns.
|
|
|
|
CREATE FUNCTION chkpass_out(chkpass)
|
|
RETURNS cstring
|
|
AS 'MODULE_PATHNAME'
|
|
LANGUAGE C STRICT IMMUTABLE;
|
|
|
|
CREATE TYPE chkpass (
|
|
internallength = 16,
|
|
input = chkpass_in,
|
|
output = chkpass_out
|
|
);
|
|
|
|
CREATE FUNCTION raw(chkpass)
|
|
RETURNS text
|
|
AS 'MODULE_PATHNAME', 'chkpass_rout'
|
|
LANGUAGE C STRICT;
|
|
|
|
--
|
|
-- The various boolean tests:
|
|
--
|
|
|
|
CREATE FUNCTION eq(chkpass, text)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME', 'chkpass_eq'
|
|
LANGUAGE C STRICT;
|
|
|
|
CREATE FUNCTION ne(chkpass, text)
|
|
RETURNS bool
|
|
AS 'MODULE_PATHNAME', 'chkpass_ne'
|
|
LANGUAGE C STRICT;
|
|
|
|
--
|
|
-- Now the operators.
|
|
--
|
|
|
|
CREATE OPERATOR = (
|
|
leftarg = chkpass,
|
|
rightarg = text,
|
|
negator = <>,
|
|
procedure = eq
|
|
);
|
|
|
|
CREATE OPERATOR <> (
|
|
leftarg = chkpass,
|
|
rightarg = text,
|
|
negator = =,
|
|
procedure = ne
|
|
);
|
|
|
|
COMMENT ON TYPE chkpass IS 'password type with checks';
|
|
|
|
--
|
|
-- eof
|
|
--
|