]> git.saurik.com Git - apple/security.git/blob - Security/sec/securityd/SecItemDb.h
Security-57031.30.12.tar.gz
[apple/security.git] / Security / sec / securityd / SecItemDb.h
1 /*
2 * Copyright (c) 2013-2014 Apple 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
24 /*!
25 @header SecItemDb.h - A Database full of SecDbItems.
26 */
27
28 #ifndef _SECURITYD_SECITEMDB_H_
29 #define _SECURITYD_SECITEMDB_H_
30
31 #include <securityd/SecDbQuery.h>
32
33 #define CURRENT_DB_VERSION 6
34
35 __BEGIN_DECLS
36
37 #if 0
38 //
39 // MARK: SecItemDb (a SecDb of SecDbItems)
40 //
41 typedef struct SecItemDb *SecItemDbRef;
42 typedef struct SecItemDbConnection *SecItemDbConnectionRef;
43
44 struct SecItemDb {
45 CFRuntimeBase _base;
46 SecDbRef db;
47 CFDictionaryRef classes; // className -> SecItemClass mapping
48 };
49
50 struct SecItemDbConnection {
51 SecDbConnectionRef db;
52 };
53
54 SecItemDbRef SecItemDbCreate(SecDbRef db);
55 SecItemDbRef SecItemDbRegisterClass(SecItemDbRef db, const SecDbClass *class, void(^upgrade)(SecDbItemRef item, uint32_t current_version));
56
57 SecItemDbConnectionRef SecItemDbAquireConnection(SecItemDbRef db);
58 void SecItemDbReleaseConnection(SecItemDbRef db, SecItemDbConnectionRef dbconn);
59
60 bool SecItemDbInsert(SecItemDbConnectionRef dbconn, SecDbItemRef item, CFErrorRef *error);
61
62 bool SecItemDbDelete(SecItemDbConnectionRef dbconn, SecDbItemRef item, CFErrorRef *error);
63
64 // Low level update, just do the update
65 bool SecItemDbDoUpdate(SecItemDbConnectionRef dbconn, SecDbItemRef old_item, SecDbItemRef new_item, CFErrorRef *error,
66 bool (^use_attr_in_where)(const SecDbAttr *attr));
67
68 // High level update, will replace tombstones and create them if needed.
69 bool SecItemDbUpdate(SecItemDbConnectionRef dbconn, SecDbItemRef old_item, SecDbItemRef new_item, CFErrorRef *error);
70
71 bool SecItemDbSelect(SecItemDbConnectionRef dbconn, SecDbQueryRef query, CFErrorRef *error,
72 bool (^use_attr_in_where)(const SecDbAttr *attr),
73 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere),
74 bool (^bind_added_where)(sqlite3_stmt *stmt, int col),
75 void (^handle_row)(SecDbItemRef item, bool *stop));
76 #endif
77
78 CFTypeRef SecDbItemCopyResult(SecDbItemRef item, ReturnTypeMask return_type, CFErrorRef *error);
79
80 bool SecDbItemSelect(SecDbQueryRef query, SecDbConnectionRef dbconn, CFErrorRef *error,
81 bool (^use_attr_in_where)(const SecDbAttr *attr),
82 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere),
83 bool (^bind_added_where)(sqlite3_stmt *stmt, int col),
84 void (^handle_row)(SecDbItemRef item, bool *stop));
85
86 CFStringRef SecDbItemCopySelectSQL(SecDbQueryRef query,
87 bool (^return_attr)(const SecDbAttr *attr),
88 bool (^use_attr_in_where)(const SecDbAttr *attr),
89 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere));
90 bool SecDbItemSelectBind(SecDbQueryRef query, sqlite3_stmt *stmt, CFErrorRef *error,
91 bool (^use_attr_in_where)(const SecDbAttr *attr),
92 bool (^bind_added_where)(sqlite3_stmt *stmt, int col));
93
94 bool SecDbItemQuery(SecDbQueryRef query, CFArrayRef accessGroups, SecDbConnectionRef dbconn, CFErrorRef *error,
95 void (^handle_row)(SecDbItemRef item, bool *stop));
96
97
98 //
99 // MARK: backup restore stuff
100 //
101
102 /* Forward declaration of import export SPIs. */
103 enum SecItemFilter {
104 kSecNoItemFilter,
105 kSecSysBoundItemFilter,
106 kSecBackupableItemFilter,
107 };
108
109 CF_RETURNS_RETAINED CFDictionaryRef SecServerExportKeychainPlist(SecDbConnectionRef dbt,
110 keybag_handle_t src_keybag, keybag_handle_t dest_keybag,
111 enum SecItemFilter filter, CFErrorRef *error);
112 bool SecServerImportKeychainInPlist(SecDbConnectionRef dbt,
113 keybag_handle_t src_keybag, keybag_handle_t dest_keybag,
114 CFDictionaryRef keychain, enum SecItemFilter filter, CFErrorRef *error);
115
116 void SecDbAppendCreateTableWithClass(CFMutableStringRef sql, const SecDbClass *c);
117 bool kc_transaction(SecDbConnectionRef dbt, CFErrorRef *error, bool(^perform)());
118 bool s3dl_copy_matching(SecDbConnectionRef dbt, Query *q, CFTypeRef *result,
119 CFArrayRef accessGroups, CFErrorRef *error);
120 bool s3dl_query_add(SecDbConnectionRef dbt, Query *q, CFTypeRef *result, CFErrorRef *error);
121 bool s3dl_query_update(SecDbConnectionRef dbt, Query *q,
122 CFDictionaryRef attributesToUpdate, CFArrayRef accessGroups, CFErrorRef *error);
123 bool s3dl_query_delete(SecDbConnectionRef dbt, Query *q, CFArrayRef accessGroups, CFErrorRef *error);
124 const SecDbAttr *SecDbAttrWithKey(const SecDbClass *c, CFTypeRef key, CFErrorRef *error);
125
126 bool s3dl_dbt_keys_current(SecDbConnectionRef dbt, uint32_t current_generation, CFErrorRef *error);
127 bool s3dl_dbt_update_keys(SecDbConnectionRef dbt, CFErrorRef *error);
128
129 __END_DECLS
130
131 #endif /* _SECURITYD_SECITEMDB_H_ */