static int server_create(
    IN const struct server_info *info,
    OUT nfs41_server **server_out)
{
    int status = NO_ERROR;
    nfs41_server *server;

    server = calloc(1, sizeof(nfs41_server));
    if (server == NULL) {
        status = GetLastError();
        eprintf("failed to allocate server %s\n", info->owner);
        goto out;
    }

    StringCchCopyA(server->scope, NFS4_OPAQUE_LIMIT, info->scope);
    StringCchCopyA(server->owner, NFS4_OPAQUE_LIMIT, info->owner);
    InitializeSRWLock(&server->addrs.lock);
    nfs41_superblock_list_init(&server->superblocks);

    status = nfs41_name_cache_create(&server->name_cache);
    if (status) {
        eprintf("nfs41_name_cache_create() failed with %d\n", status);
        goto out_free;
    }
out:
    *server_out = server;
    return status;

out_free:
    free(server);
    server = NULL;
    goto out;
}
Exemple #2
0
/*++

Io_GroupRename

    Renames an existing group.

Arguments:
    memory      - Pointer to an IO_MEMORY structure allocated by Io_ShmAlloc. The
                  buffer size must be large enough to hold the DC_RENAME structure.

    groupName   - Pointer to a null-terminated string that specifies an
                  existing group name.

    newName     - Pointer to a null-terminated string that specifies the new
                  name for the group.

Return Values:
    If the function succeeds, the return value is nonzero (true).

    If the function fails, the return value is zero (false). To get extended
    error information, call GetLastError.

--*/
BOOL
STDCALL
Io_GroupRename(
    IO_MEMORY *memory,
    const char *groupName,
    const char *newName
    )
{
    DC_RENAME *dcRename;

    // Validate arguments.
    if (memory == NULL || groupName == NULL || newName == NULL) {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    // Check if the shared memory block is large enough.
    if (memory->size < sizeof(DC_RENAME)) {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return FALSE;
    }

    // Initialise the DC_RENAME structure.
    dcRename = (DC_RENAME *)memory->block;
    StringCchCopyA(dcRename->tszName,    ARRAYSIZE(dcRename->tszName),    groupName);
    StringCchCopyA(dcRename->tszNewName, ARRAYSIZE(dcRename->tszNewName), newName);

    if (!Io_ShmQuery(memory, DC_RENAME_GROUP, 5000)) {
        return TRUE;
    }

    SetLastError(ERROR_INVALID_GROUPNAME);
    return FALSE;
}
static void server_addrs_add(
    IN OUT struct server_addrs *addrs,
    IN const netaddr4 *addr)
{
    /* we keep a list of addrs used to connect to each server. once it gets
     * bigger than NFS41_ADDRS_PER_SERVER, overwrite the oldest addrs. use
     * server_addrs.next_index to implement a circular array */

    AcquireSRWLockExclusive(&addrs->lock);

    if (multi_addr_find(&addrs->addrs, addr, NULL)) {
        dprintf(SRVLVL, "server_addrs_add() found existing addr '%s'.\n",
            addr->uaddr);
    } else {
        /* overwrite the address at 'next_index' */
        StringCchCopyA(addrs->addrs.arr[addrs->next_index].netid,
            NFS41_NETWORK_ID_LEN+1, addr->netid);
        StringCchCopyA(addrs->addrs.arr[addrs->next_index].uaddr,
            NFS41_UNIVERSAL_ADDR_LEN+1, addr->uaddr);

        /* increment/wrap next_index */
        addrs->next_index = (addrs->next_index + 1) % NFS41_ADDRS_PER_SERVER;
        /* update addrs.count if necessary */
        if (addrs->addrs.count < addrs->next_index)
            addrs->addrs.count = addrs->next_index;

        dprintf(SRVLVL, "server_addrs_add() added new addr '%s'.\n",
            addr->uaddr);
    }
    ReleaseSRWLockExclusive(&addrs->lock);
}
SystemTrayService::Handle SystemTrayServiceWindows::AddIcon(const RF_Draw::TrayIcon& Settings)
{
    // early exit if there are too many icons registered
    if(m_PImpl->m_IconData.Count() > MAX_WM_APP - WM_APP)
        return 0;

    RF_Mem::AutoPointer<NOTIFYICONDATA> notifyData(new NOTIFYICONDATA);

    RF_SysMem::Set(notifyData.Get(), 0, sizeof(NOTIFYICONDATA));
    notifyData->cbSize = sizeof(NOTIFYICONDATA);
    notifyData->hWnd = m_PImpl->m_HWND;
    notifyData->uVersion = NOTIFYICON_VERSION_4;
    notifyData->uFlags = NIF_GUID | NIF_MESSAGE;
    notifyData->uCallbackMessage = WM_APP + m_PImpl->m_IconData.Count();
    CoCreateGuid(&notifyData->guidItem);

    if(!Settings.Notification.IsEmpty())
    {
        notifyData->uFlags |= NIF_INFO | NIF_SHOWTIP;
        StringCchCopyA(notifyData->szInfo, ARRAYSIZE(notifyData->szInfo), Settings.Notification.c_str());
    }

    if(!Settings.Tooltip.IsEmpty())
    {
        notifyData->uFlags |= NIF_TIP;
        StringCchCopyA(notifyData->szTip, ARRAYSIZE(notifyData->szTip), Settings.Tooltip.c_str());
    }

    RF_IO::File icon;
    icon.SetLocation(Settings.Icon);
    if(icon.Exists())
    {
        RF_Type::String systemPath = Settings.Icon.GetComponents(RF_IO::UriComponents::Path);        
        int min = GetSystemMetrics(SM_CXSMICON);
        notifyData->hIcon = (HICON)LoadImage(NULL, systemPath.c_str(), IMAGE_ICON, 
                                             min, min, LR_LOADFROMFILE);
        if(notifyData->hIcon != 0)
        {
            notifyData->uFlags |= NIF_ICON;
        }
    }

    Handle handle = 0;
    SystemTrayService::Handle result = Shell_NotifyIcon(NIM_ADD, notifyData.Get());
    if(result)
    {
        handle = reinterpret_cast<Handle>(notifyData.Get());
        
        m_PImpl->m_IconData.Resize(m_PImpl->m_IconData.Count() + 1);
        auto& item = m_PImpl->m_IconData(m_PImpl->m_IconData.Count() - 1);
        m_PImpl->m_MessageLookup[notifyData->uCallbackMessage] = &item;
        m_PImpl->m_HandleLookup[handle] = &item;
        
        item.m_MenuHandle = m_PImpl->AddPopupMenu(Settings);
        item.m_NotificationData = notifyData;
    }

    return handle;
}
Exemple #5
0
static void user_cache_copy(
    struct list_entry *lhs,
    const struct list_entry *rhs)
{
    struct idmap_user *dst = list_container(lhs, struct idmap_user, entry);
    const struct idmap_user *src = list_container(rhs, const struct idmap_user, entry);
    StringCchCopyA(dst->username, VAL_LEN, src->username);
    StringCchCopyA(dst->principal, VAL_LEN, src->principal);
    dst->uid = src->uid;
    dst->gid = src->gid;
    dst->last_updated = src->last_updated;
}
//------------------------------------------------------------------------------
// Function: fillTypeAndModuleName
//
// Description:
//
//  Utility to fetch and populate the type and module names of a typed object.
//
// Parameters:
//
// Returns:
//
//  HRESULT.
//
// Notes:
//
static _Check_return_ HRESULT
fillTypeAndModuleName(
	_In_ DbgScriptHostContext* hostCtxt,
	_In_ ULONG typeId,
	_In_ UINT64 moduleBase,
	_Out_ DbgScriptTypedObject* typObj)
{
	HRESULT hr = S_OK;
	const char* cachedTypeName = nullptr;
	const char* cachedModName = nullptr;

	// Get type name.
	//
	const ModuleAndTypeId modAndTypeId = { typeId, moduleBase };
	cachedTypeName = GetCachedTypeName(
		hostCtxt,
		modAndTypeId);
	if (!cachedTypeName)
	{
		hr = E_FAIL;
		hostCtxt->DebugControl->Output(
			DEBUG_OUTPUT_ERROR,
			ERR_FAILED_GET_TYPE_NAME);
		
		goto exit;
	}
	hr = StringCchCopyA(STRING_AND_CCH(typObj->TypeName), cachedTypeName);
	assert(SUCCEEDED(hr));
	
	// Get module name.
	//
	cachedModName = GetCachedModuleName(
		hostCtxt,
		moduleBase);
	if (!cachedModName)
	{
		hr = E_FAIL;
		hostCtxt->DebugControl->Output(
			DEBUG_OUTPUT_ERROR,
			ERR_FAILED_GET_MODULE_NAME);
		
		goto exit;
	}

	hr = StringCchCopyA(STRING_AND_CCH(typObj->ModuleName), cachedModName);
	assert(SUCCEEDED(hr));
	
exit:
	return hr;
}
Exemple #7
0
int nfs41_idmap_uid_to_name(
    struct idmap_context *context,
    uid_t uid,
    char *name,
    size_t len)
{
    UINT_PTR uidp = uid; /* convert to pointer size to pass as void* */
    struct idmap_lookup lookup = { ATTR_UID, CLASS_USER, TYPE_INT, uid_cmp };
    struct idmap_user user;
    int status;

    dprintf(IDLVL, "--> nfs41_idmap_uid_to_name(%u)\n", uid);

    lookup.value = (const void*)uidp;

    /* look up the user entry */
    status = idmap_lookup_user(context, &lookup, &user);
    if (status) {
        dprintf(IDLVL, "<-- nfs41_idmap_uid_to_name(%u) "
            "failed with %d\n", uid, status);
        goto out;
    }

    if (FAILED(StringCchCopyA(name, len, user.username))) {
        status = ERROR_BUFFER_OVERFLOW;
        eprintf("username buffer overflow: '%s' > %u\n",
            user.username, len);
        goto out;
    }

    dprintf(IDLVL, "<-- nfs41_idmap_uid_to_name(%u) "
        "returning '%s'\n", uid, name);
out:
    return status;
}
Exemple #8
0
/* parse default values from g_options[] into idmap_config */
static int config_defaults(
    struct idmap_config *config)
{
    const struct config_option *option;
    const int count = ARRAYSIZE(g_options);
    char *dst;
    int i, status = NO_ERROR;

    for (i = 0; i < count; i++) {
        option = &g_options[i];
        dst = (char*)config + option->offset;

        if (option->type == TYPE_INT) {
            if (!parse_uint(option->def, (UINT*)dst)) {
                status = ERROR_INVALID_PARAMETER;
                eprintf("failed to parse default value of %s=\"%s\": "
                    "expected a number\n", option->key, option->def);
                break;
            }
        } else {
            if (FAILED(StringCchCopyA(dst, option->max_len, option->def))) {
                status = ERROR_BUFFER_OVERFLOW;
                eprintf("failed to parse default value of %s=\"%s\": "
                    "buffer overflow > %u\n", option->key, option->def,
                    option->max_len);
                break;
            }
        }
    }
    return status;
}
Exemple #9
0
int nfs41_idmap_gid_to_group(
    struct idmap_context *context,
    gid_t gid,
    char *name,
    size_t len)
{
    UINT_PTR gidp = gid; /* convert to pointer size to pass as void* */
    struct idmap_lookup lookup = { ATTR_GID, CLASS_GROUP, TYPE_INT, gid_cmp };
    struct idmap_group group;
    int status;

    dprintf(IDLVL, "--> nfs41_idmap_gid_to_group(%u)\n", gid);

    lookup.value = (const void*)gidp;

    /* look up the group entry */
    status = idmap_lookup_group(context, &lookup, &group);
    if (status) {
        dprintf(IDLVL, "<-- nfs41_idmap_gid_to_group(%u) "
            "failed with %d\n", gid, status);
        goto out;
    }

    if (FAILED(StringCchCopyA(name, len, group.name))) {
        status = ERROR_BUFFER_OVERFLOW;
        eprintf("group name buffer overflow: '%s' > %u\n",
            group.name, len);
        goto out;
    }

    dprintf(IDLVL, "<-- nfs41_idmap_gid_to_group(%u) "
        "returning '%s'\n", gid, name);
out:
    return status;
}
Exemple #10
0
VOID
MspWriteLogEntry(
	IN ULONG ProcessId,
	IN MSP_LOG_LEVEL Level,
	IN PSTR Format,
	...
	)
{
	ULONG IsLogging;
	va_list Argument;
	PMSP_LOG_ENTRY Entry;
	CHAR Buffer[MSP_LOG_TEXT_LIMIT];

	IsLogging = InterlockedCompareExchange(&MspLogObject.Flag, 0, 0);
	if (!IsLogging) {
		return;
	}

	va_start(Argument, Format);
	StringCchVPrintfA(Buffer, MAX_PATH, Format, Argument);
	va_end(Argument);

	Entry = (PMSP_LOG_ENTRY)MspMalloc(sizeof(MSP_LOG_ENTRY));
	Entry->ProcessId = ProcessId;

	GetLocalTime(&Entry->TimeStamp);
	StringCchCopyA(Entry->Text, MSP_LOG_TEXT_LIMIT, Buffer);

	EnterCriticalSection(&MspLogObject.Lock);
	InsertTailList(&MspLogObject.ListHead, &Entry->ListEntry);
	MspLogObject.ListDepth += 1;
	LeaveCriticalSection(&MspLogObject.Lock);

	return;
}
Exemple #11
0
std::vector<std::string> *listFilesDir(const char* dir) {
    WIN32_FIND_DATAA ffd;
	HANDLE hFind = INVALID_HANDLE_VALUE;
	char szDir[MAX_PATH];
    int arg_length;
	std::vector<std::string> *files_dir = new std::vector<std::string>();
    
    arg_length= (int)strlen(dir);

    if (arg_length > (MAX_PATH - 3))
        return files_dir;

    StringCchCopyA(szDir, MAX_PATH, dir);
    StringCchCatA(szDir, MAX_PATH, "\\*");

    hFind = FindFirstFileA(szDir, &ffd);

    if (INVALID_HANDLE_VALUE == hFind)
        return files_dir;
        
    do {
         files_dir->push_back(ffd.cFileName);
    } while (FindNextFileA(hFind, &ffd) != 0);
    
    FindClose(hFind);
    return files_dir;
}
Exemple #12
0
HRESULT __stdcall BtrfsContextMenu::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT* pwReserved, LPSTR pszName, UINT cchMax) {
    if (ignore)
        return E_INVALIDARG;
    
    if (idCmd != 0)
        return E_INVALIDARG;
    
    switch (uFlags) {
        case GCS_HELPTEXTA:
            if (LoadStringA(module, bg ? IDS_NEW_SUBVOL_HELP_TEXT : IDS_CREATE_SNAPSHOT_HELP_TEXT, pszName, cchMax))
                return S_OK;
            else
                return E_FAIL;
            
        case GCS_HELPTEXTW:
            if (LoadStringW(module, bg ? IDS_NEW_SUBVOL_HELP_TEXT : IDS_CREATE_SNAPSHOT_HELP_TEXT, (LPWSTR)pszName, cchMax))
                return S_OK;
            else
                return E_FAIL;
            
        case GCS_VALIDATEA:
        case GCS_VALIDATEW:
            return S_OK;
            
        case GCS_VERBA:
            return StringCchCopyA(pszName, cchMax, bg ? NEW_SUBVOL_VERBA : SNAPSHOT_VERBA);
            
        case GCS_VERBW:
            return StringCchCopyW((STRSAFE_LPWSTR)pszName, cchMax, bg ? NEW_SUBVOL_VERBW : SNAPSHOT_VERBW);
            
        default:
            return E_INVALIDARG;
    }
}
Exemple #13
0
/*!
	AAテキストを確保して取り込む
	@param[in]	hWnd	ウインドウハンドル
	@param[in]	pcArts	AAテキストSJIS
	@return		追加後のアイテム総数
*/
UINT DraughtItemAdding( HWND hWnd, LPSTR pcArts )
{
	UINT_PTR	cbSize;
	AAMATRIX	stItem;

	INT_PTR	iItems;


	StringCchLengthA( pcArts, STRSAFE_MAX_CCH, &cbSize );

	stItem.cbItem = cbSize;
	stItem.pcItem = (LPSTR)malloc( (cbSize + 1) );
	ZeroMemory( stItem.pcItem, (cbSize + 1) );
	StringCchCopyA( stItem.pcItem, (cbSize + 1), pcArts );


	DraughtAaImageing( hWnd, &stItem );


	gvcDrtItems.push_back( stItem );

	do	//	はみだしてたら?
	{
		iItems = gvcDrtItems.size( );
		if( (TPNL_HORIZ * TPNL_VERTI) < iItems ){	DraughtItemDelete(  0 );	}

	}while( (TPNL_HORIZ * TPNL_VERTI) < iItems );

	return iItems;
}
_Check_return_ HRESULT
DsWrapTypedData(
	_In_ DbgScriptHostContext* hostCtxt,
	_In_z_ const char* name,
	_In_ const DEBUG_TYPED_DATA* typedData,
	_Out_ DbgScriptTypedObject* typObj)
{
	HRESULT hr = StringCchCopyA(STRING_AND_CCH(typObj->Name), name);
	assert(SUCCEEDED(hr));

	typObj->TypedData = *typedData;
	typObj->TypedDataValid = true;

	hr = fillTypeAndModuleName(
		hostCtxt,
		typObj->TypedData.TypeId,
		typObj->TypedData.ModBase,
		typObj);
	if (FAILED(hr))
	{
		goto exit;
	}
exit:
	return hr;
}
ULONG __cdecl
DbgPrintEntry(
    __in PCHAR Format,
	...
	)
{
	PDBG_OUTPUTA Filter;
	PBTR_FILTER_RECORD Record;
	BTR_PROBE_CONTEXT Context;
	DBGPRINT Routine;
	size_t Length;
	ULONG UserLength;
	va_list arg;
	PULONG_PTR Sp;
	ULONG Result;
	char format[512];
	char buffer[512];
	
	BtrFltGetContext(&Context);
	Routine = Context.Destine;

	//
	// N.B. Maximum support 16 arguments
	//

	Sp = (PULONG_PTR)&Format + 1;
	Result = (*Routine)(Format, Sp[0], Sp[1], Sp[2], Sp[3], Sp[4],
			   Sp[5], Sp[6], Sp[7], Sp[8], Sp[9], 
			   Sp[10], Sp[11], Sp[12], Sp[13], Sp[14]);

	BtrFltSetContext(&Context);

	__try {

		va_start(arg, Format);
		StringCchVPrintfA(format, 512, Format, arg);
		StringCchPrintfA(buffer, 512, "%s", format);
		Length = strlen(buffer) + 1;
		va_end(arg);

		UserLength = FIELD_OFFSET(DBG_OUTPUTA, Text[Length]);
		Record = BtrFltAllocateRecord(UserLength, DbgUuid, _DbgPrint);
		if (!Record) {
			return Result;
		}

		Filter = FILTER_RECORD_POINTER(Record, DBG_OUTPUTA);
		Filter->Length = Length;
		StringCchCopyA(Filter->Text, Length, buffer);

		BtrFltQueueRecord(Record);
	}
	__except (EXCEPTION_EXECUTE_HANDLER) {
		if (Record) {
			BtrFltFreeRecord(Record);
		}		
	}

	return Result;
}
char*
OxMarkDownToHtml(char* sMarkDown)
{
	hoedown_renderer *renderer;
	hoedown_document *document;
	hoedown_buffer *buffer;
	unsigned int extensions = 0, render_flags = 0;
	const uint8_t *sHtml;

	renderer = hoedown_html_renderer_new(render_flags, 0);
	document = hoedown_document_new(renderer, extensions, 16);
	buffer = hoedown_buffer_new(16);
    
	hoedown_document_render(document, buffer, (const uint8_t *)sMarkDown, strlen(sMarkDown));
	sHtml = (char*)OxAllocate(buffer->size + 1);
	StringCchCopyA(sHtml, buffer->size + 1, buffer->data);
	hoedown_buffer_reset(buffer);
	hoedown_html_smartypants(buffer, sHtml, buffer->size);
	
	hoedown_buffer_free(buffer);
	hoedown_document_free(document);
	hoedown_html_renderer_free(renderer);

	return sHtml;
}
Exemple #17
0
/*++

Io_GroupIdToName

    Resolves a group ID to its corresponding group name.

Arguments:
    memory      - Pointer to an IO_MEMORY structure allocated by Io_ShmAlloc.
                  The buffer size must be large enough to hold the DC_NAMEID
                  structure.

    groupId     - Specifies the group ID to resolve.

    groupName   - Pointer to the buffer that receives the group's name. The
                  buffer must be able to hold "_MAX_NAME+1" characters.

Return Values:
    If the function succeeds, the return value is nonzero (true).

    If the function fails, the return value is zero (false). To get extended
    error information, call GetLastError.

--*/
BOOL
STDCALL
Io_GroupIdToName(
    IO_MEMORY *memory,
    int groupId,
    char *groupName
    )
{
    DC_NAMEID *dcNameId;

    // Validate arguments.
    if (memory == NULL || groupName == NULL) {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    // Check if the shared memory block is large enough.
    if (memory->size < sizeof(DC_NAMEID)) {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return FALSE;
    }

    // Initialise the DC_NAMEID structure.
    dcNameId = (DC_NAMEID *)memory->block;
    dcNameId->Id = groupId;

    if (!Io_ShmQuery(memory, DC_GID_TO_GROUP, 5000)) {
        StringCchCopyA(groupName, _MAX_NAME+1, dcNameId->tszName);
        return TRUE;
    }

    groupName[0] = '\0';
    SetLastError(ERROR_NO_SUCH_GROUP);
    return FALSE;
}
Exemple #18
0
/*
 * TclSetWinError
 *
 *   Sets the interpreter's errorCode variable.
 *
 * Arguments:
 *   interp    - Current interpreter.
 *   errorCode - Windows error code.
 *
 * Returns:
 *   The message that is associated with the error code.
 */
char *
TclSetWinError(
    Tcl_Interp *interp,
    DWORD errorCode
    )
{
    char errorId[12];
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    StringCchPrintfA(errorId, ARRAYSIZE(errorId), "%lu", errorCode);

    if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        errorCode,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        tsdPtr->message,
        ARRAYSIZE(tsdPtr->message),
        NULL) == 0) {
        StringCchCopyA(tsdPtr->message, ARRAYSIZE(tsdPtr->message), "unknown error");
    } else {
        size_t length;
        StringCchLengthA(tsdPtr->message, ARRAYSIZE(tsdPtr->message), &length);

        /* Remove trailing CR/LF. */
        if (length >= 2 && tsdPtr->message[length-2] == '\r' && tsdPtr->message[length-1] == '\n') {
            tsdPtr->message[length-2] = '\0';
        }
    }

    Tcl_SetErrorCode(interp, "WINDOWS", errorId, tsdPtr->message, NULL);
    return tsdPtr->message;
}
Exemple #19
0
ULONG
BtrCopyCodeViewRecord(
	__in PVOID Base,
	__out PCV_INFO_PDB70 CvRecord,
	__out PULONG NameLength
	)
{
	PIMAGE_NT_HEADERS NtHeader;
	PIMAGE_DATA_DIRECTORY Directory;
	PIMAGE_DEBUG_DIRECTORY Debug;
	ULONG Count;
	PCV_INFO_PDB70 Info;
	ULONG i;

	NtHeader = ImageNtHeader(Base);
	Directory = &NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
	Debug = (PIMAGE_DEBUG_DIRECTORY)PtrFromRva(Base, Directory->VirtualAddress);
	
	Count = Directory->Size / sizeof(IMAGE_DEBUG_DIRECTORY);

	for (i = 0; i < Count; i += 1) {
		if (Debug[i].Type == IMAGE_DEBUG_TYPE_CODEVIEW) {
			Info = (PCV_INFO_PDB70)PtrFromRva(Base, Debug[i].AddressOfRawData);
			CvRecord->CvSignature = Info->CvSignature;
			CvRecord->Signature = Info->Signature;
			CvRecord->Age = Info->Age;
			StringCchCopyA(CvRecord->PdbName, MAX_PATH, Info->PdbName);
			*NameLength = (ULONG)strlen(Info->PdbName) + 1;
			return S_OK;
		}
	}

	return S_FALSE;
}
Exemple #20
0
VOID GetAnswerToRequest( LPSTR pchRequest, 
						LPSTR pchReply, 
						LPDWORD pchBytes )
						// This routine is a simple function to print the client request to the console
						// and populate the reply buffer with a default data string. This is where you
						// would put the actual client request processing code that runs in the context
						// of an instance thread. Keep in mind the main thread will continue to wait for
						// and receive other client connections while the instance thread is working.
{
	printf("Client Request String:\"%s\"\n", pchRequest);

	DWORD dwError;
	HANDLE hFile = getDeviceHandleInternal(pchRequest, &dwError);
	printf("Driver Handle: 0x%08p\n", hFile);
	if (hFile)
	{
		char buf[BUFSIZE];
		sprintf_s(buf, BUFSIZE, "%p,%d", hFile, dwError);
		strcpy_s(pchReply, BUFSIZE, buf);
		*pchBytes = (DWORD) strlen(buf) * sizeof(char);
	}
	else
	{
		// Check the outgoing message to make sure it's not too long for the buffer.
		if (FAILED(StringCchCopyA( pchReply, BUFSIZE, "default answer from server")))
		{
			*pchBytes = 0;
			pchReply[0] = 0;
			printf("StringCchCopy failed, no outgoing message.\n");
			return;
		}
		*pchBytes = (DWORD) (strlen(pchReply) + 1) * sizeof(char);
	}
}
Exemple #21
0
VOID
ApsGetLogFilePath(
	__out PCHAR Buffer,
	__in ULONG Length
	)
{
	StringCchCopyA(Buffer, Length, ApsLogObject.Path);
}
Exemple #22
0
VOID
MspGetLogFilePath(
	OUT PCHAR Buffer,
	IN ULONG Length
	)
{
	StringCchCopyA(Buffer, Length, MspLogObject.Path);
}
//-----------------------------------------------------------------------------
// Name: HeapCopy()
// Desc: Allocate buffer in memory and copy the content of sName to the
//       buffer, then return the address of the buffer.
//-----------------------------------------------------------------------------
CHAR* HeapCopy( CHAR *sName )
{
    DWORD dwLen = (DWORD) strlen( sName ) + 1;
    CHAR * sNewName = new CHAR[ dwLen ];
    if( sNewName )
        StringCchCopyA( sNewName, dwLen, sName );
    return sNewName;
}
bool
ihiMapAssign(
    PIHI_MAP    *ioMap,
    LPCSTR  inKey,
    LPVOID      inValue)
/*++

Routine Description:

    This routine creates a new MAP entry and inserts it into the existing
    map supplied in ioMap. We pass the address of the MAP head such that
    when we insert the first item, we modify the head itself to point to it.

Returns:

    false - if memory allocation for new map failed
    true - in all other cases

--*/
{
    //IHU_DBG_ASSERT(ioMap);

    IHI_MAP *tempMap = new IHI_MAP;

    if (tempMap == NULL)
    {
        return false;
    }

    memset(tempMap, 0, sizeof(IHI_MAP));

    StringCchCopyA(
                tempMap->Key,
                MAX_PATH,
                inKey);

    tempMap->Value = inValue;

    tempMap->Next = NULL;

    if (*ioMap)
    {
        PIHI_MAP pCurrent = *ioMap;

        while(pCurrent->Next)
        {
            pCurrent = pCurrent->Next;
        }

        pCurrent->Next  = tempMap;
    }
    else
    {
        *ioMap = tempMap;
    }

    return true;
}
Exemple #25
0
/********************************************************************
 WcaLog() - outputs trace and log info

*******************************************************************/
extern "C" void __cdecl WcaLog(
    __in LOGLEVEL llv,
    __in_z __format_string PCSTR fmt, 
    ...
    )
{
    static char szFmt[LOG_BUFFER];
    static char szBuf[LOG_BUFFER];
    static bool fInLogPrint = false;

    // prevent re-entrant logprints.  (recursion issues between assert/logging code)
    if (fInLogPrint)
        return;
    fInLogPrint = true;

    if (LOGMSG_STANDARD == llv || 
        (LOGMSG_VERBOSE == llv && IsVerboseLoggingLite())
#ifdef DEBUG
        || LOGMSG_TRACEONLY == llv
#endif
        )
    {
        va_list args;
        va_start(args, fmt);

        LPCSTR szLogName = WcaGetLogName();
        if (szLogName[0] != 0)
            StringCchPrintfA(szFmt, countof(szFmt), "%s:  %s", szLogName, fmt);
        else
            StringCchCopyA(szFmt, countof(szFmt), fmt);

        StringCchVPrintfA(szBuf, countof(szBuf), szFmt, args);
        va_end(args);

#ifdef DEBUG
        // always write to the log in debug
#else
        if (llv == LOGMSG_STANDARD || (llv == LOGMSG_VERBOSE && IsVerboseLoggingLite()))
#endif
        {
            PMSIHANDLE hrec = MsiCreateRecord(1);

            ::MsiRecordSetStringA(hrec, 0, szBuf);
            // TODO:  Recursion on failure.  May not be safe to assert from here.
            WcaProcessMessage(INSTALLMESSAGE_INFO, hrec);
        }

#if DEBUG
        StringCchCatA(szBuf, countof(szBuf), "\n");
        OutputDebugStringA(szBuf);
#endif
    }

    fInLogPrint = false;
    return;
}
Exemple #26
0
static void group_cache_copy(
    struct list_entry *lhs,
    const struct list_entry *rhs)
{
    struct idmap_group *dst = list_container(lhs, struct idmap_group, entry);
    const struct idmap_group *src = list_container(rhs, const struct idmap_group, entry);
    StringCchCopyA(dst->name, VAL_LEN, src->name);
    dst->gid = src->gid;
    dst->last_updated = src->last_updated;
}
char* lstrdup(const char* asText)
{
	int nLen = asText ? lstrlenA(asText) : 0;
	char* psz = (char*)malloc(nLen+1);

	if (nLen)
		StringCchCopyA(psz, nLen+1, asText);
	else
		psz[0] = 0;

	return psz;
}
void Trace(LPSTR format, ...)
    {
    char message[256];
    va_list args = NULL;
    va_start(args, format);
    StringCchVPrintfA(message, 256, format, args);

    char buffer[256];
    StringCchCopyA(buffer, 256, "ode: ");
    StringCchCatA(buffer, 256, message);
    OutputDebugStringA(buffer);
    }
int PDPC_WindowPanel::AddProperty(bool editable,char *name,char* type,char* value){
	int length;
	if(m_properitesNum>=m_allocatedMem)
		AllocatePropertySet(m_allocatedMem*2);
	PropertyDesc*desc=(PropertyDesc*) malloc (sizeof(PropertyDesc));
	m_content[m_properitesNum]=desc;
	m_content[m_properitesNum]->m_editable=editable;
	length=min(PROPETY_NAME_MAX_L-1,strlen(name)+1);
	StringCchCopyA(m_content[m_properitesNum]->m_name,length,name);
	m_content[m_properitesNum]->m_name[PROPETY_NAME_MAX_L-1]='\0';

	length=min(PROPETY_TYPE_MAX_L-1,strlen(type)+1);
	StringCchCopyA(m_content[m_properitesNum]->m_type,length,type);
	m_content[m_properitesNum]->m_type[PROPETY_TYPE_MAX_L-1]='\0';

	length=min(PROPETY_VALUE_MAX_L-1,strlen(value)+1);
	StringCchCopyA(m_content[m_properitesNum]->m_value,length,value);
	m_content[m_properitesNum]->m_value[PROPETY_VALUE_MAX_L-1]='\0';
	m_properitesNum++;
	return 0;
}
static HKEY GetKeyA(LPCSTR appname, BOOL * closekey, BOOL fCreate)
{
    HKEY key = 0;
    char achName[MAX_PATH];
	HRESULT hr;
#if !MMPROFILECACHE
    *closekey = TRUE;
#else
    UINT n;
    ATOM atm;

    *closekey = FALSE;
    //
    // See if we have already used this key
    //
    atm = FindAtomA(appname);

    if (atm != 0) {
	// Atom exists... search the table for it.
        for (n=0; n<keyscached; ++n) {
            if (akeyatoms[n] == atm) {
                DPF2(("Found existing key for %s\n", appname));
                return ahkey[n];
            }
        }
    }
    DPF2(("No key found for %s", appname));
#endif

    hr = StringCchCopyA(achName, MAX_PATH, KEYNAMEA);
	if (FAILED(hr))
		OutputError(hr, IDS_SAFE_COPY);

    if ((!fCreate && RegOpenKeyA(ROOTKEY, achName, &key) == ERROR_SUCCESS)
        || (fCreate && RegCreateKeyA(ROOTKEY, achName, &key) == ERROR_SUCCESS)) {
#if MMPROFILECACHE
        if ((keyscached < KEYSCACHED)
	  && (atm = AddAtomA(appname))) {
            // Add this key to the cache array
            akeyatoms[keyscached] = atm;
            ahkey[keyscached] = key;
            DPF1(("Adding key %s to cache array in position %d\n", appname, keyscached));
            ++keyscached;
        } else {
            DPF2(("Not adding key %s to cache array\n", appname));
            *closekey = TRUE;
        }
#endif
    }

    return(key);
}