Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / krb / mk_err.c
1 /* 
2   Copyright (C) 1989 by the Massachusetts Institute of Technology
3
4    Export of this software from the United States of America is assumed
5    to require a specific license from the United States Government.
6    It is the responsibility of any person or organization contemplating
7    export to obtain such a license before exporting.
8
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission.  M.I.T. makes no representations about the suitability of
17 this software for any purpose.  It is provided "as is" without express
18 or implied warranty.
19
20   */
21
22 #include "krb_locl.h"
23
24 RCSID("$Id: mk_err.c,v 1.7 1998/06/09 19:25:22 joda Exp $");
25
26 /*
27  * This routine creates a general purpose error reply message.  It
28  * doesn't use KTEXT because application protocol may have long
29  * messages, and may want this part of buffer contiguous to other
30  * stuff.
31  *
32  * The error reply is built in "p", using the error code "e" and
33  * error text "e_string" given.  The length of the error reply is
34  * returned.
35  *
36  * The error reply is in the following format:
37  *
38  * unsigned char        KRB_PROT_VERSION        protocol version no.
39  * unsigned char        AUTH_MSG_APPL_ERR       message type
40  * (least significant
41  * bit of above)        HOST_BYTE_ORDER         local byte order
42  * 4 bytes              e                       given error code
43  * string               e_string                given error text
44  */
45
46 int32_t
47 krb_mk_err(u_char *p, int32_t e, char *e_string)
48 {
49     unsigned char *start = p;
50     
51     p += krb_put_int(KRB_PROT_VERSION, p, 1, 1);
52     p += krb_put_int(AUTH_MSG_APPL_ERR, p, 1, 1);
53     
54     p += krb_put_int(e, p, 4, 4);
55     p += krb_put_string(e_string, p, strlen(e_string) + 1);
56     return p - start;
57 }