2 * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /* Almost all programs use these routines (implicitly) so it's a good
35 * place to put the version string. */
37 #include "rxkad_locl.h"
45 krb4_get_int(void *f
, u_int32_t
*to
, int size
, int lsb
)
48 unsigned char *from
= (unsigned char *)f
;
52 for(i
= size
-1; i
>= 0; i
--)
53 *to
= (*to
<< 8) | from
[i
];
55 for(i
= 0; i
< size
; i
++)
56 *to
= (*to
<< 8) | from
[i
];
62 krb4_put_int(u_int32_t from
, void *to
, size_t rem
, int size
)
65 unsigned char *p
= (unsigned char *)to
;
70 for(i
= size
- 1; i
>= 0; i
--){
78 /* addresses are always sent in network byte order */
81 krb4_get_address(void *from
, u_int32_t
*to
)
83 unsigned char *p
= (unsigned char*)from
;
84 *to
= htonl((p
[0] << 24) | (p
[1] << 16) | (p
[2] << 8) | p
[3]);
89 krb4_put_address(u_int32_t addr
, void *to
, size_t rem
)
91 return krb4_put_int(ntohl(addr
), to
, rem
, 4);
95 krb4_put_string(const char *from
, void *to
, size_t rem
)
97 size_t len
= strlen(from
) + 1;
101 memcpy(to
, from
, len
);
106 krb4_get_string(void *from
, char *to
, size_t to_size
)
108 strlcpy (to
, (char *)from
, to_size
);
109 return strlen((char *)from
) + 1;
113 krb4_get_nir(void *from
,
114 char *name
, size_t name_len
,
115 char *instance
, size_t instance_len
,
116 char *realm
, size_t realm_len
)
118 char *p
= (char *)from
;
120 p
+= krb4_get_string(p
, name
, name_len
);
121 p
+= krb4_get_string(p
, instance
, instance_len
);
123 p
+= krb4_get_string(p
, realm
, realm_len
);
124 return p
- (char *)from
;
128 krb4_put_nir(const char *name
,
129 const char *instance
,
134 char *p
= (char *)to
;
137 tmp
= krb4_put_string(name
, p
, rem
);
143 tmp
= krb4_put_string(instance
, p
, rem
);
150 tmp
= krb4_put_string(realm
, p
, rem
);
156 return p
- (char *)to
;