2 * Registry testing program
4 * Copyright 1998 Matthew Becker
6 * The return codes were generated in an NT40 environment, using lcc-win32
9 * When compiling under lcc-win32, I get three (3) warning, but they all
10 * seem to be issues with lcc.
12 * If creating a new testing sequence, please try to clean up any
13 * registry changes that are made.
23 /* True this when security is implemented */
24 #define CHECK_SAM FALSE
26 #define xERROR(s,d) fprintf(stderr, "%s:#%d(Status=%ld)\n", __FUNCTION__,s,d)
29 * NOTES: These individual routines are listed in alphabetical order.
31 * They are meant to test error conditions. Success conditions are
32 * tested in the sequences found at the end.
35 /******************************************************************************
42 lSts = RegCloseKey((HKEY)2);
43 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
45 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
46 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
48 /* Check twice just for kicks */
49 lSts = RegCloseKey(HKEY_LOCAL_MACHINE);
50 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
53 /******************************************************************************
56 void TestConnectRegistry()
61 lSts = RegConnectRegistry("",(HKEY)2,&hkey);
62 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
64 lSts = RegConnectRegistry("",HKEY_LOCAL_MACHINE,&hkey);
65 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
68 lSts = RegConnectRegistry("\\\\regtest",HKEY_LOCAL_MACHINE,&hkey);
69 if (lSts != ERROR_BAD_NETPATH) xERROR(3,lSts);
73 /******************************************************************************
81 lSts = RegCreateKey((HKEY)2,"",&hkey);
82 if (lSts != ERROR_BADKEY) xERROR(1,lSts);
84 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"",&hkey);
85 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
88 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"\\asdf",&hkey);
89 if (lSts != ERROR_BAD_PATHNAME) xERROR(3,lSts);
92 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"asdf\\",&hkey);
93 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
96 lSts = RegCreateKey(HKEY_LOCAL_MACHINE,"\\asdf\\",&hkey);
97 if (lSts != ERROR_BAD_PATHNAME) xERROR(5,lSts);
100 /******************************************************************************
103 void TestCreateKeyEx()
109 lSts = RegCreateKeyEx((HKEY)2,"",0,"",0,0,NULL,&hkey,&dwDisp);
110 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
112 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"",0,0,NULL,&hkey,
114 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
116 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"asdf",0,
117 KEY_ALL_ACCESS,NULL,&hkey,&dwDisp);
118 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
120 lSts = RegCreateKeyEx(HKEY_LOCAL_MACHINE,"regtest",0,"",0,
121 KEY_ALL_ACCESS,NULL,&hkey,&dwDisp);
122 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
126 /******************************************************************************
133 lSts = RegDeleteKey((HKEY)2, "asdf");
134 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
136 lSts = RegDeleteKey(HKEY_CURRENT_USER, "asdf");
137 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(2,lSts);
140 lSts = RegDeleteKey(HKEY_CURRENT_USER, "");
141 if (lSts != ERROR_ACCESS_DENIED) xERROR(3,lSts);
145 /******************************************************************************
148 void TestDeleteValue()
152 lSts = RegDeleteValue((HKEY)2, "asdf");
153 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
155 lSts = RegDeleteValue(HKEY_CURRENT_USER, "");
156 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(2,lSts);
158 lSts = RegDeleteValue(HKEY_CURRENT_USER, "asdf");
159 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
161 lSts = RegDeleteValue(HKEY_CURRENT_USER, "\\asdf");
162 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(4,lSts);
165 /******************************************************************************
175 sVal = (char *)malloc(lVal * sizeof(char));
177 lSts = RegEnumKey((HKEY)2,3,sVal,lVal);
178 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
180 lSts = RegEnumKey(HKEY_CURRENT_USER,-1,sVal,lVal);
181 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(2,lSts);
183 lSts = RegEnumKey(HKEY_CURRENT_USER,0,sVal,lVal);
184 if (lSts != ERROR_MORE_DATA) xERROR(3,lSts);
187 /******************************************************************************
200 sVal = (char *)malloc(lLen1 * sizeof(char));
202 sClass = (char *)malloc(lLen2 * sizeof(char));
204 lSts = RegEnumKeyEx((HKEY)2,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
205 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
207 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
208 if (lSts != ERROR_MORE_DATA) xERROR(2,lSts);
210 lSts = RegEnumKeyEx(HKEY_LOCAL_MACHINE,0,sVal,&lLen1,0,sClass,&lLen2,&ft);
211 if (lSts != ERROR_MORE_DATA) xERROR(3,lSts);
214 /******************************************************************************
227 sVal = (char *)malloc(lVal * sizeof(char));
229 bVal = (char *)malloc(lLen1 * sizeof(char));
231 lSts = RegEnumValue((HKEY)2,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
232 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
234 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,-1,sVal,&lVal,0,&lType,NULL,&lLen1);
235 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(2,lSts);
237 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,&lType,NULL,&lLen1);
238 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
240 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,0,sVal,&lVal,0,NULL,NULL,&lLen1);
241 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
243 lSts = RegEnumValue(HKEY_LOCAL_MACHINE,1,sVal,&lVal,0,&lType,bVal,&lLen1);
244 if (lSts != ERROR_NO_MORE_ITEMS) xERROR(5,lSts);
247 /******************************************************************************
254 lSts = RegFlushKey((HKEY)2);
255 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
257 lSts = RegFlushKey(HKEY_LOCAL_MACHINE);
258 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
261 /******************************************************************************
264 void TestGetKeySecurity()
267 SECURITY_INFORMATION si;
268 SECURITY_DESCRIPTOR sd;
273 lSts = RegGetKeySecurity((HKEY)2,si,&sd,&lLen);
274 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
276 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
277 if (lSts != ERROR_INSUFFICIENT_BUFFER) xERROR(2,lSts);
279 si = GROUP_SECURITY_INFORMATION;
280 lSts = RegGetKeySecurity(HKEY_LOCAL_MACHINE,si,&sd,&lLen);
281 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
284 /******************************************************************************
291 lSts = RegLoadKey((HKEY)2,"","");
292 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
294 lSts = RegLoadKey(HKEY_CURRENT_USER,"","");
295 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
297 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","");
298 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
300 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","");
301 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
304 lSts = RegLoadKey(HKEY_CURRENT_USER,"regtest","regtest.dat");
305 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(5,lSts);
307 lSts = RegLoadKey(HKEY_CURRENT_USER,"\\regtest","regtest.dat");
308 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(6,lSts);
312 /******************************************************************************
313 * TestNotifyChangeKeyValue
315 void TestNotifyChangeKeyValue()
322 lSts = RegNotifyChangeKeyValue((HKEY)2, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 0);
323 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
325 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, 0, 1);
326 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
328 hEvent = (HANDLE)HKEY_CURRENT_USER;
329 lSts = RegNotifyChangeKeyValue(HKEY_CURRENT_USER, TRUE, REG_NOTIFY_CHANGE_NAME, hEvent, 1);
330 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
333 /******************************************************************************
341 lSts = RegOpenKey((HKEY)72, "",&hkey);
342 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
345 lSts = RegOpenKey((HKEY)2, "regtest",&hkey);
346 if (lSts != ERROR_INVALID_HANDLE) xERROR(2,lSts);
348 lSts = RegOpenKey(HKEY_CURRENT_USER, "regtest",&hkey);
349 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
351 lSts = RegOpenKey(HKEY_CURRENT_USER, "\\regtest",&hkey);
352 if (lSts != ERROR_BAD_PATHNAME) xERROR(4,lSts);
355 /******************************************************************************
363 lSts = RegOpenKeyEx((HKEY)2,"",0,KEY_ALL_ACCESS,&hkey);
364 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
366 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"\\regtest",0,KEY_ALL_ACCESS,&hkey);
367 if (lSts != ERROR_BAD_PATHNAME) xERROR(2,lSts);
369 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest",0,0,&hkey);
370 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
372 lSts = RegOpenKeyEx(HKEY_CURRENT_USER,"regtest\\",0,0,&hkey);
373 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(4,lSts);
376 /******************************************************************************
379 void TestQueryInfoKey()
383 unsigned long lClass;
384 unsigned long lSubKeys;
385 unsigned long lMaxSubLen;
386 unsigned long lMaxClassLen;
387 unsigned long lValues;
388 unsigned long lMaxValNameLen;
389 unsigned long lMaxValLen;
390 unsigned long lSecDescLen;
394 sClass = (char *)malloc(lClass * sizeof(char));
396 lSts = RegQueryInfoKey((HKEY)2,sClass,&lClass,0,&lSubKeys,&lMaxSubLen,
397 &lMaxClassLen,&lValues,&lMaxValNameLen,&lMaxValLen,
399 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
401 lSts = RegQueryInfoKey(HKEY_CURRENT_USER,sClass,&lClass,0,&lSubKeys,
402 &lMaxSubLen,&lMaxClassLen,&lValues,&lMaxValNameLen,
403 &lMaxValLen,&lSecDescLen, &ft);
404 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
407 /******************************************************************************
410 void TestQueryValue()
416 sVal = (char *)malloc(80 * sizeof(char));
419 lSts = RegQueryValue((HKEY)2,"",NULL,&lLen);
420 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
422 lSts = RegQueryValue(HKEY_CURRENT_USER,"",NULL,&lLen);
423 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
425 lSts = RegQueryValue(HKEY_CURRENT_USER,"\\regtest",NULL,&lLen);
426 if (lSts != ERROR_BAD_PATHNAME) xERROR(3,lSts);
428 lSts = RegQueryValue(HKEY_CURRENT_USER,"",sVal,&lLen);
429 if (lSts != ERROR_SUCCESS) xERROR(4,lSts);
432 /******************************************************************************
435 void TestQueryValueEx()
443 sVal = (char *)malloc(lLen * sizeof(char));
445 lSts = RegQueryValueEx((HKEY)2,"",0,&lType,sVal,&lLen);
446 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
448 lSts = RegQueryValueEx(HKEY_CURRENT_USER,"",(LPDWORD)1,&lType,sVal,&lLen);
449 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
451 lSts = RegQueryValueEx(HKEY_LOCAL_MACHINE,"",0,&lType,sVal,&lLen);
452 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
455 /******************************************************************************
458 void TestReplaceKey()
462 lSts = RegReplaceKey((HKEY)2,"","","");
463 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
466 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"","","");
467 if (lSts != ERROR_ACCESS_DENIED) xERROR(2,lSts);
469 lSts = RegReplaceKey(HKEY_LOCAL_MACHINE,"Software","","");
470 if (lSts != ERROR_ACCESS_DENIED) xERROR(3,lSts);
474 /******************************************************************************
477 void TestRestoreKey()
481 lSts = RegRestoreKey((HKEY)2,"",0);
482 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
484 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"",0);
485 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
487 lSts = RegRestoreKey(HKEY_LOCAL_MACHINE,"a.a",0);
488 if (lSts != ERROR_FILE_NOT_FOUND) xERROR(3,lSts);
491 /******************************************************************************
498 lSts = RegSaveKey((HKEY)2,"",NULL);
499 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
501 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"",NULL);
502 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
505 lSts = RegSaveKey(HKEY_LOCAL_MACHINE,"a.a",NULL);
506 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
510 /******************************************************************************
513 void TestSetKeySecurity()
516 SECURITY_DESCRIPTOR sd;
518 lSts = RegSetKeySecurity((HKEY)2,0,NULL);
519 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
521 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,0,NULL);
522 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
524 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,NULL);
525 if (lSts != ERROR_INVALID_PARAMETER) xERROR(3,lSts);
527 lSts = RegSetKeySecurity(HKEY_LOCAL_MACHINE,OWNER_SECURITY_INFORMATION,&sd);
528 if (lSts != ERROR_INVALID_PARAMETER) xERROR(4,lSts);
531 /******************************************************************************
541 lSts = RegSetValue((HKEY)2,"",0,NULL,0);
542 if (lSts != ERROR_INVALID_PARAMETER) xERROR(1,lSts);
546 lSts = RegSetValue((HKEY)2,"regtest",0,NULL,0);
547 if (lSts != ERROR_INVALID_PARAMETER) xERROR(2,lSts);
551 lSts = RegSetValue((HKEY)2,"regtest",REG_SZ,NULL,0);
552 if (lSts != ERROR_INVALID_HANDLE) xERROR(3,lSts);
556 lSts = RegSetValue(HKEY_LOCAL_MACHINE,"regtest",REG_SZ,NULL,0);
557 if (lSts != ERROR_INVALID_HANDLE) xERROR(4,lSts);
561 /******************************************************************************
564 void TestSetValueEx()
568 lSts = RegSetValueEx((HKEY)2,"",0,0,NULL,0);
569 if (lSts != ERROR_INVALID_HANDLE) xERROR(1,lSts);
571 lSts = RegSetValueEx(HKEY_LOCAL_MACHINE,"",0,0,NULL,0);
572 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
575 /******************************************************************************
585 lSts = RegUnLoadKey((HKEY)2,"");
586 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(1,lSts);
588 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"");
589 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(2,lSts);
591 lSts = RegUnLoadKey(HKEY_LOCAL_MACHINE,"\\regtest");
592 if (lSts != ERROR_PRIVILEGE_NOT_HELD) xERROR(3,lSts);
596 /******************************************************************************
604 lSts = RegCreateKey(HKEY_CURRENT_USER,"regtest",&hkey);
605 if (lSts != ERROR_SUCCESS) xERROR(1,lSts);
607 /* fprintf(stderr, " hkey=0x%x\n", hkey); */
609 lSts = RegDeleteKey(HKEY_CURRENT_USER, "regtest");
610 if (lSts != ERROR_SUCCESS) xERROR(2,lSts);
611 lSts = RegCloseKey(hkey);
612 if (lSts != ERROR_SUCCESS) xERROR(3,lSts);
616 int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
619 /* These can be in any order */
621 TestConnectRegistry();
630 TestGetKeySecurity();
632 TestNotifyChangeKeyValue();
641 TestSetKeySecurity();
646 /* Now we have some sequence testing */