0

I have implemented a TFTP on top of UDP in C, and I am trying to figure out how to check the read/write permission on the directory that transfer is going to take place. For the existence of the file and the case that file doesn't exist I have used access() with F_OK, but W_OK and R_OK seem to be troublesome when trying to check the permission on the directory, I have looked at stat(), but failed to implement it correctly. Any ideas on alternatives or correct implementation of the stat() or access() for the directory not the file.

EasyQuestions
  • 327
  • 1
  • 10
  • 23
  • did you try opendir(). But i guess it works for local machine where TFTP is running – Denny Mathew May 28 '13 at 08:41
  • No I haven't, because I don't need to open a directory; the server and client are running in their respective local directories, and for now I just want to check the read and write permission on that same local directory (because my tftp only supports that for now). So If the operation is not allowed (the permission is not set), an error packet will be sent to the peer (server or client) – EasyQuestions May 28 '13 at 08:46
  • Maybe you can post or link to the stat() and access() code you have so far. – thuovila May 28 '13 at 10:42

1 Answers1

1

Idea of an alternative: You don't need to check the permission for the directory; just try to open the file, and send the resulting error code.

Armali
  • 18,255
  • 14
  • 57
  • 171
  • Failure to open a file (getting a null for the FILE pointer) can be the result of many reasons, for write permission denied does it set a special error flag? – EasyQuestions May 28 '13 at 14:46