c - How can I check to see if user has execute permissions? -
i wish know how check if "user" (other running program) has execute permissions on file ? [c api]
i have looked @ "access" gives information respect caller.
i looking :-
"<cmd> <user_name> <file_name>"
here trying if <user_name>
has execute permissions <file_name>
?
i looking c api ?
possible solution :- using following algo information
boolean_t is_user_has_execute_permissions(char *run_as_user) { /* check world execute permission */ if ((cmd_stat.st_mode & s_ixoth) == s_ixoth) { return (true); } /* group id run_as_user */ getpwnam_r(run_as_user, &pw, buf, passwd_len); /* check group execute permission */ if ((cmd_stat.st_mode & s_ixgrp) == s_ixgrp) { if (pw->pw_gid == cmd_stat.st_gid) return (true); } return (false); }
did see error in 1 ?
you need call stat(2), returns permission bits, owner of file, owner group, , others. have find out id of user you're interested in , ids groups: see getpwent(3) , getgrouplist(3). first match, give resulting permissions.
Comments
Post a Comment