static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_NAMESTORE_PluginFunctions *nsp; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; struct GNUNET_CRYPTO_ShortHashCode zone; ok = 0; nsp = load_plugin (cfg); if (NULL == nsp) { FPRINTF (stderr, "%s", "Failed to initialize namestore. Database likely not setup, skipping test.\n"); return; } put_record (nsp, 1); get_record (nsp, 1); memset (&zone_key, 1, sizeof (zone_key)); GNUNET_CRYPTO_short_hash (&zone_key, sizeof (zone_key), &zone); nsp->delete_zone (nsp->cls, &zone); unload_plugin (nsp); }
static void plugins_changed_cb (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data) { gchar *path; PhidiasLoader *loader; path = g_file_get_path (file); loader = user_data; if (g_str_has_suffix (path, ".la") == TRUE) { switch (event_type) { case G_FILE_MONITOR_EVENT_DELETED: unload_plugin (loader, path); break; case G_FILE_MONITOR_EVENT_CREATED: load_plugin (loader, path); break; default: break; } } g_free (path); }
/** * Default d-tor */ NSCPlugin::~NSCPlugin() { if (isLoaded()) { try { unload_plugin(); unload_dll(); } catch (const NSPluginException&) { // ... } } }
// Decrements the reference count on the "plugin" library. This must // correspond to an earlier call to ref_plugin(). When the last // reference is removed, the plugin will be unloaded. void PPInstance:: unref_plugin() { assert( s_instanceCount > 0 ); s_instanceCount -= 1; if ( s_instanceCount == 0 && is_plugin_loaded() ) { nout << "Unloading core API\n"; unload_plugin(); // This pointer is no longer valid and must be reset for next // time. PPBrowserObject::clear_class_definition(); } }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_NAMESTORE_PluginFunctions *nsp; ok = 0; nsp = load_plugin (cfg); if (NULL == nsp) { FPRINTF (stderr, "%s", "Failed to initialize namestore. Database likely not setup, skipping test.\n"); return; } put_record (nsp, 1); get_record (nsp, 1); unload_plugin (nsp); }
int remote_sig_core_unload_plugin(char *arg) { print_debug("%s: attempting to unload %s plugin\n", GGadu_PLUGIN_NAME, arg); unload_plugin(arg); return 0; }
static inline bool trigger_plugin_event(JCR *jcr, bDirEventType eventType, bDirEvent *event, bpContext *ctx, void *value, alist *plugin_ctx_list, int *index, bRC *rc) { bool stop = false; if (!is_event_enabled(ctx, eventType)) { Dmsg1(dbglvl, "Event %d disabled for this plugin.\n", eventType); goto bail_out; } if (is_plugin_disabled(ctx)) { Dmsg0(dbglvl, "Plugin disabled.\n"); goto bail_out; } /* * See if we should care about the return code. */ if (rc) { *rc = dirplug_func(ctx->plugin)->handlePluginEvent(ctx, event, value); switch (*rc) { case bRC_OK: break; case bRC_Stop: case bRC_Error: stop = true; break; case bRC_More: break; case bRC_Term: /* * Request to unload this plugin. * As we remove the plugin from the list of plugins we decrement * the running index value so the next plugin gets triggered as * that moved back a position in the alist. */ if (index) { unload_plugin(plugin_ctx_list, ctx->plugin, *index); *index = ((*index) - 1); } break; case bRC_Seen: break; case bRC_Core: break; case bRC_Skip: stop = true; break; case bRC_Cancel: break; default: break; } } else { dirplug_func(ctx->plugin)->handlePluginEvent(ctx, event, value); } bail_out: return stop; }
/* Detect plugin */ hash_stat detect_plugin(char *plugindir,char *file, char *hash) { struct dirent **dentrylist; char soname[1024]; DIR *dir; int count=-1,i=0; char line[1024]; FILE *fd; char *preferred_plugins[] = { "ntlm","sha1","md5","lm","sha256","sha512","smf","vbulletin","ipb2",NULL }; char *preferred_special_plugins[] = { "zip","rar","wpa","privkey",NULL }; char *detected_plugins[128]; int detected; char *detected_list; int detected_list_size=0; int j,flag; char lhash[256]; // Local hashline copy cause some plugins play rough with strtok /* We are now detecting plugins, don't be verbose */ detecting=1; /* Init */ detected=-1; /* Is a cmdline hash? */ i=0; if (hash) { dir=opendir(plugindir); if (!dir) { elog("Cannot open plugins dir: %s", plugindir); return hash_err; } closedir(dir); count = scandir(plugindir, &dentrylist, 0, alphasort); /* First check preferred plugins */ while (preferred_plugins[i]) { strcpy(soname,preferred_plugins[i]); set_current_plugin(soname); if (load_plugin() == hash_ok) if (!hash_plugin_is_special()) { strcpy(lhash,hash); if (hash_plugin_parse_hash(lhash,NULL) == hash_ok) { detected++; detected_plugins[detected]=malloc(strlen(preferred_plugins[i]+1)); strcpy(detected_plugins[detected],preferred_plugins[i]); } unload_plugin(); } i++; } /* Then the next, in order */ i=0; do { if (strstr(dentrylist[i]->d_name, ".so")) { strcpy(soname,dentrylist[i]->d_name); soname[strlen(soname)-3]=0; set_current_plugin(soname); if (load_plugin() == hash_ok) if (!hash_plugin_is_special()) { strcpy(lhash,hash); if (hash_plugin_parse_hash(lhash,NULL) == hash_ok) { flag=0; for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1; if (flag==0) { detected++; detected_plugins[detected]=malloc(strlen(soname)+1); strcpy(detected_plugins[detected],soname); } } unload_plugin(); } } i++; } while (i<count); free(dentrylist); } /* Is a hashfile (but hashlist)? */ i=0; if (file) { fd=fopen(file,"r"); if (!fd) { elog("Cannot open %s\n",file); return hash_err; } fgets(line,1024,fd); line[1023]=0; if (strlen(line)<1) fgets(line,1024,fd); line[1023]=0; fclose(fd); if (line[strlen(line)-1]=='\n') line[strlen(line)-1]=0; if (line[strlen(line)-1]=='\r') line[strlen(line)-1]=0; dir=opendir(plugindir); if (!dir) { elog("Cannot open plugins dir: %s", plugindir); return hash_err; } closedir(dir); count = scandir(plugindir, &dentrylist, 0, alphasort); /* First check preferred plugins */ while (preferred_plugins[i]) { strcpy(soname,preferred_plugins[i]); set_current_plugin(soname); if (load_plugin() == hash_ok) if (!hash_plugin_is_special()) { strcpy(lhash,line); if (hash_plugin_parse_hash(lhash,NULL) == hash_ok) { detected++; detected_plugins[detected]=malloc(strlen(preferred_plugins[i])); strcpy(detected_plugins[detected],preferred_plugins[i]); } unload_plugin(); } i++; } /* Then the next, in order */ i=0; do { if (strstr(dentrylist[i]->d_name, ".so")) { strcpy(soname,dentrylist[i]->d_name); soname[strlen(soname)-3]=0; set_current_plugin(soname); if (load_plugin() == hash_ok) if (!hash_plugin_is_special()) { strcpy(lhash,line); if (hash_plugin_parse_hash(lhash,NULL) == hash_ok) { flag=0; for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1; if (flag==0) { detected++; detected_plugins[detected]=malloc(strlen(soname)+1); strcpy(detected_plugins[detected],soname); } } unload_plugin(); } } i++; } while (i<count); free(dentrylist); } /* Is a hashfile (but not hashlist)? */ i=0; if (file) { dir=opendir(plugindir); if (!dir) { elog("Cannot open plugins dir: %s", plugindir); return hash_err; } closedir(dir); count = scandir(plugindir, &dentrylist, 0, alphasort); /* First check preferred plugins */ while (preferred_special_plugins[i]) { strcpy(soname,preferred_special_plugins[i]); set_current_plugin(soname); if (load_plugin() == hash_ok) if (hash_plugin_is_special()) { if (hash_plugin_parse_hash("dummy",file) == hash_ok) { detected++; detected_plugins[detected]=malloc(strlen(preferred_special_plugins[i])+1); strcpy(detected_plugins[detected],preferred_special_plugins[i]); } unload_plugin(); } i++; } /* Then the next, in order */ i=0; do { if (strstr(dentrylist[i]->d_name, ".so")) { strcpy(soname,dentrylist[i]->d_name); soname[strlen(soname)-3]=0; set_current_plugin(soname); if (load_plugin() == hash_ok) if (hash_plugin_is_special()) { if (hash_plugin_parse_hash("dummy",file) == hash_ok) { flag=0; for (j=0;j<=detected;j++) if (strcmp(detected_plugins[j],soname)==0) flag=1; if (flag==0) { detected++; detected_plugins[detected] = malloc(strlen(soname)+1); strcpy(detected_plugins[detected],soname); } } unload_plugin(); } } i++; } while (i<count); free(dentrylist); } detected++; detecting=0; if (detected > 1) { for (i=0;i<detected;i++) { detected_list_size += strlen(detected_plugins[i])+1; } detected_list = malloc(detected_list_size+1); bzero(detected_list,detected_list_size); for (i=0;i<detected;i++) { sprintf(detected_list,"%s %s",detected_list,detected_plugins[i]); } wlog("Warning: multiple plugins match this input!%s\n",""); wlog("Plugins available:%s\n",detected_list); wlog("Choosing %s. If that's not what you meant, use the -p <plugin> switch!\n",detected_plugins[0]); set_current_plugin(detected_plugins[0]); load_plugin(); free(detected_list); for (i=0;i<detected;i++) free(detected_plugins[i]); return hash_ok; } if (detected == 1) { hlog("Loading plugin %s\n",detected_plugins[0]); set_current_plugin(detected_plugins[0]); load_plugin(); free(detected_plugins[0]); return hash_ok; } return hash_err; }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_PSYCSTORE_PluginFunctions *db; ok = 1; db = load_plugin (cfg); if (NULL == db) { FPRINTF (stderr, "%s", "Failed to initialize PSYCstore. " "Database likely not setup, skipping test.\n"); ok = 77; return; } /* Store & test membership */ LOG (GNUNET_ERROR_TYPE_INFO, "MEMBERSHIP\n"); channel_key = GNUNET_CRYPTO_eddsa_key_create (); slave_key = GNUNET_CRYPTO_ecdsa_key_create (); GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key); GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key); LOG (GNUNET_ERROR_TYPE_INFO, "membership_store()\n"); GNUNET_assert (GNUNET_OK == db->membership_store (db->cls, &channel_pub_key, &slave_pub_key, GNUNET_YES, 4, 2, 1)); LOG (GNUNET_ERROR_TYPE_INFO, "membership_test()\n"); GNUNET_assert (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key, &slave_pub_key, 4)); GNUNET_assert (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key, &slave_pub_key, 2)); GNUNET_assert (GNUNET_NO == db->membership_test (db->cls, &channel_pub_key, &slave_pub_key, 1)); /* Store & get messages */ LOG (GNUNET_ERROR_TYPE_INFO, "MESSAGES\n"); struct GNUNET_MULTICAST_MessageHeader *msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); GNUNET_assert (msg != NULL); msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key)); uint64_t fragment_id = INT64_MAX - 1; msg->fragment_id = GNUNET_htonll (fragment_id); uint64_t message_id = INT64_MAX - 10; msg->message_id = GNUNET_htonll (message_id); uint64_t group_generation = INT64_MAX - 3; msg->group_generation = GNUNET_htonll (group_generation); msg->hop_counter = htonl (9); msg->fragment_offset = GNUNET_htonll (0); msg->flags = htonl (GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT); GNUNET_memcpy (&msg[1], &channel_pub_key, sizeof (channel_pub_key)); msg->purpose.size = htonl (ntohs (msg->header.size) - sizeof (msg->header) - sizeof (msg->hop_counter) - sizeof (msg->signature)); msg->purpose.purpose = htonl (234); GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (channel_key, &msg->purpose, &msg->signature)); LOG (GNUNET_ERROR_TYPE_INFO, "fragment_store()\n"); struct FragmentClosure fcls = { 0 }; fcls.n = 0; fcls.msg[0] = msg; fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE; GNUNET_assert ( GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg, fcls.flags[0])); LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id); uint64_t ret_frags = 0; GNUNET_assert ( GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, fragment_id, fragment_id, &ret_frags, fragment_cb, &fcls)); GNUNET_assert (fcls.n == 1); LOG (GNUNET_ERROR_TYPE_INFO, "message_get_fragment()\n"); fcls.n = 0; GNUNET_assert ( GNUNET_OK == db->message_get_fragment (db->cls, &channel_pub_key, GNUNET_ntohll (msg->message_id), GNUNET_ntohll (msg->fragment_offset), fragment_cb, &fcls)); GNUNET_assert (fcls.n == 1); LOG (GNUNET_ERROR_TYPE_INFO, "message_add_flags()\n"); GNUNET_assert ( GNUNET_OK == db->message_add_flags (db->cls, &channel_pub_key, GNUNET_ntohll (msg->message_id), GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED)); LOG (GNUNET_ERROR_TYPE_INFO, "fragment_get(%" PRIu64 ")\n", fragment_id); fcls.n = 0; fcls.flags[0] |= GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED; GNUNET_assert ( GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, fragment_id, fragment_id, &ret_frags, fragment_cb, &fcls)); GNUNET_assert (fcls.n == 1); LOG (GNUNET_ERROR_TYPE_INFO, "fragment_store()\n"); struct GNUNET_MULTICAST_MessageHeader *msg1 = GNUNET_malloc (sizeof (*msg1) + sizeof (channel_pub_key)); GNUNET_memcpy (msg1, msg, sizeof (*msg1) + sizeof (channel_pub_key)); msg1->fragment_id = GNUNET_htonll (INT64_MAX); msg1->fragment_offset = GNUNET_htonll (32768); fcls.n = 0; fcls.msg[1] = msg1; fcls.flags[1] = GNUNET_PSYCSTORE_MESSAGE_STATE_HASH; GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg1, fcls.flags[1])); LOG (GNUNET_ERROR_TYPE_INFO, "message_get()\n"); GNUNET_assert ( GNUNET_OK == db->message_get (db->cls, &channel_pub_key, message_id, message_id, 0, &ret_frags, fragment_cb, &fcls)); GNUNET_assert (fcls.n == 2 && ret_frags == 2); /* Message counters */ LOG (GNUNET_ERROR_TYPE_INFO, "counters_message_get()\n"); fragment_id = 0; message_id = 0; group_generation = 0; GNUNET_assert ( GNUNET_OK == db->counters_message_get (db->cls, &channel_pub_key, &fragment_id, &message_id, &group_generation) && fragment_id == GNUNET_ntohll (msg1->fragment_id) && message_id == GNUNET_ntohll (msg1->message_id) && group_generation == GNUNET_ntohll (msg1->group_generation)); /* Modify state */ LOG (GNUNET_ERROR_TYPE_INFO, "STATE\n"); LOG (GNUNET_ERROR_TYPE_INFO, "state_modify_*()\n"); message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 1; GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, message_id, 0)); GNUNET_assert (GNUNET_OK == db->state_modify_op (db->cls, &channel_pub_key, GNUNET_PSYC_OP_ASSIGN, "_foo", C2ARG("one two three"))); GNUNET_assert (GNUNET_OK == db->state_modify_op (db->cls, &channel_pub_key, GNUNET_PSYC_OP_ASSIGN, "_foo_bar", slave_key, sizeof (*slave_key))); GNUNET_assert (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key, message_id)); LOG (GNUNET_ERROR_TYPE_INFO, "state_get()\n"); struct StateClosure scls = { 0 }; scls.n = 0; scls.value[0] = "one two three"; scls.value_size[0] = strlen ("one two three"); GNUNET_assert (GNUNET_OK == db->state_get (db->cls, &channel_pub_key, "_foo", state_cb, &scls)); GNUNET_assert (scls.n == 1); LOG (GNUNET_ERROR_TYPE_INFO, "state_get_prefix()\n"); scls.n = 0; scls.value[1] = slave_key; scls.value_size[1] = sizeof (*slave_key); GNUNET_assert (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key, "_foo", state_cb, &scls)); GNUNET_assert (scls.n == 2); LOG (GNUNET_ERROR_TYPE_INFO, "state_get_signed()\n"); scls.n = 0; GNUNET_assert (GNUNET_NO == db->state_get_signed (db->cls, &channel_pub_key, state_cb, &scls)); GNUNET_assert (scls.n == 0); LOG (GNUNET_ERROR_TYPE_INFO, "state_update_signed()\n"); GNUNET_assert (GNUNET_OK == db->state_update_signed (db->cls, &channel_pub_key)); LOG (GNUNET_ERROR_TYPE_INFO, "state_get_signed()\n"); scls.n = 0; GNUNET_assert (GNUNET_YES == db->state_get_signed (db->cls, &channel_pub_key, state_cb, &scls)); GNUNET_assert (scls.n == 2); /* State counters */ LOG (GNUNET_ERROR_TYPE_INFO, "counters_state_get()\n"); uint64_t max_state_msg_id = 0; GNUNET_assert (GNUNET_OK == db->counters_state_get (db->cls, &channel_pub_key, &max_state_msg_id) && max_state_msg_id == message_id); /* State sync */ LOG (GNUNET_ERROR_TYPE_INFO, "state_sync_*()\n"); scls.n = 0; scls.value[0] = channel_key; scls.value_size[0] = sizeof (*channel_key); scls.value[1] = "three two one"; scls.value_size[1] = strlen ("three two one"); GNUNET_assert (GNUNET_OK == db->state_sync_begin (db->cls, &channel_pub_key)); GNUNET_assert (GNUNET_OK == db->state_sync_assign (db->cls, &channel_pub_key, "_sync_bar", scls.value[0], scls.value_size[0])); GNUNET_assert (GNUNET_OK == db->state_sync_assign (db->cls, &channel_pub_key, "_sync_foo", scls.value[1], scls.value_size[1])); GNUNET_assert (GNUNET_OK == db->state_sync_end (db->cls, &channel_pub_key, max_state_msg_id, INT64_MAX - 5)); GNUNET_assert (GNUNET_NO == db->state_get_prefix (db->cls, &channel_pub_key, "_foo", state_cb, &scls)); GNUNET_assert (scls.n == 0); GNUNET_assert (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key, "_sync", state_cb, &scls)); GNUNET_assert (scls.n == 2); scls.n = 0; GNUNET_assert (GNUNET_OK == db->state_get_signed (db->cls, &channel_pub_key, state_cb, &scls)); GNUNET_assert (scls.n == 2); /* Modify state after sync */ LOG (GNUNET_ERROR_TYPE_INFO, "state_modify_*()\n"); message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 6; GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, message_id, message_id - max_state_msg_id)); GNUNET_assert (GNUNET_OK == db->state_modify_op (db->cls, &channel_pub_key, GNUNET_PSYC_OP_ASSIGN, "_sync_foo", C2ARG("five six seven"))); GNUNET_assert (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key, message_id)); /* Reset state */ LOG (GNUNET_ERROR_TYPE_INFO, "state_reset()\n"); scls.n = 0; GNUNET_assert (GNUNET_OK == db->state_reset (db->cls, &channel_pub_key)); GNUNET_assert (scls.n == 0); ok = 0; if (NULL != channel_key) { GNUNET_free (channel_key); channel_key = NULL; } if (NULL != slave_key) { GNUNET_free (slave_key); slave_key = NULL; } unload_plugin (db); }