Path: blob/main/crypto/krb5/src/lib/krad/internal.h
39536 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* lib/krad/internal.h - Internal declarations for libkrad */2/*3* Copyright 2013 Red Hat, Inc. All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in13* the documentation and/or other materials provided with the14* distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS17* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED18* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A19* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER20* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,21* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,22* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR23* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF24* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING25* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/2829#ifndef INTERNAL_H_30#define INTERNAL_H_3132#include <k5-int.h>33#include "krad.h"3435#include <errno.h>3637#include <sys/types.h>38#include <sys/socket.h>39#include <netdb.h>4041#ifndef UCHAR_MAX42#define UCHAR_MAX 25543#endif4445#define MD5_DIGEST_SIZE 164647/* RFC 2865 */48#define MAX_ATTRSIZE (UCHAR_MAX - 2)49#define MAX_ATTRSETSIZE (KRAD_PACKET_SIZE_MAX - 20)5051typedef struct krad_remote_st krad_remote;5253/* Validate constraints of an attribute. */54krb5_error_code55kr_attr_valid(krad_attr type, const krb5_data *data);5657/* Encode an attribute. */58krb5_error_code59kr_attr_encode(krb5_context ctx, const char *secret, const unsigned char *auth,60krad_attr type, const krb5_data *in,61unsigned char outbuf[MAX_ATTRSIZE], size_t *outlen);6263/* Decode an attribute. */64krb5_error_code65kr_attr_decode(krb5_context ctx, const char *secret, const unsigned char *auth,66krad_attr type, const krb5_data *in,67unsigned char outbuf[MAX_ATTRSIZE], size_t *outlen);6869/* Encode set into outbuf. If add_msgauth is true, include a zeroed70* Message-Authenticator as the first attribute. */71krb5_error_code72kr_attrset_encode(const krad_attrset *set, const char *secret,73const uint8_t *auth, krb5_boolean add_msgauth,74unsigned char outbuf[MAX_ATTRSETSIZE], size_t *outlen);7576/* Decode attributes from a buffer. */77krb5_error_code78kr_attrset_decode(krb5_context ctx, const krb5_data *in, const char *secret,79const unsigned char *auth, krad_attrset **set);8081/* Create a new remote object which manages a socket and the state of82* outstanding requests. */83krb5_error_code84kr_remote_new(krb5_context kctx, verto_ctx *vctx, const struct addrinfo *info,85const char *secret, krad_remote **rr);8687/* Free a remote object. */88void89kr_remote_free(krad_remote *rr);9091/*92* Send the packet to the remote. The cb will be called when a response is93* received, the request times out, the request is canceled or an error occurs.94*95* The timeout parameter is the total timeout across all retries in96* milliseconds.97*98* If the cb is called with a retval of ETIMEDOUT it indicates that the99* allotted time has elapsed. However, in the case of a timeout, we continue to100* listen for the packet until krad_remote_cancel() is called or a response is101* received. This means that cb will always be called twice in the event of a102* timeout. This permits you to pursue other remotes while still listening for103* a response from the first one.104*/105krb5_error_code106kr_remote_send(krad_remote *rr, krad_code code, krad_attrset *attrs,107krad_cb cb, void *data, int timeout, size_t retries,108const krad_packet **pkt);109110/* Remove packet from the queue of requests awaiting responses. */111void112kr_remote_cancel(krad_remote *rr, const krad_packet *pkt);113114/* Cancel all requests awaiting responses. */115void116kr_remote_cancel_all(krad_remote *rr);117118/* Determine if this remote object refers to the remote resource identified119* by the addrinfo struct and the secret. */120krb5_boolean121kr_remote_equals(const krad_remote *rr, const struct addrinfo *info,122const char *secret);123124/* Adapted from lib/krb5/os/sendto_kdc.c. */125static inline krb5_error_code126gai_error_code(int err)127{128switch (err) {129case 0:130return 0;131case EAI_BADFLAGS:132case EAI_FAMILY:133case EAI_SOCKTYPE:134case EAI_SERVICE:135#ifdef EAI_ADDRFAMILY136case EAI_ADDRFAMILY:137#endif138return EINVAL;139case EAI_AGAIN:140return EAGAIN;141case EAI_MEMORY:142return ENOMEM;143#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME144case EAI_NODATA:145#endif146case EAI_NONAME:147return EADDRNOTAVAIL;148#ifdef EAI_OVERFLOW149case EAI_OVERFLOW:150return EOVERFLOW;151#endif152#ifdef EAI_SYSTEM153case EAI_SYSTEM:154return errno;155#endif156default:157return EINVAL;158}159}160161#endif /* INTERNAL_H_ */162163164