PDA

View Full Version : DC_VFS Change!


darkone
11-13-2003, 04:15 PM
Structure this message uses, will be changed in next version, to something that is easier to use

Miky
12-08-2003, 04:19 AM
Hi, is this new structure?


typedef struct _DC_VFS
{
UINT32 Uid;
UINT32 Gid;
DWORD dwFileMode;
DWORD dwBuffer;
PBYTE pBuffer[1];

} DC_VFS, * LPDC_VFS;


and how it works?
where are old values? Do not necessary anymore?

When I use this structure for DC_VFS_READ I obtain {5261654, 0, 0, 1024, {NULL}} :(
I really haven't 5261654 users.

THX for anyhelp
Miky

ADDiCT
12-08-2003, 07:44 AM
i would also appreciate a small C++ usage example of the new structure, so i can easily convert it to VB :)
(now it's just guessing and trial&error for me)

Mouton
12-08-2003, 08:01 AM
void getFileOwner(const char *complete_filename, char *user)
{
if (!initSharedMem(1024 + (strlen(complete_filename) + 1) + sizeof(DC_VFS))) {
strcpy(user,"nobody");
return;
}
lpMessage->dwIdentifier = DC_VFS_READ;
LPDC_VFS pFileInformation = (LPDC_VFS)lpMessage->lpContext;
lpContext = (LPVOID)((ULONG)lpMessage->lpContext + sizeof(DC_VFS));
strcpy((LPTSTR)pFileInformation->pBuffer,complete_filename);
dwReturn = SendMessage(hIoFTPD, WM_SHMEM, NULL, (LPARAM)hMemory);
if (!dwReturn) {
WaitForSingleObject(hEvent,10000);

int uid = pFileInformation->Uid;
if (pFileInformation->dwFileMode==0 || !resolveUidToName(uid,user))
strcpy(user,"nobody");
} else {
strcpy(user,"nobody");
}
closeSharedMem();
}

Miky
12-15-2003, 04:47 AM
it's better but not enough :(

what is
DWORD dwFileMode;
DWORD dwBuffer;
?

when I insert foldername to pBuffer and want to write new owner and groupe ioftpd crash :(

can you post example for DC_VFS_WRITE too or explain new structute, because only from your example I figure out that pBuffer is for file(folder??)name

THX

darkone
12-15-2003, 04:53 AM
when writing, dwBuffer contains length of filename + additional length of directory context. Length of filename includes terminating null character. (Additional context may contain information such as, privacy information or symbolic link target)

Miky
12-15-2003, 05:08 AM
thanks, works fine :)

darkone
12-15-2003, 06:35 AM
Here's commands for context handling.. it uses really simple format: |type|length|data|TCHAR null|

BOOL CreateFileContext(LPFILECONTEXT lpContext, LPFILECONTEXT lpSourceContext)
{
// Copy context
if (lpSourceContext &&
lpSourceContext->dwData)
{
lpContext->dwData = lpSourceContext->dwData;
lpContext->lpData = Allocate("FileContext", lpContext->dwData);
if (! lpContext->lpData) return FALSE;
CopyMemory(lpContext->lpData, lpSourceContext->lpData, lpContext->dwData);
}
else ZeroMemory(lpContext, sizeof(FILECONTEXT));

return TRUE;
}




BOOL InsertFileContext(LPFILECONTEXT lpContext, BYTE Item, LPVOID lpData, DWORD dwData)
{
LPVOID lpMemory;
DWORD dwSlack, dwMemory;
TCHAR pBuffer[1];

pBuffer[0] = _TEXT('\0');
// Remove existing context
dwSlack = lpContext->dwData;
DeleteFileContext(lpContext, Item);
dwSlack = (lpContext->dwData ? dwSlack - lpContext->dwData : 0);

// Allocate more memory
if (dwSlack < (dwData + sizeof(BYTE) + sizeof(UINT32) + sizeof(TCHAR)))
{
lpMemory = ReAllocate(lpContext->lpData, "FileContext",
lpContext->dwData + dwData + sizeof(BYTE) + sizeof(UINT32) + sizeof(TCHAR));
if (! lpMemory) ERROR_RETURN(ERROR_NOT_ENOUGH_MEMORY, FALSE);
lpContext->lpData = lpMemory;
}

dwMemory = dwData + sizeof(BYTE) + sizeof(UINT32) + sizeof(TCHAR);
// Copy new data
CopyMemory((LPVOID)((ULONG)lpContext->lpData + lpContext->dwData),
&Item, sizeof(BYTE));
lpContext->dwData += sizeof(BYTE);
CopyMemory((LPVOID)((ULONG)lpContext->lpData + lpContext->dwData),
&dwMemory, sizeof(UINT32));
lpContext->dwData += sizeof(UINT32);
CopyMemory((LPVOID)((ULONG)lpContext->lpData + lpContext->dwData),
lpData, dwData);
lpContext->dwData += dwData;
CopyMemory((LPVOID)((ULONG)lpContext->lpData + lpContext->dwData), pBuffer, sizeof(TCHAR));
lpContext->dwData += sizeof(TCHAR);

return TRUE;
}


BOOL FreeFileContext(LPFILECONTEXT lpContext)
{
BOOL bReturn;

bReturn = Free(lpContext->lpData);
lpContext->lpData = NULL;
lpContext->dwData = 0;
return bReturn;
}


BOOL DeleteFileContext(LPFILECONTEXT lpContext, BYTE Item)
{
LPVOID lpMemory;
DWORD dwMemory;

// Remove existing context
lpMemory = FindFileContext(Item, lpContext);
if (lpMemory)
{
dwMemory = ((PUINT32)lpMemory)[-1];
lpMemory = (LPVOID)((ULONG)lpMemory - sizeof(UINT32) - sizeof(BYTE));
MoveMemory(lpMemory,
(LPVOID)((ULONG)lpMemory + dwMemory),
((ULONG)lpContext->lpData + lpContext->dwData) - ((ULONG)lpMemory + dwMemory));
lpContext->dwData -= dwMemory;
}
return TRUE;
}




LPVOID FindFileContext(BYTE Item, LPFILECONTEXT lpContext)
{
LPBYTE lpOffset;
UINT32 Size;

// Seek through buffer
lpOffset = (LPBYTE)lpContext->lpData;
for (;(ULONG)lpOffset - (ULONG)lpContext->lpData < lpContext->dwData;lpOffset += Size)
{
// Size of entry
Size = ((PUINT32)&lpOffset[1])[0] + sizeof(BYTE) + sizeof(UINT32);

if (lpOffset[0] == Item) return &lpOffset[sizeof(BYTE) + sizeof(UINT)];
}
return NULL;
}