When is umask() useful?

后端 未结 4 1632
星月不相逢
星月不相逢 2021-01-04 21:57
umask(0);

fd = open(\"/dev/null\", O_RDWR);

Here\'s man 2 umask:

umask() sets the calling process’s file mode creatio         


        
4条回答
  •  囚心锁ツ
    2021-01-04 22:55

    Most Mac developers (and by extension most software testers), from the time they were babies, put this in their .cshrc

    umask 002
    

    However, most end users don't know about umask, so if they create a new user on the machine, and run your app, you are likely to create a bunch of log files and whatnot without group read/write permissions. Then they switch users again and suddenly your app doesn't work. For this reason, we're adding this to all our apps. Our rule-of-thumb when it comes to security is that "we want users to be able to use our software".

    #import 
    #import 
    int main(int argc, char *argv[])
    {
        // set permissions for newly created files to ug+rwX,o+rX
        umask(0002); 
    

提交回复
热议问题