1/*
2 * kcStatus.cpp
3 *
4 * Open default keychain; get status to actually instatiate the thing; release.
5 */
6#include "testParams.h"
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <Security/Security.h>
11
12/* for malloc debug */
13#define DO_PAUSE	0
14
15/* for tracking down KC crasher */
16#define ABORT_ON_ERROR		1
17
18int kcStatusInit(TestParams *testParams)
19{
20	return 0;
21}
22
23
24int kcStatus(TestParams *testParams)
25{
26	OSStatus			ortn;
27	SecKeychainRef		kcRef;
28	unsigned			loopNum;
29	SecKeychainStatus	kcStatus;
30
31	for(loopNum=0; loopNum<testParams->numLoops; loopNum++) {
32		if(testParams->verbose) {
33			printf("kcStatus loop %d\n", loopNum);
34		}
35		else if(!testParams->quiet) {
36			printChar(testParams->progressChar);
37		}
38
39		ortn = SecKeychainCopyDefault(&kcRef);
40		if(ortn) {
41			cssmPerror("SecKeychainCopyDefault", ortn);
42			if(ABORT_ON_ERROR) {
43				exit(1);
44			}
45			else {
46				return (int)ortn;
47			}
48		}
49		ortn = SecKeychainGetStatus(kcRef, &kcStatus);
50		if(ortn) {
51			cssmPerror("SecKeychainGetStatus", ortn);
52			printf("***HEY! A keychain obtained via SecKeychainCopyDefault() resulted\n");
53			printf("   in a failed SecKeychainGetStatus()! You really need to fix this!\n");
54			printf("kcRef %p\n", kcRef);
55			char path[300];
56			UInt32 len = 300;
57			  ortn = SecKeychainGetPath(kcRef, &len, path);
58			if(ortn) {
59			  cssmPerror("SecKeychainGetPath", ortn);
60			}
61			else {
62			  printf("kc path %s\n", path);
63			}
64			if(ABORT_ON_ERROR) {
65				exit(1);
66			}
67			else {
68				return (int)ortn;
69			}
70		}
71
72		CFRelease(kcRef);
73
74		#if	DO_PAUSE
75		fpurge(stdin);
76		printf("Hit CR to continue: ");
77		getchar();
78		#endif
79	}	/* outer loop */
80	#if HOLD_SEARCH_LIST
81	CFRelease(sl);
82	#endif
83	return 0;
84}
85