2D31A0FC128074E700D5A84C /* getifmaddrs.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D31A0FB128074E700D5A84C /* getifmaddrs.c */; };
2D4070B1129354A700FE81ED /* getnameinfo_link.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D4070B0129354A700FE81ED /* getnameinfo_link.c */; };
2D5DD5D21608E6E80051891A /* configuration_profile.c in Sources */ = {isa = PBXBuildFile; fileRef = 2D5DD5D01608E6E80051891A /* configuration_profile.c */; };
- C965793A1B94C97100624699 /* muser_module.c in Sources */ = {isa = PBXBuildFile; fileRef = C96579391B94C97100624699 /* muser_module.c */; settings = {ASSET_TAGS = (); }; };
+ C965793A1B94C97100624699 /* muser_module.c in Sources */ = {isa = PBXBuildFile; fileRef = C96579391B94C97100624699 /* muser_module.c */; };
FC5284C011478C200058CCB0 /* herror.c in Sources */ = {isa = PBXBuildFile; fileRef = FC5283EE11478C200058CCB0 /* herror.c */; };
FC5284C811478C200058CCB0 /* res_comp.c in Sources */ = {isa = PBXBuildFile; fileRef = FC5283F711478C200058CCB0 /* res_comp.c */; };
FC5284CD11478C200058CCB0 /* res_query.c in Sources */ = {isa = PBXBuildFile; fileRef = FC5283FC11478C200058CCB0 /* res_query.c */; };
FC5284F411478C200058CCB0 /* thread_data.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52843811478C200058CCB0 /* thread_data.c */; };
FC5284F711478C200058CCB0 /* membership.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52843E11478C200058CCB0 /* membership.c */; };
FC5284FD11478C200058CCB0 /* getdomainname.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52844611478C200058CCB0 /* getdomainname.c */; };
- FC5284FE11478C200058CCB0 /* getnetgrent.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52844711478C200058CCB0 /* getnetgrent.c */; };
FC5284FF11478C200058CCB0 /* innetgr.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52844811478C200058CCB0 /* innetgr.c */; };
FC52850111478C200058CCB0 /* setdomainname.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52844A11478C200058CCB0 /* setdomainname.c */; };
FC52850211478C200058CCB0 /* xdr_domainname.c in Sources */ = {isa = PBXBuildFile; fileRef = FC52844B11478C200058CCB0 /* xdr_domainname.c */; };
FC52841911478C200058CCB0 /* bootparams.5 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bootparams.5; sourceTree = "<group>"; };
FC52841A11478C200058CCB0 /* bootparams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bootparams.h; sourceTree = "<group>"; };
FC52841B11478C200058CCB0 /* cache_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cache_module.c; sourceTree = "<group>"; };
- FC52841C11478C200058CCB0 /* ds_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ds_module.c; sourceTree = "<group>"; };
+ FC52841C11478C200058CCB0 /* ds_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ds_module.c; sourceTree = "<group>"; usesTabs = 1; };
FC52841D11478C200058CCB0 /* file_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = file_module.c; sourceTree = "<group>"; };
FC52841E11478C200058CCB0 /* gai_strerror.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = gai_strerror.3; sourceTree = "<group>"; };
FC52841F11478C200058CCB0 /* getaddrinfo.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = getaddrinfo.3; sourceTree = "<group>"; };
FC52842811478C200058CCB0 /* initgroups.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = initgroups.3; sourceTree = "<group>"; };
FC52842911478C200058CCB0 /* kvbuf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kvbuf.c; sourceTree = "<group>"; };
FC52842A11478C200058CCB0 /* kvbuf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kvbuf.h; sourceTree = "<group>"; };
- FC52842B11478C200058CCB0 /* libinfo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libinfo.c; sourceTree = "<group>"; };
+ FC52842B11478C200058CCB0 /* libinfo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libinfo.c; sourceTree = "<group>"; usesTabs = 1; };
FC52842C11478C200058CCB0 /* libinfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libinfo.h; sourceTree = "<group>"; };
- FC52842E11478C200058CCB0 /* mdns_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mdns_module.c; sourceTree = "<group>"; };
+ FC52842E11478C200058CCB0 /* mdns_module.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mdns_module.c; sourceTree = "<group>"; usesTabs = 1; };
FC52842F11478C200058CCB0 /* netdb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netdb.h; sourceTree = "<group>"; };
FC52843011478C200058CCB0 /* netdb_async.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = netdb_async.h; sourceTree = "<group>"; };
FC52843111478C200058CCB0 /* printerdb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = printerdb.h; sourceTree = "<group>"; };
FC52843911478C200058CCB0 /* thread_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = thread_data.h; sourceTree = "<group>"; };
FC52843C11478C200058CCB0 /* mbr_check_membership.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mbr_check_membership.3; sourceTree = "<group>"; };
FC52843D11478C200058CCB0 /* mbr_uid_to_uuid.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mbr_uid_to_uuid.3; sourceTree = "<group>"; };
- FC52843E11478C200058CCB0 /* membership.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = membership.c; sourceTree = "<group>"; };
+ FC52843E11478C200058CCB0 /* membership.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = membership.c; sourceTree = "<group>"; usesTabs = 1; };
FC52843F11478C200058CCB0 /* membership.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = membership.h; sourceTree = "<group>"; };
FC52844011478C200058CCB0 /* membershipPriv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = membershipPriv.h; sourceTree = "<group>"; };
FC52844111478C200058CCB0 /* ntsid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ntsid.h; sourceTree = "<group>"; };
);
path = lookup.subproj;
sourceTree = "<group>";
+ usesTabs = 1;
};
FC52843A11478C200058CCB0 /* membership.subproj */ = {
isa = PBXGroup;
);
path = membership.subproj;
sourceTree = "<group>";
+ usesTabs = 1;
};
FC52844511478C200058CCB0 /* nis.subproj */ = {
isa = PBXGroup;
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0700;
+ LastUpgradeCheck = 0800;
};
buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "Libinfo" */;
compatibilityVersion = "Xcode 3.2";
FC5284F411478C200058CCB0 /* thread_data.c in Sources */,
FC5284F711478C200058CCB0 /* membership.c in Sources */,
FC5284FD11478C200058CCB0 /* getdomainname.c in Sources */,
- FC5284FE11478C200058CCB0 /* getnetgrent.c in Sources */,
FC5284FF11478C200058CCB0 /* innetgr.c in Sources */,
FC52850111478C200058CCB0 /* setdomainname.c in Sources */,
FC52850211478C200058CCB0 /* xdr_domainname.c in Sources */,
isa = XCBuildConfiguration;
baseConfigurationReference = 3F397F7D185BD67F00987BCC /* Libinfo.xcconfig */;
buildSettings = {
- COMBINE_HIDPI_IMAGES = YES;
PRODUCT_NAME = info;
- SUPPORTED_PLATFORMS = "macosx iphoneos";
- VERSION_INFO_EXPORT_DECL = static;
- VERSION_INFO_PREFIX = __;
};
name = Release;
};
1DEB915008733D8E0010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
- BUILD_VARIANTS = (
- normal,
- profile,
- debug,
- );
- CODE_SIGN_IDENTITY = "-";
- CURRENT_PROJECT_VERSION = "$(RC_ProjectSourceVersion)";
- DEAD_CODE_STRIPPING = YES;
- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
- DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
- GCC_C_LANGUAGE_STANDARD = gnu99;
- GCC_TREAT_WARNINGS_AS_ERRORS = YES;
- GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- OTHER_CFLAGS = "";
- VERSIONING_SYSTEM = "apple-generic";
- WARNING_CFLAGS = "-Wno-error=deprecated-declarations";
- WARNING_LDFLAGS = "-Wall";
};
name = Release;
};
3F397F80185BD71500987BCC /* Release */ = {
isa = XCBuildConfiguration;
+ baseConfigurationReference = 3F397F7D185BD67F00987BCC /* Libinfo.xcconfig */;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
- SUPPORTED_PLATFORMS = iphonesimulator;
};
name = Release;
};
90E08A3C1BB364CA0093311B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
- BUILD_VARIANTS = (
- normal,
- profile,
- debug,
- );
- CODE_SIGN_IDENTITY = "-";
- CURRENT_PROJECT_VERSION = "$(RC_ProjectSourceVersion)";
- DEAD_CODE_STRIPPING = YES;
- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
- DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
- GCC_C_LANGUAGE_STANDARD = gnu99;
- GCC_OPTIMIZATION_LEVEL = 0;
- GCC_TREAT_WARNINGS_AS_ERRORS = YES;
- GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
- GCC_WARN_ABOUT_RETURN_TYPE = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- OTHER_CFLAGS = "-DDEBUG=1";
- VERSIONING_SYSTEM = "apple-generic";
- WARNING_CFLAGS = "-Wno-error=deprecated-declarations";
- WARNING_LDFLAGS = "-Wall";
};
name = Debug;
};
isa = XCBuildConfiguration;
baseConfigurationReference = 3F397F7D185BD67F00987BCC /* Libinfo.xcconfig */;
buildSettings = {
- COMBINE_HIDPI_IMAGES = YES;
PRODUCT_NAME = info;
- SUPPORTED_PLATFORMS = "macosx iphoneos";
- VERSION_INFO_EXPORT_DECL = static;
- VERSION_INFO_PREFIX = __;
};
name = Debug;
};
90E08A3E1BB364CA0093311B /* Debug */ = {
isa = XCBuildConfiguration;
+ baseConfigurationReference = 3F397F7D185BD67F00987BCC /* Libinfo.xcconfig */;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
- SUPPORTED_PLATFORMS = iphonesimulator;
};
name = Debug;
};
int res = -1;
si_item_t *item;
uint32_t err;
+ int cpylen = 0;
si_mod_t *dns = si_module_with_name("mdns");
if (dns == NULL) {
res = p->dns_packet_len;
- // Truncate to destination buffer size.
- memcpy(answer, p->dns_packet, MIN(res, anslen));
+ if (res >= 0 && anslen >= 0) {
+ // Truncate destination buffer size.
+ memcpy(answer, p->dns_packet, (cpylen = MIN(res, anslen)));
+ }
+ else {
+ h_errno = NO_RECOVERY;
+ res = -1;
+ }
si_item_release(item);
} else {
res = -1;
}
- if (MIN(res, anslen) >= sizeof(HEADER)) {
+ if (cpylen >= sizeof(HEADER)) {
HEADER *hp = (HEADER *)answer;
switch (hp->rcode) {
case NXDOMAIN:
}
data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (data != NULL) out = xpc_create_from_plist(data, sb.st_size);
+
+ if (data != MAP_FAILED)
+ {
+ out = xpc_create_from_plist(data, sb.st_size);
+ munmap(data, sb.st_size);
+ }
- munmap(data, sb.st_size);
close(fd);
return out;
value of the
.Fa err
argument.
+.Pp
+Historically, passing a host's own hostname to
+.Fn gethostbyname
+or
+.Fn gethostbyname2
+has been a popular
+technique for determining that host's IP address(es), but this is fragile,
+and doesn't work reliably in all cases. The appropriate way for software to
+discover the IP address(es) of the host it is running on is to use
+.Xr getifaddrs 3 .
+.Pp
.Sh FILES
.Bl -tag -width /etc/nsswitch.conf -compact
.It Pa /etc/hosts
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
+#include <os/overflow.h>
+#include <sys/errno.h>
/*
* From RFC 2553:
struct ifaddrs *ifaddrs, *ifa;
unsigned int ni;
size_t nbytes;
- struct if_nameindex *ifni, *ifni2;
+ struct if_nameindex *ifni= NULL, *ifni2;
char *cp;
+ size_t cpsz;
if (getifaddrs(&ifaddrs) < 0)
return(NULL);
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK) {
- nbytes += strlen(ifa->ifa_name) + 1;
- ni++;
+ /*
+ * Security Check: Verify nbytes and ni do not overflow
+ */
+ if (os_add_overflow(nbytes, strlen(ifa->ifa_name) + 1, &nbytes) ||
+ os_add_overflow(ni, 1, &ni)) {
+ errno = EOVERFLOW;
+ goto out;
+ }
}
}
+ /*
+ * Security Check: Verify cpsz does not overflow in next 3 operations
+ */
+ if (os_add_overflow(ni, 1, &cpsz)) {
+ errno = EOVERFLOW;
+ goto out;
+ }
+ if (os_mul_overflow(cpsz, sizeof(struct if_nameindex), &cpsz)) {
+ errno = EOVERFLOW;
+ goto out;
+ }
+ if (os_add_overflow(cpsz, nbytes, &cpsz)) {
+ errno = EOVERFLOW;
+ goto out;
+ }
/*
* Next, allocate a chunk of memory, use the first part
* for the array of structures, and the last part for
* the strings.
*/
- cp = malloc((ni + 1) * sizeof(struct if_nameindex) + nbytes);
+ cp = malloc(cpsz);
ifni = (struct if_nameindex *)cp;
if (ifni == NULL)
goto out;
#include <servers/bootstrap.h>
#include <bootstrap_priv.h>
#include <opendirectory/DSlibinfoMIG_types.h>
-#ifdef DEBUG
-#include <asl.h>
-#endif
+#include <os/activity.h>
+#include <os/log.h>
#define IPV6_ADDR_LEN 16
#define IPV4_ADDR_LEN 4
+/* The LI_OS_ACTIVITY macro contains os_activity_t functions
+ * that are not POSIX compliant. So calling them may
+ * inadvertantly change errno. To avoid this, the macro
+ * explicityly restores the errno to its state on entry
+ * when done.
+ *
+ * Macro cannot contain any {} because it will end the scope
+ * of the activity prematurely
+ */
+#define _LI_OS_ACTIVITY(_var, _desc) \
+ int _var = errno; \
+ os_activity_t activity __attribute__((__cleanup__(_li_auto_os_release))) = os_activity_create(_desc, OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); \
+ os_activity_scope(activity); \
+ errno = _var
+
+#define LI_OS_ACTIVITY(_desc) _LI_OS_ACTIVITY(OS_CONCAT(errnosav, __COUNTER__), _desc)
+
typedef si_item_t *(*od_extract_t)(si_mod_t *si, xpc_object_t reply, const void *extra, uint64_t valid_global, uint64_t valid_cat);
/* notify SPI */
_ds_port = MACH_PORT_NULL;
}
+static void
+_li_auto_os_release(os_activity_t *activity)
+{
+ os_release(*activity);
+ (*activity) = NULL;
+}
+
XPC_RETURNS_RETAINED
static xpc_pipe_t
_od_xpc_pipe(bool resetPipe)
return 1;
}
-static void
-_free_addr_list(char **l)
-{
- int i;
-
- if (l == NULL) return;
- for (i = 0; l[i] != NULL; i++) free(l[i]);
- free(l);
-}
-
-/* map ipv4 addresses and append to v6 list */
-static int
-_map_v4(char ***v6, uint32_t n6, char **v4, uint32_t n4)
-{
- struct in6_addr a6;
- uint32_t i;
-
- a6.__u6_addr.__u6_addr32[0] = 0x00000000;
- a6.__u6_addr.__u6_addr32[1] = 0x00000000;
- a6.__u6_addr.__u6_addr32[2] = htonl(0x0000ffff);
-
- if (*v6 == NULL)
- {
- *v6 = (char **)calloc(n4 + 1, sizeof(char *));
- }
- else
- {
- *v6 = (char **)reallocf(*v6, (n6 + n4 + 1) * sizeof(char *));
- }
-
- if (*v6 == NULL) return -1;
-
- for (i = 0; i < n4; i++)
- {
- (*v6)[n6] = (char *)calloc(1, IPV6_ADDR_LEN);
- if ((*v6)[n6] == NULL) return -1;
-
- memcpy(&(a6.__u6_addr.__u6_addr32[3]), v4[i], IPV4_ADDR_LEN);
- memcpy((*v6)[n6], &(a6.__u6_addr.__u6_addr32[0]), IPV6_ADDR_LEN);
-
- n6++;
- }
-
- return 0;
-}
-
static xpc_object_t
_xpc_query_key_string(const char *key, const char *value)
{
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve User by Name");
+
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve User by ID");
+
payload = _xpc_query_key_id("uid", uid);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve User by UUID");
+
payload = _xpc_query_key_uuid("uuid", uuid);
if (payload == NULL) return NULL;
static si_list_t *
ds_user_all(si_mod_t *si)
{
+ LI_OS_ACTIVITY("Performance Impact - Enumerate all users");
+
return _ds_list(si, CATEGORY_USER, "getpwent", NULL, _extract_user);
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve Group by Name");
+
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve Group by ID");
+
payload = _xpc_query_key_id("gid", gid);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve Group by UUID");
+
payload = _xpc_query_key_uuid("uuid", uuid);
if (payload == NULL) return NULL;
ds_group_all(si_mod_t *si)
{
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Performance Impact - Enumerate all Groups");
return _ds_list(si, CATEGORY_GROUP, "getgrent", NULL, _extract_group);
}
{
xpc_object_t payload, reply;
si_item_t *item = NULL;
+ os_activity_t activity;
if (!_od_running()) return NULL;
if (name == NULL) return NULL;
+ if (ngroups > 17) {
+ activity = os_activity_create("Performance impact - Resolve user group list (>17 groups)", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT);
+ os_log(OS_LOG_DEFAULT, "Too many groups requested (%u). Can cause performance issues when network directories are involved", ngroups);
+ } else {
+ activity = os_activity_create("Resolve user group list", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT);
+ }
+ os_activity_scope(activity);
+
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return NULL;
}
xpc_release(payload);
+ os_release(activity);
return item;
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve netgroup by name");
+
payload = _xpc_query_key_string("netgroup", name);
if (payload == NULL) return NULL;
if (!_od_running()) return 0;
+ LI_OS_ACTIVITY("Match netgroup");
+
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return 0;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve alias by name");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
ds_alias_all(si_mod_t *si)
{
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Enumerate all alias entries");
return _ds_list(si, CATEGORY_ALIAS, "alias_getent", NULL, _extract_alias);
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve network by name");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve network by address");
f1 = addr & 0xff;
addr >>= 8;
f2 = addr & 0xff;
ds_network_all(si_mod_t *si)
{
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Emumerate all network entries");
return _ds_list(si, CATEGORY_NETWORK, "getnetent", NULL, _extract_network);
}
if (name == NULL) name = "";
if (proto == NULL) proto = "";
+ LI_OS_ACTIVITY("Retrieve service by name");
+
/* Check our local service cache (see ds_addrinfo). */
item = pthread_getspecific(_ds_serv_cache_key);
if (item != NULL)
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve service by port");
+
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return NULL;
ds_service_all(si_mod_t *si)
{
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Enumerate all services");
return _ds_list(si, CATEGORY_SERVICE, "getservent", NULL, _extract_service);
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve protocol by name");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve protocol by number");
payload = _xpc_query_key_int("number", number);
if (payload == NULL) return NULL;
static si_list_t *
ds_protocol_all(si_mod_t *si)
{
+ LI_OS_ACTIVITY("Enumerate all protocols");
return _ds_list(si, CATEGORY_PROTOCOL, "getprotoent", NULL, _extract_protocol);
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve RPC by name");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve RPC by number");
payload = _xpc_query_key_int("number", number);
if (payload == NULL) return NULL;
static si_list_t *
ds_rpc_all(si_mod_t *si)
{
+ LI_OS_ACTIVITY("Enumerate all RPC entries");
return _ds_list(si, CATEGORY_RPC, "getrpcent", NULL, _extract_rpc);
}
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Lookup FS entry by spec");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
static si_list_t *
ds_fs_all(si_mod_t *si)
{
+ LI_OS_ACTIVITY("Performance impact - Enumerate all FS entries");
return _ds_list(si, CATEGORY_FS, "getfsent", NULL, _extract_fstab);
}
if (!_od_running()) return NULL;
if (name == NULL) return NULL;
+ LI_OS_ACTIVITY("Retrieve FS by file location");
list = ds_fs_all(si);
if (list == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve FS by name");
payload = _xpc_query_key_string("name", name);
if (payload == NULL) return NULL;
if (!_od_running()) return NULL;
+ LI_OS_ACTIVITY("Retrieve MAC entry by MAC");
cmac = si_standardize_mac_address(mac);
if (cmac == NULL) return NULL;
static int
_fsi_validate(si_mod_t *si, int cat, uint64_t va, uint64_t vb)
{
+#if !TARGET_OS_EMBEDDED
struct stat sb;
const char *path;
uint32_t item_val, curr_val, vtype;
file_si_private_t *pp;
int status;
+#endif
if (si == NULL) return 0;
-#if TARGET_OS_EMBEDDED
+#if !TARGET_OS_EMBEDDED
/* /etc is on a read-only filesystem, so no validation is required */
- return 1;
-#endif
pp = (file_si_private_t *)si->private;
if (pp == NULL) return 0;
curr_val = ntohl(curr_val);
if (item_val != curr_val) return 0;
}
+#endif
return 1;
}
root_spec = _fsi_get_device_path(rootstat.st_dev);
rootfs = (si_item_t *)LI_ils_create("L4488sssss44", (unsigned long)si, CATEGORY_FS, 1, 0LL, 0LL, root_spec, root_path, rootfsinfo.f_fstypename, FSTAB_RW, FSTAB_RW, 0, 1);
+ free(root_spec);
});
return si_item_retain(rootfs);
The
.Fn getpwent
function
-searches all available directory services on it's first invocation.
+searches all available directory services on its first invocation.
It caches the returned entries in a list
and returns user account entries one at a time.
.Pp
#define IPV6_ADDR_LEN 16
#define IPV4_ADDR_LEN 4
+#define SYSTEM_UID_LIMIT 500
+
/* kernel syscalls */
extern int __initgroups(u_int gidsetsize, gid_t *gidset, int gmuid);
int32_t key_offset;
} si_context_t;
+si_mod_t *
+si_search_file(void)
+{
+ static si_mod_t *search = NULL;
+
+ if (search == NULL) search = si_module_with_name("file");
+
+ return search;
+}
+
si_mod_t *
si_search(void)
{
struct passwd *
getpwuid(uid_t uid)
{
- si_item_t *item;
+ si_item_t *item = NULL;
#ifdef CALL_TRACE
fprintf(stderr, "-> %s %d\n", __func__, uid);
#endif
-
-
- item = si_user_byuid(si_search(), uid);
+
+ // Search the file module first for all system uids
+ // (ie, uid value < 500) since they should all be
+ // in the /etc/*passwd file.
+ if (uid < SYSTEM_UID_LIMIT)
+ item = si_user_byuid(si_search_file(), uid);
+
+ if (item == NULL)
+ item = si_user_byuid(si_search(), uid);
LI_set_thread_item(CATEGORY_USER + 200, item);
if (item == NULL) return NULL;
sictx->cat = CATEGORY_USER;
sictx->key_offset = 200;
+ // Search the file module first for all system uids
+ // (ie, uid value < 500) since they should all be
+ // in the /etc/*passwd file.
+ if (uid < SYSTEM_UID_LIMIT)
+ {
+ si_item_t *item = si_user_byuid(si_search_file(), uid);
+ if (item)
+ {
+ si_item_release(item);
+ return si_async_call(si_search_file(), SI_CALL_USER_BYUID, NULL, NULL, NULL, (uint32_t)uid, 0, 0, 0, (void *)si_libinfo_general_callback, sictx);
+ }
+ }
+
return si_async_call(si_search(), SI_CALL_USER_BYUID, NULL, NULL, NULL, (uint32_t)uid, 0, 0, 0, (void *)si_libinfo_general_callback, sictx);
}
dispatch_once(&once, ^(void) {
const char *proc_name = getprogname();
if (strcmp(proc_name, "id") != 0 && strcmp(proc_name, "smbd") != 0 && strcmp(proc_name, "rpcsvchost") != 0) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
aslmsg msg = asl_new(ASL_TYPE_MSG);
char buffer[256];
asl_free(msg);
}
+#pragma clang diagnostic pop
});
}
#endif
int
getpwuid_r(uid_t uid, struct passwd *pw, char *buffer, size_t bufsize, struct passwd **result)
{
- si_item_t *item;
+ si_item_t *item = NULL;
struct passwd *p;
int status;
- uid_t localuid = uid;
#ifdef CALL_TRACE
fprintf(stderr, "-> %s %d\n", __func__, uid);
if ((pw == NULL) || (buffer == NULL) || (result == NULL) || (bufsize == 0)) return ERANGE;
- item = si_user_byuid(si_search(), localuid);
+ // Search the file module first for all system uids
+ // (ie, uid value < 500) since they should all be
+ // in the /etc/*passwd file.
+ if (uid < SYSTEM_UID_LIMIT)
+ item = si_user_byuid(si_search_file(), uid);
+
+ if (item == NULL)
+ item = si_user_byuid(si_search(), uid);
if (item == NULL) return 0;
p = (struct passwd *)((uintptr_t)item + sizeof(si_item_t));
#include <net/if.h>
#include <time.h>
#include <unistd.h>
-#include <asl.h>
+#include <os/log.h>
#include <dns.h>
#include <dns_util.h>
#include <TargetConditionals.h>
if (_mdns_debug & MDNS_DEBUG_STDOUT) fprintf(stdout, "%s", out);
if (_mdns_debug & MDNS_DEBUG_STDERR) fprintf(stderr, "%s", out);
- if (_mdns_debug & MDNS_DEBUG_ASL) asl_log_message(ASL_LEVEL_NOTICE, "%s", out);
+ if (_mdns_debug & MDNS_DEBUG_ASL) os_log(OS_LOG_DEFAULT, "%s", out);
free(out);
va_end(v);
#if TARGET_OS_EMBEDDED
/* log a warning for queries from the main thread */
- if (pthread_is_threaded_np() && pthread_main_np()) asl_log(NULL, NULL, ASL_LEVEL_WARNING, "Warning: Libinfo call to mDNSResponder on main thread");
+ if (pthread_is_threaded_np() && pthread_main_np()) os_log(OS_LOG_DEFAULT, "Warning: Libinfo call to mDNSResponder on main thread");
#endif /* TARGET_OS_EMBEDDED */
/*
#define NI_NUMERICHOST 0x00000002
#define NI_NAMEREQD 0x00000004
#define NI_NUMERICSERV 0x00000008
+#define NI_NUMERICSCOPE 0x00000100
#define NI_DGRAM 0x00000010
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define NI_WITHSCOPEID 0x00000020
si_list_concat(si_list_t *l, si_list_t *x)
{
si_item_t *item;
- uint32_t newcount;
+ size_t newcount;
size_t size;
int i;
if (l != NULL)
{
- newcount = l->count + x->count;
+ newcount = (size_t)l->count + (size_t)x->count;
size = newcount * sizeof(si_item_t *);
l->entry = (si_item_t **)reallocf(l->entry, size);
#ifdef DS_AVAILABLE
#include <xpc/xpc.h>
#include <xpc/private.h>
+#include <os/activity.h>
#include <opendirectory/odipc.h>
#include <pthread.h>
#include <mach-o/dyld_priv.h>
#define COMPAT_PREFIX_LEN (sizeof(uuid_t) - sizeof(id_t))
+#if DS_AVAILABLE
+#define MBR_OS_ACTIVITY(_desc) \
+ os_activity_t activity __attribute__((__cleanup__(_mbr_auto_os_release))) = os_activity_create(_desc, OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); \
+ os_activity_scope(activity)
+#else
+#define MBR_OS_ACTIVITY(_desc)
+#endif
+
#ifdef DS_AVAILABLE
int _si_opendirectory_disabled;
#endif
#ifdef DS_AVAILABLE
+static void
+_mbr_auto_os_release(os_activity_t *activity)
+{
+ os_release(*activity);
+ (*activity) = NULL;
+}
+
XPC_RETURNS_RETAINED
static xpc_pipe_t
_mbr_xpc_pipe(bool resetPipe)
return false;
}
+#if !DS_AVAILABLE
static bool
compatibility_name_for_id(id_t id, int rec_type, char **result)
{
return false;
}
}
+#endif
int
mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_size, int target_type, void **result, int *rec_type)
int rc = EIO;
if (identifier == NULL || result == NULL || identifier_size == 0) return EIO;
-
+
if (identifier_size == -1) {
identifier_size = strlen(identifier);
} else {
#if DS_AVAILABLE
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return EIO;
-
+
+ MBR_OS_ACTIVITY("Membership API: translate identifier");
+
xpc_dictionary_set_int64(payload, "requesting", target_type);
xpc_dictionary_set_int64(payload, "type", id_type);
xpc_dictionary_set_data(payload, "identifier", identifier, identifier_size);
#ifdef DS_AVAILABLE
xpc_object_t payload, reply;
int rc = 0;
-
+
+ MBR_OS_ACTIVITY("Membership API: Validating user is a member of group");
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return ENOMEM;
mbr_reset_cache()
{
#ifdef DS_AVAILABLE
+ MBR_OS_ACTIVITY("Membership API: Flush the membership cache");
_od_rpc_call("mbr_cache_flush", NULL, _mbr_xpc_pipe);
return 0;
#else
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return EIO;
-
+
+ MBR_OS_ACTIVITY("Membership API: Validating user is allowed by service");
+
xpc_dictionary_set_data(payload, "user_id", user, sizeof(uuid_t));
xpc_dictionary_set_int64(payload, "user_idtype", ID_TYPE_UUID);
xpc_dictionary_set_string(payload, "service", servicename);
payload = xpc_dictionary_create(NULL, NULL, 0);
if (payload == NULL) return ENOMEM;
-
+
+ MBR_OS_ACTIVITY("Membership API: Change the TTL of a given identifier in SystemCache");
+
xpc_dictionary_set_int64(payload, "type", id_type);
xpc_dictionary_set_data(payload, "identifier", identifier, identifier_size);
xpc_dictionary_set_int64(payload, "ttl", seconds);
register XDR *xdrs = &(cd->xdrs);
xdrs->x_op = XDR_DECODE;
- (void)xdrrec_skiprecord(xdrs);
- if (xdr_callmsg(xdrs, msg)) {
+ if (xdrrec_skiprecord(xdrs) && xdr_callmsg(xdrs, msg)) {
cd->x_id = msg->rm_xid;
return (TRUE);
}
+#include "<DEVELOPER_DIR>/Makefiles/CoreOS/Xcode/BSD.xcconfig"
+
HEADER_SEARCH_PATHS = /usr/local/include $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
INSTALLHDRS_SCRIPT_PHASE = YES
SDKROOT = macosx.internal
GCC_PREPROCESSOR_DEFINITIONS = __DARWIN_NON_CANCELABLE=1 __MigTypeCheck=1 INET6=1
GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*] = MUSER_AVAILABLE $(GCC_PREPROCESSOR_DEFINITIONS)
+GCC_PREPROCESSOR_DEFINITIONS[sdk=watchos*] = MUSER_AVAILABLE $(GCC_PREPROCESSOR_DEFINITIONS)
+GCC_PREPROCESSOR_DEFINITIONS[sdk=appletvos*] = MUSER_AVAILABLE $(GCC_PREPROCESSOR_DEFINITIONS)
GCC_PREPROCESSOR_DEFINITIONS[sdk=macosx*] = CONFIG_MAC DS_AVAILABLE SYNTH_ROOTFS $(GCC_PREPROCESSOR_DEFINITIONS)
+BUILD_VARIANTS = normal profile debug
+
INSTALL_PATH = /usr/lib/system
EXECUTABLE_PREFIX = libsystem_
ORDER_FILE[sdk=macosx*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order
ORDER_FILE[sdk=iphoneos*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order
+ORDER_FILE[sdk=watchos*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order
+ORDER_FILE[sdk=appletvos*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order
LINK_WITH_STANDARD_LIBRARIES = NO
LIBNOTIFY_LDFLAGS = -lsystem_notify
LIBXPC_LDFLAGS = -lxpc
LIBNETWORK_LDFLAGS = -lsystem_network
+LIBTRACE_LDFLAGS = -lsystem_trace
+
+CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
+CLANG_WARN_BOOL_CONVERSION = YES;
+CLANG_WARN_CONSTANT_CONVERSION = YES;
+CLANG_WARN_EMPTY_BODY = YES;
+CLANG_WARN_ENUM_CONVERSION = YES;
+CLANG_WARN_INFINITE_RECURSION = YES;
+CLANG_WARN_INT_CONVERSION = YES;
+CLANG_WARN_SUSPICIOUS_MOVE = YES;
+CLANG_WARN_UNREACHABLE_CODE = YES;
+CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+GCC_NO_COMMON_BLOCKS = YES;
+GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
+GCC_WARN_ABOUT_RETURN_TYPE = YES;
+GCC_WARN_UNDECLARED_SELECTOR = YES;
+GCC_WARN_UNINITIALIZED_AUTOS = YES;
+GCC_WARN_UNUSED_VARIABLE = YES;
+WARNING_LDFLAGS = -Wall
+WARNING_CFLAGS = -Wno-error=deprecated-declarations
+GCC_WARN_UNUSED_FUNCTION = YES
+
+GCC_C_LANGUAGE_STANDARD = gnu99;
+ENABLE_STRICT_OBJC_MSGSEND = YES;
+
+//:configuration = Debug
+GCC_OPTIMIZATION_LEVEL = 0
+OTHER_CFLAGS = -DDEBUG=1
+//:completeSettings = none
+
+DYLIB_COMPATIBILITY_VERSION = 1
-OTHER_LDFLAGS = -all_load -umbrella System -L/usr/lib/system $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBLAUNCH_LDFLAGS) $(LIBASL_LDFLAGS) $(LIBBLOCKS_LDFLAGS) $(LIBDNSD_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(LIBXPC_LDFLAGS) $(LIBNETWORK_LDFLAGS)
+OTHER_LDFLAGS = -all_load -umbrella System -L/usr/lib/system $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBLAUNCH_LDFLAGS) $(LIBASL_LDFLAGS) $(LIBBLOCKS_LDFLAGS) $(LIBDNSD_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(LIBXPC_LDFLAGS) $(LIBNETWORK_LDFLAGS) $(LIBTRACE_LDFLAGS)