Exemplo n.º 1
0
int AmmServer_SetStrSettingValue(struct AmmServer_Instance * instance,unsigned int set_type,const char * set_value)
{
  switch (set_type)
   {
     case AMMSET_USERNAME_STR :  AssignStr(&instance->settings.USERNAME,set_value); return SetUsernameAndPassword(instance,instance->settings.USERNAME,instance->settings.PASSWORD); break;
     case AMMSET_PASSWORD_STR :  AssignStr(&instance->settings.PASSWORD,set_value); return SetUsernameAndPassword(instance,instance->settings.USERNAME,instance->settings.PASSWORD); break;
   };
  return 0;
}
Exemplo n.º 2
0
bool			InitUsers(FarList &users) {
	DWORD dwLevel = 3;
	DWORD dwEntriesRead = 0;
	DWORD dwTotalEntries = 0;
	DWORD dwResumeHandle = 0;
	NET_API_STATUS nStatus;

	USER_INFO_3 *psi = nullptr;
	nStatus = ::NetUserEnum(nullptr, dwLevel,
							FILTER_NORMAL_ACCOUNT,
							(PBYTE*) & psi,
							MAX_PREFERRED_LENGTH,
							&dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
	if (nStatus == NERR_Success) {
		users.ItemsNumber = 0;
		WinMem::Alloc(users.Items, sizeof(*users.Items) * dwEntriesRead);
		for (DWORD i = 0; i < dwEntriesRead; ++i) {
			if (!WinFlag::Check(psi[i].usri3_flags, (DWORD)UF_ACCOUNTDISABLE)) {
				users.Items[users.ItemsNumber].Text = AssignStr(psi[i].usri3_name);
				if (psi[i].usri3_priv == USER_PRIV_ADMIN) {
					WinFlag::Set(users.Items[users.ItemsNumber].Flags, (DWORD)LIF_CHECKED);
				}
				++users.ItemsNumber;
			}
		}
		::NetApiBufferFree(psi);
	}
	return	nStatus == NERR_Success;
}
Exemplo n.º 3
0
//----------------------------------------------------------------
CPUTResult CPUTConfigFile::LoadFile(const cString &szFilename)
{
    // Load the file
    cString             szCurrLine;
    CPUTConfigBlock    *pCurrBlock = NULL;
    FILE               *pFile = NULL;
    int                 nCurrBlock = 0;
    CPUTResult result = CPUTOSServices::GetOSServices()->OpenFile(szFilename, &pFile);
    if(CPUTFAILED(result))
    {
        return result;
    }

	_locale_t locale = _get_current_locale();

	/* Determine file size */
	fseek(pFile, 0, SEEK_END);
	int nBytes = ftell(pFile); // for text files, this is an overestimate
	fseek(pFile, 0, SEEK_SET);

	/* Read the whole thing */
	char *pFileContents = new char[nBytes + 1];
	nBytes = (int)fread(pFileContents, 1, nBytes, pFile);
	fclose(pFile);

	pFileContents[nBytes] = 0; // add 0-terminator

	/* Count the number of blocks */
	const char *pCur = pFileContents;
	const char *pStart, *pEnd;

	while(ReadLine(&pStart, &pEnd, &pCur))
	{
		const char *pOpen = FindFirst(pStart, pEnd, '[');
		const char *pClose = FindLast(pOpen + 1, pEnd, ']');
		if (pOpen < pClose)
		{
			// This line is a valid block header
			mnBlockCount++;
		}
	}

    // For files that don't have any blocks, just add the entire file to one block
    if(mnBlockCount == 0)
    {
        mnBlockCount   = 1;
    }

	pCur = pFileContents;
    mpBlocks = new CPUTConfigBlock[mnBlockCount];
    pCurrBlock = mpBlocks;

	/* Find the first block first */
	while(ReadLine(&pStart, &pEnd, &pCur))
	{
		const char *pOpen = FindFirst(pStart, pEnd, '[');
		const char *pClose = FindLast(pOpen + 1, pEnd, ']');
		if (pOpen < pClose)
		{
			// This line is a valid block header
            pCurrBlock = mpBlocks + nCurrBlock++;
			AssignStr(pCurrBlock->mszName, pOpen + 1, pClose, locale);
            std::transform(pCurrBlock->mszName.begin(), pCurrBlock->mszName.end(), pCurrBlock->mszName.begin(), ::tolower);
		}
		else if (pStart < pEnd)
		{
			// It's a value
			if (pCurrBlock == NULL)
            {
				continue;
            }

			const char *pEquals = FindFirst(pStart, pEnd, '=');
			if (pEquals == pEnd)
			{
                // No value, just a key, save it anyway
				// Optimistically, we assume it's new
				cString &name = pCurrBlock->mpValues[pCurrBlock->mnValueCount].szName;
				AssignStr(name, pStart, pEnd, locale);

                bool dup = false;
                for(int ii=0;ii<pCurrBlock->mnValueCount;++ii)
                {
                    if(!pCurrBlock->mpValues[ii].szName.compare(name))
                    {
                        dup = true;
                        break;
                    }
                }
                if(!dup)
                {
                    pCurrBlock->mnValueCount++;
                }
			}
			else
			{
				const char *pNameStart = pStart;
				const char *pNameEnd = pEquals;
				const char *pValStart = pEquals + 1;
				const char *pValEnd = pEnd;

				RemoveWhitespace(pNameStart, pNameEnd);
				RemoveWhitespace(pValStart, pValEnd);

				// Optimistically assume the name is new
				cString &name = pCurrBlock->mpValues[pCurrBlock->mnValueCount].szName;
				AssignStr(name, pNameStart, pNameEnd, locale);
				std::transform(name.begin(), name.end(), name.begin(), ::tolower);

                bool dup = false;
                for(int ii=0;ii<pCurrBlock->mnValueCount;++ii)
                {
                    if(!pCurrBlock->mpValues[ii].szName.compare(name))
                    {
                        dup = true;
                        break;
                    }
                }
                if(!dup)
                {
                    AssignStr(pCurrBlock->mpValues[pCurrBlock->mnValueCount].szValue, pValStart, pValEnd, locale);
                    pCurrBlock->mnValueCount++;
                }
			}
		}
	}

	delete[] pFileContents;
    return CPUT_SUCCESS;
}