why stat() return -1 even if file exists [RHEL 7.2] - stat

I am developing a module for Apache Server. In that, I am trying to read a file from path /tmp/_clusterMemberName/ using stat(const char *filename, struct stat *buf) function. My problem is stat() function returning -1 even if file exists on the path. If I changed the file location from /tmp/_clusterMemberName/ to /opt/ then stat() function is working fine. Please help me to find out the reason.

The most likely reason is that /tmp is not accessible.
You need to look at the errno value that is returned by stat. If it's EACCES, the reason for this is that the user does not have permissions to access /tmp. If it's EPERM, the cause could be SELinux policy preventing httpd from accessing /tmp. If you are using SELinux, make sure you're aware of the httpd_selinux manpage.
You can enable httpd access to /tmp with:
setsebool httpd_tmp_t 1
and make the change persistent with
setsebool -P httpd_tmp_t 1

Related

Creating symbolic links resulting in 500 error

Currently running a WHM / Cpanel server running Centos. Server seems to be running fine no issues there. However I'm using a deployment process to put files outside of the document root. e.g.
~/deployment
instead of:
~/public_html
Obviously I need to point public_html to this folder so my site will run. So, I'm removing the public_html and creating a symlink and pointing it to the new deployment folder. This results in a 500 error.
So looking at the logs I've discovered that it produces the following error:
Directory "/home/xyz/deployment" is writeable by group
Checking the file permissions looks as though the symlink is 777 where i need it to be 755 for the server to allow viewing.
Is there a setting in WHM ? Is there a setting in Centos? I have another box running that doesn't have this issue so I'm assuming that this is related to the current setup of this machine.
Any help would be appreciated, thanks.
when you create a hard link from a file or folder, This file/folder inherits the accesses and permissions of the original file/folder, and in soft link it will be 777 permission, so i think you can use rsync options for both purpose :
1- have a folder with all files in source
2- have your own permissions in folder

PostgreSQL : .pcppass file not found, tried other links

I am working on installing PgPoolAdmin on my local ubuntu system for installing it on server later. Currently, I am able to login but I keep getting an error Could not read .pcppass fileFile not found. I have tried this and many other resources, but no luck. Where is it looking for this file?
The username and passowrd in pcp.conf is same as here, just its in plain text in .pcppass and md5 in pcp.conf. Is that correct?
pcp.conf I have on 2 location /var/www/html and /var/www/html/admin-tool/
Its contents :
#insert:hostname:port:username:password
*:*:akshay:PASSWORD
*:*:postgres:PASSWORD
Thank you.
.pcppass needs to accessible by the user that runs your web server. For example, if you are serving pgpoolAdmin through apache2 with default paths and users. The following should solve the issue.
cp ~/.pcpass /var/www/.pcppass
chown www-data:www-data /var/www/.pcppass
chmod 600 /var/www/.pcppass
By default a .pcppass file should be located in the user's $HOME directory. If you have created it elsewhere, then initialize the $PCPPASSFILE environment variable with the filepath. Make sure the file is in this format:hostname:port:username:password. Then you should be able to access the database.
Note: You cannot use wildcards in the password files, as it will give error sometimes. It is better to use exact host/port values for better security.

Chef insufficient Permissions error on file resource

I have a file, let say xyz.sh, mounted from different file system on centos and root user does not have access to change the permissions of the file.
Current permissions are 755 for the file.
My cookbook's file resource checks for the permissions and if it is not 755 then change it to 755.
When I run the cookbook as root user it is giving an exception as 'Insufficient Permissions'.
Now I would have expected this exception if the file had some different permissions and chef tried to change it but not able to do that, but here as permissions are same as expectation, then why am I getting this exception?
Please help me!
Root is supposed to have permission to access any file in most cases (give or take some retrofits of the Unix filesystem model like POSIX ACLs). Regardless, just remove the mode property from the resource and Chef won't try to enforce anything.

Bad CPU type in executable after modifying usr/bin

I moved a folder into usr/bin because it was in my $PATH variable and I have come to believe that was a bad choice.
Now I can't access the root file structure to revert the change bc terminal won't establish a prompt (bad cpu type error) and I tried to access it via ssh but I get a
ssh_exchange_identification: connection closed error.
Are there any other ways to modify the file structure?
Reinstalling bash from Cydia solved this issue for me.

Stop Oracle from generating sqlnet.log file

I'm using DBD::Oracle in perl, and whenever a connection fails, the client generates a sqlnet.log file with error details.
The thing is, I already have the error trapped by perl, and in my own log file. I really don't need this extra information.
So, is there a flag or environment for stopping the creation of sqlnet.log?
As the Oracle Documentation states: To ensure that all errors are recorded, logging cannot be disabled on clients or Names Servers.
You can follow the suggestion of DCookie and use the /dev/null as the log directory. You can use NUL: on windows machines.
From the metalink
The logging is automatic, there is no way to turn logging off, but since you are on Unix server, you can redirect the log file to a null device, thus eliminating the problem of disk space consumption.
In the SQLNET.ORA file, set LOG_DIRECTORY_CLIENT and LOG_DIRECTORY_SERVER equal to a null device.
For example:
LOG_DIRECTORY_CLIENT = /dev/null
LOG_FILE_CLIENT = /dev/null
in SQLNET.ORA suppresses client logging completely.
To disable the listener from logging, set this parameter in the LISTENER.ORA file:
logging_listener = off
Are your clients on Windows, or *nix? If in *nix, you can set LOG_DIRECTORY_CLIENT=/dev/null in your sqlnet.ora file. Not sure if you can do much for a windows client.
EDIT: Doesn't look like it's possible in Windows. The best you could do would be to set the sqlnet.ora parameter above to a fixed location and create a scheduled task to delete the file as desired.
Okay, as Thomas points out there is a null device on windows, use the same paradigm.
IMPORTANT: DO NOT SET "LOG_FILE_CLIENT=/dev/null", this will cause permissions of /dev/null be reset each time your initialize oracle library, and when your umask is something that does not permit world readable-writable bits, those get removed from /dev/null and if you have permission to chmod that file: i.e running as root.
and running as root maybe something trivial, like php --version having oci php-extension present!
full details here:
http://lists.pld-linux.org/mailman/pipermail/pld-devel-en/2014-May/023931.html
you should use path inside directory that doesn't exist:
LOG_FILE_CLIENT = /dev/impossible/path
and hope nobody creates dir /dev/impossible :)
for Windows NUL probably is fine as it's not actual file there...