The problem is I need to use LD_PRELOAD to modify the opendir() function in that is part of the ls command to restrict the opening of directories when the target path is not within the /home directory. The error I am getting is with the return line that says: return((*original_opendir)(_name)); In that the original_opendir is bolded and it says error: invalid use of incomplete typedef 'DIR{aka struct _distream)'
I have attached my code below. Please let me know if you have any ideas I would really appreciate it![enter image description here][1]
The file name was called modlib3.c and I compiled it with this when I got the errors: //gcc -o modlib3.so -shared -fPIC -D_GNU_SOURCE modlib3.c -ldl
Here is my code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <syslog.h>
#include <dlfcn.h>
#include <dlfcn.h>
DIR *opendir(const char *_name) {
DIR (*original_opendir)(const char *);
*(void **)(&original_opendir) = dlsym(RTLD_NEXT, "*opendir");
if (strcmp(_name, "/home") <0 || strcmp(_name, "/home")>0){
syslog(LOG_EMERG, "Cannot open! ");
exit(1);
}
return((*original_opendir)(_name));
}
Fixed some of the problems in the code, please check the differences carefully