Sponsored Content
Top Forums Programming Determining file access perms for current process Post 302467523 by DreamWarrior on Friday 29th of October 2010 04:28:43 PM
Old 10-29-2010
Determining file access perms for current process

Stupid question, but is there an ANSI C stdlib function that will do this for me? I want to pass the function a path and determine if the current process can read/write/execute on the path. I suppose I can whip something up using fstat and then determining the current process's user/group IDs and checking against the file's mode...but I don't want to reinvent the wheel if something already exists.

Thanks!

-- DreamWarrior

P.S. I am sure this is a n00b question, and I'm in fact even surprised in all my years I've never actually done anything like this. I typically just try to open the file in read/write mode and if it fails assume I can't...but for this particular instance, that's not going to work nicely.
 

10 More Discussions You Might Find Interesting

1. Programming

to find current running process

Hi All, The scenario is like this: There is a process say "A" which create a child process say "B" if some condition is true and process "A" terminates. "B" invokes some C program say "C" using 'execl' function. The job of program "C" is to keep polling the server until the server will be up.... (2 Replies)
Discussion started by: ranjkuma692
2 Replies

2. Shell Programming and Scripting

current running process in shell

hi what is the shell programming code to know the number of processes currently running on the machine & information about those processes. Another one is the configuration and usage of the UNIX file system? requesting all for help. thanks (1 Reply)
Discussion started by: moco
1 Replies

3. Shell Programming and Scripting

Displaying current user process

When I typed in ps -a I get this: PID TTY TIME CMD 31799 pts/3 00:00:00 vim 31866 pts/3 00:00:00 vim And to check who is currently logged in, I type who Felix Whoals Tada Whoals Lala Whoals How can I get the user process for all current users who logged in?? I think I need to combine... (14 Replies)
Discussion started by: felixwhoals
14 Replies

4. UNIX for Dummies Questions & Answers

Current Process Running.

Hi all, When I issued command ps -ef|grep Vinay in a UNIX machine, I got the following Vinay 22491 1 255 Jun 18 ? 294248:53 -sh Vinay 26628 1 255 Jun 18 ? 294237:33 -sh Could you tell me what all process is running ? Please explain each of the fields. Thanks... (4 Replies)
Discussion started by: coolbhai
4 Replies

5. Solaris

shell-init: could not get current directory: getcwd: cannot access parent directories

Hello root@ne-ocadev-1:/root/scripts>su espos -c find /a35vol100/ESPOS/oracle/db/9.2.0/oradata/ESPOS/archive -type f -atime +10 -exec ls {} shell-init: could not get current directory: getcwd: cannot access parent directories: Permission denied find: insufficient number of... (6 Replies)
Discussion started by: babu.knb
6 Replies

6. Solaris

file open/read/write/close/access by process

Hi want to know what file (descriptor+filename+socket) is being accessed by particular process on solaris. Purpose : while running perf. test, needs to find where is the bottleneck. We are providing concurrnet load for around 1 hr and needs to capture data related to file usage pattern... (1 Reply)
Discussion started by: raxitsheth
1 Replies

7. UNIX for Advanced & Expert Users

Determining interface to access IP

Hello I've got a server with multiple NICS. In a script I want to log the outbound interface. Is there an easy way I can do this so that the output looks something like this: host(xxx.xxx.xxx.xxx): Opening connection to ... Obviously, getting the host is simple with hostname. But how... (4 Replies)
Discussion started by: brsett
4 Replies

8. UNIX for Dummies Questions & Answers

Running different process from current process?

I have been having some trouble trying to get some code working, so I was wondering...what system calls are required to execute a different program from an already running process? (1 Reply)
Discussion started by: Midwest Product
1 Replies

9. UNIX for Dummies Questions & Answers

Determining if a process is active in UNIX

We have written a bare bones scheduling app using bash scripts. The input to the scheduler is from a mainframe scheduling tool, and the scripts exit code is returned to the MF. The problem is that every now and again I have a script that does not complete and this is left in my Q. I am in the... (1 Reply)
Discussion started by: Charles Swart
1 Replies

10. UNIX for Dummies Questions & Answers

Unable to access current user's mailbox.

In any non-root account, whenever I enter mail, it gives me: /var/spool/mail/root: Permission deniedI am not logged in as root, why is mail accessing root's mailbox ? I am unable to enter the currently logged in user's mailbox. Any help is appreciated :) (2 Replies)
Discussion started by: Hijanoqu
2 Replies
chmod(2)							System Calls Manual							  chmod(2)

NAME
chmod, fchmod - Changes file access permissions SYNOPSIS
#include <sys/mode.h> #include <sys/types.h> #include <sys/stat.h> int chmod ( const char *path, mode_t mode ); int fchmod ( int filedes, mode_t mode ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: chmod(), fchmod(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the full pathname of the file. If the path parameter refers to a symbolic link, the chmod() function changes access permissions on the file specified by the symbolic link. Specifies the file descriptor of an open file. Specifies the bit pattern that determines the access permissions. DESCRIPTION
The chmod() function sets the access permissions of the file specified by the path parameter according to the bit pattern specified by the mode parameter. The fchmod() function sets the access permissions of an open file pointed to by the filedes parameter according to the bit pattern speci- fied by the mode parameter. To change file access permissions, the process must have the same effective user ID as the owner of the file or the process must have supe- ruser privilege. Upon successful completion, the chmod() and fchmod() functions mark the st_ctime field of the file for update. The mode parameter is constructed by logically ORing one or more of the following values, which are defined in the sys/mode.h header file: Sets the process' effective user ID to the file's owner on execution. Sets the process' effective group ID to the file's group on execu- tion. Saves text image after execution. Permits the file's owner to read, write, and execute it (or to search the directory). Permits the file's owner to read it. Permits the file's owner to write to it. Permits the file's owner to execute it (or to search the direc- tory). Permits the file's group to read, write, and execute it (or to search the directory). Permits the file's group to read it. Per- mits the file's group to write to it. Permits the file's group to execute it (or to search the directory). Permits others to read, write, and execute it (or to search the directory). Permits others to read the file. Permits others to write to the file. Permits others to execute the file (or to search the directory). Other mode values exist that can be set with the mknod() function, but not with the chmod() function. If the mode bit S_ISGID is set and the mode bit S_IXGRP is not set, mandatory file record locking will exist on a regular file. This may affect subsequent calls to other calls on the file, including open(), creat(), read(), write(), and truncate(). The S_ISGID bit of the file is cleared if: The file is a regular file. The effective user ID of the process does not have appropriate sys- tem privilege. The effective group ID or one of the IDs in the group access list of the process does not match the file's existing group ID. RETURN VALUES
Upon successful completion, the chmod() and fchmod() functions return a value of 0 (zero). If the chmod() or fchmod() function fails, a value of -1 is returned, and errno is set to indicate the error. ERRORS
If the chmod() function fails, the file permissions remain unchanged and errno may be set to one of the following values: A component of the path parameter has search permission denied. The path parameter points to a location outside of the allocated address space of the process. A signal was caught during execution of the system call. The file is not a regular file. Too many symbolic links were encoun- tered in translating the path parameter. The length of the path argument exceeds PATH_MAX or a pathname component is longer than NAME_MAX. The named file does not exist or is an empty string. A symbolic link was named, but the file to which it refers does not exist. A component of the path parameter is not a directory. The effective user ID does not match the ID of the owner of the file or the owner does not have appropriate system privilege. The named file resides on a read-only file system [Tru64 UNIX] The process' root or current directory is located in a virtual file sys- tem that has been unmounted. If the fchmod() function fails, the file permissions remain unchanged and errno may be set to one of the following values: The file descriptor filedes is not valid. A signal was caught during execution of the system call. The effective user ID does not match the ID of the owner of the file, and the calling process does not have superuser privilege. The file referred to by filedes resides on a read-only file system. [Tru64 UNIX] The process' root or current directory is located in a virtual file system that has been unmounted. RELATED INFORMATION
Functions: chown(2), fcntl(2), getgroups(2), mknod(2), open(2), read(2) setgroups(2) truncate(2) write(2) Commands: chgrp(1), chmod(1) Standards: standards(5) delim off chmod(2)
All times are GMT -4. The time now is 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy