• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

allow only owner access to a file

Hi all,

I'm writing a C program that needs to be portable to different platforms (runnable in any ANSI C enviornment). I need to create a file and set the permission to only allow owner access. I don't know what functions I can use from the c runtime library to do that. And I don't know if I can use any other type of libraries. Could someone give me some suggestions?

Thanks a lot!
Michelle
0
emshelly
Asked:
emshelly
2 Solutions
 
gj62Commented:
The C-runtime library does not have any functions that will do this for you - they are OS specific, if they exist at all on the platform.

Do you have specific platforms you are targeting?
0
 
jkrCommented:
If you are using UN*X, use 'chmod()' like

#include <sys/types.h>
#include <sys/stat.h>

chmod ( "/home/me/myfile.txt", S_IRUSR | S_IWUSR);
0
 
grg99Commented:
Many operating systems don't have even the concept of "owner"-- like PCDOS, Win95/98/Me.

If your program has to run on these systems, you're going to have to make your own user-level security.

This means you'll have to set up your own username/password file and have your program look up users before granting access to the file.

*Or* you could encrypt the file with a key of the user's choosing, which has its own advantages and disadvantages.

It's not a trivial thing, but not too hard to do.  I guess too it depends on exactly how secure these files have to be.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emshellyAuthor Commented:
Currently the application is for Linux and Solaris. Later it will need to also support Windows. Thanks for all your help! They are all helpful. Is it possible to award points to more than one person?

=)
0
 
emshellyAuthor Commented:
By the way, do you guys know how to make the file invisible?

Thanks again!
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between gj62 and jkr.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now