home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / krb / rd_err.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-25  |  2.3 KB  |  84 lines

  1. /*
  2.  * $Source: /usr/src/kerberosIV/krb/RCS/rd_err.c,v $
  3.  * $Author: kfall $
  4.  *
  5.  * Copyright 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.  * This routine dissects a a Kerberos 'safe msg',
  12.  * checking its integrity, and returning a pointer to the application
  13.  * data contained and its length.
  14.  *
  15.  * Returns 0 (RD_AP_OK) for success or an error code (RD_AP_...)
  16.  *
  17.  * Steve Miller    Project Athena  MIT/DEC
  18.  */
  19.  
  20. #ifndef lint
  21. static char *rcsid_rd_err_c=
  22. "$Header: /usr/src/kerberosIV/krb/RCS/rd_err.c,v 4.6 90/06/25 20:57:10 kfall Exp $";
  23. #endif /* lint */
  24.  
  25. #include <mit-copyright.h>
  26.  
  27. /* system include files */
  28. #include <stdio.h>
  29. #include <errno.h>
  30. #include <sys/types.h>
  31. #include <netinet/in.h>
  32. #include <sys/time.h>
  33.  
  34. /* application include files */
  35. #include <des.h>
  36. #include <krb.h>
  37. #include <prot.h>
  38.  
  39. /*
  40.  * Given an AUTH_MSG_APPL_ERR message, "in" and its length "in_length",
  41.  * return the error code from the message in "code" and the text in
  42.  * "m_data" as follows:
  43.  *
  44.  *    m_data->app_data    points to the error text
  45.  *    m_data->app_length    points to the length of the error text
  46.  *
  47.  * If all goes well, return RD_AP_OK.  If the version number
  48.  * is wrong, return RD_AP_VERSION, and if it's not an AUTH_MSG_APPL_ERR
  49.  * type message, return RD_AP_MSG_TYPE.
  50.  *
  51.  * The AUTH_MSG_APPL_ERR message format can be found in mk_err.c
  52.  */
  53.  
  54. int
  55. krb_rd_err(in,in_length,code,m_data)
  56.     u_char *in;                 /* pointer to the msg received */
  57.     u_long in_length;           /* of in msg */
  58.     long *code;                 /* received error code */
  59.     MSG_DAT *m_data;
  60. {
  61.     register u_char *p;
  62.     int swap_bytes = 0;
  63.     p = in;                     /* beginning of message */
  64.  
  65.     if (*p++ != KRB_PROT_VERSION)
  66.         return(RD_AP_VERSION);
  67.     if (((*p) & ~1) != AUTH_MSG_APPL_ERR)
  68.         return(RD_AP_MSG_TYPE);
  69.     if ((*p++ & 1) != HOST_BYTE_ORDER)
  70.         swap_bytes++;
  71.  
  72.     /* safely get code */
  73.     bcopy((char *)p,(char *)code,sizeof(*code));
  74.     if (swap_bytes)
  75.         swap_u_long(*code);
  76.     p += sizeof(*code);         /* skip over */
  77.  
  78.     m_data->app_data = p;       /* we're now at the error text
  79.                                  * message */
  80.     m_data->app_length = in_length;
  81.  
  82.     return(RD_AP_OK);           /* OK == 0 */
  83. }
  84.