[OpenAFS-devel] pr_Initialize falis when called within a simple application

John Hayes jhh@envirobat.org
Tue, 17 Aug 2004 11:04:38 -0400 (EDT)


Since first reading this reply I have tried removing references to any
unnecessary libraries and also simplifying my program to the barest
minimum needed.

I was using a list of libraries similar to those listed below. I have
since discovered through trial and error that libdes and libcrypto are
unnecessary to link the test application. From there I developed a script
that is as follows:
jhh@jhh:~/work/projects/afs_support> more build.sh
#!/bin/sh
gcc -c afstest.c -I/usr/local/include
gcc -o afstest afstest.o -L/usr/local/lib/afs  -lafsauthent -lrx -llwp
-lauth -lpthread -lresolv
jhh@jhh:~/work/projects/afs_support>

I believe this reflects the minimum number of libraries necessary to
support the functionality that I want to test.

My test system is a SuSE Linux 9.0 based box.

The test application in it's newest incarnation reads as follows:
#include <afs/stds.h>
#include <afs/ptint.h>
#include <afs/kautils.h>
#include <afs/ptclient.h>
#include <stdio.h>


extern struct ubik_client *pruclient;


main ( int argc, char *argv [] )

{
        char    cellname [ 1024 ] = "msu.edu",
                *Reason = (char *) malloc ( 1024 ),
                *UserName = (char *) malloc ( 1024 ),
                *Password = (char *) malloc ( 1024 ),
                realm [ 1024 ],
                instance [ 1024 ];

        int     retval = 0,
                local = 0;

        afs_int32 password_expires = -1;

        Date LifeTime = 24 * 3600;

        pruclient = NULL;

        strcpy ( UserName, argv [ 1 ] );
        strcpy ( Password, argv [ 2 ] );
        strcpy ( instance, "" );
        strcpy ( realm, cellname );

        retval = ka_Init(0);
        printf ( "R = %d\n", retval );

        if ( ! retval )
        if ( ! retval )
        {
                retval = ka_UserAuthenticateGeneral (                   
KA_USERAUTH_ONLY_VERIFY+KA_USERAUTH_VERSION,
                                                        UserName,
                                                        instance,
                                                        realm,
                                                        Password,
                                                        LifeTime,
                                                        &password_expires,
                                                        0,
                                                        &Reason);

        }

        printf ( "%d, %s\n", retval, Reason );
}

This application has no problem compiling or linking. It even begins to
execute fine but fails with a segfault error in the same place as before.

I have recompiled the libraries with debugger code to identify the place
and iteration in which the error occurs the output from the application
with the debugger messages from the libraries is as follows:
hh@jhh:~/work/projects/afs_support> ./afstest jhh yourpassword test test
R = 0
in rx1
got mem!
in rx2
in rx3
in rx4
leaving rx!
got conn error!
in newTC - calling rxnc
in rx1
got mem!
in rx2
in rx3
in rx4
leaving rx!
returned from calling rxnc
got conn error!
in newTC - calling rxnc
in rx1
got mem!
in rx2
Segmentation fault
jhh@jhh:~/work/projects/afs_support>

The debug output lists "in rx1" 3X before failing, and that after printing
"in rx2"". It never completes the third "in rx3" message before producing
the segfault.

The debugger messages being displayed around the vicinity of the error
take place within the module "rx/rx.c" on line number 758 (that is with
the inclusion of some debug print statements) right here:
printf ( "in rx2\n" );
    RXS_NewConnection(securityObject, conn);    <------
printf ( "in rx3\n" );

Now this line ( RXS_NewConnection(securityObject, conn) ) ) appears to be
a  macro which I haven't tried to make much sense out of yet.

The openafs support utilities such as klog compile against the openafs
libraries that they ship with on my system and run without problems. I am
currently going through the Makefiles to see if there are any extra
switches, flags or conditions that I must use to make this thing work.

Thanks,
John Hayes


> Works fine for me. I compiled it thusly, on Solaris 8
> cc -g -R/usr/local/lib -I/usr/local/include -L/usr/local/lib
> -L/usr/local/lib/afs -o foo foo.c -lprot -lkauth -lauth -lrxkad -lrx
> -llwp -lsys -lcom_err -lubik -ldes -lafsutil -lsocket -lnsl -lcrypto
> -lresolv
>
> Note that I have libdes replaced with a shim, which means I require
> libcrypto
>
> R1 = 0
> R2 = , 0
> R3 = 0, ANDREW.CMU.EDU, 1
> R4 = 0
> R5 = 0, 1
> 0,
>
> On Aug 11, 2004, at 7:33 PM, John Hayes wrote:
>
>>
>> #include <afs/stds.h>
>> #include <afs/ptint.h>
>> #include <afs/kautils.h>
>> #include <afs/ptclient.h>
>> #include <stdio.h>
>>
>>
>> extern struct ubik_client *pruclient;
>>
>>
>> main ( int argc, char *argv [] )
>>
>> {
>>         char    cellname [ 1024 ] = "msu.edu",
>>                 dirpath [ 1024 ] = "/usr/vice/etc",
>>                 *Reason = (char *) malloc ( 1024 ),
>>                 *UserName = (char *) malloc ( 1024 ),
>>                 *Password = (char *) malloc ( 1024 ),
>>                 *lcell,
>>                 lrealm [ 1024 ],
>>                 realm [ 1024 ],
>>                 instance [ 1024 ];
>>
>>         int     retval = 0,
>>                 local;
>>
>> afs_int32 password_expires = -1;
>>
>>         Date LifeTime = 24 * 3600;
>>
>>         pruclient = NULL;
>>
>>         strcpy ( UserName, argv [ 1 ] );
>>         strcpy ( Password, argv [ 2 ] );
>>         strcpy ( instance, "" );
>>
>> retval = ka_Init(0);
>> printf ( "R1 = %d\n", retval );
>> printf ( "R2 = %s, %d\n", lcell, local );
>> retval = ka_CellToRealm (lcell, lrealm, &local);
>> printf ( "R3 = %d, %s, %d\n", retval, lrealm, local );
>> strcpy ( realm, lcell );
>> retval = ka_CellToRealm (realm, realm, &local);
>> printf ( "R4 = %d\n", retval );
>>
>> printf ( "R5 = %d, %d\n", retval, local );
>>
>>         if ( ! retval )
>>         {
>>                 retval = ka_UserAuthenticateGeneral (
>> KA_USERAUTH_ONLY_VERIFY+KA_USERAUTH_VERSION,
>>                                                         UserName,
>>                                                         instance,
>>                                                         realm,
>>                                                         Password,
>>                                                         3600 * 5,
>>
>> &password_expires,
>>                                                         0,
>>                                                         &Reason);
>>
>>         }
>>
>>         pr_End ();
>>
>>         printf ( "%d, %s\n", retval, Reason );
>> }