Ubuntu/C++ : Make directory in /usr/local/bin/

5,693

Why not make the program have suid permission? But quite frankly, directories outside of /home should not be touched. However, if you insist on doing this, just make 100% sure that memory checks are rigorous and that there is zero vulnerabilities, then using suid permission will solve it.

Another way, make that program a member of root group.

All in all, this is an odd requirement to touch directories that is against FHS.

Share:
5,693

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I usually use mkdir function to make directory (e.g mkdir("/home/dhw/test", S_IREAD|S_IWRITE) )

    But I can't make directory in /usr/local/bin.

    I guess it is problem with authority.

    I already know I can do this work with

    system("sudo mkdir /usr/local/bin/test/");
    

    and input root password. But I don't want to make user to get root permission manually.

    What should I do?

    • Admin
      Admin over 12 years
      You have to get root permission because it is an action only root should be able to do. No way around. And there should be none.
    • Delan Azabani
      Delan Azabani over 12 years
      Your example is somewhat dodgy; why would you want to create a directory under /usr/local/bin? That completely goes against the FHS. Supporting files for a program go in /usr/local/lib and /usr/local/share.
    • Admin
      Admin over 12 years
      @Delan What You said is I should not create directory under /usr/local/bin, /usr/local/share and I should move my program in those directory?
    • Admin
      Admin over 12 years
      You should to be able to use the mkdir function to do this so long as you require the user to run your program as root (sudo ./myProgram), and just display a nice error message if your program is not root. If you're going about this, then you ought to need root access.
    • Delan Azabani
      Delan Azabani over 12 years
      Not quite. The contents of bin should not include directories, but only directly executable files. If you have multiple final executables for your program, you may want to hyphenate the name, as in myapp-program1, myapp-program2, etc. Any supporting files should go into share if they're not architecture-dependent, and lib if they are.
    • Admin
      Admin over 12 years
      @pmr I guess it so. But I want to know it exactly. Thank you.
    • Admin
      Admin over 12 years
      @Delan I am beginner in Linux. So I don't know well what I should and shouldn't do. Now I understand what you said. Thank you.
    • Admin
      Admin over 12 years
      You should just create the files in the home directory