Пример #1
0
static void ExecAsRootMac(const QString & cmd, char * const * argv)
{
    //execute
#ifdef Q_OS_MAC
    AuthorizationRef & ra = GetAuth();
    OSStatus res = AuthorizationExecuteWithPrivileges(ra,
         cmd.toStdString().c_str()	//myToolPath
         , kAuthorizationFlagDefaults,
         argv									//myArguments
         , NULL);							// pipes

    // handle misterious errors with auth service
    for (int k = 1; k < 6 && errAuthorizationToolEnvironmentError == res; ++k)		// 1500ms  total
    {
        int ms = k * 100;
        log::logt("Auth - got errAuthorizationToolEnvironmentError, sleep " + QString::number(ms) + "ms");
        QThread::msleep(ms);
        res = AuthorizationExecuteWithPrivileges(ra,
                 cmd.toStdString().c_str()	//myToolPath
                 , kAuthorizationFlagDefaults,
                 argv									//myArguments
                 , NULL);							// pipes
    }

    if (res != errAuthorizationSuccess)
        throw std::runtime_error(("AuthorizationExecuteWithPrivileges() fails with result: "
            + QString::number(res) + " cmd = " + cmd).toStdString());
#endif	// Q_OS_MAC
}
Пример #2
0
void OsSpecific::SetOwnerRoot(const QString & pfn)
{
    // check if bit set already
    if (!IsOwnerRoot(pfn))
    {
#ifdef Q_OS_WIN
#error SetOwnerRoot() Not implemented
        throw std::runtime_error("SetOwnerRoot() Not implemented");
#endif
        AuthorizationRef & ra = GetAuth();
//		QStringList args;
//		args << "u+s" << pfn;
//		ExecAsRoot("chmod", args);

        //int	chmod(const char *, mode_t) __DARWIN_ALIAS(chmod);
        int r1 = chmod(pfn.toLatin1(), 04555);
        if (r1 != 0)
        {
            QString s("cannot set 04555! err code = ");
            s += QString::number(errno);
            log::logt(s);	//throw std::runtime_error("cannot set 04555!");
        }
/*
        int r2 = chown(pfn.toLatin1(), 0, 500);
        if (r2 != 0)
        {
            QString s("cannot ch own 0 0! err code = ");
            s += QString::number(errno);
            log::logt(s);	//throw std::runtime_error("cannot ch own 0 0!");
        }
*/
/*	{
            log::logt(pfn);

        QStringList args2;
        args2
                //<< "ls"
              << "-l" << "/tmp";
        ExecAsRoot("ls", args2);
    }
*/
        try
        {
            QStringList args;
            args << "root" << pfn;
            ExecAsRoot("/usr/sbin/chown", args);


            // additional files
        }
        catch(std::exception & ex)
        {
            // do not propagate - allow different method of OpenVPN execution regardless this property change
            log::logt(QString("Cannot set owner of ") + pfn + "err = " + ex.what());
        }
    }
}
Пример #3
0
void wxGISNetworkService::PutInMessage(WXGISMSG msg)
{
	//check permissions
    if(msg.pMsg->GetState() == enumGISMsgStCmd)
    {
	    AUTHRESPOND respond = GetAuth(msg.nUserID);
	    if(!respond.bIsValid)
        {
            return;
        }
    }
	m_pApp->PutInMessage(msg);
}