Peter,

Here's some code I had laying around my source directory.  As it
shows, the "setpag()" call is unnecessary if you pass the DOSETPAG
option to the UserAuthenticate routine.  Enjoy!

Joe Jackson,
AFS Product Support,
Transarc Corp.

_____________________Makefile_____________________

PROGRAMS=test_afs_login test_getservbyname

# AFSDIR = /afs/transarc.com/product/afs/3.1b/@sys
AFSDIR = /afs/transarc.com/product/afs/3.1b/@sys
AFSLIBDIR = $(AFSDIR)/lib
AFSLIBS = -L$(AFSLIBDIR) -L$(AFSLIBDIR)/afs  -lkauth -lprot -lubik \
                -lauth -lrxkad -lsys -ldes -lrx -llwp -lcom_err \
                $(AFSLIBDIR)/afs/util.a
INCLUDES = -I$(AFSDIR)/include

LDFLAGS = $(AFSLIBS)
CFLAGS = $(INCLUDES) -g -D_NO_PROTO

all: $(PROGRAMS)

test_getservbyname: test_getservbyname.c
        $(CC) -g [email protected] -o $@

.c: ; $(CC) $(CFLAGS) [email protected] $(LDFLAGS) -o $@

_____________________test_afs_login.c_____________________

#include <afs/kautils.h>
  
  struct greet_info {
    char          *name;        /* user name */
    char          *password;     /* user password */
    char          *string;       /* random string */
  };

int try_to_login();

main(argc, argv)
     int argc;
     char **argv;
{
  int code;
  struct greet_info test_greet;
  static char name[128], password[128];
  
  memset(name,NULL,sizeof(name));
  memset(password,NULL,sizeof(password));
  
  printf("Enter AFS User Name: ");
  if( !gets(name) ){
    printf("Unable to grab name from stdin\n");
    perror("Error message returned");
    exit(1);
  }
  printf("Enter Password: ");
  if ( !gets(password) ){
    printf("Unable to grab password from stdin\n");
    perror("Error message returned");
    exit(1);
  }
  
  test_greet.name = name;
  test_greet.password = password;
  
  code = try_to_login(&test_greet);
  
  system ("/usr/ucb/groups;/usr/afsws/bin/tokens");

  return code;
}

int try_to_login (test_g)
     struct greet_info *test_g;
{
  
  int code;
  char *reason;
  
  printf("\nName: %s\nPassword: %s\n", test_g->name, test_g->password);
  
  code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION+KA_USERAUTH_DOSETPAG,
                                    test_g->name,
                                    (char *) 0,  /* instance */
                                    (char *) 0,  /* realm */
                                    test_g->password,
                                    0,           /* lifetime, default */
                                    0, 0,        /* spares */
                                    &reason);
  
  if (code != 0)
    printf("AFS Verify failed because %s\n", reason);
  else
    printf("Verify succeeded\n");
  
  return code;
}

Reply via email to