project(modules)

find_package(Libsmbclient REQUIRED)
find_package(LIBSSH)

set(MODULES_PUBLIC_INCLUDE_DIRS
  ${CMAKE_CURRENT_SOURCE_DIR}
  CACHE INTERNAL "modules include directories"
)

set(MODULES_PRIVATE_INCLUDE_DIRS
  ${CSTDLIB_PUBLIC_INCLUDE_DIRS}
  ${CSYNC_PUBLIC_INCLUDE_DIRS}
  ${LIBSMBCLIENT_INCLUDE_DIRS}
)

set(SMB_PLUGIN
  csync_smb
)

set(SFTP_PLUGIN
  csync_sftp
)

include_directories(
  ${MODULES_PUBLIC_INCLUDE_DIRS}
  ${MODULES_PRIVATE_INCLUDE_DIRS}
)

macro_add_plugin(${SMB_PLUGIN} csync_smb.c)
target_link_libraries(${SMB_PLUGIN} ${LIBSMBCLIENT_LIBRARIES})

install(
  TARGETS
    ${SMB_PLUGIN}
  DESTINATION
    ${PLUGIN_INSTALL_DIR}
)

macro_add_plugin(csync_dummy csync_dummy.c)

if (LIBSSH_FOUND)
macro_add_plugin(${SFTP_PLUGIN} csync_sftp.c)
target_link_libraries(${SFTP_PLUGIN} ${LIBSSH_LIBRARIES})

install(
  TARGETS
    ${SFTP_PLUGIN}
  DESTINATION
    ${PLUGIN_INSTALL_DIR}
)
endif (LIBSSH_FOUND)


# create test file as bad plugin for the vio testcase
file(WRITE
  ${CMAKE_CURRENT_BINARY_DIR}/csync_bad.so
  "bad plugin"
)


project(modules)

find_package(Libsmbclient REQUIRED)
find_package(LIBSSH)

set(MODULES_PUBLIC_INCLUDE_DIRS
  ${CMAKE_CURRENT_SOURCE_DIR}
  CACHE INTERNAL "modules include directories"
)

set(MODULES_PRIVATE_INCLUDE_DIRS
  ${CSTDLIB_PUBLIC_INCLUDE_DIRS}
  ${CSYNC_PUBLIC_INCLUDE_DIRS}
  ${LIBSMBCLIENT_INCLUDE_DIRS}
)

set(SMB_PLUGIN
  csync_smb
)

set(SFTP_PLUGIN
  csync_sftp
)

include_directories(
  ${MODULES_PUBLIC_INCLUDE_DIRS}
  ${MODULES_PRIVATE_INCLUDE_DIRS}
)

macro_add_plugin(${SMB_PLUGIN} csync_smb.c)
target_link_libraries(${SMB_PLUGIN} ${CSTDLIB_LIBRARY} ${LIBSMBCLIENT_LIBRARIES})

install(
  TARGETS
    ${SMB_PLUGIN}
  DESTINATION
    ${PLUGIN_INSTALL_DIR}
)

macro_add_plugin(csync_dummy csync_dummy.c)

if (LIBSSH_FOUND)
macro_add_plugin(${SFTP_PLUGIN} csync_sftp.c)
target_link_libraries(${SFTP_PLUGIN} ${CSTDLIB_LIBRARY} ${LIBSSH_LIBRARIES})

install(
  TARGETS
    ${SFTP_PLUGIN}
  DESTINATION
    ${PLUGIN_INSTALL_DIR}
)
endif (LIBSSH_FOUND)


# create test file as bad plugin for the vio testcase
file(WRITE
  ${CMAKE_CURRENT_BINARY_DIR}/csync_bad.so
  "bad plugin"
)


Fix segfault in the modules if running in a pam module.
Fix segfault in the modules if running in a pam module.

If csync is running in a pam module and the module isn't linked
against the cstdlib, the module segfaults.
