From 51023e6095f291a0cf1026b76579218476e239c4 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 19 Nov 2020 01:06:26 +0000 Subject: [PATCH] syslog-385.tar.gz --- aslcommon/asl_common.c | 12 +++++++---- aslmanager.tproj/daemon.c | 8 +++++-- libsystem_asl.tproj/include/asl_private.h | 2 +- libsystem_asl.tproj/src/asl.c | 6 +++++- libsystem_asl.tproj/src/asl_file.c | 5 +++++ syslog.xcodeproj/project.pbxproj | 26 ----------------------- syslogd.tproj/asl_action.c | 14 ++++++------ syslogd.tproj/bsd_out.c | 2 +- syslogd.tproj/daemon.c | 14 +++++++----- syslogd.tproj/daemon.h | 1 + syslogd.tproj/dbserver.c | 8 +++---- syslogd.tproj/syslogd.c | 2 +- util.tproj/syslog.c | 9 ++++---- xcodeconfig/libasl.xcconfig | 3 ++- xcodescripts/sim-compat-symlink.sh | 7 ------ 15 files changed, 55 insertions(+), 64 deletions(-) delete mode 100644 xcodescripts/sim-compat-symlink.sh diff --git a/aslcommon/asl_common.c b/aslcommon/asl_common.c index 6044938..ea0a0aa 100644 --- a/aslcommon/asl_common.c +++ b/aslcommon/asl_common.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -841,7 +842,7 @@ asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst) #if !TARGET_OS_SIMULATOR uid_t fuid = 0; gid_t fgid = 80; -#if !TARGET_OS_EMBEDDED +#if !TARGET_OS_IPHONE int status; acl_t acl; uuid_t uuid; @@ -863,9 +864,12 @@ asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst) fchown(fd, fuid, fgid); -#if TARGET_OS_EMBEDDED +#if TARGET_OS_IPHONE return fd; #else + if (os_variant_is_basesystem("com.apple.syslog")) { + return fd; + } acl = acl_init(1); for (i = 0; i < dst->ngid; i++) @@ -945,7 +949,7 @@ asl_file_create_return: acl_free(acl); return fd; -#endif /* !TARGET_OS_EMBEDDED */ +#endif /* !TARGET_OS_IPHONE */ #endif /* !TARGET_OS_SIMULATOR */ } @@ -1703,7 +1707,7 @@ _asl_out_module_parse_dst(asl_out_module_t *m, char *s, mode_t def_mode) p = NULL; } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) /* check for crashreporter files */ if ((KEYMATCH(dst->path, _PATH_CRASHREPORTER)) || (KEYMATCH(dst->path, _PATH_CRASHREPORTER_MOBILE_1)) || (KEYMATCH(dst->path, _PATH_CRASHREPORTER_MOBILE_2))) { diff --git a/aslmanager.tproj/daemon.c b/aslmanager.tproj/daemon.c index b3e162f..01a791f 100644 --- a/aslmanager.tproj/daemon.c +++ b/aslmanager.tproj/daemon.c @@ -59,7 +59,7 @@ extern uint32_t debug; extern FILE *debugfp; extern dispatch_queue_t work_queue; -static mach_port_t asl_server_port; +static mach_port_t asl_server_port = MACH_PORT_NULL; static aslclient aslc; static int asl_aux_fd = -1; @@ -1523,7 +1523,11 @@ control_query(asl_msg_t *a) if (asl_server_port == MACH_PORT_NULL) { kstatus = bootstrap_look_up2(bootstrap_port, ASL_SERVICE_NAME, &asl_server_port, 0, BOOTSTRAP_PRIVILEGED_SERVER); - if (asl_server_port == MACH_PORT_NULL) return NULL; + if (kstatus != KERN_SUCCESS) + { + asl_server_port = MACH_PORT_NULL; + return NULL; + } } qstr = asl_msg_to_string((asl_msg_t *)a, &len); diff --git a/libsystem_asl.tproj/include/asl_private.h b/libsystem_asl.tproj/include/asl_private.h index f0e03ce..55d9c8f 100644 --- a/libsystem_asl.tproj/include/asl_private.h +++ b/libsystem_asl.tproj/include/asl_private.h @@ -99,7 +99,7 @@ /* * Memory limits: work queue size for syslogd and max message size in libasl */ -#if TARGET_OS_EMBEDDED +#if TARGET_OS_IPHONE #define SYSLOGD_WORK_QUEUE_MEMORY 3072000 #define LIBASL_MAX_MSG_SIZE 2048000 #else diff --git a/libsystem_asl.tproj/src/asl.c b/libsystem_asl.tproj/src/asl.c index a504cd4..a86cdc5 100644 --- a/libsystem_asl.tproj/src/asl.c +++ b/libsystem_asl.tproj/src/asl.c @@ -268,7 +268,11 @@ _asl_global_init() char *str = getenv("ASL_DISABLE"); if ((str == NULL) || strcmp(str, "1")) { - bootstrap_look_up2(bootstrap_port, ASL_SERVICE_NAME, &_asl_global.server_port, 0, BOOTSTRAP_PRIVILEGED_SERVER); + kern_return_t kstatus = bootstrap_look_up2(bootstrap_port, ASL_SERVICE_NAME, &_asl_global.server_port, 0, BOOTSTRAP_PRIVILEGED_SERVER); + if (kstatus != KERN_SUCCESS) + { + _asl_global.server_port = MACH_PORT_NULL; + } } }); } diff --git a/libsystem_asl.tproj/src/asl_file.c b/libsystem_asl.tproj/src/asl_file.c index 4afe59d..cba5879 100644 --- a/libsystem_asl.tproj/src/asl_file.c +++ b/libsystem_asl.tproj/src/asl_file.c @@ -41,6 +41,7 @@ #include #include #include +#include #define forever for(;;) @@ -323,6 +324,10 @@ asl_file_create(const char *path, uid_t uid, gid_t gid, mode_t mode) #if TARGET_OS_IPHONE return open(path, O_RDWR | O_CREAT | O_EXCL, mode); #else + if (os_variant_is_basesystem("com.apple.syslog")) { + return open(path, O_RDWR | O_CREAT | O_EXCL, mode); + } + acl_t acl; uuid_t uuid; acl_entry_t entry; diff --git a/syslog.xcodeproj/project.pbxproj b/syslog.xcodeproj/project.pbxproj index 94504b9..4ff2fbe 100644 --- a/syslog.xcodeproj/project.pbxproj +++ b/syslog.xcodeproj/project.pbxproj @@ -315,7 +315,6 @@ 3F6F43E71613A8E300CA9ADB /* asl_msg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = asl_msg.c; sourceTree = ""; }; 3F6F43E81613A8E300CA9ADB /* asl_store.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = asl_store.c; sourceTree = ""; }; 3F6F43E91613A8E300CA9ADB /* asl_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = asl_util.c; sourceTree = ""; }; - 3F900DB619383950003CA7E6 /* sim-compat-symlink.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "sim-compat-symlink.sh"; sourceTree = ""; }; 3FCCB5361749B53D00F8FEBC /* asl.conf.ios_sim */ = {isa = PBXFileReference; lastKnownFileType = text; name = asl.conf.ios_sim; path = syslogd.tproj/asl.conf.ios_sim; sourceTree = ""; }; 3FE6E8391A529FEF0075D75F /* asl.conf.ios */ = {isa = PBXFileReference; lastKnownFileType = text; name = asl.conf.ios; path = syslogd.tproj/asl.conf.ios; sourceTree = ""; }; 3FE6E83A1A529FEF0075D75F /* asl.conf.osx */ = {isa = PBXFileReference; lastKnownFileType = text; name = asl.conf.osx; path = syslogd.tproj/asl.conf.osx; sourceTree = ""; }; @@ -408,7 +407,6 @@ 3F6F43CD1613A8E300CA9ADB /* libsystem_asl */, 505ACB9E108FD16400197086 /* Products */, 3FFD43F717485C5B007DAC1B /* xcodeconfig */, - 3F900DB519383950003CA7E6 /* xcodescripts */, 503A82461099029200B0D08A /* libbsm.dylib */, 2D60F61015657D0F00F2E3F9 /* libz.dylib */, ); @@ -475,14 +473,6 @@ path = src; sourceTree = ""; }; - 3F900DB519383950003CA7E6 /* xcodescripts */ = { - isa = PBXGroup; - children = ( - 3F900DB619383950003CA7E6 /* sim-compat-symlink.sh */, - ); - path = xcodescripts; - sourceTree = ""; - }; 3FFD43F717485C5B007DAC1B /* xcodeconfig */ = { isa = PBXGroup; children = ( @@ -612,7 +602,6 @@ 3F6F43C71613922800CA9ADB /* Frameworks */, 3F6F43C81613922800CA9ADB /* Headers */, 3F6F44131613AA9300CA9ADB /* Install man3 */, - 3F900DB41938393C003CA7E6 /* Sim compat symlink */, ); buildRules = ( ); @@ -735,21 +724,6 @@ /* End PBXProject section */ /* Begin PBXShellScriptBuildPhase section */ - 3F900DB41938393C003CA7E6 /* Sim compat symlink */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 8; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/xcodescripts/sim-compat-symlink.sh", - ); - name = "Sim compat symlink"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 1; - shellPath = "/bin/bash -e -x"; - shellScript = ". \"${SCRIPT_INPUT_FILE_0}\""; - }; 50A9CB7A10A8D16300AA715E /* after install */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 8; diff --git a/syslogd.tproj/asl_action.c b/syslogd.tproj/asl_action.c index e6dc577..3e3e9ad 100644 --- a/syslogd.tproj/asl_action.c +++ b/syslogd.tproj/asl_action.c @@ -77,7 +77,7 @@ static dispatch_queue_t asl_action_queue; static dispatch_source_t checkpoint_timer; static time_t sweep_time = 0; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) #ifndef CRASH_MOVER_SERVICE #define CRASH_MOVER_SERVICE "com.apple.crash_mover" #endif @@ -208,7 +208,7 @@ _act_notify(asl_out_module_t *m, asl_out_rule_t *r) static void _act_broadcast(asl_out_module_t *m, asl_out_rule_t *r, asl_msg_t *msg) { -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) FILE *pw; const char *val; @@ -284,7 +284,7 @@ _act_access_control(asl_out_module_t *m, asl_out_rule_t *r, asl_msg_t *msg) } } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) static void _crashlog_queue_check(void) { @@ -1287,7 +1287,7 @@ _act_store(asl_out_module_t *m, asl_out_rule_t *r, asl_msg_t *msg) if (af_data != NULL) af_data->pending++; } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (r->dst->flags & MODULE_FLAG_CRASHLOG) { _crashlog_queue_check(); @@ -1579,7 +1579,7 @@ _act_file(asl_out_module_t *m, asl_out_rule_t *r, asl_msg_t *msg) f_data = (asl_action_file_data_t *)r->dst->private; if (f_data != NULL) f_data->pending++; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (r->dst->flags & MODULE_FLAG_CRASHLOG) { _crashlog_queue_check(); @@ -2093,7 +2093,7 @@ asl_action_init(void) dispatch_once(&once, ^{ asl_action_queue = dispatch_queue_create("ASL Action Queue", NULL); -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) crashlog_queue = dispatch_queue_create("iOS CrashLog Queue", NULL); notify_register_dispatch(CRASH_MOVER_SERVICE, &crashmover_token, asl_action_queue, ^(int unused) { uint64_t cmstate = 0; @@ -2200,7 +2200,7 @@ _asl_action_free_modules(asl_out_module_t *m) static int _asl_action_close_internal(void) { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (crashmover_state != 0) { dispatch_resume(crashlog_queue); diff --git a/syslogd.tproj/bsd_out.c b/syslogd.tproj/bsd_out.c index 20ef975..571b998 100644 --- a/syslogd.tproj/bsd_out.c +++ b/syslogd.tproj/bsd_out.c @@ -543,7 +543,7 @@ _bsd_send(asl_msg_t *msg, struct config_rule *r, char **out, char **fwd, time_t } else if (r->type == DST_TYPE_WALL) { -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) FILE *pw = popen(_PATH_WALL, "w"); if (pw < 0) { diff --git a/syslogd.tproj/daemon.c b/syslogd.tproj/daemon.c index 7cf83d0..edb5dc3 100644 --- a/syslogd.tproj/daemon.c +++ b/syslogd.tproj/daemon.c @@ -42,8 +42,10 @@ #include #include #include + #include "daemon.h" + #define LIST_SIZE_DELTA 256 #define STATS_TABLE_SIZE 256 @@ -72,7 +74,7 @@ static int name_change_token = -1; static OSSpinLock count_lock = 0; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) static os_transaction_t main_transaction; #endif @@ -322,7 +324,7 @@ asl_client_count_increment() { OSSpinLockLock(&count_lock); -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (global.client_count == 0) main_transaction = os_transaction_create("com.apple.syslogd"); #endif global.client_count++; @@ -336,7 +338,7 @@ asl_client_count_decrement() OSSpinLockLock(&count_lock); if (global.client_count > 0) global.client_count--; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (global.client_count == 0) os_release(main_transaction); #endif @@ -655,7 +657,7 @@ init_globals(void) global.debug_file = NULL; global.launchd_enabled = 1; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) global.dbtype = DB_TYPE_MEMORY; #else global.dbtype = DB_TYPE_FILE; @@ -873,7 +875,7 @@ control_set_param(const char *s, bool eval) } else { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) intval = DB_TYPE_MEMORY; #else intval = DB_TYPE_FILE; @@ -914,6 +916,7 @@ control_message(asl_msg_t *msg) return 0; } + void process_message(asl_msg_t *msg, uint32_t source) { @@ -971,6 +974,7 @@ process_message(asl_msg_t *msg, uint32_t source) status = aslmsg_verify(msg, source, &kplevel, &uid); if (status == VERIFY_STATUS_OK) { + if ((source == SOURCE_KERN) && (kplevel >= 0)) { if (kplevel > 7) kplevel = 7; diff --git a/syslogd.tproj/daemon.h b/syslogd.tproj/daemon.h index c3c4808..5710937 100644 --- a/syslogd.tproj/daemon.h +++ b/syslogd.tproj/daemon.h @@ -68,6 +68,7 @@ extern const char *_path_syslogd_log; #define _PATH_SYSLOGD_LOG "/var/log/syslogd.log" #endif + #define NOTIFY_PATH_SERVICE "com.apple.system.notify.service.path:0x87:" #define DB_TYPE_FILE 0x00000001 diff --git a/syslogd.tproj/dbserver.c b/syslogd.tproj/dbserver.c index a01b209..70eb86e 100644 --- a/syslogd.tproj/dbserver.c +++ b/syslogd.tproj/dbserver.c @@ -694,7 +694,7 @@ cancel_session(task_name_t task_name) static uint32_t register_direct_watch(uint16_t port) { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) uint32_t i; int sock, flags; struct sockaddr_in address; @@ -764,7 +764,7 @@ register_direct_watch(uint16_t port) static void cancel_direct_watch(uint16_t port) { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) uint32_t i; for (i = 0; (i < direct_watch_count) && (port != direct_watch_port[i]); i++); @@ -1204,7 +1204,7 @@ database_server() static void caller_get_read_entitlement(audit_token_t *token, uid_t *uid, gid_t *gid) { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) xpc_object_t entitlements, val; bool bval = false; int64_t ival = -2; @@ -1297,7 +1297,7 @@ __asl_server_query_internal else { int x = 0; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) x = pid; #endif diff --git a/syslogd.tproj/syslogd.c b/syslogd.tproj/syslogd.c index 09997c2..200760d 100644 --- a/syslogd.tproj/syslogd.c +++ b/syslogd.tproj/syslogd.c @@ -506,7 +506,7 @@ main(int argc, const char *argv[]) init_globals(); -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) remote_enabled = 1; activate_bsd_out = 0; #endif diff --git a/util.tproj/syslog.c b/util.tproj/syslog.c index baa90f4..25d2183 100644 --- a/util.tproj/syslog.c +++ b/util.tproj/syslog.c @@ -130,7 +130,7 @@ static char *last_printmsg_str = NULL; static int last_printmsg_count = 0; static const char *tfmt = NULL; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) static uint32_t dbselect = DB_SELECT_SYSLOGD; #else static uint32_t dbselect = DB_SELECT_ASL; @@ -1118,7 +1118,7 @@ asl_stats(int argc, char *argv[]) } } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (store == NULL) store = asl_open_path(ASL_IOS_STATS_DIR, 0); if (store == NULL) { @@ -1728,6 +1728,7 @@ syslogd_query(asl_msg_list_t *q, uint64_t start, int count, int dir, uint64_t *l if (kstatus != KERN_SUCCESS) { fprintf(stderr, "query failed: can't contact syslogd\n"); + asl_server_port = MACH_PORT_NULL; return NULL; } } @@ -1785,7 +1786,7 @@ filter_and_print(asl_msg_t *msg, asl_msg_list_t *ql, FILE *f, char *pfmt, int pf if (did_match != 0) printmsg(f, msg, pfmt, pflags); } -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) void syslogd_direct_watch(FILE *f, char *pfmt, int pflags, asl_msg_list_t *ql) { @@ -2818,7 +2819,7 @@ main(int argc, char *argv[]) { if (dbselect == DB_SELECT_SYSLOGD) { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) syslogd_direct_watch(outfile, pfmt, pflags, qlist); #else fprintf(stderr, "Warning: -w flag cannot be used when querying syslogd directly\n"); diff --git a/xcodeconfig/libasl.xcconfig b/xcodeconfig/libasl.xcconfig index d55394e..7fdcf50 100644 --- a/xcodeconfig/libasl.xcconfig +++ b/xcodeconfig/libasl.xcconfig @@ -31,8 +31,9 @@ LIBM_LDFLAGS = -lsystem_m LIBDYLD_LDFLAGS = -ldyld LIBTRACE_LDFLAGS = -lsystem_trace LIBUNWIND_LDFLAGS = -lunwind +LIBDARWIN_LDFLAGS = -lsystem_darwin -OTHER_LDFLAGS = -all_load -L/usr/lib/system -umbrella System $(CR_LDFLAGS) $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBC_LDFLAGS) $(LIBUNWIND_LDFLAGS) $(LIBCLOSURE_LDFLAGS) -ldispatch $(LIBLAUNCH_LDFLAGS) -lxpc $(LIBTRACE_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(UPWARD_LINKS) +OTHER_LDFLAGS = -all_load -L/usr/lib/system -umbrella System $(CR_LDFLAGS) $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBC_LDFLAGS) $(LIBUNWIND_LDFLAGS) $(LIBCLOSURE_LDFLAGS) -ldispatch $(LIBLAUNCH_LDFLAGS) -lxpc $(LIBTRACE_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(LIBDARWIN_LDFLAGS) $(UPWARD_LINKS) UPWARD_LINKS = -Wl,-upward-lsystem_info diff --git a/xcodescripts/sim-compat-symlink.sh b/xcodescripts/sim-compat-symlink.sh deleted file mode 100644 index f965b50..0000000 --- a/xcodescripts/sim-compat-symlink.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -ex - -if [[ "${PLATFORM_NAME}" =~ "simulator" ]]; then - ln -s libsystem_asl.dylib ${DSTROOT}${INSTALL_PATH}/libsystem_sim_asl.dylib -fi - -exit 0 -- 2.45.2