]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2012 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 __ASL_COMMON_H__ | |
25 | #define __ASL_COMMON_H__ | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <xpc/xpc.h> | |
29 | #include <asl_msg.h> | |
30 | ||
31 | #define ASL_MODULE_NAME "com.apple.asl" | |
32 | #define _PATH_CRASHREPORTER "/Library/Logs/CrashReporter" | |
33 | #define _PATH_CRASHREPORTER_MOBILE_1 "/var/mobile/Library/Logs/CrashReporter" | |
34 | #define _PATH_CRASHREPORTER_MOBILE_2 "/private/var/mobile/Library/Logs/CrashReporter" | |
35 | #define ASL_INTERNAL_LOGS_DIR "Logs" | |
36 | ||
37 | #define ASL_SERVICE_NAME "com.apple.system.logger" | |
38 | ||
39 | #define CRASH_MOVER_WILL_START_NOTIFICATION "CrashMoverWillStart" | |
40 | ||
41 | #define SECONDS_PER_DAY 86400 | |
42 | #define DEFAULT_TTL (7 * SECONDS_PER_DAY) | |
43 | ||
44 | #define ACTION_NONE 0 | |
45 | #define ACTION_SET_PARAM 1 | |
46 | #define ACTION_OUT_DEST 2 | |
47 | #define ACTION_IGNORE 3 | |
48 | #define ACTION_SKIP 4 | |
49 | #define ACTION_CLAIM 5 | |
50 | #define ACTION_NOTIFY 6 | |
51 | #define ACTION_BROADCAST 7 | |
52 | #define ACTION_ACCESS 8 | |
53 | #define ACTION_SET_KEY 9 | |
54 | #define ACTION_UNSET_KEY 10 | |
55 | #define ACTION_ASL_STORE 11 /* Save in main ASL Database */ | |
56 | #define ACTION_ASL_FILE 12 /* Save in an ASL format data file */ | |
57 | #define ACTION_ASL_DIR 13 /* Save in an ASL directory */ | |
58 | #define ACTION_FILE 14 /* Save in a text file */ | |
59 | #define ACTION_FORWARD 15 | |
60 | #define ACTION_CONTROL 16 | |
61 | #define ACTION_SET_FILE 17 /* = foo [File /a/b/c] */ | |
62 | #define ACTION_SET_PLIST 18 /* = foo [Plist /a/b/c] ... */ | |
63 | #define ACTION_SET_PROF 19 /* = foo [Profile abc] ... */ | |
64 | ||
65 | #define STYLE_SEC_PREFIX_CHAR 'T' | |
66 | ||
67 | #define MODULE_FLAG_HAS_LOGGED 0x80000000 | |
68 | #define MODULE_FLAG_CLEAR_LOGGED 0x7fffffff | |
69 | #define MODULE_FLAG_ENABLED 0x00000001 | |
70 | #define MODULE_FLAG_LOCAL 0x00000002 | |
71 | #define MODULE_FLAG_ROTATE 0x00000004 | |
72 | #define MODULE_FLAG_COALESCE 0x00000008 | |
73 | #define MODULE_FLAG_COMPRESS 0x00000010 | |
74 | #define MODULE_FLAG_NONSTD_DIR 0x00000020 | |
75 | #define MODULE_FLAG_EXTERNAL 0x00000040 | |
76 | #define MODULE_FLAG_TRUNCATE 0x00000080 | |
77 | #define MODULE_FLAG_BASESTAMP 0x00000100 /* base file has timestamp */ | |
78 | #define MODULE_FLAG_SYMLINK 0x00000200 /* link to basestamp name */ | |
79 | #define MODULE_FLAG_CRASHLOG 0x00000400 /* checkpoint on CrashMoverWillStart notification */ | |
80 | #define MODULE_FLAG_SOFT_WRITE 0x00000800 /* ignore write failures */ | |
81 | #define MODULE_FLAG_TYPE_ASL 0x00001000 /* asl format file */ | |
82 | #define MODULE_FLAG_TYPE_ASL_DIR 0x00002000 /* asl format directory */ | |
83 | #define MODULE_FLAG_STD_BSD_MSG 0x00004000 /* print format is std, bsd, or msg */ | |
84 | #define MODULE_FLAG_SIZE_ONLY 0x00008000 /* checkpoint on file size only */ | |
85 | ||
86 | #define MODULE_NAME_STYLE_FORMAT_MASK 0xf0000000 | |
87 | #define MODULE_NAME_STYLE_FORMAT_BS 0x10000000 /* base.stamp */ | |
88 | #define MODULE_NAME_STYLE_FORMAT_BES 0x20000000 /* base.ext.stamp */ | |
89 | #define MODULE_NAME_STYLE_FORMAT_BSE 0x40000000 /* base.stamp.ext */ | |
90 | #define MODULE_NAME_STYLE_STAMP_MASK 0x000000ff | |
91 | #define MODULE_NAME_STYLE_STAMP_SEC 0x00000001 /* foo.T1332799722 (note STYLE_SEC_PREFIX_CHAR) */ | |
92 | #define MODULE_NAME_STYLE_STAMP_SEQ 0x00000002 /* foo.0 */ | |
93 | #define MODULE_NAME_STYLE_STAMP_UTC 0x00000004 /* foo.2012-04-06T13:45:00Z */ | |
94 | #define MODULE_NAME_STYLE_STAMP_UTC_B 0x00000008 /* ("basic utc") foo.20120406T134500Z */ | |
95 | #define MODULE_NAME_STYLE_STAMP_LCL 0x00000010 /* foo.2012-04-06T13:45:00-7 */ | |
96 | #define MODULE_NAME_STYLE_STAMP_LCL_B 0x00000020 /* ("basic local") foo.20120406T134500-7 */ | |
97 | ||
98 | #define STAMP_STYLE_INVALID -1 | |
99 | #define STAMP_STYLE_NULL 0 | |
100 | #define STAMP_STYLE_SEC 1 | |
101 | #define STAMP_STYLE_SEQ 2 | |
102 | #define STAMP_STYLE_ISO8601 3 | |
103 | ||
104 | #define CHECKPOINT_TEST 0x00000000 | |
105 | #define CHECKPOINT_FORCE 0x00000001 | |
106 | ||
107 | #define LEVEL_ALL 8 | |
108 | ||
109 | typedef struct | |
110 | { | |
111 | char *dir; | |
112 | char *path; | |
113 | char *current_name; | |
114 | char *fmt; | |
115 | char *rotate_dir; | |
116 | char *base; | |
117 | char *ext; | |
118 | const char *tfmt; | |
119 | uint32_t style_flags; | |
120 | uint32_t pvt_flags; | |
121 | uint32_t flags; | |
122 | uint32_t fails; | |
123 | uint32_t ttl[9]; | |
124 | mode_t mode; | |
125 | #if !TARGET_OS_SIMULATOR | |
126 | uid_t *uid; | |
127 | uint32_t nuid; | |
128 | gid_t *gid; | |
129 | uint32_t ngid; | |
130 | #endif | |
131 | size_t file_max; | |
132 | size_t all_max; | |
133 | uint32_t refcount; | |
134 | time_t timestamp; | |
135 | size_t size; | |
136 | void *private; | |
137 | } asl_out_dst_data_t; | |
138 | ||
139 | typedef struct asl_out_rule_s | |
140 | { | |
141 | asl_msg_t *query; | |
142 | uint32_t action; | |
143 | char *options; | |
144 | asl_out_dst_data_t *dst; | |
145 | void *private; | |
146 | struct asl_out_rule_s *next; | |
147 | } asl_out_rule_t; | |
148 | ||
149 | typedef struct asl_out_module_s | |
150 | { | |
151 | char *name; | |
152 | uint32_t flags; | |
153 | asl_out_rule_t *ruleset; | |
154 | struct asl_out_module_s *next; | |
155 | } asl_out_module_t; | |
156 | ||
157 | typedef struct asl_out_file_list_s | |
158 | { | |
159 | char *name; | |
160 | uint32_t stamp; | |
161 | time_t ftime; | |
162 | uint32_t seq; | |
163 | size_t size; | |
164 | struct asl_out_file_list_s *next; | |
165 | struct asl_out_file_list_s *prev; | |
166 | } asl_out_file_list_t; | |
167 | ||
168 | char **explode(const char *s, const char *delim); | |
169 | void free_string_list(char **l); | |
170 | char *get_line_from_file(FILE *f); | |
171 | char *next_word_from_string(char **s); | |
172 | size_t asl_str_to_size(char *s); | |
173 | asl_msg_t *xpc_object_to_asl_msg(xpc_object_t xobj); | |
174 | ||
175 | int asl_check_option(asl_msg_t *msg, const char *opt); | |
176 | ||
177 | /* ASL OUT MODULES */ | |
178 | asl_out_module_t *asl_out_module_new(const char *name); | |
179 | void asl_out_module_free(asl_out_module_t *m); | |
180 | asl_out_module_t *asl_out_module_init(void); | |
181 | asl_out_module_t *asl_out_module_init_from_file(const char *name, FILE *f); | |
182 | asl_out_rule_t *asl_out_module_parse_line(asl_out_module_t *m, char *s); | |
183 | ||
184 | void asl_out_module_print(FILE *f, asl_out_module_t *m); | |
185 | char *asl_out_module_rule_to_string(asl_out_rule_t *r); | |
186 | ||
187 | int asl_out_mkpath(asl_out_module_t *mlist, asl_out_rule_t *r); | |
188 | int asl_make_database_dir(const char *dir, char **out); | |
189 | int asl_out_dst_checkpoint(asl_out_dst_data_t *dst, uint32_t force); | |
190 | int asl_out_dst_file_create_open(asl_out_dst_data_t *dst, char **pathp); | |
191 | int asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst); | |
192 | void asl_make_timestamp(time_t stamp, uint32_t flags, char *buf, size_t len); | |
193 | void asl_dst_make_current_name(asl_out_dst_data_t *dst, uint32_t xflags, char *buf, size_t len); | |
194 | ||
195 | asl_out_dst_data_t *asl_out_dst_data_retain(asl_out_dst_data_t *dst); | |
196 | void asl_out_dst_data_release(asl_out_dst_data_t *dst); | |
197 | ||
198 | /* rotated log files */ | |
199 | asl_out_file_list_t *asl_list_log_files(const char *dir, const char *base, const char *ext, uint32_t flags, bool src); | |
200 | asl_out_file_list_t * asl_list_src_files(asl_out_dst_data_t *dst); | |
201 | asl_out_file_list_t * asl_list_dst_files(asl_out_dst_data_t *dst); | |
202 | void asl_out_file_list_free(asl_out_file_list_t *l); | |
203 | asl_out_dst_data_t *asl_out_dest_for_path(asl_out_module_t *m, const char *path); | |
204 | ||
205 | asl_msg_t *configuration_profile_to_asl_msg(const char *ident); | |
206 | ||
207 | int asl_secure_chown_chmod_dir(const char *path, uid_t uid, gid_t gid, mode_t mode); | |
208 | ||
209 | #endif /* __ASL_COMMON_H__ */ |