#include <sia.h>
#include <siad.h>
 
main (argc, argv)
int argc;
char **argv;
{
        int i;
 
        i = sia_auth(getuid());
        printf("result is %d \n", i);
 
}
 
int  sia_auth(uid)
int uid;
{
 
        char	uname[32];
        static	SIAENTITY *entity=NULL;
        static	int oargc = 1;
        static	char *oargv[1] = { "siatest" };
        static	int (*sia_collect)()=sia_collect_trm;
	struct	passwd *pw;
 
	pw = getpwuid(uid);
	if (!pw) {
	    printf("getpwuid failure \n");
	    return 8;
	}
	(void) strcpy(uname, pw->pw_name);
        printf("SIA authentication for uid: %d, uname: %s \n",uid, pw->pw_name);
        if (sia_ses_init(&entity,oargc,oargv,NULL,uname,NULL, \
                                        FALSE, NULL) == SIASUCCESS) {
                printf( "sia_ses_init successful \n");
                entity->authtype = SIA_A_SUAUTH;
		if (sia_make_entity_pwd(pw, entity) == SIASUCCESS) {
		    printf("sia_make_entity_pwd successful \n");
		}
		else {
		    printf("sia_make_entity_pwd un-successful \n");
		}
                if ((sia_ses_launch(NULL, entity)) == SIASUCCESS) {
                        printf( "sia_ses_launch successful \n");
                }
                else {
                        printf( "sia_ses_launch un-successful \n");
			entity = NULL;
                }
                if ((sia_ses_release(&entity)) == SIASUCCESS) {
                        printf( "sia_ses_release successful \n");
                }
                else {
                        printf( "sia_ses_release un-successful \n");
                        return(4);
                }
 
        }
        else {
                printf( "sia_ses_init un-successful \n");
                return(5);
        }
        printf( "sia  **** successful \n");
        return(6);
}


