]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/dl/dl-10-create-delete.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / dl / dl-10-create-delete.c
1 /*
2 * Copyright (c) 2005-2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * 00DL_Create-Delete.c
24 */
25
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <Security/cssmapi.h>
29 #include <Security/cssmapple.h>
30
31 #include "testmore.h"
32 #include "testenv.h"
33 #include "testcssm.h"
34 #include "testleaks.h"
35
36 #define DBNAME "testdl.db"
37
38 static CSSM_APPLEDL_OPEN_PARAMETERS openParameters =
39 {
40 sizeof(CSSM_APPLEDL_OPEN_PARAMETERS),
41 CSSM_APPLEDL_OPEN_PARAMETERS_VERSION,
42 CSSM_FALSE,
43 kCSSM_APPLEDL_MASK_MODE,
44 0600
45 };
46 static CSSM_DBINFO dbInfo =
47 {
48 0 /* NumberOfRecordTypes */,
49 NULL,
50 NULL,
51 NULL,
52 CSSM_TRUE /* IsLocal */,
53 NULL, /* AccessPath - URL, dir path, etc. */
54 NULL /* reserved */
55 };
56
57 int
58 static test1(CSSM_DL_HANDLE dl)
59 {
60 int pass = 1;
61 CSSM_DL_DB_HANDLE dldb = { dl };
62
63 /* Case 1 regular create close delete. */
64 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
65 NULL /* DbLocation */,
66 &dbInfo,
67 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
68 NULL /* CredAndAclEntry */,
69 NULL /* &openParameters */,
70 &dldb.DBHandle),
71 "CSSM_DL_DbCreate");
72
73 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
74 pass &= ok_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
75 NULL /* DbLocation */,
76 NULL /* AccessCred */), "CSSM_DL_DbDelete");
77 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
78
79 return pass;
80 }
81
82 int
83 static test2(CSSM_DL_HANDLE dl)
84 {
85 int pass = 1;
86 CSSM_DL_DB_HANDLE dldb = { dl };
87
88 /* Case 2 regular create delete then close. */
89 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
90 NULL /* DbLocation */,
91 &dbInfo,
92 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
93 NULL /* CredAndAclEntry */,
94 NULL /* &openParameters */,
95 &dldb.DBHandle),
96 "CSSM_DL_DbCreate");
97
98 pass &= ok_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
99 NULL /* DbLocation */,
100 NULL /* AccessCred */), "CSSM_DL_DbDelete");
101 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
102 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
103
104 return pass;
105 }
106
107 int
108 static test3(CSSM_DL_HANDLE dl)
109 {
110 int pass = 1;
111 CSSM_DL_DB_HANDLE dldb = { dl };
112
113 /* Case 3 non autocommit create close delete. */
114 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
115 NULL /* DbLocation */,
116 &dbInfo,
117 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
118 NULL /* CredAndAclEntry */,
119 &openParameters,
120 &dldb.DBHandle),
121 "CSSM_DL_DbCreate");
122
123 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
124 pass &= ok_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
125 NULL /* DbLocation */,
126 NULL /* AccessCred */), "CSSM_DL_DbDelete");
127 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
128
129 return pass;
130 }
131
132 int
133 static test4(CSSM_DL_HANDLE dl)
134 {
135 int pass = 1;
136 CSSM_DL_DB_HANDLE dldb = { dl };
137
138 /* Case 4 non autocommit create delete then close. */
139 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
140 NULL /* DbLocation */,
141 &dbInfo,
142 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
143 NULL /* CredAndAclEntry */,
144 &openParameters,
145 &dldb.DBHandle),
146 "CSSM_DL_DbCreate");
147
148 pass &= ok_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
149 NULL /* DbLocation */,
150 NULL /* AccessCred */), "CSSM_DL_DbDelete");
151 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
152 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
153
154 return pass;
155 }
156
157 int
158 static test5(CSSM_DL_HANDLE dl)
159 {
160 int pass = 1;
161 CSSM_DL_DB_HANDLE dldb = { dl };
162
163 /* Case 5 non autocommit create rollback close delete. */
164 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
165 NULL /* DbLocation */,
166 &dbInfo,
167 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
168 NULL /* CredAndAclEntry */,
169 &openParameters,
170 &dldb.DBHandle),
171 "CSSM_DL_DbCreate");
172 pass &= ok_status(CSSM_DL_PassThrough(dldb, CSSM_APPLEFILEDL_ROLLBACK,
173 NULL, NULL), "CSSM_APPLEFILEDL_ROLLBACK");
174 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
175 pass &= is_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
176 NULL /* DbLocation */, NULL /* AccessCred */),
177 CSSMERR_DL_DATASTORE_DOESNOT_EXIST, "CSSM_DL_DbDelete");
178 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
179
180 return pass;
181 }
182
183 int
184 static test6(CSSM_DL_HANDLE dl)
185 {
186 int pass = 1;
187 CSSM_DL_DB_HANDLE dldb = { dl };
188
189 /* Case 6 non autocommit create rollback delete then close. */
190 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
191 NULL /* DbLocation */,
192 &dbInfo,
193 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
194 NULL /* CredAndAclEntry */,
195 &openParameters,
196 &dldb.DBHandle),
197 "CSSM_DL_DbCreate");
198
199 pass &= ok_status(CSSM_DL_PassThrough(dldb, CSSM_APPLEFILEDL_ROLLBACK,
200 NULL, NULL), "CSSM_APPLEFILEDL_ROLLBACK");
201 pass &= is_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
202 NULL /* DbLocation */, NULL /* AccessCred */),
203 CSSMERR_DL_DATASTORE_DOESNOT_EXIST, "CSSM_DL_DbDelete");
204 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
205 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
206
207 return pass;
208 }
209
210 int
211 static test7(CSSM_DL_HANDLE dl)
212 {
213 int pass = 1;
214 CSSM_DL_DB_HANDLE dldb = { dl };
215
216 /* Case 7 non autocommit create delete rollback then close. */
217 pass &= ok_status(CSSM_DL_DbCreate(dldb.DLHandle, DBNAME,
218 NULL /* DbLocation */,
219 &dbInfo,
220 CSSM_DB_ACCESS_READ | CSSM_DB_ACCESS_WRITE,
221 NULL /* CredAndAclEntry */,
222 &openParameters,
223 &dldb.DBHandle),
224 "CSSM_DL_DbCreate");
225
226 pass &= ok_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
227 NULL /* DbLocation */, NULL /* AccessCred */), "CSSM_DL_DbDelete");
228 pass &= ok_status(CSSM_DL_PassThrough(dldb, CSSM_APPLEFILEDL_ROLLBACK,
229 NULL, NULL), "CSSM_APPLEFILEDL_ROLLBACK");
230 pass &= ok_status(CSSM_DL_DbClose(dldb), "CSSM_DL_DbClose");
231 pass &= is_unix(unlink(DBNAME), ENOENT, "unlink");
232
233 return pass;
234 }
235
236 int
237 static test8(CSSM_DL_HANDLE dl)
238 {
239 int pass = 1;
240 CSSM_DL_DB_HANDLE dldb = { dl };
241
242 /* Case 8 delete non existant db. */
243 pass &= is_status(CSSM_DL_DbDelete(dldb.DLHandle, DBNAME,
244 NULL /* DbLocation */, NULL /* AccessCred */),
245 CSSMERR_DL_DATASTORE_DOESNOT_EXIST, "CSSM_DL_DbDelete");
246
247
248 return pass;
249 }
250
251 int
252 main(int argc, char * const *argv)
253 {
254 int guid_alt = argc > 1 && !strcmp(argv[1], "-g");
255 /* {2cb56191-ee6f-432d-a377-853d3c6b949e} */
256 CSSM_GUID s3dl_guid =
257 {
258 0x2cb56191, 0xee6f, 0x432d,
259 { 0xa3, 0x77, 0x85, 0x3d, 0x3c, 0x6b, 0x94, 0x9e }
260 };
261 const CSSM_GUID *guid = guid_alt ? & s3dl_guid : &gGuidAppleFileDL;
262 CSSM_DL_HANDLE dl;
263
264 /* Total number of test cases in this file. */
265 plan_tests(45);
266
267 ok(cssm_attach(guid, &dl), "cssm_attach");
268 ok(tests_begin(argc, argv), "setup");
269
270 /* Run tests. */
271 ok(test1(dl), "create close delete");
272 ok(test2(dl), "create delete close");
273 ok(test3(dl), "autocommit off create close delete");
274 ok(test4(dl), "autocommit off create delete close");
275 ok(test5(dl), "autocommit off create rollback close delete");
276 ok(test6(dl), "autocommit off create rollback delete close");
277 ok(test7(dl), "autocommit off create delete rollback close");
278 ok(test8(dl), "delete non existant db");
279
280 ok(cssm_detach(guid, dl), "cssm_detach");
281 ok(tests_end(1), "cleanup");
282 TODO: {ok_leaks("leaks");}
283
284 return 0;
285 }