PAM-Linux in FPC lazarus / 32-Linux ---------------------------------------------------------------------- RedCat · 2022-02-19 05:51 Hi all! I needed to use PAM-Linux in my project, does the FPC have ported header files (pam_appl, pam_client, etc.). I tried first to find these files, but I couldn't, then I tried to translate it myself, but there are a few things I don't understand. All I need from PAM is to verify that the username and password are entered correctly. ---------------------------------------------------------------------- Thaddy · 2022-02-19 10:48 They are really plain C header files, so can be 99% translated with h2pas and h2paspp. Just make sure the calling conventions are correct. ---------------------------------------------------------------------- RedCat · 2022-02-19 11:40 h2pas produces several syntax errors, h2paspp translates almost nothing, and I can't translate this structure by hand: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typedef struct pam_handle pam_handle_t;the problem is that the pam_handle description is in the pam_private.h file, which is not in the libpam0g-dev package, and the structure has a comment: Quote/* This is a blind structure; users aren't allowed to see inside a   * pam_handle_t, so we don't define struct pam_handle here. This is   * defined in a file private to the PAM library. (i.e., it's private   * to PAM service modules, too!) */ but if I translate this structure like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typepam_handle_t = pam_handle; the compiler will give an error saying that it doesn't know anything about pam_handle ---------------------------------------------------------------------- Thaddy · 2022-02-19 11:46 FPC supports such opaque data in system: https://www.freepascal.org/docs-html/rtl/system/topaquedata.html May be you need to tweak some settings in the headers, but AFICS there is not really a problem. ---------------------------------------------------------------------- RedCat · 2022-02-19 11:50 Thanks I'll try it now ---------------------------------------------------------------------- MarkMLl · 2022-02-19 12:14 Let us know how you get on, since header conversion- and making sure that extra libraries work- is of universal interest. MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-19 13:14 I tried to translate so far only the main functions I need, it turned out badly, I have very superficial knowledge of C syntax, I did this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit pam_types;{$IFDEF FPC}  {$mode objfpc}{$H+}{$ENDIF} interface  uses  Classes, SysUtils; const  {$IFDEF FPC}    {$IFDEF LINUX}      libPAM = 'libpam.so';    {$ENDIF}   {$ENDIF}typepam_handle_t=recordend; type  pam_message = record      msg_style : long      msg : ^char;    end; type  pam_response = record      resp : ^char;      resp_retcode : longint;    end; typeppam_message = ^pam_message;ppam_response = ^pam_response;pppam_message = ^ppam_message;ppam_response = ^ppam_response;    typepam_conv_t = record          conv : function (num_msg:longint; msg:PPpam_message; resp:PPpam_response; appdata_ptr:pointer):longint;cdecl;          appdata_ptr : pointer;      end; typeppam_handle_t = ^pam_handle_t;PPpam_handle_t = ^Ppam_handle_t;   typeppam_conv = pam_conv_t; function pam_start(const service_name : PByte; const user : PByte; const pam_conversation : Ppam_conv; pamh : PPpam_handle_t):integer; cdecl; external libPAM;function pam_end(pamh : PPpam_handle_t;pam_status:integer):integer; cdecl; external libPAM;implementationend. I call like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i varres:inte ger;pam_hannn:Ppam_handle_t; pam_cconv:pam_conv_t;beginres:=pam_start( Pbyte(PChar('check')),Pbyte(Pchar('redcat')),pam_cconv,@pam_hannn);Mem o1.Lines.Add(IntToStr(res));end; and received in response when the application was launched External: SIGSEGV (Accesss violation) ---------------------------------------------------------------------- MarkMLl · 2022-02-19 13:32 Use h2pas, as somebody has said already. That will result in a separate file into which the command line will be embedded so that people can duplicate what you're doing. https://www.freepascal.org/tools/h2pas.html https://wiki.freepascal.org/H2Pas https://wiki.freepascal.org/Creating_bindings_for_C_libraries https://wiki.freepascal.org/Common_problems_when_converting_C_header_f iles MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-19 13:55 Maybe I'm doing something wrong, but the pam_appl.h h2pas file does not want to translate at all, this is how the original file looks like: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /* *  * * This header file collects definitions for the PAM API --- that is, * public interface between the PAM library and an application program * that wishes to use it. * * Note, the copyright information is at end of file. */ #ifndef _SECURITY_PAM_APPL_H#define _SECURITY_PAM_APPL_H #ifdef __cplusplusextern "C" {#endif #include      /* Linux-PAM common defined types */ /* -------------- The Linux-PAM Framework layer API ------------- */ extern int PAM_NONNULL((1,3,4))pam_start(const char *service_name, const char *user,          const struct pam_conv *pam_conversation,          pam_handle_t **pamh); extern int PAM_NONNULL((1))pam_end(pam_handle_t *pamh, int pam_status); /* Authentication API's */ extern int PAM_NONNULL((1))pam_authenticate(pam_handle_t *pamh, int flags); extern int PAM_NONNULL((1))pam_setcred(pam_handle_t *pamh, int flags); /* Account Management API's */ extern int PAM_NONNULL((1))pam_acct_mgmt(pam_handle_t *pamh, int flags); /* Session Management API's */ extern int PAM_NONNULL((1))pam_open_session(pam_handle_t *pamh, int flags); extern int PAM_NONNULL((1))pam_close_session(pam_handle_t *pamh, int flags); /* Password Management API's */ extern int PAM_NONNULL((1))pam_chauthtok(pam_handle_t *pamh, int flags);  /* take care of any compatibility issues */#include  #ifdef __cplusplus}#endif /* * Copyright Theodore Ts'o, 1996.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, and the entire permission notice in its entirety, *    including the disclaimer of warranties. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote *    products derived from this software without specific prior *    written permission. * * ALTERNATIVELY, this product may be distributed under the terms of * the GNU Public License, in which case the provisions of the GPL are * required INSTEAD OF the above restrictions.  (This clause is * necessary due to a potential bad interaction between the GPL and * the restrictions contained in a BSD-style copyright.) * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #endif /* _SECURITY_PAM_APPL_H */ and after processing h2pas: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit pam_appl;interface {  Automatically converted by H2Pas 1.0.0 from D:\Projects\Lazarus\RTS_Configurator\LibPAM\pam_appl.h  The following command line parameters were used:    D:\Projects\Lazarus\RTS_Configurator\LibPAM\pam_appl.h} {$IFDEF FPC}{$PACKRECORDS C}{$ENDIF}    {   *    *   * This header file collects definitions for the PAM API --- that is,   * public interface between the PAM library and an application program   * that wishes to use it.   *   * Note, the copyright information is at end of file.    }{$ifndef _SECURITY_PAM_APPL_H}{$define _SECURITY_PAM_APPL_H}  { C++ extern C conditionnal removed }{$include      /* Linux-PAM common defined types */}  { -------------- The Linux-PAM Framework layer API -------------  }(* error extern int PAM_NONNULL((1,3,4))(* error extern int PAM_NONNULL((1,3,4))(* error extern int PAM_NONNULL((1,3,4))(* error pam_start(const char *service_name, const char *user,(* error         const struct pam_conv *pam_conversation,(* error           pam_handle_t **pamh); in declarator_list *) in declarator_list *) in declarator_list *) in declarator_list *) in declarator_list *) in declarator_list *)(* error extern int PAM_NONNULL((1))(* error pam_end(pam_handle_t *pamh, int pam_status); in declarator_list *) in declarator_list *)  { Authentication API's  }(* error extern int PAM_NONNULL((1))(* error pam_authenticate(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)(* error extern int PAM_NONNULL((1))(* error pam_setcred(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)  { Account Management API's  }(* error extern int PAM_NONNULL((1))(* error pam_acct_mgmt(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)  { Session Management API's  }(* error extern int PAM_NONNULL((1))(* error pam_open_session(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)(* error extern int PAM_NONNULL((1))(* error pam_close_session(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)  { Password Management API's  }(* error extern int PAM_NONNULL((1))(* error pam_chauthtok(pam_handle_t *pamh, int flags); in declarator_list *) in declarator_list *)  { take care of any compatibility issues  }{$include }{ C++ end of extern C conditionnal removed }  {   * Copyright Theodore Ts'o, 1996.  All rights reserved.   *   * Redistribution and use in source and binary forms, with or without   * modification, are permitted provided that the following conditions   * are met:   * 1. Redistributions of source code must retain the above copyright   *    notice, and the entire permission notice in its entirety,   *    including the disclaimer of warranties.   * 2. Redistributions in binary form must reproduce the above copyright   *    notice, this list of conditions and the following disclaimer in the   *    documentation and/or other materials provided with the distribution.   * 3. The name of the author may not be used to endorse or promote   *    products derived from this software without specific prior   *    written permission.   *   * ALTERNATIVELY, this product may be distributed under the terms of   * the GNU Public License, in which case the provisions of the GPL are   * required INSTEAD OF the above restrictions.  (This clause is   * necessary due to a potential bad interaction between the GPL and   * the restrictions contained in a BSD-style copyright.)   *   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE   * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED   * OF THE POSSIBILITY OF SUCH DAMAGE.    }{$endif}  { _SECURITY_PAM_APPL_H  } implementation  end. ---------------------------------------------------------------------- RedCat · 2022-02-19 14:05 And if you run from the IDE, lazarus first freezes, and then gives an error: QuoteTRegExpr exec: empty input string ---------------------------------------------------------------------- MarkMLl · 2022-02-19 14:14 Quote from: RedCat on February 19, 2022, 02:55:21 pmMaybe I'm doing something wrong, but the pam_appl.h h2pas file does not want to translate at all, this is how the original file looks like: OK, I'm not the local expert but I'm here while the other guys have hopefully got more fun things to do :-) First, pam_appl.h isn't on my (Debian x86_64) system: where did you get it? MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-19 14:19 There is a contact! The error was that I declared one of the parameters type ppam_conv = pam_conv_t; And should have type ppam_conv = ^pam_conv_t; Now there is no Access Violation and there is a return code from LibPAM Code 4 is:   { system error }      PAM_SYSTEM_ERR = 4; ---------------------------------------------------------------------- RedCat · 2022-02-19 14:41 Have code 0 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit pam_types;{$IFDEF FPC}  {$mode objfpc}{$H+}{$ENDIF} interface  uses  Classes, SysUtils; const  {$IFDEF FPC}    {$IFDEF LINUX}      libPAM = 'libpam.so';    {$ENDIF}   {$ENDIF} const  {$IFDEF FPC}    {$IFDEF LINUX}      libPAM_misc = 'libpam_misc.so';    {$ENDIF}   {$ENDIF}  const    __LINUX_PAM__ = 1;    __LINUX_PAM_MINOR__ = 0;  { ----------------- The Linux-PAM return values ------------------  }  { Successful function return  }    PAM_SUCCESS = 0;  { dlopen() failure when dynamically  }    PAM_OPEN_ERR = 1;  { loading a service module  }  { Symbol not found  }    PAM_SYMBOL_ERR = 2;  { Error in service module  }    PAM_SERVICE_ERR = 3;  { System error  }    PAM_SYSTEM_ERR = 4;  { Memory buffer error  }    PAM_BUF_ERR = 5;  { Permission denied  }    PAM_PERM_DENIED = 6;  { Authentication failure  }    PAM_AUTH_ERR = 7;  { Can not access authentication data  }    PAM_CRED_INSUFFICIENT = 8;  { due to insufficient credentials  }  { Underlying authentication service  }    PAM_AUTHINFO_UNAVAIL = 9;  { can not retrieve authentication  }  { information   }  { User not known to the underlying  }    PAM_USER_UNKNOWN = 10;  { authenticaiton module  }  { An authentication service has  }    PAM_MAXTRIES = 11;  { maintained a retry count which has  }  { been reached.  No further retries  }  { should be attempted  }  { New authentication token required.  }    PAM_NEW_AUTHTOK_REQD = 12;  { This is normally returned if the  }  { machine security policies require  }  { that the password should be changed  }  { beccause the password is NULL or it  }  { has aged  }  { User account has expired  }    PAM_ACCT_EXPIRED = 13;  { Can not make/remove an entry for  }    PAM_SESSION_ERR = 14;  { the specified session  }  { Underlying authentication service  }    PAM_CRED_UNAVAIL = 15;  { can not retrieve user credentials  }  { unavailable  }  { User credentials expired  }    PAM_CRED_EXPIRED = 16;  { Failure setting user credentials  }    PAM_CRED_ERR = 17;  { No module specific data is present  }    PAM_NO_MODULE_DATA = 18;  { Conversation error  }    PAM_CONV_ERR = 19;  { Authentication token manipulation error  }    PAM_AUTHTOK_ERR = 20;  { Authentication information  }    PAM_AUTHTOK_RECOVERY_ERR = 21;  { cannot be recovered  }  { Authentication token lock busy  }    PAM_AUTHTOK_LOCK_BUSY = 22;  { Authentication token aging disabled  }    PAM_AUTHTOK_DISABLE_AGING = 23;  { Preliminary check by password service  }    PAM_TRY_AGAIN = 24;  { Ignore underlying account module  }    PAM_IGNORE = 25;  { regardless of whether the control  }  { flag is required, optional, or sufficient  }  { Critical error (?module fail now request)  }    PAM_ABORT = 26;  { user's authentication token has expired  }    PAM_AUTHTOK_EXPIRED = 27;  { module is not known  }    PAM_MODULE_UNKNOWN = 28;  { Bad item passed to pam_*_item()  }    PAM_BAD_ITEM = 29;  { conversation function is event driven                                   and data is not available yet  }    PAM_CONV_AGAIN = 30;  { please call this function again to                                 complete authentication stack. Before                                 calling again, verify that conversation                                 is completed  }    PAM_INCOMPLETE = 31;  {   * Add new #define's here - take care to also extend the libpam code:   * pam_strerror() and "libpam/pam_tokens.h" .    }  { this is the number of return values  }    _PAM_RETURN_VALUES = 32;  { ---------------------- The Linux-PAM flags --------------------  }  { Authentication service should not generate any messages  }    PAM_SILENT = $8000;  { Note: these flags are used by pam_authenticate,_secondary()  }  { The authentication service should return PAM_AUTH_ERROR if the   * user has a null authentication token  }    PAM_DISALLOW_NULL_AUTHTOK = $0001;  { Note: these flags are used for pam_setcred()  }  { Set user credentials for an authentication service  }    PAM_ESTABLISH_CRED = $0002;  { Delete user credentials associated with an authentication service  }    PAM_DELETE_CRED = $0004;  { Reinitialize user credentials  }    PAM_REINITIALIZE_CRED = $0008;  { Extend lifetime of user credentials  }    PAM_REFRESH_CRED = $0010;  { Note: these flags are used by pam_chauthtok  }  { The password service should only update those passwords that have   * aged.  If this flag is not passed, the password service should   * update all passwords.  }    PAM_CHANGE_EXPIRED_AUTHTOK = $0020;  { ------------------ The Linux-PAM item types -------------------  }  { These defines are used by pam_set_item() and pam_get_item().     Please check the spec which are allowed for use by applications     and which are only allowed for use by modules.  }  { The service name  }    PAM_SERVICE = 1;  { The user name  }    PAM_USER = 2;  { The tty name  }    PAM_TTY = 3;  { The remote host name  }    PAM_RHOST = 4;  { The pam_conv structure  }    PAM_CONV = 5;  { The authentication token (password)  }    PAM_AUTHTOK = 6;  { The old authentication token  }    PAM_OLDAUTHTOK = 7;  { The remote user name  }    PAM_RUSER = 8;  { the prompt for getting a username  }    PAM_USER_PROMPT = 9;  { Linux-PAM extensions  }  { app supplied function to override failure                                   delays  }    PAM_FAIL_DELAY = 10;  { X display name  }    PAM_XDISPLAY = 11;  { X server authentication data  }    PAM_XAUTHDATA = 12;  { The type for pam_get_authtok  }    PAM_AUTHTOK_TYPE = 13; typepam_handle_t=recordend; type  pam_message = record      msg_style : longint;      msg : ^char;    end; type  pam_response = record      resp : ^char;      resp_retcode : longint;    end; typePpam_message  = ^pam_message;Ppam_response  = ^pam_response;PPpam_message  = ^Ppam_message;PPpam_response  = ^Ppam_response;    typepam_conv_t = record          conv : function (num_msg:longint; msg:PPpam_message; resp:PPpam_response; appdata_ptr:pointer):longint;cdecl;          appdata_ptr : pointer;      end; typePpam_handle_t = ^pam_handle_t;PPpam_handle_t = ^Ppam_handle_t;   typePpam_conv = ^pam_conv_t; function pam_start(const service_name : PByte; const user : PByte; const pam_conversation : Ppam_conv; pamh : PPpam_handle_t):integer; cdecl; external libPAM;function pam_end(pamh : PPpam_handle_t;pam_status:integer):integer; cdecl; external libPAM;function misc_conv(num_msg:longint; msg:PPpam_message; resp:PPpam_response; appdata_ptr:pointer):longint; cdecl; external libPAM_misc; implementationend. I call like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);varres:integer;pam_hannn:Ppam_han dle_t;TestConv:pam_conv_t;beginTestConv.conv:=@misc_conv;TestConv.appd ata_ptr:=nil;res:=pam_start(Pbyte(PChar('check')),Pbyte(Pchar('redcat' )),@TestConv,@pam_hannn);Memo1.Lines.Add(IntToStr(res));end; end. As functions are added, I will post pam_types.pas here ---------------------------------------------------------------------- RedCat · 2022-02-20 04:33 The first version of the translation of titles (Some functions have not been tested, and some have not yet been translated). There is also a console application for testing authentication, but until the problem of redirecting the output of the password request by the library to its application has been resolved, this prevents the library from being used in the GUI application https://github.com/RedCatN1/LibPAM_Pascal-headers ---------------------------------------------------------------------- MarkMLl · 2022-02-20 08:39 Quote from: RedCat on February 20, 2022, 05:33:18 amuntil the problem of redirecting the output of the password request by the library to its application has been resolved, this prevents the library from being used in the GUI application That's likely to be a problem. Research the way that e.g. Subversion does it: IIRC there's a daemon involved which pops up a dialog(u)e. I've previously looked at this to some extent in the context of getting the IDE to set POSIX capabilities etc. post-compilation. I can't remember the details, the patch is somewhere in whatever's taken over from Mantis. MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-20 09:55 There is an easier way to write my own conversion implementation, I'm trying now, I'm confused about pointers, who knows C well please help me, I do this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function conversation(num_msg:longint; msg:PPpam_message; resp:PPpam_response; appdata_ptr:pointer):longint;cdecl;vari:longint;passstr:string;m:ppam_ message;r:ppam_response;begin    appdata_ptr:=nil;    { check the count of message }    if (num_msg <= 0 ) or (num_msg >= PAM_MAX_MSG_SIZE) then    begin        writeln('invalid num_msg '+inttostr(num_msg));        result:=PAM_CONV_ERR;    end;    { alloc memory for response }    r:=CAlloc(num_msg,SizeOf(pam_response));    if r=nil then    begin      writeln('bad alloc ');      result:=PAM_BUF_ERR;    end;    { response for message }    for i:= 0 to num_msg-1 do    Begin        m:=msg[i];      if m^.msg_style = PAM_PROMPT_ECHO_OFF then          begin             writeln('MyMessage: '+Pchar(m^.msg));            readln(passstr);          r^.resp:=Pchar(passstr);            r^.resp_retcode:= 0;          resp:=@r[i];            break;         end;    end;    result:=PAM_SUCCESS;end; And so it is done in the example to the source codes of LibPAM: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i static int conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr){    (void)(appdata_ptr);    int i;     /* check the count of message */    if (num_msg <= 0 || num_msg >= PAM_MAX_MSG_SIZE)    {        fprintf(stderr, "invalid num_msg(%d)\n", num_msg);        return PAM_CONV_ERR;    }     /* alloc memory for response */    if ((resp[0] = malloc(num_msg * sizeof(struct pam_response))) == NULL)    {        fprintf(stderr, "bad alloc\n");        return PAM_BUF_ERR;    }     /* response for message */    for (i = 0; i < num_msg; i++)    {        const struct pam_message *m = *msg + i;        struct pam_response *r = *resp + i;        r->resp_retcode = 0;    /* currently un-used, zero expected */      switch (m->msg_style)        {        case PAM_PROMPT_ECHO_OFF: /* get the input with echo off, like the password */            printf("%s", m->msg);            echoOffStdin();            r->resp = readline();            echoOnStdin();            printf("\n");          break;         case PAM_PROMPT_ECHO_ON:    /* get the input with echo on, like the username */            printf("%s", m->msg);          r->resp = readline();            break;         case PAM_TEXT_INFO:         /* normal info */            printf("%s\n", m->msg);          break;         case PAM_ERROR_MSG:         /* error info */          fprintf(stderr, "%s\n", m->msg);            break;         default:          fprintf(stderr, "unexpected msg_style: %d\n", m->msg_style);            break;        }    }    return PAM_SUCCESS;} I get Access Violation, or with other parameters error free unknown pointer, or else malloc corrupted top size , and with this code, the authorization function returns code 7 just a few pointers to pointers completely confused me ---------------------------------------------------------------------- RedCat · 2022-02-20 10:43 I especially don't understand these lines: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i resp[0] = malloc(num_msg * sizeof(struct pam_response)) here it is not clear to me whether resp[0] is the same as resp[0] in FPC? If struct pam_response **resp and in fpc resp:PPpam_response? Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i          const struct pam_message *m = *msg + i;         struct pam_response *r = *resp + i;  And here, too, it is not entirely clear how the assignment is obtained ---------------------------------------------------------------------- MarkMLl · 2022-02-20 11:40 You've still not said what package etc. you got the original files from. The first of those will depend on how you're defining the resp[] array, but if I'm reading your example properly malloc() is allocating a block of memory sufficient for the size of a response multiplied by the number of responses and saving a pointer to the start (remember the array/pointer duality in C). I the second I /think/ the addition is incrementing by the size of the message or response, i.e. is stepping on to the next element in the array. MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-20 12:28 Source files taken from here: https://github.com/linux-pam Do I understand correctly that resp[0] = malloc(num_msg * sizeof(struct pam_response)) is the same as resp[0]:= GetMem(num_msg * sizeof(pam_response)) in fpc? And what about the assignment of r to resp? and is it possible to directly specify resp[0]^^. resp := Phar(pass ) I have a feeling that there is a confusion with addresses, since resp:PPpam_response and the library reads the wrong thing, and I can’t find out in any way what is really transferred to LibPAM with this callback ---------------------------------------------------------------------- MarkMLl · 2022-02-20 13:09 No promises but I'll try to take a bit of a look later... particularly if the I2C stuff I'm playing with continues in its intransigence. Note however that I'm not the most experienced guy around at doing this, so trust almost anybody else's advice before mine :-) I've seen where your h2pas commandline is noted. Have you checked that the C variant of that project actually compiles and runs successfully on your system? I've seen plenty of other projects where Github etc. contained sources which didn't quite match the kernel and standard libraries that the rest of the World assumed were "stable". MarkMLl ---------------------------------------------------------------------- RedCat · 2022-02-20 14:35 No, to be honest, I have not tried to collect these sources, but what has already been translated without my implementation of the conversion function works fine, (meaning with the conversion function from the pam_misc.so library) I understand that the problem is in pointers and arrays, I know very little and I don’t know English well, and as luck would have it, I didn’t find a description of my problem in my language, for some reason I found a description in English. description in attached As far as I understand, I'm trying to work with a pointer to an array of pointers ---------------------------------------------------------------------- RedCat · 2022-02-22 12:34 Updated header file and test project, now has its own function CatConversion for transferring login and password to LibPAM https://github.com/RedCatN1/LibPAM_Pascal-headers