示例#1
0
//-----------------------------------------------------------------------------
EStatus BaseArray::SetLength (INT  iLengthIn)
  {
  INT    iNewAllocSize = iAllocSize;

  // calculate how much to grow the array.
  while (iLengthIn > iNewAllocSize)
    {
    iNewAllocSize += iAllocInc;
    };

  // if more memory is to be allocated, allocate it, copy over old values, and delete old memory.
  if (iNewAllocSize > iAllocSize)
    {
    VOID *  pNewArray = AllocArray (iNewAllocSize);

    // Note:  Ideally you need to detect an allocation failure here and return a failure code.
    if (pNewArray == NULL)  return (EStatus::kFailure);

    INT     iOldAllocSize = iAllocSize;
    VOID *  pOldArray     = pArray;

    pArray = pNewArray;
    iAllocSize = iNewAllocSize;

    if (iOldAllocSize > 0)
      {
      CopyValues (pOldArray, 0, 0, iOldAllocSize);
      DeleteArray (&pOldArray);
      };
    };
  iLength = iLengthIn;
  return (EStatus::kSuccess);
  };
示例#2
0
文件: afsreg.c 项目: bagdxk/openafs
/*
 * CopyKey() -- worker function implementing RegDupKeyAlt().
 *
 *     Note: - assumes target does not exist (i.e., deleted by RegDupKeyAlt())
 *           - no cleanup on failure (i.e., assumes done by RegDupKeyAlt())
 */
static long
CopyKey(const char *sourceKey, const char *targetKey)
{
    long status;
    HKEY srcKey, dupKey;

    /* open source key */
    status = RegOpenKeyAlt(AFSREG_NULL_KEY, sourceKey,
			   KEY_READ, 0, &srcKey, NULL);
    if (status == ERROR_SUCCESS) {
	/* create target key */
	status = RegOpenKeyAlt(AFSREG_NULL_KEY, targetKey,
			       KEY_ALL_ACCESS, 1 /* create */, &dupKey, NULL);
	if (status == ERROR_SUCCESS) {
	    /* copy values and their data from source to target */
	    status = CopyValues(srcKey, dupKey);

	    if (status == ERROR_SUCCESS) {
		/* copy subkeys from source to target */
		status = CopySubkeys(sourceKey, srcKey, targetKey, dupKey);
	    }
	    (void) RegCloseKey(dupKey);
	}
	(void) RegCloseKey(srcKey);
    }
    return status;
}
示例#3
0
//-----------------------------------------------------------------------------
EStatus  BaseArray::RemoveSequentialValues (INT  iStartIndex,
                                            INT  iNumToRemove)
  {
  // perform the removal on the actual sequential data
  if ((iStartIndex + iNumToRemove) > iLength) return (EStatus::kFailure);

  if ((iStartIndex + iNumToRemove) != iLength)
    {
    CopyValues (pArray, iStartIndex + iNumToRemove, iStartIndex, iLength - iStartIndex - iNumToRemove);
    };
  iLength -= iNumToRemove;
  return (EStatus::kSuccess);
  };
示例#4
0
bool RegistryUtils::CopyKey(const HKEY& hRootHive, const HKEY& hSourceKey, const CStdString& sTargetKey)
{
	HKEY hTargetKey = NULL;
	long lRet = RegCreateKeyEx(hRootHive, sTargetKey.c_str(), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hTargetKey, NULL);

	if (lRet == ERROR_SUCCESS)
	{
		CopyValues(hSourceKey, hTargetKey);
		RegCloseKey(hTargetKey);
		return true;
	}
	else
	{
		CStdString sErr;
		sErr.Format(_T("Failed to create target key %s, error %d"), sTargetKey.c_str(), lRet);
	}

	return false;
}
示例#5
0
BOOL CopyRegistryKey(HKEY hkRootFrom, const CString& strFromPath, HKEY hkRootTo, const CString& strToPath) 
{
	HKEY hkFrom;
	LONG res = ::RegOpenKeyEx(hkRootFrom, strFromPath, 0, KEY_READ, &hkFrom);
	if (ERROR_SUCCESS != res) {
		return FALSE;	
	}
	HKEY hkTo;
	res = ::RegCreateKeyEx(hkRootTo, strToPath, 0, 0, REG_OPTION_NON_VOLATILE, KEY_WRITE, 0, &hkTo, 0);
	if (ERROR_SUCCESS != res) {
		::RegCloseKey(hkFrom);
		return FALSE;	
	}
	BOOL bRes = CopyKeys(hkFrom, hkTo) && CopyValues(hkFrom, hkTo);

	::RegCloseKey(hkFrom);
	::RegCloseKey(hkTo);

	return bRes;
}
示例#6
0
// wrappers for ldap_modify_ext
//
nsresult
nsLDAPOperation::ModifyExt(const char *base,
                           nsIArray *mods,
                           LDAPControl **serverctrls,
                           LDAPControl **clientctrls)
{
  if (mMessageListener == 0) {
    NS_ERROR("nsLDAPOperation::ModifyExt(): mMessageListener not set");
    return NS_ERROR_NOT_INITIALIZED;
  }

  LDAPMod **attrs = 0;
  int retVal = 0;
  PRUint32 modCount = 0;
  nsresult rv = mods->GetLength(&modCount);
  NS_ENSURE_SUCCESS(rv, rv);
  if (modCount && mods) {
    attrs = static_cast<LDAPMod **>(nsMemory::Alloc((modCount + 1) *
                                                       sizeof(LDAPMod *)));
    if (!attrs) {
      NS_ERROR("nsLDAPOperation::ModifyExt: out of memory ");
      return NS_ERROR_OUT_OF_MEMORY;
    }

    nsCAutoString type;
    PRUint32 index;
    for (index = 0; index < modCount && NS_SUCCEEDED(rv); ++index) {
      attrs[index] = new LDAPMod();
      if (!attrs[index])
        return NS_ERROR_OUT_OF_MEMORY;

      nsCOMPtr<nsILDAPModification> modif(do_QueryElementAt(mods, index, &rv));
      if (NS_FAILED(rv))
        break;

      PRInt32 operation;
      nsresult rv = modif->GetOperation(&operation);
      if (NS_FAILED(rv))
        break;

      attrs[index]->mod_op = operation | LDAP_MOD_BVALUES;

      rv = modif->GetType(type);
      if (NS_FAILED(rv))
        break;

      attrs[index]->mod_type = ToNewCString(type);

      rv = CopyValues(modif, &attrs[index]->mod_bvalues);
      if (NS_FAILED(rv))
        break;
    }

    if (NS_SUCCEEDED(rv)) {
      attrs[modCount] = 0;

      retVal = ldap_modify_ext(mConnectionHandle, base, attrs,
                               serverctrls, clientctrls, &mMsgID);
    }
    else
      // reset the modCount so we correctly free the array.
      modCount = index;

  }

  for (PRUint32 counter = 0; counter < modCount; ++counter)
    delete attrs[counter];

  nsMemory::Free(attrs);

  return NS_FAILED(rv) ? rv : TranslateLDAPErrorToNSError(retVal);
}
示例#7
0
int main( int argc ATTR_UNUSED, char **argv )
{
	DSpec dspec;
	ValArr va;
	char *ci, *disp, *dcls, *cfgfile;
	int what;

	if (!(ci = getenv( "CONINFO" ))) {
		fprintf( stderr, "This program is part of kdm and should not be run manually.\n" );
		return 1;
	}
	if (sscanf( ci, "%d %d", &rfd, &wfd ) != 2)
		return 1;

	InitLog();

	if ((debugLevel = GRecvInt()) & DEBUG_WCONFIG)
		sleep( 100 );

/*	Debug ("parsing command line\n");*/
	if (**++argv)
		kdmrc = *argv;
/*
	while (*++argv) {
	}
*/

	for (;;) {
/*		Debug ("Awaiting command ...\n");*/
		if (!GRecvCmd( &what ))
			break;
		switch (what) {
		case GC_Files:
/*			Debug ("GC_Files\n");*/
			ReadConf();
			CopyValues( 0, &secGeneral, 0, C_CONFIG );
#ifdef XDMCP
			CopyValues( 0, &secXdmcp, 0, C_CONFIG );
			GSendInt( 2 );
#else
			GSendInt( 1 );
#endif
			GSendStr( kdmrc );
				GSendInt( -1 );
#ifdef XDMCP
			GSendNStr( VXaccess.ptr, VXaccess.len - 1 );
				GSendInt( 0 );
#endif
			for (; (what = GRecvInt()) != -1; )
				switch (what) {
				case GC_gGlobal:
				case GC_gDisplay:
					GSendInt( 0 );
					break;
#ifdef XDMCP
				case GC_gXaccess:
					GSendInt( 1 );
					break;
#endif
				default:
					GSendInt( -1 );
					break;
				}
			break;
		case GC_GetConf:
/*		Debug( "GC_GetConf\n" );*/
			memset( &va, 0, sizeof(va) );
			what = GRecvInt();
			cfgfile = GRecvStr();
			switch (what) {
			case GC_gGlobal:
/*		Debug( "GC_gGlobal\n" );*/
				Debug( "getting global config\n" );
				ReadConf();
				CopyValues( &va, &secGeneral, 0, 0 );
#ifdef XDMCP
				CopyValues( &va, &secXdmcp, 0, 0 );
#endif
				CopyValues( &va, &secShutdown, 0, 0 );
				SendValues( &va );
				break;
			case GC_gDisplay:
/*		Debug( "GC_gDisplay\n" );*/
				disp = GRecvStr();
/*		Debug( " Display %s\n", disp );*/
				dcls = GRecvStr();
/*		Debug( " Class %s\n", dcls );*/
				Debug( "getting config for display %s, class %s\n", disp, dcls );
				MkDSpec( &dspec, disp, dcls ? dcls : "" );
				ReadConf();
				CopyValues( &va, &sec_Core, &dspec, 0 );
				CopyValues( &va, &sec_Greeter, &dspec, 0 );
				free( disp );
				if (dcls)
					free( dcls );
				SendValues( &va );
				break;
#ifdef XDMCP
			case GC_gXaccess:
				ReadAccessFile( cfgfile );
				break;
#endif
			default:
				Debug( "Unsupported config category %#x\n", what );
			}
			free( cfgfile );
			break;
		default:
			Debug( "Unknown config command %#x\n", what );
		}
	}

/*	Debug( "Config reader exiting ..." );*/
	return EX_NORMAL;
}
示例#8
0
void CValueListLayers::InsertValue(int nIndex,CValue Val,CString Str,int nCount)
{
	CValueList::InsertValue(nIndex,Val,Str,nCount);
	CopyValues();
}
示例#9
0
int CValueListLayers::Set(CString Str,CValue Val)
{
	int nRes=CValueList::Set(Str,Val);
	CopyValues();
	return nRes;
}
示例#10
0
void CValueListLayers::RemoveAll(void)
{
	CValueList::RemoveAll();
	CopyValues();
}
示例#11
0
void CValueListLayers::Sort(int nDirect)
{
	CValueList::Sort(nDirect);
	CopyValues();
}
示例#12
0
void CValueListLayers::FromSeparatedString(CString Str)
{
	CValueList::FromSeparatedString(Str);
	CopyValues();
}
示例#13
0
void CValueListLayers::RemoveValue(int nIndex, int nCount)
{
	CValueList::RemoveValue(nIndex,nCount);
	CopyValues();
}
示例#14
0
void CValueListLayers::MoveValue(int nCount,int nIndex)
{
	CValueList::MoveValue(nCount,nIndex);
	CopyValues();
}
示例#15
0
void CValueListLayers::SetSize(int nSize)
{
	CValueList::SetSize(nSize);
	CopyValues();
}
示例#16
0
void CValueListLayers::AddValue(CValue Val,CString Str)
{
	CValueList::AddValue(Val,Str);
	CopyValues();
}