From 9d0fc09c9d153cee4aa77a87d0b019f6e669054e Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 8 Jul 2015 00:48:41 +0000 Subject: [PATCH] Libinfo-476.tar.gz --- lookup.subproj/ds_module.c | 6 ++ lookup.subproj/file_module.c | 10 +- lookup.subproj/ils.c | 5 + lookup.subproj/libinfo.c | 3 +- lookup.subproj/mdns_module.c | 171 +++++++++++++++++++++++++------- lookup.subproj/si_data.c | 9 +- lookup.subproj/si_getaddrinfo.c | 19 +++- membership.subproj/membership.c | 44 +++++++- nis.subproj/getnetgrent.c | 5 +- rpc.subproj/clnt_simple.c | 3 +- xcodescripts/Libinfo.xcconfig | 21 +--- xcodescripts/install_files.sh | 14 ++- 12 files changed, 237 insertions(+), 73 deletions(-) diff --git a/lookup.subproj/ds_module.c b/lookup.subproj/ds_module.c index b9d1193..35a7f70 100644 --- a/lookup.subproj/ds_module.c +++ b/lookup.subproj/ds_module.c @@ -267,12 +267,14 @@ _od_rpc_call(const char *procname, xpc_object_t payload, xpc_pipe_t (*get_pipe)( xpc_object_t reply; xpc_pipe_t od_pipe; int retries, rc; + bool free_payload = false; od_pipe = get_pipe(false); if (od_pipe == NULL) return NULL; if (payload == NULL) { payload = xpc_dictionary_create(NULL, NULL, 0); + free_payload = true; } // we nest it for backward compatibility so we can do independent submissions @@ -309,6 +311,10 @@ _od_rpc_call(const char *procname, xpc_object_t payload, xpc_pipe_t (*get_pipe)( xpc_release(od_pipe); } + if (free_payload) { + xpc_release(payload); + } + return result; } diff --git a/lookup.subproj/file_module.c b/lookup.subproj/file_module.c index 95c9adb..2e9969e 100644 --- a/lookup.subproj/file_module.c +++ b/lookup.subproj/file_module.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2011 Apple Inc. All rights reserved. + * Copyright (c) 2008-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -236,12 +236,12 @@ char * _fsi_get_line(FILE *fp) { char s[4096]; - char *out; + char *x, *out; s[0] = '\0'; - fgets(s, sizeof(s), fp); - if ((s == NULL) || (s[0] == '\0')) return NULL; + x = fgets(s, sizeof(s), fp); + if ((x == NULL) || (s[0] == '\0')) return NULL; if (s[0] != '#') s[strlen(s) - 1] = '\0'; @@ -464,6 +464,8 @@ _fsi_append_char_to_line(char c, char *buf, size_t *x) if ((*x % CHUNK) == 0) { buf = reallocf(buf, *x + CHUNK); + if (buf == NULL) return NULL; + memset(buf + *x, 0, CHUNK); } diff --git a/lookup.subproj/ils.c b/lookup.subproj/ils.c index 167ed2e..1900867 100644 --- a/lookup.subproj/ils.c +++ b/lookup.subproj/ils.c @@ -41,7 +41,12 @@ /* GLOBAL */ +#if __ARM_ARCH_7K__ && __BIGGEST_ALIGNMENT__ > 4 +static const uint32_t align_32[] = { 0, 1, 2, 0, 4, 0, 0, 0, 8 }; +#else static const uint32_t align_32[] = { 0, 1, 2, 0, 4, 0, 0, 0, 4 }; +#endif + static const uint32_t align_64[] = { 0, 1, 2, 0, 4, 0, 0, 0, 8 }; static uint32_t diff --git a/lookup.subproj/libinfo.c b/lookup.subproj/libinfo.c index cb24b34..8babc95 100644 --- a/lookup.subproj/libinfo.c +++ b/lookup.subproj/libinfo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2013 Apple Inc. All rights reserved. + * Copyright (c) 2008-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -731,6 +731,7 @@ _getgrouplist_2_internal(const char *name, gid_t basegid, gid_t **groups) * we add one to the count that was found in case the basegid is not there */ gids = calloc(gl->gl_count + 1, sizeof(gid_t)); + if (gids == NULL) return -1; count = 0; merge_gid(gids, basegid, &count); diff --git a/lookup.subproj/mdns_module.c b/lookup.subproj/mdns_module.c index 09f99fc..5c4c120 100644 --- a/lookup.subproj/mdns_module.c +++ b/lookup.subproj/mdns_module.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2011 Apple Inc. All rights reserved. + * Copyright (c) 2008-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -138,7 +138,6 @@ #define MDNS_DEBUG_STDERR 0x00000002 #define MDNS_DEBUG_ASL 0x00000004 #define MDNS_DEBUG_OUT 0x00000007 -#define MDNS_DEBUG_MORE 0x00000010 static int _mdns_debug = 0; @@ -313,6 +312,7 @@ _mdns_hostent_append_alias(mdns_hostent_t *h, const char *alias) int i; char *name; + _mdns_debug_message(";; _mdns_hostent_append_alias(%p, %s)\n", h, alias); if ((h == NULL) || (alias == NULL)) return 0; name = _mdns_canonicalize(alias); @@ -357,6 +357,7 @@ _mdns_hostent_append_alias(mdns_hostent_t *h, const char *alias) static int _mdns_hostent_append_addr(mdns_hostent_t *h, const uint8_t *addr, uint32_t len) { + _mdns_debug_message(";; _mdns_hostent_append_addr(%p, %p, %u)\n", h, addr, len); if ((h == NULL) || (addr == NULL) || (len == 0)) return 0; /* copy the address buffer */ @@ -464,7 +465,7 @@ mdns_hostbyname(si_mod_t *si, const char *name, int af, const char *interface, u } _mdns_debug_message(";; mdns_hostbyname %s type %u class %u\n", name, type, ns_c_in); - + h.host.h_addrtype = af; status = _mdns_search(name, ns_c_in, type, interface, flags, NULL, NULL, &reply); @@ -539,7 +540,7 @@ mdns_hostbyaddr(si_mod_t *si, const void *addr, int af, const char *interface, u h.host.h_addrtype = af; _mdns_debug_message(";; mdns_hostbyaddr %s type %u class %u\n", name, ns_t_ptr, ns_c_in); - + status = _mdns_search(name, ns_c_in, ns_t_ptr, interface, flags, NULL, NULL, &reply); free(name); if (status != 0) @@ -610,7 +611,7 @@ mdns_addrinfo(si_mod_t *si, const void *node, const void *serv, uint32_t family, if (err != NULL) *err = SI_STATUS_NO_ERROR; _mdns_debug_message(";; mdns_addrinfo node %s serv %s\n", (const char *)node, (const char *)serv); - + si_list_t *out = NULL; memset(&h4, 0, sizeof(h4)); @@ -772,7 +773,7 @@ mdns_item_call(si_mod_t *si, int call, const char *name, const char *ignored, co if (err != NULL) *err = SI_STATUS_NO_ERROR; _mdns_debug_message(";; mdns_item_call %s type %u class %u\n", name, type, class); - + memset(&h4, 0, sizeof(h4)); memset(&h6, 0, sizeof(h6)); memset(&reply, 0, sizeof(reply)); @@ -868,7 +869,6 @@ _mdns_init(void) if ((c[i] == 'o') || (c[i] == 'O')) _mdns_debug |= MDNS_DEBUG_STDOUT; if ((c[i] == 'e') || (c[i] == 'E')) _mdns_debug |= MDNS_DEBUG_STDERR; if ((c[i] == 'a') || (c[i] == 'A')) _mdns_debug |= MDNS_DEBUG_ASL; - if ((c[i] == 'm') || (c[i] == 'M')) _mdns_debug |= MDNS_DEBUG_MORE; } } } @@ -1127,7 +1127,7 @@ _mdns_make_query(const char* name, int class, int type, uint8_t *buf, uint32_t b return len; } -typedef struct +typedef struct mdns_query_context_s { mdns_reply_t *reply; mdns_hostent_t *host; @@ -1141,8 +1141,11 @@ typedef struct DNSServiceFlags flags; DNSServiceErrorType error; int kq; // kqueue to notify when callback received + struct mdns_query_context_s *next; // linked list } mdns_query_context_t; +static mdns_query_context_t *in_flight; + static void _mdns_query_callback(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType, const char *, uint16_t, uint16_t, uint16_t, const void *, uint32_t, void *); @@ -1208,6 +1211,11 @@ _mdns_query_start(mdns_query_context_t *ctx, mdns_reply_t *reply, uint8_t *answe status = DNSServiceQueryRecord(&ctx->sd, flags, iface, qname, type, class, _mdns_query_callback, ctx); if (qname != name) free(qname); + + /* keep a linked list of all in-flight queries */ + ctx->next = in_flight; + in_flight = ctx; + return status; } @@ -1217,25 +1225,23 @@ _mdns_query_start(mdns_query_context_t *ctx, mdns_reply_t *reply, uint8_t *answe * considered complete. */ static bool -_mdns_query_is_complete(mdns_query_context_t *ctx) +_mdns_query_is_complete(mdns_query_context_t *ctx, bool *more) { bool complete = false; /* NULL context is an error, but we call it complete */ if (ctx == NULL) return true; - /* - * The default is to ignore kDNSServiceFlagsMoreComing, since it has either - * never been supported or worked correctly. MDNS_DEBUG_MORE makes us honor it. - */ + /* not complete if discoveryd says there is more coming (for some in-flight query - possibly not this one) */ if (ctx->flags & kDNSServiceFlagsMoreComing) { - if (_mdns_debug & MDNS_DEBUG_MORE) - { - _mdns_debug_message(";; mdns is_complete type %d ctx %p more coming - incomplete\n", ctx->type, ctx); - return false; - } - } + if (more != NULL) *more = true; + _mdns_debug_message(";; mdns is_complete type %d ctx %p more coming - incomplete\n", ctx->type, ctx); + return false; + } else { + if (more != NULL) *more = false; + _mdns_debug_message(";; mdns is_complete type %d ctx %p clear more coming - complete\n", ctx->type, ctx); + } if (ctx->last_type != ctx->type) { @@ -1247,19 +1253,31 @@ _mdns_query_is_complete(mdns_query_context_t *ctx) { case ns_t_a: case ns_t_aaaa: - if (ctx->host != NULL && ctx->host->addr_count > 0) complete = true; + if (ctx->host != NULL && ctx->host->addr_count > 0) + { + _mdns_debug_message(";; mdns is_complete type %d ctx %p host addr count %d complete -> true\n", ctx->type, ctx, ctx->host->addr_count); + complete = true; + } break; case ns_t_ptr: - if (ctx->host != NULL && ctx->host->host.h_name != NULL) complete = true; + if (ctx->host != NULL && ctx->host->host.h_name != NULL) + { + complete = true; + _mdns_debug_message(";; mdns is_complete type %d ctx %p host name %s complete -> true\n", ctx->type, ctx, ctx->host->host.h_name); + } break; case ns_t_srv: - if (ctx->reply != NULL && ctx->reply->srv != NULL) complete = true; + if (ctx->reply != NULL && ctx->reply->srv != NULL) + { + _mdns_debug_message(";; mdns is_complete type %d ctx %p srv %s complete -> true\n", ctx->type, ctx, ctx->reply->srv); + complete = true; + } break; default: _mdns_debug_message(";; mdns is_complete unexpected type %d ctx %p\n", ctx->type, ctx); } - _mdns_debug_message(";; mdns is_complete type %d ctx %p %s%scomplete\n", ctx->type, ctx, (ctx->flags & kDNSServiceFlagsMoreComing) ? "(more coming flag ignored)" : "", complete ? " - " : " - in"); + _mdns_debug_message(";; mdns is_complete type %d ctx %p %scomplete\n", ctx->type, ctx, complete ? " - " : " - in"); return complete; } @@ -1267,14 +1285,17 @@ _mdns_query_is_complete(mdns_query_context_t *ctx) /* * _mdns_query_clear * Clear out the temporary fields of the context, and clear any result - * structures that are incomplete. Retrns 1 if the query was complete. + * structures that are incomplete. Returns true if the query was complete. */ static bool _mdns_query_clear(mdns_query_context_t *ctx) { - bool complete = _mdns_query_is_complete(ctx); + mdns_query_context_t *p; + + if (ctx == NULL) return true; - if (ctx == NULL) return complete; + bool more = false; + bool complete = _mdns_query_is_complete(ctx, &more); if (ctx->sd != NULL) { @@ -1290,27 +1311,54 @@ _mdns_query_clear(mdns_query_context_t *ctx) ctx->flags = 0; ctx->kq = -1; - if (!complete) + if (in_flight == ctx) + { + in_flight = ctx->next; + } + else + { + p = in_flight; + while ((p != NULL) && (p->next != ctx)) p = p->next; + if (p != NULL) p->next = ctx->next; + } + + ctx->next = NULL; + + if (!complete && !more) { _mdns_hostent_clear(ctx->host); ctx->anslen = -1; } - return complete; + return complete | more; } static void _mdns_query_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata, uint32_t ttl, void *ctx) { - mdns_query_context_t *context; + mdns_query_context_t *p, *context; struct in6_addr a6; context = (mdns_query_context_t *)ctx; + _mdns_debug_message(";; _mdns_query_callback ctx %p flags=0x%08x%s\n", context, flags, (flags & kDNSServiceFlagsMoreComing) ? " (kDNSServiceFlagsMoreComing is set)" : ""); context->flags = flags; context->error = errorCode; context->last_type = rrtype; + /* if kDNSServiceFlagsMoreComing is NOT set, there is no more data coming for ALL in-flight queries */ + if (!(flags & kDNSServiceFlagsMoreComing)) + { + for (p = in_flight; p != NULL; p = p->next) + { + if (p->flags & kDNSServiceFlagsMoreComing) + { + _mdns_debug_message(";; cleared kDNSServiceFlagsMoreComing flag for ctx %p\n", p); + p->flags &= ~kDNSServiceFlagsMoreComing; + } + } + } + if (errorCode != kDNSServiceErr_NoError) { _mdns_debug_message(";; [%s type %hu class %hu]: error %d [ctx %p]\n", fullname, rrtype, rrclass, errorCode, context); @@ -1524,6 +1572,7 @@ wakeup_kevent: /* Ping the waiting thread in case this callback was invoked on another */ if (context->kq != -1) { + _mdns_debug_message(";; _mdns_query_callback sending kevent wakeup\n"); struct kevent ev; EV_SET(&ev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0); int res = kevent(context->kq, &ev, 1, NULL, 0, NULL); @@ -1607,6 +1656,7 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe /* 2 for A and AAAA parallel queries */ int n_ctx = 0; mdns_query_context_t ctx[2]; + bool more_coming[2]; if (name == NULL) return -1; @@ -1638,8 +1688,11 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe timeout = delta; _mdns_now(&start); - for (i = 0; i < 2; ++i) memset(&ctx[i], 0 , sizeof(mdns_query_context_t)); + for (i = 0; i < 2; ++i) { + memset(&ctx[i], 0 , sizeof(mdns_query_context_t)); + more_coming[i] = false; + } /* set up the kqueue */ kq = kqueue(); EV_SET(&ev, 1, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, 0); @@ -1648,6 +1701,8 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe while (wait) { + _mdns_debug_message(";; _mdns_search wait loop\n"); + if (initialize) { initialize = false; @@ -1726,6 +1781,7 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe _mdns_debug_message(";; set kevent timeout %ld.%ld [ctx %p %p]\n", timeout.tv_sec, timeout.tv_nsec, (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); + errno = 0; n = kevent(kq, NULL, 0, &ev, 1, &timeout); if ((n < 0) && (errno != EINTR)) { @@ -1745,10 +1801,13 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe if (_mdns_sdref == NULL) { initialize = true; + _mdns_debug_message(";; _mdns_sdref is NULL, initialize = true\n"); } else if (m > 0 && ev.filter == EVFILT_READ) { + _mdns_debug_message(";; _mdns_search calling DNSServiceProcessResult\n", err); err = DNSServiceProcessResult(_mdns_sdref); + _mdns_debug_message(";; DNSServiceProcessResult -> %s\n", err); if ((err == kDNSServiceErr_ServiceNotRunning) || (err == kDNSServiceErr_BadReference)) { _mdns_debug_message(";; DNSServiceProcessResult status %d [ctx %p %p]\n", err, (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); @@ -1761,17 +1820,29 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe initialize = true; } } + else if (m == 0 && ev.filter == EVFILT_USER) + { + _mdns_debug_message(";; kevent wakeup\n", m, (int)ev.filter); + } + else + { + _mdns_debug_message(";; kevent m=%d ev.filter=0x%08x\n", m, ev.filter); + } /* Check if all queries are complete (including errors) */ complete = true; for (i = 0; i < n_ctx; ++i) { - if ((ctx[i].error != 0) || _mdns_query_is_complete(&ctx[i])) + bool qc = _mdns_query_is_complete(&ctx[i], &more_coming[i]); + _mdns_debug_message(";; ctx %d %p error=%d complete=%s\n", i, &(ctx[i]), ctx[i].error, qc ? "true" : "false"); + + if ((ctx[i].error != 0) || qc) { if (ctx[i].type == ns_t_a) { got_a_response = GOT_DATA; if (ctx[i].error != 0) got_a_response = GOT_ERROR; + _mdns_debug_message(";; type ns_t_a got_a_response=%s ctx %p\n", (got_a_response == GOT_DATA) ? "GOT_DATA" : "GOT_ERROR", &(ctx[i])); } _mdns_debug_message(";; [%s type %d class %d] finished processing ctx %p\n", name, type, class, &(ctx[i])); @@ -1795,7 +1866,30 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe _mdns_debug_message(";; [%s type %d class %d] done [ctx %p %p]\n", name, type, class, (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); break; } - else if (got_a_response != 0) + else if (more_coming[0] || more_coming[1]) + { + /* got partial data - probably from cache - reduce wait time */ + struct timespec now, tmp, extra; + + /* tmp = now - start */ + _mdns_now(&now); + _mdns_sub_time(&tmp, &now, &start); + + extra.tv_sec = MEDIUM_AAAA_EXTRA; + extra.tv_nsec = 0; + + /* delta = tmp + extra */ + _mdns_add_time(&delta, &tmp, &extra); + + /* check that delta doesn't exceed our total timeout */ + _mdns_sub_time(&tmp, &timeout, &delta); + if (tmp.tv_sec >= 0) + { + _mdns_debug_message(";; new timeout [%s type %d class %d] (waiting for more) %ld.%ld [ctx %p %p]\n", name, type, class, delta.tv_sec, delta.tv_nsec, (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); + _mdns_deadline(&finish, &delta); + } + } + else if (got_a_response == GOT_DATA) { /* got A, adjust deadline for AAAA */ struct timespec now, tn, extra; @@ -1807,7 +1901,7 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe extra.tv_sec = SHORT_AAAA_EXTRA; extra.tv_nsec = 0; - /* if delta is small (<= 20 milliseconds), we probably got a result from mDNSResponder's cache */ + /* if delta is small (<= 20 milliseconds), we probably got a result from cache */ if ((delta.tv_sec == 0) && (delta.tv_nsec <= 20000000)) { extra.tv_sec = MEDIUM_AAAA_EXTRA; @@ -1847,16 +1941,22 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe } } + _mdns_debug_message(";; finished _mdns_search loop [ctx %p %p]\n", (n_ctx > 0) ? &(ctx[0]) : NULL, (n_ctx > 1) ? &(ctx[1]) : NULL); + complete = false; pthread_mutex_lock(&_mdns_mutex); for (i = 0; i < n_ctx; ++i) { - if (err == 0) err = ctx[i].error; /* only clears hostents if result is incomplete */ - complete = _mdns_query_clear(&ctx[i]) | complete; + bool cc = _mdns_query_clear(&ctx[i]); + complete = cc | complete; + _mdns_debug_message(";; _mdns_search ctx %p %scomplete\n", &ctx[i], cc ? "" : "in"); } + if (more_coming[0] || more_coming[1]) complete = false; + + _mdns_debug_message(";; _mdns_search overall %scomplete\n", complete ? "" : "in"); pthread_mutex_unlock(&_mdns_mutex); /* everything should be done with the kq by now */ @@ -1866,5 +1966,6 @@ _mdns_search(const char *name, int class, int type, const char *interface, DNSSe if (!complete) res = -1; if (anslen != NULL) *anslen = ctx[0].anslen; + _mdns_debug_message(";; _mdns_search exit res %d\n", res); return res; } diff --git a/lookup.subproj/si_data.c b/lookup.subproj/si_data.c index 978f6ac..be9b541 100644 --- a/lookup.subproj/si_data.c +++ b/lookup.subproj/si_data.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2009 Apple Inc. All rights reserved. + * Copyright (c) 2008-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -38,7 +38,7 @@ si_list_add(si_list_t *l, si_item_t *e) if (l == NULL) { l = (si_list_t *)calloc(1, sizeof(si_list_t)); - l->refcount = 1; + if (l != NULL) l->refcount = 1; } if (l != NULL) @@ -46,10 +46,7 @@ si_list_add(si_list_t *l, si_item_t *e) size = (l->count + 1) * sizeof(si_item_t *); l->entry = (si_item_t **)reallocf(l->entry, size); - if (l->entry != NULL) - { - l->entry[l->count++] = si_item_retain(e); - } + if (l->entry != NULL) l->entry[l->count++] = si_item_retain(e); } if ((l == NULL) || (l->entry == NULL)) diff --git a/lookup.subproj/si_getaddrinfo.c b/lookup.subproj/si_getaddrinfo.c index cf0e584..cb2fc1e 100644 --- a/lookup.subproj/si_getaddrinfo.c +++ b/lookup.subproj/si_getaddrinfo.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2011 Apple Inc. All rights reserved. + * Copyright (c) 2008-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -272,6 +272,13 @@ si_nameinfo(si_mod_t *si, const struct sockaddr *sa, int flags, const char *inte { struct hostent *h; h = (struct hostent *)((uintptr_t)item + sizeof(si_item_t)); + if (h->h_name == NULL) + { + si_item_release(item); + if (err != NULL) *err = SI_STATUS_EAI_FAIL; + return NULL; + } + host = strdup(h->h_name); si_item_release(item); if (host == NULL) @@ -289,6 +296,14 @@ si_nameinfo(si_mod_t *si, const struct sockaddr *sa, int flags, const char *inte { struct servent *s; s = (struct servent *)((uintptr_t)item + sizeof(si_item_t)); + if (s->s_name == NULL) + { + si_item_release(item); + free(host); + if (err != NULL) *err = SI_STATUS_EAI_FAIL; + return NULL; + } + serv = strdup(s->s_name); si_item_release(item); if (serv == NULL) @@ -1324,6 +1339,7 @@ lower_case(const char *s) if (s == NULL) return NULL; t = malloc(strlen(s) + 1); + if (t == NULL) return NULL; for (i = 0; s[i] != '\0'; i++) { @@ -1343,6 +1359,7 @@ merge_alias(const char *name, build_hostent_t *h) if (name == NULL) return 0; if (h == NULL) return 0; + if (h->host.h_name == NULL) return 0; if ((h->host.h_name != NULL) && (string_equal(name, h->host.h_name))) return 0; diff --git a/membership.subproj/membership.c b/membership.subproj/membership.c index 3074ed5..ff37c3c 100644 --- a/membership.subproj/membership.c +++ b/membership.subproj/membership.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2010 Apple Inc. All rights reserved. + * Copyright (c) 2004-2015 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #include #include "membership.h" #include "membershipPriv.h" @@ -183,6 +186,7 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ if (memcmp(uu, _user_compat_prefix, COMPAT_PREFIX_LEN) == 0) { id_t *tempRes = malloc(sizeof(*tempRes)); + if (tempRes == NULL) return ENOMEM; memcpy(&tempID, &uu[COMPAT_PREFIX_LEN], sizeof(tempID)); (*tempRes) = ntohl(tempID); (*result) = tempRes; @@ -192,6 +196,7 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ return 0; } else if (memcmp(uu, _group_compat_prefix, COMPAT_PREFIX_LEN) == 0) { id_t *tempRes = malloc(sizeof(*tempRes)); + if (tempRes == NULL) return ENOMEM; memcpy(&tempID, &uu[COMPAT_PREFIX_LEN], sizeof(tempID)); (*tempRes) = ntohl(tempID); (*result) = tempRes; @@ -213,6 +218,7 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ tempID = *((id_t *) identifier); if ((tempID == 0) || (_mbr_od_available() == false)) { uint8_t *tempUU = malloc(sizeof(uuid_t)); + if (tempUU == NULL) return ENOMEM; uuid_copy(tempUU, _user_compat_prefix); *((id_t *) &tempUU[COMPAT_PREFIX_LEN]) = htonl(tempID); (*result) = tempUU; @@ -229,6 +235,7 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ tempID = *((id_t *) identifier); if ((tempID == 0) || (_mbr_od_available() == false)) { uint8_t *tempUU = malloc(sizeof(uuid_t)); + if (tempUU == NULL) return ENOMEM; uuid_copy(tempUU, _group_compat_prefix); *((id_t *) &tempUU[COMPAT_PREFIX_LEN]) = htonl(tempID); (*result) = tempUU; @@ -260,7 +267,8 @@ mbr_identifier_translate(int id_type, const void *identifier, size_t identifier_ reply_id = xpc_dictionary_get_data(reply, "identifier", &idLen); if (reply_id != NULL) { char *identifier = malloc(idLen); - + if (identifier == NULL) return ENOMEM; + memcpy(identifier, reply_id, idLen); // should already be NULL terminated, etc. (*result) = identifier; @@ -345,6 +353,37 @@ mbr_identifier_to_uuid(int id_type, const void *identifier, size_t identifier_si uuid_copy(uu, result); free(result); } + else if ((rc == EIO) && (_mbr_od_available() == false)) { + switch (id_type) { + case ID_TYPE_USERNAME: + { + struct passwd *pw = getpwnam(identifier); + if (pw) { + rc = mbr_identifier_translate(ID_TYPE_UID, &(pw->pw_uid), sizeof(id_t), ID_TYPE_UUID, (void **) &result, NULL); + if (rc == 0) { + uuid_copy(uu, result); + free(result); + } + } + break; + } + case ID_TYPE_GROUPNAME: + { + struct group *grp = getgrnam(identifier); + if (grp) { + rc = mbr_identifier_translate(ID_TYPE_GID, &(grp->gr_gid), sizeof(id_t), ID_TYPE_UUID, (void **) &result, NULL); + if (rc == 0) { + uuid_copy(uu, result); + free(result); + } + } + break; + } + + default: + break; + } + } return rc; } @@ -427,6 +466,7 @@ mbr_check_membership_ext(int userid_type, const void *userid, size_t userid_size xpc_dictionary_set_int64(payload, "user_idtype", userid_type); xpc_dictionary_set_data(payload, "user_id", userid, userid_size); xpc_dictionary_set_int64(payload, "group_idtype", groupid_type); + xpc_dictionary_set_bool(payload, "refresh", refresh); switch (groupid_type) { case ID_TYPE_GROUPNAME: diff --git a/nis.subproj/getnetgrent.c b/nis.subproj/getnetgrent.c index 3894676..04b0acc 100644 --- a/nis.subproj/getnetgrent.c +++ b/nis.subproj/getnetgrent.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2015 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -72,6 +72,7 @@ void _old_setnetgrent(grp) if (oldgrp == NULL) oldgrp = (char *)calloc(1,256); + if (oldgrp == NULL) return; if (strcmp(oldgrp, grp) == 0) grlist = grouplist; else { @@ -162,6 +163,7 @@ doit(group,list) if (*p == '(') { gpls = (struct grouplist *) malloc(sizeof(struct grouplist)); + if (gpls == NULL) return; p++; if (!(p = fill(p,&gpls->gl_machine,','))) goto syntax_error; @@ -215,6 +217,7 @@ fill(start,target,termchar) ; size = q - p + 1; *target = malloc(size+1); + if (*target == NULL) return NULL; (void) strncpy(*target,p,(int) size); (*target)[size] = 0; } diff --git a/rpc.subproj/clnt_simple.c b/rpc.subproj/clnt_simple.c index b00bc19..06ce74a 100644 --- a/rpc.subproj/clnt_simple.c +++ b/rpc.subproj/clnt_simple.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2015 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -101,6 +101,7 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) } if (crp->oldhost == NULL) { crp->oldhost = malloc(256); + if (crp->oldhost == NULL) return -1; crp->oldhost[0] = 0; crp->socket = RPC_ANYSOCK; } diff --git a/xcodescripts/Libinfo.xcconfig b/xcodescripts/Libinfo.xcconfig index ad31df8..e9256fc 100644 --- a/xcodescripts/Libinfo.xcconfig +++ b/xcodescripts/Libinfo.xcconfig @@ -1,16 +1,12 @@ -#include "/AppleInternal/XcodeConfig/SimulatorSupport.xcconfig" - INSTALLHDRS_SCRIPT_PHASE = YES GCC_PREPROCESSOR_DEFINITIONS = __DARWIN_NON_CANCELABLE=1 __MigTypeCheck=1 INET6=1 GCC_PREPROCESSOR_DEFINITIONS[sdk=iphone*] = CONFIG_IPHONE $(GCC_PREPROCESSOR_DEFINITIONS) GCC_PREPROCESSOR_DEFINITIONS[sdk=macosx*] = CONFIG_MAC DS_AVAILABLE SYNTH_ROOTFS $(GCC_PREPROCESSOR_DEFINITIONS) -INSTALL_PATH_ACTUAL = /usr/lib/system -INSTALL_PATH[sdk=macosx*] = $(INSTALL_PATH_ACTUAL) +INSTALL_PATH = /usr/lib/system EXECUTABLE_PREFIX = libsystem_ -EXECUTABLE_PREFIX[sdk=iphonesimulator*] = libsystem_sim_ ORDER_FILE[sdk=macosx*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order ORDER_FILE[sdk=iphoneos*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsystem_info.order @@ -18,32 +14,23 @@ ORDER_FILE[sdk=iphoneos*] = $(SDKROOT)/$(APPLE_INTERNAL_DIR)/OrderFiles/libsyste LINK_WITH_STANDARD_LIBRARIES = NO LIBCOMPILER_RT_LDFLAGS = -lcompiler_rt -LIBCOMPILER_RT_LDFLAGS[sdk=iphonesimulator*] = -lcompiler_rt_sim LIBMALLOC_LDFLAGS = -lsystem_malloc -LIBMALLOC_LDFLAGS[sdk=iphonesimulator*] = -Wl,-upward-lSystem LIBPLATFORM_LDFLAGS = -lsystem_platform -LIBPLATFORM_LDFLAGS[sdk=iphonesimulator*] = -Wl,-upward-lSystem +LIBPLATFORM_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_platform LIBPTHREAD_LDFLAGS = -lsystem_pthread -LIBPTHREAD_LDFLAGS[sdk=iphonesimulator*] = -Wl,-upward-lSystem +LIBPTHREAD_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_pthread LIBSYSCALL_LDFLAGS = -lsystem_kernel -LIBSYSCALL_LDFLAGS[sdk=iphonesimulator*] = -Wl,-upward-lSystem +LIBSYSCALL_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_kernel LIBM_LDFLAGS = -lsystem_m LIBM_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_m LIBDYLD_LDFLAGS = -ldyld -LIBDYLD_LDFLAGS[sdk=iphonesimulator*] = -ldyld_sim LIBC_LDFLAGS = -lsystem_c -LIBC_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_c LIBDISPATCH_LDFLAGS = -ldispatch LIBLAUNCH_LDFLAGS = -llaunch -LIBLAUNCH_LDFLAGS[sdk=iphonesimulator*] = LIBASL_LDFLAGS = -lsystem_asl -LIBASL_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_asl LIBBLOCKS_LDFLAGS = -lsystem_blocks -LIBBLOCKS_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_blocks LIBDNSD_LDFLAGS = -lsystem_dnssd -LIBDNSD_LDFLAGS[sdk=iphonesimulator*] = -lsystem_sim_dnssd LIBNOTIFY_LDFLAGS = -lsystem_notify -LIBNOTIFY_LDFLAGS[sdk=iphonesimulator*] = -lnotify_sim LIBXPC_LDFLAGS = -lxpc LIBNETWORK_LDFLAGS = -Wl,-upward-lsystem_network diff --git a/xcodescripts/install_files.sh b/xcodescripts/install_files.sh index 85d1a7d..c54d8a8 100755 --- a/xcodescripts/install_files.sh +++ b/xcodescripts/install_files.sh @@ -1,8 +1,8 @@ +#!/bin/bash -e -x # exit immediately on failure -set -e -x function InstallHeaders() { - DESTDIR="$DSTROOT/$INSTALL_PATH_PREFIX/$1" + DESTDIR="$DSTROOT/$1" shift install -d -o "$INSTALL_OWNER" -g "$INSTALL_GROUP" -m 0755 "$DESTDIR" install -o "$INSTALL_OWNER" -g "$INSTALL_GROUP" -m 0444 "$@" "$DESTDIR" @@ -51,9 +51,13 @@ InstallHeaders /usr/include/rpcsvc \ nis.subproj/ypclnt.h # Don't install man pages for installhdrs nor simulator builds -if [ "$ACTION" == "installhdrs" -o \ - "${RC_ProjectName%_Sim}" != "${RC_ProjectName}" ] ; then - exit 0 +if [[ "${ACTION}" == "installhdrs" ]]; then + exit 0 +fi + +if [[ "${PLATFORM_NAME}" =~ "simulator" ]]; then + ln -s libsystem_info.dylib ${DSTROOT}${INSTALL_PATH}/libsystem_sim_info.dylib + exit 0 fi function InstallManPages() { -- 2.47.2