

/*
 * for testing the server authentication
 */

main ()
{
  struct sockaddr_in saddr;
  int slen = sizeof(saddr);
  int fd, nfd;
  char prin[ANAME_SZ];
  char inst[INST_SZ];
  char realm[REALM_SZ];
  int on = 1;

#ifdef ultrix
  openlog ("sauth", 0);
#else
  openlog ("sauth", 0, LOG_LOCAL4);
#endif
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(PORT_NUMBER);
  saddr.sin_addr.s_addr = 0;
  fd = socket(AF_INET, SOCK_STREAM, 0);
  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
  if (bind (fd, &saddr, sizeof(saddr))) {
    perror ("bind");
    exit(1);
  }
  listen (fd, 1);
  nfd = accept (fd, &saddr, &slen);
  if (check_authentication (nfd, prin, inst, realm))
    printf ("oops. authentication failed.\n");
  else
    printf ("authenticated from %s.%s@%s\n",
	    prin, inst, realm);
  write (nfd, "200 You win\n", 12);
  close (fd);
  close (nfd);
}

