I’ve been trying to figure out how to do a read only resource manager. My best guess is in the mode_t section of the iofunc_attr_init.
Normally the parameters for this is: S_IFNAM | 0666
What does the 0666 mean?
I tried changing this to: S_IRUSR | S_IRGRP | S_IROTH
running echo 50 > resmgr results in:
cannot create resmgr: permission denied
however if I change to root, I can write to the resmgr (it runs the io_write function). Which seems odd because the permissions for the file are: -r–r–r–
How do I fix this to disable root’s write permissions??
Just a guess but it’s prolly up to you to respond with the appropriate write access error from the io_write function. The “permission denied” error you got may have been for another reason independant of write access.
I’m surprised this requirement has never come up before. I am writing a resmgr that maps an input-only port, there’s no hardware to write out, so if the system can write a value to the resource manager, it doesn’t really make sense. How is this typically handelled - with write error messages like evanh said above??
I think I’ve figured out how to do this the most elegant way (that I can think of at least) - don’t allow the file to be opened. Here’s how you get conditions (and some of it isn’t really straignforward):
This is your open function:
int io_open (resmgr_context_t *ctp, io_open_t *msg, RESMGR_HANDLE_T *handle, void *extra)
The following statement
(int) (msg->connect.ioflag & O_ACCMODE)
will have a value of:
1 for read only i.e. fopen(“file”, “r”)
2 for write only i.e. fopen(“file”, “w”), fopen(“file”, “a”),
3 for read/write i.e. fopen(“file”, “r+”), fopen(“file”, “w+”) etc…
0 when you use more utility - don’t know why
Note the fcntl.h flags such as O_RDONLY, O_RDWR, O_WRONLY do NOT match up to these values (I learned this the hard way).
I used this to block my iofunc_open_default for certain cases and returned EACCES in those situations