]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCPreferencesInternal.h
configd-1061.101.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCPreferencesInternal.h
1 /*
2 * Copyright (c) 2000, 2001, 2003-2005, 2007-2011, 2013-2020 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 #ifndef _SCPREFERENCESINTERNAL_H
25 #define _SCPREFERENCESINTERNAL_H
26
27 #include <dispatch/dispatch.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <sys/time.h>
31 #include <os/log.h>
32 #include <os/state_private.h>
33 #include <CoreFoundation/CoreFoundation.h>
34 #include <CoreFoundation/CFRuntime.h>
35
36 #ifndef SC_LOG_HANDLE
37 #define SC_LOG_HANDLE __log_SCPreferences
38 #endif // SC_LOG_HANDLE
39 #include <SystemConfiguration/SystemConfiguration.h>
40 #include <SystemConfiguration/SCValidation.h>
41 #include <SystemConfiguration/SCPrivate.h>
42
43 #include <SystemConfiguration/SCPreferences.h>
44 #include <SystemConfiguration/SCDynamicStore.h>
45
46
47 #define PREFS_DEFAULT_DIR_PATH_RELATIVE "Library/Preferences/SystemConfiguration"
48 #define PREFS_DEFAULT_DIR_RELATIVE CFSTR(PREFS_DEFAULT_DIR_PATH_RELATIVE "/")
49
50 #define PREFS_DEFAULT_DIR_PATH "/" PREFS_DEFAULT_DIR_PATH_RELATIVE
51 #define PREFS_DEFAULT_DIR CFSTR(PREFS_DEFAULT_DIR_PATH)
52
53 #define PREFS_DEFAULT_CONFIG_PLIST "preferences.plist"
54 #define PREFS_DEFAULT_CONFIG CFSTR(PREFS_DEFAULT_CONFIG_PLIST)
55
56 #define PREFS_DEFAULT_DIR_OLD CFSTR("/var/db/SystemConfiguration")
57 #define PREFS_DEFAULT_CONFIG_OLD CFSTR("preferences.xml")
58
59 #define PREFS_DEFAULT_USER_DIR CFSTR("Library/Preferences")
60
61 #define INTERFACES_DEFAULT_CONFIG_PLIST "NetworkInterfaces.plist"
62 #define INTERFACES_DEFAULT_CONFIG CFSTR(INTERFACES_DEFAULT_CONFIG_PLIST)
63 #define INTERFACES CFSTR("Interfaces")
64
65
66 /* Define the per-preference-handle structure */
67 typedef struct {
68
69 /* base CFType information */
70 CFRuntimeBase cfBase;
71
72 /* lock */
73 pthread_mutex_t lock;
74
75 /* session name */
76 CFStringRef name;
77
78 /* preferences ID */
79 CFStringRef prefsID;
80
81 /* options */
82 CFDictionaryRef options;
83
84 /* configuration file */
85 char *path;
86 char *newPath;
87
88 /* preferences lock, lock file */
89 Boolean locked;
90 int lockFD;
91 char *lockPath;
92 struct timeval lockTime;
93
94 /* configuration file signature */
95 CFDataRef signature;
96
97 /* configd session */
98 SCDynamicStoreRef session;
99 SCDynamicStoreRef sessionNoO_EXLOCK;
100 int sessionRefcnt;
101
102 /* configd session keys */
103 CFStringRef sessionKeyLock;
104 CFStringRef sessionKeyCommit;
105 CFStringRef sessionKeyApply;
106
107 /* run loop source, callout, context, rl scheduling info */
108 Boolean scheduled;
109 CFRunLoopSourceRef rls;
110 SCPreferencesCallBack rlsFunction;
111 SCPreferencesContext rlsContext;
112 CFMutableArrayRef rlList;
113 dispatch_queue_t dispatchQueue; // SCPreferencesSetDispatchQueue
114
115 /* preferences */
116 CFMutableDictionaryRef prefs;
117
118 /* companion preferences, manipulate under lock */
119 SCPreferencesRef parent; // [strong] reference from companion to parent
120 CFMutableDictionaryRef companions; // [weak] reference from parent to companions
121
122 /* flags */
123 Boolean accessed;
124 Boolean changed;
125 Boolean isRoot;
126 uint32_t nc_flags; // SCNetworkConfiguration flags
127
128 /* authorization, helper */
129 CFDataRef authorizationData;
130 mach_port_t helper_port;
131
132 } SCPreferencesPrivate, *SCPreferencesPrivateRef;
133
134
135 /* Define signature data */
136 typedef struct {
137 int64_t st_dev; /* inode's device */
138 uint64_t st_ino; /* inode's number */
139 uint64_t tv_sec; /* time of last data modification */
140 uint64_t tv_nsec;
141 off_t st_size; /* file size, in bytes */
142 } SCPSignatureData, *SCPSignatureDataRef;
143
144
145 __BEGIN_DECLS
146
147 static __inline__ CFTypeRef
148 isA_SCPreferences(CFTypeRef obj)
149 {
150 return (isA_CFType(obj, SCPreferencesGetTypeID()));
151 }
152
153 os_log_t
154 __log_SCPreferences (void);
155
156 Boolean
157 __SCPreferencesCreate_helper (SCPreferencesRef prefs);
158
159 void
160 __SCPreferencesAccess (SCPreferencesRef prefs);
161
162 void
163 __SCPreferencesAddSessionKeys (SCPreferencesRef prefs);
164
165 Boolean
166 __SCPreferencesAddSession (SCPreferencesRef prefs);
167
168 void
169 __SCPreferencesRemoveSession (SCPreferencesRef prefs);
170
171 void
172 __SCPreferencesUpdateLockedState (SCPreferencesRef prefs,
173 Boolean locked);
174
175 CF_RETURNS_RETAINED
176 CFDataRef
177 __SCPSignatureFromStatbuf (const struct stat *statBuf);
178
179 char *
180 __SCPreferencesPath (CFAllocatorRef allocator,
181 CFStringRef prefsID,
182 Boolean useNewPrefs);
183
184 off_t
185 __SCPreferencesPrefsSize (SCPreferencesRef prefs);
186
187 CF_RETURNS_RETAINED
188 CFStringRef
189 _SCPNotificationKey (CFAllocatorRef allocator,
190 CFStringRef prefsID,
191 int keyType);
192
193 uint32_t
194 __SCPreferencesGetNetworkConfigurationFlags
195 (SCPreferencesRef prefs);
196
197 void
198 __SCPreferencesSetNetworkConfigurationFlags
199 (SCPreferencesRef prefs,
200 uint32_t nc_flags);
201
202 Boolean
203 __SCPreferencesUsingDefaultPrefs (SCPreferencesRef prefs);
204
205 SCPreferencesRef
206 __SCPreferencesCreateNIPrefsFromPrefs (SCPreferencesRef prefs);
207
208 __END_DECLS
209
210 #endif /* _SCPREFERENCESINTERNAL_H */