ReactOS 0.4.15-dev-7705-g2320c37
CShellCommandOwner Class Reference

#include <ShellCommandOwner.h>

Inheritance diagram for CShellCommandOwner:
Collaboration diagram for CShellCommandOwner:

Public Member Functions

 CShellCommandOwner (CRegistryTree &rTree)
 
virtual ~CShellCommandOwner ()
 
virtual BOOL Match (const TCHAR *pchCommand)
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)
 
virtual const TCHARGetHelpString ()
 
virtual const TCHARGetHelpShortDescriptionString ()
 
- Public Member Functions inherited from CShellCommand
 CShellCommand ()
 
virtual ~CShellCommand ()
 
virtual BOOL Match (const TCHAR *pchCommand)=0
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)=0
 
virtual const TCHARGetHelpString ()=0
 
virtual const TCHARGetHelpShortDescriptionString ()=0
 

Private Attributes

CRegistryTreem_rTree
 

Detailed Description

Definition at line 12 of file ShellCommandOwner.h.

Constructor & Destructor Documentation

◆ CShellCommandOwner()

CShellCommandOwner::CShellCommandOwner ( CRegistryTree rTree)

Definition at line 39 of file ShellCommandOwner.cpp.

39 :m_rTree(rTree)
40{
41}
CRegistryTree & m_rTree

◆ ~CShellCommandOwner()

CShellCommandOwner::~CShellCommandOwner ( )
virtual

Definition at line 43 of file ShellCommandOwner.cpp.

44{
45}

Member Function Documentation

◆ Execute()

int CShellCommandOwner::Execute ( CConsole rConsole,
CArgumentParser rArguments 
)
virtual

Implements CShellCommand.

Definition at line 60 of file ShellCommandOwner.cpp.

61{
62 const TCHAR *pchKey = NULL;
63 BOOL blnDo = TRUE;
64 BOOL blnBadParameter = FALSE;
65 BOOL blnHelp = FALSE;
66 const TCHAR *pchParameter;
67 DWORD dwError;
68
69 rArguments.ResetArgumentIteration();
70 const TCHAR *pchCommandItself = rArguments.GetNextArgument();
71
72 if ((_tcsnicmp(pchCommandItself,OWNER_CMD _T(".."),OWNER_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
73 (_tcsnicmp(pchCommandItself,OWNER_CMD _T("\\"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
74 {
75 pchKey = pchCommandItself + OWNER_CMD_LENGTH;
76 }
77 else if (_tcsnicmp(pchCommandItself,OWNER_CMD _T("/"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
78 {
79 pchParameter = pchCommandItself + OWNER_CMD_LENGTH;
80 goto CheckOwnerArgument;
81 }
82
83 while((pchParameter = rArguments.GetNextArgument()) != NULL)
84 {
85CheckOwnerArgument:
86 blnBadParameter = FALSE;
87 if ((_tcsicmp(pchParameter,_T("/?")) == 0)
88 ||(_tcsicmp(pchParameter,_T("-?")) == 0))
89 {
90 blnHelp = TRUE;
91 blnDo = pchKey != NULL;
92 }
93 else if (!pchKey)
94 {
95 pchKey = pchParameter;
96 blnDo = TRUE;
97 }
98 else
99 {
100 blnBadParameter = TRUE;
101 }
102 if (blnBadParameter)
103 {
104 rConsole.Write(_T("Bad parameter: "));
105 rConsole.Write(pchParameter);
106 rConsole.Write(_T("\n"));
107 }
108 }
109
111
112 if (!m_rTree.GetKey(pchKey?pchKey:_T("."),KEY_QUERY_VALUE|READ_CONTROL,Key))
113 {
115 blnDo = FALSE;
116 }
117
118 if (blnHelp)
119 {
120 rConsole.Write(GetHelpString());
121 }
122
123 if (blnDo&&blnHelp) rConsole.Write(_T("\n"));
124
125 if (!blnDo)
126 return 0;
127
128 if (Key.IsRoot())
129 { // root key
131 return 0;
132 }
133
134 PISECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
135 TCHAR *pchName = NULL, *pchDomainName = NULL;
136 try
137 {
138 DWORD dwSecurityDescriptorLength;
139 rConsole.Write(_T("Key : "));
140 rConsole.Write(_T("\\"));
141 rConsole.Write(Key.GetKeyName());
142 rConsole.Write(_T("\n"));
143 dwError = Key.GetSecurityDescriptorLength(&dwSecurityDescriptorLength);
144 if (dwError != ERROR_SUCCESS) throw dwError;
145
146 pSecurityDescriptor = (PISECURITY_DESCRIPTOR) new unsigned char [dwSecurityDescriptorLength];
147 DWORD dwSecurityDescriptorLength1 = dwSecurityDescriptorLength;
148 dwError = Key.GetSecurityDescriptor((SECURITY_INFORMATION)OWNER_SECURITY_INFORMATION,pSecurityDescriptor,&dwSecurityDescriptorLength1);
149 if (dwError != ERROR_SUCCESS) throw dwError;
150 PSID psidOwner;
151 BOOL blnOwnerDefaulted;
152 if (!GetSecurityDescriptorOwner(pSecurityDescriptor,&psidOwner,&blnOwnerDefaulted))
153 throw GetLastError();
154 if (psidOwner == NULL)
155 {
156 rConsole.Write(_T("Key has no owner."));
157 }
158 else
159 {
160 if (!IsValidSid(psidOwner))
161 {
162 rConsole.Write(_T("Key has invalid owner SID."));
163 }
164 else
165 {
166 rConsole.Write(_T("Key Owner: \n"));
167 DWORD dwSIDStringSize = 0;
168 BOOL blnRet = GetTextualSid(psidOwner,NULL,&dwSIDStringSize);
169 ASSERT(!blnRet);
171 TCHAR *pchSID = new TCHAR[dwSIDStringSize];
172 if(!GetTextualSid(psidOwner,pchSID,&dwSIDStringSize))
173 {
174 dwError = GetLastError();
176 rConsole.Write(_T("Error "));
177 TCHAR Buffer[256];
178 rConsole.Write(_itoa(dwError,Buffer,10));
179 rConsole.Write(_T("\nGetting string representation of SID\n"));
180 }
181 else
182 {
183 rConsole.Write(_T("\tSID: "));
184 rConsole.Write(pchSID);
185 rConsole.Write(_T("\n"));
186 }
187 delete [] pchSID;
188 DWORD dwNameBufferLength, dwDomainNameBufferLength;
189 dwNameBufferLength = 1024;
190 dwDomainNameBufferLength = 1024;
191 pchName = new TCHAR [dwNameBufferLength];
192 pchDomainName = new TCHAR [dwDomainNameBufferLength];
193 DWORD dwNameLength = dwNameBufferLength, dwDomainNameLength = dwDomainNameBufferLength;
194 SID_NAME_USE Use;
195 if (!LookupAccountSid(NULL,psidOwner,pchName,&dwNameLength,pchDomainName,&dwDomainNameLength,&Use))
196 throw GetLastError();
197 else
198 {
199 rConsole.Write(_T("\tOwner Domain: "));
200 rConsole.Write(pchDomainName);
201 rConsole.Write(_T("\n"));
202 rConsole.Write(_T("\tOwner Name: "));
203 rConsole.Write(pchName);
204 rConsole.Write(_T("\n\tSID type: "));
205 rConsole.Write(GetSidTypeName(Use));
206 rConsole.Write(_T("\n"));
207 rConsole.Write(_T("\tOwner defaulted: "));
208 rConsole.Write(blnOwnerDefaulted?_T("Yes"):_T("No"));
209 rConsole.Write(_T("\n"));
210 }
211 delete [] pchName;
212 pchName = NULL;
213 delete [] pchDomainName;
214 pchDomainName = NULL;
215
216 }
217 }
218 delete [] pSecurityDescriptor;
219 }
220 catch (DWORD dwError)
221 {
222 rConsole.Write(_T("Error "));
223 TCHAR Buffer[256];
224 rConsole.Write(_itoa(dwError,Buffer,10));
225 rConsole.Write(_T("\n"));
226 if (pchName) delete [] pchName;
227 if (pchDomainName) delete [] pchDomainName;
228 if (pSecurityDescriptor) delete [] pSecurityDescriptor;
229 }
230
231 return 0;
232}
#define COMMAND_NA_ON_ROOT
const TCHAR * GetSidTypeName(SID_NAME_USE Use)
BOOL GetTextualSid(PSID pSid, LPTSTR TextualSid, LPDWORD lpdwBufferLen)
#define OWNER_CMD_LENGTH
#define OWNER_CMD
Definition: bufpool.h:45
void ResetArgumentIteration()
TCHAR * GetNextArgument()
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
const TCHAR * GetLastErrorDescription()
virtual const TCHAR * GetHelpString()
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI IsValidSid(PSID pSid)
Definition: security.c:819
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP char *__cdecl _itoa(_In_ int _Value, _Pre_notnull_ _Post_z_ char *_Dest, _In_ int _Radix)
enum _SID_NAME_USE SID_NAME_USE
#define ASSERT(a)
Definition: mode.c:44
DWORD SECURITY_INFORMATION
Definition: ms-dtyp.idl:311
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define READ_CONTROL
Definition: nt_native.h:58
BOOL WINAPI GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID *pOwner, LPBOOL lpbOwnerDefaulted)
Definition: sec.c:103
#define _T(x)
Definition: vfdio.h:22
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define LookupAccountSid
Definition: winbase.h:3802
#define OWNER_SECURITY_INFORMATION
Definition: setypes.h:123
struct _SECURITY_DESCRIPTOR * PISECURITY_DESCRIPTOR
char TCHAR
Definition: xmlstorage.h:189
#define _tcsnicmp
Definition: xmlstorage.h:207
#define _tcsicmp
Definition: xmlstorage.h:205

◆ GetHelpShortDescriptionString()

const TCHAR * CShellCommandOwner::GetHelpShortDescriptionString ( )
virtual

Implements CShellCommand.

Definition at line 243 of file ShellCommandOwner.cpp.

244{
246}
#define OWNER_CMD_SHORT_DESC

◆ GetHelpString()

const TCHAR * CShellCommandOwner::GetHelpString ( )
virtual

Implements CShellCommand.

Definition at line 234 of file ShellCommandOwner.cpp.

235{
237 _T("Syntax: ") OWNER_CMD _T(" [<KEY>] [/?]\n\n")
238 _T(" <KEY> - Optional relative path of desired key.\n")
239 _T(" /? - This help.\n\n")
240 _T("Without parameters, command displays information about owner of current key.\n");
241}
int help
Definition: sort.c:20
static PDB_INFORMATION information
Definition: db.cpp:178
GLdouble n
Definition: glext.h:7729
int desired
Definition: jpeglib.h:1119
struct task_struct * current
Definition: linux.c:32
int about
Definition: msacm.c:1366
Definition: btrfs.h:143
Definition: copy.c:22

Referenced by Execute().

◆ Match()

BOOL CShellCommandOwner::Match ( const TCHAR pchCommand)
virtual

Implements CShellCommand.

Definition at line 47 of file ShellCommandOwner.cpp.

48{
49 if (_tcsicmp(pchCommand,OWNER_CMD) == 0)
50 return TRUE;
51 if (_tcsnicmp(pchCommand,OWNER_CMD _T(".."),OWNER_CMD_LENGTH+2*sizeof(TCHAR)) == 0)
52 return TRUE;
53 if (_tcsnicmp(pchCommand,OWNER_CMD _T("/") ,OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
54 return TRUE;
55 if (_tcsnicmp(pchCommand,OWNER_CMD _T("\\"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
56 return TRUE;
57 return FALSE;
58}

Member Data Documentation

◆ m_rTree

CRegistryTree& CShellCommandOwner::m_rTree
private

Definition at line 22 of file ShellCommandOwner.h.

Referenced by Execute().


The documentation for this class was generated from the following files: