Rust import PAM C functions - rust

I'm trying to figure out how to write a Linux PAM in Rust and I've started with this repo. When I compile it with --features libpam (which enables #[link(name="pam")] that imports external C functions), the compiler complains:
error: linking with `cc` failed: exit status: 1
...
note: /usr/bin/ld: cannot find -lpam: No such file or directory
Looking around SO, I've realized that the pam library was not found to be linked. However, I just cannot figure out how to either install it (I can find many libpam-something packages, but no libpam) or locate it such that I can indicate to the compiler/linker where to find it.
When I look into other crates that also work with PAM, they all import the C functions using #[link(name="pam")], and none specifies how to make it work.
I'm using Ubuntu 22.04.

The necessary headers for PAM library can be installed on Ubuntu as part of libpam0g-dev package (link for jammy):
sudo apt install libpam0g-dev
Debian package has the same name (so sudo apt-get install libpam0g-dev), CentOS uses pam-devel package for that (sudo yum install pam-devel).
Alternatively, on any platform you can use the source code from github and follow the installation instructions from README.

Related

Compiling Rust with pcap in Alma Linux

I'm trying to run a rust program that I've been using on Ubuntu on an AlmaLinux distro.
It utilizes the pcap crate, which is installed.
When I try to compile the application, I'm getting a
/user/bin/ld: cannot find -lpcap
collect2: error: ld returned 1 exit status
My initial thought was that libpcap was not installed on this machine, but in fact, it is. I've uninstalled and reinstalled it just in case there was something wrong with the initial install.
Any ideas on what could be wrong?
You need to install pcap with lib and header, on AlmaLinux this mean devel package. You can use https://pkgs.org/search/?q=pcap to search what packet you need to install, on your case probably https://almalinux.pkgs.org/9/almalinux-crb-x86_64/libpcap-devel-1.10.0-4.el9.i686.rpm.html. This package require you activate CRB repository, see doc https://wiki.almalinux.org/repos/AlmaLinux.html.
dnf config-manager --set-enabled crb
dnf install libpcap-devel

linking to linux shared libraries

I am trying to install opendkim on amazon linux ec2 instance. When compiling from source I get:
configure: error: no strlcpy/strlcat found
so I installed libbsd from source. once that is installed I can go to the man page of strlcat and strlcpy but I can't access those functions. I verified that the shared libraries are installed. The output of the libbsd install stated to use one of the 4 options:
If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
I ran
export LD_RUN_PATH=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib/
Additionally my /etc/ld.so.conf contains
include ld.so.conf.d/*.conf
and my /etc/ld.so.conf.d/libbsd.conf contains
/usr/local/lib/libbsd
Lastly checking my libbsd library nm -D /usr/local/lib/libbsd.so contains:
000000000000de30 T strlcat
000000000000ded0 T strlcpy
So my questions how do I either, expose strlcat and strlcpy to the command line? Or how to I do the "use the `-Wl,-rpath -Wl,LIBDIR' linker flag" option, or in general what am i doing wrong in linking to shared libraries? Any help is appreciated. Thanks!
So wasn't ever able to link against the libraries but I was able to resolve the dependencies. The binary rpm from centos installed perfectly :
sudo wget http://dl.fedoraproject.org/pub/epel/7/x86_64/l/libbsd-0.6.0-3.el7.x86_64.rpm
sudo yum localinstall ./libbsd-0.6.0-3.el7.x86_64.rpm
sudo wget http://dl.fedoraproject.org/pub/epel/7/x86_64/l/libbsd-devel-0.6.0-3.el7.x86_64.rpm
sudo yum localinstall ./libbsd-devel-0.6.0-3.el7.x86_64.rpm

How to compile c++ programs in the new c++ driver provided by Datastax in Linux

I am new to Cassandra. I installed c++ driver from Datastax. Can some one please provide me the steps like in which path I have to create the ā€˜.cā€™ file and how I can compile it. I can see some example programs in example folder. Can anyone plz tell me how to compile the example programs.
The cpp-driver uses cmake and depends on libuv. So the first steps would be to ensure you have cmake installed as well as libuv. Depending on your linux distribution it may be as simple as using package manager like apt or yum (i.e. sudo apt-get install cmake libuv-dev)
Building is just a matter of running the following steps in the cpp-driver directory:
cmake .
make
sudo make install
This will install libcassandra.so to somewhere in your lib path. You can then link by providing '-lcassandra' in your parameters to clang or gcc (i.e. clang myfile.c -o myfile -lcassandra)
There is very comprehensive documentation on building from source here.

Unable to install yesod-bin

I'm updating my yesod framework to the latest yesod 1.2 version. I've installed yesod-platform (painfully....had to manually delete old dependency....cabal hell), now I need to install yesod-bin and it should be done. However, after sudo cabal install yesod-bin I'm getting the following error.
Building yesod-bin-1.2.0...
Preprocessing executable 'yesod-ld-wrapper' for yesod-bin-1.2.0...
[1 of 1] Compiling Main ( ghcwrapper.hs, dist/build/yesod-ld-wrapper/yesod-ld-wrapper-tmp/Main.o )
Linking dist/build/yesod-ld-wrapper/yesod-ld-wrapper ...
/usr/bin/ld: cannot find -lHStar-0.4.0.1
/usr/bin/ld: cannot find -lHSoptparse-applicative-0.5.2.1
/usr/bin/ld: cannot find -lHSghc-paths-0.1.0.9
/usr/bin/ld: cannot find -lHSfsnotify-0.0.6
/usr/bin/ld: cannot find -lHShinotify-0.3.5
collect2: ld returned 1 exit status
Failed to install yesod-bin-1.2.0
cabal: Error: some packages failed to install:
yesod-bin-1.2.0 failed during the building phase. The exception was:
ExitFailure 1
According to this, I feel it may have something to do with privileges I'm not sure.
EDIT: So I only found the following two libraries.
/usr/lib/haskell-packages/ghc/lib/tar-0.3.2.0/ghc-7.4.1/libHStar-0.3.2.0.a
/usr/lib/haskell-packages/ghc/lib/ghc-paths-0.1.0.8/ghc-7.4.1/libHSghc-paths-0.1.0.8.a
I'm trying to update libghc-tar-dev to the newest version 0.4.0.1. However, 0.3.2.0 is the newest version on apt-get what are my options?
First, I'd check to see if you have the libraries libHStar, libHSoptparse-applicative, libHSghc-paths, libHSfsnotify and libHShinotify. If you installed the haskell platform using your distro's package manager, I suspect you'll find those libraries in /usr/local/lib/ghc-*.*.*/. For example, you might search for the first library using this command:
sudo find /usr/local/lib -name 'libHStar*'
If you don't have those libraries, then I think you can get them by using your distro's package manager to install the following:
libghc-tar-dev
libghc-optparse-applicative-dev
libghc-ghc-paths-dev
libghc-fsnotify-dev
libghc-hinotify-dev
If you already have those libraries, then you could adapt the fix suggested in your link:
sudo chmod a+r /usr/local/lib/ghc-*/libHS*
UPDATE:
The standard recommendation seems to be that you should always use your linux distro's package manager to install stuff, rather than using the cabal command directly. And if a package you want isn't available yet on your distro, request it. This approach is the safest, because all of the dependencies have been sorted out for you. The disadvantage is that you won't usually have the latest release. I see that there is a yesod package on Ubuntu. I have no idea if it contains yesod-bin (I'm not familiar with yesod), but if it does, that's the safest approach. The downside is that you will probably have to wipe out your cabal library and start from scratch (re-install haskell-platform, then yesod).
Another option, which seems to be the road you're on, is to use your package manager to install the haskell-platform, but after that use the cabal command to install any haskell-y stuff. You'll still use your package manager to install things that can't be installed using cabal (e.g., non-haskell stuff). If you do this, you can avoid a lot of cabal hell by never running cabal as root, and never letting your package manager do anything that can be done using cabal. The main disadvantage of this approach is that you have to deal with library dependencies yourself, as you've discovered. If you want to continue down this road, you might be able to get everything you need by switching to some development/test build for Ubuntu. Or you may have to get the correct versions of the libraries you need and manually install them.

Building mysql++ libraries for powerpc

I have an embedded application written in C++ (running on a PowerPC in linux environment) which accesses an external database. So my application needs mysql++ libraries which needs to be built using a powerpc compiler. Before building the libraries, I wanted to build mysql++ libraries for linux on my Ubuntu VM to check the procedure. I downloaded the latest package from Official Website. Then I followed the steps mentioned.
Ran ./configure from the root directory, I got the below error.
*checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'*
I tried locate mysqlclient and did not find any references, hence I followed instructions given in other forums and tried to install the libmysqlclient15-dev using the below command.
sudo apt-get install libmysqlclient15-dev
The output is as shown below
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libmysqlclient-dev' instead of 'libmysqlclient15-dev'
libmysqlclient-dev is already the newest version.
The following packages were automatically installed and are no longer required:
libcommons-collections3-java junit4 libecj-java libdb5.1-java libasm3-java libgcj-bc gcj-4.6-jre-lib libgnomeui-common libcommons-el-java
junit linux-headers-3.2.0-32 linux-headers-3.2.0-29 libcommons-compress-java libregexp-java libdb-java libswt-cairo-gtk-3-jni libjasper-java
libbonoboui2-common libbonoboui2-0 libdb5.1-java-gcj libcommons-httpclient-java libservlet2.4-java liblucene2-java libswt-gtk-3-java
libcommons-cli-java libslf4j-java libgcj12 libxml-commons-external-java libswt-webkit-gtk-3-jni linux-headers-3.2.0-29-generic-pae
libswt-gtk-3-jni ant gcj-4.6-base libcommons-logging-java default-jdk libswt-glx-gtk-3-jni libcommons-codec-java jarwrapper
libequinox-osgi-java libgcj-common libapache-pom-java libgnomeui-0 libjetty-java libjline-java libxerces2-java sat4j
libcommons-beanutils-java libdb-je-java fastjar libcommons-digester-java libcommons-parent-java libhamcrest-java libjtidy-java
libxml-commons-resolver1.1-java libicu4j-java linux-headers-3.2.0-32-generic-pae libicu4j-4.4-java libwebkitgtk-1.0-common
libcommons-lang-java libwebkitgtk-1.0-0 libjavascriptcoregtk-1.0-0 libjsch-java ant-optional libswt-gnome-gtk-3-jni
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
After this I tried to locate libmysqlclient and I still couldn't find the libraries (.so files). I tried ./configure again and it failed in the same location with the same error message. How can I install libmysqlclient ?
Once this is solved I will rebuild the mysql++ library using my toolchain for powerpc. Has anyone tried this ? To build mysql++ library I need mysqlclient, in the earlier example I would install it by executing the command apt-get, but the libraries would be compiled using a gnu compiler ? How to cross compile mysqlclient for powerpc ? I guess I need to do the below
Build mysqlclient for powerpc.
Use those libraries and build mysql++ libraries for powerpc.
Use mysql++ and mysqlclient libraries in my application and compile for powerpc.
I am new to linux and databases.
I finally solved this problem. I did the below.
Downloaded the Connector/C (libmysql) source files from here
Cross compiled it for powerpc, below is the command given to cmake
cmake -DCMAKE_INSTALL_PREFIX="~/mysqlclient_C/lib" -DCMAKE_C_COMPILER="ppc_4xx-gcc" -DCMAKE_C_FLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include/" -DCMAKE_CXX_COMPILER="ppc_4xx-g++" -DCMAKE_CXX_FLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include/" -DCMAKE_EXE_LINKER_FLAGS="-lm"
Then a simple make generated the libmysql libraries.
Downloaded mysql++ source files from here
Cross compiled it for powerpc, below is my configure command
./configure --target=powerpc-linux --host=powerpc-linux --prefix="$HOME/mysql++/lib" --enable-thread-check --with-mysql="$HOME/mysqlclient_C/lib" CC=ppc_4xx-gcc CXX=ppc_4xx-g++ LDFLAGS=-lm CFFLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include" CXXFLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include"
The mysql++ libraries is generated now.
I have not tested the built libraries yet.

Resources