google / google-authenticator-libpam

Apache License 2.0
1.77k stars 281 forks source link

compilation error: getopt.h not found on AIX #122

Open stwongst opened 5 years ago

stwongst commented 5 years ago

Hi, I tried to compile it on AIX 7.2 but failed with error during make:

  CC       src/google-authenticator.o
src/google-authenticator.c:25:10: fatal error: getopt.h: No such file or directory
 #include <getopt.h>
          ^~~~~~~~~~
compilation terminated.
make: 1254-004 The error code from the last command is 1.

I tried to add getopt module but not sure if the steps are correct:

./bootstrap.sh
/usr/local/src/gnulib/gnulib-tool --import getopt
/usr/local/src/gnulib/gnulib-tool --add-import getopt
/usr/local/src/gnulib/gnulib-tool --add-import vasprintf
./configure
make

Can only found lib/getopt.in.h but nowhere else.

Would anyone please help? Sorry for the newbie question.

Thanks and rgds

stwongst commented 5 years ago

Can get getopt.h compiled after completing manual configuration steps after running gnulib-tool. However, got other error that err.h is not found even the gnulib error module is imported. Have to comment out err.h and rewrite functions, e.g. replace err with fprintf.

After handling the err.h problem, got _GL_INLINE_HEADER_BEGIN undefined problem:

  CC       src/base32_prog.o
In file included from /opt/freeware/lib/gcc/powerpc-ibm-aix7.2.0.0/8.1.0/include-fixed/fcntl.h:242,
                 from src/base32_prog.c:20:
./lib/unistd.h:627:3: error: #error "Please include config.h first."
  #error "Please include config.h first."
   ^~~~~
./lib/unistd.h:629:1: error: unknown type name '_GL_INLINE_HEADER_BEGIN'
 _GL_INLINE_HEADER_BEGIN
 ^~~~~~~~~~~~~~~~~~~~~~~
./lib/unistd.h:2147:22: error: expected ';' before 'extern'
 _GL_INLINE_HEADER_END
                      ^
                      ;

Checked following line is already in configure.ac but seems didn't help.

AC_CONFIG_HEADER(config.h)

Would anyone please help? Thanks a lot.

ThomasHabets commented 5 years ago

What if you add #include "config.h" as the first include in src/base32_prog.c?

stwongst commented 5 years ago

Yes, get compiled after adding '#include "config.h" to src/base32_prog.c. Thanks for your help.

stwongst commented 5 years ago

I put a line in /etc/pam.conf for testing. `

su auth sufficient pam_allowroot

su auth required pam_google_authenticator.so user=root secret=/var/lib/google-authenticator/${USER} su auth required pam_aix `

Will prompt for entering Verification Code but got segmentation fault.

Repeat the test by removing all arguments in pam.conf, got same result.

su auth required pam_google_authenticator.so

Tried truss on AIX but not much information disclosed:

[snipped] 8847830: 20971843: _sigaction(1, 0x2FF21D18, 0x00000000) = 0 8847830: 20971843: thread_setmymask_fast(0x00000000, 0x00000000, 0x00000000, 0x11400143, 0x00003BE8, 0x00000000, 0x507B4000, 0x00000000) = 0x00000000 8847830: Received signal #11, SIGSEGV [default] 8847830: *** process killed ***

Would anyone please shed some light on steps to compile it on AIX 7.x ? Thanks a lot.

ThomasHabets commented 5 years ago

Looks like it may be the same issue as issue #100.

stwongst commented 5 years ago

Thanks. Seems no solution yet.... Tried to do backtrace and gives following, not much information.

#0  0xd3628fec in vsyslog () from /usr/lib/security/pam_google_authenticator.so
#1  0xd3629b9c in log_message ()
   from /usr/lib/security/pam_google_authenticator.so
#2  0xd362d4a0 in google_authenticator ()
   from /usr/lib/security/pam_google_authenticator.so
#3  0xd200ffac in pam_authenticate () from /usr/lib/libpam.a(shr.o)
warning: (Internal error: pc 0x10002a23 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x10002a23 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x10002a23 in read in psymtab, but not in symtab.)

#4  0x10002a24 in ?? ()
warning: (Internal error: pc 0x100018f7 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x100018f7 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x100018f7 in read in psymtab, but not in symtab.)

#5  0x100018f8 in ?? ()
warning: (Internal error: pc 0x1000016b in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x1000016b in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x1000016b in read in psymtab, but not in symtab.)

#6  0x1000016c in ?? ()
ThomasHabets commented 5 years ago

Copy-paste of comment from #100:

I'm afraid that realistically I don't have time to troubleshoot this, not having access to an AIX system[1]. You could sprinkle some fprintf(stderr, in there, which may help if you know what you're doing.

[1] even with access I'm unlikely to have time at least the next month or two.

stwongst commented 5 years ago

Thanks. After doing some debugging, seems the segmentation fault was caught at vsyslog in pam_google_authenticator.c:

#if !defined(DEMO) && !defined(TESTING)
  openlog(logname, LOG_CONS | LOG_PID, LOG_AUTHPRIV);
  vsyslog(priority, format, args);       <----
  closelog();

Also tried to make up a local vsyslog function and the segmentation fault was caught at vasprintf:

void vsyslog (int facility_priority, const char *format, va_list arglist)
{
        char *msg = NULL;
        vasprintf(&msg, format, arglist);
        if (!msg)
                return;
        syslog(facility_priority, "%s", msg);
        SAFE_FREE(msg);
}

Yet to do more debugging on the vasprintf call from gnulib....

ThomasHabets commented 5 years ago

I'd inspect that format string, see if it's NULL or bad.

stwongst commented 5 years ago

Just have time to re-visit the case. The format string looks good:

Failed to read "%s" for "%s"

Always got segmentation fault when calling "vasprintf(&msg, format, arglist);".

Does anyone has made it on AIX?

Thanks.