gtkmm example using zvtterm?



This may be slightly more focused toward zvtterm use but I'm trying to
write a gtkmm app that uses zvtterm and am having some difficulty.

I'm trying to develop a simple first application to issue a command that
needs root access so I'm trying to use zvtterm similarily to gnomesu to
create a zvtterm and issue the command on a su -c command via execl.

I've been using gnomesu as a guide but still cannot get the end result
I'm looking for (which is basically su'ing via entering ID/PWD via a
dialog and passing this on). I always get prompted for the Password on
the CLI.

I'm basically doing the following:

    GtkWidget* term;
    int i;
    char command[50];
   
    term = zvt_term_new ();
   
    if (term!=NULL)
    {
        std::cout << "Created zvt terminal." << std::endl;
        i = zvt_term_forkpty (ZVT_TERM (term), ZVT_TERM_DO_UTMP_LOG |
ZVT_TERM_DO_WTMP_LOG);
        std::cout << "i=" << i << std::endl;
        //At this point I thought i should be either -1 for error or 0
for success but I keep getting a large ntmber 19000+
    }
    else
    {
        std::cout << "Error creating zvt terminal." << std::endl;
    }
   
    if (i==-1)
    {
        std::cout << "Error executing zvt_term_forkpty()." << std::endl;
    }
   
    if (i>0) //I think this should be i==0
    {
       
        std::cout << "zvt_term_forkpty successful. i= "<< i << std::endl;
       
        std::cout << "Executing su -c tc command..." << std::endl;
       
        sprintf(command, "tc qdisc add dev eth0 root netem delay 10ms\n");
        execl("/bin/su", "-", m_sUserID.c_str(), "-c", command, NULL);
       
        std::cout << "Parent executing entering password to su..." <<
std::endl;
        usleep(200);
        gchar* password_return;
        password_return = g_strdup_printf ("%s\n", m_sPassword.c_str());
        zvt_term_writechild (ZVT_TERM (term), password_return, strlen
(password_return));
            
    }

When executed from a terminal, su is executed, I then get the Password:
prompt, and the results are displayed after I manually enter the root
passwrd. So basically, sending the password isn't working.

All that being said, does anyone have a simple example in gtkmm that
implements this functionality (or ia it obvious what I'm doing wrong
here)? I'm also interested in capturing the output from the zvtterm to
display the results in a message box but haven't got past this point yet.

Thanks,
_________________
-
Don



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]