/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Modifications for Lustre * Copyright 2004, Cluster File Systems, Inc. * All rights reserved * Author: Eric Mei */ /* * linux/net/sunrpc/gss_mech_switch.c * * Copyright (c) 2001 The Regents of the University of Michigan. * All rights reserved. * * J. Bruce Fields * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif #define DEBUG_SUBSYSTEM S_SEC #ifdef __KERNEL__ #include #include #include #else #include #endif #include #include #include #include #include #include #include #include #include "gss_err.h" #include "gss_internal.h" #include "gss_api.h" static LIST_HEAD(registered_mechs); static spinlock_t registered_mechs_lock = SPIN_LOCK_UNLOCKED; int kgss_mech_register(struct gss_api_mech *gm) { spin_lock(®istered_mechs_lock); list_add(&gm->gm_list, ®istered_mechs); spin_unlock(®istered_mechs_lock); CWARN("registered gss mechanism %s\n", gm->gm_name); return 0; } //EXPORT_SYMBOL(kgss_mech_register); void kgss_mech_unregister(struct gss_api_mech *gm) { spin_lock(®istered_mechs_lock); list_del(&gm->gm_list); spin_unlock(®istered_mechs_lock); CWARN("unregistered gss mechanism %s\n", gm->gm_name); // gss_mech_free(gm); } //EXPORT_SYMBOL(gss_mech_unregister); struct gss_api_mech * kgss_mech_get(struct gss_api_mech *gm) { __module_get(gm->gm_owner); return gm; } //EXPORT_SYMBOL(kgss_mech_get); struct gss_api_mech * kgss_name_to_mech(char *name) { struct gss_api_mech *pos, *gm = NULL; spin_lock(®istered_mechs_lock); list_for_each_entry(pos, ®istered_mechs, gm_list) { if (0 == strcmp(name, pos->gm_name)) { if (!try_module_get(pos->gm_owner)) continue; gm = pos; break; } } spin_unlock(®istered_mechs_lock); return gm; } //EXPORT_SYMBOL(gss_name_to_mech); static inline int mech_supports_subflavor(struct gss_api_mech *gm, __u32 subflavor) { int i; for (i = 0; i < gm->gm_sf_num; i++) { if (gm->gm_sfs[i].subflavor == subflavor) return 1; } return 0; } struct gss_api_mech * kgss_subflavor_to_mech(__u32 subflavor) { struct gss_api_mech *pos, *gm = NULL; spin_lock(®istered_mechs_lock); list_for_each_entry(pos, ®istered_mechs, gm_list) { if (!try_module_get(pos->gm_owner)) continue; if (!mech_supports_subflavor(pos, subflavor)) { module_put(pos->gm_owner); continue; } gm = pos; break; } spin_unlock(®istered_mechs_lock); return gm; } //EXPORT_SYMBOL(gss_subflavor_to_mech); void kgss_mech_put(struct gss_api_mech *gm) { module_put(gm->gm_owner); } //EXPORT_SYMBOL(kgss_mech_put); /* The mech could probably be determined from the token instead, but it's just * as easy for now to pass it in. */ __u32 kgss_import_sec_context(rawobj_t *input_token, struct gss_api_mech *mech, struct gss_ctx **ctx_id) { OBD_ALLOC(*ctx_id, sizeof(**ctx_id)); if (*ctx_id == NULL) return GSS_S_FAILURE; (*ctx_id)->mech_type = kgss_mech_get(mech); LASSERT(mech); LASSERT(mech->gm_ops); LASSERT(mech->gm_ops->gss_import_sec_context); return mech->gm_ops->gss_import_sec_context(input_token, *ctx_id); } /* * this interface is much simplified, currently we only need endtime. */ __u32 kgss_inquire_context(struct gss_ctx *context_handle, __u64 *endtime) { LASSERT(context_handle); LASSERT(context_handle->mech_type); LASSERT(context_handle->mech_type->gm_ops); LASSERT(context_handle->mech_type->gm_ops->gss_inquire_context); return context_handle->mech_type->gm_ops ->gss_inquire_context(context_handle, endtime); } /* gss_get_mic: compute a mic over message and return mic_token. */ __u32 kgss_get_mic(struct gss_ctx *context_handle, __u32 qop, rawobj_t *message, rawobj_t *mic_token) { LASSERT(context_handle); LASSERT(context_handle->mech_type); LASSERT(context_handle->mech_type->gm_ops); LASSERT(context_handle->mech_type->gm_ops->gss_get_mic); return context_handle->mech_type->gm_ops ->gss_get_mic(context_handle, qop, message, mic_token); } /* gss_verify_mic: check whether the provided mic_token verifies message. */ __u32 kgss_verify_mic(struct gss_ctx *context_handle, rawobj_t *message, rawobj_t *mic_token, __u32 *qstate) { LASSERT(context_handle); LASSERT(context_handle->mech_type); LASSERT(context_handle->mech_type->gm_ops); LASSERT(context_handle->mech_type->gm_ops->gss_verify_mic); return context_handle->mech_type->gm_ops ->gss_verify_mic(context_handle, message, mic_token, qstate); } __u32 kgss_wrap(struct gss_ctx *context_handle, __u32 qop, rawobj_buf_t *inbuf, rawobj_t *outbuf) { LASSERT(context_handle); LASSERT(context_handle->mech_type); LASSERT(context_handle->mech_type->gm_ops); LASSERT(context_handle->mech_type->gm_ops->gss_wrap); return context_handle->mech_type->gm_ops ->gss_wrap(context_handle, qop, inbuf, outbuf); } __u32 kgss_unwrap(struct gss_ctx *context_handle, __u32 qop, rawobj_t *inbuf, rawobj_t *outbuf) { LASSERT(context_handle); LASSERT(context_handle->mech_type); LASSERT(context_handle->mech_type->gm_ops); LASSERT(context_handle->mech_type->gm_ops->gss_unwrap); return context_handle->mech_type->gm_ops ->gss_unwrap(context_handle, qop, inbuf, outbuf); } /* gss_delete_sec_context: free all resources associated with context_handle. * Note this differs from the RFC 2744-specified prototype in that we don't * bother returning an output token, since it would never be used anyway. */ __u32 kgss_delete_sec_context(struct gss_ctx **context_handle) { struct gss_api_mech *mech; CDEBUG(D_SEC, "deleting %p\n", *context_handle); if (!*context_handle) return(GSS_S_NO_CONTEXT); mech = (*context_handle)->mech_type; if ((*context_handle)->internal_ctx_id != 0) { LASSERT(mech); LASSERT(mech->gm_ops); LASSERT(mech->gm_ops->gss_delete_sec_context); mech->gm_ops->gss_delete_sec_context( (*context_handle)->internal_ctx_id); } if (mech) kgss_mech_put(mech); OBD_FREE(*context_handle, sizeof(**context_handle)); *context_handle=NULL; return GSS_S_COMPLETE; }