jpmens / mosquitto-auth-plug

Authentication plugin for Mosquitto with multiple back-ends (MySQL, Redis, CDB, SQLite3)
Other
825 stars 496 forks source link

Compilation Error config.h: No such file or directory #386

Closed RadwanNizam closed 5 years ago

RadwanNizam commented 5 years ago

Hello

I am getting this error when trying to compile the code:

In file included from auth-plug.c:35:0: ..//src/mosquitto_broker.h:20:20: fatal error: config.h: No such file or directory compilation terminated.

: recipe for target 'auth-plug.o' failed make: *** [auth-plug.o] Error 1
jpmens commented 5 years ago

You haven't installed the prerequisite mosquitto package and/or haven't correctly configured config.mk.

RadwanNizam commented 5 years ago

Thank you for the response @jpmens, I will review it again.

gongfan99 commented 5 years ago

@RadwanNizam You have to first (1) download mosquitto source files (2) build it and install it. Note you cannot install mosquitto with "sudo apt-get install mosquitto" and then download the mosquitto source files.

RadwanNizam commented 5 years ago

Actually I am trying to build it using this Docker file, Mosquitto source is downloaded using the following command: wget http://mosquitto.org/files/source/mosquitto-${MOSQUITTO_VERSION}.tar.gz && \

Plugin source is downloaded using the command: git clone git://github.com/jpmens/mosquitto-auth-plug.git && \

However I am still getting the same error:

`CFLAGS: -I..//src/ -I..//lib/ -fPIC -Wall -Werror -DBE_REDIS -DBE_POSTGRES -DBE_HTTP -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include LDFLAGS: -L/usr/local/lib -L..//lib/ LDADD: -lhiredis -L/usr/lib -lpq -lcurl -L/usr/lib -lcrypto -lmosquitto

cc -I..//src/ -I..//lib/ -fPIC -Wall -Werror -DBE_REDIS -DBE_POSTGRES -DBE_HTTP -I/usr/local/include/hiredis -Ipg_config --includedir -I/src -DDEBUG=1 -I/usr/include -c -o auth-plug.o auth-plug.c In file included from auth-plug.c:35:0: ..//src/mosquitto_broker.h:20:20: fatal error: config.h: No such file or directory compilation terminated. make: *** [auth-plug.o] Error 1

: recipe for target 'auth-plug.o' failed `
RadwanNizam commented 5 years ago

@jpmens @gongfan99 Thanks for the support, could you please check these updates :

I fixed this issue by adding the directories of mosquitto source to the build command like the following:

In file included from ../lib/mosquitto_internal.h:20:0, from ../src/mosquitto_broker.h:43, from auth-plug.c:35: auth-plug.c: In function 'mosquitto_auth_plugin_cleanup': ../config.h:28:29: error: implicit declaration of function '_mosquitto_free' [-Werror=implicit-function-declaration] #define uthash_free(ptr,sz) _mosquitto_free(ptr) ` ../src/uthash.h:220:9: note: in expansion of macro 'uthash_free' uthash_free((head)->hh.tbl->buckets, ` ` ../src/uthash.h:271:5: note: in expansion of macro 'HASH_DELETE' HASH_DELETE(hh,head,delptr) auth-plug.c:460:4: note: in expansion of macro 'HASH_DEL' HASH_DEL(ud->aclcache, a); auth-plug.c: In function 'mosquitto_auth_unpwd_check': auth-plug.c:555:56: error: implicit declaration of function 'mosquitto_client_id' [-Werror=implicit-function-declaration] rc = b->getuser(b->conf, username, password, &phash, mosquitto_client_id(client)); auth-plug.c:555:76: error: 'client' undeclared (first use in this function) rc = b->getuser(b->conf, username, password, &phash, mosquitto_client_id(client)); auth-plug.c:555:76: note: each undeclared identifier is reported only once for each function it appears in cc1: all warnings being treated as errors make: *** [auth-plug.o] Error 1

vagiam commented 5 years ago

Hi, I am trying to install plugins for JWT and I am also getting the following Error:

/bin/sh :1: mysql_config auth-plug.c:35:30: fatal error: mosquitto_broker.h: No such file or directory compilation terminated. : recipe for target 'auth-plug.o' failed make: *** [auth-plug.o] Error 1

Nevertheless, mosquitto_broker.h exists (path:home/mqtt/mosquitto/src), while auth-plug.so is not created.

I have followed this tutorial http://www.yasith.me/2016/04/securing-mqtt-connection-using.html and I consider that I configured correctly the config.mk file, setting yes to JWT, MySQL and http.

Any idea/ advice??

Thank you in advance!

gongfan99 commented 5 years ago

@RadwanNizam You should not need to twist anything to make it work. If you exactly follow the the steps below, it will work:

(1) install mosquitto

wget http://mosquitto.org/files/source/mosquitto-1.5.3.tar.gz
tar -xvzf mosquitto-1.5.3.tar.gz
sudo apt-get install build-essential libc-ares-dev uuid-dev libssl-dev openssl libssl-dev libcurl4-openssl-dev
cd mosquitto-1.5.3
make binary
make install

(2) install mosquitto-auth-plug by downloading mosquitto-auth-plug, modifying "config.mk" and run "sudo make" just like what you are doing

The important thing is that the step (1) should not be skipped even if you already have mosquitto installed in your system by "apt-get" or other means. The command "make install" in step (1) will put the files like "config.h" into the correct folder in the system so that it can be found during building the mosquitto-auth-plug.

gongfan99 commented 5 years ago

@vagiam In your "config.mk" file, it should be MOSQUITTO_SRC = /home/USER/mqtt/mosquitto

It should NOT be MOSQUITTO_SRC = /home/USER/mqtt/mosquitto/src

vagiam commented 5 years ago

@gongfan99 thank you for your help!

In my "config.mk" file, it is MOSQUITTO_SRC = /home/USER/mqtt/mosquitto, but it does not work.

Αs far as the 'USER' folder is concerned, should I create it inside Home or does it already exist?

wasd5 commented 5 years ago

I just found out that the latest version seems to have a problem. Older versions are fine. @RadwanNizam @jpmens @vagiam

gongfan99 commented 5 years ago

@vagiam "USER" is just a place holder. You should use your own username. For example, assume the username you used to login Linux is "vagiam" (it could be something else), there must already exist a folder "/home/vagiam". Then if you download the mosquitto source code into the "/home/vagiam" folder, you should set MOSQUITTO_SRC = /home/vagiam/mosquitto

wasd5 commented 5 years ago

@gongfan99 Your comment is actually very precise, and it works well. However, the latest version 0.1.3 itself has a compilation problem, and it doesn't work even if following your guide. Other versions are working fine.

gongfan99 commented 5 years ago

@wasd5 I installed it this Monday and it worked fine. The version I was using is: mosquitto 1.5.3 mosquitto-auth-plug 0.1.3

BTW, I installed them in an Ubuntu machine from AWS EC2

RadwanNizam commented 5 years ago

@gongfan99 Thanks for the answer. I tried using the version 1.5.2 and the compilation issue is fixed now. The version 1.4.10 did not work for me.

rlamp commented 5 years ago

I have been having the same problems with mosquitto-auth-plug v0.1.3 and mosquitto v1.4.15.

First error:

In file included from auth-plug.c:35:0:
/usr/local/mosquitto-1.4.15/src/mosquitto_broker.h:20:20: fatal error: config.h: No such file or directory
 #include <config.h>

This can be solved by copying mosquitto-1.4.15/config.h to mosquitto-1.4.15/src/config.h or using mosquitto-1.4.15/ in build path.

Then second error:

In file included from /usr/local/mosquitto-1.4.15/src/mosquitto_broker.h:47:0,
                 from auth-plug.c:35:
auth-plug.c: In function ‘mosquitto_auth_plugin_cleanup’:
/usr/local/mosquitto-1.4.15/src/uthash.h:218:12: error: implicit declaration of function ‘_mosquitto_free’
     struct UT_hash_handle *_hd_hh_del;                                           \
            ^
/usr/local/mosquitto-1.4.15/src/uthash.h:271:5: note: in expansion of macro ‘HASH_DELETE’
     HASH_DELETE(hh,head,delptr)
     ^
auth-plug.c:460:4: note: in expansion of macro ‘HASH_DEL’
    HASH_DEL(ud->aclcache, a);

In the end I used mosquitto-auth-plug v0.1.2 with mosquitto v1.4.15. (As others have said mosquitto-auth-plug v0.1.3 + mosquitto v1.5.x also works.) Conclusion, mosquitto-auth-plug >= v0.1.3 does not work with mosquitto < v1.5.

jpmens commented 5 years ago

For the record, I am not particularly interested in supporting earlier Mosquitto versions.

facetime88 commented 5 years ago

Same here. I am in debian. Mosquitto installed version 1.5.5. It said: auth-plug.c:35:30: fatal error: mosquitto_broker.h: No such file or directory. The mosquitto source has been set correctly.

suniastar commented 5 years ago

@RadwanNizam Just FYI. I managed to build everything in docker with the mysql backend.

Dockerfile

FROM debian:latest

# set environment variables
LABEL maintainer="frederik.enste@gmail.com"
ENV MOSQUITTO_VERSION 1.5.5
ENV AUTH_VERSION 0.1.3

# install dependencies and get source code and prepare /etc dir
RUN apt-get update \
 && apt-get install --no-install-recommends --no-install-suggests --yes \
        axel \
        git \
        ca-certificates \
        build-essential \
        libc-ares-dev \
        uuid-dev \
        libwebsockets-dev \
        libmariadbclient-dev \
        libssl-dev \
        xsltproc \
        docbook-xsl \
 && rm -rfv /var/lib/apt/lists/* \
 && axel -o mosquitto-src.tar.gz https://github.com/eclipse/mosquitto/archive/v${MOSQUITTO_VERSION}.tar.gz \
 && axel -o mosquitto-auth-plug.tar.gz https://github.com/jpmens/mosquitto-auth-plug/archive/${AUTH_VERSION}.tar.gz \
 && tar -xvzf mosquitto-src.tar.gz \
 && tar -xvzf mosquitto-auth-plug.tar.gz \
 && rm -v mosquitto-src.tar.gz \
 && rm -v mosquitto-auth-plug.tar.gz \
 && mv -v mosquitto-${MOSQUITTO_VERSION} mosquitto \
 && mv -v mosquitto-auth-plug-${AUTH_VERSION} auth \
 && mkdir -p /etc/mosquitto

# build mosquitto
WORKDIR /mosquitto
RUN make WITH_SRV=yes WITH_UUID=no WITH_WEBSOCKETS=yes WITH_TLS=yes WITH_DOCS=yes \
 && make install

# install mosquitto library files
WORKDIR /usr/lib/x86_64-linux-gnu/
RUN ln -s -v ./../../../mosquitto/lib/libmosquitto.so.1 ./

# copy auth build config
COPY config.mk /auth/config.mk

# build auth plugin
WORKDIR /auth
RUN make 

# config default program
WORKDIR /
CMD ["/usr/local/sbin/mosquitto", "-c", "/etc/mosquitto/mosquitto.conf"]

config.mk

# Select your backends from this list
BACKEND_CDB ?= no
BACKEND_MYSQL ?= yes
BACKEND_SQLITE ?= no
BACKEND_REDIS ?= no
BACKEND_POSTGRES ?= no
BACKEND_LDAP ?= no
BACKEND_HTTP ?= no
BACKEND_JWT ?= no
BACKEND_MONGO ?= no
BACKEND_FILES ?= no
BACKEND_MEMCACHED ?= no

# Specify the path to the Mosquitto sources here
# MOSQUITTO_SRC = /usr/local/Cellar/mosquitto/1.4.12
MOSQUITTO_SRC = /mosquitto

# Specify the path the OpenSSL here
OPENSSLDIR =

# Add support for django hashers algorithm name
SUPPORT_DJANGO_HASHERS ?= no

# Specify optional/additional linker/compiler flags here
# On macOS, add
#   CFG_LDFLAGS = -undefined dynamic_lookup
# as described in https://github.com/eclipse/mosquitto/issues/244
#
# CFG_LDFLAGS = -undefined dynamic_lookup  -L/usr/local/Cellar/openssl/1.0.2l/lib
# CFG_CFLAGS = -I/usr/local/Cellar/openssl/1.0.2l/include -I/usr/local/Cellar/mosquitto/1.4.12/include
CFG_LDFLAGS =
CFG_CFLAGS = -I/usr/include/mysql

Don know if the CFG_CFLAGS are acutally needed but they dont break the compilation.

RadwanNizam commented 5 years ago

@t00manysecretss It works for me too. Actually, you may get the compilation error when using earlier versions.