From 1d9e5cb8ce34c6120503c023c843076e0804d8c8 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 2 May 2006 16:17:04 +0000 Subject: [PATCH] Libinfo-222.4.6.tar.gz --- Makefile.preamble | 2 +- lookup.subproj/getaddrinfo.c | 137 +++------------ lookup.subproj/lu_alias.c | 2 +- lookup.subproj/lu_bootparam.c | 2 +- lookup.subproj/lu_fstab.c | 4 +- lookup.subproj/lu_group.c | 27 ++- lookup.subproj/lu_host.c | 1 - lookup.subproj/lu_host_async.c | 1 - lookup.subproj/lu_network.c | 4 +- lookup.subproj/lu_printer.c | 2 +- lookup.subproj/lu_protocol.c | 2 +- lookup.subproj/lu_rpc.c | 2 +- lookup.subproj/lu_utils.c | 122 ++++++++++++- mdns.subproj/dnssd_clientstub.c | 19 +- mdns.subproj/dnssd_ipc.h | 2 +- membership.subproj/memberd.defs | 74 +++----- membership.subproj/membership.c | 375 ++++++++++++++++++---------------------- rpc.subproj/getrpcent.c | 2 +- rpc.subproj/svc_auth_unix.c | 10 +- 19 files changed, 377 insertions(+), 413 deletions(-) diff --git a/Makefile.preamble b/Makefile.preamble index bea5923..25d484e 100644 --- a/Makefile.preamble +++ b/Makefile.preamble @@ -3,4 +3,4 @@ STRIP_ON_INSTALL = NO BEFORE_INSTALL += debug profile override LINK_SUBPROJECTS = NO -export CCOMPILER = /usr/bin/gcc-3.5 +# export CCOMPILER = /usr/bin/gcc-X.X diff --git a/lookup.subproj/getaddrinfo.c b/lookup.subproj/getaddrinfo.c index ae67e31..ce51a5e 100644 --- a/lookup.subproj/getaddrinfo.c +++ b/lookup.subproj/getaddrinfo.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -107,7 +106,7 @@ static int gai_family_type_check(int32_t f) { int32_t i; - + for (i = 0; i < supported_family_count; i++) { if (f == supported_family[i]) return 0; @@ -120,7 +119,7 @@ static int gai_socket_type_check(int32_t s) { int32_t i; - + for (i = 0; i < supported_socket_count; i++) { if (s == supported_socket[i]) return 0; @@ -133,7 +132,7 @@ static int gai_protocol_type_check(int32_t p) { int32_t i; - + for (i = 0; i < supported_protocol_count; i++) { if (p == supported_protocol[i]) return 0; @@ -146,7 +145,7 @@ static int gai_socket_protocol_type_check(int32_t s, int32_t p) { int32_t i, j, ss, sp; - + for (i = 0, j = 0; i < supported_socket_protocol_pair_count; i++, j+=2) { ss = supported_socket_protocol_pair[j]; @@ -518,7 +517,6 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo if (!xdr_int(&outxdr, (int32_t *)&na)) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } @@ -527,7 +525,6 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo if (encode_kv(&outxdr, "name", nodename) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -537,7 +534,6 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo if (encode_kv(&outxdr, "service", servname) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -548,69 +544,62 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo if (encode_kv(&outxdr, "protocol", str) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (socktype != SOCK_UNSPEC) { snprintf(str, 64, "%u", socktype); if (encode_kv(&outxdr, "socktype", str) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (family != PF_UNSPEC) { snprintf(str, 64, "%u", family); if (encode_kv(&outxdr, "family", str) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (canonname != 0) { if (encode_kv(&outxdr, "canonname", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (passive != 0) { if (encode_kv(&outxdr, "passive", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (parallel != 0) { if (encode_kv(&outxdr, "parallel", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } - + if (numerichost != 0) { if (encode_kv(&outxdr, "numerichost", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -618,7 +607,7 @@ gai_make_query(const char *nodename, const char *servname, const struct addrinfo *len = xdr_getpos(&outxdr); xdr_destroy(&outxdr); - + return 0; } @@ -817,16 +806,10 @@ gai_lookupd(const char *nodename, const char *servname, const struct addrinfo *h if (gai_proc < 0) { status = _lookup_link(server_port, "getaddrinfo", &gai_proc); - if (status != KERN_SUCCESS) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (status != KERN_SUCCESS) return EAI_SYSTEM; } qlen = LU_QBUF_SIZE; - - /* gai_make_query sets errno if it fails */ i = gai_make_query(nodename, servname, hints, qbuf, &qlen); if (i != 0) return EAI_SYSTEM; @@ -844,7 +827,6 @@ gai_lookupd(const char *nodename, const char *servname, const struct addrinfo *h if (!xdr_int(&inxdr, (int32_t *)&n)) { xdr_destroy(&inxdr); - errno = EIO; return EAI_SYSTEM; } @@ -905,7 +887,7 @@ getaddrinfo(const char * __restrict nodename, const char * __restrict servname, servnull = 0; if ((servname == NULL) || (servname[0] == '\0')) servnull = 1; - + if ((nodenull == 1) && (servnull == 1)) return EAI_NONAME; status = gai_checkhints(hints); if (status != 0) return status; @@ -936,38 +918,21 @@ getaddrinfo_async_start(mach_port_t *p, const char *nodename, const char *servna server_port = MACH_PORT_NULL; if (_lu_running()) server_port = _lookupd_port(0); - if (server_port == MACH_PORT_NULL) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (server_port == MACH_PORT_NULL) return EAI_SYSTEM; if (gai_proc < 0) { status = _lookup_link(server_port, "getaddrinfo", &gai_proc); - if (status != KERN_SUCCESS) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (status != KERN_SUCCESS) return EAI_SYSTEM; } qlen = LU_QBUF_SIZE; - - /* gai_make_query sets errno if it fails */ i = gai_make_query(nodename, servname, hints, qbuf, &qlen); if (i != 0) return EAI_SYSTEM; qlen /= BYTES_PER_XDR_UNIT; - status = lu_async_start(p, gai_proc, qbuf, qlen, (void *)callback, context); - if (status != 0) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } - - return 0; + return lu_async_start(p, gai_proc, qbuf, qlen, (void *)callback, context); } int32_t @@ -994,7 +959,6 @@ gai_extract_data(char *buf, uint32_t len, struct addrinfo **res) if (!xdr_int(&xdr, (int32_t *)&n)) { xdr_destroy(&xdr); - errno = EIO; return EAI_SYSTEM; } @@ -1116,17 +1080,9 @@ gni_lookupd_process_dictionary(XDR *inxdr, char **host, char **serv) int32_t i, j, nkeys, nvals, status; char *key, **vals; - if ((host == NULL) || (serv == NULL)) - { - errno = EINVAL; - return EAI_SYSTEM; - } + if ((host == NULL) || (serv == NULL)) return EAI_SYSTEM; - if (!xdr_int(inxdr, &nkeys)) - { - errno = EIO; - return EAI_SYSTEM; - } + if (!xdr_int(inxdr, &nkeys)) return EAI_SYSTEM; *host = NULL; *serv = NULL; @@ -1136,13 +1092,9 @@ gni_lookupd_process_dictionary(XDR *inxdr, char **host, char **serv) key = NULL; vals = NULL; nvals = 0; - + status = _lu_xdr_attribute(inxdr, &key, &vals, (uint32_t *)&nvals); - if (status < 0) - { - errno = EIO; - return EAI_SYSTEM; - } + if (status < 0) return EAI_SYSTEM; if (nvals == 0) { @@ -1240,7 +1192,7 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse ifnum = s6->sin6_addr.__u6_addr.__u6_addr16[1]; if (ifnum == 0) ifnum = s6->sin6_scope_id; else if ((s6->sin6_scope_id != 0) && (ifnum != s6->sin6_scope_id)) return EAI_FAIL; - + s6->sin6_addr.__u6_addr.__u6_addr16[1] = 0; s6->sin6_scope_id = ifnum; if ((ifnum != 0) && (flags & NI_NUMERICHOST)) flags |= NI_WITHSCOPEID; @@ -1295,7 +1247,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (!xdr_int(&outxdr, (int32_t *)&na)) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } @@ -1316,7 +1267,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, key, str) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1327,7 +1277,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "port", str) != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1337,7 +1286,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "protocol", "udp") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1347,7 +1295,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "fqdn", "0") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1357,7 +1304,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "numerichost", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1367,7 +1313,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "numericserv", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1377,7 +1322,6 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse if (encode_kv(&outxdr, "name_required", "1") != 0) { xdr_destroy(&outxdr); - errno = EIO; return EAI_SYSTEM; } } @@ -1385,7 +1329,7 @@ gni_make_query(const struct sockaddr *sa, size_t salen, int wanthost, int wantse *len = xdr_getpos(&outxdr); xdr_destroy(&outxdr); - + return 0; } @@ -1447,7 +1391,7 @@ getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __res return i; } } - + wanth = 0; if ((host != NULL) && (hostlen != 0)) wanth = 1; @@ -1504,20 +1448,12 @@ getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __res */ server_port = MACH_PORT_NULL; if (_lu_running()) server_port = _lookupd_port(0); - if (server_port == MACH_PORT_NULL) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (server_port == MACH_PORT_NULL) return EAI_SYSTEM; if (gni_proc < 0) { status = _lookup_link(server_port, "getnameinfo", &gni_proc); - if (status != KERN_SUCCESS) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (status != KERN_SUCCESS) return EAI_SYSTEM; } qlen = LU_QBUF_SIZE; @@ -1538,7 +1474,6 @@ getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __res if (!xdr_int(&inxdr, (int32_t *)&n)) { xdr_destroy(&inxdr); - errno = EIO; return EAI_SYSTEM; } @@ -1592,20 +1527,12 @@ getnameinfo_async_start(mach_port_t *p, const struct sockaddr *sa, size_t salen, server_port = MACH_PORT_NULL; if (_lu_running()) server_port = _lookupd_port(0); - if (server_port == MACH_PORT_NULL) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (server_port == MACH_PORT_NULL) return EAI_SYSTEM; if (gni_proc < 0) { status = _lookup_link(server_port, "getnameinfo", &gni_proc); - if (status != KERN_SUCCESS) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } + if (status != KERN_SUCCESS) return EAI_SYSTEM; } qlen = LU_QBUF_SIZE; @@ -1614,14 +1541,7 @@ getnameinfo_async_start(mach_port_t *p, const struct sockaddr *sa, size_t salen, qlen /= BYTES_PER_XDR_UNIT; - status = lu_async_start(p, gni_proc, qbuf, qlen, (void *)callback, context); - if (status != 0) - { - errno = ECONNREFUSED; - return EAI_SYSTEM; - } - - return 0; + return lu_async_start(p, gni_proc, qbuf, qlen, (void *)callback, context); } int32_t @@ -1648,7 +1568,6 @@ gni_extract_data(char *buf, uint32_t len, char **host, char **serv) if (!xdr_int(&xdr, (int32_t *)&n)) { xdr_destroy(&xdr); - errno = EIO; return EAI_SYSTEM; } diff --git a/lookup.subproj/lu_alias.c b/lookup.subproj/lu_alias.c index cb62a7c..7d22d91 100644 --- a/lookup.subproj/lu_alias.c +++ b/lookup.subproj/lu_alias.c @@ -305,7 +305,7 @@ lu_alias_getent(void) tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_alias, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_bootparam.c b/lookup.subproj/lu_bootparam.c index 9fe1b84..9594b74 100644 --- a/lookup.subproj/lu_bootparam.c +++ b/lookup.subproj/lu_bootparam.c @@ -266,7 +266,7 @@ lu_bootparams_getent(void) tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_bootparams, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_fstab.c b/lookup.subproj/lu_fstab.c index 725255b..be1d532 100644 --- a/lookup.subproj/lu_fstab.c +++ b/lookup.subproj/lu_fstab.c @@ -297,7 +297,7 @@ lu_endfsent(void) struct lu_thread_info *tdata; tdata = _lu_data_create_key(_lu_data_key_fstab, free_lu_thread_info_fstab); - _lu_data_free_vm_xdr(tdata); + _lu_data_free_vm_xdr(tdata); } static int @@ -320,7 +320,7 @@ lu_getfsent() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_fstab, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_group.c b/lookup.subproj/lu_group.c index 117eaa2..ae18310 100644 --- a/lookup.subproj/lu_group.c +++ b/lookup.subproj/lu_group.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2007 Apple Computer, Inc. All rights reserved. + * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -64,7 +64,7 @@ static pthread_mutex_t _group_lock = PTHREAD_MUTEX_INITIALIZER; #define MEMBERD_NAME "com.apple.memberd" static mach_port_t mbr_port = MACH_PORT_NULL; typedef uint32_t GIDArray[16]; -extern kern_return_t _mbr_GetGroups(mach_port_t server, uint32_t uid, uint32_t *numGroups, GIDArray gids, security_token_t *token); +extern kern_return_t _mbr_GetGroups(mach_port_t server, uint32_t uid, uint32_t *numGroups, GIDArray gids); #define GR_GET_NAME 1 #define GR_GET_GID 2 @@ -104,7 +104,7 @@ free_lu_thread_info_group(void *x) if (x == NULL) return; tdata = (struct lu_thread_info *)x; - + if (tdata->lu_entry != NULL) { free_group((struct group *)tdata->lu_entry); @@ -290,7 +290,7 @@ copy_group_r(struct group *in, struct group *out, char *buffer, int buflen) ap += hsize; } } - + memset(bp, 0, sizeof(unsigned long)); bp = ap; @@ -458,7 +458,7 @@ lu_getgrgid(int gid) static int proc = -1; int count; char *lookup_buf; - + if (proc < 0) { if (_lookup_link(_lu_port, "getgrgid", &proc) != KERN_SUCCESS) @@ -675,7 +675,6 @@ mbr_getgrouplist(const char *name, int basegid, int *groups, int *grpcnt, int du int pwstatus; GIDArray gids; int status, maxgroups; - security_token_t token; status = 0; @@ -700,13 +699,9 @@ mbr_getgrouplist(const char *name, int basegid, int *groups, int *grpcnt, int du if (pwstatus != 0) return status; if (res == NULL) return status; - token.val[0] = -1; - token.val[1] = -1; - count = 0; - kstatus = _mbr_GetGroups(mbr_port, p.pw_uid, &count, gids, &token); + kstatus = _mbr_GetGroups(mbr_port, p.pw_uid, &count, gids); if (kstatus != KERN_SUCCESS) return status; - if (token.val[0] != 0) return KERN_FAILURE; for (i = 0; (i < count) && (status == 0); i++) { @@ -734,7 +729,7 @@ lu_getgrouplist(const char *name, int basegid, int *groups, int *grpcnt, int dup if (name == NULL) return status; if (groups == NULL) return status; if (grpcnt == NULL) return status; - + maxgroups = *grpcnt; *grpcnt = 0; @@ -797,12 +792,12 @@ getgrouplist_internal(const char *name, int basegid, int *groups, int *grpcnt, i { return mbr_getgrouplist(name, basegid, groups, grpcnt, dupbase); } - + if (_lu_running()) { return lu_getgrouplist(name, basegid, groups, grpcnt, dupbase); } - + return _old_getgrouplist(name, basegid, groups, grpcnt); } @@ -841,7 +836,7 @@ lu_getgrent() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_group, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) @@ -891,7 +886,7 @@ lu_getgrent() } tdata->lu_vm_cursor--; - + return g; } diff --git a/lookup.subproj/lu_host.c b/lookup.subproj/lu_host.c index 962c434..d9d178e 100644 --- a/lookup.subproj/lu_host.c +++ b/lookup.subproj/lu_host.c @@ -649,7 +649,6 @@ lu_gethostbyaddr(const char *addr, int want, int *err) if (family == AF_INET) { memmove(&(addr4.s_addr), addr, IPV4_ADDR_LEN); - addr4.s_addr = htonl(addr4.s_addr); address = (char *)&(addr4.s_addr); proc = proc4; } diff --git a/lookup.subproj/lu_host_async.c b/lookup.subproj/lu_host_async.c index bdf6796..6b50471 100644 --- a/lookup.subproj/lu_host_async.c +++ b/lookup.subproj/lu_host_async.c @@ -379,7 +379,6 @@ _gethostbyaddr_async_start(const char *addr, int len, int type, a_request_callou v4addr = malloc(len); memmove(v4addr, addr, len); - v4addr->s_addr = htonl(v4addr->s_addr); address = (void *)v4addr; proc = proc4; diff --git a/lookup.subproj/lu_network.c b/lookup.subproj/lu_network.c index 8f9a551..db1ba65 100644 --- a/lookup.subproj/lu_network.c +++ b/lookup.subproj/lu_network.c @@ -357,7 +357,7 @@ lu_endnetent() struct lu_thread_info *tdata; tdata = _lu_data_create_key(_lu_data_key_network, free_lu_thread_info_network); - _lu_data_free_vm_xdr(tdata); + _lu_data_free_vm_xdr(tdata); } static void @@ -379,7 +379,7 @@ lu_getnetent() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_network, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_printer.c b/lookup.subproj/lu_printer.c index e455b4c..86fd0b7 100644 --- a/lookup.subproj/lu_printer.c +++ b/lookup.subproj/lu_printer.c @@ -334,7 +334,7 @@ lu_prdb_get() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_printer, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_protocol.c b/lookup.subproj/lu_protocol.c index e91932d..a6a0451 100644 --- a/lookup.subproj/lu_protocol.c +++ b/lookup.subproj/lu_protocol.c @@ -363,7 +363,7 @@ lu_getprotoent() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_protocol, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_rpc.c b/lookup.subproj/lu_rpc.c index 5381201..3689087 100644 --- a/lookup.subproj/lu_rpc.c +++ b/lookup.subproj/lu_rpc.c @@ -361,7 +361,7 @@ lu_getrpcent() tdata = (struct lu_thread_info *)calloc(1, sizeof(struct lu_thread_info)); _lu_data_set_key(_lu_data_key_rpc, tdata); } - + if (tdata->lu_vm == NULL) { if (proc < 0) diff --git a/lookup.subproj/lu_utils.c b/lookup.subproj/lu_utils.c index 3362147..5970cf2 100644 --- a/lookup.subproj/lu_utils.c +++ b/lookup.subproj/lu_utils.c @@ -303,6 +303,12 @@ _lu_create_request(uint32_t proc, const char *buf, uint32_t len, void *callback, r->proc = proc; r->request_buffer = malloc(len * BYTES_PER_XDR_UNIT); + if (r->request_buffer == NULL) + { + free(r); + return NULL; + } + memcpy(r->request_buffer, buf, len * BYTES_PER_XDR_UNIT); r->request_buffer_len = len; @@ -417,6 +423,8 @@ _lookupd_xdr_dictionary(XDR *inxdr) if (!xdr_int(inxdr, &nkeys)) return NULL; l = (ni_proplist *)malloc(sizeof(ni_proplist)); + if (l == NULL) return NULL; + NI_INIT(l); l->ni_proplist_len = nkeys; @@ -424,6 +432,11 @@ _lookupd_xdr_dictionary(XDR *inxdr) if (nkeys > 0) { l->ni_proplist_val = (ni_property *)calloc(nkeys, sizeof(ni_property)); + if (l->ni_proplist_val == NULL) + { + free(l); + return NULL; + } } for (i = 0; i < nkeys; i++) @@ -447,6 +460,11 @@ _lookupd_xdr_dictionary(XDR *inxdr) if (nvals > 0) { l->ni_proplist_val[i].nip_val.ni_namelist_val = (ni_name *)calloc(nvals, sizeof(ni_name)); + if (l->ni_proplist_val[i].nip_val.ni_namelist_val == NULL) + { + ni_proplist_free(l); + return NULL; + } } for (j = 0; j < nvals; j++) @@ -552,6 +570,11 @@ lookupd_query(ni_proplist *l, ni_proplist ***out) } *out = (ni_proplist **)malloc(n * sizeof(ni_proplist *)); + if (out == NULL) + { + xdr_destroy(&inxdr); + return 0; + } for (i = 0; i < n; i++) { @@ -578,6 +601,8 @@ lookupd_make_query(char *cat, char *fmt, ...) if (fmt[0] != 'k') return NULL; l = (ni_proplist *)malloc(sizeof(ni_proplist)); + if (l == NULL) return NULL; + NI_INIT(l); na = 0; @@ -586,13 +611,36 @@ lookupd_make_query(char *cat, char *fmt, ...) if (cat != NULL) { l->ni_proplist_val = (ni_property *)malloc(sizeof(ni_property)); + if (l->ni_proplist_val == NULL) + { + free(l); + return NULL; + } + p = &(l->ni_proplist_val[0]); arg = "_lookup_category"; p->nip_name = strdup(arg); + if (p->nip_name == NULL) + { + ni_proplist_free(l); + return NULL; + } + p->nip_val.ni_namelist_len = 1; p->nip_val.ni_namelist_val = (ni_name *)malloc(sizeof(ni_name)); + if (p->nip_val.ni_namelist_val == NULL) + { + ni_proplist_free(l); + return NULL; + } + p->nip_val.ni_namelist_val[0] = strdup(cat); - + if (p->nip_val.ni_namelist_val[0] == NULL) + { + ni_proplist_free(l); + return NULL; + } + l->ni_proplist_len++; x++; } @@ -603,10 +651,21 @@ lookupd_make_query(char *cat, char *fmt, ...) arg = va_arg(ap, char *); if (*f == 'k') { - l->ni_proplist_val = (ni_property *)realloc(l->ni_proplist_val, (l->ni_proplist_len + 1) * sizeof(ni_property)); - + l->ni_proplist_val = (ni_property *)reallocf(l->ni_proplist_val, (l->ni_proplist_len + 1) * sizeof(ni_property)); + if (l->ni_proplist_val == NULL) + { + ni_proplist_free(l); + return NULL; + } + p = &(l->ni_proplist_val[l->ni_proplist_len]); p->nip_name = strdup(arg); + if (p->nip_name == NULL) + { + ni_proplist_free(l); + return NULL; + } + p->nip_val.ni_namelist_len = 0; p->nip_val.ni_namelist_val = NULL; @@ -622,9 +681,22 @@ lookupd_make_query(char *cat, char *fmt, ...) } else { - p->nip_val.ni_namelist_val = (ni_name *)realloc(p->nip_val.ni_namelist_val, (p->nip_val.ni_namelist_len + 1) * sizeof(ni_name)); + p->nip_val.ni_namelist_val = (ni_name *)reallocf(p->nip_val.ni_namelist_val, (p->nip_val.ni_namelist_len + 1) * sizeof(ni_name)); + } + + if (p->nip_val.ni_namelist_val == NULL) + { + ni_proplist_free(l); + return NULL; } + p->nip_val.ni_namelist_val[p->nip_val.ni_namelist_len] = strdup(arg); + if (p->nip_val.ni_namelist_val[p->nip_val.ni_namelist_len] == NULL) + { + ni_proplist_free(l); + return NULL; + } + p->nip_val.ni_namelist_len++; } } @@ -651,8 +723,17 @@ ni_property_merge(ni_property *a, ni_property *b) if (addme == 1) { - a->nip_val.ni_namelist_val = (ni_name *)realloc(a->nip_val.ni_namelist_val, (a->nip_val.ni_namelist_len + 1) * sizeof(ni_name)); + a->nip_val.ni_namelist_val = (ni_name *)reallocf(a->nip_val.ni_namelist_val, (a->nip_val.ni_namelist_len + 1) * sizeof(ni_name)); + if (a->nip_val.ni_namelist_val == NULL) return; + a->nip_val.ni_namelist_val[a->nip_val.ni_namelist_len] = strdup(b->nip_val.ni_namelist_val[j]); + if (a->nip_val.ni_namelist_val[a->nip_val.ni_namelist_len] == NULL) + { + free(a->nip_val.ni_namelist_val); + a->nip_val.ni_namelist_val = NULL; + return; + } + a->nip_val.ni_namelist_len++; } } @@ -676,8 +757,17 @@ ni_proplist_merge(ni_proplist *a, ni_proplist *b) } if (addme == 1) { - a->ni_proplist_val = (ni_property *)realloc(a->ni_proplist_val, (a->ni_proplist_len + 1) * sizeof(ni_property)); + a->ni_proplist_val = (ni_property *)reallocf(a->ni_proplist_val, (a->ni_proplist_len + 1) * sizeof(ni_property)); + if (a->ni_proplist_val == NULL) return; + a->ni_proplist_val[a->ni_proplist_len].nip_name = strdup(b->ni_proplist_val[wb].nip_name); + if (a->ni_proplist_val[a->ni_proplist_len].nip_name == NULL) + { + free(a->ni_proplist_val); + a->ni_proplist_val = NULL; + return NULL; + } + a->ni_proplist_val[a->ni_proplist_len].nip_val.ni_namelist_len = 0; a->ni_proplist_val[a->ni_proplist_len].nip_val.ni_namelist_val = NULL; a->ni_proplist_len++; @@ -751,6 +841,7 @@ _lu_data_get() if (libinfo_data != NULL) return libinfo_data; libinfo_data = (struct _lu_data_s *)calloc(1, sizeof(struct _lu_data_s)); + if (libinfo_data == NULL) return NULL; pthread_setspecific(_info_key, libinfo_data); return libinfo_data; @@ -763,6 +854,7 @@ _lu_data_create_key(unsigned int key, void (*destructor)(void *)) unsigned int i, n; libinfo_data = _lu_data_get(); + if (libinfo_data == NULL) return NULL; for (i = 0; i < libinfo_data->icount; i++) { @@ -780,9 +872,17 @@ _lu_data_create_key(unsigned int key, void (*destructor)(void *)) } else { - libinfo_data->ikey = (unsigned int *)realloc(libinfo_data->ikey, n * sizeof(unsigned int)); - libinfo_data->idata = (void **)realloc(libinfo_data->idata, n * sizeof(void *)); - libinfo_data->idata_destructor = (void (**)(void *))realloc(libinfo_data->idata_destructor, n * sizeof(void (*)(void *))); + libinfo_data->ikey = (unsigned int *)reallocf(libinfo_data->ikey, n * sizeof(unsigned int)); + libinfo_data->idata = (void **)reallocf(libinfo_data->idata, n * sizeof(void *)); + libinfo_data->idata_destructor = (void (**)(void *))reallocf(libinfo_data->idata_destructor, n * sizeof(void (*)(void *))); + } + + if ((libinfo_data->ikey == NULL) || (libinfo_data->idata == NULL) || (libinfo_data->idata_destructor == NULL)) + { + if (libinfo_data->ikey != NULL) free(libinfo_data->ikey); + if (libinfo_data->idata != NULL) free(libinfo_data->idata); + if (libinfo_data->idata_destructor != NULL) free(libinfo_data->idata_destructor); + return NULL; } libinfo_data->ikey[i] = key; @@ -815,6 +915,7 @@ _lu_data_set_key(unsigned int key, void *data) unsigned int i; libinfo_data = _lu_data_get(); + if (libinfo_data == NULL) return; i = _lu_data_index(key, libinfo_data); if (i == (unsigned int)-1) return; @@ -829,6 +930,7 @@ _lu_data_get_key(unsigned int key) unsigned int i; libinfo_data = _lu_data_get(); + if (libinfo_data == NULL) return NULL; i = _lu_data_index(key, libinfo_data); if (i == (unsigned int)-1) return NULL; @@ -885,6 +987,8 @@ _lu_xdr_attribute(XDR *xdr, char **key, char ***val, unsigned int *count) *count = len; x = (char **)calloc(len + 1, sizeof(char *)); + if (x == NULL) return -1; + *val = x; for (i = 0; i < len; i++) diff --git a/mdns.subproj/dnssd_clientstub.c b/mdns.subproj/dnssd_clientstub.c index cd6cb55..e2e4fc1 100644 --- a/mdns.subproj/dnssd_clientstub.c +++ b/mdns.subproj/dnssd_clientstub.c @@ -28,18 +28,18 @@ Change History (most recent first): $Log: dnssd_clientstub.c,v $ -Revision 1.20.68.3 2006/05/02 16:16:08 majka +Revision 1.20.70.3 2006/05/02 16:17:04 majka Make NumTries unsigned. -Revision 1.20.68.2 2006/05/01 21:41:19 majka -Additional change (make NumTries static) for 4374646. -SUTiLondon Libinfo-222.3.3 +Revision 1.20.70.2 2006/05/01 21:43:09 majka +Additional change (make NumTries static) for 4527193 +SUChardLondon Libinfo-222.4.6 -Revision 1.20.68.1 2006/05/01 16:22:28 majka -Libinfo-222_3_2 is equivalent to SUTiLondon8J109 Libinfo-222.2 +Revision 1.20.70.1 2006/05/01 16:10:54 majka +Libinfo-222_4_5 is equivalent to Chardonnay Libinfo-222.0.5 -Revision 1.20.64.1 2006/04/27 21:19:51 majka -Bug #: 4374646 +Revision 1.20.60.1 2006/04/27 21:33:30 majka +Integrated 4527193 Revision 1.20 2005/02/03 00:39:05 majka Integrated 3942900 @@ -47,6 +47,9 @@ Integrated 3942900 Revision 1.19.4.1 2005/02/02 00:47:40 ksekar dnd-sd shows the wrong port numbers +Revision 1.19 2004/12/23 23:10:59 majka +*** empty log message *** + Revision 1.18.8.1 2004/12/23 17:32:56 ksekar Rendevzous calls leak sockets if mDNSResponder is not running diff --git a/mdns.subproj/dnssd_ipc.h b/mdns.subproj/dnssd_ipc.h index cecfd46..ccdcd25 100644 --- a/mdns.subproj/dnssd_ipc.h +++ b/mdns.subproj/dnssd_ipc.h @@ -183,7 +183,7 @@ typedef union uint32_t ptr64[2]; } client_context_t; -typedef struct __attribute__((__packed__)) ipc_msg_hdr_struct +typedef struct ipc_msg_hdr_struct { uint32_t version; uint32_t datalen; diff --git a/membership.subproj/memberd.defs b/membership.subproj/memberd.defs index 1c25c31..8067127 100644 --- a/membership.subproj/memberd.defs +++ b/membership.subproj/memberd.defs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2007 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -26,11 +26,10 @@ subsystem memberd 8000; serverprefix Server; #include -#include import "memberd_defines.h"; -type kauth_identity_extlookup = struct [50] of integer_t; -type guid_t = struct [4] of uint32_t; +type kauth_identity_extlookup = struct [200] of uint8_t; +type guid_t = struct [16] of uint8_t; type StatBlock = struct [16] of uint32_t; @@ -38,53 +37,30 @@ type GIDArray = array [16] of uint32_t; type string = c_string[*:256]; -routine _mbr_DoMembershipCall -( - server: mach_port_t; - inout request: kauth_identity_extlookup; - UserSecToken token : security_token_t -); +routine _mbr_DoMembershipCall( + server: mach_port_t; + inout request: kauth_identity_extlookup); -routine _mbr_GetStats -( - server: mach_port_t; - out stats: StatBlock; - UserSecToken token : security_token_t -); +routine _mbr_GetStats( + server: mach_port_t; + out stats: StatBlock); -routine _mbr_ClearStats -( - server: mach_port_t; - UserSecToken token : security_token_t -); +routine _mbr_ClearStats( server: mach_port_t ); -routine _mbr_MapName -( - server: mach_port_t; - in isUser: uint8_t; - in name: string; - out guid: guid_t; - UserSecToken token : security_token_t -); +routine _mbr_MapName( + server: mach_port_t; + in isUser: uint8_t; + in name: string; + out guid: guid_t ); -routine _mbr_GetGroups -( - server: mach_port_t; - in uid: uint32_t; - out numGroups: uint32_t; - out gids: GIDArray; - UserSecToken token : security_token_t -); - -routine _mbr_ClearCache -( - server: mach_port_t; - UserSecToken token : security_token_t -); +routine _mbr_GetGroups( + server: mach_port_t; + in uid: uint32_t; + out numGroups: uint32_t; + out gids: GIDArray ); + +routine _mbr_ClearCache( server: mach_port_t ); -routine _mbr_DumpState -( - server: mach_port_t; - in logOnly: uint8_t; - UserSecToken token : security_token_t -); +routine _mbr_DumpState( + server: mach_port_t; + in logOnly: uint8_t ); diff --git a/membership.subproj/membership.c b/membership.subproj/membership.c index d5ff613..de01653 100644 --- a/membership.subproj/membership.c +++ b/membership.subproj/membership.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2007 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -28,18 +28,24 @@ #include #include #include -#include +#import static mach_port_t GetServerPort() { kern_return_t result; - static mach_port_t bsPort = 0; - static mach_port_t fServerPort = 0; - + static mach_port_t bsPort = 0; + static mach_port_t fServerPort = 0; + if (bsPort == 0) { - result = task_get_bootstrap_port(mach_task_self(), &bsPort); - result = bootstrap_look_up(bsPort, "com.apple.memberd", &fServerPort); + result = task_get_bootstrap_port( mach_task_self(), &bsPort ); + result = bootstrap_look_up( bsPort, "com.apple.memberd", &fServerPort ); + +// if the port lookup failed, the rpc will fail and we will return EIO +// if (result != MACH_MSG_SUCCESS) +// { +// printf("Got error %d on lookup (is memberd running?)\n", result); +// } } return fServerPort; @@ -48,18 +54,15 @@ static mach_port_t GetServerPort() int mbr_uid_to_uuid(uid_t id, uuid_t uu) { struct kauth_identity_extlookup request; - security_token_t token; int result = 0; - token.val[0] = -1; - token.val[1] = -1; - + request.el_seqno = 1; // used as byte order field request.el_flags = KAUTH_EXTLOOKUP_VALID_UID | KAUTH_EXTLOOKUP_WANT_UGUID; request.el_uid = id; - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_UGUID) != 0) memcpy(uu, &request.el_uguid, sizeof(guid_t)); else @@ -71,44 +74,39 @@ int mbr_uid_to_uuid(uid_t id, uuid_t uu) int mbr_gid_to_uuid(gid_t id, uuid_t uu) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - + request.el_seqno = 1; // used as byte order field request.el_flags = KAUTH_EXTLOOKUP_VALID_GID | KAUTH_EXTLOOKUP_WANT_GGUID; request.el_gid = id; - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_GGUID) != 0) memcpy(uu, &request.el_gguid, sizeof(guid_t)); else error = ENOENT; - + return error; } -int mbr_uuid_to_id(const uuid_t uu, uid_t *id, int *id_type) +int mbr_uuid_to_id( const uuid_t uu, uid_t* id, int* id_type) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - - request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | KAUTH_EXTLOOKUP_WANT_UID | KAUTH_EXTLOOKUP_WANT_GID; + request.el_seqno = 1; // used as byte order field + request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | + KAUTH_EXTLOOKUP_WANT_UID | KAUTH_EXTLOOKUP_WANT_GID; memcpy(&request.el_uguid, uu, sizeof(guid_t)); memcpy(&request.el_gguid, uu, sizeof(guid_t)); - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_UID) != 0) { *id = request.el_uid; @@ -120,242 +118,215 @@ int mbr_uuid_to_id(const uuid_t uu, uid_t *id, int *id_type) *id_type = ID_TYPE_GID; } else - { error = ENOENT; - } - + return error; } -int mbr_sid_to_uuid(const nt_sid_t *sid, uuid_t uu) +int mbr_sid_to_uuid(const nt_sid_t* sid, uuid_t uu) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - + request.el_seqno = 1; // used as byte order field request.el_flags = KAUTH_EXTLOOKUP_VALID_GSID | KAUTH_EXTLOOKUP_WANT_GGUID; memset(&request.el_gsid, 0, sizeof(ntsid_t)); memcpy(&request.el_gsid, sid, KAUTH_NTSID_SIZE(sid)); - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_GGUID) != 0) memcpy(uu, &request.el_gguid, sizeof(guid_t)); else error = ENOENT; - + return error; } -int mbr_uuid_to_sid(const uuid_t uu, nt_sid_t *sid) +int mbr_uuid_to_sid(const uuid_t uu, nt_sid_t* sid) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - + request.el_seqno = 1; // used as byte order field request.el_flags = KAUTH_EXTLOOKUP_VALID_GGUID | KAUTH_EXTLOOKUP_WANT_GSID; memcpy(&request.el_gguid, uu, sizeof(guid_t)); - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_GSID) != 0) memcpy(sid, &request.el_gsid, sizeof(nt_sid_t)); else error = ENOENT; - + return error; } -int mbr_check_membership(uuid_t user, uuid_t group, int *ismember) +int mbr_check_membership(uuid_t user, uuid_t group, int* ismember) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - - request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | KAUTH_EXTLOOKUP_WANT_MEMBERSHIP; + request.el_seqno = 1; // used as byte order field + request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | + KAUTH_EXTLOOKUP_WANT_MEMBERSHIP; memcpy(&request.el_uguid, user, sizeof(guid_t)); memcpy(&request.el_gguid, group, sizeof(guid_t)); - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_MEMBERSHIP) != 0) + { *ismember = ((request.el_flags & KAUTH_EXTLOOKUP_ISMEMBER) != 0); + } else error = ENOENT; - + return error; } -int mbr_check_membership_refresh(uuid_t user, uuid_t group, int *ismember) +int mbr_check_membership_refresh(uuid_t user, uuid_t group, int* ismember) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - - request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | KAUTH_EXTLOOKUP_WANT_MEMBERSHIP | (1 << 15); + request.el_seqno = 1; // used as byte order field + request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GGUID | + KAUTH_EXTLOOKUP_WANT_MEMBERSHIP | (1<<15); memcpy(&request.el_uguid, user, sizeof(guid_t)); memcpy(&request.el_gguid, group, sizeof(guid_t)); - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_MEMBERSHIP) != 0) + { *ismember = ((request.el_flags & KAUTH_EXTLOOKUP_ISMEMBER) != 0); + } else error = ENOENT; - + return error; } -int mbr_check_membership_by_id(uuid_t user, gid_t group, int *ismember) +int mbr_check_membership_by_id(uuid_t user, gid_t group, int* ismember) { struct kauth_identity_extlookup request; - security_token_t token; kern_return_t result; int error = 0; - token.val[0] = -1; - token.val[1] = -1; - - request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GID | KAUTH_EXTLOOKUP_WANT_MEMBERSHIP; + request.el_seqno = 1; // used as byte order field + request.el_flags = KAUTH_EXTLOOKUP_VALID_UGUID | KAUTH_EXTLOOKUP_VALID_GID | + KAUTH_EXTLOOKUP_WANT_MEMBERSHIP; memcpy(&request.el_uguid, user, sizeof(guid_t)); request.el_gid = group; - result = _mbr_DoMembershipCall(GetServerPort(), &request, &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_DoMembershipCall(GetServerPort(), &request); + if (result != KERN_SUCCESS) + return EIO; + if ((request.el_flags & KAUTH_EXTLOOKUP_VALID_MEMBERSHIP) != 0) + { *ismember = ((request.el_flags & KAUTH_EXTLOOKUP_ISMEMBER) != 0); + } else error = ENOENT; - + return error; } int mbr_reset_cache() { - security_token_t token; kern_return_t result; - - token.val[0] = -1; - token.val[1] = -1; - - result = _mbr_ClearCache(GetServerPort(), &token); - if (result != KERN_SUCCESS) return EIO; - if (token.val[0] != 0) return EAUTH; - + result = _mbr_ClearCache(GetServerPort()); + if (result != KERN_SUCCESS) + return EIO; return 0; } -int mbr_user_name_to_uuid(const char *name, uuid_t uu) +int mbr_user_name_to_uuid(const char* name, uuid_t uu) { - security_token_t token; kern_return_t result; - - if (name == NULL) return EINVAL; - if (strlen(name) > 255) return EINVAL; - - token.val[0] = -1; - token.val[1] = -1; - - result = _mbr_MapName(GetServerPort(), 1, (char *)name, (guid_t *)uu, &token); - if (result == KERN_FAILURE) return ENOENT; - else if (result != KERN_SUCCESS) return EIO; - - if (token.val[0] != 0) return EAUTH; - + + if (strlen(name) > 255) + return EINVAL; + + result = _mbr_MapName(GetServerPort(), 1, (char*)name, (guid_t*)uu); + + if (result == KERN_FAILURE) + return ENOENT; + else if (result != KERN_SUCCESS) + return EIO; + return 0; } -int mbr_group_name_to_uuid(const char *name, uuid_t uu) +int mbr_group_name_to_uuid(const char* name, uuid_t uu) { - security_token_t token; kern_return_t result; - - if (name == NULL) return EINVAL; - if (strlen(name) > 255) return EINVAL; - - token.val[0] = -1; - token.val[1] = -1; - - result = _mbr_MapName(GetServerPort(), 0, (char *)name, (guid_t *)uu, &token); - if (result == KERN_FAILURE) return ENOENT; - else if (result != KERN_SUCCESS) return EIO; - - if (token.val[0] != 0) return EAUTH; - + + if (strlen(name) > 255) + return EINVAL; + + result = _mbr_MapName(GetServerPort(), 0, (char*)name, (guid_t*)uu); + + if (result == KERN_FAILURE) + return ENOENT; + else if (result != KERN_SUCCESS) + return EIO; + return 0; } -int mbr_check_service_membership(const uuid_t user, const char *servicename, int *ismember) +int mbr_check_service_membership(const uuid_t user, const char* servicename, int* ismember) { - char *prefix = "com.apple.access_"; - char *all_services = "com.apple.access_all_services"; + char* prefix = "com.apple.access_"; + char* all_services = "com.apple.access_all_services"; char groupName[256]; uuid_t group_uu; int result, dummy; - - if (servicename == NULL) return EINVAL; - if (strlen(servicename) > (255 - strlen(prefix))) return EINVAL; - - /* start by checking "all services" */ + + if (strlen(servicename) > 255 - strlen(prefix)) + return EINVAL; + + // start by checking "all services" result = mbr_group_name_to_uuid(all_services, group_uu); - - if (result == EAUTH) return result; - + if (result == ENOENT) { - /* all_services group didn't exist, check individual group */ + // all_services group didn't exist, check individual group memcpy(groupName, prefix, strlen(prefix)); strcpy(groupName + strlen(prefix), servicename); result = mbr_group_name_to_uuid(groupName, group_uu); } - + if (result == 0) - { result = mbr_check_membership_refresh(user, group_uu, ismember); - } - else if (result == EAUTH) - { - return result; - } else { - /* just force cache update with bogus membership check */ + // just force cache update with bogus membership check memset(group_uu, 0, sizeof(group_uu)); mbr_check_membership_refresh(user, group_uu, &dummy); } - + return result; } -static char *ConvertBytesToDecimal(char *buffer, unsigned long long value) +static char* ConvertBytesToDecimal(char* buffer, unsigned long long value) { - char *temp; + char* temp; buffer[24] = '\0'; buffer[23] = '0'; - - if (value == 0) return &buffer[23]; - + + if (value == 0) + return &buffer[23]; + temp = &buffer[24]; while (value != 0) { @@ -363,22 +334,23 @@ static char *ConvertBytesToDecimal(char *buffer, unsigned long long value) *temp = '0' + (value % 10); value /= 10; } - + return temp; } -int mbr_sid_to_string(const nt_sid_t *sid, char *string) +int mbr_sid_to_string(const nt_sid_t* sid, char* string) { - char *current = string; + char* current = string; long long temp = 0; int i; char tempBuffer[25]; - - if (sid->sid_authcount > NTSID_MAX_AUTHORITIES) return EINVAL; - + + if (sid->sid_authcount > NTSID_MAX_AUTHORITIES) + return EINVAL; + for (i = 0; i < 6; i++) temp = (temp << 8) | sid->sid_authority[i]; - + current[0] = 'S'; current[1] = '-'; current += 2; @@ -387,54 +359,54 @@ int mbr_sid_to_string(const nt_sid_t *sid, char *string) *current = '-'; current++; strcpy(current, ConvertBytesToDecimal(tempBuffer, temp)); - - for (i = 0; i < sid->sid_authcount; i++) + + for(i=0; i < sid->sid_authcount; i++) { current = current + strlen(current); *current = '-'; current++; strcpy(current, ConvertBytesToDecimal(tempBuffer, sid->sid_authorities[i])); } - + return 0; } -int mbr_string_to_sid(const char *string, nt_sid_t *sid) +int mbr_string_to_sid(const char* string, nt_sid_t* sid) { - char *current = string+2; + char* current = string+2; int count = 0; long long temp; memset(sid, 0, sizeof(nt_sid_t)); - if ((string[0] != 'S') || (string[1] != '-')) return EINVAL; - + if (string[0] != 'S' || string[1] != '-') return EINVAL; + sid->sid_kind = strtol(current, ¤t, 10); if (*current == '\0') return EINVAL; current++; temp = strtoll(current, ¤t, 10); - - /* convert to BigEndian before copying */ + // convert to BigEndian before copying temp = OSSwapHostToBigInt64(temp); memcpy(sid->sid_authority, ((char*)&temp)+2, 6); - while ((*current != '\0') && (count < NTSID_MAX_AUTHORITIES)) + while (*current != '\0' && count < NTSID_MAX_AUTHORITIES) { current++; sid->sid_authorities[count] = strtol(current, ¤t, 10); count++; } - - if (*current != '\0') return EINVAL; - + + if (*current != '\0') + return EINVAL; + sid->sid_authcount = count; - + return 0; } -static void ConvertBytesToHex(char **string, char **data, int numBytes) +static void ConvertBytesToHex(char** string, char** data, int numBytes) { int i; - - for (i = 0; i < numBytes; i++) + + for (i=0; i < numBytes; i++) { unsigned char hi = ((**data) >> 4) & 0xf; unsigned char low = (**data) & 0xf; @@ -442,7 +414,7 @@ static void ConvertBytesToHex(char **string, char **data, int numBytes) **string = '0' + hi; else **string = 'A' + hi - 10; - + (*string)++; if (low < 10) @@ -455,10 +427,10 @@ static void ConvertBytesToHex(char **string, char **data, int numBytes) } } -int mbr_uuid_to_string(const uuid_t uu, char *string) +int mbr_uuid_to_string(const uuid_t uu, char* string) { - char *guid = (char *)uu; - char *strPtr = string; + char* guid = (char*)uu; + char* strPtr = string; ConvertBytesToHex(&strPtr, &guid, 4); *strPtr = '-'; strPtr++; ConvertBytesToHex(&strPtr, &guid, 2); @@ -469,41 +441,36 @@ int mbr_uuid_to_string(const uuid_t uu, char *string) *strPtr = '-'; strPtr++; ConvertBytesToHex(&strPtr, &guid, 6); *strPtr = '\0'; - + return 0; } -int mbr_string_to_uuid(const char *string, uuid_t uu) +int mbr_string_to_uuid(const char* string, uuid_t uu) { short dataIndex = 0; int isFirstNibble = 1; - + if (strlen(string) > MBR_UU_STRING_SIZE) return EINVAL; - + while (*string != '\0' && dataIndex < 16) { char nibble; - - if ((*string >= '0') && (*string <= '9')) - { + + if (*string >= '0' && *string <= '9') nibble = *string - '0'; - } - else if ((*string >= 'A') && (*string <= 'F')) - { + else if (*string >= 'A' && *string <= 'F') nibble = *string - 'A' + 10; - } - else if ((*string >= 'a') && (*string <= 'f')) - { + else if (*string >= 'a' && *string <= 'f') nibble = *string - 'a' + 10; - } else { - if (*string != '-') return EINVAL; + if (*string != '-') + return EINVAL; string++; continue; } - + if (isFirstNibble) { uu[dataIndex] = nibble << 4; @@ -515,11 +482,13 @@ int mbr_string_to_uuid(const char *string, uuid_t uu) dataIndex++; isFirstNibble = 1; } - + string++; } - - if (dataIndex != 16) return EINVAL; - + + if (dataIndex != 16) + return EINVAL; + return 0; } + diff --git a/rpc.subproj/getrpcent.c b/rpc.subproj/getrpcent.c index 74fc043..1a8fe44 100644 --- a/rpc.subproj/getrpcent.c +++ b/rpc.subproj/getrpcent.c @@ -183,7 +183,7 @@ getrpcent() static struct rpcent * interpret(val, len) char *val; - u_int len; + int len; { register struct rpcdata *d = _rpcdata(); char *p; diff --git a/rpc.subproj/svc_auth_unix.c b/rpc.subproj/svc_auth_unix.c index e96e505..cd19041 100644 --- a/rpc.subproj/svc_auth_unix.c +++ b/rpc.subproj/svc_auth_unix.c @@ -89,7 +89,8 @@ _svcauth_unix(rqst, msg) char area_machname[MAX_MACHINE_NAME+1]; int area_gids[NGROUPS]; } *area; - u_int auth_len, str_len, gid_len; + u_int auth_len; + int str_len, gid_len; register int i; area = (struct area *) rqst->rq_clntcred; @@ -106,7 +107,7 @@ _svcauth_unix(rqst, msg) stat = AUTH_BADCRED; goto done; } - bcopy((caddr_t)buf, aup->aup_machname, str_len); + bcopy((caddr_t)buf, aup->aup_machname, (u_int)str_len); aup->aup_machname[str_len] = 0; str_len = RNDUP(str_len); buf += str_len / sizeof (long); @@ -126,9 +127,8 @@ _svcauth_unix(rqst, msg) * timestamp, hostname len (0), uid, gid, and gids len (0). */ if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) { - /* LIBRARY CODE SHOULD NOT PRINT - (void) printf("bad auth_len gid %d str %d auth %d\n", gid_len, str_len, auth_len); - */ + (void) printf("bad auth_len gid %d str %d auth %d\n", + gid_len, str_len, auth_len); stat = AUTH_BADCRED; goto done; } -- 2.7.4