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.
24 #define __FUNCTION__ "<function>"
27 /* True this when security is implemented */
28 #define CHECK_SAM FALSE
30 #define xERROR(s,d) fprintf(stderr, "%s:#%d(Status=%ld)\n", __FUNCTION__,s,d)
33 * NOTES: These individual routines are listed in alphabetical order.
35 * They are meant to test error conditions. Success conditions are
36 * tested in the sequences found at the end.
39 /******************************************************************************
46 lSts
= RegCloseKey((HKEY
)2);
47 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
49 lSts
= RegCloseKey(HKEY_LOCAL_MACHINE
);
50 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
52 /* Check twice just for kicks */
53 lSts
= RegCloseKey(HKEY_LOCAL_MACHINE
);
54 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
57 /******************************************************************************
60 void TestConnectRegistry()
65 lSts
= RegConnectRegistry("",(HKEY
)2,&hkey
);
66 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
68 lSts
= RegConnectRegistry("",HKEY_LOCAL_MACHINE
,&hkey
);
69 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
72 lSts
= RegConnectRegistry("\\\\regtest",HKEY_LOCAL_MACHINE
,&hkey
);
73 if (lSts
!= ERROR_BAD_NETPATH
) xERROR(3,lSts
);
77 /******************************************************************************
85 lSts
= RegCreateKey((HKEY
)2,"",&hkey
);
86 if (lSts
!= ERROR_BADKEY
) xERROR(1,lSts
);
88 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"",&hkey
);
89 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
92 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"\\asdf",&hkey
);
93 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(3,lSts
);
96 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"asdf\\",&hkey
);
97 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
100 lSts
= RegCreateKey(HKEY_LOCAL_MACHINE
,"\\asdf\\",&hkey
);
101 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(5,lSts
);
104 /******************************************************************************
107 void TestCreateKeyEx()
113 lSts
= RegCreateKeyEx((HKEY
)2,"",0,"",0,0,NULL
,&hkey
,&dwDisp
);
114 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
116 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"",0,0,NULL
,&hkey
,
118 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
120 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"asdf",0,
121 KEY_ALL_ACCESS
,NULL
,&hkey
,&dwDisp
);
122 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
124 lSts
= RegCreateKeyEx(HKEY_LOCAL_MACHINE
,"regtest",0,"",0,
125 KEY_ALL_ACCESS
,NULL
,&hkey
,&dwDisp
);
126 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
130 /******************************************************************************
137 lSts
= RegDeleteKey((HKEY
)2, "asdf");
138 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
140 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "asdf");
141 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(2,lSts
);
144 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "");
145 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(3,lSts
);
149 /******************************************************************************
152 void TestDeleteValue()
156 lSts
= RegDeleteValue((HKEY
)2, "asdf");
157 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
159 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "");
160 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(2,lSts
);
162 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "asdf");
163 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
165 lSts
= RegDeleteValue(HKEY_CURRENT_USER
, "\\asdf");
166 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(4,lSts
);
169 /******************************************************************************
179 sVal
= (char *)malloc(lVal
* sizeof(char));
181 lSts
= RegEnumKey((HKEY
)2,3,sVal
,lVal
);
182 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
184 lSts
= RegEnumKey(HKEY_CURRENT_USER
,-1,sVal
,lVal
);
185 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(2,lSts
);
187 lSts
= RegEnumKey(HKEY_CURRENT_USER
,0,sVal
,lVal
);
188 if (lSts
!= ERROR_MORE_DATA
) xERROR(3,lSts
);
191 /******************************************************************************
204 sVal
= (char *)malloc(lLen1
* sizeof(char));
206 sClass
= (char *)malloc(lLen2
* sizeof(char));
208 lSts
= RegEnumKeyEx((HKEY
)2,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
209 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
211 lSts
= RegEnumKeyEx(HKEY_LOCAL_MACHINE
,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
212 if (lSts
!= ERROR_MORE_DATA
) xERROR(2,lSts
);
214 lSts
= RegEnumKeyEx(HKEY_LOCAL_MACHINE
,0,sVal
,&lLen1
,0,sClass
,&lLen2
,&ft
);
215 if (lSts
!= ERROR_MORE_DATA
) xERROR(3,lSts
);
218 /******************************************************************************
231 sVal
= (char *)malloc(lVal
* sizeof(char));
233 bVal
= (char *)malloc(lLen1
* sizeof(char));
235 lSts
= RegEnumValue((HKEY
)2,-1,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
236 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
238 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,-1,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
239 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(2,lSts
);
241 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,0,sVal
,&lVal
,0,&lType
,NULL
,&lLen1
);
242 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
244 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,0,sVal
,&lVal
,0,NULL
,NULL
,&lLen1
);
245 if (lSts
!= ERROR_SUCCESS
) xERROR(4,lSts
);
247 lSts
= RegEnumValue(HKEY_LOCAL_MACHINE
,1,sVal
,&lVal
,0,&lType
,bVal
,&lLen1
);
248 if (lSts
!= ERROR_NO_MORE_ITEMS
) xERROR(5,lSts
);
251 /******************************************************************************
258 lSts
= RegFlushKey((HKEY
)2);
259 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
261 lSts
= RegFlushKey(HKEY_LOCAL_MACHINE
);
262 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
265 /******************************************************************************
268 void TestGetKeySecurity()
271 SECURITY_INFORMATION si
;
272 SECURITY_DESCRIPTOR sd
;
277 lSts
= RegGetKeySecurity((HKEY
)2,si
,&sd
,&lLen
);
278 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
280 lSts
= RegGetKeySecurity(HKEY_LOCAL_MACHINE
,si
,&sd
,&lLen
);
281 if (lSts
!= ERROR_INSUFFICIENT_BUFFER
) xERROR(2,lSts
);
283 si
= GROUP_SECURITY_INFORMATION
;
284 lSts
= RegGetKeySecurity(HKEY_LOCAL_MACHINE
,si
,&sd
,&lLen
);
285 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
288 /******************************************************************************
295 lSts
= RegLoadKey((HKEY
)2,"","");
296 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
298 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"","");
299 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
301 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"regtest","");
302 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
304 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"\\regtest","");
305 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
308 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"regtest","regtest.dat");
309 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(5,lSts
);
311 lSts
= RegLoadKey(HKEY_CURRENT_USER
,"\\regtest","regtest.dat");
312 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(6,lSts
);
316 /******************************************************************************
317 * TestNotifyChangeKeyValue
319 void TestNotifyChangeKeyValue()
326 lSts
= RegNotifyChangeKeyValue((HKEY
)2, TRUE
, REG_NOTIFY_CHANGE_NAME
, 0, 0);
327 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
329 lSts
= RegNotifyChangeKeyValue(HKEY_CURRENT_USER
, TRUE
, REG_NOTIFY_CHANGE_NAME
, 0, 1);
330 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
332 hEvent
= (HANDLE
)HKEY_CURRENT_USER
;
333 lSts
= RegNotifyChangeKeyValue(HKEY_CURRENT_USER
, TRUE
, REG_NOTIFY_CHANGE_NAME
, hEvent
, 1);
334 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(3,lSts
);
337 /******************************************************************************
345 lSts
= RegOpenKey((HKEY
)72, "",&hkey
);
346 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
349 lSts
= RegOpenKey((HKEY
)2, "regtest",&hkey
);
350 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(2,lSts
);
352 lSts
= RegOpenKey(HKEY_CURRENT_USER
, "regtest",&hkey
);
353 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
355 lSts
= RegOpenKey(HKEY_CURRENT_USER
, "\\regtest",&hkey
);
356 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(4,lSts
);
359 /******************************************************************************
367 lSts
= RegOpenKeyEx((HKEY
)2,"",0,KEY_ALL_ACCESS
,&hkey
);
368 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
370 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"\\regtest",0,KEY_ALL_ACCESS
,&hkey
);
371 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(2,lSts
);
373 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"regtest",0,0,&hkey
);
374 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
376 lSts
= RegOpenKeyEx(HKEY_CURRENT_USER
,"regtest\\",0,0,&hkey
);
377 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(4,lSts
);
380 /******************************************************************************
383 void TestQueryInfoKey()
387 unsigned long lClass
;
388 unsigned long lSubKeys
;
389 unsigned long lMaxSubLen
;
390 unsigned long lMaxClassLen
;
391 unsigned long lValues
;
392 unsigned long lMaxValNameLen
;
393 unsigned long lMaxValLen
;
394 unsigned long lSecDescLen
;
398 sClass
= (char *)malloc(lClass
* sizeof(char));
400 lSts
= RegQueryInfoKey((HKEY
)2,sClass
,&lClass
,0,&lSubKeys
,&lMaxSubLen
,
401 &lMaxClassLen
,&lValues
,&lMaxValNameLen
,&lMaxValLen
,
403 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
405 lSts
= RegQueryInfoKey(HKEY_CURRENT_USER
,sClass
,&lClass
,0,&lSubKeys
,
406 &lMaxSubLen
,&lMaxClassLen
,&lValues
,&lMaxValNameLen
,
407 &lMaxValLen
,&lSecDescLen
, &ft
);
408 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
411 /******************************************************************************
414 void TestQueryValue()
420 sVal
= (char *)malloc(80 * sizeof(char));
423 lSts
= RegQueryValue((HKEY
)2,"",NULL
,&lLen
);
424 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
426 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"",NULL
,&lLen
);
427 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
429 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"\\regtest",NULL
,&lLen
);
430 if (lSts
!= ERROR_BAD_PATHNAME
) xERROR(3,lSts
);
432 lSts
= RegQueryValue(HKEY_CURRENT_USER
,"",sVal
,&lLen
);
433 if (lSts
!= ERROR_SUCCESS
) xERROR(4,lSts
);
436 /******************************************************************************
439 void TestQueryValueEx()
447 sVal
= (char *)malloc(lLen
* sizeof(char));
449 lSts
= RegQueryValueEx((HKEY
)2,"",0,&lType
,sVal
,&lLen
);
450 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
452 lSts
= RegQueryValueEx(HKEY_CURRENT_USER
,"",(LPDWORD
)1,&lType
,sVal
,&lLen
);
453 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
455 lSts
= RegQueryValueEx(HKEY_LOCAL_MACHINE
,"",0,&lType
,sVal
,&lLen
);
456 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
459 /******************************************************************************
462 void TestReplaceKey()
466 lSts
= RegReplaceKey((HKEY
)2,"","","");
467 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
470 lSts
= RegReplaceKey(HKEY_LOCAL_MACHINE
,"","","");
471 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(2,lSts
);
473 lSts
= RegReplaceKey(HKEY_LOCAL_MACHINE
,"Software","","");
474 if (lSts
!= ERROR_ACCESS_DENIED
) xERROR(3,lSts
);
478 /******************************************************************************
481 void TestRestoreKey()
485 lSts
= RegRestoreKey((HKEY
)2,"",0);
486 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
488 lSts
= RegRestoreKey(HKEY_LOCAL_MACHINE
,"",0);
489 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
491 lSts
= RegRestoreKey(HKEY_LOCAL_MACHINE
,"a.a",0);
492 if (lSts
!= ERROR_FILE_NOT_FOUND
) xERROR(3,lSts
);
495 /******************************************************************************
502 lSts
= RegSaveKey((HKEY
)2,"",NULL
);
503 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
505 lSts
= RegSaveKey(HKEY_LOCAL_MACHINE
,"",NULL
);
506 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
509 lSts
= RegSaveKey(HKEY_LOCAL_MACHINE
,"a.a",NULL
);
510 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(3,lSts
);
514 /******************************************************************************
517 void TestSetKeySecurity()
520 SECURITY_DESCRIPTOR sd
;
522 lSts
= RegSetKeySecurity((HKEY
)2,0,NULL
);
523 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
525 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,0,NULL
);
526 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
528 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,OWNER_SECURITY_INFORMATION
,NULL
);
529 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(3,lSts
);
531 lSts
= RegSetKeySecurity(HKEY_LOCAL_MACHINE
,OWNER_SECURITY_INFORMATION
,&sd
);
532 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(4,lSts
);
535 /******************************************************************************
545 lSts
= RegSetValue((HKEY
)2,"",0,NULL
,0);
546 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(1,lSts
);
550 lSts
= RegSetValue((HKEY
)2,"regtest",0,NULL
,0);
551 if (lSts
!= ERROR_INVALID_PARAMETER
) xERROR(2,lSts
);
555 lSts
= RegSetValue((HKEY
)2,"regtest",REG_SZ
,NULL
,0);
556 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(3,lSts
);
560 lSts
= RegSetValue(HKEY_LOCAL_MACHINE
,"regtest",REG_SZ
,NULL
,0);
561 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(4,lSts
);
565 /******************************************************************************
568 void TestSetValueEx()
572 lSts
= RegSetValueEx((HKEY
)2,"",0,0,NULL
,0);
573 if (lSts
!= ERROR_INVALID_HANDLE
) xERROR(1,lSts
);
575 lSts
= RegSetValueEx(HKEY_LOCAL_MACHINE
,"",0,0,NULL
,0);
576 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
579 /******************************************************************************
589 lSts
= RegUnLoadKey((HKEY
)2,"");
590 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(1,lSts
);
592 lSts
= RegUnLoadKey(HKEY_LOCAL_MACHINE
,"");
593 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(2,lSts
);
595 lSts
= RegUnLoadKey(HKEY_LOCAL_MACHINE
,"\\regtest");
596 if (lSts
!= ERROR_PRIVILEGE_NOT_HELD
) xERROR(3,lSts
);
600 /******************************************************************************
608 lSts
= RegCreateKey(HKEY_CURRENT_USER
,"regtest",&hkey
);
609 if (lSts
!= ERROR_SUCCESS
) xERROR(1,lSts
);
611 /* fprintf(stderr, " hkey=0x%x\n", hkey); */
613 lSts
= RegDeleteKey(HKEY_CURRENT_USER
, "regtest");
614 if (lSts
!= ERROR_SUCCESS
) xERROR(2,lSts
);
615 lSts
= RegCloseKey(hkey
);
616 if (lSts
!= ERROR_SUCCESS
) xERROR(3,lSts
);
620 int PASCAL
WinMain (HANDLE inst
, HANDLE prev
, LPSTR cmdline
, int show
)
623 /* These can be in any order */
625 TestConnectRegistry();
634 TestGetKeySecurity();
636 TestNotifyChangeKeyValue();
645 TestSetKeySecurity();
650 /* Now we have some sequence testing */