From 314225cedb810a3cf8d035183954343f0f548787 Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Sat, 31 May 2014 12:28:37 +0900 Subject: [PATCH] Initialize Tizen 2.3 --- AUTHORS | 3 + CMakeLists.txt | 104 ++++++++ LICENSE | 204 +++++++++++++++ app-checker-server.pc.in | 13 + app-checker.manifest | 5 + app-checker.pc.in | 13 + debian/changelog | 64 +++++ debian/compat | 1 + debian/control | 37 +++ debian/dirs | 2 + debian/docs | 0 debian/libapp-checker-0.install.in | 1 + debian/libapp-checker-0.postinst | 10 + debian/libapp-checker-dev.install.in | 2 + debian/libapp-checker-server-0.install.in | 1 + debian/libapp-checker-server-0.postinst | 12 + debian/libapp-checker-server-dev.install.in | 2 + debian/rules | 114 ++++++++ include/ac_sock.h | 54 ++++ include/app-checker-server.h | 46 ++++ include/app-checker.h | 50 ++++ include/internal.h | 61 +++++ packaging/app-checker.spec | 97 +++++++ src/ac_lib.c | 108 ++++++++ src/ac_server.c | 385 ++++++++++++++++++++++++++++ src/ac_sock.c | 322 +++++++++++++++++++++++ 26 files changed, 1711 insertions(+) create mode 100644 AUTHORS create mode 100755 CMakeLists.txt create mode 100644 LICENSE create mode 100755 app-checker-server.pc.in create mode 100644 app-checker.manifest create mode 100755 app-checker.pc.in create mode 100755 debian/changelog create mode 100644 debian/compat create mode 100755 debian/control create mode 100644 debian/dirs create mode 100644 debian/docs create mode 100755 debian/libapp-checker-0.install.in create mode 100755 debian/libapp-checker-0.postinst create mode 100755 debian/libapp-checker-dev.install.in create mode 100755 debian/libapp-checker-server-0.install.in create mode 100755 debian/libapp-checker-server-0.postinst create mode 100755 debian/libapp-checker-server-dev.install.in create mode 100755 debian/rules create mode 100755 include/ac_sock.h create mode 100755 include/app-checker-server.h create mode 100755 include/app-checker.h create mode 100755 include/internal.h create mode 100644 packaging/app-checker.spec create mode 100755 src/ac_lib.c create mode 100755 src/ac_server.c create mode 100755 src/ac_sock.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..064881e --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Jayoun Lee +Sewook Park +Jaeho Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..2de8706 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,104 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) + +PROJECT(app-checker C) +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.1.0") + +### Global setting ### + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(INCLUDEDIR "\${prefix}/include/app-checker") + +# Build type : Release +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF() +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + + +# Set required packages +INCLUDE(FindPkgConfig) + +pkg_check_modules(pkgs REQUIRED dlog glib-2.0) +pkg_check_modules(libpkgs REQUIRED dlog glib-2.0) + +FIND_LIBRARY(LIB_DL dl) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(TEST_CFLAGS "${TEST_CFLAGS} ${flag}") +ENDFOREACH(flag) + +# Compiler flags +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_SKIP_BUILD_RPATH true) + +# Get uname value to set 'TARGET' definition +# TODO: Is this needed? +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DRW_DATA_PREFIX=\"/opt/share\"") +ADD_DEFINITIONS("-DLIBPREFIX=\"${LIB_INSTALL_DIR}\"") +# Linker flags +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + + +### Build ### + + +# app-checker +add_library(app-checker SHARED + src/ac_lib.c + src/ac_sock.c + ) +target_link_libraries(app-checker ${libpkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(app-checker PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(app-checker PROPERTIES VERSION ${VERSION}) + +# +SET(DAEMON_NAME "app-checker-server") +add_library(${DAEMON_NAME} SHARED + src/ac_server.c + src/ac_sock.c + ) + +target_link_libraries(${DAEMON_NAME} ${pkgs_LDFLAGS} ${LIB_DL}) +SET_TARGET_PROPERTIES(${DAEMON_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${DAEMON_NAME} PROPERTIES VERSION ${VERSION}) + +# pkgconfig file +CONFIGURE_FILE(app-checker.pc.in app-checker.pc @ONLY) +CONFIGURE_FILE(app-checker-server.pc.in app-checker-server.pc @ONLY) + + +MESSAGE("LIBDIR ${LIB_INSTALL_DIR}") +### Install ### +INSTALL(TARGETS app-checker DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(TARGETS ${DAEMON_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/app-checker.h DESTINATION include/app-checker) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/app-checker.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/app-checker-server.h DESTINATION include/app-checker) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/app-checker-server.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c13a9b --- /dev/null +++ b/LICENSE @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/app-checker-server.pc.in b/app-checker-server.pc.in new file mode 100755 index 0000000..9c4f455 --- /dev/null +++ b/app-checker-server.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=@EXEC_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDEDIR@ + +Name: libapp-checker-server +Description: application checker server +Version: @VERSION@ +Requires: +Libs: -L${libdir} -lapp-checker-server +Cflags: -I${includedir} diff --git a/app-checker.manifest b/app-checker.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/app-checker.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/app-checker.pc.in b/app-checker.pc.in new file mode 100755 index 0000000..7393673 --- /dev/null +++ b/app-checker.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=@EXEC_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDEDIR@ + +Name: libapp-checker +Description: application checker +Version: @VERSION@ +Requires: +Libs: -L${libdir} -lapp-checker +Cflags: -I${includedir} diff --git a/debian/changelog b/debian/changelog new file mode 100755 index 0000000..d6e34cc --- /dev/null +++ b/debian/changelog @@ -0,0 +1,64 @@ +app-checker (0.0.8) unstable; urgency=low + + * Fixed compile warnings + * Git: slp/pkgs/a/app-checker + * Tag: app-checker_0.0.8 + + -- Jaeho Lee Tue, 20 Mar 2012 13:42:36 +0900 + +app-checker (0.0.7) unstable; urgency=low + + * Fix bug (memset) + * Git: slp/pkgs/a/app-checker + * Tag: app-checker_0.0.7 + + -- Jaeho Lee Fri, 02 Mar 2012 18:09:01 +0900 + +app-checker (0.0.6) unstable; urgency=low + + * Added TC + * Git: slp/pkgs/a/app-checker + * Tag: app-checker_0.0.6 + + -- Jaeho Lee Mon, 19 Dec 2011 19:06:25 +0900 + +app-checker (0.0.5) unstable; urgency=low + + * Changed boilerplate + * Git: 165.213.180.234:slp/pkgs/a/app-checker + * Tag: app-checker_0.0.5 + + -- Jaeho Lee Mon, 05 Dec 2011 16:35:25 +0900 + +app-checker (0.0.4) unstable; urgency=low + + * Fix svace bugs + * Git: 165.213.180.234:slp/pkgs/a/app-checker + * Tag: app-checker_0.0.4 + + -- Jaeho Lee Tue, 25 Oct 2011 19:04:37 +0900 + +app-checker (0.0.3) unstable; urgency=low + + * Fix memory leak + * Git: 165.213.180.234:slp/pkgs/a/app-checker + * Tag: app-checker_0.0.3 + + -- Jaeho Lee Tue, 25 Oct 2011 16:36:06 +0900 + +app-checker (0.0.2) unstable; urgency=low + + * add plugin directory + * Git: 165.213.180.234:slp/pkgs/a/app-checker + * Tag: app-checker_0.0.2 + + -- root Mon, 17 Oct 2011 19:09:13 +0900 + +app-checker (0.0.1) unstable; urgency=low + + * initial update + * Git: 165.213.180.234:slp/pkgs/a/app-checker + * Tag: app-checker_0.0.1 + + -- Jaeho Lee Tue, 19 Jul 2011 10:23:24 +0900 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..cb7ba32 --- /dev/null +++ b/debian/control @@ -0,0 +1,37 @@ +Source: app-checker +Section: devel +Priority: extra +Maintainer: Jayoun Lee , Sewook Park , Jaeho Lee +Build-Depends: debhelper (>= 5), dlog-dev, libglib2.0-dev +Standards-Version: 0.1.0 + +Package: libapp-checker-dev +Section: libs +Architecture: any +Depends: libapp-checker-0 (= ${Source-Version}) +Description: libapp-checker dev package + +Package: libapp-checker-0 +Section: libs +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: libapp-checker-0 package + +Package: libapp-checker-server-dev +Section: libs +Architecture: any +Depends: libapp-checker-server-0 (= ${Source-Version}) +Description: libapp-checker dev package + +Package: libapp-checker-server-0 +Section: devel +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: libapp-checker server package + +Package: app-checker-dbg +Section: debug +Architecture: any +Depends: libapp-checker-0, libapp-checker-server-0, ${shlibs:Depends}, ${misc:Depends} +Description: app-checker dbg package + diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..ca882bb --- /dev/null +++ b/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/sbin diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/libapp-checker-0.install.in b/debian/libapp-checker-0.install.in new file mode 100755 index 0000000..95060a0 --- /dev/null +++ b/debian/libapp-checker-0.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/libapp-checker.so* diff --git a/debian/libapp-checker-0.postinst b/debian/libapp-checker-0.postinst new file mode 100755 index 0000000..f904ab2 --- /dev/null +++ b/debian/libapp-checker-0.postinst @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ "${USER}" = "root" ] +then + chown root:root /usr/lib/libapp-checker.so.0.1.0 +fi + +chmod 644 /usr/lib/libapp-checker.so.0.1.0 + +#chmod 1777 /opt/share/miregex # Set directory to be writable for other accounts diff --git a/debian/libapp-checker-dev.install.in b/debian/libapp-checker-dev.install.in new file mode 100755 index 0000000..ef3d90e --- /dev/null +++ b/debian/libapp-checker-dev.install.in @@ -0,0 +1,2 @@ +@PREFIX@/include/app-checker/app-checker.h +@PREFIX@/lib/pkgconfig/app-checker.pc diff --git a/debian/libapp-checker-server-0.install.in b/debian/libapp-checker-server-0.install.in new file mode 100755 index 0000000..de22c58 --- /dev/null +++ b/debian/libapp-checker-server-0.install.in @@ -0,0 +1 @@ +@PREFIX@/lib/libapp-checker-server.so* diff --git a/debian/libapp-checker-server-0.postinst b/debian/libapp-checker-server-0.postinst new file mode 100755 index 0000000..2c53bed --- /dev/null +++ b/debian/libapp-checker-server-0.postinst @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "${USER}" = "root" ] +then + chown root:root /usr/lib/libapp-checker-server.so.0.1.0 +fi + +chmod 644 /usr/lib/libapp-checker-server.so.0.1.0 + +mkdir -p /usr/lib/ac-plugins + +#chmod 1777 /opt/share/miregex # Set directory to be writable for other accounts diff --git a/debian/libapp-checker-server-dev.install.in b/debian/libapp-checker-server-dev.install.in new file mode 100755 index 0000000..88dc4bc --- /dev/null +++ b/debian/libapp-checker-server-dev.install.in @@ -0,0 +1,2 @@ +@PREFIX@/include/app-checker/app-checker-server.h +@PREFIX@/lib/pkgconfig/app-checker-server.pc diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..379306f --- /dev/null +++ b/debian/rules @@ -0,0 +1,114 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +CFLAGS += -Wall -g +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +CFLAGS += -fvisibility=hidden -fpic +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +CMAKE_TMP_DIR = $(CURDIR)/cmake_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + mkdir -p $(CMAKE_TMP_DIR); + cd $(CMAKE_TMP_DIR); CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + cd $(CMAKE_TMP_DIR) && $(MAKE) all + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + rm -rf $(CMAKE_TMP_DIR) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/wavplayer. + cd $(CMAKE_TMP_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip --dbg-package=app-checker-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/include/ac_sock.h b/include/ac_sock.h new file mode 100755 index 0000000..6866c72 --- /dev/null +++ b/include/ac_sock.h @@ -0,0 +1,54 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef __APP_PKT_T_ +#define __APP_PKT_T_ + +#include +#define __USE_GNU +#include +#include + +enum ac_cmd { + AC_CHECK, + AC_REGISTER, + AC_UNREGISTER, +}; + +#define AC_SOCK_NAME "/tmp/ac-socket" +#define AC_SOCK_MAXBUFF 65535 + +typedef struct _ac_pkt_t { + int cmd; + int len; + unsigned char data[1]; +} ac_pkt_t; + +int _create_server_sock(); +int _create_client_sock(); +int _app_send_raw(int cmd, unsigned char *data, int datalen); +ac_pkt_t *_app_recv_raw(int fd, int *clifd, struct ucred *cr); +int _send_result_to_server(int fd, int res); + + +#endif + diff --git a/include/app-checker-server.h b/include/app-checker-server.h new file mode 100755 index 0000000..a1f4614 --- /dev/null +++ b/include/app-checker-server.h @@ -0,0 +1,46 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef __APP_CHECKER_SERVER_H__ +#define __APP_CHECKER_SERVER_H__ + +#ifdef __cpulusplus +extern "C" { +#endif + +typedef enum _ac_return_val { + AC_R_ERROR = -1, /**< General error */ + AC_R_OK = 0 /**< General success */ +}ac_return_val; + +int ac_server_initialize(); +int ac_server_check_launch_privilege(const char *pkg_name, const char *pkg_type, int pid); + +#ifdef __cpulusplus + } +#endif + +#endif /* __APP_CHECKER_SERVER_H__ */ + + + + diff --git a/include/app-checker.h b/include/app-checker.h new file mode 100755 index 0000000..9ae03be --- /dev/null +++ b/include/app-checker.h @@ -0,0 +1,50 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef __APP_CHECKER_H__ +#define __APP_CHECKER_H__ + +#ifdef __cpulusplus +extern "C" { +#endif + +typedef enum _ac_return_val { + AC_R_ETIMEOUT = -6, /**< Timeout */ + AC_R_EINVAL = -4, /**< Invalid argument */ + AC_R_ECOMM = -3, + AC_R_ENOPULUGINS = -2, + AC_R_ERROR = -1, /**< General error */ + AC_R_OK = 0 /**< General success */ +}ac_return_val; + +int ac_check_launch_privilege(const char *appid, const char *pkg_type, int pid); + +int ac_register_launch_privilege(const char *pkg_name, const char *pkg_type); + +int ac_unregister_launch_privilege(const char *pkg_name, const char *pkg_type); + + +#ifdef __cpulusplus + } +#endif + +#endif /* __APP_CHECKER_H__ */ diff --git a/include/internal.h b/include/internal.h new file mode 100755 index 0000000..731263d --- /dev/null +++ b/include/internal.h @@ -0,0 +1,61 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#ifndef __INTERNAL_H__ +#define __INTERNAL_H__ + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "APP_CHECKER" + +#define MAX_PACKAGE_STR_SIZE 512 +#define MAX_PACKAGE_TYPE_SIZE 128 + +struct ac_data { + char pkg_name[MAX_PACKAGE_STR_SIZE]; + char pkg_type[MAX_PACKAGE_TYPE_SIZE]; + int pid; +}; + +#define _E(fmt, arg...) LOGE(fmt,##arg) +#define _D(fmt, arg...) LOGD(fmt,##arg) + +#define retvm_if(expr, val, fmt, arg...) do { \ + if(expr) { \ + _E(fmt, ##arg); \ + _E("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ +} while (0) + +#define retv_if(expr, val) do { \ + if(expr) { \ + _E("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ +} while (0) + +#endif /* __INTERNAL_H__ */ + diff --git a/packaging/app-checker.spec b/packaging/app-checker.spec new file mode 100644 index 0000000..5197646 --- /dev/null +++ b/packaging/app-checker.spec @@ -0,0 +1,97 @@ +Name: app-checker +Summary: App Checker +Version: 0.0.16 +Release: 1 +Group: System/Libraries +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(glib-2.0) + + +%description +libapp-checker + +%package devel +Summary: App Checker +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +libapp-checker (developement files) + +%package server +Summary: App Checker Server +Group: System/Libraries +Requires: %{name} = %{version}-%{release} + +%description server +libapp-checker server + +%package server-devel +Summary: App Checker Server +Group: System/Libraries +Requires: %{name}-server = %{version}-%{release} + +%description server-devel +libapp-checker server (developement files) + + + +%prep +%setup -q + + +%build + +%cmake . + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +mkdir -p %{buildroot}/usr/lib/ac-plugins + +mkdir -p %{buildroot}/usr/share/license +cp LICENSE %{buildroot}/usr/share/license/%{name} +cp LICENSE %{buildroot}/usr/share/license/%{name}-devel +cp LICENSE %{buildroot}/usr/share/license/%{name}-server +cp LICENSE %{buildroot}/usr/share/license/%{name}-server-devel + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%manifest app-checker.manifest +%defattr(-,root,root,-) +%{_libdir}/libapp-checker.so.0 +%{_libdir}/libapp-checker.so.0.1.0 +/usr/lib/ac-plugins +/usr/share/license/%{name} + + +%files devel +%defattr(-,root,root,-) +%{_libdir}/libapp-checker.so +%{_libdir}/pkgconfig/app-checker.pc +/usr/include/app-checker/app-checker.h +/usr/share/license/%{name}-devel + +%files server +%manifest app-checker.manifest +%defattr(-,root,root,-) +%{_libdir}/libapp-checker-server.so.0 +%{_libdir}/libapp-checker-server.so.0.1.0 +/usr/share/license/%{name}-server + +%files server-devel +%defattr(-,root,root,-) +%{_libdir}/libapp-checker-server.so +%{_libdir}/pkgconfig/app-checker-server.pc +/usr/include/app-checker/app-checker-server.h +/usr/share/license/%{name}-server-devel + diff --git a/src/ac_lib.c b/src/ac_lib.c new file mode 100755 index 0000000..cfb92b3 --- /dev/null +++ b/src/ac_lib.c @@ -0,0 +1,108 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include +#include +#include + +#include +#include "ac_sock.h" +#include "internal.h" + +#ifndef SLPAPI +#define SLPAPI __attribute__ ((visibility("default"))) +#endif + +static int app_send_cmd(const char *pkg_name, const char *pkg_type, int pid, int cmd) +{ + int ret = -1; + unsigned char *data; + struct ac_data ad; + + memset(&ad, 0, sizeof(ad)); + + strncpy(ad.pkg_name, pkg_name, MAX_PACKAGE_STR_SIZE-1); + strncpy(ad.pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE-1); + ad.pid = pid; + + data = (unsigned char *)g_base64_encode((const guchar *)&ad, sizeof(ad)); + + if ((ret = _app_send_raw(cmd, data, (int)strnlen((char *)data, AC_SOCK_MAXBUFF - 8))) < 0) { + switch (ret) { + case -EINVAL: + ret = AC_R_EINVAL; + break; + case -ECOMM: + ret = AC_R_ECOMM; + break; + case -EAGAIN: + ret = AC_R_ETIMEOUT; + break; + case AC_R_ENOPULUGINS: + ret = AC_R_ENOPULUGINS; + break; + default: + ret = AC_R_ERROR; + } + } + + g_free(data); + return ret; +} + +SLPAPI int ac_check_launch_privilege(const char *appid, const char *pkg_type, int pid) +{ + int ret = -1; + + if(appid == NULL || pkg_type == NULL) + return AC_R_EINVAL; + + ret = app_send_cmd(appid, pkg_type, pid, AC_CHECK); + + return ret; +} + +SLPAPI int ac_register_launch_privilege(const char *pkg_name, const char *pkg_type) +{ + int ret = -1; + + if(pkg_name == NULL || pkg_type == NULL) + return AC_R_EINVAL; + + ret = app_send_cmd(pkg_name, pkg_type, -1, AC_REGISTER); + + return ret; +} + +SLPAPI int ac_unregister_launch_privilege(const char *pkg_name, const char *pkg_type) +{ + int ret = -1; + + if(pkg_name == NULL || pkg_type == NULL) + return AC_R_EINVAL; + + ret = app_send_cmd(pkg_name, pkg_type, -1, AC_UNREGISTER); + + return ret; +} + diff --git a/src/ac_server.c b/src/ac_server.c new file mode 100755 index 0000000..2508bc4 --- /dev/null +++ b/src/ac_server.c @@ -0,0 +1,385 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ac_sock.h" +#include "internal.h" + +#define PLUGINS_PREFIX LIBPREFIX "/ac-plugins" +#define MAX_LOCAL_BUFSZ 512 + +#ifndef SLPAPI +#define SLPAPI __attribute__ ((visibility("default"))) +#endif + +GSList *pkg_type_list = NULL; + +typedef struct _ac_type_list_t { + char *pkg_type; + GSList *so_list; +} ac_type_list_t; + +typedef struct _ac_so_list_t { + char *so_name; + int (*ac_check)(const char*); + int (*ac_register)(const char*); + int (*ac_unregister)(const char*); +} ac_so_list_t; + +static int __send_to_sigkill(int pid) +{ + int pgid; + + pgid = getpgid(pid); + if (pgid <= 1) + return -1; + + if (killpg(pgid, SIGKILL) < 0) + return -1; + + return 0; +} + +static int __check_launch_privilege(const char *pkg_name, const char *pkg_type, int pid) +{ + GSList *iter = NULL; + GSList *iter2 = NULL; + ac_type_list_t *type_t; + ac_so_list_t *so_t; + + for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) { + type_t = iter->data; + if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) { + for (iter2 = type_t->so_list; iter2 != NULL; iter2 = g_slist_next(iter2)) { + so_t = iter2->data; + _D("type : %s / so name : %s / func : %x", type_t->pkg_type, so_t->so_name, so_t->ac_check); + if (so_t->ac_check && so_t->ac_check(pkg_name) < 0) { + if(pid > 0) + __send_to_sigkill(pid); + return AC_R_ERROR; + } + } + return AC_R_OK; + } + } + + return AC_R_ENOPULUGINS; +} + +static int __register_launch_privilege(const char *pkg_name, const char *pkg_type) +{ + GSList *iter = NULL; + GSList *iter2 = NULL; + ac_type_list_t *type_t; + ac_so_list_t *so_t; + int ret = AC_R_OK; + + for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) { + type_t = iter->data; + if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) { + for (iter2 = type_t->so_list; iter2 != NULL; iter = g_slist_next(iter2)) { + so_t = iter2->data; + if (so_t->ac_register && so_t->ac_register(pkg_name) < 0) { + ret = AC_R_ERROR; + } + } + return ret; + } + } + + return AC_R_ENOPULUGINS; + +} + +static int __unregister_launch_privilege(const char *pkg_name, const char *pkg_type) +{ + GSList *iter = NULL; + GSList *iter2 = NULL; + ac_type_list_t *type_t; + ac_so_list_t *so_t; + int ret = AC_R_OK; + + for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) { + type_t = iter->data; + if (strncmp(type_t->pkg_type, pkg_type, MAX_PACKAGE_TYPE_SIZE) == 0) { + for (iter2 = type_t->so_list; iter2 != NULL; iter = g_slist_next(iter2)) { + so_t = iter2->data; + if (so_t->ac_unregister && so_t->ac_unregister(pkg_name) < 0) { + ret = AC_R_ERROR; + } + } + return ret; + } + } + + return AC_R_ENOPULUGINS;; + +} + +static gboolean __ac_handler(gpointer data) +{ + GPollFD *gpollfd = (GPollFD *) data; + int fd = gpollfd->fd; + ac_pkt_t *pkt; + int clifd; + struct ucred cr; + struct ac_data *ad; + int ret = -1; + int size; + + if ((pkt = _app_recv_raw(fd, &clifd, &cr)) == NULL) { + _E("recv error"); + return FALSE; + } + + ad = (struct ac_data *)g_base64_decode((const gchar*)pkt->data, (gsize *)&size); + + _D("cmd : %d, pkgname : %s, pkgtype : %s", pkt->cmd, ad->pkg_name, ad->pkg_type); + + switch (pkt->cmd) { + case AC_CHECK: + _send_result_to_server(clifd, AC_R_OK); + ret = __check_launch_privilege(ad->pkg_name, ad->pkg_type, ad->pid); + g_free(ad); + free(pkt); + return TRUE; + break; + case AC_REGISTER: + ret = __register_launch_privilege(ad->pkg_name, ad->pkg_type); + break; + case AC_UNREGISTER: + ret = __unregister_launch_privilege(ad->pkg_name, ad->pkg_type); + break; + default: + _E("no support packet"); + } + + _send_result_to_server(clifd, ret); + + g_free(ad); + free(pkt); + return TRUE; +} + +static gboolean __ac_glib_check(GSource *src) +{ + GSList *fd_list; + GPollFD *tmp; + + fd_list = src->poll_fds; + do { + tmp = (GPollFD *) fd_list->data; + if ((tmp->revents & (POLLIN | POLLPRI))) + return TRUE; + fd_list = fd_list->next; + } while (fd_list); + + return FALSE; +} + +static gboolean __ac_glib_dispatch(GSource *src, GSourceFunc callback, + gpointer data) +{ + callback(data); + return TRUE; +} + +static gboolean __ac_glib_prepare(GSource *src, gint *timeout) +{ + return FALSE; +} + +static GSourceFuncs funcs = { + .prepare = __ac_glib_prepare, + .check = __ac_glib_check, + .dispatch = __ac_glib_dispatch, + .finalize = NULL +}; + +static void __pkt_type_list_free() +{ + GSList *iter = NULL; + GSList *iter2 = NULL; + ac_type_list_t *type_t; + ac_so_list_t *so_t; + + for (iter = pkg_type_list; iter != NULL; iter = g_slist_next(iter)) { + type_t = iter->data; + if(type_t) { + for (iter2 = type_t->so_list; iter2 != NULL; iter2 = g_slist_next(iter2)) { + so_t = iter2->data; + if(so_t) { + if(so_t->so_name) + free(so_t->so_name); + free(so_t); + } + } + g_slist_free(type_t->so_list); + + + if(type_t->pkg_type) + free(type_t->pkg_type); + free(type_t); + } + } + g_slist_free(pkg_type_list); + return; +} + +int __initialize() +{ + int fd; + GPollFD *gpollfd; + GSource *src; + int ret; + + _D("app checker server initialize"); + + fd = _create_server_sock(); + + src = g_source_new(&funcs, sizeof(GSource)); + + gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD)); + gpollfd->events = POLLIN; + gpollfd->fd = fd; + + g_source_add_poll(src, gpollfd); + g_source_set_callback(src, (GSourceFunc) __ac_handler, + (gpointer) gpollfd, NULL); + g_source_set_priority(src, G_PRIORITY_DEFAULT); + + ret = g_source_attach(src, NULL); + if (ret == 0) + { + /* TODO: error handle*/ + return AC_R_ERROR; + } + + g_source_unref(src); + + DIR *dp; + struct dirent *dentry; + DIR *sub_dp = NULL; + struct dirent *sub_dentry; + char buf[MAX_LOCAL_BUFSZ]; + char buf2[MAX_LOCAL_BUFSZ]; + ac_type_list_t *type_t = NULL; + void *handle = NULL; + ac_so_list_t *so_t = NULL; + + dp = opendir(PLUGINS_PREFIX); + if (dp == NULL) { + return AC_R_ERROR; + } + while ((dentry = readdir(dp)) != NULL) { + + if(dentry->d_type != DT_DIR) + continue; + if(strcmp(dentry->d_name,".") == 0 || strcmp(dentry->d_name,"..") == 0) + continue; + + snprintf(buf,MAX_LOCAL_BUFSZ,"%s/%s",PLUGINS_PREFIX,dentry->d_name); + _D("type : %s", dentry->d_name); + + type_t = malloc(sizeof(ac_type_list_t)); + if(type_t == NULL) { + __pkt_type_list_free(); + closedir(dp); + return AC_R_ERROR; + } + memset(type_t, 0, sizeof(ac_type_list_t)); + type_t->pkg_type = strdup(dentry->d_name); + type_t->so_list = NULL; + + pkg_type_list = g_slist_append(pkg_type_list, (void *)type_t); + + sub_dp = opendir(buf); + if (sub_dp == NULL) { + __pkt_type_list_free(); + closedir(dp); + return AC_R_ERROR; + } + + while ((sub_dentry = readdir(sub_dp)) != NULL) { + + if(sub_dentry->d_type == DT_DIR) + continue; + snprintf(buf2,MAX_LOCAL_BUFSZ,"%s/%s", buf, sub_dentry->d_name); + _D("so_name : %s", buf2); + + handle = dlopen(buf2, RTLD_LAZY); + if(handle == NULL) + continue; + so_t = malloc(sizeof(ac_so_list_t)); + if(so_t == NULL) { + __pkt_type_list_free(); + dlclose(handle); + handle = NULL; + closedir(sub_dp); + closedir(dp); + return AC_R_ERROR; + } + memset(so_t, 0, sizeof(ac_so_list_t)); + so_t->so_name = strdup(sub_dentry->d_name); + so_t->ac_check = dlsym(handle, "check_launch_privilege"); + so_t->ac_register = dlsym(handle, "check_register_privilege"); + so_t->ac_unregister = dlsym(handle, "check_unregister_privilege"); + + type_t->so_list = g_slist_append(type_t->so_list, (void *)so_t); + handle = NULL; + } + closedir(sub_dp); + } + closedir(dp); + + return AC_R_OK; +} + +SLPAPI int ac_server_initialize() +{ + int ret = AC_R_OK; + + ret = __initialize(); + + return ret; +} + +SLPAPI int ac_server_check_launch_privilege(const char *pkg_name, const char *pkg_type, int pid) +{ + int ret = -1; + ret = __check_launch_privilege(pkg_name, pkg_type, pid); + + return ret; +} + + diff --git a/src/ac_sock.c b/src/ac_sock.c new file mode 100755 index 0000000..ce81406 --- /dev/null +++ b/src/ac_sock.c @@ -0,0 +1,322 @@ +/* + * app-checker + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee , Sewook Park , Jaeho Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + +#include +#include +#include +#include +#include +#include +#include + + +#include "ac_sock.h" +#include "internal.h" + +static int __connect_client_sock(int sockfd, const struct sockaddr *saptr, socklen_t salen, + int nsec); + +static inline void __set_sock_option(int fd, int cli) +{ + int size; + struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */ + + size = AC_SOCK_MAXBUFF; + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)); + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); + if (cli) + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); +} + +int _create_server_sock() +{ + struct sockaddr_un saddr; + int fd; + + fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + /* support above version 2.6.27*/ + if (fd < 0) { + if(errno == EINVAL) { + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd < 0) { + _E("second chance - socket create error"); + return -1; + } + } else { + _E("socket error"); + return -1; + } + } + + memset(&saddr, 0, sizeof(saddr)); + saddr.sun_family = AF_UNIX; + snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s",AC_SOCK_NAME); + unlink(saddr.sun_path); + + if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { + _E("bind error"); + close(fd); + return -1; + } + + if (chmod(saddr.sun_path, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) { + /* Flawfinder: ignore*/ + _E("failed to change the socket permission"); + close(fd); + return -1; + } + + __set_sock_option(fd, 0); + + if (listen(fd, 10) == -1) { + _E("listen error"); + close(fd); + return -1; + } + + return fd; +} + +int _create_client_sock() +{ + int fd = -1; + struct sockaddr_un saddr = { 0, }; + int retry = 1; + int ret = -1; + + fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + /* support above version 2.6.27*/ + if (fd < 0) { + if (errno == EINVAL) { + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + _E("second chance - socket create error"); + return -1; + } + } else { + _E("socket error"); + return -1; + } + } + + saddr.sun_family = AF_UNIX; + snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s", AC_SOCK_NAME); + retry_con: + ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, sizeof(saddr), + 100 * 1000); + if (ret < -1) { + _E("maybe peer not launched or peer daed\n"); + if (retry > 0) { + usleep(100 * 1000); + retry--; + goto retry_con; + } + } + if (ret < 0) { + close(fd); + return -1; + } + + __set_sock_option(fd, 1); + + return fd; +} + +static int __connect_client_sock(int fd, const struct sockaddr *saptr, socklen_t salen, + int nsec) +{ + int flags; + int ret; + int error; + socklen_t len; + fd_set readfds; + fd_set writefds; + struct timeval timeout; + + flags = fcntl(fd, F_GETFL, 0); + fcntl(fd, F_SETFL, flags | O_NONBLOCK); + + error = 0; + if ((ret = connect(fd, (struct sockaddr *)saptr, salen)) < 0) { + if (errno != EAGAIN && errno != EINPROGRESS) { + fcntl(fd, F_SETFL, flags); + return (-2); + } + } + + /* Do whatever we want while the connect is taking place. */ + if (ret == 0) + goto done; /* connect completed immediately */ + + FD_ZERO(&readfds); + FD_SET(fd, &readfds); + writefds = readfds; + timeout.tv_sec = 0; + timeout.tv_usec = nsec; + + if ((ret = select(fd + 1, &readfds, &writefds, NULL, + nsec ? &timeout : NULL)) == 0) { + close(fd); /* timeout */ + errno = ETIMEDOUT; + return (-1); + } + + if (FD_ISSET(fd, &readfds) || FD_ISSET(fd, &writefds)) { + len = sizeof(error); + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) + return (-1); /* Solaris pending error */ + } else + return (-1); /* select error: sockfd not set*/ + + done: + fcntl(fd, F_SETFL, flags); + if (error) { + close(fd); + errno = error; + return (-1); + } + return (0); +} + +/** + * @brief Send data (in raw) to the process with 'pid' via socket + */ +int _app_send_raw(int cmd, unsigned char *data, int datalen) +{ + int fd; + int len; + int res = 0; + ac_pkt_t *pkt = NULL; + + if (data == NULL || datalen > AC_SOCK_MAXBUFF - 8) { + _E("keybundle error\n"); + return -EINVAL; + } + + fd = _create_client_sock(); + if (fd < 0) + return -ECOMM; + + pkt = (ac_pkt_t *) malloc(sizeof(char) * AC_SOCK_MAXBUFF); + if (NULL == pkt) { + _E("Malloc Failed!"); + return -ENOMEM; + } + memset(pkt, 0, AC_SOCK_MAXBUFF); + + pkt->cmd = cmd; + pkt->len = datalen; + memcpy(pkt->data, data, datalen); + + if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) { + _E("sendto() failed - %d %d", len, datalen + 8); + if (errno == EPIPE) { + _E("fd:%d\n", fd); + } + close(fd); + if (pkt) { + free(pkt); + pkt = NULL; + } + return -ECOMM; + } + if (pkt) { + free(pkt); + pkt = NULL; + } + + len = recv(fd, &res, sizeof(int), 0); + if (len == -1) { + if (errno == EAGAIN) { + _E("recv timeout \n"); + res = -EAGAIN; + } else { + _E("recv error\n"); + res = -ECOMM; + } + } else + _D("recv result = %d (%d)", res, len); + close(fd); + + return res; +} + +ac_pkt_t *_app_recv_raw(int fd, int *clifd, struct ucred *cr) +{ + int len; + struct sockaddr_un aul_addr = { 0, }; + int sun_size; + ac_pkt_t *pkt = NULL; + int cl = sizeof(struct ucred); + + sun_size = sizeof(struct sockaddr_un); + + if ((*clifd = accept(fd, (struct sockaddr *)&aul_addr, + (socklen_t *) &sun_size)) == -1) { + if (errno != EINTR) + _E("accept error"); + return NULL; + } + + if (getsockopt(*clifd, SOL_SOCKET, SO_PEERCRED, cr, + (socklen_t *) &cl) < 0) { + _E("peer information error"); + close(*clifd); + return NULL; + } + + pkt = (ac_pkt_t *) malloc(sizeof(char) * AC_SOCK_MAXBUFF); + if(pkt == NULL) { + close(*clifd); + return NULL; + } + memset(pkt, 0, AC_SOCK_MAXBUFF); + + __set_sock_option(*clifd, 1); + + retry_recv: + /* receive single packet from socket */ + len = recv(*clifd, pkt, AC_SOCK_MAXBUFF, 0); + if (len < 0) + if (errno == EINTR) + goto retry_recv; + + if ((len < 8) || (len != (pkt->len + 8))) { + _E("recv error %d %d", len, pkt->len); + free(pkt); + close(*clifd); + return NULL; + } + + return pkt; +} + +int _send_result_to_server(int fd, int res) +{ + if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) { + if (errno == EPIPE) + _E("send failed due to EPIPE.\n"); + _E("send fail to client"); + } + close(fd); + return 0; +} -- 2.7.4