How to compile modsecurity on Ubuntu? - c

After I followed the instructions in (Building Custom ModSecurity Modules)section in modsecurity dev guide in order to compile (mod_tfn_reverse.c) using the command apxs -ca mod_tfn_reverse.c, I'm still finding "fatal errors" such as unable to find the file modsecurity.h mentioned in the header of the C document.
Here is the link to the source on github modsec
Instructions I did:
I am using Ubuntu 14.4 64bits (New installation with updates).
I installed "apache dev" package, to run "APXS" command on terminal.
Downloaded "modsecurity" zip file from github.
I extracted the zip file, then I located where the mod_tfn_reverse.c is.
It's path : ModSecurity/ext/mod_tfn_reverse.c
Then I changed the directory to the targeted file CD modsecurity/ext
as I placed the folder in "home".
Finally, I executed the command apxs -ca mod_tfn_reverse.c.
These are the instructions I did, apxs works, but the compilation fails because "modsecurity.h" declared in the header was not found, I searched this file I found it in another directory (ModSecurity/apache2/modsecurity.h).
So, the difficulty is, how can I successfully compile that specific file and have the module done and ready to use in apache2 server.
I am also confused about what are the other archives, headers, and development tools required to:
to compile a custom apache module.
to compile mod_tfn_reverse.c, in my case, knowing that this is only the starting point to create custom module for modsecurity.

This is covered by the included README:
apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
-ca mod_tfn_reverse.c

Related

C Code Won't Compile in MacOS Catalina or Big Sur

I am unable to compile C code on neither MacOS Catalina nor Big Sur. I see the header files present in /usr/include/, but I get errors from my C compiler.
Current error messages I get from the compiler are:
For "#include <time.h>" => error: cannot open source file "time.h"
For "#include <stdint.h>" => error: cannot open source file
"stdint.h"
What I've tried:
I tried sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target / and it says "upgrade successful", but does not resolve any errors.
I tried uninstalling and reinstalling XCode (Version 10.1)
I tried downloading the .pkg file you mentioned (because I was missing it) but was told my macOS version was too new
The files I need are stored in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include, so we added a new CPATH and PATH variable (separately) for that path to ~/.bash_profile and /etc/paths
I tried to provide #include statements with explicit paths to those files, which quickly spiraled out of control
I tried to move all of the required files from the above directory to my project folder and changing the paths appropriately in the code
I tried to run sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
The files should also be stored in Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include, so I tried doing the above steps with this path as well
Any advice would be helpful. Thank you!
To provide more clarity based on a comment from Joshua below, these are the steps I followed to set up the 32-bit ARM cross-compiler:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
brew install gmp
brew install mpfr
brew install libmpc
Downloaded "binutils-2.36.tar.xz" from here
Outside of the binutils directory, created a directory called
"build32"
../binutils-2.36/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers
make -j4 all
sudo make install
Downloaded "gcc-arm-src-snapshot-10.2-2020.11.tar.xz" from here
Inside the main directory, created a subdirectory called "build32"
../gcc-arm-src-snapshot-10.2-2020.11/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers
make -j4 all-gcc
sudo make install-gcc
I ended up switching to a Windows Subsystem for Linux setup on another machine for what I was working on. Another option is to set up a VM on the Mac. I could not figure out another solution for getting it to "just work" on the Mac. Thanks to everyone for the suggestions!
For those looking to pivot to WSL, follow this setup guide.
For those looking to go the VM workaround route, this is one process that was graciously recommended to me:
"1. Install Virtualbox from https://www.virtualbox.org/
Install Vagrant from https://www.vagrantup.com/
Download the prebuilt ARM gcc cross compiler from the link above in my question.
Move the download file into the project directory and run the following command to extract it:
tar -xvf gcc-arm-10.2-2020.11-x86_64-arm-none-eabi.tar.xz
Download this Vagrantfile (fyi 'this' triggers a download of said file) and move it to the project directory as
well. This file tells vagrant how to setup the VM. It will mount the
project directory as well as the SD card. On line 41 of this file it
tells vagrant where the SD card is located so change the first path
on this line to where your SD card is located. Additionally, because
the project directory is mounted, you can still edit the project
files locally on your machine instead of having to use what's on the
VM if you use this solution.
After all that, you should be ready to create/start the VM using the
command vagrant up. To log into the VM, vagrant ssh after the
vagrant up command finishes. Your project files should be located in
the /vagrant directory. You are now all setup to compile the project
and if you run make cp it should compile the project and copy it
over to the SD card.
To shutdown the VM you can run vagrant halt to shutdown the VM, and
to get rid of the VM you can run vagrant destroy. vagrant destroy
will not delete any of the files that were shared from your computer
to the VM."

autogen.sh - no such file or directory

I'm at the Get Started build instructions for libimobiledevice:
Build
Enter the commands provided below.
$ ./autogen.sh \
--prefix=/opt/local \
--enable-debug
$ make
... and I see the following error:
bash: ./autogen.sh: No such file or directory
So, where can I get this file?
I missed the part where you need to download those libraries, but then I found these docs. However, it still wasn't working for me because fuse was not installed on my system. Fortunately, I found another article which explained that process. Now I can successfully pair my phone and mount it, but I only see iOS related folders. Is that normal?

Building Anjay tutorial codes

I'm getting some difficulties on building the tutorial codes of Anjay https://github.com/AVSystem/Anjay. the doc wasn't really helpful.
I tried a simple :
cd examples/tutorial/custom-object
cmake . && make
but I'm getting this message :
By not providing "Findanjay.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "anjay", but
CMake did not find one.
Could not find a package configuration file provided by "anjay" with any of
the following names:
anjayConfig.cmake
anjay-config.cmake
Add the installation prefix of "anjay" to CMAKE_PREFIX_PATH or set
"anjay_DIR" to a directory containing one of the above files. If "anjay"
provides a separate development package or SDK, be sure it has been
installed.
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.10)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
I would appreciate any suggetions.
Thank you.
I was doing the same thing. The error is because you have not installed anjay libraries on your local system or provide a way for CMake to find it.
I installed it by following steps mentioned in compilation docs
In the root of Anjay directory execute the following:
cmake . && make && sudo make install

CMake: Header files cannot be opened

I am working to build a Code Composer Studio project using cmake, which is new to me. It builds successfully under Linux but I am struggling to get it to work under Windows. The cmake command executes without issue, but make fails during the very first C object at the very first #include with the error code
fatal error: could not open source file "stdbool.h" (no directories in search list)
I'm using the libraries included in CCS's compiler (c6000_7.4.15), and that whole folder is included in the CSS project. I include it in cmake as well. In my .cmake file:
set (CCS_ROOT ${CCS_ROOT_V6_WIN} CACHE PATH "code composer install directory")
set(CGT_COMPILER_ROOT ${CCS_ROOT}/tools/compiler/c6000_7.4.15 CACHE INTERNAL "DSP Compiler Root")`
And in the CMakeLists.txt file:
set (COMPILER_INCLUDE ${CGT_COMPILER_ROOT}/include)
INCLUDE_DIRECTORIES ("${COMPILER_INCLUDE}")
Why can the header files not be opened when they're linked in the project and CMake can find them just fine?
EDIT: The directory structure had been changed underneath me, so I took the opportunity to add all of the external files directly into the project to make it completely platform-independent. That way, since the project is managed by our Git repository, users won't have to install the CSL or any other programs to build the project. This also means that paths to libraries and header files will never change between revisions and environments.
Unfortunately, this has not solved my problem. The project continues to build in Linux while failing to ind the very first included header file. I also notice that, under Windows, it cannot find my own header files unless I provide a relative path, e.g. #include "../Common.h" I can get make to find stdbool.h if I provide an absolute path to the compiler directory, but that exposes a web of additional broken links between files.
As a side note, the project builds successfully within Code Composer Studio, so I am assuming that this isn't an issue with my specific Windows environment nor with the code within the project itself.
This seems to be an issue with gcc.exe. I set an environment variable CC to the path of a different compiler (in my case a TI compiler) within my build script and that fixed the problem.

Issue Statically Compiling Thrift 0.9.0 on Centos 6.5

I'm working to compile the Thrift 0.9.0 binary statically in a CentOS VM. I get the issue that the libthrift.a binary is not being created. I am using a vagrant box to run centos:
https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
Once I ssh to the vagrant box I run the following commands:
wget https://archive.apache.org/dist/thrift/0.9.0/thrift-0.9.0.tar.gz
tar -zxvf thrift-0.9.0.tar.gz
cd thrift-0.9.0
./configure --enable-static
make
This will run but I ran a find command (sudo find / -name "*.a") on the system to see if there was any ".a" files made and the only file that was made was "libparse.a" which doesn't seem right. From my understanding it should be "libthrift.a".
Searching through the config.log file it says that it does want to build the static libraries:
configure:11944: checking whether to build static libraries
configure:11948: result: yes
Looking at more locations in the log file that has the keyword "static" reveals potential places that may be errors.
configure:9028: checking if gcc static flag -static works
configure:9056: result: no
configure:13915: checking if g++ static flag -static works
configure:13943: result: no
lt_cv_prog_compiler_static_works=no
lt_cv_prog_compiler_static_works_CXX=no
The full log file is here: http://www.filehosting.org/file/details/449460/staticThriftErrorLog.rtf
Any help is appreciated
I was able to generate the libthrift.a file. After running the command for the extra dependancies mentioned in my comment I forgot to run the make command. So after doing the make command I found the libthrift.a file in "thrift-0.9.0/lib/cpp/.libs/". Interestingly enough, even after fixing the dependencies, config.log still had the same potential problem areas regarding the gcc/g++ static flag and static compiler.
Specifically the dependency command is as follows:
sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel.x86_64
Edit: After getting advice on the Jira ticket, it turns out the specific vagrant box I was using was causing the errors. Using the VM he linked I was able to successfully build Thrift using the provided instructions. (Jira ticket https://issues.apache.org/jira/browse/THRIFT-2559)

Resources