128
128
DBUG_VOID_RETURN;
131
new_thd->thread_stack= (char*) &new_thd;
132
new_thd->store_globals();
134
new_thd->set_db(db, sizeof(db)-1);
136
bzero((uchar*) &tables,sizeof(tables));
137
tables.alias= tables.table_name= (char*) "func";
138
tables.lock_type = TL_READ;
141
if (simple_open_n_lock_tables(new_thd, &tables))
143
DBUG_PRINT("error",("Can't open udf table"));
144
sql_print_error("Can't open the mysql.func table. Please "
145
"run mysql_upgrade to create it.");
150
init_read_record(&read_record_info, new_thd, table, NULL,1,0);
151
table->use_all_columns();
152
while (!(error= read_record_info.read_record(&read_record_info)))
154
DBUG_PRINT("info",("init udf record"));
156
name.str=get_field(&mem, table->field[0]);
157
name.length = strlen(name.str);
158
char *dl_name= get_field(&mem, table->field[2]);
160
Item_udftype udftype=UDFTYPE_FUNCTION;
161
if (table->s->fields >= 4) // New func table
162
udftype=(Item_udftype) table->field[3]->val_int();
165
Ensure that the .dll doesn't have a path
166
This is done to ensure that only approved dll from the system
167
directories are used (to make this even remotely secure).
169
On windows we must check both FN_LIBCHAR and '/'.
171
if (my_strchr(files_charset_info, dl_name,
172
dl_name + strlen(dl_name), FN_LIBCHAR) ||
173
IF_WIN(my_strchr(files_charset_info, dl_name,
174
dl_name + strlen(dl_name), '/'), 0) ||
175
check_identifier_name(&name))
177
sql_print_error("Invalid row in mysql.func table for function '%.64s'",
182
if (!(tmp= add_udf(&name,(Item_result) table->field[1]->val_int(),
185
sql_print_error("Can't alloc memory for udf function: '%.64s'", name.str);
189
void *dl = find_udf_dl(tmp->dl);
192
char dlpath[FN_REFLEN];
193
strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl,
195
if (!(dl= dlopen(dlpath, RTLD_NOW)))
197
/* Print warning to log */
198
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, errno, dlerror());
199
/* Keep the udf in the hash so that we can remove it later */
206
char buf[NAME_LEN+16], *missing;
207
if ((missing= init_syms(tmp, buf)))
209
sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), missing);
217
sql_print_error("Got unknown error: %d", my_errno);
218
end_read_record(&read_record_info);
219
new_thd->version--; // Force close to free memory
222
133
close_thread_tables(new_thd);
224
135
/* Remember that we don't have a THD */