Thread: set root through program

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    24

    set root through program

    I'm writing a program and I need it to goto root. The user knows the password but I'm using QT and do not know how-to get the password to su.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    I doubt you could use setuid(RootID) unless you ran the program as root, in which case, it could do what you wanted anyway. You can get it from man getpwnam
    One thing though, which I prefer the manual pages on FreeBSD, it uses the library -lc (which isn't mentioned here), but I don't think you need to use it, bceause it's just the standard C library

    Hope this helps
    - Daniel Wallace

  3. #3
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Question Even I wanted an answer to a similar question

    Hi,
    even I wanted an answer to a similar question, How do I trap the return value (well, not exactly value as I can use exec to do that).

    Suppose i write..
    Code:
    system("su");
    then how can I collect the return string "Password: " and then pass the value (password) to that program(command) again?


    Also, another question I wanted an answer to is the #defines' in the header files. What is the significance of two underscores before the word.
    Eg: __NULL__ etc. which is most commonly seen in standard headerfiles like stdio etc. Why cannot they simply use
    Code:
    #define NULL 0
    Also, if such a statement is not defined, how does the compiler know when we use...
    Code:
    if(xxx == NULL)
    ...
    ...
    Regards,
    Harsha.
    Help everyone you can

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    But "su" isn't going to help you, no matter how you roll it. It will always be a child process of your program, so only the child process (that's su) will have root access. Your program will remain with the access which it started with.

    See the manual page for setuid(). There are all sorts of side issues regarding security etc. Be sure about why you want to goto root in the first place, and be specific about what you want to achieve when you get there. If you fudge the issue, your program will be insecure.

    > What is the significance of two underscores before the word.
    It means you shouldn't be using them.
    Anything beginning with an underscore is reserved for use by the system. It may appear / disappear / change meaning at any time.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Lightbulb Further Explanation??

    Hi Salem,
    Thanks for the "its-not-your-business" answer. But I was wondering if I can have some more details about it? Those answers ("Its reserver for use by system" etc etc)... keep my brain racked until I find more. I need answers in detail (Or even a LINK to anyplace that explains them in detail). I couldnt find them in the Tutorials or Advanced Tutorials and have never come across them in the standard C Books.

    1. Can only the compiler designers use them in their standard libraries (which they ship along with their packages). If so, how do they use them and for what purposes?

    2. Can I not use those variables for any benificial purposes in my header files?

    Please give me a link to an appropriate explanation.

    Thank you and
    Kind Regards,
    Harsha.
    Help everyone you can

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    If they have an underscore, the compiler will use them. The compiler could use them for any purpose, to see what chip you are using to if you have a local APIC or not, etc., stuff we usually don't have to deal with unless we are writing compilers or kernels.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > But I was wondering if I can have some more details about it?
    Read the standard then.
    This is the last draft of C99, which is available for free. Proper copies cost money
    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

    Then pay attention to
    7.1.3 Reserved identifiers

    > 2. Can I not use those variables for any benificial purposes in my header files?
    Sure you can - but the risk is enormous in doing so.
    You risk having to change your code every time you upgrade your compiler (in any way), or change to a new compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. optimising program
    By SONU in forum C Programming
    Replies: 1
    Last Post: 05-18-2008, 10:28 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. Replies: 5
    Last Post: 09-03-2001, 09:45 PM