Note that your specification explicitly talks about newly created files. You couldn't even use
chmod to change that, since a new file would have some set of permissions when created, before you could use
chmod on them.
Also, while that Ruby script doesn't run the
chmod command/utility, it does use the same underlying system call, so it's practically the same thing. If it were me, I wouldn't allow that.
Without giving out the full answer, I'd suggest looking at what the man page for
open() says about the permissions of the created file:
The mode argument specifies the file mode bits be applied when
a new file is created. This argument must be supplied when
O_TMPFILE is specified in flags; if neither
O_TMPFILE is specified, then mode is ignored. The
effective mode is modified by the process's umask in the usual
way: in the absence of a default ACL, the mode of the created
(mode & ~umask). Note that this mode applies only to
future accesses of the newly created file; the
that creates a read-only file may well return a read/write
The following symbolic constants are provided for mode:
00700 user (file owner) has read, write, and execute
Also note that the part you quoted said to "decrease the permissions by 222", not to 222. That's also important regarding the function I'm thinking of.
Since it was already mentioned in the comments
I'm thinking of
umask, which limits the permissions of newly-created files. It should be a standard feature, and should work the same in Linux and in DragonFly.
Of course, all of this is just my interpretation of that assignment. There's no way for any of us here to know for sure what the correct answer is in the opinion of your teacher/professor, especially since sometimes the answers given by professors are not even the correct ones.