home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / krb / decomp_ticket.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-25  |  4.2 KB  |  135 lines

  1. /*
  2.  * $Source: /usr/src/kerberosIV/krb/RCS/decomp_ticket.c,v $
  3.  * $Author: bostic $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology.
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  */
  11.  
  12. #ifndef lint
  13. static char *rcsid_decomp_ticket_c =
  14. "$Header: /usr/src/kerberosIV/krb/RCS/decomp_ticket.c,v 4.14 91/02/25 15:21:17 bostic Exp $";
  15. #endif /* lint */
  16.  
  17. #include <mit-copyright.h>
  18. #include <stdio.h>
  19. #include <des.h>
  20. #include <krb.h>
  21. #include <prot.h>
  22. #include <strings.h>
  23.  
  24. /*
  25.  * This routine takes a ticket and pointers to the variables that
  26.  * should be filled in based on the information in the ticket.  It
  27. #ifndef NOENCRYPTION
  28.  * decrypts the ticket using the given key, and 
  29. #endif
  30.  * fills in values for its arguments.
  31.  *
  32.  * Note: if the client realm field in the ticket is the null string,
  33.  * then the "prealm" variable is filled in with the local realm (as
  34.  * defined by KRB_REALM).
  35.  *
  36.  * If the ticket byte order is different than the host's byte order
  37.  * (as indicated by the byte order bit of the "flags" field), then
  38.  * the KDC timestamp "time_sec" is byte-swapped.  The other fields
  39.  * potentially affected by byte order, "paddress" and "session" are
  40.  * not byte-swapped.
  41.  *
  42.  * The routine returns KFAILURE if any of the "pname", "pinstance",
  43.  * or "prealm" fields is too big, otherwise it returns KSUCCESS.
  44.  *
  45.  * The corresponding routine to generate tickets is create_ticket.
  46.  * When changes are made to this routine, the corresponding changes
  47.  * should also be made to that file.
  48.  *
  49.  * See create_ticket.c for the format of the ticket packet.
  50.  */
  51.  
  52. decomp_ticket(tkt, flags, pname, pinstance, prealm, paddress, session,
  53.               life, time_sec, sname, sinstance, key, key_s)
  54.     KTEXT tkt;            /* The ticket to be decoded */
  55.     unsigned char *flags;       /* Kerberos ticket flags */
  56.     char *pname;        /* Authentication name */
  57.     char *pinstance;        /* Principal's instance */
  58.     char *prealm;        /* Principal's authentication domain */
  59.     unsigned long *paddress;    /* Net address of entity
  60.                                  * requesting ticket */
  61.     C_Block session;        /* Session key inserted in ticket */
  62.     int *life;                 /* Lifetime of the ticket */
  63.     unsigned long *time_sec;    /* Issue time and date */
  64.     char *sname;        /* Service name */
  65.     char *sinstance;        /* Service instance */
  66.     C_Block key;        /* Service's secret key
  67.                                  * (to decrypt the ticket) */
  68.     Key_schedule key_s;        /* The precomputed key schedule */
  69. {
  70.     static int tkt_swap_bytes;
  71.     unsigned char *uptr;
  72.     char *ptr = (char *)tkt->dat;
  73.  
  74. #ifndef NOENCRYPTION
  75.     /* Do the decryption */
  76.     pcbc_encrypt((C_Block *)tkt->dat,(C_Block *)tkt->dat,
  77.                  (long) tkt->length,key_s,key,0);
  78. #endif /* ! NOENCRYPTION */
  79.  
  80.     *flags = *ptr;              /* get flags byte */
  81.     ptr += sizeof(*flags);
  82.     tkt_swap_bytes = 0;
  83.     if (HOST_BYTE_ORDER != ((*flags >> K_FLAG_ORDER)& 1))
  84.         tkt_swap_bytes++;
  85.  
  86.     if (strlen(ptr) > ANAME_SZ)
  87.         return(KFAILURE);
  88.     (void) strcpy(pname,ptr);   /* pname */
  89.     ptr += strlen(pname) + 1;
  90.  
  91.     if (strlen(ptr) > INST_SZ)
  92.         return(KFAILURE);
  93.     (void) strcpy(pinstance,ptr); /* instance */
  94.     ptr += strlen(pinstance) + 1;
  95.  
  96.     if (strlen(ptr) > REALM_SZ)
  97.         return(KFAILURE);
  98.     (void) strcpy(prealm,ptr);  /* realm */
  99.     ptr += strlen(prealm) + 1;
  100.     /* temporary hack until realms are dealt with properly */
  101.     if (*prealm == 0)
  102.     return(KFAILURE);
  103.  
  104. #ifdef    notdef
  105.     Do not want to use this definition -kfall
  106.         (void) strcpy(prealm,KRB_REALM);
  107. #endif
  108.  
  109.     bcopy(ptr,(char *)paddress,4); /* net address */
  110.     ptr += 4;
  111.  
  112.     bcopy(ptr,(char *)session,8); /* session key */
  113.     ptr+= 8;
  114. #ifdef notdef /* DONT SWAP SESSION KEY spm 10/22/86 */
  115.     if (tkt_swap_bytes)
  116.         swap_C_Block(session);
  117. #endif
  118.  
  119.     /* get lifetime, being certain we don't get negative lifetimes */
  120.     uptr = (unsigned char *) ptr++;
  121.     *life = (int) *uptr;
  122.  
  123.     bcopy(ptr,(char *) time_sec,4); /* issue time */
  124.     ptr += 4;
  125.     if (tkt_swap_bytes)
  126.         swap_u_long(*time_sec);
  127.  
  128.     (void) strcpy(sname,ptr);   /* service name */
  129.     ptr += 1 + strlen(sname);
  130.  
  131.     (void) strcpy(sinstance,ptr); /* instance */
  132.     ptr += 1 + strlen(sinstance);
  133.     return(KSUCCESS);
  134. }
  135.