Skip to contentSkip to conversation

libsepol, checkpolicy, secilc: Replace #ifdef DARWIN with __APPLE__.

PATCH In review Stephen Smalley 4 participants 4 messages May 3, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol, checkpolicy, secilc: Replace #ifdef DARWIN with __APPLE__.

As per discussion in https://android-review.googlesource.com/#/c/221980,
we should be using #ifdef __APPLE__ rather than our own custom-defined DARWIN for building on MacOS X.

---
 checkpolicy/Android.mk      | 4 ----
 checkpolicy/checkpolicy.c   | 2 +-
 checkpolicy/policy_define.c | 2 +-
 libsepol/Android.mk         | 4 ----
 libsepol/src/genbools.c     | 4 ++--
 libsepol/src/genusers.c     | 4 ++--
 libsepol/src/node_record.c  | 4 ++--
 libsepol/src/private.h      | 4 ++--
 secilc/Android.mk           | 4 ----
 9 files changed, 10 insertions(+), 22 deletions(-)
checkpolicy/Android.mk +0 -4
index 98f5168..3b7ff8a 100644
@@ -12,10 +12,6 @@ common_cflags := \
 	-Wall -Wshadow -O2 \
 	-pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS),darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
 	$(LOCAL_PATH)/ \
 	$(LOCAL_PATH)/../libsepol/include/ \
checkpolicy/checkpolicy.c +1 -1
index 7947c20..2d68316 100644
@@ -73,7 +73,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <ctype.h>
 #endif
 
checkpolicy/policy_define.c +1 -1
index 2068b71..100e517 100644
@@ -5140,7 +5140,7 @@ int define_ipv6_node_context(void)
 
 	memset(newc, 0, sizeof(ocontext_t));
 
-#ifdef DARWIN
+#ifdef __APPLE__
 	memcpy(&newc->u.node6.addr[0], &addr.s6_addr[0], 16);
 	memcpy(&newc->u.node6.mask[0], &mask.s6_addr[0], 16);
 #else
libsepol/Android.mk +0 -4
index 5d2c96b..6d89f17 100644
@@ -69,10 +69,6 @@ common_cflags := \
 	-Wshadow -Wmissing-noreturn \
 	-Wmissing-format-attribute
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
 	$(LOCAL_PATH)/include/ \
 	$(LOCAL_PATH)/src/ \
libsepol/src/genbools.c +2 -2
index 6a06ec9..c81e848 100644
@@ -79,7 +79,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
 	if (boolf == NULL)
 		goto localbool;
 
-#ifdef DARWIN
+#ifdef __APPLE__
         if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
           ERR(NULL, "out of memory");
 	  return -1;
@@ -111,7 +111,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
 	boolf = fopen(localbools, "r");
 	if (boolf != NULL) {
 
-#ifdef DARWIN
+#ifdef __APPLE__
 
 	  while(fgets(buffer, 255, boolf) != NULL) {
 #else
libsepol/src/genusers.c +2 -2
index 7826b71..0b98a76 100644
@@ -7,7 +7,7 @@
 
 #include <sepol/policydb/policydb.h>
 
-#ifndef DARWIN
+#ifndef __APPLE__
 #include <stdio_ext.h>
 #endif
 
@@ -47,7 +47,7 @@ static int load_users(struct policydb *policydb, const char *path)
 	if (fp == NULL)
 		return -1;
 
-#ifdef DARWIN
+#ifdef __APPLE__
 	if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
 	  ERR(NULL, "out of memory");
 	  return -1;
libsepol/src/node_record.c +2 -2
index bd48ba0..21043b6 100644
@@ -70,7 +70,7 @@ static int node_parse_addr(sepol_handle_t * handle,
 				return STATUS_ERR;
 			}
 
-#ifdef DARWIN
+#ifdef __APPLE__
 			memcpy(addr_bytes, in_addr.s6_addr, 16);
 #else
 			memcpy(addr_bytes, in_addr.s6_addr32, 16);
@@ -162,7 +162,7 @@ static int node_expand_addr(sepol_handle_t * handle,
 		{
 			struct in6_addr addr;
 			memset(&addr, 0, sizeof(struct in6_addr));
-#ifdef DARWIN
+#ifdef __APPLE__
 			memcpy(&addr.s6_addr[0], addr_bytes, 16);
 #else
 			memcpy(&addr.s6_addr32[0], addr_bytes, 16);
libsepol/src/private.h +2 -2
index 8a6d4bb..9c700c9 100644
@@ -5,7 +5,7 @@
 #include <sepol/policydb/policydb.h>
 
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <sys/types.h>
 #include <machine/endian.h>
 #else
@@ -16,7 +16,7 @@
 #include <errno.h>
 #include <dso.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #define __BYTE_ORDER  BYTE_ORDER
 #define __LITTLE_ENDIAN  LITTLE_ENDIAN
 #endif
secilc/Android.mk +0 -4
index 3dd9023..6c7b9d3 100644
@@ -6,10 +6,6 @@ common_cflags := \
 	-Wall -Wshadow -O2 \
 	-pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
 	$(LOCAL_PATH)/../libsepol/cil/include/ \
 	$(LOCAL_PATH)/../libsepol/include/ \
Signature · 1 line
2.5.5
#1 lore raw

lgtm. thanks!

Quoted 179 lines · Stephen Smalley

As per discussion in https://android-review.googlesource.com/#/c/221980,
we should be using #ifdef __APPLE__ rather than our own custom-defined DARWIN for building on MacOS X.

---
 checkpolicy/Android.mk      | 4 ----
 checkpolicy/checkpolicy.c   | 2 +-
 checkpolicy/policy_define.c | 2 +-
 libsepol/Android.mk         | 4 ----
 libsepol/src/genbools.c     | 4 ++--
 libsepol/src/genusers.c     | 4 ++--
 libsepol/src/node_record.c  | 4 ++--
 libsepol/src/private.h      | 4 ++--
 secilc/Android.mk           | 4 ----
 9 files changed, 10 insertions(+), 22 deletions(-)
checkpolicy/Android.mk +0 -4
index 98f5168..3b7ff8a 100644
@@ -12,10 +12,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS),darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/ \
        $(LOCAL_PATH)/../libsepol/include/ \
checkpolicy/checkpolicy.c +1 -1
index 7947c20..2d68316 100644
@@ -73,7 +73,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <ctype.h>
 #endif
 
checkpolicy/policy_define.c +1 -1
index 2068b71..100e517 100644
@@ -5140,7 +5140,7 @@ int define_ipv6_node_context(void)
 
        memset(newc, 0, sizeof(ocontext_t));
 
-#ifdef DARWIN
+#ifdef __APPLE__
        memcpy(&newc->u.node6.addr[0], &addr.s6_addr[0], 16);
        memcpy(&newc->u.node6.mask[0], &mask.s6_addr[0], 16);
 #else
libsepol/Android.mk +0 -4
index 5d2c96b..6d89f17 100644
@@ -69,10 +69,6 @@ common_cflags := \
        -Wshadow -Wmissing-noreturn \
        -Wmissing-format-attribute
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/include/ \
        $(LOCAL_PATH)/src/ \
libsepol/src/genbools.c +2 -2
index 6a06ec9..c81e848 100644
@@ -79,7 +79,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
        if (boolf == NULL)
                goto localbool;
 
-#ifdef DARWIN
+#ifdef __APPLE__
         if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
           ERR(NULL, "out of memory");
          return -1;
@@ -111,7 +111,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
        boolf = fopen(localbools, "r");
        if (boolf != NULL) {
 
-#ifdef DARWIN
+#ifdef __APPLE__
 
          while(fgets(buffer, 255, boolf) != NULL) {
 #else
libsepol/src/genusers.c +2 -2
index 7826b71..0b98a76 100644
@@ -7,7 +7,7 @@
 
 #include <sepol/policydb/policydb.h>
 
-#ifndef DARWIN
+#ifndef __APPLE__
 #include <stdio_ext.h>
 #endif
 
@@ -47,7 +47,7 @@ static int load_users(struct policydb *policydb, const char *path)
        if (fp == NULL)
                return -1;
 
-#ifdef DARWIN
+#ifdef __APPLE__
        if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
          ERR(NULL, "out of memory");
          return -1;
libsepol/src/node_record.c +2 -2
index bd48ba0..21043b6 100644
@@ -70,7 +70,7 @@ static int node_parse_addr(sepol_handle_t * handle,
                                return STATUS_ERR;
                        }
 
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(addr_bytes, in_addr.s6_addr, 16);
 #else
                        memcpy(addr_bytes, in_addr.s6_addr32, 16);
@@ -162,7 +162,7 @@ static int node_expand_addr(sepol_handle_t * handle,
                {
                        struct in6_addr addr;
                        memset(&addr, 0, sizeof(struct in6_addr));
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(&addr.s6_addr[0], addr_bytes, 16);
 #else
                        memcpy(&addr.s6_addr32[0], addr_bytes, 16);
libsepol/src/private.h +2 -2
index 8a6d4bb..9c700c9 100644
@@ -5,7 +5,7 @@
 #include <sepol/policydb/policydb.h>
 
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <sys/types.h>
 #include <machine/endian.h>
 #else
@@ -16,7 +16,7 @@
 #include <errno.h>
 #include <dso.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #define __BYTE_ORDER  BYTE_ORDER
 #define __LITTLE_ENDIAN  LITTLE_ENDIAN
 #endif
secilc/Android.mk +0 -5
index 3dd9023..6c7b9d3 100644
@@ -6,10 +6,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/../libsepol/cil/include/ \
        $(LOCAL_PATH)/../libsepol/include/ \
--

2.5.5

Signature · 2 lines
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
Acked-by on v1 1/1
#2 lore raw
In reply to Stephen Smalley
Quoted 5 lines · Stephen Smalley

As per discussion in https://android-review.googlesource.com/#/c/221980,
we should be using #ifdef __APPLE__ rather than our own custom-defined DARWIN for building on MacOS X.

Quoted 174 lines
---
 checkpolicy/Android.mk      | 4 ----
 checkpolicy/checkpolicy.c   | 2 +-
 checkpolicy/policy_define.c | 2 +-
 libsepol/Android.mk         | 4 ----
 libsepol/src/genbools.c     | 4 ++--
 libsepol/src/genusers.c     | 4 ++--
 libsepol/src/node_record.c  | 4 ++--
 libsepol/src/private.h      | 4 ++--
 secilc/Android.mk           | 4 ----
 9 files changed, 10 insertions(+), 22 deletions(-)
checkpolicy/Android.mk +0 -4
index 98f5168..3b7ff8a 100644
@@ -12,10 +12,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS),darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/ \
        $(LOCAL_PATH)/../libsepol/include/ \
checkpolicy/checkpolicy.c +1 -1
index 7947c20..2d68316 100644
@@ -73,7 +73,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <ctype.h>
 #endif
 
checkpolicy/policy_define.c +1 -1
index 2068b71..100e517 100644
@@ -5140,7 +5140,7 @@ int define_ipv6_node_context(void)
 
        memset(newc, 0, sizeof(ocontext_t));
 
-#ifdef DARWIN
+#ifdef __APPLE__
        memcpy(&newc->u.node6.addr[0], &addr.s6_addr[0], 16);
        memcpy(&newc->u.node6.mask[0], &mask.s6_addr[0], 16);
 #else
libsepol/Android.mk +0 -4
index 5d2c96b..6d89f17 100644
@@ -69,10 +69,6 @@ common_cflags := \
        -Wshadow -Wmissing-noreturn \
        -Wmissing-format-attribute
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/include/ \
        $(LOCAL_PATH)/src/ \
libsepol/src/genbools.c +2 -2
index 6a06ec9..c81e848 100644
@@ -79,7 +79,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
        if (boolf == NULL)
                goto localbool;
 
-#ifdef DARWIN
+#ifdef __APPLE__
         if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
           ERR(NULL, "out of memory");
          return -1;
@@ -111,7 +111,7 @@ static int load_booleans(struct policydb *policydb, const char *path,
        boolf = fopen(localbools, "r");
        if (boolf != NULL) {
 
-#ifdef DARWIN
+#ifdef __APPLE__
 
          while(fgets(buffer, 255, boolf) != NULL) {
 #else
libsepol/src/genusers.c +2 -2
index 7826b71..0b98a76 100644
@@ -7,7 +7,7 @@
 
 #include <sepol/policydb/policydb.h>
 
-#ifndef DARWIN
+#ifndef __APPLE__
 #include <stdio_ext.h>
 #endif
 
@@ -47,7 +47,7 @@ static int load_users(struct policydb *policydb, const char *path)
        if (fp == NULL)
                return -1;
 
-#ifdef DARWIN
+#ifdef __APPLE__
        if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
          ERR(NULL, "out of memory");
          return -1;
libsepol/src/node_record.c +2 -2
index bd48ba0..21043b6 100644
@@ -70,7 +70,7 @@ static int node_parse_addr(sepol_handle_t * handle,
                                return STATUS_ERR;
                        }
 
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(addr_bytes, in_addr.s6_addr, 16);
 #else
                        memcpy(addr_bytes, in_addr.s6_addr32, 16);
@@ -162,7 +162,7 @@ static int node_expand_addr(sepol_handle_t * handle,
                {
                        struct in6_addr addr;
                        memset(&addr, 0, sizeof(struct in6_addr));
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(&addr.s6_addr[0], addr_bytes, 16);
 #else
                        memcpy(&addr.s6_addr32[0], addr_bytes, 16);
libsepol/src/private.h +2 -2
index 8a6d4bb..9c700c9 100644
@@ -5,7 +5,7 @@
 #include <sepol/policydb/policydb.h>
 
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <sys/types.h>
 #include <machine/endian.h>
 #else
@@ -16,7 +16,7 @@
 #include <errno.h>
 #include <dso.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #define __BYTE_ORDER  BYTE_ORDER
 #define __LITTLE_ENDIAN  LITTLE_ENDIAN
 #endif
secilc/Android.mk +0 -5
index 3dd9023..6c7b9d3 100644
@@ -6,10 +6,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/../libsepol/cil/include/ \
        $(LOCAL_PATH)/../libsepol/include/ \
--

2.5.5

Signature · 1 line
Nick Kralevich | Android Security | [email protected] | 650.214.4037
#3 lore raw

LGTM, but have no way to test it. I have no apples.

Quoted 198 lines · Nick Kralevich
Quoted 5 lines · Stephen Smalley

As per discussion in https://android-review.googlesource.com/#/c/221980,
we should be using #ifdef __APPLE__ rather than our own custom-defined DARWIN for building on MacOS X.

libsepol/src/genbools.c static int load_booleans(struct policydb *policydb,

Quoted 73 lines
---
 checkpolicy/Android.mk      | 4 ----
 checkpolicy/checkpolicy.c   | 2 +-
 checkpolicy/policy_define.c | 2 +-
 libsepol/Android.mk         | 4 ----
 libsepol/src/genbools.c     | 4 ++--
 libsepol/src/genusers.c     | 4 ++--
 libsepol/src/node_record.c  | 4 ++--
 libsepol/src/private.h      | 4 ++--
 secilc/Android.mk           | 4 ----
 9 files changed, 10 insertions(+), 22 deletions(-)
checkpolicy/Android.mk +0 -4
index 98f5168..3b7ff8a 100644
@@ -12,10 +12,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS),darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/ \
        $(LOCAL_PATH)/../libsepol/include/ \
checkpolicy/checkpolicy.c +1 -1
index 7947c20..2d68316 100644
@@ -73,7 +73,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <ctype.h>
 #endif
 
checkpolicy/policy_define.c +1 -1
index 2068b71..100e517 100644
@@ -5140,7 +5140,7 @@ int define_ipv6_node_context(void)
 
        memset(newc, 0, sizeof(ocontext_t));
 
-#ifdef DARWIN
+#ifdef __APPLE__
        memcpy(&newc->u.node6.addr[0], &addr.s6_addr[0], 16);
        memcpy(&newc->u.node6.mask[0], &mask.s6_addr[0], 16);
 #else
libsepol/Android.mk +0 -4
index 5d2c96b..6d89f17 100644
@@ -69,10 +69,6 @@ common_cflags := \
        -Wshadow -Wmissing-noreturn \
        -Wmissing-format-attribute
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/include/ \
        $(LOCAL_PATH)/src/ \
libsepol/src/genbools.c +0 -0
index 6a06ec9..c81e848 100644
@@ -79,7 +79,7 @@ static int load_booleans(struct policydb *policydb,

const char *path,

libsepol/src/genbools.c static int load_booleans(struct policydb *policydb,

Quoted 9 lines
libsepol/src/genbools.c +1 -1
        if (boolf == NULL)
                goto localbool;
 
-#ifdef DARWIN
+#ifdef __APPLE__
         if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
           ERR(NULL, "out of memory");
          return -1;
@@ -111,7 +111,7 @@ static int load_booleans(struct policydb *policydb,

const char *path,

libsepol/src/genusers.c static int load_users(struct policydb *policydb, const

Quoted 22 lines
libsepol/src/genbools.c +1 -1
        boolf = fopen(localbools, "r");
        if (boolf != NULL) {
 
-#ifdef DARWIN
+#ifdef __APPLE__
 
          while(fgets(buffer, 255, boolf) != NULL) {
 #else
libsepol/src/genusers.c +1 -1
index 7826b71..0b98a76 100644
@@ -7,7 +7,7 @@
 
 #include <sepol/policydb/policydb.h>
 
-#ifndef DARWIN
+#ifndef __APPLE__
 #include <stdio_ext.h>
 #endif
 
@@ -47,7 +47,7 @@ static int load_users(struct policydb *policydb, const

char *path)

Quoted 68 lines
libsepol/src/genusers.c +1 -1
        if (fp == NULL)
                return -1;
 
-#ifdef DARWIN
+#ifdef __APPLE__
        if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
          ERR(NULL, "out of memory");
          return -1;
libsepol/src/node_record.c +2 -2
index bd48ba0..21043b6 100644
@@ -70,7 +70,7 @@ static int node_parse_addr(sepol_handle_t * handle,
                                return STATUS_ERR;
                        }
 
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(addr_bytes, in_addr.s6_addr, 16);
 #else
                        memcpy(addr_bytes, in_addr.s6_addr32, 16);
@@ -162,7 +162,7 @@ static int node_expand_addr(sepol_handle_t * handle,
                {
                        struct in6_addr addr;
                        memset(&addr, 0, sizeof(struct in6_addr));
-#ifdef DARWIN
+#ifdef __APPLE__
                        memcpy(&addr.s6_addr[0], addr_bytes, 16);
 #else
                        memcpy(&addr.s6_addr32[0], addr_bytes, 16);
libsepol/src/private.h +2 -2
index 8a6d4bb..9c700c9 100644
@@ -5,7 +5,7 @@
 #include <sepol/policydb/policydb.h>
 
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #include <sys/types.h>
 #include <machine/endian.h>
 #else
@@ -16,7 +16,7 @@
 #include <errno.h>
 #include <dso.h>
 
-#ifdef DARWIN
+#ifdef __APPLE__
 #define __BYTE_ORDER  BYTE_ORDER
 #define __LITTLE_ENDIAN  LITTLE_ENDIAN
 #endif
secilc/Android.mk +0 -5
index 3dd9023..6c7b9d3 100644
@@ -6,10 +6,6 @@ common_cflags := \
        -Wall -Wshadow -O2 \
        -pipe -fno-strict-aliasing \
 
-ifeq ($(HOST_OS), darwin)
-common_cflags += -DDARWIN
-endif
-
 common_includes := \
        $(LOCAL_PATH)/../libsepol/cil/include/ \
        $(LOCAL_PATH)/../libsepol/include/ \
--
Quoted 2 lines

2.5.5

--
Nick Kralevich | Android Security | [email protected] | 650.214.4037
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].

Signature · 3 lines
Respectfully,

William C Roberts