Bug 450742

Summary: server should pass in config entry to plugin init function
Product: [Retired] 389 Reporter: Nalin Dahyabhai <nalin>
Component: Server - PluginsAssignee: Rich Megginson <rmeggins>
Status: CLOSED CURRENTRELEASE QA Contact: Ben Levenson <benl>
Severity: low Docs Contact:
Priority: low    
Version: 1.1.1CC: jgalipea, nhosoi
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-12-10 18:37:34 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 743970    

Description Nalin Dahyabhai 2008-06-10 19:11:38 UTC
In a plugin which needs to read its configuration before the directory server
drops privileges, it would be very helpful to have the name and contents of the
plugin's configuration entry provided for the initialization function.  (In my
case I need to bind to a privileged port, and I want to allow the administrator
to specify a port so that I don't have to use bindresvport(), so that a hole can
be punched in a firewall).

Currently SLAPI_TARGET_DN isn't set, and attempts to locate the entry using
slapi_search_internal_set_pb()/slapi_search_internal_callback_pb() cause the
server to crash.

(Rich suggested using nsslapd-pluginArg0, and I can work with that for now.)

Comment 1 Rich Megginson 2008-06-10 20:23:06 UTC
In a plugin start function, the plugin receives the plugin config entry in the
pblock parameter SLAPI_ADD_ENTRY e.g. from pam_passthru:

static int
pam_passthru_bindpreop_start( Slapi_PBlock *pb )
{
    int rc;
    Slapi_Entry *config_e = NULL; /* entry containing plugin config */

    PAM_PASSTHRU_ASSERT( pb != NULL );

    slapi_log_error( SLAPI_LOG_PLUGIN, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
	    "=> pam_passthru_bindpreop_start\n" );

    if ( slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &config_e ) != 0 ) {
	slapi_log_error( SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
			 "missing config entry\n" );
	return( -1 );
    }

    /* process config using config_e */

We should do the same for plugin init, for those cases where the plugin must
have access to its config during the init phase.

Comment 4 Martin Kosek 2012-01-04 13:44:39 UTC
Upstream ticket:
https://fedorahosted.org/389/ticket/120

Comment 5 Rich Megginson 2012-01-06 16:54:50 UTC
fixed
commit b6d3ba77683722ed8b88994a637ba64fa18e57a1
Author: Rich Megginson <rmeggins>
Date:   Wed Oct 5 16:53:30 2011 -0600

    pass the plugin config entry to the plugin init function
    
    A plugin init function can get the plugin config entry (that is, its own
    config entry) by using the pblock parameter SLAPI_PLUGIN_CONFIG_ENTRY
    int
    my_plugin_init(Slapi_PBlock *pb)
    {
      Slapi_Entry *my_config_entry = NULL;
      slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &my_config_entry);
    Reviewed by: nkinder, nhosoi (Thanks!)