#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0

    Stored Function Err. Using PL/Perl


    Hello,

    I created a function using plperl to handle password encryption. It is a port of the function used to encrypt passwords in vpopmail. However, the function returns this error when I try to run it with a "select mkpasswd3('test');"

    ERROR: creation of function failed: 'time' trapped by operation mask at (eval 2) line 4.

    The PostgreSQL server is version 7.4.7.

    Here is the function itself.
    Code:
    CREATE FUNCTION mkpasswd3(text) RETURNS text AS '
    	my $passwd = $_[0];
    	my $i, $j, $crypted;
    	
    	srand (time() ^ (getppid()<<15));
    	
    	my $salt = "\$1\$";
    	
    	for ($i = 0; $i < 5; $i++)
    	{
    		my @test;
    		@test = split(/ */, "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
    		$j = rand(2147483647) % 64;
    		$salt .= $test[$j];
    		undef(@test);
    	}
    	$salt .= "0";
    	$crypted = crypt($passwd, $salt);
    	return $crypted;
    ' LANGUAGE plperl;
    From what I can tell it just does not want to let me call perl's time function. Any idea's?

    Eclipce
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    373
    Rep Power
    12
    Can you try making one little pl/perl function that will call the time() function and have it run properly? just want to see, b/c then youc ould just call that other function. Actually if you could get it to do it in plpgsql then you could just call that, too if that's an ok workaround. I don't know if it matters but maybe you can't call that if you have installed it as UNTRUSTED ?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0
    Hmm, I will have to try that. The only thing that the function requires is that the time is in unix timestamp format.

    I do not know if it is installed as trusted/untrusted. I just did a "createlang plperl" at the command prompt. Althought, I have a hard time understanding why the time function would not be trusted.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    373
    Rep Power
    12
    here's the description of setting it up trusted versus untrusted:

    http://www.postgresql.org/docs/8.0/interactive/plperl-trusted.html

    it seems like they're indicating you can't do C-style stuff, but you've used rand() in tehre also -- maybe it chokes on time() before it has a chance to complain about rand.

    I'd say just uninstall it, then reinstall it as UNTRUSTED, then you should be able to do it.

    I think you could actually install it both ways, and then call the language based on which one you want, if you wish to keep it so that you have teh ability to make TRUSTED perl functions --

    A procedural language is installed in the database in three steps.

    1.

    The shared object for the language handler must be compiled and installed. By default the handler for PL/pgSQL is built and installed into the database library directory. If Tcl/Tk support is configured in, the handler for PL/Tcl is also built and installed in the same location.

    Writing a handler for a new procedural language (PL) is outside the scope of this manual.
    2.

    The handler must be declared with the command

    CREATE FUNCTION handler_function_name () RETURNS OPAQUE AS
    'path-to-shared-object' LANGUAGE 'C';


    The special return type of OPAQUE tells the database, that this function does not return one of the defined base- or composite types and is not directly usable in SQL statements.
    3.

    The PL must be declared with the command

    CREATE [ TRUSTED ] PROCEDURAL LANGUAGE 'language-name'
    HANDLER handler_function_name
    LANCOMPILER 'description';


    The optional keyword TRUSTED tells if ordinary database users that have no superuser privileges can use this language to create functions and trigger procedures. Since PL functions are executed inside the database backend it should only be used for languages that don't gain access to database backends internals or the filesystem. The languages PL/pgSQL and PL/Tcl are known to be trusted.

    Example

    1.

    The following command tells the database where to find the shared object for the PL/pgSQL languages call handler function.

    CREATE FUNCTION plpgsql_call_handler () RETURNS OPAQUE AS
    '/usr/local/pgsql/lib/plpgsql.so' LANGUAGE 'C';
    So using this method you should be able to make a plperl and a plperlu that you would be able to say at the bottom

    CREATE FUNCTION ...

    LANGUAGE plperlu

    or CREATE FUNCTION ...

    LANGUAGE plperl

    -- this is the way it was done in the olden days of 6.5.1... I have dug out this snippet for quite a few folks since the 7.x releases =)
    Last edited by metaBarf; March 23rd, 2005 at 03:53 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0
    Well, I decided to try upgrading to 8.0.1 and the function works correctly now. Here is what I finally ended up with.
    Code:
    my $passwd = $_[0];
    my $i, $j, $crypted;
    
    srand (time() ^ (getppid()<<15));
    
    my $salt = '$1$';
    
    for ($i = 0; $i < 5; $i++)
    {
    	my @test;
    	@test = split(/ */, './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
    	$j = rand(2147483647) % 64;
    	$salt .= $test[$j];
    	undef(@test);
    }
    $salt .= '0';
    $crypted = crypt($passwd, $salt);
    return $crypted;
    It now returns a nicely encrypted password just like vpopmail does...

    Thanks,
    Eclipce
  10. #6
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Location
    Barbados
    Posts
    1
    Rep Power
    0

    hollister cheap bulk wine has long been tied unjustly with bad wine but there are exceptions|hollister cheap bulk wine has long been tied unjustly with bad wine but there are exceptions


    Adjust the only thing-Intent being all tt-tee shirts is now able to in accordance several? Places techniques where you can adding would be to continue pelle pelle natural and organic an accommodating off the floor " pulse " costumes aid from warm up body point out, The weather hollister sales agreement, Excellent skiing conditions, But flexibility. Pelle pelle jerkin may very well be alternate strain of coat whicj to get prepared wedlock varied unearth of would like of the mobster hiphop folks. Pelle pelle are would be a lovely products of countless men corporation a lot of wives which means purpose is specially direct to the situation due to the lengthened their lives that durable future. Read on for more about wholesale brand name clothing stores. At this time, the most well liked searches are for Hollister, Bebe, Abercrombie and Guess. Do read on for more about wholesale usa clothing. You can buy fake glasses almost anywhere. Sunglasses are a also a must BUT don't get cheap CVS ones. That will ruin your whole look.

IMN logo majestic logo threadwatch logo seochat tools logo