fix typos.
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandDOKA.cpp
1 /* $Id$
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 // ShellCommandDOKA.cpp: implementation of the CShellCommandDOKA class.
24 //
25 //////////////////////////////////////////////////////////////////////
26
27 #include "ph.h"
28 #include "ShellCommandDOKA.h"
29 #include "RegistryExplorer.h"
30 #include "SecurityDescriptor.h"
31
32 #define DOKA_CMD _T("DOKA")
33 #define DOKA_CMD_SHORT_DESC DOKA_CMD _T(" command is used to view/edit Desired Open Key Access.\n")
34
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
38
39 CShellCommandDOKA::CShellCommandDOKA(CRegistryTree& rTree):m_rTree(rTree)
40 {
41 }
42
43 CShellCommandDOKA::~CShellCommandDOKA()
44 {
45 }
46
47 BOOL CShellCommandDOKA::Match(const TCHAR *pchCommand)
48 {
49 return _tcsicmp(pchCommand,DOKA_CMD) == 0;
50 }
51
52 int CShellCommandDOKA::Execute(CConsole &rConsole, CArgumentParser& rArguments)
53 {
54 REGSAM Access = m_rTree.GetDesiredOpenKeyAccess();
55 const TCHAR *pchParameter;
56 BOOL blnBadParameter = FALSE;
57 BOOL blnHelp = FALSE;
58
59 while((pchParameter = rArguments.GetNextArgument()) != NULL)
60 {
61 blnBadParameter = FALSE;
62 // Console.Write(_T("Processing parameter: \")");
63 // Console.Write(pchParameter);
64 // Console.Write(_T("\")\n");
65 if ((_tcsicmp(pchParameter,_T("/?")) == 0)
66 ||(_tcsicmp(pchParameter,_T("-?")) == 0))
67 {
68 blnHelp = TRUE;
69 }
70 else if (*pchParameter == _T('-'))
71 {
72 TCHAR a = *(pchParameter+1);
73 if (a == 0)
74 {
75 Access = 0;
76 }
77 else
78 {
79 if (*(pchParameter+2) != 0)
80 {
81 blnBadParameter = TRUE;
82 }
83 else
84 {
85 switch(a)
86 {
87 case _T('l'): // KEY_CREATE_LINK
88 case _T('L'):
89 Access &= ~KEY_CREATE_LINK;
90 break;
91 case _T('c'): // KEY_CREATE_SUB_KEY
92 case _T('C'):
93 Access &= ~KEY_CREATE_SUB_KEY;
94 break;
95 case _T('e'): // KEY_ENUMERATE_SUB_KEYS
96 case _T('E'):
97 Access &= ~KEY_ENUMERATE_SUB_KEYS;
98 break;
99 case _T('n'): // KEY_NOTIFY
100 case _T('N'):
101 Access &= ~KEY_NOTIFY;
102 break;
103 case _T('q'): // KEY_QUERY_VALUE
104 case _T('Q'):
105 Access &= ~KEY_QUERY_VALUE;
106 break;
107 case _T('s'): // KEY_SET_VALUE
108 case _T('S'):
109 Access &= ~KEY_SET_VALUE;
110 break;
111 default:
112 blnBadParameter = TRUE;
113 } // switch
114 } // else (*(pchParameter+2) != 0)
115 } // else (a == 0)
116 } // if (*pchParameter == _T('-'))
117 else if (*pchParameter == _T('+'))
118 {
119 TCHAR a = *(pchParameter+1);
120 if (a == 0)
121 {
122 blnBadParameter = TRUE;
123 }
124 else
125 {
126 if (*(pchParameter+2) != 0)
127 {
128 blnBadParameter = TRUE;
129 }
130 else
131 {
132 switch(a)
133 {
134 case _T('a'): // KEY_ALL_ACCESS
135 case _T('A'):
136 Access |= KEY_ALL_ACCESS;
137 break;
138 case _T('l'): // KEY_CREATE_LINK
139 case _T('L'):
140 Access |= KEY_CREATE_LINK;
141 break;
142 case _T('c'): // KEY_CREATE_SUB_KEY
143 case _T('C'):
144 Access |= KEY_CREATE_SUB_KEY;
145 break;
146 case _T('e'): // KEY_ENUMERATE_SUB_KEYS
147 case _T('E'):
148 Access |= KEY_ENUMERATE_SUB_KEYS;
149 break;
150 case _T('n'): // KEY_NOTIFY
151 case _T('N'):
152 Access |= KEY_NOTIFY;
153 break;
154 case _T('q'): // KEY_QUERY_VALUE
155 case _T('Q'):
156 Access |= KEY_QUERY_VALUE;
157 break;
158 case _T('s'): // KEY_SET_VALUE
159 case _T('S'):
160 Access |= KEY_SET_VALUE;
161 break;
162 // case _T('X'): // KEY_EXECUTE
163 // case _T('x'):
164 // Access |= KEY_EXECUTE;
165 // break;
166 case _T('R'): // KEY_READ
167 case _T('r'):
168 Access |= KEY_READ;
169 break;
170 default:
171 blnBadParameter = TRUE;
172 } // switch
173 } // else (*(pchParameter+2) != 0)
174 } // else (a == 0)
175 } // if (*pchParameter == _T('-'))
176 else
177 {
178 blnBadParameter = TRUE;
179 }
180
181 if (blnBadParameter)
182 {
183 rConsole.Write(_T("Bad parameter: "));
184 rConsole.Write(pchParameter);
185 rConsole.Write(_T("\n"));
186 blnHelp = TRUE;
187 }
188 } // while((pchParameter = Parser.GetNextArgument()) != NULL)
189
190 if (blnHelp)
191 {
192 rConsole.Write(GetHelpString());
193 }
194 else
195 {
196 m_rTree.SetDesiredOpenKeyAccess(Access);
197 rConsole.Write(_T("Desired open key access:\n"));
198 REGSAM Access = m_rTree.GetDesiredOpenKeyAccess();
199 if (Access & KEY_CREATE_LINK)
200 {
201 rConsole.Write(_T("\tKEY_CREATE_LINK - Permission to create a symbolic link.\n"));
202 }
203 if (Access & KEY_CREATE_SUB_KEY)
204 {
205 rConsole.Write(_T("\tKEY_CREATE_SUB_KEY - Permission to create subkeys.\n"));
206 }
207 if (Access & KEY_ENUMERATE_SUB_KEYS)
208 {
209 rConsole.Write(_T("\tKEY_ENUMERATE_SUB_KEYS - Permission to enumerate subkeys.\n"));
210 }
211 if (Access & KEY_NOTIFY)
212 {
213 rConsole.Write(_T("\tKEY_NOTIFY - Permission for change notification.\n"));
214 }
215 if (Access & KEY_QUERY_VALUE)
216 {
217 rConsole.Write(_T("\tKEY_QUERY_VALUE - Permission to query subkey data.\n"));
218 }
219 if (Access & KEY_SET_VALUE)
220 {
221 rConsole.Write(_T("\tKEY_SET_VALUE - Permission to set subkey data.\n"));
222 }
223 }
224 return 0;
225 }
226
227 const TCHAR * CShellCommandDOKA::GetHelpString()
228 {
229 return DOKA_CMD_SHORT_DESC
230 _T("Syntax: ") DOKA_CMD _T(" [Switches] [/?]\n\n")
231 _T(" /? - This help.\n\n")
232 _T("Switches are:\n")
233 _T(" - - Reset all permisions.\n")
234 _T(" -l - Reset permission to create a symbolic link.\n")
235 _T(" -c - Reset permission to create subkeys.\n")
236 _T(" -e - Reset permission to enumerate subkeys.\n")
237 _T(" -n - Reset permission for change notification.\n")
238 _T(" -q - Reset permission to query subkey data.\n")
239 _T(" -s - Reset permission to set subkey data.\n")
240 _T(" +a - Set all permisions.\n")
241 _T(" +l - Set permission to create a symbolic link.\n")
242 _T(" +c - Set permission to create subkeys.\n")
243 _T(" +e - Set permission to enumerate subkeys.\n")
244 _T(" +n - Set permission for change notification.\n")
245 _T(" +q - Set permission to query subkey data.\n")
246 _T(" +s - Set permission to set subkey data.\n")
247 _T(" +r - Equivalent to combination of +q , +e and +n\n\n")
248 _T("Without parameters, command displays current Desired Open Key Access.\n");
249 }
250
251 const TCHAR * CShellCommandDOKA::GetHelpShortDescriptionString()
252 {
253 return DOKA_CMD_SHORT_DESC;
254 }