c - Compile object file for PAM module with curl -


I am writing a PAM module and I have to make an https request every time a user logs in. I have already applied that the problem with using curls is that as soon as I start curl, my c code is included, the module stops working.

I use the commands given here to compile it:

GCC -FPIC -fno-stack-protector -c mypam.c

Sudo LD-X - SHARE -O / LIB / x86_64-linux-gnu / security / mypam.so mypam.o

It collects without problems but PAM module Is not being interpreted. If I remove the curl part then it works fine (I add lines required to use mypam.so )

I think the problem is that the GCC Along with that I'm not saying that I want to use curls I tried to do gcc -fPIC -fno-stack-protector -c mypam.c -lcurl but it complains :

MyPam.c: function in pam_sm_authenticateĆ¢ ????: mypam.c: 593: 2: error: unknown type name Ć¢ "PRAP" < p> any witch What is happening and ?? If I compile this as a normal program with a main function and use the command: GCC-GGDB-VALVISHER -O FO FU C-Liverapto-LM - Cool This works great.

Code: #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Include & lt; Security / pam_appl.h & gt; # Include & lt; Security / pam_modules.h & gt; # Include & lt; Security / pam_ext.h> # Include & lt; Sys / types.h & gt; # Include & lt; sys / stat.h & gt; # Include & lt; Fcntl.h & gt; # Include & lt; Curl / curl.h & gt; Zero foo (zero) {curl * curl; Curled red; Curl = curl_easy_init (); // if I just keep a printf ("hello!"); This works) / * Expected hook / PAM_EXTERN int pam_sm_setcred (pam_handle_t * pamh, int flags, int argc, const char ** argv) {return PAM_SUCCESS; } PAM_EXTERN int pam_sm_acct_mgmt (pam_handle_t * pamh, int flags, int argc, const char ** argv) {back PAM_SUCCESS; } / * Expected hook, this is where the custom contents are * / PAM_EXTERN int pam_sm_authenticate (pam_handle_t * pamh, int flags, int argc, const char ** argv) {int retval; Const char * pUsername; Retval = pam_get_user (Pum, and PU name, "Username:"); Printf ("Welcome% s \ n", pUsername); foo (); If (retval! = PAM_SUCCESS) {return retval; } Return PAM_AUTHINFO_UNAVAIL; }

As you can see that the code is super easy. If I only work in curls, but if I give any reference to the curl library (as curl * curl; it breaks), what is the solution? Thanks!

Well, you are not linking to libpam for one thing, so there is a problem. Normally I want to test a Palm module deploying and then want to find the symbols which the module expects with dlsym. This is basically what the pam library does when you configure pam.conf, finds the library and gives it dot snaps and looks for the given symbols. So here's a test code that you can run on your compiled palm module.

  #include & lt; Dlfcn.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; int main (int argc, const char * argv []) {if (argc! = 2) {printf ("Usage: .dlopentest & lt; path_to_pam_module»; \ n "); Exit (1); } Void * libhandle = dlopen (argv [1], RTLD_NOW); If (libhandle == NULL) {printf ("% s", dlerror ()); Exit (1); } Zero * sym = dlsym (libhandle, "pam_sm_authenticate"); If (sim == faucet) {printf ("% s", dealer ()); Exit (1); } Sym = dlsym (libhandle, "pam_sm_setcred"); If (sim == tap) {printf ("% s", dealer ()); Exit (1); } Delclose (life); }   

Clearly all pam_sm_ * symbols are not being tested, just take the test of those you expect of your module.

Build and run with it - and then run it on your Palm module sharing object. After you have configured in pam.conf, you should complain about whatever is happening due to your module failure to load. Although it is quite easy, and it can be easily included in a unit test. I would recommend this type of "dlopentest" to any person who is developing serious Palm modules.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -