2 * lib/krb5/krb/srv_rcache.c
4 * Copyright 1991 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * Allocate & prepare a default replay cache for a server.
32 krb5_get_server_rcache(context, piece, rcptr)
34 const krb5_data *piece;
37 krb5_rcache rcache = 0;
40 extern krb5_deltat krb5_clockskew;
41 krb5_error_code retval;
44 rcache = (krb5_rcache) malloc(sizeof(*rcache));
48 retval = krb5_rc_resolve_type(context, &rcache, "dfl");
49 if (retval) goto cleanup;
51 len = piece->length + 3 + 1;
52 for (i = 0; i <= piece->length; i++) {
53 if (piece->data[i] == '\\')
55 else if (!isgraph(piece->data[i]))
58 cachename = malloc(len);
63 strcpy(cachename, "rc_");
65 for (i = 0; i < piece->length; i++) {
66 if (piece->data[i] == '\\') {
67 cachename[p++] = '\\';
68 cachename[p++] = '\\';
71 if (!isgraph(piece->data[i])) {
72 sprintf(tmp, "%03o", piece->data[i]);
73 cachename[p++] = '\\';
74 cachename[p++] = tmp[0];
75 cachename[p++] = tmp[1];
76 cachename[p++] = tmp[2];
79 cachename[p++] = piece->data[i];
81 cachename[p++] = '\0';
83 if (retval = krb5_rc_resolve(context, rcache, cachename))
87 * First try to recover the replay cache; if that doesn't work,
90 if (krb5_rc_recover(context, rcache)) {
91 if (retval = krb5_rc_initialize(context, rcache, krb5_clockskew)) {
92 krb5_rc_close(context, rcache);
105 krb5_xfree(cachename);