Lines 173-178
Link Here
|
173 |
#endif |
173 |
#endif |
174 |
|
174 |
|
175 |
|
175 |
|
|
|
176 |
#ifdef COPY_MODULE_ONLOAD |
176 |
void DeleteTempModules(void) |
177 |
void DeleteTempModules(void) |
177 |
{ |
178 |
{ |
178 |
char tempbuf[PATH_MAX+1]; |
179 |
char tempbuf[PATH_MAX+1]; |
Lines 221-226
Link Here
|
221 |
FindClose(hFile); |
222 |
FindClose(hFile); |
222 |
#endif |
223 |
#endif |
223 |
} |
224 |
} |
|
|
225 |
#endif |
224 |
|
226 |
|
225 |
void Module_Init(void) |
227 |
void Module_Init(void) |
226 |
{ |
228 |
{ |
Lines 322-331
Link Here
|
322 |
path_)); |
324 |
path_)); |
323 |
path = path_; |
325 |
path = path_; |
324 |
|
326 |
|
325 |
|
327 |
#ifdef COPY_MODULE_ONLOAD |
|
|
328 |
/* running on linux using grsecurity's trusted path execution will prevent |
329 |
* module loading from the /tmp folder due to the module not being owned |
330 |
* by root. Define COPY_MODULE_ONLOAD if you wish to use the unreal functions |
331 |
* to copy the module before loading it. |
332 |
*/ |
326 |
tmppath = unreal_mktemp("tmp", unreal_getfilename(path)); |
333 |
tmppath = unreal_mktemp("tmp", unreal_getfilename(path)); |
327 |
if (!tmppath) |
334 |
if (!tmppath) |
328 |
return "Unable to create temporary file!"; |
335 |
return "Unable to create temporary file!"; |
|
|
336 |
#endif |
329 |
if(!strchr(path, '/')) |
337 |
if(!strchr(path, '/')) |
330 |
{ |
338 |
{ |
331 |
path = MyMalloc(strlen(path) + 3); |
339 |
path = MyMalloc(strlen(path) + 3); |
Lines 338-343
Link Here
|
338 |
snprintf(errorbuf, sizeof(errorbuf), "Cannot open module file: %s", strerror(errno)); |
346 |
snprintf(errorbuf, sizeof(errorbuf), "Cannot open module file: %s", strerror(errno)); |
339 |
return errorbuf; |
347 |
return errorbuf; |
340 |
} |
348 |
} |
|
|
349 |
#ifdef COPY_MODULE_ONLOAD |
350 |
/* running on linux using grsecurity's trusted path execution will prevent |
351 |
* module loading from the /tmp folder due to the module not being owned |
352 |
* by root. Define COPY_MODULE_ONLOAD if you wish to use the unreal functions |
353 |
* to copy the module before loading it. |
354 |
*/ |
341 |
#ifdef __OpenBSD__ |
355 |
#ifdef __OpenBSD__ |
342 |
/* For OpenBSD, do not do a hardlinkink attempt first because it checks inode |
356 |
/* For OpenBSD, do not do a hardlinkink attempt first because it checks inode |
343 |
* numbers to see if a certain module is already loaded. -- Syzop |
357 |
* numbers to see if a certain module is already loaded. -- Syzop |
Lines 351-356
Link Here
|
351 |
snprintf(errorbuf, sizeof(errorbuf), "Failed to copy module file."); |
365 |
snprintf(errorbuf, sizeof(errorbuf), "Failed to copy module file."); |
352 |
return errorbuf; |
366 |
return errorbuf; |
353 |
} |
367 |
} |
|
|
368 |
#else |
369 |
tmppath = path; |
370 |
#endif |
354 |
if ((Mod = irc_dlopen(tmppath, RTLD_NOW))) |
371 |
if ((Mod = irc_dlopen(tmppath, RTLD_NOW))) |
355 |
{ |
372 |
{ |
356 |
/* We have engaged the borg cube. Scan for lifesigns. */ |
373 |
/* We have engaged the borg cube. Scan for lifesigns. */ |
Lines 361-367
Link Here
|
361 |
"Module was compiled for '%s', we were configured for '%s'. SOLUTION: Recompile the module(s).", |
378 |
"Module was compiled for '%s', we were configured for '%s'. SOLUTION: Recompile the module(s).", |
362 |
Mod_Version, expectedmodversion); |
379 |
Mod_Version, expectedmodversion); |
363 |
irc_dlclose(Mod); |
380 |
irc_dlclose(Mod); |
|
|
381 |
#ifdef COPY_MODULE_ONLOAD |
364 |
remove(tmppath); |
382 |
remove(tmppath); |
|
|
383 |
#endif |
365 |
return errorbuf; |
384 |
return errorbuf; |
366 |
} |
385 |
} |
367 |
if (!Mod_Version) |
386 |
if (!Mod_Version) |
Lines 369-375
Link Here
|
369 |
snprintf(errorbuf, sizeof(errorbuf), |
388 |
snprintf(errorbuf, sizeof(errorbuf), |
370 |
"Module is lacking Mod_Version. Perhaps a very old one you forgot to recompile?"); |
389 |
"Module is lacking Mod_Version. Perhaps a very old one you forgot to recompile?"); |
371 |
irc_dlclose(Mod); |
390 |
irc_dlclose(Mod); |
|
|
391 |
#ifdef COPY_MODULE_ONLOAD |
372 |
remove(tmppath); |
392 |
remove(tmppath); |
|
|
393 |
#endif |
373 |
return errorbuf; |
394 |
return errorbuf; |
374 |
} |
395 |
} |
375 |
irc_dlsym(Mod, "compiler_version", compiler_version); |
396 |
irc_dlsym(Mod, "compiler_version", compiler_version); |
Lines 382-401
Link Here
|
382 |
"Module was compiled with GCC %s, core was compiled with GCC %s. SOLUTION: Recompile your UnrealIRCd and all it's modules by doing a 'make clean; ./Config -quick && make'.", |
403 |
"Module was compiled with GCC %s, core was compiled with GCC %s. SOLUTION: Recompile your UnrealIRCd and all it's modules by doing a 'make clean; ./Config -quick && make'.", |
383 |
theyhad, wehave); |
404 |
theyhad, wehave); |
384 |
irc_dlclose(Mod); |
405 |
irc_dlclose(Mod); |
|
|
406 |
#ifdef COPY_MODULE_ONLOAD |
385 |
remove(tmppath); |
407 |
remove(tmppath); |
|
|
408 |
#endif |
386 |
return errorbuf; |
409 |
return errorbuf; |
387 |
} |
410 |
} |
388 |
irc_dlsym(Mod, "Mod_Header", mod_header); |
411 |
irc_dlsym(Mod, "Mod_Header", mod_header); |
389 |
if (!mod_header) |
412 |
if (!mod_header) |
390 |
{ |
413 |
{ |
391 |
irc_dlclose(Mod); |
414 |
irc_dlclose(Mod); |
|
|
415 |
#ifdef COPY_MODULE_ONLOAD |
392 |
remove(tmppath); |
416 |
remove(tmppath); |
|
|
417 |
#endif |
393 |
return ("Unable to locate Mod_Header"); |
418 |
return ("Unable to locate Mod_Header"); |
394 |
} |
419 |
} |
395 |
if (!mod_header->modversion) |
420 |
if (!mod_header->modversion) |
396 |
{ |
421 |
{ |
397 |
irc_dlclose(Mod); |
422 |
irc_dlclose(Mod); |
|
|
423 |
#ifdef COPY_MODULE_ONLOAD |
398 |
remove(tmppath); |
424 |
remove(tmppath); |
|
|
425 |
#endif |
399 |
return ("Lacking mod_header->modversion"); |
426 |
return ("Lacking mod_header->modversion"); |
400 |
} |
427 |
} |
401 |
if (!(modsys_ver = parse_modsys_version(mod_header->modversion))) |
428 |
if (!(modsys_ver = parse_modsys_version(mod_header->modversion))) |
Lines 403-422
Link Here
|
403 |
snprintf(errorbuf, 1023, "Unsupported module system version '%s'", |
430 |
snprintf(errorbuf, 1023, "Unsupported module system version '%s'", |
404 |
mod_header->modversion); |
431 |
mod_header->modversion); |
405 |
irc_dlclose(Mod); |
432 |
irc_dlclose(Mod); |
|
|
433 |
#ifdef COPY_MODULE_ONLOAD |
406 |
remove(tmppath); |
434 |
remove(tmppath); |
|
|
435 |
#endif |
407 |
return(errorbuf); |
436 |
return(errorbuf); |
408 |
} |
437 |
} |
409 |
if (!mod_header->name || !mod_header->version || |
438 |
if (!mod_header->name || !mod_header->version || |
410 |
!mod_header->description) |
439 |
!mod_header->description) |
411 |
{ |
440 |
{ |
412 |
irc_dlclose(Mod); |
441 |
irc_dlclose(Mod); |
|
|
442 |
#ifdef COPY_MODULE_ONLOAD |
413 |
remove(tmppath); |
443 |
remove(tmppath); |
|
|
444 |
#endif |
414 |
return("Lacking sane header pointer"); |
445 |
return("Lacking sane header pointer"); |
415 |
} |
446 |
} |
416 |
if (Module_Find(mod_header->name)) |
447 |
if (Module_Find(mod_header->name)) |
417 |
{ |
448 |
{ |
418 |
irc_dlclose(Mod); |
449 |
irc_dlclose(Mod); |
|
|
450 |
#ifdef COPY_MODULE_ONLOAD |
419 |
remove(tmppath); |
451 |
remove(tmppath); |
|
|
452 |
#endif |
420 |
return (NULL); |
453 |
return (NULL); |
421 |
} |
454 |
} |
422 |
mod = (Module *)Module_make(mod_header, Mod); |
455 |
mod = (Module *)Module_make(mod_header, Mod); |
Lines 699-705
Link Here
|
699 |
} |
732 |
} |
700 |
DelListItem(mi,Modules); |
733 |
DelListItem(mi,Modules); |
701 |
irc_dlclose(mi->dll); |
734 |
irc_dlclose(mi->dll); |
|
|
735 |
#ifdef COPY_MODULE_ONLOAD |
702 |
remove(mi->tmp_file); |
736 |
remove(mi->tmp_file); |
|
|
737 |
#endif |
703 |
MyFree(mi->tmp_file); |
738 |
MyFree(mi->tmp_file); |
704 |
MyFree(mi); |
739 |
MyFree(mi); |
705 |
} |
740 |
} |
Lines 1556-1562
Link Here
|
1556 |
irc_dlsym(m->dll, "Mod_Unload", Mod_Unload); |
1591 |
irc_dlsym(m->dll, "Mod_Unload", Mod_Unload); |
1557 |
if (Mod_Unload) |
1592 |
if (Mod_Unload) |
1558 |
(*Mod_Unload)(0); |
1593 |
(*Mod_Unload)(0); |
|
|
1594 |
#ifdef COPY_MODULE_ONLOAD |
1559 |
remove(m->tmp_file); |
1595 |
remove(m->tmp_file); |
|
|
1596 |
#endif |
1560 |
} |
1597 |
} |
1561 |
} |
1598 |
} |
1562 |
|
1599 |
|