Thread: su-command from c++ with popen gives "standard in must be a tty"

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    23

    su-command from c++ with popen gives "standard in must be a tty"

    hi,

    i'm trying to execute some programs from within a c++-program, where i
    ask the user to specify the root password and would like to execute the
    command then with "su -c "the-command", via popen.
    but i always get back the error "standard in must be a tty" from su.
    i know what the error means, but is there a possibility by maybe pretending
    the c++-program to be a tty? any ideas?

    thanks,

    toby

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is it possible to run the same command using 'expect' ?

    expect is a scripting tool which interacts with command line programs. If that manages to do it, then perhaps a look through the expect source code to find out how it does it would prove useful.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    23
    yes it does, so i'll have a look at the expect source-code...
    it's c though, and im not very good at thinking in pure c-code,
    but c++-code...
    thanks anyway!

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by t0bias View Post
    i know what the error means, but is there a possibility by maybe pretending
    the c++-program to be a tty? any ideas?
    This is exactly what pseudo-terminals are for.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    23
    but sending the password to /dev/pts/1 prints it but does not
    make su accepting it..?
    maybe i am doint something wrong?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have you ever thought that perhaps forbidding su to use anything but the console for input is there on purpose? Like to prevent someone writing a program that attempts to crack the password for su?

    If the user knows the root password, then why not run YOUR application under su? Or, even, set the "setuid" bit for the app, so that it can run as root in the first place?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User t3chn0n3rd's Avatar
    Join Date
    Dec 2007
    Location
    kansas city
    Posts
    25

    source code

    That is an interesting problem, I havent tried it before. But it will be an interesting problem to work on

Popular pages Recent additions subscribe to a feed