2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 @header SecItemDb.h - A Database full of SecDbItems.
28 #ifndef _SECURITYD_SECITEMDB_H_
29 #define _SECURITYD_SECITEMDB_H_
31 #include "keychain/securityd/SecDbQuery.h"
33 struct SecurityClient
;
37 bool SecItemDbCreateSchema(SecDbConnectionRef dbt
, const SecDbSchema
*schema
, CFArrayRef classIndexesForNewTables
, bool includeVersion
, CFErrorRef
*error
);
39 bool SecItemDbDeleteSchema(SecDbConnectionRef dbt
, const SecDbSchema
*schema
, CFErrorRef
*error
);
41 CFTypeRef
SecDbItemCopyResult(SecDbItemRef item
, ReturnTypeMask return_type
, CFErrorRef
*error
);
43 bool SecDbItemSelect(SecDbQueryRef query
, SecDbConnectionRef dbconn
, CFErrorRef
*error
,
44 bool (^return_attr
)(const SecDbAttr
*attr
),
45 bool (^use_attr_in_where
)(const SecDbAttr
*attr
),
46 bool (^add_where_sql
)(CFMutableStringRef sql
, bool *needWhere
),
47 bool (^bind_added_where
)(sqlite3_stmt
*stmt
, int col
),
48 void (^handle_row
)(SecDbItemRef item
, bool *stop
));
50 CFStringRef
SecDbItemCopySelectSQL(SecDbQueryRef query
,
51 bool (^return_attr
)(const SecDbAttr
*attr
),
52 bool (^use_attr_in_where
)(const SecDbAttr
*attr
),
53 bool (^add_where_sql
)(CFMutableStringRef sql
, bool *needWhere
));
54 bool SecDbItemSelectBind(SecDbQueryRef query
, sqlite3_stmt
*stmt
, CFErrorRef
*error
,
55 bool (^use_attr_in_where
)(const SecDbAttr
*attr
),
56 bool (^bind_added_where
)(sqlite3_stmt
*stmt
, int col
));
58 bool SecDbItemQuery(SecDbQueryRef query
, CFArrayRef accessGroups
, SecDbConnectionRef dbconn
, CFErrorRef
*error
,
59 void (^handle_row
)(SecDbItemRef item
, bool *stop
));
61 void query_pre_add(Query
*q
, bool force_date
);
63 bool SecItemIsSystemBound(CFDictionaryRef item
, const SecDbClass
*cls
, bool multiUser
);
66 // MARK: backup restore stuff
69 /* Forward declaration of import export SPIs. */
72 kSecSysBoundItemFilter
,
73 kSecBackupableItemFilter
,
76 CFDictionaryRef
SecServerCopyKeychainPlist(SecDbConnectionRef dbt
,
77 struct SecurityClient
*client
,
78 keybag_handle_t src_keybag
,
79 keybag_handle_t dest_keybag
,
80 enum SecItemFilter filter
,
82 bool SecServerImportKeychainInPlist(SecDbConnectionRef dbt
,
83 struct SecurityClient
*client
,
84 keybag_handle_t src_keybag
,
85 keybag_handle_t dest_keybag
,
86 CFDictionaryRef keychain
,
87 enum SecItemFilter filter
,
88 bool removeKeychainContent
,
92 SecServerBackupGetKeybagUUID(CFDictionaryRef keychain
, CFErrorRef
*error
);
96 bool SecServerDeleteAllForUser(SecDbConnectionRef dbt
, CFDataRef musrView
, bool keepU
, CFErrorRef
*error
);
99 bool kc_transaction(SecDbConnectionRef dbt
, CFErrorRef
*error
, bool(^perform
)(void));
100 bool kc_transaction_type(SecDbConnectionRef dbt
, SecDbTransactionType type
, CFErrorRef
*error
, bool(^perform
)(void));
101 bool s3dl_copy_matching(SecDbConnectionRef dbt
, Query
*q
, CFTypeRef
*result
,
102 CFArrayRef accessGroups
, CFErrorRef
*error
);
103 bool s3dl_query_add(SecDbConnectionRef dbt
, Query
*q
, CFTypeRef
*result
, CFErrorRef
*error
);
104 bool s3dl_query_update(SecDbConnectionRef dbt
, Query
*q
,
105 CFDictionaryRef attributesToUpdate
, CFArrayRef accessGroups
, CFErrorRef
*error
);
106 bool s3dl_query_delete(SecDbConnectionRef dbt
, Query
*q
, CFArrayRef accessGroups
, CFErrorRef
*error
);
107 bool s3dl_copy_digest(SecDbConnectionRef dbt
, Query
*q
, CFArrayRef
*result
, CFArrayRef accessGroups
, CFErrorRef
*error
);
109 const SecDbAttr
*SecDbAttrWithKey(const SecDbClass
*c
, CFTypeRef key
, CFErrorRef
*error
);
111 bool s3dl_dbt_keys_current(SecDbConnectionRef dbt
, uint32_t current_generation
, CFErrorRef
*error
);
112 bool s3dl_dbt_update_keys(SecDbConnectionRef dbt
, struct SecurityClient
*client
, CFErrorRef
*error
);
114 // We'd love to take a query here, but switching layers at the callsite means we don't have it
115 bool s3dl_item_make_new_uuid(SecDbItemRef item
, bool uuid_from_primary_key
, CFErrorRef
* error
);
119 #endif /* _SECURITYD_SECITEMDB_H_ */