- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C/C++ access() problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:08 AM
тАО09-17-2009 11:08 AM
This used to work fine using the C compiler and HP OS 10.x. Never noticed till now that it does not on HP OS 11iv2 and the aCC/C v3.7 compiler...
Don't know if this is/was a bug and whether the OS or compiler is causing this...any ideas?
Thx.
#include
#include
int main(int argc, char *argv[])
{
int tmp1 = 0;
tmp1 = access("/root_owned_dir/testfile.txt", 0);
printf("result= %d\n", tmp1);
}
Solved! Go to Solution.
- Tags:
- access
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:23 AM
тАО09-17-2009 11:23 AM
Re: C/C++ access() problem
The code works for me on an 11.23 Itanium box. It correctly returns a result of zero when a file exists and -1 when it doesn't.
By the way, you really should replace the mode parameter with 'F_OK' :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:34 AM
тАО09-17-2009 11:34 AM
Re: C/C++ access() problem
Ok thanks for checking.
I assume you did the following:
mkdir /root_own_dir
touch /root_own_dir/testifile.txt
chmod -R 700 /root_own_dir
chown -R root /root_own_dir
chmod 6755 testit
Then run it as a regular user...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:50 AM
тАО09-17-2009 11:50 AM
Solution-- start man page quote ---
The access() system call checks the file pointed to by path for accessibility according to the bit pattern contained in amode. access() uses the real user ID, not the effective user ID, and the real group ID, not the effective group ID.
--- end man page quote ---
Superuser privileges only change the effective user ID -- the real user ID is still the original user. Hence the behavior you see. Same man page on v1 and v3 and 11.0 -- which makes sense as this could break existing programs and could only have been changed across a major release number version.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:55 AM
тАО09-17-2009 11:55 AM
Re: C/C++ access() problem
> I assume you did the following...
Well no, not the first time; sorry that was silly :-)
OK, so correcting your typos of "/root_own_dir" and "/root_owned_dir" to match and adding a display of the actual 'errno' I do see failure when running as a regular user:
# ./access.o
result=-1 errno=13
# ls -l ./access.o
ls -l access.o
-rwsr-sr-x 1 root sys 70288 Sep 17 15:46 access.o
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 11:58 AM
тАО09-17-2009 11:58 AM
Re: C/C++ access() problem
Don just showed me how to read better :-)
I looked at that manpage and completely missed that even having seen errno=13 as the darn result!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 12:03 PM
тАО09-17-2009 12:03 PM
Re: C/C++ access() problem
If you check the example at the bottom of the man page -- they're checking whether the file "test" is accessible based on the Effective UID instead of the Real UID, which is what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 12:32 PM
тАО09-17-2009 12:32 PM
Re: C/C++ access() problem
Thanks, should have read the man page first. Replacing it with getaccess() does the trick.
James,
Thanks for testing it out for me.
Regards,
Craig.
Code:
#include
#include
#include
#include
int main(int argc, char *argv[])
{
int tmp1 = 0, err = 0;
tmp1 = getaccess("/root_owned_dir/testfile.txt", UID_EUID, NGROUPS_EGID_SUPP,
(int *)0, (void *)0, (void *)0);
if (tmp1 < 0 )
err = errno;
printf("result= %d, err = %d\n", tmp1, err);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2009 12:34 PM
тАО09-17-2009 12:34 PM
Re: C/C++ access() problem
Replaced access() with getaccess()