// SPDX-License-Identifier: BSD-3-Clause /* * linux/net/sunrpc/gss_mech_switch.c * * Copyright (c) 2001 The Regents of the University of Michigan. * All rights reserved. * * J. Bruce Fields <bfields@umich.edu>
*/
new = kmalloc(strlen(name) + strlen(prefix) + 1, GFP_KERNEL); if (new) {
strcpy(new, prefix);
strcat(new, name);
} returnnew;
}
staticint
gss_mech_svc_setup(struct gss_api_mech *gm)
{ struct auth_domain *dom; struct pf_desc *pf; int i, status;
for (i = 0; i < gm->gm_pf_num; i++) {
pf = &gm->gm_pfs[i];
pf->auth_domain_name = make_auth_domain_name(pf->name);
status = -ENOMEM; if (pf->auth_domain_name == NULL) goto out;
dom = svcauth_gss_register_pseudoflavor(
pf->pseudoflavor, pf->auth_domain_name); if (IS_ERR(dom)) {
status = PTR_ERR(dom); goto out;
}
pf->domain = dom;
} return 0;
out:
gss_mech_free(gm); return status;
}
/** * gss_mech_register - register a GSS mechanism * @gm: GSS mechanism handle * * Returns zero if successful, or a negative errno.
*/ int gss_mech_register(struct gss_api_mech *gm)
{ int status;
/** * gss_svc_to_pseudoflavor - map a GSS service number to a pseudoflavor * @gm: GSS mechanism handle * @qop: GSS quality-of-protection value * @service: GSS service value * * Returns a matching security flavor, or RPC_AUTH_MAXFLAVOR if none is found.
*/
rpc_authflavor_t gss_svc_to_pseudoflavor(struct gss_api_mech *gm, u32 qop,
u32 service)
{ int i;
for (i = 0; i < gm->gm_pf_num; i++) { if (gm->gm_pfs[i].qop == qop &&
gm->gm_pfs[i].service == service) { return gm->gm_pfs[i].pseudoflavor;
}
} return RPC_AUTH_MAXFLAVOR;
}
/** * gss_mech_info2flavor - look up a pseudoflavor given a GSS tuple * @info: a GSS mech OID, quality of protection, and service value * * Returns a matching pseudoflavor, or RPC_AUTH_MAXFLAVOR if the tuple is * not supported.
*/
rpc_authflavor_t gss_mech_info2flavor(struct rpcsec_gss_info *info)
{
rpc_authflavor_t pseudoflavor; struct gss_api_mech *gm;
gm = gss_mech_get_by_OID(&info->oid); if (gm == NULL) return RPC_AUTH_MAXFLAVOR;
/** * gss_mech_flavor2info - look up a GSS tuple for a given pseudoflavor * @pseudoflavor: GSS pseudoflavor to match * @info: rpcsec_gss_info structure to fill in * * Returns zero and fills in "info" if pseudoflavor matches a * supported mechanism. Otherwise a negative errno is returned.
*/ int gss_mech_flavor2info(rpc_authflavor_t pseudoflavor, struct rpcsec_gss_info *info)
{ struct gss_api_mech *gm; int i;
gm = gss_mech_get_by_pseudoflavor(pseudoflavor); if (gm == NULL) return -ENOENT;
for (i = 0; i < gm->gm_pf_num; i++) { if (gm->gm_pfs[i].pseudoflavor == pseudoflavor) {
memcpy(info->oid.data, gm->gm_oid.data, gm->gm_oid.len);
info->oid.len = gm->gm_oid.len;
info->qop = gm->gm_pfs[i].qop;
info->service = gm->gm_pfs[i].service;
gss_mech_put(gm); return 0;
}
}
gss_mech_put(gm); return -ENOENT;
}
u32
gss_pseudoflavor_to_service(struct gss_api_mech *gm, u32 pseudoflavor)
{ int i;
for (i = 0; i < gm->gm_pf_num; i++) { if (gm->gm_pfs[i].pseudoflavor == pseudoflavor) return gm->gm_pfs[i].service;
} return 0;
}
EXPORT_SYMBOL(gss_pseudoflavor_to_service);
bool
gss_pseudoflavor_to_datatouch(struct gss_api_mech *gm, u32 pseudoflavor)
{ int i;
for (i = 0; i < gm->gm_pf_num; i++) { if (gm->gm_pfs[i].pseudoflavor == pseudoflavor) return gm->gm_pfs[i].datatouch;
} returnfalse;
}
char *
gss_service_to_auth_domain_name(struct gss_api_mech *gm, u32 service)
{ int i;
for (i = 0; i < gm->gm_pf_num; i++) { if (gm->gm_pfs[i].service == service) return gm->gm_pfs[i].auth_domain_name;
} return NULL;
}
/* The mech could probably be determined from the token instead, but it's just
* as easy for now to pass it in. */ int
gss_import_sec_context(constvoid *input_token, size_t bufsize, struct gss_api_mech *mech, struct gss_ctx **ctx_id,
time64_t *endtime,
gfp_t gfp_mask)
{ if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask))) return -ENOMEM;
(*ctx_id)->mech_type = gss_mech_get(mech);
/* * This function is called from both the client and server code. * Each makes guarantees about how much "slack" space is available * for the underlying function in "buf"'s head and tail while * performing the wrap. * * The client and server code allocate RPC_MAX_AUTH_SIZE extra * space in both the head and tail which is available for use by * the wrap function. * * Underlying functions should verify they do not use more than * RPC_MAX_AUTH_SIZE of extra space in either the head or tail * when performing the wrap.
*/
u32
gss_wrap(struct gss_ctx *ctx_id, int offset, struct xdr_buf *buf, struct page **inpages)
{ return ctx_id->mech_type->gm_ops
->gss_wrap(ctx_id, offset, buf, inpages);
}
u32
gss_unwrap(struct gss_ctx *ctx_id, int offset, int len, struct xdr_buf *buf)
{ return ctx_id->mech_type->gm_ops
->gss_unwrap(ctx_id, offset, len, buf);
}
/* 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. */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.