|
er...make that
Calls the appropriate constructors first then does not need to do assignments.
|
|
|
|
|
i've the following problem. i'd like to create a folder on my DNS server and share it only to selecte users. for example i'd like to create a folder named BEckhard an then share it. Only the user BEckhard and the group of Administrators should have rights for this folder. (example: BEckhard is only allowed to create files). The users are stored in the active directory (win2000 server). creating the folder isn't the problem but sharing it seems to be impossible :*-(( please could you give me a code example for sharing a folder for a specific user.
thanks
benedikt
|
|
|
|
|
Here is asample of sharing the directory.
#define FORCE_UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>
#pragma comment ( lib, "Netapi32.lib")
void wmain( int argc, TCHAR *argv[ ])
{
NET_API_STATUS res;
SHARE_INFO_2 p;
DWORD parm_err = 0;
if(argc<2)
printf("Usage: NetShareAdd server\n");
else
{
p.shi2_netname = (unsigned short *)TEXT("TESTSHARE");
p.shi2_type = STYPE_DISKTREE;
p.shi2_remark = (unsigned short *)TEXT("TESTSHARE to test NetShareAdd");
p.shi2_permissions = 0;
p.shi2_max_uses = 4;
p.shi2_current_uses = 0;
p.shi2_path = (unsigned short * )TEXT("C:\\");
p.shi2_passwd = NULL;
res=NetShareAdd((unsigned short *)argv[1], 2, (LPBYTE) &p, &parm_err);
if(res==0)
printf("Share created.\n");
else
printf("Error: %u\tparmerr=%u\n", res, parm_err);
}
return;
}
In this sample the Level of sharing is 2.
In your case where you want to restrict the sharing to specific users you need to modifiy the info structure to pass it
a pointer to SHARE_INFO_502 structure instead of SHARE_INFO_2. after you define the PSECURITY_DESCRIPTOR for it.
Hope this might help
cheers
Alfadhly
|
|
|
|
|
thank you for your example. i tried to work with the PSECURITY_DESCRIPTOR, but it's a little bit difficult. would it be possible to gife me an example of sharing a folder (lets say "Benedikt") for the user "BEckhard"? isn't it possible to use the netshare functions like in the console. it would be much more easier.
thanx
benedikt
|
|
|
|
|
Hi,
Why is it diffecult to use the PSECURITY_DESCRIPTOR
Steps are as follow
1) get the required size to hold Sid associated with the supplied user "BEckhard" using LookupAccountNameW it will be returned in the 4th parameter of the LookupAccountNameW function
2) Now that you have the size get the Sid associated with the supplied user "BEckhard" using LookupAccountNameW again
3)Add the required access to the PSID using AddAccessAllowedAce
4) Initilize a new SID
5) set the information in a discretionary access-control (SetSecurityDescriptorDacl)list in the new Sid using the SID you got in setp 2
6) Now set up the share information in the SHARE_INFO_502 structure and set the "si502.shi502_security_descriptor" to the one you set in step 5 , and si502.shi502_path to "The full path of Benedikt directory"
7) Finally call NetShareAdd to add the share on the
Hope this might help
Cheers
Alfadhly
|
|
|
|
|
thank you for your answer. i'll try it on sunday. maybe i'll send you a code snipped an you could tell me why it doesn't work.
benedikt
|
|
|
|
|
I have not been able to reply to your message with the source code for the last two days.
However, I have written my own test function that you may like to use.
I hope it will help.
But first let me make sure that this posting goes through.
I have already sent Chris the dscription of the problem , But I know he has his hand full after VSLive, ... As I read ..
Cheers
Alfadhly
|
|
|
|
|
Hi,
I have tried the following code and was able to see the sharing.
This simple function will add sharing for the specified user on the specified machine
Hope it will help.
P.S in the following example the machine Name, and Domain was changed to protect the yada yada yada.
cheers
Alfadhly
#include "stdafx.h"
#include "NetShareMFC.h"
#include < LM.h >
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define _UNICODE
#define RTN_OK 0
#define RTN_ERROR 13
#pragma comment ( lib, "Netapi32.lib")
CWinApp theApp;
using namespace std;
int CleanUp( PSECURITY_DESCRIPTOR pSid, PACL pAcl, BOOL bSuccess);
int ShareFolder( LPCSTR szDirectory, LPCSTR szShareName, LPCSTR szUserName, LPCSTR szServer);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
cout << "Share folder returned " ;
cout << ShareFolder(
"c:\\temp"
, "alfadhly44$"
, "MYDOMAIN\\alfadhlyG"
,"\\\\MYMACHINE"
) ;
cout << endl;
}
return nRetCode;
}
int ShareFolder( LPCSTR szDirectory, LPCSTR szShareName, LPCSTR szUserName, LPCSTR szServer)
{
LPWSTR DirectoryToShare;
LPWSTR Sharename;
LPWSTR Username;
LPWSTR Server;
PSID pSid = NULL;
DWORD cbSid;
WCHAR RefDomain[DNLEN + 1];
DWORD cchDomain = DNLEN + 1;
SID_NAME_USE peUse;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
DWORD dwAclSize;
SHARE_INFO_502 si502;
NET_API_STATUS nas;
BOOL bSuccess = FALSE;
DWORD dwString;
dwString = MultiByteToWideChar(CP_ACP, 0, szDirectory, -1, NULL, 0);
DirectoryToShare = (PWSTR)LocalAlloc(LMEM_FIXED, dwString * sizeof(WCHAR));
if(dwString == NULL)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szDirectory, -1, DirectoryToShare, dwString);
if(dwString == 0)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szShareName, -1, NULL, 0);
Sharename = (PWSTR)LocalAlloc(LMEM_FIXED, dwString * sizeof(WCHAR));
if(dwString == NULL)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szShareName, -1, Sharename, dwString);
if(dwString == 0)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szUserName, -1, NULL, 0);
Username = (PWSTR)LocalAlloc(LMEM_FIXED, dwString * sizeof(WCHAR));
if(dwString == NULL)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szUserName, -1, Username, dwString);
if(dwString == 0)
return -1;
if (lstrlen(szServer)>0)
{
dwString = MultiByteToWideChar(CP_ACP, 0, szServer, -1, NULL, 0);
Server = (PWSTR)LocalAlloc(LMEM_FIXED, dwString * sizeof(WCHAR));
if(dwString == NULL)
return -1;
dwString = MultiByteToWideChar(CP_ACP, 0, szServer, -1, Server, dwString);
if(dwString == 0)
return -1;
}
else
Server = NULL;
#define SID_SIZE 96
cbSid = SID_SIZE;
pSid = (PSID)HeapAlloc(GetProcessHeap(), 0, cbSid);
if(pSid == NULL) {
TRACE("HeapAlloc error!\n");
return RTN_ERROR;
}
if(!LookupAccountNameW(
NULL,
Username,
pSid,
&cbSid,
RefDomain,
&cchDomain,
&peUse
)) {
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
pSid = (PSID)HeapReAlloc(GetProcessHeap(), 0, pSid, cbSid);
if(pSid == NULL) {
TRACE("HeapReAlloc error!\n");
return CleanUp( pSid, pDacl, FALSE);
}
cchDomain = DNLEN + 1;
if(!LookupAccountNameW(
NULL,
Username,
pSid,
&cbSid,
RefDomain,
&cchDomain,
&peUse
))
{
TRACE("LookupAccountName error! (rc=%lu)\n", GetLastError());
return CleanUp( pSid, pDacl, FALSE);
}
} else
{
TRACE("LookupAccountName error! (rc=%lu)\n", GetLastError());
return CleanUp( pSid, pDacl, FALSE);
}
}
dwAclSize = sizeof(ACL) +
1 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
GetLengthSid(pSid) ;
pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize);
if(pDacl == NULL) return CleanUp( pSid, pDacl, FALSE);
if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
return CleanUp( pSid, pDacl, FALSE);
if(!AddAccessAllowedAce(
pDacl,
ACL_REVISION,
GENERIC_ALL,
pSid
)) return CleanUp( pSid, pDacl, FALSE);
if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
return CleanUp( pSid, pDacl, FALSE);
if(!SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE)) {
TRACE( "SetSecurityDescriptorDacl error! (rc=%lu)\n", GetLastError());
return CleanUp( pSid, pDacl, FALSE);
}
si502.shi502_netname = (LPTSTR) Sharename;
si502.shi502_type = STYPE_DISKTREE;
si502.shi502_remark = NULL;
si502.shi502_permissions = 0;
si502.shi502_max_uses = SHI_USES_UNLIMITED;
si502.shi502_current_uses = 0;
si502.shi502_path = (LPTSTR) DirectoryToShare;
si502.shi502_passwd = NULL;
si502.shi502_reserved = 0;
si502.shi502_security_descriptor = &sd;
nas = NetShareAdd(
(LPTSTR) Server,
502,
(LPBYTE)&si502,
NULL
);
if(nas != NO_ERROR) {
TRACE("NetShareAdd error! (rc=%lu)\n", nas);
return CleanUp( pSid, pDacl, FALSE);
}
return CleanUp( pSid, pDacl, TRUE);
}
int CleanUp( PSECURITY_DESCRIPTOR pSid, PACL pAcl, BOOL bSuccess)
{
if(pAcl != NULL)
HeapFree(GetProcessHeap(), 0, pAcl);
if(pSid != NULL)
HeapFree(GetProcessHeap(), 0, pSid);
if(!bSuccess) {
return RTN_ERROR;
}
return RTN_OK;
}
|
|
|
|
|
thank you for your code. i'll try it tomorrow. it's now very late at my time zone.
benedikt
|
|
|
|
|
thank you for your description. i tried it with the following code, but something doesn't work. i get no error message but there must be an error! maybe you find time to check my code. thanx
CString cstrStandardpfad = "C:\\User\\";
CString cstrOrdnername = "";
CString cstrPfad = "";
int nCounter = 1;
SHARE_INFO_502 shareInfo;
PSECURITY_DESCRIPTOR security;
EXPLICIT_ACCESS actrlEntrys[2];
PACL pACL = NULL;
char* pcNetname = new char[MAX_PATH];
char* pcPath = new char[MAX_PATH];
//acl entry erstellen
ZeroMemory(&actrlEntrys, 2 * sizeof(EXPLICIT_ACCESS));
actrlEntrys[0].grfAccessMode = GRANT_ACCESS;
actrlEntrys[0].grfAccessPermissions = FILE_ADD_SUBDIRECTORY|FILE_ADD_FILE|FILE_DELETE_CHILD|
FILE_LIST_DIRECTORY|FILE_TRAVERSE;
actrlEntrys[0].grfInheritance = CONTAINER_INHERIT_ACE;
actrlEntrys[0].Trustee.pMultipleTrustee = NULL;
actrlEntrys[0].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
actrlEntrys[0].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
actrlEntrys[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
actrlEntrys[0].Trustee.ptstrName = "Administratoren";
actrlEntrys[1].grfAccessMode = GRANT_ACCESS;
actrlEntrys[1].grfAccessPermissions = FILE_ADD_FILE|FILE_DELETE_CHILD|
FILE_LIST_DIRECTORY|FILE_TRAVERSE;
actrlEntrys[1].grfInheritance = CONTAINER_INHERIT_ACE;
actrlEntrys[1].Trustee.pMultipleTrustee = NULL;
actrlEntrys[1].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
actrlEntrys[1].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
actrlEntrys[1].Trustee.TrusteeType = TRUSTEE_IS_USER;
while(nCounter<20)
{
//ordnername + pfad ermitteln
cstrOrdnername = m_pGrid->GetItemText(nCounter,1);
cstrPfad = cstrStandardpfad+cstrOrdnername;
pcPath = (char*)(LPCSTR)(cstrPfad);
pcNetname = (char*)(LPCSTR)(cstrOrdnername);
//ace entry modifizieren
actrlEntrys[1].Trustee.ptstrName = pcNetname;
//access list generieren
SetEntriesInAcl(2,actrlEntrys,NULL,&pACL);
// security descriptor initialisieren
security = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
if (security == NULL) {
AfxMessageBox("Fehler beim Erstellen vom Security Descriptor!");
}
if (!InitializeSecurityDescriptor(security, SECURITY_DESCRIPTOR_REVISION)) {
AfxMessageBox("Fehler beim Initialisieren des security descriptors!");
}
// die acl dem security descriptor hinzufügen
if (!SetSecurityDescriptorDacl(security,
TRUE, // fDaclPresent flag
pACL,
FALSE)) // not a default DACL
{
AfxMessageBox("Irgendein Fehler bein zuweisen vom security descriptor!");
}
//Freigabe für gleichnamigen benutzer erstellen
shareInfo.shi502_netname = pcNetname; //name der freigabe
shareInfo.shi502_type = STYPE_DISKTREE; //freigabe ist irgendein ordner
shareInfo.shi502_remark = "Das ist eine Freigabe!"; //kommentar
shareInfo.shi502_permissions = ACCESS_ALL; //zugriff zur freigabe
shareInfo.shi502_max_uses = -1; //anzahl der gleichzeitig zugreifenden user
shareInfo.shi502_current_uses = 0; //anzahl der derzeitigen user
shareInfo.shi502_path = pcPath; //pfad zum ordner
shareInfo.shi502_passwd = NULL; //passwort der freigabe
shareInfo.shi502_security_descriptor = security; //security descriptor
NET_API_STATUS res;
DWORD parm_err = 0;
//endlich freigeben
res = NetShareAdd("derhackler",502,(LPBYTE)&shareInfo,&parm_err);
if(res==0)
AfxMessageBox("ok");
else
{
if(res==ERROR_ACCESS_DENIED)
AfxMessageBox("Zugriff verweigert");
else if(res==ERROR_INVALID_LEVEL)
AfxMessageBox("der level parameter ist falsch");
else if(res==ERROR_INVALID_NAME)
AfxMessageBox("irgendwas mim file system parameter");
else if(res==ERROR_INVALID_PARAMETER)
AfxMessageBox("der parameter ist ungültig");
else if(res==NERR_DuplicateShare)
AfxMessageBox("Freigabe bereits vorhanden");
else if(res==NERR_RedirectedPath)
AfxMessageBox("Aktion ist für den Pfad ungültig");
else if(res==NERR_UnknownDevDir)
AfxMessageBox("Pfad existiert nicht");
}
TRACE("Error: %u\tparmerr=%u\n", res, parm_err);
nCounter++;
}
|
|
|
|
|
Can somebody tell me why does this error message come when i execute my visual c++ 5.0 application
|
|
|
|
|
Can somebody tell me why invalid page fault message appears in some application ( I am using visual c++ 5.0 version )
Lets share our knowledge and make this world even more beautiful.
|
|
|
|
|
Not without more information. Saying why do I get an Invalid Page Fault is like asking why I get an access violation or a general protection fault. Post the suspected code and maybe someone can help out.
|
|
|
|
|
Hi,
is anybody out there who has experience in Midi-Programming with Win32-API ( no MFC !) ?
Especially in the following things :
- timer and resolution
- callbacks for midi-input
- midi-synchronisation via MTC / SMPTE
- midi-syschronisation with parallel wave-out ( API or DirectX )
I`m still looking for a good book about Midi & Win32 Api. Not that small introduction like Petzold did in his book.
If you any good book please send an ISBN.
Greatings Mario ///
--------------------
www.klangwerker.de
rocknix@lycos.de
--------------------
|
|
|
|
|
i have bulid a com component which is functioning properly in debug mode
whereas it gives error while building the dll in release mode(Min dependancy)
error C2259: 'CComObject<class cgraphics="">' : cannot instantiate abstract class due to following members:
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class atl::ccomobject<class="" cgraphics=""> >::CreateInstance(void *,const struct _GUID &,v
oid ** )'
so please help me
|
|
|
|
|
Hi,
I have created controls in runtime.
I want to know how to do the following things in the run time:
Move the controls in the dialog
Insert or hide the scroll bar in the dialog, depending on the control's position
Increase the scroll area size, if the control is moved out of the dialog (right or bottom sides)
Decrease the scroll area size, if the control is moved on the left or top sides of the dialog
Thanks in advance
bye
Mani
|
|
|
|
|
Hi,
You might want to check the MSDN Library, SetWindowPos, and all related articles.
Good luck.
--
Alex Marbus
|
|
|
|
|
Some time ago I had found a class that allows the controls to be replaced/resized responding to the size changes made over a dialog/window...
You can try to find it at codeguru, it was called CControlPos, if you don't find it e-mail me and I'll send it to you.
It can be possible that that class don't solve your concrete problem, then you should try to use SetWindowPos() or MoveWindow() always taking a look at the differences between Client and nonclient areas of the rects that you get using GetWindowRect(), GetCliewntRect()...
If you want a dynamic scroll bar placed in your dialog you should activate it from the dialog properties, and then recalculate its size every time you make a "control-move".
I expect this helps you.
PD: excuse my english I'm just a begginer.
|
|
|
|
|
My application is a container, and It implement that, drag a item or items from a view to anther view( a item is a control ). The code of copy or cut items to anther view is finished, which is also used by the code of drag-drop --- save data to a COleDataSource and load data from COleDataObject.
The question is that, when I drag items ( copy or move ) in the save view, no error, but , when I drag items to another view in this MDI application, when I use pItem->DoVerb( OLEIVERB_SHOW, this ) in view class, error ocurs, and cause a ASSERT error, in COleFrameHook::OnDocActivate(BOOL bActive) as follows:
if (pNotifyHook != this)
{
// shouldn't be removing some other hook
ASSERT(pNotifyHook->m_pFrameWnd->m_pNotifyHook == pNotifyHook); // this line
pNotifyHook->m_pFrameWnd->m_pNotifyHook = NULL;
}
drag copy in the save view has no error, I know maybe something is not set correctly, but I donot know where. Help please, it is in hurry.
Pardon my poor english!
|
|
|
|
|
Hello,
This is bit wierd, please bear with me.
I am using the Ultimate Toolbox classes from Dundas to create a tabbed toolbar. No problem there. The toolbar is created in the 3dTabView, and the 3dTabView is created in a docked window.
However, when the docking window (window) is created it is way to big. Here's the question...
How can I resize that docking window's height only?
I've been able to resize the width, by altering the rect before creating it. But when I do the same thing with rect.bottom the window is resized way small. I did set a breakpoint to see what the rect contained and it was a huge negative number. Is this correct?
Thanks for the help...oh, and not for laughing.
Frank
"640k ought to be enough for anybody."
Bill Gates, Chairman of the Board, and CEO, Microsoft Corporation, 1981
|
|
|
|
|
Duh.
Fixed it. The Create function was using CFrameWnd::RectDefault. Once I initialized my own rect, and got rid of the rectdefault it worked.
Sorry!
Frank
|
|
|
|
|
The huge negative number sounds like an int/unsigned int problem. It's hard to know without seeing the code. Did you try SetWindowPos AFTER creation ? Did you try different values in to rect you passed in, or changing the top instead ?
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Is there a way to select a line (drawn by LineTo or points -SetPixel) say by mouse either by clicking on it or by CRectTracker .. I have found a way which is very long, and I think there is a better way, if you got an idea please help me.
Thanks for reading. Neda
|
|
|
|
|
Hi Neda, Chetovri!
1- Are you using any collection or data structures when you draw the line?
2- Are you drwaing the new lines with the C++ new operator?
If Yes to (1), then you must have some sort of collection class to collect the new instances of the lines.
If Yes to (2), then you can just return the index of your line from the collection class.
|
|
|
|
|
Does anyone have any recommendations on whether to use ODBC or OLE DB in a C++ project? What are the pros and cons of using either one? From what I've been reading, it sounded like OLE DB would allow you to access everything ODBC will, but also allow you access to other data sources as well. However, am wondering how portable OLE DB is compared to ODBC and what other issues may suggest using one access method over the other.
Comments and suggestions appreciated. Thanks.
|
|
|
|
|