| 742 | #endif /* HAVE_DLOPEN */ |
| 743 | |
| 744 | static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, myf MyFlags) |
| 745 | { |
| 746 | #ifdef HAVE_DLOPEN |
| 747 | char dlpath[FN_REFLEN]; |
| 748 | size_t plugin_dir_len,i; |
| 749 | uint dummy_errors; |
| 750 | struct st_plugin_dl *tmp= 0, plugin_dl; |
| 751 | void *sym; |
| 752 | st_ptr_backup tmp_backup[array_elements(list_of_services)]; |
| 753 | DBUG_ENTER("plugin_dl_add"); |
| 754 | DBUG_PRINT("enter", ("dl->str: '%s', dl->length: %d", |
| 755 | dl->str, (int) dl->length)); |
| 756 | mysql_mutex_assert_owner(&LOCK_plugin); |
| 757 | plugin_dir_len= strlen(opt_plugin_dir); |
| 758 | /* |
| 759 | Ensure that the dll doesn't have a path. |
| 760 | This is done to ensure that only approved libraries from the |
| 761 | plugin directory are used (to make this even remotely secure). |
| 762 | */ |
| 763 | if (check_string_char_length((LEX_CSTRING *) dl, 0, NAME_CHAR_LEN, |
| 764 | system_charset_info, 1) || |
| 765 | check_valid_path(dl->str, dl->length) || |
| 766 | plugin_dir_len + dl->length + 1 >= FN_REFLEN) |
| 767 | { |
| 768 | my_error(ER_UDF_NO_PATHS, MyFlags); |
| 769 | DBUG_RETURN(0); |
| 770 | } |
| 771 | /* If this dll is already loaded just increase ref_count. */ |
| 772 | if ((tmp= plugin_dl_find(dl))) |
| 773 | { |
| 774 | tmp->ref_count++; |
| 775 | DBUG_RETURN(tmp); |
| 776 | } |
| 777 | bzero(&plugin_dl, sizeof(plugin_dl)); |
| 778 | /* Compile dll path */ |
| 779 | strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS); |
| 780 | (void) unpack_filename(dlpath, dlpath); |
| 781 | plugin_dl.ref_count= 1; |
| 782 | /* Open new dll handle */ |
| 783 | if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW))) |
| 784 | { |
| 785 | if (!opt_silent_startup) |
| 786 | my_error(ER_CANT_OPEN_LIBRARY, MyFlags, dlpath, errno, |
| 787 | my_dlerror(dlpath)); |
| 788 | goto ret; |
| 789 | } |
| 790 | dlopen_count++; |
| 791 | |
| 792 | #ifdef HAVE_LINK_H |
| 793 | if (global_system_variables.log_warnings > 2) |
| 794 | { |
| 795 | struct link_map *lm = (struct link_map*) plugin_dl.handle; |
| 796 | sql_print_information("Loaded '%s' with offset 0x%zx", dl->str, (size_t)lm->l_addr); |
| 797 | } |
| 798 | #endif |
| 799 | |
| 800 | /* Checks which plugin interface present and reads info */ |
| 801 | if (!(sym= dlsym(plugin_dl.handle, maria_plugin_interface_version_sym))) |
no test coverage detected