2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/krb/srv_rcache.c
2N/A *
2N/A * Copyright 1991 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A */
2N/A/*
2N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A/*
2N/A * Allocate & prepare a default replay cache for a server.
2N/A */
2N/A
2N/A#include "k5-int.h"
2N/A#include <ctype.h>
2N/A#include <stdio.h>
2N/A
2N/A/* Macro for valid RC name characters*/
2N/A#define isvalidrcname(x) ((!ispunct(x))&&isgraph(x))
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_get_server_rcache(krb5_context context, const krb5_data *piece,
2N/A krb5_rcache *rcptr)
2N/A{
2N/A krb5_rcache rcache = 0;
2N/A char *cachename = 0, *cachetype;
2N/A krb5_error_code retval;
2N/A unsigned int i;
2N/A struct k5buf buf;
2N/A char *def_env = 0; /* Solaris Kerberos */
2N/A#ifdef HAVE_GETEUID
2N/A unsigned long uid = geteuid();
2N/A#endif
2N/A
2N/A if (piece == NULL)
2N/A return ENOMEM;
2N/A
2N/A cachetype = krb5_rc_default_type(context);
2N/A
2N/A krb5int_buf_init_dynamic(&buf);
2N/A /*
2N/A * Solaris Kerberos: Check to see if something other than the default
2N/A * replay cache name will be used. If so then skip over the construction
2N/A * of said name.
2N/A */
2N/A if ((def_env = krb5_rc_default_name(context)) != 0) {
2N/A /*
2N/A * We expect to have the fully qualified rcache name (<type>:<name>),
2N/A * so we populate the default type here if the type is missing.
2N/A */
2N/A if (strchr(def_env, ':') == NULL)
2N/A krb5int_buf_add_fmt(&buf, "%s:%s", cachetype, def_env);
2N/A else
2N/A krb5int_buf_add(&buf, def_env);
2N/A } else {
2N/A /* Standard MIT 1.8 code */
2N/A krb5int_buf_add(&buf, cachetype);
2N/A krb5int_buf_add(&buf, ":");
2N/A for (i = 0; i < piece->length; i++) {
2N/A if (piece->data[i] == '-')
2N/A krb5int_buf_add(&buf, "--");
2N/A else if (!isvalidrcname((int) piece->data[i]))
2N/A krb5int_buf_add_fmt(&buf, "-%03o", piece->data[i]);
2N/A else
2N/A krb5int_buf_add_len(&buf, &piece->data[i], 1);
2N/A }
2N/A#ifdef HAVE_GETEUID
2N/A krb5int_buf_add_fmt(&buf, "_%lu", uid);
2N/A#endif
2N/A }
2N/A
2N/A cachename = krb5int_buf_data(&buf);
2N/A if (cachename == NULL)
2N/A return ENOMEM;
2N/A
2N/A retval = krb5_rc_resolve_full(context, &rcache, cachename);
2N/A if (retval)
2N/A goto cleanup;
2N/A
2N/A retval = krb5_rc_recover_or_initialize(context, rcache,
2N/A context->clockskew);
2N/A if (retval)
2N/A goto cleanup;
2N/A
2N/A *rcptr = rcache;
2N/A rcache = 0;
2N/A retval = 0;
2N/A
2N/Acleanup:
2N/A if (rcache)
2N/A krb5_rc_close(context, rcache);
2N/A if (cachename)
2N/A free(cachename);
2N/A return retval;
2N/A}