Hi all, I am writing an apache module for my own use. As a part of this, I have created a new C file mod_log_newtest.c. Then, I have compiled and created .so file by executing these commands ./configure --enable-log_newtest make gcc -shared -o mod_newtest.so mod_newtest.o Then I have changed httpd.conf file by adding one more module. After successfull creation of mod_nestest.so I have inserted this .so file in my apache modules. Then I have restarted my apache server. Everything was fine. It was working when am accessing anything on my web browser. I would like to create a file, when I am calling a virtual host that I have added in my httpd.conf. But I have no permission to create a file in /etc/httpd/conf/logs/ . But if there is a file created and for that file has a write permission I can access that file and I can write into that file. But I cant create a file in that directory. But apache created access_log file and error_log file there. So, I am not able to understand why I cant create a file there. Suppose, if apache can create a file means, I too can. But I have no permission when accessing a virtual host from my browser. There is no mistake in my C program that I have created for apache module FILE *out_file; out_file = fopen(file_mod_path, "a+"); But there will not be a file created. Actually is there any function doing that for apache? I mean is there any module that can create a file like this? I just want to create file in /etc/httld/conf/logs after the execution of a virtual hosts that I have added. I am a fresher and it is the first time I am writing a module for apache and also I dont more about Linux and Apache. But, this feels being very interested and I would like to share your experience with you, if you have interested. Also, it will be a pleasure if you are helping me for this event. Thank You Best Regards, Kapil Krishnan CPK HP
I am not sure apache creates those files. They are usually created by the person/script that adds the vhost.
Apache does create those files but it creates them while running as root. Your module will be running as the normal Apache user (often "www-data", "apache" or "nobody") and won't have permission to modify that directory. Creating a new file counts as modifying a directory. You can work around this by chmoding the directory to 775 rather than the normal 755 and chgrping it to have the same group that Apache runs as. You could also chown the directory to the user that Apache runs as. You can probably access root permissions from within a module but I'm not sure how it's done and I'm not sure you would want to anyway. Running a program as root means that any flaw in your program could result in a complete compromise of your system. That is precisely the reason that Apache drops it's privileges after it does everything it needs to do as root.