Click here to Skip to main content
15,913,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modifying the limits of an integer edit control Pin
adamUK16-Oct-02 9:29
adamUK16-Oct-02 9:29 
GeneralRe: Modifying the limits of an integer edit control Pin
jhwurmbach16-Oct-02 20:44
jhwurmbach16-Oct-02 20:44 
GeneralRe: Modifying the limits of an integer edit control [corrected] Pin
Joaquín M López Muñoz16-Oct-02 3:34
Joaquín M López Muñoz16-Oct-02 3:34 
GeneralRe: Modifying the limits of an integer edit control Pin
Tomasz Sowinski16-Oct-02 3:44
Tomasz Sowinski16-Oct-02 3:44 
GeneralRe: Modifying the limits of an integer edit control Pin
jhwurmbach16-Oct-02 4:52
jhwurmbach16-Oct-02 4:52 
GeneralRe: Modifying the limits of an integer edit control Pin
Tomasz Sowinski16-Oct-02 5:03
Tomasz Sowinski16-Oct-02 5:03 
GeneralRe: Modifying the limits of an integer edit control Pin
PJ Arends16-Oct-02 6:16
professionalPJ Arends16-Oct-02 6:16 
GeneralFile Owner Question ...... SOS - SOS - SOS Pin
Qiang.Fu15-Oct-02 23:14
Qiang.Fu15-Oct-02 23:14 
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <tchar.h>

#define ErrorHandler(s) _ErrorHandler(s, __FILE__, __LINE__)

void _ErrorHandler(LPCSTR lpszLocation, LPCTSTR lpszSrcFile, UINT nSrcLine)
{
LPVOID lpMsgBuf;
DWORD dwError = GetLastError();

FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPSTR) &lpMsgBuf,
0,
NULL );

// Process any inserts in lpMsgBuf.
cout<<"ERROR @ "<<lpszLocation<<" : "<<'('<<dwError<<')'<<(LPCSTR)lpMsgBuf;
cout<<"SOURCE @ Line = "<<nSrcLine<<", File = "<<lpszSrcFile<<'\n';

// Free the buffer.
LocalFree( lpMsgBuf );
}

BOOL SetFileOwner(LPCTSTR lpszFileName, LPCSTR lpszAccount, LPCSTR lpszGroup)
{
PSECURITY_DESCRIPTOR pSD;

PSID pSID, pSIDGroup;
DWORD cbSID = 1024;
LPSTR lpszDomain;
DWORD cchDomainName = 80;
PSID_NAME_USE psnuType;

// Initialize a security descriptor.

pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH); // defined in WINNT.H
if (pSD == NULL) {
ErrorHandler("LocalAlloc");
goto Cleanup;
}

if (!InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION)) { // defined in WINNT.H
ErrorHandler("InitializeSecurityDescriptor");
goto Cleanup;
}

// Retrieve the SID for User.

pSID = (PSID) LocalAlloc(LPTR, cbSID);
psnuType = (PSID_NAME_USE) LocalAlloc(LPTR, 1024);
lpszDomain = (LPSTR) LocalAlloc(LPTR, cchDomainName);
if (pSID == NULL || psnuType == NULL ||
lpszDomain == NULL) {
ErrorHandler("LocalAlloc");
goto Cleanup;
}

if (!LookupAccountName((LPSTR) NULL, // local name
lpszAccount,
pSID,
&cbSID,
lpszDomain,
&cchDomainName,
psnuType)) {
ErrorHandler("LookupAccountName");
goto Cleanup;
}

if (!IsValidSid(pSID))
{
ErrorHandler("IsValidSid");
goto Cleanup;
}

// Sets the owner to the SD

if (!SetSecurityDescriptorOwner(pSD, pSID, FALSE)) { // not a default SID
ErrorHandler("SetSecurityDescriptorOwner");
goto Cleanup;
}

// Retrieve the SID for Group.
cbSID = 1024;

pSIDGroup = (PSID) LocalAlloc(LPTR, cbSID);
if (pSIDGroup == NULL) {
ErrorHandler("LocalAlloc");
goto Cleanup;
}

if (!LookupAccountName((LPSTR) NULL, // local name
lpszGroup,
pSIDGroup,
&cbSID,
lpszDomain,
&cchDomainName,
psnuType)) {

pSIDGroup = (PSID)LocalReAlloc((HLOCAL) pSIDGroup, cbSID, LPTR);
lpszDomain = (LPSTR) LocalReAlloc((HLOCAL) lpszDomain, cchDomainName, LPTR);
if (pSIDGroup == NULL || lpszDomain == NULL) {
ErrorHandler("LocalReAlloc");
goto Cleanup;
}

if (!LookupAccountName((LPSTR) NULL, // local name
lpszGroup,
pSIDGroup,
&cbSID,
lpszDomain,
&cchDomainName,
psnuType)) {
ErrorHandler("LookupAccountName");
goto Cleanup;
}
}

if (!IsValidSid(pSIDGroup))
{
ErrorHandler("IsValidSid");
goto Cleanup;
}

// Sets the group to the SD
if (!SetSecurityDescriptorGroup(pSD, pSIDGroup, FALSE)) { // not a default SID
ErrorHandler("SetSecurityDescriptorGroup");
goto Cleanup;
}

// Use the new SD as the file's security info.
if (!SetFileSecurity(lpszFileName, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION, pSD)) {
ErrorHandler("SetFileSecurity");
goto Cleanup;
}

return TRUE;

Cleanup:
FreeSid(pSID);
FreeSid(pSIDGroup);

if(pSD != NULL)
LocalFree((HLOCAL) pSD);
if(psnuType != NULL)
LocalFree((HLOCAL) psnuType);
if(lpszDomain != NULL)
LocalFree((HLOCAL) lpszDomain);

return FALSE;
}








int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{
if (argc < 4) {
cout<<"ERROR @ main : Not enough parameters\n";
return 0;
}

TCHAR tszFileName[MAX_PATH];
char szUserName[256];
char szGroupName[256];

_tcscpy(tszFileName, argv[1]);

#if defined(_UNICODE) || defined(UNICODE)
if (!WideCharToMultiByte(CP_ACP, 0, argv[2], -1, szUserName, 256, NULL, NULL)) {
ErrorHandler("WideCharToMultiByte");
return 0;
}
if (!WideCharToMultiByte(CP_ACP, 0, argv[3], -1, szGroupName, 256, NULL, NULL)) {
ErrorHandler("WideCharToMultiByte");
return 0;
}
#else
strcpy(szUserName, argv[2]);
strcpy(szGroupName, argv[3]);
#endif

if (!SetFileOwner(tszFileName, szUserName, szGroupName)) {
cout<<"Operation Failed!\n";
return 0;
}

cout<<"Operation Succeeded!\n";
return 0;
}







=======================================================================
This program can set file and dir owner for "administrator"
or "administrators", but can't set for other user, else return
the "ERROR_INVALID_OWNER(1703L)"...
Why??? Please help me ~!!!
=======================================================================
GeneralRe: File Owner Question ...... SOS - SOS - SOS Pin
Andreas Saurwein16-Oct-02 4:10
Andreas Saurwein16-Oct-02 4:10 
GeneralRe: File Owner Question ...... SOS - SOS - SOS Pin
Qiang.Fu18-Oct-02 2:48
Qiang.Fu18-Oct-02 2:48 
Generalcalculation of runing time of program Pin
Anonymous15-Oct-02 22:35
Anonymous15-Oct-02 22:35 
GeneralRe: calculation of runing time of program Pin
l a u r e n16-Oct-02 4:46
l a u r e n16-Oct-02 4:46 
Generallicense Pin
helping hand15-Oct-02 21:11
helping hand15-Oct-02 21:11 
GeneralRe: license Pin
Christian Graus15-Oct-02 21:22
protectorChristian Graus15-Oct-02 21:22 
GeneralRe: license Pin
Jon Hulatt15-Oct-02 21:26
Jon Hulatt15-Oct-02 21:26 
GeneralRe: license Pin
Christian Graus15-Oct-02 21:38
protectorChristian Graus15-Oct-02 21:38 
GeneralRe: license Pin
Nish Nishant16-Oct-02 1:03
sitebuilderNish Nishant16-Oct-02 1:03 
GeneralRe: license Pin
Tomasz Sowinski15-Oct-02 23:37
Tomasz Sowinski15-Oct-02 23:37 
QuestionHow to export classes in ActiveX project? Pin
denkor15-Oct-02 21:05
denkor15-Oct-02 21:05 
QuestionHow to handle event in DHTML? Pin
sonshiro15-Oct-02 20:54
sonshiro15-Oct-02 20:54 
GeneralStructure Query Pin
Anonymous15-Oct-02 20:45
Anonymous15-Oct-02 20:45 
GeneralRe: Structure Query Pin
Christian Graus15-Oct-02 21:23
protectorChristian Graus15-Oct-02 21:23 
GeneralRe: Structure Query Pin
jhwurmbach15-Oct-02 22:48
jhwurmbach15-Oct-02 22:48 
GeneralIE and SSL question! Pin
wabc15-Oct-02 20:08
wabc15-Oct-02 20:08 
GeneralCArray template class Pin
15-Oct-02 19:14
suss15-Oct-02 19:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.