Exemplo n.º 1
0
unsigned int CFunctionParser::ParseSaveToFile(CScriptVariable*& retVar, int& index)
{
    index++;
    bool b = false;
    if(m_pToken[index].GetTokenString()[0] != '(')
        return ERROR_EXPECTED_SYMBOL;

    ScriptStep step;

    char* varName[3] = {0};
    CParser::VariableInfo* varInfo = 0;
    int i_marker = index + 1;

    step.funcData = new CScriptVariable*[3];
    step.funcData[0] = m_parser.GetStatementVar(index,true);
    if(!step.funcData[0])
    {
		varInfo = m_parser.GetInitVar(m_pToken[i_marker].GetTokenString());
		if (!varInfo && !strcmp(m_pToken[i_marker].GetType(), S_IDENTIFIER))
        {
            OutputErrorMsg(ERROR_UNDEFINED_VARIABLE, m_pToken[i_marker]);
            return ERROR_UNDEFINED_VARIABLE;
        }
        varName[0] = varInfo->m_name;

    }

    i_marker = index + 1;
    step.funcData[1] = m_parser.GetStatementVar(index,true);
    if(!step.funcData[0])
    {
        varInfo = m_parser.GetInitVar(m_pToken[i_marker].GetTokenString());
        if(!varInfo && !strcmp(m_pToken[i_marker].GetType(),S_IDENTIFIER))
        {
            OutputErrorMsg(ERROR_UNDEFINED_VARIABLE, m_pToken[i_marker]);
            return ERROR_UNDEFINED_VARIABLE;
        }
        varName[0] = varInfo->m_name;

    }

    step.funcData[2] = new CScriptVariable(BOOL, &b, -1, "RETURN_VAR");
    step.nVars = 3;
    step.func = &S_FUNC::ENGINE::SAVETOFILE;
    step.scope = m_parser.m_currentScope;
    step.SetVarNames(varName);

    m_pScript->m_funcTree.AddScriptStep(step);
    return NO_ERROR;
}
Exemplo n.º 2
0
unsigned int CFunctionParser::ParseOutput(CScriptVariable*& retVar, int& index)
{
    bool b = false;
    retVar = new CScriptVariable(BOOL, &b, -1, "RETURN_VAR");
    index++;
    if(m_pToken[index].GetTokenString()[0] != '(')
    {
        OutputErrorMsg(ERROR_UNEXPECTED_TOKEN, m_pToken[index]);
        return ERROR_UNEXPECTED_TOKEN;
    }
    ScriptStep step;
    step.func = S_FUNC::OUTPUT;
    step.nVars = 2;
    step.funcData = new CScriptVariable*[1];
    step.funcData[0] = m_parser.GetStatementVar(index, true);
    step.funcData[1] = retVar;
    step.scope = m_parser.m_currentScope;

    m_pScript->m_funcTree.AddScriptStep(step);


    if(!step.funcData[0])
        return ERROR_UNDEFINED_ERROR;

    return NO_ERROR;
}
Exemplo n.º 3
0
    bool WindowsUser::createProcess(
        LPCTSTR lpApplicationName,
        LPTSTR lpCommandLine,
        LPSECURITY_ATTRIBUTES lpProcessAttributes,
        LPSECURITY_ATTRIBUTES lpThreadAttributes,
        BOOL bInheritHandles,
        DWORD dwCreationFlags,
        LPVOID lpEnvironment,
        LPCTSTR lpCurrentDirectory,
        LPSTARTUPINFO lpStartupInfo,
        LPPROCESS_INFORMATION lpProcessInformation)
    {
        if (!CreateProcessAsUser(tokenHandle_,
            lpApplicationName,
            lpCommandLine,
            lpProcessAttributes,
            lpThreadAttributes,
            bInheritHandles,
            dwCreationFlags,
            lpEnvironment,
            lpCurrentDirectory,
            lpStartupInfo,
            lpProcessInformation))
        {
            OutputErrorMsg(OJStr("CreateProcessAsUser faild"));
            return false;
        }

        return true;
    }
Exemplo n.º 4
0
    bool WindowsUser::setPrivilege(
        LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
        BOOL bEnablePrivilege   // to enable or disable privilege
        ) 
    {
        TOKEN_PRIVILEGES tp;
        LUID luid;

        if ( !LookupPrivilegeValue( 
            NULL,            // lookup privilege on local system
            lpszPrivilege,   // privilege to lookup 
            &luid ) )        // receives LUID of privilege
        {
            OutputErrorMsg(OJStr("LookupPrivilegeValue error ")); 
            return false; 
        }

        tp.PrivilegeCount = 1;
        tp.Privileges[0].Luid = luid;
        if (bEnablePrivilege)
            tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        else
            tp.Privileges[0].Attributes = 0;

        // Enable the privilege or disable all privileges.

        if ( !AdjustTokenPrivileges(
            tokenHandle_, 
            FALSE, 
            &tp, 
            sizeof(TOKEN_PRIVILEGES), 
            (PTOKEN_PRIVILEGES) NULL, 
            (PDWORD) NULL) )
        { 
            OutputErrorMsg(OJStr("AdjustTokenPrivileges failded")); 
            return false; 
        } 

        if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
        {
            OutputErrorMsg(OJStr("The token does not have the specified privilege. "));
            return false;
        } 

        return true;
    }
Exemplo n.º 5
0
unsigned int CFunctionParser::ParseOutput(CScriptVariable*& retVar, int& index)
{
    char* varName[2] = {0};
    CParser::VariableInfo* varInfo = 0;
    int i_marker;

    bool b = false;
    retVar = new CScriptVariable(BOOL, &b, -1, "RETURN_VAR");
    index++;
    if(m_pToken[index].GetTokenString()[0] != '(')
    {
        OutputErrorMsg(ERROR_UNEXPECTED_TOKEN, m_pToken[index]);
        return ERROR_UNEXPECTED_TOKEN;
    }
    ScriptStep step;
    step.func = S_FUNC::OUTPUT;
    step.nVars = 2;
    step.funcData = new CScriptVariable*[2];
    i_marker = index + 1;
    step.funcData[0] = m_parser.GetStatementVar(index, true);

    if(!step.funcData[0])
    {
        varInfo = m_parser.GetInitVar(m_pToken[i_marker].GetTokenString());
        if(!varInfo)
        {
            OutputErrorMsg(ERROR_UNDEFINED_VARIABLE, m_pToken[i_marker]);
            return ERROR_UNDEFINED_VARIABLE;
        }
        varName[0] = varInfo->m_name;
    }
    step.funcData[1] = retVar;
    step.scope = m_parser.m_currentScope;
    step.SetVarNames(varName);
    m_pScript->m_funcTree.AddScriptStep(step);

    return NO_ERROR;
}
Exemplo n.º 6
0
    bool WindowsUser::login(const OJString & userName, const OJString & domain, const OJString & password)
    {
        assert(tokenHandle_==NULL && "wrong call!");

        // Log the client on to the local computer.

        if (!LogonUser(
            userName.c_str(),
            domain.c_str(),
            password.c_str(),
            LOGON32_LOGON_INTERACTIVE,
            LOGON32_PROVIDER_DEFAULT,
            &tokenHandle_) ) 
        {
            tokenHandle_ = NULL;
            OutputErrorMsg(OJStr("LogonUser failed "));
            return false;
        }

        // Save a handle to the caller's current window station.


        HWINSTA hwinstaSave = GetProcessWindowStation();
        if (hwinstaSave == NULL)
        {
            OutputErrorMsg(OJStr("GetProcessWindowStation failed "));
            return false;
        }

        // Get a handle to the interactive window station.

        winstaHandle_ = OpenWindowStation(
            OJStr("winsta0"),               // the interactive window station 
            FALSE,                       // handle is not inheritable
            READ_CONTROL | WRITE_DAC);   // rights to read/write the DACL

        if (winstaHandle_ == NULL) 
        {
            OutputErrorMsg(OJStr("OpenWindowStation failed!"));
            return false;
        }

        // To get the correct default desktop, set the caller's 
        // window station to the interactive window station.

        if (!SetProcessWindowStation(winstaHandle_))
        {
            OutputErrorMsg(OJStr("SetProcessWindowStation 1 failed "));
            return false;
        }

        // Get a handle to the interactive desktop.

        deskHandle_ = OpenDesktop(
            OJStr("default"),     // the interactive window station 
            0,             // no interaction with other desktop processes
            FALSE,         // handle is not inheritable
            READ_CONTROL | // request the rights to read and write the DACL
            WRITE_DAC | 
            DESKTOP_WRITEOBJECTS | 
            DESKTOP_READOBJECTS);

        // Restore the caller's window station.

        if (!SetProcessWindowStation(hwinstaSave)) 
        {
            OutputErrorMsg(OJStr("SetProcessWindowStation 2 failed "));
            return false;
        }

        if (deskHandle_ == NULL)
        {
            OutputErrorMsg(OJStr("OpenDesktop failed"));
            return false;
        }

        // Get the SID for the client's logon session.

        if (!getLogonSID(tokenHandle_, &pSid_)) 
        {
            OutputErrorMsg(OJStr("GetLogonSID failed "));
            return false;
        }

        // Allow logon SID full access to interactive window station.

        if (! addAceToWindowStation(winstaHandle_, pSid_) ) 
        {
            OutputErrorMsg(OJStr("AddAceToWindowStation failed "));
            return false;
        }

        // Allow logon SID full access to interactive desktop.

        if (! addAceToDesktop(deskHandle_, pSid_) ) 
        {
            OutputErrorMsg(OJStr("AddAceToDesktop failed "));
            return false;
        }

        // Impersonate client to ensure access to executable file.

        if (! ImpersonateLoggedOnUser(tokenHandle_) ) 
        {
            OutputErrorMsg(OJStr("ImpersonateLoggedOnUser failed "));
            return false;
        }

        return true;
    }