Esempio n. 1
0
int slapi_apib_get_interface_all(char *guid, void ****api)
{
	void ***retapi = NULL;
	int idx = 0;

	if(buffer_lock == 0)
		return -1;

	if(buffer_lock == 0)
	{
		if(0 == (buffer_lock = slapi_new_mutex())) /* we never free this mutex */
			/* badness */
			return -1;
	}

	slapi_lock_mutex(buffer_lock);

	retapi = ABAPIBroker_FindInterface_All(guid);
	for (idx = 0; retapi && retapi[idx]; ++idx) {
		void **theapi = retapi[idx];
		if(theapi[0])
		{
			slapi_apib_addref(theapi);
		}
	}

	*api = retapi;

	slapi_unlock_mutex(buffer_lock);

	return 0;
}
Esempio n. 2
0
int slapi_apib_get_interface(char *guid, void ***api)
{
	int ret = -1;
	ABAPI **theapi;

	if(buffer_lock == 0)
		return ret;

	if(buffer_lock == 0)
	{
		if(0 == (buffer_lock = slapi_new_mutex())) /* we never free this mutex */
			/* badness */
			return -1;
	}

	slapi_lock_mutex(buffer_lock);

	if((theapi = ABAPIBroker_FindInterface(guid)) != NULL)
	{
		*api = (*theapi)->api;
		if((*api)[0])
		{
			slapi_apib_addref(*api);
		}

		ret = 0;
	}

	slapi_unlock_mutex(buffer_lock);

	return ret;
}
Esempio n. 3
0
/*
 * Perform any PAM subsystem initialization that must be done at startup time.
 * For now, this means only the PAM mutex since PAM is not thread safe.
 */
int
pam_passthru_pam_init( void )
{
	if (!(PAMLock = slapi_new_mutex())) {
		return LDAP_LOCAL_ERROR;
	}

	return 0;
}
Esempio n. 4
0
/*
 * Read configuration and create a configuration data structure.
 * This is called after the server has configured itself so we can check
 * schema and whatnot.
 * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
 */
int
ipa_winsync_config(Slapi_Entry *config_e)
{
    int returncode = LDAP_SUCCESS;
    char returntext[SLAPI_DSE_RETURNTEXT_SIZE];

    if ( inited ) {
        LOG_FATAL("Error: IPA WinSync plug-in already configured.  "
                  "Please remove the plugin config entry [%s]\n",
                  slapi_entry_get_dn_const(config_e));
        return( LDAP_PARAM_ERROR );
    }

    /* initialize fields */
    if ((theConfig.lock = slapi_new_mutex()) == NULL) {
        return( LDAP_LOCAL_ERROR );
    }

    /* init defaults */
    theConfig.config_e = slapi_entry_alloc();
    slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
    theConfig.flatten = PR_TRUE;

    if (SLAPI_DSE_CALLBACK_OK == ipa_winsync_validate_config(NULL, NULL, config_e,
                                                             &returncode, returntext, NULL)) {
        ipa_winsync_apply_config(NULL, NULL, config_e,
                                 &returncode, returntext, NULL);
    }

    /* config DSE must be initialized before we get here */
    if (returncode == LDAP_SUCCESS) {
        const char *config_dn = slapi_entry_get_dn_const(config_e);
        slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_validate_config,NULL);
        slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_apply_config,NULL);
        slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, dont_allow_that, NULL);
        slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, dont_allow_that, NULL);
        slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_search,NULL);
    }

    inited = 1;

    if (returncode != LDAP_SUCCESS) {
        LOG_FATAL("Error %d: %s\n", returncode, returntext);
    }

    return returncode;
}
Esempio n. 5
0
int slapi_apib_register(char *guid, void **api )
{
	int ret = -1;
	ABAPI *item;

	if(buffer_lock == 0)
	{
		if(0 == (buffer_lock = slapi_new_mutex())) /* we never free this mutex */
			/* badness */
			return -1;
	}

	/* simple - we don't check for duplicates */
	
	item = (ABAPI*)slapi_ch_malloc(sizeof(ABAPI));
	if(item)
	{
		item->guid = guid;
		item->api = api;

		slapi_lock_mutex(buffer_lock);
		if(head == NULL)
		{
			head = item;
			head->next = head;
			head->prev = head;
		}
		else
		{
			item->next = head;
			item->prev = head->prev;
			head->prev = item;
			item->prev->next = item;
		}
		slapi_unlock_mutex(buffer_lock);

		ret = 0;
	}

	return ret;
}
Esempio n. 6
0
int slapi_apib_unregister(char *guid)
{
	int ret = -1;
	ABAPI **api;

	if(buffer_lock == 0)
		return ret;

	if(buffer_lock == 0)
	{
		if(0 == (buffer_lock = slapi_new_mutex())) /* we never free this mutex */
			/* badness */
			return -1;
	}

	slapi_lock_mutex(buffer_lock);

	if((api = ABAPIBroker_FindInterface(guid)) != NULL)
	{
		(*api)->prev->next = (*api)->next;
		(*api)->next->prev = (*api)->prev;

		if(*api == head)
		{
			head = (*api)->next;
		}

		if(*api == head) /* must be the last item, turn off the lights */
			head = 0;

		slapi_ch_free((void**)api);
		*api = 0;
		ret = 0;
	}

	slapi_unlock_mutex(buffer_lock);

	return ret;
}
Esempio n. 7
0
int slapi_apib_make_reference_counted(void **api, slapi_apib_callback_on_zero callback_on_zero)
{
	int ret = -1;

	if(api[0] == 0)
	{
		api[0] = slapi_ch_malloc(sizeof(APIB_FEATURES));
		if(api[0])
		{
			((APIB_FEATURES*)(api[0]))->lock = slapi_new_mutex();
			if(((APIB_FEATURES*)(api[0]))->lock)
			{
				((APIB_FEATURES*)(api[0]))->refcount = 0; /* the ref count */
				((APIB_FEATURES*)(api[0]))->callback_on_zero = callback_on_zero;
				ret = 0;
			}
			else
				slapi_ch_free(&(api[0]));
		}
	}

	return ret;
}
Esempio n. 8
0
static int 
snmp_collator_init(void)
{
	int i;

	/*
	 * Create the global SNMP counters
	 */
	g_get_global_snmp_vars()->ops_tbl.dsAnonymousBinds		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsUnAuthBinds			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsSimpleAuthBinds		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsStrongAuthBinds		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsBindSecurityErrors		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsInOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsReadOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsCompareOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsAddEntryOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsRemoveEntryOps		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsModifyEntryOps		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsModifyRDNOps		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsListOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsSearchOps			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsOneLevelSearchOps		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsWholeSubtreeSearchOps	= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsReferrals			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsChainings			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsSecurityErrors		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsErrors			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsConnections			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsConnectionSeq		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsBytesRecv			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsBytesSent			= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsEntriesReturned		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsReferralsReturned		= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsConnectionsInMaxThreads	= slapi_counter_new();
	g_get_global_snmp_vars()->ops_tbl.dsMaxThreadsHit		= slapi_counter_new();
	g_get_global_snmp_vars()->entries_tbl.dsMasterEntries		= slapi_counter_new();
	g_get_global_snmp_vars()->entries_tbl.dsCopyEntries		= slapi_counter_new();
	g_get_global_snmp_vars()->entries_tbl.dsCacheEntries		= slapi_counter_new();
	g_get_global_snmp_vars()->entries_tbl.dsCacheHits		= slapi_counter_new();
	g_get_global_snmp_vars()->entries_tbl.dsSlaveHits		= slapi_counter_new();

	/* Initialize the global interaction table */
	for(i=0; i < NUM_SNMP_INT_TBL_ROWS; i++)
	{
		g_get_global_snmp_vars()->int_tbl[i].dsIntIndex                    = i + 1;
		strncpy(g_get_global_snmp_vars()->int_tbl[i].dsName, "Not Available",
			sizeof(g_get_global_snmp_vars()->int_tbl[i].dsName));
		g_get_global_snmp_vars()->int_tbl[i].dsTimeOfCreation              = 0;
		g_get_global_snmp_vars()->int_tbl[i].dsTimeOfLastAttempt           = 0;
		g_get_global_snmp_vars()->int_tbl[i].dsTimeOfLastSuccess           = 0;
		g_get_global_snmp_vars()->int_tbl[i].dsFailuresSinceLastSuccess    = 0;
		g_get_global_snmp_vars()->int_tbl[i].dsFailures                    = 0;
		g_get_global_snmp_vars()->int_tbl[i].dsSuccesses                   = 0;
		strncpy(g_get_global_snmp_vars()->int_tbl[i].dsURL, "Not Available",
			sizeof(g_get_global_snmp_vars()->int_tbl[i].dsURL));
	}

	/* Get the semaphore */
	snmp_collator_sem_wait();

	/* Initialize the mmap structure */
	memset((void *) stats, 0, sizeof(*stats));

	/* Load header stats table */
	strncpy(stats->hdr_stats.dsVersion, SLAPD_VERSION_STR,
                (sizeof(stats->hdr_stats.dsVersion)/sizeof(char)) - 1);
	stats->hdr_stats.restarted = 0;			 
	stats->hdr_stats.startTime = time(0);		/* This is a bit off, hope it's ok */
	loadConfigStats();

	/* update the mmap'd tables */
	snmp_update_ops_table();
	snmp_update_entries_table();
	snmp_update_interactions_table();

	/* Release the semaphore */
	sem_post(stats_sem);

	/* create lock for interaction table */
	if (!interaction_table_mutex) {
		interaction_table_mutex = slapi_new_mutex();
	}

	return 0;
}