Solved

Checking directory permissions from within C++

Posted on 1998-01-07
5
954 Views
Last Modified: 2011-09-20
My program saves files to a directory selected by the user.  Since the user could be an administrator with full read/write permissions, or a guest with limited access to only a few directories, how can I have the program check for write access on a specific directory without actually creating a "test" file in that directory?
0
Comment
Question by:DenMan
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1177728
This is an OS dependent problem.  Normally you just try the operation and if it fails, the error code will tell you that you didn't have permission to write the data.
0
 

Author Comment

by:DenMan
ID: 1177729
The particular case I have in mind is saving files to a directory with Add+Read permissions.  A file can be created, but not removed.  How can I verify that this directory can be written to without creating an unremovable temp file?
0
 
LVL 32

Expert Comment

by:jhance
ID: 1177730
Like I said, it's OS dependent (i.e. it's not a part of the C/C++ standard libraries).  If you could provide some information about your run-time environment, I might be able to help.
0
 

Author Comment

by:DenMan
ID: 1177731
Sure...I'm running NT 4.0, with it's security features (read, add, change) in use on certain directories.  In this particular case, I have a directory that is Read+Add (i.e. no changing or deleting), so if I create a test file to check for write-access, I can't delete it after it's created.

Does that help?
0
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 1177732
Yes, that does help.  Under Windows NT you can use the Win32 API GetFileSecurity() call to get the permissions associated with any file system object.  Of course, this ONLY applies to NTFS volumes as FAT volumes have no security.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question