home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libk.lha / Lib / KRB / CRERREP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-31  |  2.9 KB  |  98 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/krb/RCS/cr_err_reply.c,v $
  3.  * $Author: steiner $
  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_cr_err_reply_c =
  14. "$Header: cr_err_reply.c,v 4.10 89/01/10 11:34:42 steiner Exp $";
  15. #endif /* lint */
  16.  
  17. #include <mit_copy.h>
  18. #include <sys/types.h>
  19. #include <krb.h>
  20. #include <prot.h>
  21. #include <string.h>
  22.  
  23. extern int req_act_vno;        /* this is defined in the kerberos
  24.                  * server code */
  25.  
  26. /*
  27.  * This routine is used by the Kerberos authentication server to
  28.  * create an error reply packet to send back to its client.
  29.  *
  30.  * It takes a pointer to the packet to be built, the name, instance,
  31.  * and realm of the principal, the client's timestamp, an error code
  32.  * and an error string as arguments.  Its return value is undefined.
  33.  *
  34.  * The packet is built in the following format:
  35.  * 
  36.  * type            variable       data
  37.  *            or constant
  38.  * ----            -----------       ----
  39.  *
  40.  * unsigned char    req_ack_vno       protocol version number
  41.  * 
  42.  * unsigned char    AUTH_MSG_ERR_REPLY protocol message type
  43.  * 
  44.  * [least significant    HOST_BYTE_ORDER       sender's (server's) byte
  45.  * bit of above field]               order
  46.  * 
  47.  * string        pname           principal's name
  48.  * 
  49.  * string        pinst           principal's instance
  50.  * 
  51.  * string        prealm           principal's realm
  52.  * 
  53.  * unsigned long    time_ws           client's timestamp
  54.  * 
  55.  * unsigned long    e           error code
  56.  * 
  57.  * string        e_string       error text
  58.  */
  59.  
  60. void
  61. cr_err_reply(pkt,pname,pinst,prealm,time_ws,e,e_string)
  62.     KTEXT pkt;
  63.     char *pname;        /* Principal's name */
  64.     char *pinst;        /* Principal's instance */
  65.     char *prealm;        /* Principal's authentication domain */
  66.     u_long time_ws;        /* Workstation time */
  67.     u_long e;            /* Error code */
  68.     char *e_string;        /* Text of error */
  69. {
  70.     u_char *v = (u_char *) pkt->dat; /* Prot vers number */
  71.     u_char *t = (u_char *)(pkt->dat+1); /* Prot message type */
  72.  
  73.     /* Create fixed part of packet */
  74.     *v = (unsigned char) req_act_vno; /* KRB_PROT_VERSION; */
  75.     *t = (unsigned char) AUTH_MSG_ERR_REPLY;
  76.     *t |= HOST_BYTE_ORDER;
  77.  
  78.     /* Add the basic info */
  79.     (void) strcpy((char *) (pkt->dat+2),pname);
  80.     pkt->length = 3 + strlen(pname);
  81.     (void) strcpy((char *)(pkt->dat+pkt->length),pinst);
  82.     pkt->length += 1 + strlen(pinst);
  83.     (void) strcpy((char *)(pkt->dat+pkt->length),prealm);
  84.     pkt->length += 1 + strlen(prealm);
  85.     /* ws timestamp */
  86.     bcopy((char *) &time_ws,(char *)(pkt->dat+pkt->length),4);
  87.     pkt->length += 4;
  88.     /* err code */
  89.     bcopy((char *) &e,(char *)(pkt->dat+pkt->length),4);
  90.     pkt->length += 4;
  91.     /* err text */
  92.     (void) strcpy((char *)(pkt->dat+pkt->length),e_string);
  93.     pkt->length += 1 + strlen(e_string);
  94.  
  95.     /* And return */
  96.     return;
  97. }
  98.