1/*
2 * Copyright (c) 2000, 2001, 2003-2005, 2007-2011, 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#ifndef _SCPREFERENCESINTERNAL_H
25#define _SCPREFERENCESINTERNAL_H
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/time.h>
30#include <CoreFoundation/CoreFoundation.h>
31#include <CoreFoundation/CFRuntime.h>
32#include <SystemConfiguration/SCPreferences.h>
33#include <SystemConfiguration/SCDynamicStore.h>
34#include <dispatch/dispatch.h>
35
36
37#define	PREFS_DEFAULT_DIR		CFSTR("/Library/Preferences/SystemConfiguration")
38#define	PREFS_DEFAULT_CONFIG		CFSTR("preferences.plist")
39
40#define	PREFS_DEFAULT_DIR_OLD		CFSTR("/var/db/SystemConfiguration")
41#define	PREFS_DEFAULT_CONFIG_OLD	CFSTR("preferences.xml")
42
43#define	PREFS_DEFAULT_USER_DIR		CFSTR("Library/Preferences")
44
45#define	NETWORK_INTERFACES_PREFS	CFSTR("NetworkInterfaces.plist")
46#define	INTERFACES			CFSTR("Interfaces")
47
48
49/* Define the per-preference-handle structure */
50typedef struct {
51
52	/* base CFType information */
53	CFRuntimeBase		cfBase;
54
55	/* lock */
56	pthread_mutex_t		lock;
57
58	/* session name */
59	CFStringRef		name;
60
61	/* preferences ID */
62	CFStringRef		prefsID;
63
64	/* options */
65	CFDictionaryRef		options;
66
67	/* configuration file */
68	char			*path;
69	char			*newPath;
70
71	/* preferences lock, lock file */
72	Boolean			locked;
73	int			lockFD;
74	char			*lockPath;
75	struct timeval		lockTime;
76
77	/* configuration file signature */
78	CFDataRef		signature;
79
80	/* configd session */
81	SCDynamicStoreRef	session;
82
83	/* configd session keys */
84	CFStringRef		sessionKeyLock;
85	CFStringRef		sessionKeyCommit;
86	CFStringRef		sessionKeyApply;
87
88	/* run loop source, callout, context, rl scheduling info */
89	Boolean			scheduled;
90	CFRunLoopSourceRef      rls;
91	SCPreferencesCallBack	rlsFunction;
92	SCPreferencesContext	rlsContext;
93	CFMutableArrayRef       rlList;
94	dispatch_queue_t	dispatchQueue;		// SCPreferencesSetDispatchQueue
95
96	/* preferences */
97	CFMutableDictionaryRef	prefs;
98
99	/* flags */
100	Boolean			accessed;
101	Boolean			changed;
102	Boolean			isRoot;
103	Boolean			limit_SCNetworkConfiguration;
104
105	/* authorization, helper */
106	CFDataRef		authorizationData;
107	Boolean			authorizationRequired;
108	mach_port_t		helper_port;
109
110} SCPreferencesPrivate, *SCPreferencesPrivateRef;
111
112
113/* Define signature data */
114typedef struct {
115	int64_t		st_dev;		/* inode's device */
116	uint64_t	st_ino;		/* inode's number */
117	uint64_t	tv_sec;		/* time of last data modification */
118	uint64_t	tv_nsec;
119	off_t		st_size;	/* file size, in bytes */
120} SCPSignatureData, *SCPSignatureDataRef;
121
122
123__BEGIN_DECLS
124
125Boolean
126__SCPreferencesCreate_helper		(SCPreferencesRef	prefs);
127
128void
129__SCPreferencesAccess			(SCPreferencesRef	prefs);
130
131Boolean
132__SCPreferencesAddSession		(SCPreferencesRef       prefs);
133
134CF_RETURNS_RETAINED
135CFDataRef
136__SCPSignatureFromStatbuf		(const struct stat	*statBuf);
137
138char *
139__SCPreferencesPath			(CFAllocatorRef		allocator,
140					 CFStringRef		prefsID,
141					 Boolean		useNewPrefs);
142
143CF_RETURNS_RETAINED
144CFStringRef
145_SCPNotificationKey			(CFAllocatorRef		allocator,
146					 CFStringRef		prefsID,
147					 int			keyType);
148Boolean
149__SCPreferencesGetLimitSCNetworkConfiguration	(SCPreferencesRef prefs);
150
151void
152__SCPreferencesSetLimitSCNetworkConfiguration
153					(SCPreferencesRef	prefs,
154					 Boolean		limit_SCNetworkConfiguration);
155
156Boolean
157__SCPreferencesUsingDefaultPrefs		(SCPreferencesRef	prefs);
158
159SCPreferencesRef
160__SCPreferencesCreateNIPrefsFromPrefs	(SCPreferencesRef prefs);
161
162__END_DECLS
163
164#endif /* _SCPREFERENCESINTERNAL_H */
165