]> git.saurik.com Git - apple/libinfo.git/commitdiff
Libinfo-222.0.4.tar.gz mac-os-x-1044x86 mac-os-x-1045x86 mac-os-x-1046x86 v222.0.4
authorApple <opensource@apple.com>
Mon, 20 Feb 2006 21:35:59 +0000 (21:35 +0000)
committerApple <opensource@apple.com>
Mon, 20 Feb 2006 21:35:59 +0000 (21:35 +0000)
Makefile.preamble
lookup.subproj/getaddrinfo.c
lookup.subproj/lu_host.c
lookup.subproj/lu_host_async.c
lookup.subproj/lu_service.c
lookup.subproj/lu_utils.c
membership.subproj/memberd.defs
membership.subproj/membership.c

index 606002d886cf68ec69baa30c3d8228d2af1a11a1..25d484ec8a2ad34c5865f0bd73409a558d4ab96a 100644 (file)
@@ -3,6 +3,4 @@ STRIP_ON_INSTALL = NO
 BEFORE_INSTALL += debug profile
 override LINK_SUBPROJECTS = NO
 
-# for building 64-bit
-# <rdar://problem/3819761> Libinfo need to build with gcc-3.5 and 3-way fat
-export CCOMPILER = /usr/bin/gcc-3.5
+# export CCOMPILER = /usr/bin/gcc-X.X
index d23a37cef78674d0e72f5f0f3ca7a999c122810b..ce51a5e784dbeb14cbf2a57fd855e6ab38b23077 100644 (file)
@@ -1369,7 +1369,7 @@ getnameinfo(const struct sockaddr * __restrict sa, socklen_t salen, char * __res
                 */
                if ((isll != 0) || (issl != 0))
                {
-                       ifnum = s6->sin6_addr.__u6_addr.__u6_addr16[1];
+                       ifnum = ntohs(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;
 
index 962c434bba3b91f10e76cdb2c4449b74a7f26fd7..d9d178efaf23be50c2ffef851ddb1b1a074d94e4 100644 (file)
@@ -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;
        }
index bdf6796c9b1f39fc196d1f5f1955e6aaefd34e2e..6b5047133024b67331d85985a02a8ae7b7edbe76 100644 (file)
@@ -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;
index 1f00b6124b58684b9eab1c3a8bfc51b048eedc14..58b3996af4f0f209951510d6b1855947b0b33ed5 100644 (file)
@@ -415,6 +415,9 @@ lu_getservbyport(int port, const char *proto)
        /* Encode NULL for xmission to lookupd. */
        if (proto == NULL) proto = "";  
 
+       /* convert to host order */
+       port = ntohs(port);
+
        xdrmem_create(&outxdr, output_buf, sizeof(output_buf), XDR_ENCODE);
        if (!xdr_int(&outxdr, &port) || !xdr__lu_string(&outxdr, (_lu_string *)&proto))
        {
index 3362147edd924363bc0785594b3db5423d410919..5970cf20bbf63e14c2ca5a6b74624f5aabc2b80f 100644 (file)
@@ -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++)
index 9f98bacc1013a110d829b6fea2a9d253ea31b787..8067127fad3f29bb183c5210d42fbaffa6ce6cd9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -28,8 +28,8 @@ serverprefix Server;
 #include <mach/std_types.defs>
 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;
 
index 223aeef54dcc28ee89359d6c976bde86b9d0f5a6..de0165352e09452776e41b62c7f57be717f66b52 100644 (file)
@@ -28,6 +28,7 @@
 #include <servers/bootstrap.h>
 #include <mach/mach.h>
 #include <stdlib.h>
+#import <libkern/OSByteOrder.h>
 
 static mach_port_t GetServerPort()
 {
@@ -55,6 +56,7 @@ int mbr_uid_to_uuid(uid_t id, uuid_t uu)
        struct kauth_identity_extlookup request;
        int result = 0;
 
+       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);
@@ -75,6 +77,7 @@ int mbr_gid_to_uuid(gid_t id, uuid_t uu)
        kern_return_t result;
        int error = 0;
 
+       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);
@@ -95,6 +98,7 @@ int mbr_uuid_to_id( const uuid_t uu, uid_t* id, int* id_type)
        kern_return_t result;
        int error = 0;
 
+       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));
@@ -125,6 +129,7 @@ int mbr_sid_to_uuid(const nt_sid_t* sid, uuid_t uu)
        kern_return_t result;
        int error = 0;
 
+       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));
@@ -146,6 +151,7 @@ int mbr_uuid_to_sid(const uuid_t uu, nt_sid_t* sid)
        kern_return_t result;
        int error = 0;
 
+       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);
@@ -166,6 +172,7 @@ int mbr_check_membership(uuid_t user, uuid_t group, int* ismember)
        kern_return_t result;
        int error = 0;
 
+       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));
@@ -184,12 +191,38 @@ int mbr_check_membership(uuid_t user, uuid_t group, int* ismember)
        return error;
 }
 
+int mbr_check_membership_refresh(uuid_t user, uuid_t group, int* ismember)
+{
+       struct kauth_identity_extlookup request;
+       kern_return_t result;
+       int error = 0;
+
+       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);
+       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)
 {
        struct kauth_identity_extlookup request;
        kern_return_t result;
        int error = 0;
 
+       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));
@@ -257,7 +290,7 @@ int mbr_check_service_membership(const uuid_t user, const char* servicename, int
        char* all_services = "com.apple.access_all_services";
        char groupName[256];
        uuid_t group_uu;
-       int result;
+       int result, dummy;
        
        if (strlen(servicename) > 255 - strlen(prefix))
                return EINVAL;
@@ -274,7 +307,13 @@ int mbr_check_service_membership(const uuid_t user, const char* servicename, int
        }
        
        if (result == 0)
-               result = mbr_check_membership(user, group_uu, ismember);
+               result = mbr_check_membership_refresh(user, group_uu, ismember);
+       else
+       {
+               // 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;
 }
@@ -309,7 +348,8 @@ int mbr_sid_to_string(const nt_sid_t* sid, char* string)
        if (sid->sid_authcount > NTSID_MAX_AUTHORITIES)
                return EINVAL;
        
-       memcpy(((char*)&temp)+2, sid->sid_authority, 6);
+       for (i = 0; i < 6; i++)
+               temp = (temp << 8) | sid->sid_authority[i];
        
        current[0] = 'S';
        current[1] = '-';
@@ -344,6 +384,8 @@ int mbr_string_to_sid(const char* string, nt_sid_t* sid)
        if (*current == '\0') return EINVAL;
        current++;
        temp = strtoll(current, &current, 10);
+       // convert to BigEndian before copying
+       temp = OSSwapHostToBigInt64(temp);
        memcpy(sid->sid_authority, ((char*)&temp)+2, 6);
        while (*current != '\0' && count < NTSID_MAX_AUTHORITIES)
        {