简体   繁体   中英

Execute /bin/login from QProcess

I'm working on embedded system running linux (without X11 server). I want my Qt application to be started with root privileges then from within spawn new QProcess which should be "/bin/login user_name" then provide password. The problem is the "Password:" that usually prints on console (I assume it's stdout) doesn't show up, and QProcess.write() doesn't seem to work at all. If I run this QProcess as normal user I get an error message at redirected stderr (via setStandardErrorFile). I think I have general problem with understanding /bin/login.

I tried to

echo "userPassword" > /proc/LOGIN_PID/fd/0 

from different console, but it also doesn't work.

The function I wrote in c++ goes like this:

void BashWrapper::bashEcho(QStringList t_echo){
    QString bash = "/bin/login";

    QStringList args(t_echo[0]);

    static QProcess *newProc = new QProcess();

    newProc->setStandardOutputFile("/dev/pts/2");
    newProc->setStandardErrorFile("/dev/pts/2");

    newProc->start(bash,args);

    if(newProc->waitForStarted()){
        qDebug() << newProc->state();
    }
    newProc->write(t_echo[1].toUtf8());

    if(!newProc->waitForFinished(10000)){
        qDebug() << "timeout";
    }
    else{
        qDebug() << "finished";
    }
}

t_echo contains ("user_name", "userPassword")

What I want to do is spawn new program (let's say /bin/myApp) as user_name. I thought that login as that user and setting .bash_profile to run /bin/myApp would be easy, painless and... secure? If using /bin/login from application is impossible is there any simple way to this? Best Regards, Michał

好的,我在这里找到了答案: https : //www.thegeekstuff.com/2010/10/expect-examples/有一个执行su命令的示例脚本,只需将其更改为/ bin / login即可让我通过密码通过一些其他脚本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM