|
"Gordon R. Robinson IV" <GRobinson@ruger.com> wrote: > > Does anyone know a way, particularly an API, to check if a user has > authority to a file? I found an API to check the user's authority to an > object in the QSYS.LIB file system, but I need to be able to check the > user's authority to a file in the Root file system. I'm writing a program > that will only show certain options if the users has access the authority to > use those files. > Sure. Use the access() API... Here's an example: D********************************************************************** D* Access mode flags for access() D* D* F_OK = File Exists D* R_OK = Read Access D* W_OK = Write Access D* X_OK = Execute or Search D********************************************************************** D F_OK C 0 D R_OK C 4 D W_OK C 2 D X_OK C 1 D*-------------------------------------------------------------------- D* Determine file accessibility D* D* int access(const char *path, int amode) D* D*-------------------------------------------------------------------- D access PR 10I 0 ExtProc('access') D Path * Value options(*string) D amode 10I 0 Value D FileFound S 1N Inz(*OFF) D ReadOk S 1N Inz(*OFF) D WriteOk S 1N Inz(*OFF) D SearchOk S 1N Inz(*OFF) D Msg S 52A C* Check if file found: c if access('/test/foo.bar': F_OK) = 0 c eval FileFound = *On c endif C* Check if user has read access: c if FileFound and c access('/test/foo.bar': R_OK) = 0 c eval ReadOk = *On c endif C* Check if user has write access: c if FileFound and c access('/test/foo.bar': W_OK) = 0 c eval WriteOk = *On c endif C* Check if user has execute/search access: c if FileFound and c access('/test/foo.bar': X_OK) = 0 c eval SearchOk = *On c endif C* Show results: c if FileFound c eval Msg = 'Read Access: ' + ReadOk c Msg dsply c eval Msg = 'Write Access: ' + WriteOk c Msg dsply c eval Msg = 'Search Access: ' + SearchOk c dsply Msg c else c eval Msg = 'File Not Found!' c dsply Msg c endif c eval *inlr = *on +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.