libsepol: Android/MacOS X build support

Android/MacOS X build support for libsepol.
Create a Android.mk file for Android build integration.
Introduce DARWIN ifdefs for building on MacOS X.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Stephen Smalley 2012-02-23 10:05:01 -05:00 committed by Eric Paris
parent d21ec5a560
commit 84f6ac246f
6 changed files with 153 additions and 4 deletions

97
libsepol/Android.mk Normal file
View File

@ -0,0 +1,97 @@
LOCAL_PATH:= $(call my-dir)
common_src_files := \
src/assertion.c \
src/avrule_block.c \
src/avtab.c \
src/boolean_record.c \
src/booleans.c \
src/conditional.c \
src/constraint.c \
src/context.c \
src/context_record.c \
src/debug.c \
src/ebitmap.c \
src/expand.c \
src/genbools.c \
src/genusers.c \
src/handle.c \
src/hashtab.c \
src/hierarchy.c \
src/iface_record.c \
src/interfaces.c \
src/link.c \
src/mls.c \
src/module.c \
src/node_record.c \
src/nodes.c \
src/polcaps.c \
src/policydb.c \
src/policydb_convert.c \
src/policydb_public.c \
src/port_record.c \
src/ports.c \
src/roles.c \
src/services.c \
src/sidtab.c \
src/symtab.c \
src/user_record.c \
src/users.c \
src/util.c \
src/write.c
common_cflags := \
-Wall -W -Wundef \
-Wshadow -Wmissing-noreturn \
-Wmissing-format-attribute
ifeq ($(HOST_OS), darwin)
common_cflags += -DDARWIN
endif
common_includes := \
$(LOCAL_PATH)/include/ \
$(LOCAL_PATH)/src/
##
# libsepol.so
#
include $(CLEAR_VARS)
LOCAL_MODULE := libsepol
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := $(common_src_files)
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_HOST_SHARED_LIBRARY)
##
# libsepol.a
#
include $(CLEAR_VARS)
LOCAL_MODULE := libsepol
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := $(common_src_files)
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
include $(BUILD_HOST_STATIC_LIBRARY)
##
# chkcon
#
include $(CLEAR_VARS)
LOCAL_MODULE := chkcon
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes)
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := utils/chkcon.c
LOCAL_SHARED_LIBRARIES := libsepol
LOCAL_MODULE_CLASS := EXECUTABLES
include $(BUILD_HOST_EXECUTABLE)

View File

@ -79,7 +79,16 @@ static int load_booleans(struct policydb *policydb, const char *path,
if (boolf == NULL)
goto localbool;
#ifdef DARWIN
if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
ERR(NULL, "out of memory");
return -1;
}
while(fgets(buffer, 255, boolf) != NULL) {
#else
while (getline(&buffer, &size, boolf) > 0) {
#endif
int ret = process_boolean(buffer, name, sizeof(name), &val);
if (ret == -1)
errors++;
@ -101,7 +110,14 @@ static int load_booleans(struct policydb *policydb, const char *path,
snprintf(localbools, sizeof(localbools), "%s.local", path);
boolf = fopen(localbools, "r");
if (boolf != NULL) {
while (getline(&buffer, &size, boolf) > 0) {
#ifdef DARWIN
while(fgets(buffer, 255, boolf) != NULL) {
#else
while (getline(&buffer, &size, boolf) > 0) {
#endif
int ret =
process_boolean(buffer, name, sizeof(name), &val);
if (ret == -1)

View File

@ -1,11 +1,16 @@
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <sepol/policydb/policydb.h>
#ifndef DARWIN
#include <stdio_ext.h>
#endif
#include <stdarg.h>
#include "debug.h"
@ -41,9 +46,19 @@ static int load_users(struct policydb *policydb, const char *path)
fp = fopen(path, "r");
if (fp == NULL)
return -1;
__fsetlocking(fp, FSETLOCKING_BYCALLER);
#ifdef DARWIN
if ((buffer = (char *)malloc(255 * sizeof(char))) == NULL) {
ERR(NULL, "out of memory");
return -1;
}
while(fgets(buffer, 255, fp) != NULL) {
#else
__fsetlocking(fp, FSETLOCKING_BYCALLER);
while ((nread = getline(&buffer, &len, fp)) > 0) {
#endif
lineno++;
if (buffer[nread - 1] == '\n')
buffer[nread - 1] = 0;

View File

@ -70,7 +70,11 @@ static int node_parse_addr(sepol_handle_t * handle,
return STATUS_ERR;
}
#ifdef DARWIN
memcpy(addr_bytes, in_addr.s6_addr, 16);
#else
memcpy(addr_bytes, in_addr.s6_addr32, 16);
#endif
break;
}
default:
@ -158,8 +162,11 @@ static int node_expand_addr(sepol_handle_t * handle,
{
struct in6_addr addr;
memset(&addr, 0, sizeof(struct in6_addr));
#ifdef DARWIN
memcpy(&addr.s6_addr[0], addr_bytes, 16);
#else
memcpy(&addr.s6_addr32[0], addr_bytes, 16);
#endif
if (inet_ntop(AF_INET6, &addr, addr_str,
INET6_ADDRSTRLEN) == NULL) {

View File

@ -4,11 +4,23 @@
#include <sepol/policydb/policydb.h>
#ifdef DARWIN
#include <sys/types.h>
#include <machine/endian.h>
#else
#include <byteswap.h>
#include <endian.h>
#endif
#include <errno.h>
#include <dso.h>
#ifdef DARWIN
#define __BYTE_ORDER BYTE_ORDER
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define cpu_to_le16(x) (x)
#define le16_to_cpu(x) (x)

View File

@ -6,6 +6,8 @@
#include <string.h>
#include <errno.h>
void usage(char*) __attribute__((noreturn));
void usage(char *progname)
{
printf("usage: %s policy context\n", progname);