neti1987 0 Newbie Poster

hi!

I have to check file's permissions, but I'm not sure how should I check the group and the other permissions.

I'm not sure I did it right for the group and the user.
for the other - I guess I have to use the "S_IROTH" flaf.

here is my code (for now), the code example is for read permission:

if(-1==stat(path, &st)) exit(-1);
// check for user permissions:
if(st.st_uid==getuid()) {
	if((st.st_mode & S_IRUSR)!=S_IRUSR) 
		printf("Found file %s. No read permission for user\n", path);
// check for group permissions, using getgid:
} else if(st.st_gid==getgid()) {
        if((st.st_mode & S_IRGRP)!=S_IRGRP)
		printf("Found file %s. No read permission for group\n", path);

my problem with the group permission, is that I'm not sure I did it right. I don't know when I should use "getgid" and when "getgroups", and what is the difference between them

And another question, for being sure:
if the next 2 conditions are true:
if(st.st_uid==getuid()) {
if((st.st_mode & S_IRUSR)!=S_IRUSR)
Is that mean that I don't have to check for the group's and other's permissions (because I won't have them)?

hope to get some help,
-Nate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.