/**********************************************************************
 * Moira list -> TechInfo acl converter
 * by Bruce Lewis
 *
 * Example usage:
 *     blanche -r -noauth -verbose foo-info | aclconvert foo
 *
 * $Author: brlewis $
 * $Source$
 * $Header$
 *
 * Copyright 1994 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

static char rcsid[] = "$Header$";

#include <stdio.h>
#include <ctype.h>

#define USAGEFMT "Usage: %s sourcename\n"

main(argc, argv)
     int argc;
     char *argv[];
{
  char inbuf[256], princbuf[256], outbuf[256], *s;

  if (argc != 2)
    {
      fprintf(stderr, USAGEFMT, argv[0]);
      exit(1);
    }

  /* read input */
  while (fgets(inbuf, 255, stdin))
    {
      /* remove trailing whitespace */
      for(s=inbuf+strlen(inbuf)-1; isspace(*s); s--) *s = '\0';

      /* is it a user or kerberos principal? */
      if (!strncmp("USER:", inbuf, 5) || !strncmp("KERBEROS:", inbuf, 9))
	{
	  /* canonicalize username / principal */
	  acl_canonicalize_principal(strchr(inbuf, ':')+1, princbuf);

	  /* make sure all chars are legal */
	  for(s=princbuf; *s; s++)
	    if (!isalpha(*s) && !isdigit(*s) && *s != '.' && *s != '@')
	      break;
	  if (*s) continue;

	  /* It's ok.  We'll output it. */
	  printf("%s:%s:Kerberos\n", argv[1], princbuf);
	}
    }
  exit(0);
}
