Пример #1
0
/*
 * Lwt_LsaOpenSession
 *
 * Check that LsaEnumUsers, LsaBeginEnumUsers, LsaEndEnumUsers behave
 * as expected, mostly by matching information against pUsersCsv.
 */
DWORD
Lwt_LsaOpenSession(
    HANDLE hLsaConnection,
    PTESTDATA pTestData
)
{
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;

    size_t nCurrentUser;
    PLWTUSER pUser = NULL;

    if ( ! pTestData)
    {
        dwError = LW_ERROR_TEST_SKIPPED;
        goto error;
    }

    /* For each user (line), verify the information is correct. */
    for ( nCurrentUser = 0;
            nCurrentUser < pTestData->dwNumUsers;
            nCurrentUser++)
    {
        dwLocalError = GetUser(pTestData, nCurrentUser, &pUser);
        BAIL_ON_TEST_BROKE(dwLocalError);

        if ( !IsNullOrEmpty(pUser->pszNTName) )
        {
            dwLocalError = CheckLsaOpenSession(
                               hLsaConnection,
                               pUser->pszNTName,
                               pUser);
            BAIL_ON_TEST_BROKE(dwLocalError);
        }

        if ( !IsNullOrEmpty(pUser->pszUserPrincipalName) )
        {
            dwLocalError = CheckLsaOpenSession(
                               hLsaConnection,
                               pUser->pszUserPrincipalName,
                               pUser);
            BAIL_ON_TEST_BROKE(dwLocalError);
        }

        FreeUser(&pUser);
    }

    dwLocalError = VerifyNullHandling(hLsaConnection);
    BAIL_ON_TEST_BROKE(dwLocalError);

cleanup:

    return dwError;

error:
    goto cleanup;
}
int SecureDescriptorStream::readData(uint8_t *buf, int buflen) {
  if (!IsNullOrEmpty(buf)) {
    int total_read = 0;
      int status = 0;
      while (buflen) {
        int sslStatus;
        do {
          status = SSL_read(ssl_, buf, buflen);
          sslStatus = SSL_get_error(ssl_, status);
        } while (status < 0 && sslStatus == SSL_ERROR_WANT_READ);

        if (status < 0)
              break;

        buflen -= status;
        buf += status;
        total_read += status;
      }

      return total_read;

  } else {
    return -1;
  }
}
Пример #3
0
bool StringUtil::IsValidEmail(const char* email)
{
    if (IsNullOrEmpty(email))
    {
        return false;
    }
    if (strchr(email, ' ') != NULL)
    {
        return false;
    }
    const char* atPos = strchr(email, '@');
    if (NULL == atPos)
    {
        return false;
    }
    const char* at2Pos = strchr(atPos + 1, '@');
    if (NULL != at2Pos)
    {
        return false;
    }
    const char* dotPos = strchr(atPos + 1, '.');
    if (NULL == dotPos || 0 == *(dotPos + 1))
    {
        return false;
    }
    return true;
}
Пример #4
0
void GDK_API GDK::TrimCRLF(_Inout_ wchar_t*& str)
{
    if (IsNullOrEmpty(str))
        return;

    while (IsCRLFChar(*str))
        ++str;
}
Пример #5
0
void GDK_API GDK::TrimUTFBOM(_Inout_ wchar_t*& str)
{
    if (IsNullOrEmpty(str))
        return;

    while (IsUTFBOMChar(*str))
        ++str;
}
Пример #6
0
void GDK_API GDK::TrimWhitespaces(_Inout_ wchar_t*& str)
{
    if (IsNullOrEmpty(str))
        return;

    while (IsWhitespaceChar(*str))
        ++str;
}
Пример #7
0
bool GDK_API GDK::StartsWith(_In_ const wchar_t* str, _In_ const wchar_t* pattern, _In_ bool caseSensitive)
{
    if (IsNullOrEmpty(str))
        return false;

    if (IsNullOrEmpty(pattern))
        return false;

    size_t strLen = wcslen(str);
    size_t patternLen = wcslen(pattern);

    if (patternLen > strLen)
        return false;

    return (caseSensitive ? 
                wcsncmp(str, pattern, patternLen) == 0 : 
                _wcsnicmp(str, pattern, patternLen) == 0);
}
Пример #8
0
std::vector<std::string> StringUtil::Split(const char* s, const char* seps)
{
    std::vector<std::string> results;
    if (IsNullOrEmpty(s) || IsNullOrEmpty(seps))
    {
        return results;
    };

    const char* tokenBegin = NULL;
    while (*s)
    {
       const char* sepsBegin =  seps;
       while (*sepsBegin && *sepsBegin != *s)
       {
           ++sepsBegin;
       }
       // match seps
       if (*sepsBegin)
       {
           if (NULL != tokenBegin)
           {
               results.push_back(std::string(tokenBegin, s - tokenBegin));
               tokenBegin = NULL;
           }
       }
       else
       {
           // not match seps
           if (NULL == tokenBegin)
           {
               tokenBegin = s;
           }
       }
       ++s;
    }
    if (tokenBegin != NULL)
    {
       results.push_back(Trim(std::string(tokenBegin, s - tokenBegin).c_str()));
    }

    return results;
}
Пример #9
0
/*
	SetFunction function
	Setup function.
*/
SUIMLIB_API int SetFunction(const int *S, const char *pchFuncName, CallBack pclCallBack)
{
	if(S== NULL) return (ERR_S_NULL);
	int inFlag = IsNullOrEmpty(pchFuncName);
	if(inFlag!= 0) return (ERR_NAME);
	if(pclCallBack== NULL) return (ERR_S_NULL);
	int inLength = strlen(pchFuncName);
	if(inLength>= MAX_KEY_LENGTH - 1) return (ERR_SET_NAME);

	struct ST_SUIM *pS = (struct ST_SUIM *)S;

	int inErrCode = AddCallBack(pS, pchFuncName, pclCallBack);

	return (inErrCode);
}
Пример #10
0
std::string StringUtil::Join(const std::vector<std::string>& ids, const char* seps)
{
    if (ids.empty() || IsNullOrEmpty(seps))
    {
        return "";
    }

    std::string result;
    for (size_t i = 0; i + 1 < ids.size(); ++i)
    {
        result.append(ids[i]).append(seps);
    }
    result.append(ids.back());
    return result;
}
Пример #11
0
/*
	IsExistFunction function
	Check exist function.
*/
SUIMLIB_API const int IsExistFunction(const int *S, const char *pchFuncName)
{
	char *pchLine;

	if(S== NULL) return (0);
	int inFlag = IsNullOrEmpty(pchFuncName);
	if(inFlag!= 0) return (0);

	struct ST_SUIM *pS = (struct ST_SUIM *)S;

	int inLineNo = GetFunctionDefine(pS, pchFuncName);
	if(inLineNo== 0) return (0);

	return (1);
}
Пример #12
0
void GDK_API GDK::TrimTrailingWhitespaces(_Inout_ wchar_t*& str)
{
    if (IsNullOrEmpty(str))
        return;

    wchar_t* end = str;
    while (*end != 0)
        ++end;

    --end;
    while (IsWhitespaceChar(*end))
    {
        --end;
    }

    *(end + 1) = 0;
}
Пример #13
0
geek::GeekResult geek::GeekMapDb::DeleteKeyValue(INPARAM const std::wstring & wszKey) {
	if (IsNullOrEmpty(wszKey)) {
		logger->error(LoggerContext(L"要修改的数据名为空"));
		return GEEK_ERROR_INVALIDPARAM;
	}

	KeyValueIterator it = m_kvContainer.find(wszKey);
	if (it == m_kvContainer.end()) {
		logger->error(LoggerContext(L"没有找到要删除的数据"));
		return GEEK_ERROR_ENTRYNOTFOUND;
	}

	m_kvContainer.erase(wszKey);
	logger->info(LoggerContext(L"删除了一条数据"));
	updateContext(0, 1);
	Notify();
	return GEEK_SUCCESS;
}
Пример #14
0
    int ValidateNumberString(const char* psz, int nMinValue, int nMaxValue, int* pnResult)
    {
        int nVal = 0;

        if (IsNullOrEmpty(psz) || (pnResult==NULL))
        {
            return -1;
        }

        nVal = atoi(psz);

        if(nVal < nMinValue) return -1;
        if(nVal > nMaxValue) return -1;

        *pnResult = nVal;
        return 0;

    }
Пример #15
0
int HttpStream::writeData(uint8_t *value, int size) {
  if (!IsNullOrEmpty(value)) {
    if (!started_) {
      std::lock_guard<std::mutex> lock(mutex_);
      if (!started_) {
        callback_.ptr = &http_callback_;
        callback_.pos = 0;
        http_client_->setUploadCallback(&callback_);
        http_client_future_ = std::async(std::launch::async, submit_client, http_client_);
        started_ = true;
      }
    }
    http_callback_.process(value, size);
    return size;
  } else {
    return -1;
  }
}
Пример #16
0
bool SiteToSitePeer::Open() {
  if (IsNullOrEmpty(host_))
    return false;

  if (!this->local_network_interface_.empty())
      stream_->setInterface(local_network_interface_);

  if (stream_->initialize() < 0)
    return false;

  uint16_t data_size = sizeof MAGIC_BYTES;

  if (stream_->writeData(reinterpret_cast<uint8_t *>(const_cast<char*>(MAGIC_BYTES)), data_size) != data_size) {
    return false;
  }

  return true;
}
Пример #17
0
int HttpStream::readData(uint8_t *buf, int buflen) {
  if (!IsNullOrEmpty(buf)) {
    if (!started_) {
      std::lock_guard<std::mutex> lock(mutex_);
      if (!started_) {
        read_callback_.ptr = &http_read_callback_;
        read_callback_.pos = 0;
        http_client_->setReadCallback(&read_callback_);
        http_client_future_ = std::async(std::launch::async, submit_read_client, http_client_, &http_read_callback_);
        started_ = true;
      }
    }
    return http_read_callback_.readFully((char*) buf, buflen);

  } else {
    return -1;
  }
}
Пример #18
0
geek::GeekResult geek::GeekMapDb::QueryKeyValue(
	INPARAM const std::wstring & wszKey,
	OUTPARAM std::vector<GeekKeyValue>& entries) {

	if (IsNullOrEmpty(wszKey)) {
		logger->error(LoggerContext(L"要查询的数据名为空"));
		return GEEK_ERROR_INVALIDPARAM;
	}
	KeyValueIterator it = m_kvContainer.find(wszKey);
	if (it == m_kvContainer.end()) {
		logger->error(LoggerContext(L"没有找到要查询的数据"));
		return GEEK_ERROR_ENTRYNOTFOUND;
	}
	entries.push_back(*it);
	logger->error(LoggerContext(L"查询到了一条数据"));
	updateContext(0, 0, 0, 1);
	Notify();
	return GEEK_SUCCESS;
}
Пример #19
0
/*
	GetToken function
	Get token from line
*/
int CountToken(char *pchLine)
{
	int inFlag = IsNullOrEmpty(pchLine);
	if(inFlag!= 0) return (0);

	int inCntToken = 0;
	char *pchSt = pchLine;
	char *pchEd = strchr(pchSt, ' ');
	while(1)
	{
		inCntToken++;

		if(pchEd== NULL) break;
		pchSt = pchEd + 1;
		pchEd = strchr(pchSt, ' ');
	}

	return (inCntToken);
}
Пример #20
0
geek::GeekResult geek::GeekMapDb::DumpKeyValues(INPARAM const std::wstring & wszFileName) {
	if (IsNullOrEmpty(wszFileName)) {
		logger->error(LoggerContext(L"要Dump的文件名为空"));
		return GEEK_ERROR_INVALIDPARAM;
	}

	GeekDbStorage *p_stg = new GeekDbStorage(wszFileName, this->m_Metadata, true);
	if (p_stg == nullptr) {
		logger->error(LoggerContext(L"没有找到要Dump的文件"));
		return GEEK_ERROR_OUTOFMEMORY;
	}

	GeekResult result = p_stg->AddRange(m_kvContainer.cbegin(), m_kvContainer.cend());
	DISPOSE_OBJECT(p_stg);

	if (result == GEEK_SUCCESS) {
		logger->info(LoggerContext(L"文件成功Dump"));
		Notify();
	}
	return result;
}
int SecureDescriptorStream::writeData(uint8_t *value, int size) {
  if (!IsNullOrEmpty(value)) {
    std::lock_guard<std::recursive_mutex> lock(file_lock_);
    int bytes = 0;
     int sent = 0;
     while (bytes < size) {
       sent = SSL_write(ssl_, value + bytes, size - bytes);
       // check for errors
       if (sent < 0) {
         int ret = 0;
         ret = SSL_get_error(ssl_, sent);
         logger_->log_error("WriteData socket %d send failed %s %d", fd_, strerror(errno), ret);
         return sent;
       }
       bytes += sent;
     }
     return size;
  } else {
    return -1;
  }
}
Пример #22
0
geek::GeekResult geek::GeekMapDb::LoadKeyValues(
	INPARAM const std::wstring & wszFileName,
	OUTPARAM std::wstring & wszName) {

	if (IsNullOrEmpty(wszFileName)) {
		logger->error(LoggerContext(L"要加载的文件名为空"));
		return GEEK_ERROR_INVALIDPARAM;
	}
	GeekDbStorage* pstg = new GeekDbStorage(wszFileName, this->m_Metadata, false);
	if (pstg == nullptr) {
		logger->error(LoggerContext(L"没有找到要加载的文件"));
		return GEEK_ERROR_FILENOTFOUND;
	}
	KeyValueContainer().swap(m_kvContainer);
	wszName.clear();

	GeekResult result = pstg->LoadAll(m_Metadata, m_kvContainer);
	wszName.assign(m_Metadata.wszName);
	DISPOSE_OBJECT(pstg);

	logger->info(LoggerContext(L"文件成功加载"));
	Notify();
	return GEEK_SUCCESS;
}
Пример #23
0
/*
 * CheckLsaOpenSession
 *
 */
static
DWORD
CheckLsaOpenSession(
    HANDLE hLsaConnection,
    PCSTR pszLoginId,
    PLWTUSER pUser
)
{
    PCSTR pszTestDescription =
        "Home directory exists after call to LsaOpenSession for valid user.";
    PCSTR pszTestAPIs =
        "LsaOpenSession,"
        "LsaCloseSession,"
        "LsaCheckUserInList,"
        "LsaAuthenticateUser";
    char szTestMsg[128] = { 0 };

    DWORD dwError = LW_ERROR_SUCCESS;

    int bSessionIsOpen = 0;

    snprintf(szTestMsg, sizeof(szTestMsg), "Session for %s", pszLoginId);

    dwError = LsaOpenSession(hLsaConnection, pszLoginId);
    if ( dwError )
        goto error;
    bSessionIsOpen = 1;

    if ( !IsNullOrEmpty(pUser->pszUnixHomeDirectory) )
    {
        struct stat statbuf;
        if ( stat(pUser->pszUnixHomeDirectory, &statbuf) < 0 )
        {
            char buf[64];
            snprintf(
                buf,
                sizeof(buf),
                ",could not stat %s",
                pUser->pszUnixHomeDirectory);
            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
            goto error;
        }

        if ( !S_ISDIR(statbuf.st_mode) )
        {
            Lwt_strcat(
                szTestMsg,
                sizeof(szTestMsg),
                ",home is not a directory.");
            dwError = LW_ERROR_TEST_FAILED;
        }

        if ( !IsNullOrEmpty(pUser->pszUnixUid) )
        {
            if ( statbuf.st_uid != pUser->nUnixUid )
            {
                Lwt_strcat(
                    szTestMsg,
                    sizeof(szTestMsg),
                    ",uid doesn't match expected");
                dwError = LW_ERROR_TEST_FAILED;
            }
        }
    }


cleanup:

    if ( bSessionIsOpen )
    {
        dwError = LsaCloseSession(hLsaConnection, pszLoginId);
        bSessionIsOpen = 0;
    }

    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:

    goto cleanup;

}
Пример #24
0
/*
 * MatchUserInfo0
 *
 * Check LSA_USER_INFO_0 matches information in CSV.
 */
static
DWORD
MatchUserInfo0(
    PLWTUSER pUser,
    PCSTR pszLookedUpBy,
    PLSA_USER_INFO_0 pUserInfo
    )
{
    PCSTR pszTestDescription =
        "LsaFindUserByName retrieved LSA_USER_INFO_0 that matches expected values.";
    PCSTR pszTestAPIs = 
        "LsaFindUserByName";
    char szTestMsg[128] = { 0 };
    DWORD dwError = LW_ERROR_SUCCESS;

    snprintf( szTestMsg, 
              sizeof(szTestMsg), 
              "\n\tAccount %s.\n", 
              pszLookedUpBy);

    if ( pUser->pszAlias )
    {
        if ( !pUserInfo->pszName || 
             strcasecmp(pUser->pszAlias, pUserInfo->pszName) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tAlias: test[%s] != lsassd[%s]\n",
                      pUser->pszAlias,
                      pUserInfo->pszName);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }
    else if ( pUser->pszNTName )
    {
        if ( !pUserInfo->pszName || 
             strcasecmp(pUser->pszNTName, pUserInfo->pszName) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tNT Name: test[%s] != lsassd[%s]\n",
                      pUser->pszNTName,
                      pUserInfo->pszName);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszSid) )
    {
        if ( ! pUserInfo->pszSid || 
             strcmp(pUser->pszSid, pUserInfo->pszSid) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tsid: test[%s] != lsassd[%s]\n",
                      pUser->pszSid,
                      pUserInfo->pszSid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }


    if ( pUser->pszUnixUid )
    {
        if ( pUser->nUnixUid != pUserInfo->uid )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tuid: test[%lu (%s)] != lsassd[%lu]\n",
                      (unsigned long) pUser->nUnixUid,
                      pUser->pszUnixUid,
                      (unsigned long) pUserInfo->uid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( pUser->pszUnixGid )
    {
        if ( pUser->nUnixGid != pUserInfo->gid )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tgid: test[%lu (%s)] != lsassd[%lu]\n",
                      (unsigned long)pUser->nUnixGid,
                      pUser->pszUnixGid,
                      (unsigned long)pUserInfo->gid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixGecos) )
    {
        if ( ! pUserInfo->pszGecos ||
             strcmp(pUser->pszUnixGecos, pUserInfo->pszGecos) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tgecos: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixGecos,
                      pUserInfo->pszGecos ? pUserInfo->pszGecos : "<null>");

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixLoginShell) )
    {
        if ( ! pUserInfo->pszShell || 
             strcmp(pUser->pszUnixLoginShell, pUserInfo->pszShell) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tshell: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixLoginShell,
                      pUserInfo->pszShell);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixHomeDirectory) )
    {
        if ( ! pUserInfo->pszHomedir || 
             strcmp(pUser->pszUnixHomeDirectory, pUserInfo->pszHomedir) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\thome directory: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixHomeDirectory,
                      pUserInfo->pszHomedir);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    LWT_LOG_TEST(szTestMsg);
    return dwError;
}
Пример #25
0
/*
	ExecFunction function
	Execute function.
*/
SUIMLIB_API const int ExecFunction(const int *S, const char *pchFuncName)
{
	char *pchLine;

	if(S== NULL) return (ERR_S_NULL);
	int inFlag = IsNullOrEmpty(pchFuncName);
	if(inFlag!= 0) return (ERR_S_NULL);

	struct ST_SUIM *pS = (struct ST_SUIM *)S;

	int inLineNo = GetFunctionDefine(pS, pchFuncName);
	if(inLineNo== 0) return (ERR_FUNC_NAME);

	inLineNo++;

	while(1)
	{
		pS->inLineNo = inLineNo;
		inLineNo = ExecLine(pS, (char *)(pS->ppchLines[inLineNo] + pS->pchListStartPos[inLineNo]));
		if(inLineNo< 0) {
			if(inLineNo== ORDER_SEPARATOR || inLineNo== ORDER_RETURN || inLineNo== ORDER_END) {
				//finish
				break;
			}
			else {
				//error
				return (inLineNo);
			}
		}
	}

/*
	int inLineNoBase = inLineNo;
	double doTime = 0.0;
	int inCnt;
	for(inCnt= 0;inCnt< 20;inCnt++) {
		clock_t start = clock();

		inLineNo = inLineNoBase;

		while(1)
		{
			pS->inLineNo = inLineNo;
			inLineNo = ExecLine(pS, (char *)(pS->ppchLines[inLineNo] + pS->pchListStartPos[inLineNo]));
			if(inLineNo< 0) break;
		}

		clock_t end = clock();
		doTime += (double)(end - start) / CLOCKS_PER_SEC;
	}
	printf("time= %f ms\n", doTime / 20.0 * 1000.0);

	if(pS->inFlgError) {
		printf("err:%s", pS->pchErrMsg);
	}
*/

/*
--01
s|ad:------ end ------
s|ab:level
s|ac:----- start -----
s|ae:BREAK_EFFECT
s|aa:resonance
s|af:data_prim_key=
f|init:20
f|exec:33
--
8:ag=0
9:ah=0
10:ai=0
11:aj=0
12:ak=0
13:al=0
14:am=0
15:an=0.1
16:ao=0
18:ap=0.1

22:f:init
23:ai=aq
24:aj=ar
25:o:aq
25:o:ar
25:c:WorldPos2BlockPos ag,ah
26:al=as
27:am=25.0 as /
28:an=0.1
29:ao=0.1
31:o:aa
31:c:PlaySE
32:e:

35:f:exec
36:ak=ak ap +
38:o:at
38:o:au
38:c:WorldPos2BlockPos av,aw
39:i:(ag av != ah aw != ||)e41
40:o:0
40:r:
43:i:(ax ab !=)e44
44:o:0
44:r:
47:an=an am ap * +
49:o:-an
49:o:an
49:c:MathRandom ay
50:aq=ai ay 100.0 / +
51:o:-an
51:o:an
51:c:MathRandom az
52:ar=aj az 100.0 / +
55:ao=ao ap -
56:i:(ao 0 <=)e63
57:o:ac
57:c:Printf
58:ao=aA
59:o:ad
59:c:Printf
61:o:ae
61:o:af aB +
61:c:AddEffect
64:i:(ak al >)e77
65:o:aC
65:o:ag
65:o:ah
65:c:SetBreak
68:aD=0
70:i:(aD 8 >)e75
71:o:ae
71:o:af aB +
71:c:AddEffect
72:aD=aD 1 +
73:g:69
76:o:0
76:r:
79:o:1
79:r:
80:e:
--
*/

	return (SUCCESS);
}
Пример #26
0
DWORD
Lwt_LsaTestSetup(
    int argc,
    char *argv[],
    HANDLE *phLsaConnection,
    PTESTDATA *ppTestData
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;

    HANDLE hLsaConnection = NULL;

    PSTR pszUsersFilename = NULL;
    PSTR pszGroupsFilename = NULL;
    PSTR pszInvalidFileName = NULL;
    PSTR pszLogFilename = NULL;
    int nLogLevel = 0;
    int nAppend = 0;

    PLWTDATAIFACE pLwtUserIface = NULL;
    PLWTDATAIFACE pLwtGroupIface = NULL;
    PLWTDATAIFACE pLwtInvalidDataIface = NULL;
    DWORD dwMaxGroup = 0;
    DWORD dwMaxUser = 0;
    DWORD dwMaxInvalidDataSet = 0;
    int nDataFormat = -1;    /* Update it from the config file */

    PLWTCSV  pGroupInfo = NULL;

    PTESTDATA pTestData = NULL;

    ParseArgs(
        argc,
        argv,
        &pszUsersFilename,
        &pszGroupsFilename,
        &pszInvalidFileName,
        &pszLogFilename,
        &nLogLevel,
        &nAppend);
    nDataFormat = LWT_DATA_CSV; /* FIXME -- hardcoding to CSV. */

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LWT_ERROR(dwError);

    if(nDataFormat == LWT_DATA_CSV)
    {
        if ( !IsNullOrEmpty(pszUsersFilename) )
        {
            dwError = Csv_LoadInterface(&pLwtUserIface);
            BAIL(dwError);

            dwError = InitialiseUserInfo(pszUsersFilename, &pLwtUserIface, &dwMaxUser);
            BAIL(dwError);
        }
        if ( !IsNullOrEmpty(pszGroupsFilename))
        {
            dwError = Csv_LoadInterface(&pLwtGroupIface);
            BAIL(dwError);

            dwError = InitializeGroupInfo(pszGroupsFilename, &pLwtGroupIface, &dwMaxGroup);
            BAIL(dwError);
        }
        if ( !IsNullOrEmpty(pszInvalidFileName) )
        {
            dwError = Csv_LoadInterface(&pLwtInvalidDataIface);
            BAIL(dwError);

            dwError = InitialiseInvalidDataSet(pszInvalidFileName, &pLwtInvalidDataIface, &dwMaxInvalidDataSet);
            BAIL(dwError);
        }

    }
    else if (nDataFormat == LWT_DATA_LDIF)
    {
        if ( !IsNullOrEmpty(pszUsersFilename) )
        {

            dwError = Ldif_LoadInterface(&pLwtUserIface);
            BAIL(dwError);

            InitialiseUserInfo(pszUsersFilename, &pLwtUserIface, &dwMaxUser);
            BAIL(dwError);
        }
        if ( !IsNullOrEmpty(pszGroupsFilename))
        {
            dwError = Ldif_LoadInterface(&pLwtGroupIface);
            BAIL(dwError);

            dwError = InitializeGroupInfo(
                        pszGroupsFilename,
                        &pLwtGroupIface,
                        &dwMaxGroup);
            BAIL(dwError);
        }
    }
    else
    {
            dwError = LW_ERROR_DATA_ERROR;
            BAIL(dwError);
    }

    dwError = LwtInitLogging(pszLogFilename, nAppend, nLogLevel);
    BAIL(dwError);

    dwError = LwAllocateMemory(sizeof(TESTDATA), (PVOID)&pTestData);
    BAIL_ON_LWT_ERROR(dwError);

cleanup:

    LW_SAFE_FREE_STRING(pszUsersFilename);
    LW_SAFE_FREE_STRING(pszGroupsFilename);

    if ( pTestData )
    {
        pTestData->pUserIface =  pLwtUserIface;
        pTestData->pGroupIface = pLwtGroupIface;
        pTestData->pInvalidDataIface = pLwtInvalidDataIface;
        pTestData->dwNumGroups = dwMaxGroup;
        pTestData->dwNumUsers = dwMaxUser;
        pTestData->dwNumInvalidDataSet = dwMaxInvalidDataSet;
    }

    *phLsaConnection = hLsaConnection;
    *ppTestData = pTestData;

    return dwError;

error:

    if(pGroupInfo)
    {
        DestroyGroupInfo(pLwtGroupIface);
        pGroupInfo = NULL;
    }

    if ( hLsaConnection != (HANDLE)NULL) 
    {
        LsaCloseServer(hLsaConnection);
        hLsaConnection = NULL;
    }

    LW_SAFE_FREE_MEMORY(pTestData);

    LwtShutdownLogging();

    goto cleanup;
}
Пример #27
0
/*
	SetTokenDouble function
*/
void SetTokenData(struct ST_SUIM *pS, char *pchLine, int inTokenSt)
{
	int inFlag = IsNullOrEmpty(pchLine);
	if(inFlag!= 0) return;

	int inCntToken = 0;
	char *pchSt = pchLine;
	char *pchEd = strchr(pchSt, ' ');
	while(1)
	{
		char pchWord[MAX_WORD];
		if(pchEd== NULL) {
			strcpy(pchWord, pchSt);
		}
		else {
			int inLength = pchEd- pchSt;
			strncpy(pchWord, pchSt, inLength);
			pchWord[inLength] = '\0';
		}

		//copy token word
		strcpy(&pS->pchListTokenWord[MAX_WORD * (inTokenSt + inCntToken)], pchWord);

		//setup token type
		if(isalpha(pchWord[0]) && isalpha(pchWord[1])) {
			pS->pchListTokenType[inTokenSt + inCntToken] = 2;
		}
		else {
			if(pchWord[0]== '-' && isalpha(pchWord[1]) && isalpha(pchWord[2])) {
				pS->pchListTokenType[inTokenSt + inCntToken] = 3;
			}
			else {
				int isDouble = IsDouble(pchWord);
				if(isDouble) {
					pS->pchListTokenType[inTokenSt + inCntToken] = 1;
					pS->pdoListToken[inTokenSt + inCntToken] = atof(pchSt);
				}
				else {
					if(pchWord[0]== '+') {
						pS->pchListTokenType[inTokenSt + inCntToken] = 4;
					}
					else {
						if(pchWord[0]== '=' && pchWord[1]== '=') {
							pS->pchListTokenType[inTokenSt + inCntToken] = 5;
						}
						else {
							if(pchWord[0]== '!' && pchWord[1]== '=') {
								pS->pchListTokenType[inTokenSt + inCntToken] = 6;
							}
							else {
								if(pchWord[0]== '-') {
									pS->pchListTokenType[inTokenSt + inCntToken] = 7;
								}
								else {
									if(pchWord[0]== '*') {
										pS->pchListTokenType[inTokenSt + inCntToken] = 8;
									}
									else {
										if(pchWord[0]== '/') {
											pS->pchListTokenType[inTokenSt + inCntToken] = 9;
										}
										else {
											if(pchWord[0]== '%') {
												pS->pchListTokenType[inTokenSt + inCntToken] = 10;
											}
											else {
												if(pchWord[0]== '>' && pchWord[1]== '=') {
													pS->pchListTokenType[inTokenSt + inCntToken] = 11;
												}
												else {
													if(pchWord[0]== '<' && pchWord[1]== '=') {
														pS->pchListTokenType[inTokenSt + inCntToken] = 12;
													}
													else {
														if(pchWord[0]== '>') {
															pS->pchListTokenType[inTokenSt + inCntToken] = 13;
														}
														else {
															if(pchWord[0]== '<') {
																pS->pchListTokenType[inTokenSt + inCntToken] = 14;
															}
															else {
																if(pchWord[0]== '&' && pchWord[1]== '&') {
																	pS->pchListTokenType[inTokenSt + inCntToken] = 15;
																}
																else {
																	if(pchWord[0]== '|' && pchWord[1]== '|') {
																		pS->pchListTokenType[inTokenSt + inCntToken] = 16;
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		inCntToken++;

		if(pchEd== NULL) break;
		pchSt = pchEd + 1;
		pchEd = strchr(pchSt, ' ');
	}
}
Пример #28
0
/*
	SetBuffer function
	Setup suim code.
*/
SUIMLIB_API int SetBuffer(const int *S, const char *pchSuimName, const char *pchBuffer, const int inVarCount, const int inOutCount, int inCallBackCount)
{
	if(S== NULL) return (ERR_S_NULL);
	int inFlag = IsNullOrEmpty(pchSuimName);
	if(inFlag!= 0) return (ERR_NAME);
	inFlag = IsNullOrEmpty(pchBuffer);
	if(inFlag!= 0) return (ERR_BUFFLER);
	if(inVarCount>= MAX_VARIABLE_COUNT) return (ERR_OVERFLOW);

	struct ST_SUIM *pS = (struct ST_SUIM *)S;
	if(pS->pchSuimName!= NULL) return (ERR_SET_NAME);
	if(pS->pchBuffer!= NULL) return (ERR_SET_BUFFER);

	size_t szLength = strlen(pchSuimName);
	pS->pchSuimName = malloc(szLength + 1);
	if(pS->pchSuimName== NULL) return (ERR_MEMORY);
	strcpy(pS->pchSuimName, pchSuimName);

	szLength = strlen(pchBuffer);
	pS->pchBuffer = malloc(szLength + 1);
	if(pS->pchBuffer== NULL) return (ERR_MEMORY);
	strcpy(pS->pchBuffer, pchBuffer);

	int inMaxLine = 0;
	int inCnt, inMax = strlen(pchBuffer);
	for(inCnt= 0;inCnt< inMax;inCnt++)
	{
		if(pchBuffer[inCnt]== '\n') inMaxLine++;
	}

	pS->inMaxLineNum = inMaxLine;

	pS->ppchLines = malloc(sizeof(char *) * (inMaxLine));
	if(pS->ppchLines== NULL) return (ERR_MEMORY);
	memset(pS->ppchLines, 0x00, sizeof(char *) * (inMaxLine));

	//split lines
	inCnt = 0;
	char *pchPos = strtok( pS->pchBuffer, "\n" );
	while( pchPos != NULL && inCnt < inMaxLine )
	{
		pS->ppchLines[inCnt] = pchPos;
		inCnt++;

		pchPos = strtok( NULL, "\n" );
	}

	int inCountFunction = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		if(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|') inCountFunction++;
	}

	//define setting
	pS->inCountVariable = inVarCount;
	if(inVarCount> 0) {
		pS->ppstListVariable = malloc(sizeof(struct ST_VALUE *) * inVarCount);
		memset(pS->ppstListVariable, 0x00, sizeof(struct ST_VALUE *) * inVarCount);
		for(inCnt= 0;inCnt< inVarCount;inCnt++)
		{
			SetValueDouble(pS->ppstListVariable, inCnt, 0.0);
		}

		for(inCnt= 0;inCnt< inMaxLine;inCnt++)
		{
			if(!(pS->ppchLines[inCnt][0]== 's' && pS->ppchLines[inCnt][1]== '|')) continue;

			char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":");
			char *pchValue = strtok(NULL, ":");

			const int inNo = CngKey2No(pchKey);
			if(inNo< 0) return (ERR_OVERFLOW);
			if(inNo>= inMax) return (ERR_OVERFLOW);
			int inErrCode = SetValueString(pS->ppstListVariable, inNo, pchValue);
			if(inErrCode!= SUCCESS) return (inErrCode);
		}
	}

	//callback setting
	pS->inCountCallBack = inCallBackCount;
	if(inCallBackCount> 0) {
		pS->ppstListCallBack = malloc(sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount);
		memset(pS->ppstListCallBack, 0x00, sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount);
	}

	//out setting
	pS->pchInArgs = NULL;

	pS->inNoOut = 0;

	pS->inCountOut = inOutCount;
	if(inOutCount> 0) {
		pS->pchOutArgsType = malloc(inOutCount + 1);
		memset(pS->pchOutArgsType, 0x00, inOutCount + 1);

		pS->ppstListOut = malloc(sizeof(struct ST_VALUE *) * inOutCount);
		memset(pS->ppstListOut, 0x00, sizeof(struct ST_VALUE *) * inOutCount);
		for(inCnt= 0;inCnt< inOutCount;inCnt++)
		{
			SetValueDouble(pS->ppstListOut, inCnt, 0.0);
		}
	}

	//function setting
	pS->inCountFunction = inCountFunction;
	if(inCountFunction> 0) {
		pS->ppstListFunction = malloc(sizeof(struct ST_VALUE *) * inCountFunction);
		memset(pS->ppstListFunction, 0x00, sizeof(struct ST_VALUE *) * inCountFunction);
		for(inCnt= 0;inCnt< inMaxLine;inCnt++)
		{
			if(!(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|')) continue;

			char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":");
			char *pchValue = strtok(NULL, ":");
			int inLineNo = atoi(pchValue);

			int inRes = AddFunctionDefine(pS, pchKey, inLineNo);
			if(inRes!= SUCCESS) return (inRes);
		}
	}

	//set start position
	//set jump line no
	//create cmp string
	pS->pchListStartPos = malloc(sizeof(char) * inMaxLine);
	pS->pinListJumpNo = malloc(sizeof(int) * inMaxLine);
	pS->ppchListCmp = malloc(sizeof(char *) * inMaxLine);
	memset(pS->ppchListCmp, 0x00, sizeof(char *) * inMaxLine);
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		pS->pchListStartPos[inCnt] = 0;
		pS->pinListJumpNo[inCnt] = 0;
		pS->ppchListCmp[inCnt] = NULL;

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		char *pchIndex = strchr(pchLine, ':');
		if(pchIndex== NULL) continue;
		pchIndex+= 1;

		pS->pchListStartPos[inCnt] = (char)(pchIndex - pchLine);

		if(pchIndex[0]== 'i' && pchIndex[1]== ':')
		{
			char *pchIndex2 = strstr(pchIndex, ")e");
			if(pchIndex2!= NULL)
			{
				pS->pinListJumpNo[inCnt] = atoi(pchIndex2 + 2);

				int inSize = (int)(pchIndex2 - &pchIndex[3]);
				pS->ppchListCmp[inCnt] = malloc(inSize + 1);
				memset(pS->ppchListCmp[inCnt], 0x00, inSize + 1);
				strncpy(pS->ppchListCmp[inCnt], &pchIndex[3], inSize);
			}
			continue;
		}

		if(pchIndex[0]== 'g' && pchIndex[1]== ':')
		{
			pchIndex = strchr(pchIndex, ':');
			if(pchIndex!= NULL)
			{
				pS->pinListJumpNo[inCnt] = atoi(pchIndex + 1);
			}
			continue;
		}
	}

	//memory allocate
	int inSize = sizeof(int) * inMaxLine;
	pS->pinListTokenNum = malloc(inSize);
	memset(pS->pinListTokenNum, 0x00, inSize);

	inSize = sizeof(int) * inMaxLine;
	pS->pinListTokenSt = malloc(inSize);
	memset(pS->pinListTokenSt, 0x00, inSize);

	//count token
	int inStToken = 0;
	int inMaxToken = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		if(pS->pchListStartPos[inCnt]== 0) continue;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);
		if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue;

		int inCntToken = 0;
		if(pchIndex[0]== 'o' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[2]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
/*
		if(pchIndex[0]== 's' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[5]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
		if(pchIndex[0]== 'd' && pchIndex[1]== ':') {
			inCntToken = CountToken(&pchIndex[5]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
*/
		if(pchIndex[0]== 'i' && pchIndex[1]== ':') {
			inCntToken = CountToken(pS->ppchListCmp[inCnt]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}
		if(pchIndex[2]== '=') {
			inCntToken = CountToken(&pchIndex[3]);
			if(inMaxToken< inCntToken) inMaxToken = inCntToken;
		}

		pS->pinListTokenSt[inCnt] = inStToken;
		inStToken+= inCntToken;

		pS->pinListTokenNum[inCnt] = inCntToken;
	}

	//memory allocate
	pS->inMaxTokenNum = inMaxToken;

	inSize = sizeof(double) * inMaxToken * inMaxLine;
	pS->pdoListToken = malloc(inSize);
	memset(pS->pdoListToken, 0x00, inSize);

	inSize = sizeof(char) * inMaxToken * inMaxLine;
	pS->pchListTokenType = malloc(inSize);
	memset(pS->pchListTokenType, 0x00, inSize);

	inSize = sizeof(char) * MAX_WORD * inMaxToken * inMaxLine;
	pS->pchListTokenWord = malloc(inSize);
	memset(pS->pchListTokenWord, 0x00, inSize);

	//setup token data
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') continue;
		if(pchLine[1]== '|') continue;

		if(pS->pchListStartPos[inCnt]== 0) continue;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);
		if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue;
		if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue;

		int inStToken = pS->pinListTokenSt[inCnt];
		if(pchIndex[0]== 'o' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[2], inStToken);
		}
/*
		if(pchIndex[0]== 's' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[5], inStToken);
		}
		if(pchIndex[0]== 'd' && pchIndex[1]== ':') {
			SetTokenData(pS, &pchIndex[5], inStToken);
		}
*/
		if(pchIndex[0]== 'i' && pchIndex[1]== ':') {
			SetTokenData(pS, pS->ppchListCmp[inCnt], inStToken);
		}
		if(pchIndex[2]== '=') {
			SetTokenData(pS, &pchIndex[3], inStToken);
		}
	}

	//global line execute
	int inFunc = 0;
	for(inCnt= 0;inCnt< inMaxLine;inCnt++)
	{
		const char *pchLine = pS->ppchLines[inCnt];

		if(pchLine[0]== '-' && pchLine[1]== '-') {
			int inLength = strlen(pchLine);
			if(inLength<= 2) continue;

			int inVersion = atoi(&pchLine[2]);
			if(inVersion== VERSION) continue;

			return (ERR_VERSION);
		}

		if(pchLine[1]== '|') continue;

		pS->inLineNo = inCnt;

		char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]);

		if(pchIndex[0]== 'f') inFunc = 1;
		if(pchIndex[0]== 'e') inFunc = 0;
		if(inFunc== 1) continue;

		if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue;

		int inLineNo = ExecLine(pS, pchIndex);
		if(inLineNo< 0) return (inLineNo);
	}

	return (SUCCESS);
}