]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/SecItemDb.h
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / 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 #include "securityd_client.h"
33
34 __BEGIN_DECLS
35
36 #if 0
37 //
38 // MARK: SecItemDb (a SecDb of SecDbItems)
39 //
40 typedef struct SecItemDb *SecItemDbRef;
41 typedef struct SecItemDbConnection *SecItemDbConnectionRef;
42
43 struct SecItemDb {
44 CFRuntimeBase _base;
45 SecDbRef db;
46 CFDictionaryRef classes; // className -> SecItemClass mapping
47 };
48
49 struct SecItemDbConnection {
50 SecDbConnectionRef db;
51 };
52
53 SecItemDbRef SecItemDbCreate(SecDbRef db);
54 SecItemDbRef SecItemDbRegisterClass(SecItemDbRef db, const SecDbClass *class, void(^upgrade)(SecDbItemRef item, uint32_t current_version));
55
56 SecItemDbConnectionRef SecItemDbAcquireConnection(SecItemDbRef db);
57 void SecItemDbReleaseConnection(SecItemDbRef db, SecItemDbConnectionRef dbconn);
58
59 bool SecItemDbInsert(SecItemDbConnectionRef dbconn, SecDbItemRef item, CFErrorRef *error);
60
61 bool SecItemDbDelete(SecItemDbConnectionRef dbconn, SecDbItemRef item, CFErrorRef *error);
62
63 // Low level update, just do the update
64 bool SecItemDbDoUpdate(SecItemDbConnectionRef dbconn, SecDbItemRef old_item, SecDbItemRef new_item, CFErrorRef *error,
65 bool (^use_attr_in_where)(const SecDbAttr *attr));
66
67 // High level update, will replace tombstones and create them if needed.
68 bool SecItemDbUpdate(SecItemDbConnectionRef dbconn, SecDbItemRef old_item, SecDbItemRef new_item, CFErrorRef *error);
69
70 bool SecItemDbSelect(SecItemDbConnectionRef dbconn, SecDbQueryRef query, CFErrorRef *error,
71 bool (^use_attr_in_where)(const SecDbAttr *attr),
72 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere),
73 bool (^bind_added_where)(sqlite3_stmt *stmt, int col),
74 void (^handle_row)(SecDbItemRef item, bool *stop));
75 #endif
76
77
78 bool SecItemDbCreateSchema(SecDbConnectionRef dbt, const SecDbSchema *schema, bool includeVersion, CFErrorRef *error);
79
80 bool SecItemDbDeleteSchema(SecDbConnectionRef dbt, const SecDbSchema *schema, CFErrorRef *error);
81
82 CFTypeRef SecDbItemCopyResult(SecDbItemRef item, ReturnTypeMask return_type, CFErrorRef *error);
83
84 bool SecDbItemSelect(SecDbQueryRef query, SecDbConnectionRef dbconn, CFErrorRef *error,
85 bool (^return_attr)(const SecDbAttr *attr),
86 bool (^use_attr_in_where)(const SecDbAttr *attr),
87 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere),
88 bool (^bind_added_where)(sqlite3_stmt *stmt, int col),
89 void (^handle_row)(SecDbItemRef item, bool *stop));
90
91 CFStringRef SecDbItemCopySelectSQL(SecDbQueryRef query,
92 bool (^return_attr)(const SecDbAttr *attr),
93 bool (^use_attr_in_where)(const SecDbAttr *attr),
94 bool (^add_where_sql)(CFMutableStringRef sql, bool *needWhere));
95 bool SecDbItemSelectBind(SecDbQueryRef query, sqlite3_stmt *stmt, CFErrorRef *error,
96 bool (^use_attr_in_where)(const SecDbAttr *attr),
97 bool (^bind_added_where)(sqlite3_stmt *stmt, int col));
98
99 bool SecDbItemQuery(SecDbQueryRef query, CFArrayRef accessGroups, SecDbConnectionRef dbconn, CFErrorRef *error,
100 void (^handle_row)(SecDbItemRef item, bool *stop));
101
102 void query_pre_add(Query *q, bool force_date);
103
104 //
105 // MARK: backup restore stuff
106 //
107
108 /* Forward declaration of import export SPIs. */
109 enum SecItemFilter {
110 kSecNoItemFilter,
111 kSecSysBoundItemFilter,
112 kSecBackupableItemFilter,
113 };
114
115 CFDictionaryRef SecServerCopyKeychainPlist(SecDbConnectionRef dbt,
116 SecurityClient *client,
117 keybag_handle_t src_keybag,
118 keybag_handle_t dest_keybag,
119 enum SecItemFilter filter,
120 CFErrorRef *error);
121 bool SecServerImportKeychainInPlist(SecDbConnectionRef dbt,
122 SecurityClient *client,
123 keybag_handle_t src_keybag,
124 keybag_handle_t dest_keybag,
125 CFDictionaryRef keychain,
126 enum SecItemFilter filter,
127 CFErrorRef *error);
128
129 CFStringRef
130 SecServerBackupGetKeybagUUID(CFDictionaryRef keychain);
131
132
133 #if TARGET_OS_IPHONE
134 bool SecServerDeleteAllForUser(SecDbConnectionRef dbt, CFDataRef musrView, bool keepU, CFErrorRef *error);
135 #endif
136
137 bool kc_transaction(SecDbConnectionRef dbt, CFErrorRef *error, bool(^perform)());
138 bool s3dl_copy_matching(SecDbConnectionRef dbt, Query *q, CFTypeRef *result,
139 CFArrayRef accessGroups, CFErrorRef *error);
140 bool s3dl_query_add(SecDbConnectionRef dbt, Query *q, CFTypeRef *result, CFErrorRef *error);
141 bool s3dl_query_update(SecDbConnectionRef dbt, Query *q,
142 CFDictionaryRef attributesToUpdate, CFArrayRef accessGroups, CFErrorRef *error);
143 bool s3dl_query_delete(SecDbConnectionRef dbt, Query *q, CFArrayRef accessGroups, CFErrorRef *error);
144 const SecDbAttr *SecDbAttrWithKey(const SecDbClass *c, CFTypeRef key, CFErrorRef *error);
145
146 bool s3dl_dbt_keys_current(SecDbConnectionRef dbt, uint32_t current_generation, CFErrorRef *error);
147 bool s3dl_dbt_update_keys(SecDbConnectionRef dbt, SecurityClient *client, CFErrorRef *error);
148
149 __END_DECLS
150
151 #endif /* _SECURITYD_SECITEMDB_H_ */