예제 #1
0
static void header_field_cb(void *data, const char *field, size_t flen,
        const char *value, size_t vlen)
{
    Request *req = (Request *)data;

    if(hash_isfull(req->headers)) {
        log_err("Request had more than %d headers allowed by limits.header_count.",
                MAX_HEADER_COUNT);
    } else {
        bstring vstr = blk2bstr(value, vlen);
        bstring fstr = blk2bstr(field, flen);
        btolower(fstr);
        Request_set(req, fstr, vstr, 0);

        bdestroy(fstr); // we still own the key
    }
}
예제 #2
0
static Module *load_stdmodule( const char *modfilename, Client * u )
{
	int err;
	void *handle;
	ModuleInfo *infoptr = NULL;
	ModuleEvent *eventlistptr = NULL;
	Module *mod_ptr = NULL;
	int( *ModInit )( void );
	CmdParams *cmd;

	SET_SEGV_LOCATION();
	if( hash_isfull( modulehash ) ) {
		load_module_error( u, modfilename, __( "module list is full", u ) );
		return NULL;
	} 
	handle = ns_dlopen( modfilename, RTLD_NOW | RTLD_GLOBAL );
	if( !handle ) {
		load_module_error( u, modfilename, ns_dlerrormsg, modfilename );
		return NULL;
	}
	infoptr = ns_dlsym( handle, "module_info" );
	if( infoptr == NULL ) {
		load_module_error( u, modfilename, __( "missing module_info", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	/* Check module was built for this version of NeoStats */
	if( ircstrncasecmp( NEOSTATS_VERSION, infoptr->neostats_version, VERSIONSIZE ) !=0 ) {
		load_module_error( u, modfilename, __( "module built with an old version of NeoStats and must be rebuilt.", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	if( !infoptr->copyright || ircstrcasecmp( infoptr->copyright[0], "Copyright (c) <year>, <your name>" ) ==0 ) {
		load_module_error( u, modfilename, __( "missing copyright text.", u ) );
		ns_dlclose( handle );
		return NULL;
	}	
	if( !infoptr->about_text || ircstrcasecmp( infoptr->about_text[0], "About your module" ) ==0 ) {
		load_module_error( u, modfilename, __( "missing about text.", u ) );
		ns_dlclose( handle );
		return NULL;
	}	
	/* Check that the Module hasn't already been loaded */
	if( hash_lookup( modulehash, infoptr->name ) ) {
		ns_dlclose( handle );
		load_module_error( u, modfilename, __( "already loaded", u ) );
		return NULL;
	}
	/* Check we have require PROTOCOL/FEATURE support for module */
	if( ( infoptr->features & ircd_srv.features ) != infoptr->features ) {
		load_module_error( u, modfilename, __( "Required module features not available on this IRCd.", u ), modfilename );
		ns_dlclose( handle );
		return NULL;
	}
	/* Lookup ModInit( replacement for library __init() call */
	ModInit = ns_dlsym( ( int * ) handle, "ModInit" );
	if( !ModInit ) {
		load_module_error( u, modfilename, __( "missing ModInit.", u ) );
		ns_dlclose( handle );
		return NULL;
	}
	/* Allocate module */
	mod_ptr = ( Module * ) ns_calloc( sizeof( Module ) );
	dlog( DEBUG1, "Module internal name: %s", infoptr->name );
	dlog( DEBUG1, "Module description: %s", infoptr->description );
	mod_ptr->info = infoptr;
	mod_ptr->handle = handle;
	insert_module( mod_ptr );
	mod_ptr->type = MOD_TYPE_STANDARD;
	/* Extract pointer to event list */
	eventlistptr = ns_dlsym( handle, "module_events" );
	if( eventlistptr ) {
		SET_RUN_LEVEL( mod_ptr );
		AddEventList( eventlistptr );
		RESET_RUN_LEVEL();
	}
    /* For Auth modules, register auth function */
	if( infoptr->flags & MODULE_FLAG_AUTH ) {
		if( AddAuthModule( mod_ptr ) != NS_SUCCESS ) {
			load_module_error( u, modfilename, __( "Unable to load auth module: %s missing ModAuthUser function",u ), infoptr->name );
			unload_module( mod_ptr->info->name, NULL );
			return NULL;
		}
	}
    /* Module side user authentication for e.g. SecureServ helpers 
     * Not available on auth modules */
	if( !( infoptr->flags & MODULE_FLAG_AUTH ) )
		mod_ptr->authcb = ns_dlsym( ( int * ) handle, "ModAuthUser" );
	if( infoptr->flags & MODULE_FLAG_CTCP_VERSION )
		me.versionscan ++;		
	/* assign a module number to this module */
	assign_mod_number( mod_ptr );

	SET_SEGV_LOCATION();
	SET_RUN_LEVEL( mod_ptr );
	DBAOpenDatabase();
	err = ( *ModInit )(); 
	RESET_RUN_LEVEL();
	if( err < 1 || IsModuleError( mod_ptr ) ) {
		load_module_error( u, modfilename, __( "See %s.log for further information.",u ), mod_ptr->info->name );
		unload_module( mod_ptr->info->name, NULL );
		return NULL;
	}
	if( infoptr->flags & MODULE_FLAG_LOCAL_EXCLUDES ) 
	{
		SET_RUN_LEVEL( mod_ptr );	
		InitExcludes( mod_ptr );
		RESET_RUN_LEVEL();
	}
	SET_SEGV_LOCATION();

	/* Let this module know we are online if we are! */
	if( IsNeoStatsSynched() ) {
		if( SynchModule( mod_ptr ) != NS_SUCCESS || IsModuleError( mod_ptr ) )
		{
			load_module_error( u, modfilename, __( "See %s.log for further information.", u ), mod_ptr->info->name );
			unload_module( mod_ptr->info->name, NULL );
			return NULL;
		}
	}
	cmd = ns_calloc( sizeof( CmdParams ) );
	cmd->param = ( char * )infoptr->name;
	SendAllModuleEvent( EVENT_MODULELOAD, cmd );
	ns_free( cmd );
	if( u ) {
		irc_prefmsg( ns_botptr, u, __( "Module %s loaded, %s",u ), infoptr->name, infoptr->description );
		irc_globops( NULL, _( "Module %s loaded" ), infoptr->name );
	}
	return mod_ptr;
}