Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
1 deleted
83 edited
21 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/heimdal/lib/krb5/acache.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    3840#endif
    3941
     42#ifndef KCM_IS_API_CACHE
     43
    4044static HEIMDAL_MUTEX acc_mutex = HEIMDAL_MUTEX_INITIALIZER;
    4145static cc_initialize_func init_func;
     46static void (KRB5_CALLCONV *set_target_uid)(uid_t);
     47static void (KRB5_CALLCONV *clear_target)(void);
     48
    4249#ifdef HAVE_DLOPEN
    4350static void *cc_handle;
     
    5057} krb5_acc;
    5158
    52 static krb5_error_code acc_close(krb5_context, krb5_ccache);
     59static krb5_error_code KRB5_CALLCONV acc_close(krb5_context, krb5_ccache);
    5360
    5461#define ACACHE(X) ((krb5_acc *)(X)->data.data)
     
    8390init_ccapi(krb5_context context)
    8491{
    85     const char *lib;
     92    const char *lib = NULL;
    8693
    8794    HEIMDAL_MUTEX_lock(&acc_mutex);
    8895    if (init_func) {
    8996        HEIMDAL_MUTEX_unlock(&acc_mutex);
    90         krb5_clear_error_message(context);
     97        if (context)
     98            krb5_clear_error_message(context);
    9199        return 0;
    92100    }
    93101
    94     lib = krb5_config_get_string(context, NULL,
    95                                  "libdefaults", "ccapi_library",
    96                                  NULL);
     102    if (context)
     103        lib = krb5_config_get_string(context, NULL,
     104                                     "libdefaults", "ccapi_library",
     105                                     NULL);
    97106    if (lib == NULL) {
    98107#ifdef __APPLE__
    99108        lib = "/System/Library/Frameworks/Kerberos.framework/Kerberos";
     109#elif defined(KRB5_USE_PATH_TOKENS) && defined(_WIN32)
     110        lib = "%{LIBDIR}/libkrb5_cc.dll";
    100111#else
    101112        lib = "/usr/lib/libkrb5_cc.so";
     
    108119#define RTLD_LAZY 0
    109120#endif
    110 
    111     cc_handle = dlopen(lib, RTLD_LAZY);
     121#ifndef RTLD_LOCAL
     122#define RTLD_LOCAL 0
     123#endif
     124
     125#ifdef KRB5_USE_PATH_TOKENS
     126    {
     127      char * explib = NULL;
     128      if (_krb5_expand_path_tokens(context, lib, &explib) == 0) {
     129        cc_handle = dlopen(explib, RTLD_LAZY|RTLD_LOCAL);
     130        free(explib);
     131      }
     132    }
     133#else
     134    cc_handle = dlopen(lib, RTLD_LAZY|RTLD_LOCAL);
     135#endif
     136
    112137    if (cc_handle == NULL) {
    113138        HEIMDAL_MUTEX_unlock(&acc_mutex);
    114         krb5_set_error_message(context, KRB5_CC_NOSUPP,
    115                                N_("Failed to load API cache module %s", "file"),
    116                                lib);
     139        if (context)
     140            krb5_set_error_message(context, KRB5_CC_NOSUPP,
     141                                   N_("Failed to load API cache module %s", "file"),
     142                                   lib);
    117143        return KRB5_CC_NOSUPP;
    118144    }
    119145
    120146    init_func = (cc_initialize_func)dlsym(cc_handle, "cc_initialize");
     147    set_target_uid = (void (KRB5_CALLCONV *)(uid_t))
     148        dlsym(cc_handle, "krb5_ipc_client_set_target_uid");
     149    clear_target = (void (KRB5_CALLCONV *)(void))
     150        dlsym(cc_handle, "krb5_ipc_client_clear_target");
    121151    HEIMDAL_MUTEX_unlock(&acc_mutex);
    122152    if (init_func == NULL) {
    123         krb5_set_error_message(context, KRB5_CC_NOSUPP,
    124                                N_("Failed to find cc_initialize"
    125                                  "in %s: %s", "file, error"), lib, dlerror());
     153        if (context)
     154            krb5_set_error_message(context, KRB5_CC_NOSUPP,
     155                                   N_("Failed to find cc_initialize"
     156                                      "in %s: %s", "file, error"), lib, dlerror());
    126157        dlclose(cc_handle);
    127158        return KRB5_CC_NOSUPP;
     
    131162#else
    132163    HEIMDAL_MUTEX_unlock(&acc_mutex);
    133     krb5_set_error_message(context, KRB5_CC_NOSUPP,
    134                            N_("no support for shared object", ""));
     164    if (context)
     165        krb5_set_error_message(context, KRB5_CC_NOSUPP,
     166                               N_("no support for shared object", ""));
    135167    return KRB5_CC_NOSUPP;
    136168#endif
     169}
     170
     171void
     172_heim_krb5_ipc_client_set_target_uid(uid_t uid)
     173{
     174    init_ccapi(NULL);
     175    if (set_target_uid != NULL)
     176        (*set_target_uid)(uid);
     177}
     178
     179void
     180_heim_krb5_ipc_client_clear_target(void)
     181{
     182    init_ccapi(NULL);
     183    if (clear_target != NULL)
     184        (*clear_target)();
    137185}
    138186
     
    406454
    407455
    408 static const char*
     456static const char* KRB5_CALLCONV
    409457acc_get_name(krb5_context context,
    410458             krb5_ccache id)
     
    443491}
    444492
    445 static krb5_error_code
     493static krb5_error_code KRB5_CALLCONV
    446494acc_alloc(krb5_context context, krb5_ccache *id)
    447495{
     
    473521}
    474522
    475 static krb5_error_code
     523static krb5_error_code KRB5_CALLCONV
    476524acc_resolve(krb5_context context, krb5_ccache *id, const char *res)
    477525{
     
    513561}
    514562
    515 static krb5_error_code
     563static krb5_error_code KRB5_CALLCONV
    516564acc_gen_new(krb5_context context, krb5_ccache *id)
    517565{
     
    531579}
    532580
    533 static krb5_error_code
     581static krb5_error_code KRB5_CALLCONV
    534582acc_initialize(krb5_context context,
    535583               krb5_ccache id,
     
    585633}
    586634
    587 static krb5_error_code
     635static krb5_error_code KRB5_CALLCONV
    588636acc_close(krb5_context context,
    589637          krb5_ccache id)
     
    607655}
    608656
    609 static krb5_error_code
     657static krb5_error_code KRB5_CALLCONV
    610658acc_destroy(krb5_context context,
    611659            krb5_ccache id)
     
    625673}
    626674
    627 static krb5_error_code
     675static krb5_error_code KRB5_CALLCONV
    628676acc_store_cred(krb5_context context,
    629677               krb5_ccache id,
     
    660708}
    661709
    662 static krb5_error_code
     710static krb5_error_code KRB5_CALLCONV
    663711acc_get_principal(krb5_context context,
    664712                  krb5_ccache id,
     
    688736}
    689737
    690 static krb5_error_code
     738static krb5_error_code KRB5_CALLCONV
    691739acc_get_first (krb5_context context,
    692740               krb5_ccache id,
     
    713761
    714762
    715 static krb5_error_code
     763static krb5_error_code KRB5_CALLCONV
    716764acc_get_next (krb5_context context,
    717765              krb5_ccache id,
     
    740788}
    741789
    742 static krb5_error_code
     790static krb5_error_code KRB5_CALLCONV
    743791acc_end_get (krb5_context context,
    744792             krb5_ccache id,
     
    750798}
    751799
    752 static krb5_error_code
     800static krb5_error_code KRB5_CALLCONV
    753801acc_remove_cred(krb5_context context,
    754802                krb5_ccache id,
     
    826874}
    827875
    828 static krb5_error_code
     876static krb5_error_code KRB5_CALLCONV
    829877acc_set_flags(krb5_context context,
    830878              krb5_ccache id,
     
    834882}
    835883
    836 static int
     884static int KRB5_CALLCONV
    837885acc_get_version(krb5_context context,
    838886                krb5_ccache id)
     
    846894};
    847895
    848 static krb5_error_code
     896static krb5_error_code KRB5_CALLCONV
    849897acc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
    850898{
     
    880928}
    881929
    882 static krb5_error_code
     930static krb5_error_code KRB5_CALLCONV
    883931acc_get_cache_next(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
    884932{
     
    918966}
    919967
    920 static krb5_error_code
     968static krb5_error_code KRB5_CALLCONV
    921969acc_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
    922970{
     
    931979}
    932980
    933 static krb5_error_code
     981static krb5_error_code KRB5_CALLCONV
    934982acc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
    935983{
     
    9631011}
    9641012
    965 static krb5_error_code
     1013static krb5_error_code KRB5_CALLCONV
    9661014acc_get_default_name(krb5_context context, char **str)
    9671015{
     
    9851033    }
    9861034       
    987     asprintf(str, "API:%s", name->data);
     1035    error = asprintf(str, "API:%s", name->data);
    9881036    (*name->func->release)(name);
    9891037    (*cc->func->release)(cc);
    9901038
    991     if (*str == NULL) {
     1039    if (error < 0 || *str == NULL) {
    9921040        krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    9931041        return ENOMEM;
     
    9961044}
    9971045
    998 static krb5_error_code
     1046static krb5_error_code KRB5_CALLCONV
    9991047acc_set_default(krb5_context context, krb5_ccache id)
    10001048{
     
    10151063}
    10161064
    1017 static krb5_error_code
     1065static krb5_error_code KRB5_CALLCONV
    10181066acc_lastchange(krb5_context context, krb5_ccache id, krb5_timestamp *mtime)
    10191067{
     
    10691117    acc_lastchange
    10701118};
     1119
     1120#endif
  • trunk/server/source4/heimdal/lib/krb5/add_et_list.c

    r414 r745  
    4848 */
    4949
    50 krb5_error_code KRB5_LIB_FUNCTION
     50KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5151krb5_add_et_list (krb5_context context,
    5252                  void (*func)(struct et_list **))
  • trunk/server/source4/heimdal/lib/krb5/addr_families.c

    r414 r745  
    176176    } else
    177177        p = address;
    178 #ifdef HAVE_INET_ATON
    179178    if(inet_aton(p, &a) == 0)
    180179        return -1;
    181 #elif defined(HAVE_INET_ADDR)
    182     a.s_addr = inet_addr(p);
    183     if(a.s_addr == INADDR_NONE)
    184         return -1;
    185 #else
    186     return -1;
    187 #endif
    188180    addr->addr_type = KRB5_ADDRESS_INET;
    189181    if(krb5_data_alloc(&addr->address, 4) != 0)
     
    340332{
    341333    char buf[128], buf2[3];
    342 #ifdef HAVE_INET_NTOP
    343334    if(inet_ntop(AF_INET6, addr->address.data, buf, sizeof(buf)) == NULL)
    344 #endif
    345335        {
    346336            /* XXX this is pretty ugly, but better than abort() */
     
    791781 */
    792782
    793 krb5_error_code KRB5_LIB_FUNCTION
     783KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    794784krb5_sockaddr2address (krb5_context context,
    795785                       const struct sockaddr *sa, krb5_address *addr)
     
    819809 */
    820810
    821 krb5_error_code KRB5_LIB_FUNCTION
     811KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    822812krb5_sockaddr2port (krb5_context context,
    823813                    const struct sockaddr *sa, int16_t *port)
     
    854844 */
    855845
    856 krb5_error_code KRB5_LIB_FUNCTION
     846KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    857847krb5_addr2sockaddr (krb5_context context,
    858848                    const krb5_address *addr,
     
    890880 */
    891881
    892 size_t KRB5_LIB_FUNCTION
     882KRB5_LIB_FUNCTION size_t KRB5_LIB_CALL
    893883krb5_max_sockaddr_size (void)
    894884{
     
    914904 */
    915905
    916 krb5_boolean KRB5_LIB_FUNCTION
     906KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    917907krb5_sockaddr_uninteresting(const struct sockaddr *sa)
    918908{
     
    942932 */
    943933
    944 krb5_error_code KRB5_LIB_FUNCTION
     934KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    945935krb5_h_addr2sockaddr (krb5_context context,
    946936                      int af,
     
    973963 */
    974964
    975 krb5_error_code KRB5_LIB_FUNCTION
     965KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    976966krb5_h_addr2addr (krb5_context context,
    977967                  int af,
     
    1004994 */
    1005995
    1006 krb5_error_code KRB5_LIB_FUNCTION
     996KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1007997krb5_anyaddr (krb5_context context,
    1008998              int af,
     
    10391029 */
    10401030
    1041 krb5_error_code KRB5_LIB_FUNCTION
     1031KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10421032krb5_print_address (const krb5_address *addr,
    10431033                    char *str, size_t len, size_t *ret_len)
     
    10891079 */
    10901080
    1091 krb5_error_code KRB5_LIB_FUNCTION
     1081KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10921082krb5_parse_address(krb5_context context,
    10931083                   const char *string,
     
    11701160 */
    11711161
    1172 int KRB5_LIB_FUNCTION
     1162KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    11731163krb5_address_order(krb5_context context,
    11741164                   const krb5_address *addr1,
     
    12191209 */
    12201210
    1221 krb5_boolean KRB5_LIB_FUNCTION
     1211KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    12221212krb5_address_compare(krb5_context context,
    12231213                     const krb5_address *addr1,
     
    12401230 */
    12411231
    1242 krb5_boolean KRB5_LIB_FUNCTION
     1232KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    12431233krb5_address_search(krb5_context context,
    12441234                    const krb5_address *addr,
     
    12651255 */
    12661256
    1267 krb5_error_code KRB5_LIB_FUNCTION
     1257KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12681258krb5_free_address(krb5_context context,
    12691259                  krb5_address *address)
     
    12891279 */
    12901280
    1291 krb5_error_code KRB5_LIB_FUNCTION
     1281KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12921282krb5_free_addresses(krb5_context context,
    12931283                    krb5_addresses *addresses)
     
    13151305 */
    13161306
    1317 krb5_error_code KRB5_LIB_FUNCTION
     1307KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13181308krb5_copy_address(krb5_context context,
    13191309                  const krb5_address *inaddr,
     
    13391329 */
    13401330
    1341 krb5_error_code KRB5_LIB_FUNCTION
     1331KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13421332krb5_copy_addresses(krb5_context context,
    13431333                    const krb5_addresses *inaddr,
     
    13661356 */
    13671357
    1368 krb5_error_code KRB5_LIB_FUNCTION
     1358KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13691359krb5_append_addresses(krb5_context context,
    13701360                      krb5_addresses *dest,
     
    14101400 */
    14111401
    1412 krb5_error_code KRB5_LIB_FUNCTION
     1402KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14131403krb5_make_addrport (krb5_context context,
    14141404                    krb5_address **res, const krb5_address *addr, int16_t port)
     
    14771467 */
    14781468
    1479 krb5_error_code KRB5_LIB_FUNCTION
     1469KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14801470krb5_address_prefixlen_boundary(krb5_context context,
    14811471                                const krb5_address *inaddr,
  • trunk/server/source4/heimdal/lib/krb5/appdefault.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 void KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    3737krb5_appdefault_boolean(krb5_context context, const char *appname,
    3838                        krb5_const_realm realm, const char *option,
     
    7676}
    7777
    78 void KRB5_LIB_FUNCTION
     78KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    7979krb5_appdefault_string(krb5_context context, const char *appname,
    8080                       krb5_const_realm realm, const char *option,
     
    120120}
    121121
    122 void KRB5_LIB_FUNCTION
     122KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    123123krb5_appdefault_time(krb5_context context, const char *appname,
    124124                     krb5_const_realm realm, const char *option,
  • trunk/server/source4/heimdal/lib/krb5/asn1_glue.c

    r414 r745  
    3838#include "krb5_locl.h"
    3939
    40 krb5_error_code KRB5_LIB_FUNCTION
     40KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4141_krb5_principal2principalname (PrincipalName *p,
    4242                               const krb5_principal from)
     
    4545}
    4646
    47 krb5_error_code KRB5_LIB_FUNCTION
     47KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4848_krb5_principalname2krb5_principal (krb5_context context,
    4949                                    krb5_principal *principal,
  • trunk/server/source4/heimdal/lib/krb5/auth_context.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_auth_con_init(krb5_context context,
    3838                   krb5_auth_context *auth_context)
     
    6565}
    6666
    67 krb5_error_code KRB5_LIB_FUNCTION
     67KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6868krb5_auth_con_free(krb5_context context,
    6969                   krb5_auth_context auth_context)
     
    8787}
    8888
    89 krb5_error_code KRB5_LIB_FUNCTION
     89KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9090krb5_auth_con_setflags(krb5_context context,
    9191                       krb5_auth_context auth_context,
     
    9797
    9898
    99 krb5_error_code KRB5_LIB_FUNCTION
     99KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    100100krb5_auth_con_getflags(krb5_context context,
    101101                       krb5_auth_context auth_context,
     
    106106}
    107107
    108 krb5_error_code KRB5_LIB_FUNCTION
     108KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    109109krb5_auth_con_addflags(krb5_context context,
    110110                       krb5_auth_context auth_context,
     
    118118}
    119119
    120 krb5_error_code KRB5_LIB_FUNCTION
     120KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    121121krb5_auth_con_removeflags(krb5_context context,
    122122                          krb5_auth_context auth_context,
     
    130130}
    131131
    132 krb5_error_code KRB5_LIB_FUNCTION
     132KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    133133krb5_auth_con_setaddrs(krb5_context context,
    134134                       krb5_auth_context auth_context,
     
    155155}
    156156
    157 krb5_error_code KRB5_LIB_FUNCTION
     157KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    158158krb5_auth_con_genaddrs(krb5_context context,
    159159                       krb5_auth_context auth_context,
    160                        int fd, int flags)
     160                       krb5_socket_t fd, int flags)
    161161{
    162162    krb5_error_code ret;
     
    171171        if (auth_context->local_address == NULL) {
    172172            len = sizeof(ss_local);
    173             if(getsockname(fd, local, &len) < 0) {
    174                 ret = errno;
    175                 krb5_set_error_message(context, ret,
    176                                        "getsockname: %s",
    177                                        strerror(ret));
     173            if(rk_IS_SOCKET_ERROR(getsockname(fd, local, &len))) {
     174                char buf[128];
     175                ret = rk_SOCK_ERRNO;
     176                rk_strerror_r(ret, buf, sizeof(buf));
     177                krb5_set_error_message(context, ret, "getsockname: %s", buf);
    178178                goto out;
    179179            }
     
    189189    if(flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR) {
    190190        len = sizeof(ss_remote);
    191         if(getpeername(fd, remote, &len) < 0) {
    192             ret = errno;
    193             krb5_set_error_message(context, ret,
    194                                    "getpeername: %s", strerror(ret));
     191        if(rk_IS_SOCKET_ERROR(getpeername(fd, remote, &len))) {
     192            char buf[128];
     193            ret = rk_SOCK_ERRNO;
     194            rk_strerror_r(ret, buf, sizeof(buf));
     195            krb5_set_error_message(context, ret, "getpeername: %s", buf);
    195196            goto out;
    196197        }
     
    216217}
    217218
    218 krb5_error_code KRB5_LIB_FUNCTION
     219KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    219220krb5_auth_con_setaddrs_from_fd (krb5_context context,
    220221                                krb5_auth_context auth_context,
    221222                                void *p_fd)
    222223{
    223     int fd = *(int*)p_fd;
     224    krb5_socket_t fd = *(krb5_socket_t *)p_fd;
    224225    int flags = 0;
    225226    if(auth_context->local_address == NULL)
     
    230231}
    231232
    232 krb5_error_code KRB5_LIB_FUNCTION
     233KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    233234krb5_auth_con_getaddrs(krb5_context context,
    234235                       krb5_auth_context auth_context,
     
    273274}
    274275
    275 krb5_error_code KRB5_LIB_FUNCTION
     276KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    276277krb5_auth_con_getkey(krb5_context context,
    277278                     krb5_auth_context auth_context,
     
    281282}
    282283
    283 krb5_error_code KRB5_LIB_FUNCTION
     284KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    284285krb5_auth_con_getlocalsubkey(krb5_context context,
    285286                             krb5_auth_context auth_context,
     
    289290}
    290291
    291 krb5_error_code KRB5_LIB_FUNCTION
     292KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    292293krb5_auth_con_getremotesubkey(krb5_context context,
    293294                              krb5_auth_context auth_context,
     
    297298}
    298299
    299 krb5_error_code KRB5_LIB_FUNCTION
     300KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    300301krb5_auth_con_setkey(krb5_context context,
    301302                     krb5_auth_context auth_context,
     
    307308}
    308309
    309 krb5_error_code KRB5_LIB_FUNCTION
     310KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    310311krb5_auth_con_setlocalsubkey(krb5_context context,
    311312                             krb5_auth_context auth_context,
     
    317318}
    318319
    319 krb5_error_code KRB5_LIB_FUNCTION
     320KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    320321krb5_auth_con_generatelocalsubkey(krb5_context context,
    321322                                  krb5_auth_context auth_context,
     
    337338
    338339
    339 krb5_error_code KRB5_LIB_FUNCTION
     340KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    340341krb5_auth_con_setremotesubkey(krb5_context context,
    341342                              krb5_auth_context auth_context,
     
    347348}
    348349
    349 krb5_error_code KRB5_LIB_FUNCTION
     350KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    350351krb5_auth_con_setcksumtype(krb5_context context,
    351352                           krb5_auth_context auth_context,
     
    356357}
    357358
    358 krb5_error_code KRB5_LIB_FUNCTION
     359KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    359360krb5_auth_con_getcksumtype(krb5_context context,
    360361                           krb5_auth_context auth_context,
     
    365366}
    366367
    367 krb5_error_code KRB5_LIB_FUNCTION
     368KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    368369krb5_auth_con_setkeytype (krb5_context context,
    369370                          krb5_auth_context auth_context,
     
    374375}
    375376
    376 krb5_error_code KRB5_LIB_FUNCTION
     377KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    377378krb5_auth_con_getkeytype (krb5_context context,
    378379                          krb5_auth_context auth_context,
     
    384385
    385386#if 0
    386 krb5_error_code KRB5_LIB_FUNCTION
     387KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    387388krb5_auth_con_setenctype(krb5_context context,
    388389                         krb5_auth_context auth_context,
     
    398399}
    399400
    400 krb5_error_code KRB5_LIB_FUNCTION
     401KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    401402krb5_auth_con_getenctype(krb5_context context,
    402403                         krb5_auth_context auth_context,
     
    407408#endif
    408409
    409 krb5_error_code KRB5_LIB_FUNCTION
     410KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    410411krb5_auth_con_getlocalseqnumber(krb5_context context,
    411412                            krb5_auth_context auth_context,
     
    416417}
    417418
    418 krb5_error_code KRB5_LIB_FUNCTION
     419KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    419420krb5_auth_con_setlocalseqnumber (krb5_context context,
    420421                             krb5_auth_context auth_context,
     
    425426}
    426427
    427 krb5_error_code KRB5_LIB_FUNCTION
    428 krb5_auth_getremoteseqnumber(krb5_context context,
    429                             krb5_auth_context auth_context,
    430                             int32_t *seqnumber)
     428KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     429krb5_auth_con_getremoteseqnumber(krb5_context context,
     430                                krb5_auth_context auth_context,
     431                                int32_t *seqnumber)
    431432{
    432433  *seqnumber = auth_context->remote_seqnumber;
     
    434435}
    435436
    436 krb5_error_code KRB5_LIB_FUNCTION
     437KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    437438krb5_auth_con_setremoteseqnumber (krb5_context context,
    438439                              krb5_auth_context auth_context,
     
    444445
    445446
    446 krb5_error_code KRB5_LIB_FUNCTION
     447KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    447448krb5_auth_con_getauthenticator(krb5_context context,
    448449                           krb5_auth_context auth_context,
     
    461462
    462463
    463 void KRB5_LIB_FUNCTION
     464KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    464465krb5_free_authenticator(krb5_context context,
    465466                        krb5_authenticator *authenticator)
     
    471472
    472473
    473 krb5_error_code KRB5_LIB_FUNCTION
     474KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    474475krb5_auth_con_setuserkey(krb5_context context,
    475476                         krb5_auth_context auth_context,
     
    481482}
    482483
    483 krb5_error_code KRB5_LIB_FUNCTION
     484KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    484485krb5_auth_con_getrcache(krb5_context context,
    485486                        krb5_auth_context auth_context,
     
    490491}
    491492
    492 krb5_error_code KRB5_LIB_FUNCTION
     493KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    493494krb5_auth_con_setrcache(krb5_context context,
    494495                        krb5_auth_context auth_context,
     
    501502#if 0 /* not implemented */
    502503
    503 krb5_error_code KRB5_LIB_FUNCTION
     504KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    504505krb5_auth_con_initivector(krb5_context context,
    505506                          krb5_auth_context auth_context)
     
    509510
    510511
    511 krb5_error_code KRB5_LIB_FUNCTION
     512KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    512513krb5_auth_con_setivector(krb5_context context,
    513514                         krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/build_ap_req.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_build_ap_req (krb5_context context,
    3838                   krb5_enctype enctype,
  • trunk/server/source4/heimdal/lib/krb5/build_auth.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    3636static krb5_error_code
     
    100100}
    101101
    102 krb5_error_code KRB5_LIB_FUNCTION
    103 krb5_build_authenticator (krb5_context context,
    104                           krb5_auth_context auth_context,
    105                           krb5_enctype enctype,
    106                           krb5_creds *cred,
    107                           Checksum *cksum,
    108                           Authenticator **auth_result,
    109                           krb5_data *result,
    110                           krb5_key_usage usage)
     102KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     103_krb5_build_authenticator (krb5_context context,
     104                           krb5_auth_context auth_context,
     105                           krb5_enctype enctype,
     106                           krb5_creds *cred,
     107                           Checksum *cksum,
     108                           krb5_data *result,
     109                           krb5_key_usage usage)
    111110{
    112     Authenticator *auth;
     111    Authenticator auth;
    113112    u_char *buf = NULL;
    114113    size_t buf_size;
     
    117116    krb5_crypto crypto;
    118117
    119     auth = calloc(1, sizeof(*auth));
    120     if (auth == NULL) {
    121         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    122         return ENOMEM;
    123     }
     118    memset(&auth, 0, sizeof(auth));
    124119
    125     auth->authenticator_vno = 5;
    126     copy_Realm(&cred->client->realm, &auth->crealm);
    127     copy_PrincipalName(&cred->client->name, &auth->cname);
     120    auth.authenticator_vno = 5;
     121    copy_Realm(&cred->client->realm, &auth.crealm);
     122    copy_PrincipalName(&cred->client->name, &auth.cname);
    128123
    129     krb5_us_timeofday (context, &auth->ctime, &auth->cusec);
     124    krb5_us_timeofday (context, &auth.ctime, &auth.cusec);
    130125
    131     ret = krb5_auth_con_getlocalsubkey(context, auth_context, &auth->subkey);
     126    ret = krb5_auth_con_getlocalsubkey(context, auth_context, &auth.subkey);
    132127    if(ret)
    133128        goto fail;
     
    138133                                      &cred->session,
    139134                                      &auth_context->local_seqnumber);
    140         ALLOC(auth->seq_number, 1);
    141         if(auth->seq_number == NULL) {
     135        ALLOC(auth.seq_number, 1);
     136        if(auth.seq_number == NULL) {
    142137            ret = ENOMEM;
    143138            goto fail;
    144139        }
    145         *auth->seq_number = auth_context->local_seqnumber;
     140        *auth.seq_number = auth_context->local_seqnumber;
    146141    } else
    147         auth->seq_number = NULL;
    148     auth->authorization_data = NULL;
    149     auth->cksum = cksum;
     142        auth.seq_number = NULL;
     143    auth.authorization_data = NULL;
    150144
    151     if (cksum != NULL && cksum->cksumtype == CKSUMTYPE_GSSAPI) {
    152         /*
    153          * This is not GSS-API specific, we only enable it for
    154          * GSS for now
    155          */
    156         ret = make_etypelist(context, &auth->authorization_data);
     145    if (cksum) {
     146        ALLOC(auth.cksum, 1);
     147        if (auth.cksum == NULL) {
     148            ret = ENOMEM;
     149            goto fail;
     150        }
     151        ret = copy_Checksum(cksum, auth.cksum);
    157152        if (ret)
    158153            goto fail;
     154
     155        if (auth.cksum->cksumtype == CKSUMTYPE_GSSAPI) {
     156            /*
     157             * This is not GSS-API specific, we only enable it for
     158             * GSS for now
     159             */
     160            ret = make_etypelist(context, &auth.authorization_data);
     161            if (ret)
     162                goto fail;
     163        }
    159164    }
    160165
    161166    /* XXX - Copy more to auth_context? */
    162167
    163     auth_context->authenticator->ctime = auth->ctime;
    164     auth_context->authenticator->cusec = auth->cusec;
     168    auth_context->authenticator->ctime = auth.ctime;
     169    auth_context->authenticator->cusec = auth.cusec;
    165170
    166     ASN1_MALLOC_ENCODE(Authenticator, buf, buf_size, auth, &len, ret);
     171    ASN1_MALLOC_ENCODE(Authenticator, buf, buf_size, &auth, &len, ret);
    167172    if (ret)
    168173        goto fail;
     
    176181                        crypto,
    177182                        usage /* KRB5_KU_AP_REQ_AUTH */,
    178                         buf + buf_size - len,
     183                        buf,
    179184                        len,
    180185                        result);
     
    184189        goto fail;
    185190
     191 fail:
     192    free_Authenticator (&auth);
    186193    free (buf);
    187194
    188     if (auth_result)
    189         *auth_result = auth;
    190     else {
    191         /* Don't free the `cksum', it's allocated by the caller */
    192         auth->cksum = NULL;
    193         free_Authenticator (auth);
    194         free (auth);
    195     }
    196     return ret;
    197   fail:
    198     free_Authenticator (auth);
    199     free (auth);
    200     free (buf);
    201195    return ret;
    202196}
  • trunk/server/source4/heimdal/lib/krb5/cache.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    8284        char *principal;
    8385
    84         krb5_unparse_name_short(context, creds.server, &principal);
     86        krb5_unparse_name(context, creds.server, &principal);
    8587        printf("principal: %s\\n", principal);
    8688        free(principal);
     
    113115 */
    114116
    115 krb5_error_code KRB5_LIB_FUNCTION
     117KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    116118krb5_cc_register(krb5_context context,
    117119                 const krb5_cc_ops *ops,
     
    120122    int i;
    121123
    122     for(i = 0; i < context->num_cc_ops && context->cc_ops[i].prefix; i++) {
    123         if(strcmp(context->cc_ops[i].prefix, ops->prefix) == 0) {
     124    for(i = 0; i < context->num_cc_ops && context->cc_ops[i]->prefix; i++) {
     125        if(strcmp(context->cc_ops[i]->prefix, ops->prefix) == 0) {
    124126            if(!override) {
    125127                krb5_set_error_message(context,
     
    133135    }
    134136    if(i == context->num_cc_ops) {
    135         krb5_cc_ops *o = realloc(context->cc_ops,
    136                                  (context->num_cc_ops + 1) *
    137                                  sizeof(*context->cc_ops));
     137        const krb5_cc_ops **o = realloc(rk_UNCONST(context->cc_ops),
     138                                        (context->num_cc_ops + 1) *
     139                                        sizeof(context->cc_ops[0]));
    138140        if(o == NULL) {
    139141            krb5_set_error_message(context, KRB5_CC_NOMEM,
     
    141143            return KRB5_CC_NOMEM;
    142144        }
     145        context->cc_ops = o;
     146        context->cc_ops[context->num_cc_ops] = NULL;
    143147        context->num_cc_ops++;
    144         context->cc_ops = o;
    145         memset(context->cc_ops + i, 0,
    146                (context->num_cc_ops - i) * sizeof(*context->cc_ops));
    147     }
    148     memcpy(&context->cc_ops[i], ops, sizeof(context->cc_ops[i]));
     148    }
     149    context->cc_ops[i] = ops;
    149150    return 0;
    150151}
     
    186187{
    187188    krb5_error_code ret;
    188 
    189     ret = _krb5_cc_allocate(context, ops, id);
     189#ifdef KRB5_USE_PATH_TOKENS
     190    char * exp_residual = NULL;
     191
     192    ret = _krb5_expand_path_tokens(context, residual, &exp_residual);
    190193    if (ret)
    191194        return ret;
     195
     196    residual = exp_residual;
     197#endif
     198
     199    ret = _krb5_cc_allocate(context, ops, id);
     200    if (ret) {
     201#ifdef KRB5_USE_PATH_TOKENS
     202        if (exp_residual)
     203            free(exp_residual);
     204#endif
     205        return ret;
     206    }
     207
    192208    ret = (*id)->ops->resolve(context, id, residual);
    193     if(ret)
     209    if(ret) {
    194210        free(*id);
     211        *id = NULL;
     212    }
     213
     214#ifdef KRB5_USE_PATH_TOKENS
     215    if (exp_residual)
     216        free(exp_residual);
     217#endif
     218
    195219    return ret;
     220}
     221
     222static int
     223is_possible_path_name(const char * name)
     224{
     225    const char * colon;
     226
     227    if ((colon = strchr(name, ':')) == NULL)
     228        return TRUE;
     229
     230#ifdef _WIN32
     231    /* <drive letter>:\path\to\cache ? */
     232
     233    if (colon == name + 1 &&
     234        strchr(colon + 1, ':') == NULL)
     235        return TRUE;
     236#endif
     237
     238    return FALSE;
    196239}
    197240
     
    211254
    212255
    213 krb5_error_code KRB5_LIB_FUNCTION
     256KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    214257krb5_cc_resolve(krb5_context context,
    215258                const char *name,
     
    220263    *id = NULL;
    221264
    222     for(i = 0; i < context->num_cc_ops && context->cc_ops[i].prefix; i++) {
    223         size_t prefix_len = strlen(context->cc_ops[i].prefix);
    224 
    225         if(strncmp(context->cc_ops[i].prefix, name, prefix_len) == 0
     265    for(i = 0; i < context->num_cc_ops && context->cc_ops[i]->prefix; i++) {
     266        size_t prefix_len = strlen(context->cc_ops[i]->prefix);
     267
     268        if(strncmp(context->cc_ops[i]->prefix, name, prefix_len) == 0
    226269           && name[prefix_len] == ':') {
    227             return allocate_ccache (context, &context->cc_ops[i],
     270            return allocate_ccache (context, context->cc_ops[i],
    228271                                    name + prefix_len + 1,
    229272                                    id);
    230273        }
    231274    }
    232     if (strchr (name, ':') == NULL)
     275    if (is_possible_path_name(name))
    233276        return allocate_ccache (context, &krb5_fcc_ops, name, id);
    234277    else {
     
    251294 */
    252295
    253 krb5_error_code KRB5_LIB_FUNCTION
     296KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    254297krb5_cc_new_unique(krb5_context context, const char *type,
    255298                   const char *hint, krb5_ccache *id)
     
    283326
    284327
    285 const char* KRB5_LIB_FUNCTION
     328KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    286329krb5_cc_get_name(krb5_context context,
    287330                 krb5_ccache id)
     
    297340
    298341
    299 const char* KRB5_LIB_FUNCTION
     342KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    300343krb5_cc_get_type(krb5_context context,
    301344                 krb5_ccache id)
     
    305348
    306349/**
    307  * Return the complete resolvable name the ccache `id' in `strÂŽ.
    308  * `str` should be freed with free(3).
    309  * Returns 0 or an error (and then *str is set to NULL).
    310  *
    311  * @ingroup krb5_ccache
    312  */
    313 
    314 
    315 krb5_error_code KRB5_LIB_FUNCTION
     350 * Return the complete resolvable name the cache
     351
     352 * @param context a Keberos context
     353 * @param id return pointer to a found credential cache
     354 * @param str the returned name of a credential cache, free with krb5_xfree()
     355 *
     356 * @return Returns 0 or an error (and then *str is set to NULL).
     357 *
     358 * @ingroup krb5_ccache
     359 */
     360
     361
     362KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    316363krb5_cc_get_full_name(krb5_context context,
    317364                      krb5_ccache id,
     
    351398
    352399
    353 const krb5_cc_ops *
     400KRB5_LIB_FUNCTION const krb5_cc_ops * KRB5_LIB_CALL
    354401krb5_cc_get_ops(krb5_context context, krb5_ccache id)
    355402{
     
    364411_krb5_expand_default_cc_name(krb5_context context, const char *str, char **res)
    365412{
    366     size_t tlen, len = 0;
    367     char *tmp, *tmp2, *append;
    368 
    369     *res = NULL;
    370 
    371     while (str && *str) {
    372         tmp = strstr(str, "%{");
    373         if (tmp && tmp != str) {
    374             append = malloc((tmp - str) + 1);
    375             if (append) {
    376                 memcpy(append, str, tmp - str);
    377                 append[tmp - str] = '\0';
    378             }
    379             str = tmp;
    380         } else if (tmp) {
    381             tmp2 = strchr(tmp, '}');
    382             if (tmp2 == NULL) {
    383                 free(*res);
    384                 *res = NULL;
    385                 krb5_set_error_message(context, KRB5_CONFIG_BADFORMAT,
    386                                        "variable missing }");
    387                 return KRB5_CONFIG_BADFORMAT;
    388             }
    389             if (strncasecmp(tmp, "%{uid}", 6) == 0)
    390                 asprintf(&append, "%u", (unsigned)getuid());
    391             else if (strncasecmp(tmp, "%{null}", 7) == 0)
    392                 append = strdup("");
    393             else {
    394                 free(*res);
    395                 *res = NULL;
    396                 krb5_set_error_message(context,
    397                                        KRB5_CONFIG_BADFORMAT,
    398                                        "expand default cache unknown "
    399                                        "variable \"%.*s\"",
    400                                        (int)(tmp2 - tmp) - 2, tmp + 2);
    401                 return KRB5_CONFIG_BADFORMAT;
    402             }
    403             str = tmp2 + 1;
    404         } else {
    405             append = strdup(str);
    406             str = NULL;
    407         }
    408         if (append == NULL) {
    409             free(*res);
    410             *res = NULL;
    411             krb5_set_error_message(context, ENOMEM,
    412                                    N_("malloc: out of memory", ""));
    413             return ENOMEM;
    414         }
    415        
    416         tlen = strlen(append);
    417         tmp = realloc(*res, len + tlen + 1);
    418         if (tmp == NULL) {
    419             free(append);
    420             free(*res);
    421             *res = NULL;
    422             krb5_set_error_message(context, ENOMEM,
    423                                    N_("malloc: out of memory", ""));
    424             return ENOMEM;
    425         }
    426         *res = tmp;
    427         memcpy(*res + len, append, tlen + 1);
    428         len = len + tlen;
    429         free(append);
    430     }
    431     return 0;
     413    return _krb5_expand_path_tokens(context, str, res);
    432414}
    433415
     
    445427    if (context->default_cc_name_set)
    446428        return 0;
     429
     430    /* XXX performance: always ask KCM/API if default name has changed */
     431    if (context->default_cc_name &&
     432        (strncmp(context->default_cc_name, "KCM:", 4) == 0 ||
     433         strncmp(context->default_cc_name, "API:", 4) == 0))
     434        return 1;
    447435
    448436    if(issuid())
     
    474462 */
    475463
    476 krb5_error_code
     464KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    477465krb5_cc_switch(krb5_context context, krb5_ccache id)
    478466{
     
    485473
    486474/**
     475 * Return true if the default credential cache support switch
     476 *
     477 * @ingroup krb5_ccache
     478 */
     479
     480KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
     481krb5_cc_support_switch(krb5_context context, const char *type)
     482{
     483    const krb5_cc_ops *ops;
     484
     485    ops = krb5_cc_get_prefix_ops(context, type);
     486    if (ops && ops->set_default)
     487        return 1;
     488    return FALSE;
     489}
     490
     491/**
    487492 * Set the default cc name for `context' to `name'.
    488493 *
     
    490495 */
    491496
    492 krb5_error_code KRB5_LIB_FUNCTION
     497KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    493498krb5_cc_set_default_name(krb5_context context, const char *name)
    494499{
    495500    krb5_error_code ret = 0;
    496     char *p;
     501    char *p = NULL, *exp_p = NULL;
    497502
    498503    if (name == NULL) {
     
    508513            }
    509514        }
     515
     516#ifdef _WIN32
     517        if (e == NULL) {
     518            e = p = _krb5_get_default_cc_name_from_registry();
     519        }
     520#endif
    510521        if (e == NULL) {
    511522            e = krb5_config_get_string(context, NULL, "libdefaults",
     
    546557    }
    547558
     559    ret = _krb5_expand_path_tokens(context, p, &exp_p);
     560    free(p);
     561    if (ret)
     562        return ret;
     563
    548564    if (context->default_cc_name)
    549565        free(context->default_cc_name);
    550566
    551     context->default_cc_name = p;
    552 
    553     return ret;
     567    context->default_cc_name = exp_p;
     568
     569    return 0;
    554570}
    555571
     
    564580
    565581
    566 const char* KRB5_LIB_FUNCTION
     582KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    567583krb5_cc_default_name(krb5_context context)
    568584{
     
    582598
    583599
    584 krb5_error_code KRB5_LIB_FUNCTION
     600KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    585601krb5_cc_default(krb5_context context,
    586602                krb5_ccache *id)
     
    604620
    605621
    606 krb5_error_code KRB5_LIB_FUNCTION
     622KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    607623krb5_cc_initialize(krb5_context context,
    608624                   krb5_ccache id,
     
    622638
    623639
    624 krb5_error_code KRB5_LIB_FUNCTION
     640KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    625641krb5_cc_destroy(krb5_context context,
    626642                krb5_ccache id)
     
    642658
    643659
    644 krb5_error_code KRB5_LIB_FUNCTION
     660KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    645661krb5_cc_close(krb5_context context,
    646662              krb5_ccache id)
     
    661677
    662678
    663 krb5_error_code KRB5_LIB_FUNCTION
     679KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    664680krb5_cc_store_cred(krb5_context context,
    665681                   krb5_ccache id,
     
    674690 * krb5_free_cred_contents.
    675691 *
    676  * @return Return an error code or 0, see krb5_get_error_message().
    677  *
    678  * @ingroup krb5_ccache
    679  */
    680 
    681 
    682 krb5_error_code KRB5_LIB_FUNCTION
     692 * @param context A Kerberos 5 context
     693 * @param id a Kerberos 5 credential cache
     694 * @param whichfields what fields to use for matching credentials, same
     695 *        flags as whichfields in krb5_compare_creds()
     696 * @param mcreds template credential to use for comparing
     697 * @param creds returned credential, free with krb5_free_cred_contents()
     698 *
     699 * @return Return an error code or 0, see krb5_get_error_message().
     700 *
     701 * @ingroup krb5_ccache
     702 */
     703
     704
     705KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    683706krb5_cc_retrieve_cred(krb5_context context,
    684707                      krb5_ccache id,
     
    718741
    719742
    720 krb5_error_code KRB5_LIB_FUNCTION
     743KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    721744krb5_cc_get_principal(krb5_context context,
    722745                      krb5_ccache id,
     
    736759
    737760
    738 krb5_error_code KRB5_LIB_FUNCTION
     761KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    739762krb5_cc_start_seq_get (krb5_context context,
    740763                       const krb5_ccache id,
     
    754777
    755778
    756 krb5_error_code KRB5_LIB_FUNCTION
     779KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    757780krb5_cc_next_cred (krb5_context context,
    758781                   const krb5_ccache id,
     
    770793
    771794
    772 krb5_error_code KRB5_LIB_FUNCTION
     795KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    773796krb5_cc_end_seq_get (krb5_context context,
    774797                     const krb5_ccache id,
     
    785808
    786809
    787 krb5_error_code KRB5_LIB_FUNCTION
     810KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    788811krb5_cc_remove_cred(krb5_context context,
    789812                    krb5_ccache id,
     
    808831
    809832
    810 krb5_error_code KRB5_LIB_FUNCTION
     833KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    811834krb5_cc_set_flags(krb5_context context,
    812835                  krb5_ccache id,
     
    822845 */
    823846
    824 krb5_error_code KRB5_LIB_FUNCTION
     847KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    825848krb5_cc_get_flags(krb5_context context,
    826849                  krb5_ccache id,
     
    847870 */
    848871
    849 krb5_error_code KRB5_LIB_FUNCTION
     872KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    850873krb5_cc_copy_match_f(krb5_context context,
    851874                     const krb5_ccache from,
     
    900923 */
    901924
    902 krb5_error_code KRB5_LIB_FUNCTION
     925KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    903926krb5_cc_copy_cache(krb5_context context,
    904927                   const krb5_ccache from,
     
    915938
    916939
    917 krb5_error_code KRB5_LIB_FUNCTION
     940KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    918941krb5_cc_get_version(krb5_context context,
    919942                    const krb5_ccache id)
     
    932955
    933956
    934 void KRB5_LIB_FUNCTION
     957KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    935958krb5_cc_clear_mcred(krb5_creds *mcred)
    936959{
     
    951974
    952975
    953 const krb5_cc_ops *
     976KRB5_LIB_FUNCTION const krb5_cc_ops * KRB5_LIB_CALL
    954977krb5_cc_get_prefix_ops(krb5_context context, const char *prefix)
    955978{
     
    971994        *p1 = '\0';
    972995
    973     for(i = 0; i < context->num_cc_ops && context->cc_ops[i].prefix; i++) {
    974         if(strcmp(context->cc_ops[i].prefix, p) == 0) {
     996    for(i = 0; i < context->num_cc_ops && context->cc_ops[i]->prefix; i++) {
     997        if(strcmp(context->cc_ops[i]->prefix, p) == 0) {
    975998            free(p);
    976             return &context->cc_ops[i];
     999            return context->cc_ops[i];
    9771000        }
    9781001    }
     
    10001023
    10011024
    1002 krb5_error_code KRB5_LIB_FUNCTION
     1025KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10031026krb5_cc_cache_get_first (krb5_context context,
    10041027                         const char *type,
     
    10471070 * and advance `cursor'.
    10481071 *
     1072 * @param context A Kerberos 5 context
     1073 * @param cursor the iterator cursor, returned by krb5_cc_cache_get_first()
     1074 * @param id next ccache
     1075 *
    10491076 * @return Return 0 or an error code. Returns KRB5_CC_END when the end
    10501077 *         of caches is reached, see krb5_get_error_message().
     
    10541081
    10551082
    1056 krb5_error_code KRB5_LIB_FUNCTION
     1083KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10571084krb5_cc_cache_next (krb5_context context,
    10581085                   krb5_cc_cache_cursor cursor,
     
    10711098
    10721099
    1073 krb5_error_code KRB5_LIB_FUNCTION
     1100KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10741101krb5_cc_cache_end_seq_get (krb5_context context,
    10751102                           krb5_cc_cache_cursor cursor)
     
    10971124
    10981125
    1099 krb5_error_code KRB5_LIB_FUNCTION
     1126KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11001127krb5_cc_cache_match (krb5_context context,
    11011128                     krb5_principal client,
     
    11631190 */
    11641191
    1165 krb5_error_code
     1192KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11661193krb5_cc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
    11671194{
     
    12311258 */
    12321259
    1233 krb5_boolean KRB5_LIB_FUNCTION
     1260KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    12341261krb5_is_config_principal(krb5_context context,
    12351262                         krb5_const_principal principal)
     
    12591286 */
    12601287
    1261 krb5_error_code KRB5_LIB_FUNCTION
     1288KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12621289krb5_cc_set_config(krb5_context context, krb5_ccache id,
    12631290                   krb5_const_principal principal,
     
    13071334
    13081335
    1309 krb5_error_code KRB5_LIB_FUNCTION
     1336KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13101337krb5_cc_get_config(krb5_context context, krb5_ccache id,
    13111338                   krb5_const_principal principal,
     
    13381365 */
    13391366
    1340 struct krb5_cccol_cursor {
     1367struct krb5_cccol_cursor_data {
    13411368    int idx;
    13421369    krb5_cc_cache_cursor cursor;
     
    13551382 */
    13561383
    1357 krb5_error_code KRB5_LIB_FUNCTION
     1384KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13581385krb5_cccol_cursor_new(krb5_context context, krb5_cccol_cursor *cursor)
    13591386{
     
    13871414
    13881415
    1389 krb5_error_code KRB5_LIB_FUNCTION
     1416KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13901417krb5_cccol_cursor_next(krb5_context context, krb5_cccol_cursor cursor,
    13911418                       krb5_ccache *cache)
     
    13991426        if (cursor->cursor == NULL) {
    14001427            ret = krb5_cc_cache_get_first (context,
    1401                                            context->cc_ops[cursor->idx].prefix,
     1428                                           context->cc_ops[cursor->idx]->prefix,
    14021429                                           &cursor->cursor);
    14031430            if (ret) {
     
    14141441        if (ret != KRB5_CC_END)
    14151442            break;
    1416        
     1443
    14171444        cursor->idx++;
    14181445    }
     
    14381465 */
    14391466
    1440 krb5_error_code KRB5_LIB_FUNCTION
     1467KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14411468krb5_cccol_cursor_free(krb5_context context, krb5_cccol_cursor *cursor)
    14421469{
     
    14651492
    14661493
    1467 krb5_error_code KRB5_LIB_FUNCTION
     1494KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14681495krb5_cc_last_change_time(krb5_context context,
    14691496                         krb5_ccache id,
     
    14881515 */
    14891516
    1490 krb5_error_code KRB5_LIB_FUNCTION
     1517KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14911518krb5_cccol_last_change_time(krb5_context context,
    14921519                            const char *type,
     
    15291556 */
    15301557
    1531 krb5_error_code KRB5_LIB_FUNCTION
     1558KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    15321559krb5_cc_get_friendly_name(krb5_context context,
    15331560                          krb5_ccache id,
     
    15661593 */
    15671594
    1568 krb5_error_code KRB5_LIB_FUNCTION
     1595KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    15691596krb5_cc_set_friendly_name(krb5_context context,
    15701597                          krb5_ccache id,
     
    15941621 */
    15951622
    1596 krb5_error_code KRB5_LIB_FUNCTION
     1623KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    15971624krb5_cc_get_lifetime(krb5_context context, krb5_ccache id, time_t *t)
    15981625{
     
    16141641                *t = cred.times.endtime - now;
    16151642            krb5_free_cred_contents(context, &cred);
    1616             goto out;
     1643            break;
    16171644        }
    16181645        krb5_free_cred_contents(context, &cred);
    16191646    }
    16201647   
    1621  out:
    16221648    krb5_cc_end_seq_get(context, id, &cursor);
    16231649
    16241650    return ret;
    16251651}
     1652
     1653/**
     1654 * Set the time offset betwen the client and the KDC
     1655 *
     1656 * If the backend doesn't support KDC offset, use the context global setting.
     1657 *
     1658 * @param context A Kerberos 5 context.
     1659 * @param id a credential cache
     1660 * @param offset the offset in seconds
     1661 *
     1662 * @return Return an error code or 0, see krb5_get_error_message().
     1663 *
     1664 * @ingroup krb5_ccache
     1665 */
     1666
     1667KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     1668krb5_cc_set_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat offset)
     1669{
     1670    if (id->ops->set_kdc_offset == NULL) {
     1671        context->kdc_sec_offset = offset;
     1672        context->kdc_usec_offset = 0;
     1673        return 0;
     1674    }
     1675    return (*id->ops->set_kdc_offset)(context, id, offset);
     1676}
     1677
     1678/**
     1679 * Get the time offset betwen the client and the KDC
     1680 *
     1681 * If the backend doesn't support KDC offset, use the context global setting.
     1682 *
     1683 * @param context A Kerberos 5 context.
     1684 * @param id a credential cache
     1685 * @param offset the offset in seconds
     1686 *
     1687 * @return Return an error code or 0, see krb5_get_error_message().
     1688 *
     1689 * @ingroup krb5_ccache
     1690 */
     1691
     1692KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     1693krb5_cc_get_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat *offset)
     1694{
     1695    if (id->ops->get_kdc_offset == NULL) {
     1696        *offset = context->kdc_sec_offset;
     1697        return 0;
     1698    }
     1699    return (*id->ops->get_kdc_offset)(context, id, offset);
     1700}
     1701
     1702
     1703#ifdef _WIN32
     1704
     1705char *
     1706_krb5_get_default_cc_name_from_registry()
     1707{
     1708    HKEY hk_k5 = 0;
     1709    LONG code;
     1710    char * ccname = NULL;
     1711
     1712    code = RegOpenKeyEx(HKEY_CURRENT_USER,
     1713                        "Software\\MIT\\Kerberos5",
     1714                        0, KEY_READ, &hk_k5);
     1715
     1716    if (code != ERROR_SUCCESS)
     1717        return NULL;
     1718
     1719    ccname = _krb5_parse_reg_value_as_string(NULL, hk_k5, "ccname",
     1720                                             REG_NONE, 0);
     1721
     1722    RegCloseKey(hk_k5);
     1723
     1724    return ccname;
     1725}
     1726
     1727#endif
  • trunk/server/source4/heimdal/lib/krb5/changepw.c

    r414 r745  
    3434#define KRB5_DEPRECATED
    3535
    36 #include <krb5_locl.h>
     36#include "krb5_locl.h"
    3737
    3838#undef __attribute__
     
    7373                    krb5_principal targprinc,
    7474                    int is_stream,
    75                     int sock,
     75                    rk_socket_t sock,
    7676                    const char *passwd,
    7777                    const char *host)
     
    142142    iov[2].iov_len     = krb_priv_data.length;
    143143
    144     if (sendmsg (sock, &msghdr, 0) < 0) {
    145         ret = errno;
     144    if (rk_IS_SOCKET_ERROR( sendmsg (sock, &msghdr, 0) )) {
     145        ret = rk_SOCK_ERRNO;
    146146        krb5_set_error_message(context, ret, "sendmsg %s: %s",
    147147                               host, strerror(ret));
     
    165165                    krb5_principal targprinc,
    166166                    int is_stream,
    167                     int sock,
     167                    rk_socket_t sock,
    168168                    const char *passwd,
    169169                    const char *host)
     
    252252    iov[2].iov_len     = krb_priv_data.length;
    253253
    254     if (sendmsg (sock, &msghdr, 0) < 0) {
    255         ret = errno;
     254    if (rk_IS_SOCKET_ERROR( sendmsg (sock, &msghdr, 0) )) {
     255        ret = rk_SOCK_ERRNO;
    256256        krb5_set_error_message(context, ret, "sendmsg %s: %s",
    257257                               host, strerror(ret));
     
    269269               krb5_auth_context auth_context,
    270270               int is_stream,
    271                int sock,
     271               rk_socket_t sock,
    272272               int *result_code,
    273273               krb5_data *result_code_string,
     
    289289            ret = recvfrom (sock, reply + len, sizeof(reply) - len,
    290290                            0, NULL, NULL);
    291             if (ret < 0) {
    292                 save_errno = errno;
     291            if (rk_IS_SOCKET_ERROR(ret)) {
     292                save_errno = rk_SOCK_ERRNO;
    293293                krb5_set_error_message(context, save_errno,
    294294                                       "recvfrom %s: %s",
     
    317317    } else {
    318318        ret = recvfrom (sock, reply, sizeof(reply), 0, NULL, NULL);
    319         if (ret < 0) {
    320             save_errno = errno;
     319        if (rk_IS_SOCKET_ERROR(ret)) {
     320            save_errno = rk_SOCK_ERRNO;
    321321            krb5_set_error_message(context, save_errno,
    322322                                   "recvfrom %s: %s",
     
    465465                                              krb5_principal,
    466466                                              int,
    467                                               int,
     467                                              rk_socket_t,
    468468                                              const char *,
    469469                                              const char *);
     
    471471                                               krb5_auth_context,
    472472                                               int,
    473                                                int,
     473                                               rk_socket_t,
    474474                                               int *,
    475475                                               krb5_data *,
     
    518518    krb5_krbhst_handle handle = NULL;
    519519    krb5_krbhst_info *hi;
    520     int sock;
     520    rk_socket_t sock;
    521521    unsigned int i;
    522522    int done = 0;
     
    566566
    567567            sock = socket (a->ai_family, a->ai_socktype | SOCK_CLOEXEC, a->ai_protocol);
    568             if (sock < 0)
     568            if (rk_IS_BAD_SOCKET(sock))
    569569                continue;
    570570            rk_cloexec(sock);
    571571
    572572            ret = connect(sock, a->ai_addr, a->ai_addrlen);
    573             if (ret < 0) {
    574                 close (sock);
     573            if (rk_IS_SOCKET_ERROR(ret)) {
     574                rk_closesocket (sock);
    575575                goto out;
    576576            }
     
    579579                                          KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR);
    580580            if (ret) {
    581                 close (sock);
     581                rk_closesocket (sock);
    582582                goto out;
    583583            }
     
    599599                                             hi->hostname);
    600600                    if (ret) {
    601                         close(sock);
     601                        rk_closesocket(sock);
    602602                        goto out;
    603603                    }
    604604                }
    605        
     605
     606#ifndef NO_LIMIT_FD_SETSIZE
    606607                if (sock >= FD_SETSIZE) {
    607608                    ret = ERANGE;
    608609                    krb5_set_error_message(context, ret,
    609610                                           "fd %d too large", sock);
    610                     close (sock);
     611                    rk_closesocket (sock);
    611612                    goto out;
    612613                }
     614#endif
    613615
    614616                FD_ZERO(&fdset);
     
    618620
    619621                ret = select (sock + 1, &fdset, NULL, NULL, &tv);
    620                 if (ret < 0 && errno != EINTR) {
    621                     close(sock);
     622                if (rk_IS_SOCKET_ERROR(ret) && rk_SOCK_ERRNO != EINTR) {
     623                    rk_closesocket(sock);
    622624                    goto out;
    623625                }
     
    639641                }
    640642            }
    641             close (sock);
     643            rk_closesocket (sock);
    642644        }
    643645    }
     
    671673
    672674/**
    673  * krb5_change_password() is deprecated, use krb5_set_password().
     675 * Deprecated: krb5_change_password() is deprecated, use krb5_set_password().
    674676 *
    675677 * @param context a Keberos context
     
    685687 */
    686688
    687 krb5_error_code KRB5_LIB_FUNCTION
     689KRB5_DEPRECATED
     690KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    688691krb5_change_password (krb5_context      context,
    689692                      krb5_creds        *creds,
     
    692695                      krb5_data         *result_code_string,
    693696                      krb5_data         *result_string)
    694     KRB5_DEPRECATED
    695697{
    696698    struct kpwd_proc *p = find_chpw_proto("change password");
     
    727729 */
    728730
    729 krb5_error_code KRB5_LIB_FUNCTION
     731KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    730732krb5_set_password(krb5_context context,
    731733                  krb5_creds *creds,
     
    770772 */
    771773
    772 krb5_error_code KRB5_LIB_FUNCTION
     774KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    773775krb5_set_password_using_ccache(krb5_context context,
    774776                               krb5_ccache ccache,
     
    835837 */
    836838
    837 const char* KRB5_LIB_FUNCTION
     839KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    838840krb5_passwd_result_to_string (krb5_context context,
    839841                              int result)
  • trunk/server/source4/heimdal/lib/krb5/codec.c

    r414 r745  
    3838#ifndef HEIMDAL_SMALLER
    3939
    40 krb5_error_code KRB5_LIB_FUNCTION
     40KRB5_DEPRECATED
     41KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4142krb5_decode_EncTicketPart (krb5_context context,
    4243                           const void *data,
     
    4445                           EncTicketPart *t,
    4546                           size_t *len)
    46     KRB5_DEPRECATED
    4747{
    4848    return decode_EncTicketPart(data, length, t, len);
    4949}
    5050
    51 krb5_error_code KRB5_LIB_FUNCTION
     51KRB5_DEPRECATED
     52KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5253krb5_encode_EncTicketPart (krb5_context context,
    5354                           void *data,
     
    5556                           EncTicketPart *t,
    5657                           size_t *len)
    57     KRB5_DEPRECATED
    5858{
    5959    return encode_EncTicketPart(data, length, t, len);
    6060}
    6161
    62 krb5_error_code KRB5_LIB_FUNCTION
     62KRB5_DEPRECATED
     63KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6364krb5_decode_EncASRepPart (krb5_context context,
    6465                          const void *data,
     
    6667                          EncASRepPart *t,
    6768                          size_t *len)
    68     KRB5_DEPRECATED
    6969{
    7070    return decode_EncASRepPart(data, length, t, len);
    7171}
    7272
    73 krb5_error_code KRB5_LIB_FUNCTION
     73KRB5_DEPRECATED
     74KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    7475krb5_encode_EncASRepPart (krb5_context context,
    7576                          void *data,
     
    7778                          EncASRepPart *t,
    7879                          size_t *len)
    79     KRB5_DEPRECATED
    8080{
    8181    return encode_EncASRepPart(data, length, t, len);
    8282}
    8383
    84 krb5_error_code KRB5_LIB_FUNCTION
     84KRB5_DEPRECATED
     85KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    8586krb5_decode_EncTGSRepPart (krb5_context context,
    8687                           const void *data,
     
    8889                           EncTGSRepPart *t,
    8990                           size_t *len)
    90     KRB5_DEPRECATED
    9191{
    9292    return decode_EncTGSRepPart(data, length, t, len);
    9393}
    9494
    95 krb5_error_code KRB5_LIB_FUNCTION
     95KRB5_DEPRECATED
     96KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9697krb5_encode_EncTGSRepPart (krb5_context context,
    9798                           void *data,
     
    99100                           EncTGSRepPart *t,
    100101                           size_t *len)
    101     KRB5_DEPRECATED
    102102{
    103103    return encode_EncTGSRepPart(data, length, t, len);
    104104}
    105105
    106 krb5_error_code KRB5_LIB_FUNCTION
     106KRB5_DEPRECATED
     107KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    107108krb5_decode_EncAPRepPart (krb5_context context,
    108109                          const void *data,
     
    110111                          EncAPRepPart *t,
    111112                          size_t *len)
    112     KRB5_DEPRECATED
    113113{
    114114    return decode_EncAPRepPart(data, length, t, len);
    115115}
    116116
    117 krb5_error_code KRB5_LIB_FUNCTION
     117KRB5_DEPRECATED
     118KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    118119krb5_encode_EncAPRepPart (krb5_context context,
    119120                          void *data,
     
    121122                          EncAPRepPart *t,
    122123                          size_t *len)
    123     KRB5_DEPRECATED
    124124{
    125125    return encode_EncAPRepPart(data, length, t, len);
    126126}
    127127
    128 krb5_error_code KRB5_LIB_FUNCTION
     128KRB5_DEPRECATED
     129KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    129130krb5_decode_Authenticator (krb5_context context,
    130131                           const void *data,
     
    132133                           Authenticator *t,
    133134                           size_t *len)
    134     KRB5_DEPRECATED
    135135{
    136136    return decode_Authenticator(data, length, t, len);
    137137}
    138138
    139 krb5_error_code KRB5_LIB_FUNCTION
     139KRB5_DEPRECATED
     140KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    140141krb5_encode_Authenticator (krb5_context context,
    141142                           void *data,
     
    143144                           Authenticator *t,
    144145                           size_t *len)
    145     KRB5_DEPRECATED
    146146{
    147147    return encode_Authenticator(data, length, t, len);
    148148}
    149149
    150 krb5_error_code KRB5_LIB_FUNCTION
     150KRB5_DEPRECATED
     151KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    151152krb5_decode_EncKrbCredPart (krb5_context context,
    152153                            const void *data,
     
    154155                            EncKrbCredPart *t,
    155156                            size_t *len)
    156     KRB5_DEPRECATED
    157157{
    158158    return decode_EncKrbCredPart(data, length, t, len);
    159159}
    160160
    161 krb5_error_code KRB5_LIB_FUNCTION
     161KRB5_DEPRECATED
     162KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    162163krb5_encode_EncKrbCredPart (krb5_context context,
    163164                            void *data,
     
    165166                            EncKrbCredPart *t,
    166167                            size_t *len)
    167     KRB5_DEPRECATED
    168168{
    169169    return encode_EncKrbCredPart (data, length, t, len);
    170170}
    171171
    172 krb5_error_code KRB5_LIB_FUNCTION
     172KRB5_DEPRECATED
     173KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    173174krb5_decode_ETYPE_INFO (krb5_context context,
    174175                        const void *data,
     
    176177                        ETYPE_INFO *t,
    177178                        size_t *len)
    178     KRB5_DEPRECATED
    179179{
    180180    return decode_ETYPE_INFO(data, length, t, len);
    181181}
    182182
    183 krb5_error_code KRB5_LIB_FUNCTION
     183KRB5_DEPRECATED
     184KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    184185krb5_encode_ETYPE_INFO (krb5_context context,
    185186                        void *data,
     
    187188                        ETYPE_INFO *t,
    188189                        size_t *len)
    189     KRB5_DEPRECATED
    190190{
    191191    return encode_ETYPE_INFO (data, length, t, len);
    192192}
    193193
    194 krb5_error_code KRB5_LIB_FUNCTION
     194KRB5_DEPRECATED
     195KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    195196krb5_decode_ETYPE_INFO2 (krb5_context context,
    196197                        const void *data,
     
    198199                        ETYPE_INFO2 *t,
    199200                        size_t *len)
    200     KRB5_DEPRECATED
    201201{
    202202    return decode_ETYPE_INFO2(data, length, t, len);
    203203}
    204204
    205 krb5_error_code KRB5_LIB_FUNCTION
     205KRB5_DEPRECATED
     206KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    206207krb5_encode_ETYPE_INFO2 (krb5_context context,
    207208                         void *data,
     
    209210                         ETYPE_INFO2 *t,
    210211                         size_t *len)
    211     KRB5_DEPRECATED
    212212{
    213213    return encode_ETYPE_INFO2 (data, length, t, len);
  • trunk/server/source4/heimdal/lib/krb5/config_file.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    3234 */
    3335
     36#define KRB5_DEPRECATED
     37
    3438#include "krb5_locl.h"
     39
     40#ifdef __APPLE__
     41#include <CoreFoundation/CoreFoundation.h>
     42#endif
    3543
    3644/* Gaah! I want a portable funopen */
     
    6876static krb5_error_code parse_section(char *p, krb5_config_section **s,
    6977                                     krb5_config_section **res,
    70                                      const char **error_message);
     78                                     const char **err_message);
    7179static krb5_error_code parse_binding(struct fileptr *f, unsigned *lineno, char *p,
    7280                                     krb5_config_binding **b,
    7381                                     krb5_config_binding **parent,
    74                                      const char **error_message);
     82                                     const char **err_message);
    7583static krb5_error_code parse_list(struct fileptr *f, unsigned *lineno,
    7684                                  krb5_config_binding **parent,
    77                                   const char **error_message);
    78 
    79 static krb5_config_section *
    80 get_entry(krb5_config_section **parent, const char *name, int type)
     85                                  const char **err_message);
     86
     87krb5_config_section *
     88_krb5_config_get_entry(krb5_config_section **parent, const char *name, int type)
    8189{
    8290    krb5_config_section **q;
     
    112120 * starting at the line in `p', storing the resulting structure in
    113121 * `s' and hooking it into `parent'.
    114  * Store the error message in `error_message'.
     122 * Store the error message in `err_message'.
    115123 */
    116124
    117125static krb5_error_code
    118126parse_section(char *p, krb5_config_section **s, krb5_config_section **parent,
    119               const char **error_message)
     127              const char **err_message)
    120128{
    121129    char *p1;
     
    124132    p1 = strchr (p + 1, ']');
    125133    if (p1 == NULL) {
    126         *error_message = "missing ]";
     134        *err_message = "missing ]";
    127135        return KRB5_CONFIG_BADFORMAT;
    128136    }
    129137    *p1 = '\0';
    130     tmp = get_entry(parent, p + 1, krb5_config_list);
     138    tmp = _krb5_config_get_entry(parent, p + 1, krb5_config_list);
    131139    if(tmp == NULL) {
    132         *error_message = "out of memory";
     140        *err_message = "out of memory";
    133141        return KRB5_CONFIG_BADFORMAT;
    134142    }
     
    140148 * Parse a brace-enclosed list from `f', hooking in the structure at
    141149 * `parent'.
    142  * Store the error message in `error_message'.
     150 * Store the error message in `err_message'.
    143151 */
    144152
    145153static krb5_error_code
    146154parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent,
    147            const char **error_message)
    148 {
    149     char buf[BUFSIZ];
     155           const char **err_message)
     156{
     157    char buf[KRB5_BUFSIZ];
    150158    krb5_error_code ret;
    151159    krb5_config_binding *b = NULL;
     
    168176        if (*p == '\0')
    169177            continue;
    170         ret = parse_binding (f, lineno, p, &b, parent, error_message);
     178        ret = parse_binding (f, lineno, p, &b, parent, err_message);
    171179        if (ret)
    172180            return ret;
    173181    }
    174182    *lineno = beg_lineno;
    175     *error_message = "unclosed {";
     183    *err_message = "unclosed {";
    176184    return KRB5_CONFIG_BADFORMAT;
    177185}
     
    184192parse_binding(struct fileptr *f, unsigned *lineno, char *p,
    185193              krb5_config_binding **b, krb5_config_binding **parent,
    186               const char **error_message)
     194              const char **err_message)
    187195{
    188196    krb5_config_binding *tmp;
     
    194202        ++p;
    195203    if (*p == '\0') {
    196         *error_message = "missing =";
     204        *err_message = "missing =";
    197205        return KRB5_CONFIG_BADFORMAT;
    198206    }
     
    201209        ++p;
    202210    if (*p != '=') {
    203         *error_message = "missing =";
     211        *err_message = "missing =";
    204212        return KRB5_CONFIG_BADFORMAT;
    205213    }
     
    209217    *p2 = '\0';
    210218    if (*p == '{') {
    211         tmp = get_entry(parent, p1, krb5_config_list);
     219        tmp = _krb5_config_get_entry(parent, p1, krb5_config_list);
    212220        if (tmp == NULL) {
    213             *error_message = "out of memory";
     221            *err_message = "out of memory";
    214222            return KRB5_CONFIG_BADFORMAT;
    215223        }
    216         ret = parse_list (f, lineno, &tmp->u.list, error_message);
     224        ret = parse_list (f, lineno, &tmp->u.list, err_message);
    217225    } else {
    218         tmp = get_entry(parent, p1, krb5_config_string);
     226        tmp = _krb5_config_get_entry(parent, p1, krb5_config_string);
    219227        if (tmp == NULL) {
    220             *error_message = "out of memory";
     228            *err_message = "out of memory";
    221229            return KRB5_CONFIG_BADFORMAT;
    222230        }
     
    232240}
    233241
     242#if defined(__APPLE__)
     243
     244#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
     245#define HAVE_CFPROPERTYLISTCREATEWITHSTREAM 1
     246#endif
     247
     248static char *
     249cfstring2cstring(CFStringRef string)
     250{
     251    CFIndex len;
     252    char *str;
     253   
     254    str = (char *) CFStringGetCStringPtr(string, kCFStringEncodingUTF8);
     255    if (str)
     256        return strdup(str);
     257
     258    len = CFStringGetLength(string);
     259    len = 1 + CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8);
     260    str = malloc(len);
     261    if (str == NULL)
     262        return NULL;
     263       
     264    if (!CFStringGetCString (string, str, len, kCFStringEncodingUTF8)) {
     265        free (str);
     266        return NULL;
     267    }
     268    return str;
     269}
     270
     271static void
     272convert_content(const void *key, const void *value, void *context)
     273{
     274    krb5_config_section *tmp, **parent = context;
     275    char *k;
     276
     277    if (CFGetTypeID(key) != CFStringGetTypeID())
     278        return;
     279
     280    k = cfstring2cstring(key);
     281    if (k == NULL)
     282        return;
     283
     284    if (CFGetTypeID(value) == CFStringGetTypeID()) {
     285        tmp = _krb5_config_get_entry(parent, k, krb5_config_string);
     286        tmp->u.string = cfstring2cstring(value);
     287    } else if (CFGetTypeID(value) == CFDictionaryGetTypeID()) {
     288        tmp = _krb5_config_get_entry(parent, k, krb5_config_list);
     289        CFDictionaryApplyFunction(value, convert_content, &tmp->u.list);
     290    } else {
     291        /* log */
     292    }
     293    free(k);
     294}
     295
     296static krb5_error_code
     297parse_plist_config(krb5_context context, const char *path, krb5_config_section **parent)
     298{
     299    CFReadStreamRef s;
     300    CFDictionaryRef d;
     301    CFURLRef url;
     302   
     303    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8 *)path, strlen(path), FALSE);
     304    if (url == NULL) {
     305        krb5_clear_error_message(context);
     306        return ENOMEM;
     307    }
     308
     309    s = CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
     310    CFRelease(url);
     311    if (s == NULL) {
     312        krb5_clear_error_message(context);
     313        return ENOMEM;
     314    }
     315
     316    if (!CFReadStreamOpen(s)) {
     317        CFRelease(s);
     318        krb5_clear_error_message(context);
     319        return ENOENT;
     320    }
     321
     322#ifdef HAVE_CFPROPERTYLISTCREATEWITHSTREAM
     323    d = (CFDictionaryRef)CFPropertyListCreateWithStream(NULL, s, 0, kCFPropertyListImmutable, NULL, NULL);
     324#else
     325    d = (CFDictionaryRef)CFPropertyListCreateFromStream(NULL, s, 0, kCFPropertyListImmutable, NULL, NULL);
     326#endif
     327    CFRelease(s);
     328    if (d == NULL) {
     329        krb5_clear_error_message(context);
     330        return ENOENT;
     331    }
     332
     333    CFDictionaryApplyFunction(d, convert_content, parent);
     334    CFRelease(d);
     335
     336    return 0;
     337}
     338
     339#endif
     340
     341
    234342/*
    235343 * Parse the config file `fname', generating the structures into `res'
    236  * returning error messages in `error_message'
     344 * returning error messages in `err_message'
    237345 */
    238346
     
    241349                         krb5_config_section **res,
    242350                         unsigned *lineno,
    243                          const char **error_message)
     351                         const char **err_message)
    244352{
    245353    krb5_config_section *s = NULL;
    246354    krb5_config_binding *b = NULL;
    247     char buf[BUFSIZ];
     355    char buf[KRB5_BUFSIZ];
    248356    krb5_error_code ret;
    249357
     
    259367            continue;
    260368        if (*p == '[') {
    261             ret = parse_section(p, &s, res, error_message);
     369            ret = parse_section(p, &s, res, err_message);
    262370            if (ret)
    263371                return ret;
    264372            b = NULL;
    265373        } else if (*p == '}') {
    266             *error_message = "unmatched }";
     374            *err_message = "unmatched }";
    267375            return EINVAL;      /* XXX */
    268376        } else if(*p != '\0') {
    269377            if (s == NULL) {
    270                 *error_message = "binding before section";
     378                *err_message = "binding before section";
    271379                return EINVAL;
    272380            }
    273             ret = parse_binding(f, lineno, p, &b, &s->u.list, error_message);
     381            ret = parse_binding(f, lineno, p, &b, &s->u.list, err_message);
    274382            if (ret)
    275383                return ret;
     
    279387}
    280388
    281 krb5_error_code KRB5_LIB_FUNCTION
    282 krb5_config_parse_string_multi(krb5_context context,
    283                                const char *string,
    284                                krb5_config_section **res)
    285 {
    286     const char *str;
    287     unsigned lineno = 0;
    288     krb5_error_code ret;
    289     struct fileptr f;
    290     f.f = NULL;
    291     f.s = string;
    292 
    293     ret = krb5_config_parse_debug (&f, res, &lineno, &str);
    294     if (ret) {
    295         krb5_set_error_message (context, ret, "%s:%u: %s",
    296                                 "<constant>", lineno, str);
    297         return ret;
    298     }
    299     return 0;
     389static int
     390is_plist_file(const char *fname)
     391{
     392    size_t len = strlen(fname);
     393    char suffix[] = ".plist";
     394    if (len < sizeof(suffix))
     395        return 0;
     396    if (strcasecmp(&fname[len - (sizeof(suffix) - 1)], suffix) != 0)
     397        return 0;
     398    return 1;
    300399}
    301400
     
    313412 */
    314413
    315 krb5_error_code KRB5_LIB_FUNCTION
     414KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    316415krb5_config_parse_file_multi (krb5_context context,
    317416                              const char *fname,
     
    329428     * enabled by calling krb5_set_home_dir_access().
    330429     */
    331     if (_krb5_homedir_access(context) && fname[0] == '~' && fname[1] == '/') {
     430    if (fname[0] == '~' && fname[1] == '/') {
     431#ifndef KRB5_USE_PATH_TOKENS
    332432        const char *home = NULL;
     433
     434        if (!_krb5_homedir_access(context)) {
     435            krb5_set_error_message(context, EPERM,
     436                                   "Access to home directory not allowed");
     437            return EPERM;
     438        }
    333439
    334440        if(!issuid())
     
    349455            fname = newfname;
    350456        }
    351     }
    352 
    353     f.f = fopen(fname, "r");
    354     f.s = NULL;
    355     if(f.f == NULL) {
    356         ret = errno;
    357         krb5_set_error_message (context, ret, "open %s: %s",
    358                                 fname, strerror(ret));
     457#else  /* KRB5_USE_PATH_TOKENS */
     458        if (asprintf(&newfname, "%%{USERCONFIG}%s", &fname[1]) < 0 ||
     459            newfname == NULL)
     460        {
     461            krb5_set_error_message(context, ENOMEM,
     462                                   N_("malloc: out of memory", ""));
     463            return ENOMEM;
     464        }
     465        fname = newfname;
     466#endif
     467    }
     468
     469    if (is_plist_file(fname)) {
     470#ifdef __APPLE__
     471        ret = parse_plist_config(context, fname, res);
     472        if (ret) {
     473            krb5_set_error_message(context, ret,
     474                                   "Failed to parse plist %s", fname);
     475            if (newfname)
     476                free(newfname);
     477            return ret;
     478        }
     479#else
     480        krb5_set_error_message(context, ENOENT,
     481                               "no support for plist configuration files");
     482        return ENOENT;
     483#endif
     484    } else {
     485#ifdef KRB5_USE_PATH_TOKENS
     486        char * exp_fname = NULL;
     487
     488        ret = _krb5_expand_path_tokens(context, fname, &exp_fname);
     489        if (ret) {
     490            if (newfname)
     491                free(newfname);
     492            return ret;
     493        }
     494       
    359495        if (newfname)
    360496            free(newfname);
    361         return ret;
    362     }
    363 
    364     ret = krb5_config_parse_debug (&f, res, &lineno, &str);
    365     fclose(f.f);
    366     if (ret) {
    367         krb5_set_error_message (context, ret, "%s:%u: %s", fname, lineno, str);
    368         if (newfname)
    369             free(newfname);
    370         return ret;
    371     }
    372     if (newfname)
    373         free(newfname);
     497        fname = newfname = exp_fname;
     498#endif
     499
     500        f.f = fopen(fname, "r");
     501        f.s = NULL;
     502        if(f.f == NULL) {
     503            ret = errno;
     504            krb5_set_error_message (context, ret, "open %s: %s",
     505                                    fname, strerror(ret));
     506            if (newfname)
     507                free(newfname);
     508            return ret;
     509        }
     510       
     511        ret = krb5_config_parse_debug (&f, res, &lineno, &str);
     512        fclose(f.f);
     513        if (ret) {
     514            krb5_set_error_message (context, ret, "%s:%u: %s",
     515                                    fname, lineno, str);
     516            if (newfname)
     517                free(newfname);
     518            return ret;
     519        }
     520    }
    374521    return 0;
    375522}
    376523
    377 krb5_error_code KRB5_LIB_FUNCTION
     524KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    378525krb5_config_parse_file (krb5_context context,
    379526                        const char *fname,
     
    404551}
    405552
    406 krb5_error_code KRB5_LIB_FUNCTION
     553/**
     554 * Free configuration file section, the result of
     555 * krb5_config_parse_file() and krb5_config_parse_file_multi().
     556 *
     557 * @param context A Kerberos 5 context
     558 * @param s the configuration section to free
     559 *
     560 * @return returns 0 on successes, otherwise an error code, see
     561 *          krb5_get_error_message()
     562 *
     563 * @ingroup krb5_support
     564 */
     565
     566KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    407567krb5_config_file_free (krb5_context context, krb5_config_section *s)
    408568{
     
    411571}
    412572
    413 krb5_error_code
     573#ifndef HEIMDAL_SMALLER
     574
     575KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    414576_krb5_config_copy(krb5_context context,
    415577                  krb5_config_section *c,
     
    445607}
    446608
    447 
    448 
    449 const void *
    450 krb5_config_get_next (krb5_context context,
    451                       const krb5_config_section *c,
    452                       const krb5_config_binding **pointer,
    453                       int type,
    454                       ...)
     609#endif /* HEIMDAL_SMALLER */
     610
     611KRB5_LIB_FUNCTION const void * KRB5_LIB_CALL
     612_krb5_config_get_next (krb5_context context,
     613                       const krb5_config_section *c,
     614                       const krb5_config_binding **pointer,
     615                       int type,
     616                       ...)
    455617{
    456618    const char *ret;
     
    458620
    459621    va_start(args, type);
    460     ret = krb5_config_vget_next (context, c, pointer, type, args);
     622    ret = _krb5_config_vget_next (context, c, pointer, type, args);
    461623    va_end(args);
    462624    return ret;
     
    486648}
    487649
    488 const void *
    489 krb5_config_vget_next (krb5_context context,
    490                        const krb5_config_section *c,
    491                        const krb5_config_binding **pointer,
    492                        int type,
    493                        va_list args)
     650KRB5_LIB_FUNCTION const void * KRB5_LIB_CALL
     651_krb5_config_vget_next (krb5_context context,
     652                        const krb5_config_section *c,
     653                        const krb5_config_binding **pointer,
     654                        int type,
     655                        va_list args)
    494656{
    495657    const krb5_config_binding *b;
     
    522684}
    523685
    524 const void *
    525 krb5_config_get (krb5_context context,
    526                  const krb5_config_section *c,
    527                  int type,
    528                  ...)
     686KRB5_LIB_FUNCTION const void * KRB5_LIB_CALL
     687_krb5_config_get (krb5_context context,
     688                  const krb5_config_section *c,
     689                  int type,
     690                  ...)
    529691{
    530692    const void *ret;
     
    532694
    533695    va_start(args, type);
    534     ret = krb5_config_vget (context, c, type, args);
     696    ret = _krb5_config_vget (context, c, type, args);
    535697    va_end(args);
    536698    return ret;
    537699}
    538700
     701
    539702const void *
    540 krb5_config_vget (krb5_context context,
    541                   const krb5_config_section *c,
    542                   int type,
    543                   va_list args)
     703_krb5_config_vget (krb5_context context,
     704                   const krb5_config_section *c,
     705                   int type,
     706                   va_list args)
    544707{
    545708    const krb5_config_binding *foo = NULL;
    546709
    547     return krb5_config_vget_next (context, c, &foo, type, args);
    548 }
    549 
    550 const krb5_config_binding *
     710    return _krb5_config_vget_next (context, c, &foo, type, args);
     711}
     712
     713/**
     714 * Get a list of configuration binding list for more processing
     715 *
     716 * @param context A Kerberos 5 context.
     717 * @param c a configuration section, or NULL to use the section from context
     718 * @param ... a list of names, terminated with NULL.
     719 *
     720 * @return NULL if configuration list is not found, a list otherwise
     721 *
     722 * @ingroup krb5_support
     723 */
     724
     725KRB5_LIB_FUNCTION const krb5_config_binding * KRB5_LIB_CALL
    551726krb5_config_get_list (krb5_context context,
    552727                      const krb5_config_section *c,
     
    562737}
    563738
    564 const krb5_config_binding *
     739/**
     740 * Get a list of configuration binding list for more processing
     741 *
     742 * @param context A Kerberos 5 context.
     743 * @param c a configuration section, or NULL to use the section from context
     744 * @param args a va_list of arguments
     745 *
     746 * @return NULL if configuration list is not found, a list otherwise
     747 *
     748 * @ingroup krb5_support
     749 */
     750
     751KRB5_LIB_FUNCTION const krb5_config_binding * KRB5_LIB_CALL
    565752krb5_config_vget_list (krb5_context context,
    566753                       const krb5_config_section *c,
    567754                       va_list args)
    568755{
    569     return krb5_config_vget (context, c, krb5_config_list, args);
    570 }
    571 
    572 const char* KRB5_LIB_FUNCTION
     756    return _krb5_config_vget (context, c, krb5_config_list, args);
     757}
     758
     759/**
     760 * Returns a "const char *" to a string in the configuration database.
     761 * The string may not be valid after a reload of the configuration
     762 * database so a caller should make a local copy if it needs to keep
     763 * the string.
     764 *
     765 * @param context A Kerberos 5 context.
     766 * @param c a configuration section, or NULL to use the section from context
     767 * @param ... a list of names, terminated with NULL.
     768 *
     769 * @return NULL if configuration string not found, a string otherwise
     770 *
     771 * @ingroup krb5_support
     772 */
     773 
     774KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    573775krb5_config_get_string (krb5_context context,
    574776                        const krb5_config_section *c,
     
    584786}
    585787
    586 const char* KRB5_LIB_FUNCTION
     788/**
     789 * Like krb5_config_get_string(), but uses a va_list instead of ...
     790 *
     791 * @param context A Kerberos 5 context.
     792 * @param c a configuration section, or NULL to use the section from context
     793 * @param args a va_list of arguments
     794 *
     795 * @return NULL if configuration string not found, a string otherwise
     796 *
     797 * @ingroup krb5_support
     798 */
     799
     800KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    587801krb5_config_vget_string (krb5_context context,
    588802                         const krb5_config_section *c,
    589803                         va_list args)
    590804{
    591     return krb5_config_vget (context, c, krb5_config_string, args);
    592 }
    593 
    594 const char* KRB5_LIB_FUNCTION
     805    return _krb5_config_vget (context, c, krb5_config_string, args);
     806}
     807
     808/**
     809 * Like krb5_config_vget_string(), but instead of returning NULL,
     810 * instead return a default value.
     811 *
     812 * @param context A Kerberos 5 context.
     813 * @param c a configuration section, or NULL to use the section from context
     814 * @param def_value the default value to return if no configuration
     815 *        found in the database.
     816 * @param args a va_list of arguments
     817 *
     818 * @return a configuration string
     819 *
     820 * @ingroup krb5_support
     821 */
     822
     823KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    595824krb5_config_vget_string_default (krb5_context context,
    596825                                 const krb5_config_section *c,
     
    606835}
    607836
    608 const char* KRB5_LIB_FUNCTION
     837/**
     838 * Like krb5_config_get_string(), but instead of returning NULL,
     839 * instead return a default value.
     840 *
     841 * @param context A Kerberos 5 context.
     842 * @param c a configuration section, or NULL to use the section from context
     843 * @param def_value the default value to return if no configuration
     844 *        found in the database.
     845 * @param ... a list of names, terminated with NULL.
     846 *
     847 * @return a configuration string
     848 *
     849 * @ingroup krb5_support
     850 */
     851
     852KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    609853krb5_config_get_string_default (krb5_context context,
    610854                                const krb5_config_section *c,
     
    621865}
    622866
    623 char ** KRB5_LIB_FUNCTION
     867static char *
     868next_component_string(char * begin, char * delims, char **state)
     869{
     870    char * end;
     871
     872    if (begin == NULL)
     873        begin = *state;
     874
     875    if (*begin == '\0')
     876        return NULL;
     877
     878    end = begin;
     879    while (*end == '"') {
     880        char * t = strchr(end + 1, '"');
     881
     882        if (t)
     883            end = ++t;
     884        else
     885            end += strlen(end);
     886    }
     887
     888    if (*end != '\0') {
     889        size_t pos;
     890
     891        pos = strcspn(end, delims);
     892        end = end + pos;
     893    }
     894
     895    if (*end != '\0') {
     896        *end = '\0';
     897        *state = end + 1;
     898        if (*begin == '"' && *(end - 1) == '"' && begin + 1 < end) {
     899            begin++; *(end - 1) = '\0';
     900        }
     901        return begin;
     902    }
     903
     904    *state = end;
     905    if (*begin == '"' && *(end - 1) == '"' && begin + 1 < end) {
     906        begin++; *(end - 1) = '\0';
     907    }
     908    return begin;
     909}
     910
     911/**
     912 * Get a list of configuration strings, free the result with
     913 * krb5_config_free_strings().
     914 *
     915 * @param context A Kerberos 5 context.
     916 * @param c a configuration section, or NULL to use the section from context
     917 * @param args a va_list of arguments
     918 *
     919 * @return TRUE or FALSE
     920 *
     921 * @ingroup krb5_support
     922 */
     923
     924KRB5_LIB_FUNCTION char ** KRB5_LIB_CALL
    624925krb5_config_vget_strings(krb5_context context,
    625926                         const krb5_config_section *c,
     
    631932    const char *p;
    632933
    633     while((p = krb5_config_vget_next(context, c, &b,
    634                                      krb5_config_string, args))) {
     934    while((p = _krb5_config_vget_next(context, c, &b,
     935                                      krb5_config_string, args))) {
    635936        char *tmp = strdup(p);
    636937        char *pos = NULL;
     
    638939        if(tmp == NULL)
    639940            goto cleanup;
    640         s = strtok_r(tmp, " \t", &pos);
     941        s = next_component_string(tmp, " \t", &pos);
    641942        while(s){
    642943            char **tmp2 = realloc(strings, (nstr + 1) * sizeof(*strings));
     
    648949            if(strings[nstr-1] == NULL)
    649950                goto cleanup;
    650             s = strtok_r(NULL, " \t", &pos);
     951            s = next_component_string(NULL, " \t", &pos);
    651952        }
    652953        free(tmp);
     
    668969}
    669970
    670 char**
     971/**
     972 * Get a list of configuration strings, free the result with
     973 * krb5_config_free_strings().
     974 *
     975 * @param context A Kerberos 5 context.
     976 * @param c a configuration section, or NULL to use the section from context
     977 * @param ... a list of names, terminated with NULL.
     978 *
     979 * @return TRUE or FALSE
     980 *
     981 * @ingroup krb5_support
     982 */
     983
     984KRB5_LIB_FUNCTION char** KRB5_LIB_CALL
    671985krb5_config_get_strings(krb5_context context,
    672986                        const krb5_config_section *c,
     
    681995}
    682996
    683 void KRB5_LIB_FUNCTION
     997/**
     998 * Free the resulting strings from krb5_config-get_strings() and
     999 * krb5_config_vget_strings().
     1000 *
     1001 * @param strings strings to free
     1002 *
     1003 * @ingroup krb5_support
     1004 */
     1005
     1006KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    6841007krb5_config_free_strings(char **strings)
    6851008{
     
    6921015}
    6931016
    694 krb5_boolean KRB5_LIB_FUNCTION
     1017/**
     1018 * Like krb5_config_get_bool_default() but with a va_list list of
     1019 * configuration selection.
     1020 *
     1021 * Configuration value to a boolean value, where yes/true and any
     1022 * non-zero number means TRUE and other value is FALSE.
     1023 *
     1024 * @param context A Kerberos 5 context.
     1025 * @param c a configuration section, or NULL to use the section from context
     1026 * @param def_value the default value to return if no configuration
     1027 *        found in the database.
     1028 * @param args a va_list of arguments
     1029 *
     1030 * @return TRUE or FALSE
     1031 *
     1032 * @ingroup krb5_support
     1033 */
     1034
     1035KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    6951036krb5_config_vget_bool_default (krb5_context context,
    6961037                               const krb5_config_section *c,
     
    7081049}
    7091050
    710 krb5_boolean KRB5_LIB_FUNCTION
     1051/**
     1052 * krb5_config_get_bool() will convert the configuration
     1053 * option value to a boolean value, where yes/true and any non-zero
     1054 * number means TRUE and other value is FALSE.
     1055 *
     1056 * @param context A Kerberos 5 context.
     1057 * @param c a configuration section, or NULL to use the section from context
     1058 * @param args a va_list of arguments
     1059 *
     1060 * @return TRUE or FALSE
     1061 *
     1062 * @ingroup krb5_support
     1063 */
     1064
     1065KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    7111066krb5_config_vget_bool  (krb5_context context,
    7121067                        const krb5_config_section *c,
     
    7161071}
    7171072
    718 krb5_boolean KRB5_LIB_FUNCTION
     1073/**
     1074 * krb5_config_get_bool_default() will convert the configuration
     1075 * option value to a boolean value, where yes/true and any non-zero
     1076 * number means TRUE and other value is FALSE.
     1077 *
     1078 * @param context A Kerberos 5 context.
     1079 * @param c a configuration section, or NULL to use the section from context
     1080 * @param def_value the default value to return if no configuration
     1081 *        found in the database.
     1082 * @param ... a list of names, terminated with NULL.
     1083 *
     1084 * @return TRUE or FALSE
     1085 *
     1086 * @ingroup krb5_support
     1087 */
     1088
     1089KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    7191090krb5_config_get_bool_default (krb5_context context,
    7201091                              const krb5_config_section *c,
     
    7301101}
    7311102
    732 krb5_boolean KRB5_LIB_FUNCTION
     1103/**
     1104 * Like krb5_config_get_bool() but with a va_list list of
     1105 * configuration selection.
     1106 *
     1107 * Configuration value to a boolean value, where yes/true and any
     1108 * non-zero number means TRUE and other value is FALSE.
     1109 *
     1110 * @param context A Kerberos 5 context.
     1111 * @param c a configuration section, or NULL to use the section from context
     1112 * @param ... a list of names, terminated with NULL.
     1113 *
     1114 * @return TRUE or FALSE
     1115 *
     1116 * @ingroup krb5_support
     1117 */
     1118
     1119KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    7331120krb5_config_get_bool (krb5_context context,
    7341121                      const krb5_config_section *c,
     
    7431130}
    7441131
    745 int KRB5_LIB_FUNCTION
     1132/**
     1133 * Get the time from the configuration file using a relative time.
     1134 *
     1135 * Like krb5_config_get_time_default() but with a va_list list of
     1136 * configuration selection.
     1137 *
     1138 * @param context A Kerberos 5 context.
     1139 * @param c a configuration section, or NULL to use the section from context
     1140 * @param def_value the default value to return if no configuration
     1141 *        found in the database.
     1142 * @param args a va_list of arguments
     1143 *
     1144 * @return parsed the time (or def_value on parse error)
     1145 *
     1146 * @ingroup krb5_support
     1147 */
     1148
     1149KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    7461150krb5_config_vget_time_default (krb5_context context,
    7471151                               const krb5_config_section *c,
     
    7601164}
    7611165
    762 int KRB5_LIB_FUNCTION
     1166/**
     1167 * Get the time from the configuration file using a relative time, for example: 1h30s
     1168 *
     1169 * @param context A Kerberos 5 context.
     1170 * @param c a configuration section, or NULL to use the section from context
     1171 * @param args a va_list of arguments
     1172 *
     1173 * @return parsed the time or -1 on error
     1174 *
     1175 * @ingroup krb5_support
     1176 */
     1177
     1178KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    7631179krb5_config_vget_time  (krb5_context context,
    7641180                        const krb5_config_section *c,
     
    7681184}
    7691185
    770 int KRB5_LIB_FUNCTION
     1186/**
     1187 * Get the time from the configuration file using a relative time, for example: 1h30s
     1188 *
     1189 * @param context A Kerberos 5 context.
     1190 * @param c a configuration section, or NULL to use the section from context
     1191 * @param def_value the default value to return if no configuration
     1192 *        found in the database.
     1193 * @param ... a list of names, terminated with NULL.
     1194 *
     1195 * @return parsed the time (or def_value on parse error)
     1196 *
     1197 * @ingroup krb5_support
     1198 */
     1199
     1200KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    7711201krb5_config_get_time_default (krb5_context context,
    7721202                              const krb5_config_section *c,
     
    7821212}
    7831213
    784 int KRB5_LIB_FUNCTION
     1214/**
     1215 * Get the time from the configuration file using a relative time, for example: 1h30s
     1216 *
     1217 * @param context A Kerberos 5 context.
     1218 * @param c a configuration section, or NULL to use the section from context
     1219 * @param ... a list of names, terminated with NULL.
     1220 *
     1221 * @return parsed the time or -1 on error
     1222 *
     1223 * @ingroup krb5_support
     1224 */
     1225
     1226KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    7851227krb5_config_get_time (krb5_context context,
    7861228                      const krb5_config_section *c,
     
    7961238
    7971239
    798 int KRB5_LIB_FUNCTION
     1240KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    7991241krb5_config_vget_int_default (krb5_context context,
    8001242                              const krb5_config_section *c,
     
    8171259}
    8181260
    819 int KRB5_LIB_FUNCTION
     1261KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    8201262krb5_config_vget_int  (krb5_context context,
    8211263                       const krb5_config_section *c,
     
    8251267}
    8261268
    827 int KRB5_LIB_FUNCTION
     1269KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    8281270krb5_config_get_int_default (krb5_context context,
    8291271                             const krb5_config_section *c,
     
    8391281}
    8401282
    841 int KRB5_LIB_FUNCTION
     1283KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    8421284krb5_config_get_int (krb5_context context,
    8431285                     const krb5_config_section *c,
     
    8511293    return ret;
    8521294}
     1295
     1296
     1297#ifndef HEIMDAL_SMALLER
     1298
     1299/**
     1300 * Deprecated: configuration files are not strings
     1301 *
     1302 * @ingroup krb5_deprecated
     1303 */
     1304
     1305KRB5_DEPRECATED
     1306KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     1307krb5_config_parse_string_multi(krb5_context context,
     1308                               const char *string,
     1309                               krb5_config_section **res)
     1310{
     1311    const char *str;
     1312    unsigned lineno = 0;
     1313    krb5_error_code ret;
     1314    struct fileptr f;
     1315    f.f = NULL;
     1316    f.s = string;
     1317
     1318    ret = krb5_config_parse_debug (&f, res, &lineno, &str);
     1319    if (ret) {
     1320        krb5_set_error_message (context, ret, "%s:%u: %s",
     1321                                "<constant>", lineno, str);
     1322        return ret;
     1323    }
     1324    return 0;
     1325}
     1326
     1327#endif
  • trunk/server/source4/heimdal/lib/krb5/constants.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    3638KRB5_LIB_VARIABLE const char *krb5_config_file =
    3739#ifdef __APPLE__
    38 "~/Library/Preferences/edu.mit.Kerberos:"
    39 "/Library/Preferences/edu.mit.Kerberos:"
     40"~/Library/Preferences/com.apple.Kerberos.plist" PATH_SEP
     41"/Library/Preferences/com.apple.Kerberos.plist" PATH_SEP
     42"~/Library/Preferences/edu.mit.Kerberos" PATH_SEP
     43"/Library/Preferences/edu.mit.Kerberos" PATH_SEP
     44#endif  /* __APPLE__ */
     45"~/.krb5/config" PATH_SEP
     46SYSCONFDIR "/krb5.conf"
     47#ifdef _WIN32
     48PATH_SEP "%{COMMON_APPDATA}/Kerberos/krb5.conf"
     49PATH_SEP "%{WINDOWS}/krb5.ini"
     50#else
     51PATH_SEP "/etc/krb5.conf"
    4052#endif
    41 SYSCONFDIR "/krb5.conf:/etc/krb5.conf";
     53;
     54
    4255KRB5_LIB_VARIABLE const char *krb5_defkeyname = KEYTAB_DEFAULT;
    4356
  • trunk/server/source4/heimdal/lib/krb5/context.c

    r414 r745  
    11/*
    2  * Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan
     2 * Copyright (c) 1997 - 2010 Kungliga Tekniska Högskolan
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    8688
    8789/*
    88  *
    89  */
    90 
    91 static krb5_error_code
    92 copy_etypes (krb5_context context,
    93              krb5_enctype *enctypes,
    94              krb5_enctype **ret_enctypes)
    95 {
    96     unsigned int i;
    97 
    98     for (i = 0; enctypes[i]; i++)
    99         ;
    100     i++;
    101 
    102     *ret_enctypes = malloc(sizeof(ret_enctypes[0]) * i);
    103     if (*ret_enctypes == NULL) {
    104         krb5_set_error_message(context, ENOMEM,
    105                                N_("malloc: out of memory", ""));
    106         return ENOMEM;
    107     }
    108     memcpy(*ret_enctypes, enctypes, sizeof(ret_enctypes[0]) * i);
    109     return 0;
    110 }
    111 
    112 
    113 /*
    11490 * read variables from the configuration file and set in `context'
    11591 */
     
    12096    krb5_error_code ret;
    12197    const char * tmp;
     98    char **s;
    12299    krb5_enctype *tmptypes;
    123100
     
    127104
    128105    INIT_FIELD(context, string, http_proxy, NULL, "http_proxy");
     106
     107    ret = krb5_config_get_bool_default(context, NULL, FALSE,
     108                                       "libdefaults",
     109                                       "allow_weak_crypto", NULL);
     110    if (ret) {
     111        krb5_enctype_enable(context, ETYPE_DES_CBC_CRC);
     112        krb5_enctype_enable(context, ETYPE_DES_CBC_MD4);
     113        krb5_enctype_enable(context, ETYPE_DES_CBC_MD5);
     114        krb5_enctype_enable(context, ETYPE_DES_CBC_NONE);
     115        krb5_enctype_enable(context, ETYPE_DES_CFB64_NONE);
     116        krb5_enctype_enable(context, ETYPE_DES_PCBC_NONE);
     117    }
    129118
    130119    ret = set_etypes (context, "default_etypes", &tmptypes);
     
    218207    context->default_cc_name_set = 0;
    219208
    220     ret = krb5_config_get_bool_default(context, NULL, FALSE,
    221                                        "libdefaults",
    222                                        "allow_weak_crypto", NULL);
    223     if (ret) {
    224         krb5_enctype_enable(context, ETYPE_DES_CBC_CRC);
    225         krb5_enctype_enable(context, ETYPE_DES_CBC_MD4);
    226         krb5_enctype_enable(context, ETYPE_DES_CBC_MD5);
    227         krb5_enctype_enable(context, ETYPE_DES_CBC_NONE);
    228         krb5_enctype_enable(context, ETYPE_DES_CFB64_NONE);
    229         krb5_enctype_enable(context, ETYPE_DES_PCBC_NONE);
     209    s = krb5_config_get_strings(context, NULL, "logging", "krb5", NULL);
     210    if(s) {
     211        char **p;
     212        krb5_initlog(context, "libkrb5", &context->debug_dest);
     213        for(p = s; *p; p++)
     214            krb5_addlog_dest(context, context->debug_dest, *p);
     215        krb5_config_free_strings(s);
     216    }
     217
     218    tmp = krb5_config_get_string(context, NULL, "libdefaults",
     219                                 "check-rd-req-server", NULL);
     220    if (tmp == NULL && !issuid())
     221        tmp = getenv("KRB5_CHECK_RD_REQ_SERVER");
     222    if(tmp) {
     223        if (strcasecmp(tmp, "ignore") == 0)
     224            context->flags |= KRB5_CTX_F_RD_REQ_IGNORE;
    230225    }
    231226
     
    239234    context->num_cc_ops = 0;
    240235
     236#ifndef KCM_IS_API_CACHE
    241237    krb5_cc_register(context, &krb5_acc_ops, TRUE);
     238#endif
    242239    krb5_cc_register(context, &krb5_fcc_ops, TRUE);
    243240    krb5_cc_register(context, &krb5_mcc_ops, TRUE);
     241#ifdef HAVE_SCC
    244242    krb5_cc_register(context, &krb5_scc_ops, TRUE);
     243#endif
    245244#ifdef HAVE_KCM
     245#ifdef KCM_IS_API_CACHE
     246    krb5_cc_register(context, &krb5_akcm_ops, TRUE);
     247#endif
    246248    krb5_cc_register(context, &krb5_kcm_ops, TRUE);
    247249#endif
     250    _krb5_load_ccache_plugins(context);
     251    return 0;
     252}
     253
     254static krb5_error_code
     255cc_ops_copy(krb5_context context, const krb5_context src_context)
     256{
     257    const krb5_cc_ops **cc_ops;
     258
     259    context->cc_ops = NULL;
     260    context->num_cc_ops = 0;
     261
     262    if (src_context->num_cc_ops == 0)
     263        return 0;
     264
     265    cc_ops = malloc(sizeof(cc_ops[0]) * src_context->num_cc_ops);
     266    if (cc_ops == NULL) {
     267        krb5_set_error_message(context, KRB5_CC_NOMEM,
     268                               N_("malloc: out of memory", ""));
     269        return KRB5_CC_NOMEM;
     270    }
     271
     272    memcpy(rk_UNCONST(cc_ops), src_context->cc_ops,
     273           sizeof(cc_ops[0]) * src_context->num_cc_ops);
     274    context->cc_ops = cc_ops;
     275    context->num_cc_ops = src_context->num_cc_ops;
     276
    248277    return 0;
    249278}
     
    266295}
    267296
     297static krb5_error_code
     298kt_ops_copy(krb5_context context, const krb5_context src_context)
     299{
     300    context->num_kt_types = 0;
     301    context->kt_types     = NULL;
     302
     303    if (src_context->num_kt_types == 0)
     304        return 0;
     305
     306    context->kt_types = malloc(sizeof(context->kt_types[0]) * src_context->num_kt_types);
     307    if (context->kt_types == NULL) {
     308        krb5_set_error_message(context, ENOMEM,
     309                               N_("malloc: out of memory", ""));
     310        return ENOMEM;
     311    }
     312
     313    context->num_kt_types = src_context->num_kt_types;
     314    memcpy(context->kt_types, src_context->kt_types,
     315           sizeof(context->kt_types[0]) * src_context->num_kt_types);
     316
     317    return 0;
     318}
     319
     320static const char *sysplugin_dirs[] =  {
     321    LIBDIR "/plugin/krb5",
     322#ifdef __APPLE__
     323    "/Library/KerberosPlugins/KerberosFrameworkPlugins",
     324    "/System/Library/KerberosPlugins/KerberosFrameworkPlugins",
     325#endif
     326    NULL
     327};
     328
     329static void
     330init_context_once(void *ctx)
     331{
     332    krb5_context context = ctx;
     333
     334    _krb5_load_plugins(context, "krb5", sysplugin_dirs);
     335   
     336    bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR);
     337}
     338
    268339
    269340/**
     
    282353 */
    283354
    284 krb5_error_code KRB5_LIB_FUNCTION
     355KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    285356krb5_init_context(krb5_context *context)
    286357{
     358    static heim_base_once_t init_context = HEIM_BASE_ONCE_INIT;
    287359    krb5_context p;
    288360    krb5_error_code ret;
     
    290362
    291363    *context = NULL;
    292 
    293     /* should have a run_once */
    294     bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR);
    295364
    296365    p = calloc(1, sizeof(*p));
     
    320389    kt_ops_register(p);
    321390
     391#ifdef PKINIT
     392    ret = hx509_context_init(&p->hx509ctx);
     393    if (ret)
     394        goto out;
     395#endif 
     396    if (rk_SOCK_INIT())
     397        p->flags |= KRB5_CTX_F_SOCKETS_INITIALIZED;
     398
    322399out:
    323400    if(ret) {
    324401        krb5_free_context(p);
    325402        p = NULL;
     403    } else {
     404        heim_base_once_f(&init_context, p, init_context_once);
    326405    }
    327406    *context = p;
     
    329408}
    330409
    331 /**
    332  * Make a copy for the Kerberos 5 context, allocated krb5_contex shoud
     410#ifndef HEIMDAL_SMALLER
     411
     412KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     413krb5_get_permitted_enctypes(krb5_context context,
     414                            krb5_enctype **etypes)
     415{
     416    return krb5_get_default_in_tkt_etypes(context, etypes);
     417}
     418
     419/*
     420 *
     421 */
     422
     423static krb5_error_code
     424copy_etypes (krb5_context context,
     425             krb5_enctype *enctypes,
     426             krb5_enctype **ret_enctypes)
     427{
     428    unsigned int i;
     429
     430    for (i = 0; enctypes[i]; i++)
     431        ;
     432    i++;
     433
     434    *ret_enctypes = malloc(sizeof(ret_enctypes[0]) * i);
     435    if (*ret_enctypes == NULL) {
     436        krb5_set_error_message(context, ENOMEM,
     437                               N_("malloc: out of memory", ""));
     438        return ENOMEM;
     439    }
     440    memcpy(*ret_enctypes, enctypes, sizeof(ret_enctypes[0]) * i);
     441    return 0;
     442}
     443
     444/**
     445 * Make a copy for the Kerberos 5 context, the new krb5_context shoud
    333446 * be freed with krb5_free_context().
    334447 *
     
    342455 */
    343456
    344 krb5_error_code KRB5_LIB_FUNCTION
     457KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    345458krb5_copy_context(krb5_context context, krb5_context *out)
    346459{
     
    394507    /* XXX should copy */
    395508    krb5_init_ets(p);
    396     cc_ops_register(p);
    397     kt_ops_register(p);
     509
     510    cc_ops_copy(p, context);
     511    kt_ops_copy(p, context);
    398512
    399513#if 0 /* XXX */
    400514    if(context->warn_dest != NULL)
     515        ;
     516    if(context->debug_dest != NULL)
    401517        ;
    402518#endif
     
    422538}
    423539
     540#endif
     541
    424542/**
    425543 * Frees the krb5_context allocated by krb5_init_context().
     
    430548 */
    431549
    432 void KRB5_LIB_FUNCTION
     550KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    433551krb5_free_context(krb5_context context)
    434552{
     
    442560    krb5_config_file_free (context, context->cf);
    443561    free_error_table (context->et_list);
    444     free(context->cc_ops);
     562    free(rk_UNCONST(context->cc_ops));
    445563    free(context->kt_types);
    446564    krb5_clear_error_message(context);
    447565    if(context->warn_dest != NULL)
    448566        krb5_closelog(context, context->warn_dest);
     567    if(context->debug_dest != NULL)
     568        krb5_closelog(context, context->debug_dest);
    449569    krb5_set_extra_addresses(context, NULL);
    450570    krb5_set_ignore_addresses(context, NULL);
    451571    krb5_set_send_to_kdc_func(context, NULL, NULL);
    452572
     573#ifdef PKINIT
     574    if (context->hx509ctx)
     575        hx509_context_free(&context->hx509ctx);
     576#endif
     577
    453578    HEIMDAL_MUTEX_destroy(context->mutex);
    454579    free(context->mutex);
     580    if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) {
     581        rk_SOCK_EXIT();
     582    }
    455583
    456584    memset(context, 0, sizeof(*context));
     
    470598 */
    471599
    472 krb5_error_code KRB5_LIB_FUNCTION
     600KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    473601krb5_set_config_files(krb5_context context, char **filenames)
    474602{
     
    477605    while(filenames != NULL && *filenames != NULL && **filenames != '\0') {
    478606        ret = krb5_config_parse_file_multi(context, *filenames, &tmp);
    479         if(ret != 0 && ret != ENOENT && ret != EACCES) {
     607        if(ret != 0 && ret != ENOENT && ret != EACCES && ret != EPERM) {
    480608            krb5_config_file_free(context, tmp);
    481609            return ret;
     
    489617        return ENXIO;
    490618#endif
     619
     620#ifdef _WIN32
     621    _krb5_load_config_from_registry(context, &tmp);
     622#endif
     623
    491624    krb5_config_file_free(context, context->cf);
    492625    context->cf = tmp;
     
    525658 */
    526659
    527 krb5_error_code KRB5_LIB_FUNCTION
     660KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    528661krb5_prepend_config_files(const char *filelist, char **pq, char ***ret_pp)
    529662{
     
    541674        ssize_t l;
    542675        q = p;
    543         l = strsep_copy(&q, ":", NULL, 0);
     676        l = strsep_copy(&q, PATH_SEP, NULL, 0);
    544677        if(l == -1)
    545678            break;
     
    549682            return ENOMEM;
    550683        }
    551         (void)strsep_copy(&p, ":", fn, l + 1);
     684        (void)strsep_copy(&p, PATH_SEP, fn, l + 1);
    552685        ret = add_file(&pp, &len, fn);
    553686        if (ret) {
     
    590723 */
    591724
    592 krb5_error_code KRB5_LIB_FUNCTION
     725KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    593726krb5_prepend_config_files_default(const char *filelist, char ***pfilenames)
    594727{
     
    609742}
    610743
     744#ifdef _WIN32
     745
     746/**
     747 * Checks the registry for configuration file location
     748 *
     749 * Kerberos for Windows and other legacy Kerberos applications expect
     750 * to find the configuration file location in the
     751 * SOFTWARE\MIT\Kerberos registry key under the value "config".
     752 */
     753char *
     754_krb5_get_default_config_config_files_from_registry()
     755{
     756    static const char * KeyName = "Software\\MIT\\Kerberos";
     757    char *config_file = NULL;
     758    LONG rcode;
     759    HKEY key;
     760
     761    rcode = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, &key);
     762    if (rcode == ERROR_SUCCESS) {
     763        config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config",
     764                                                            REG_NONE, 0, PATH_SEP);
     765        RegCloseKey(key);
     766    }
     767
     768    if (config_file)
     769        return config_file;
     770
     771    rcode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyName, 0, KEY_READ, &key);
     772    if (rcode == ERROR_SUCCESS) {
     773        config_file = _krb5_parse_reg_value_as_multi_string(NULL, key, "config",
     774                                                            REG_NONE, 0, PATH_SEP);
     775        RegCloseKey(key);
     776    }
     777
     778    return config_file;
     779}
     780
     781#endif
     782
    611783/**
    612784 * Get the global configuration list.
     
    620792 */
    621793
    622 krb5_error_code KRB5_LIB_FUNCTION
     794KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    623795krb5_get_default_config_files(char ***pfilenames)
    624796{
     
    629801    if(!issuid())
    630802        files = getenv("KRB5_CONFIG");
     803
     804#ifdef _WIN32
     805    if (files == NULL) {
     806        char * reg_files;
     807        reg_files = _krb5_get_default_config_config_files_from_registry();
     808        if (reg_files != NULL) {
     809            krb5_error_code code;
     810
     811            code = krb5_prepend_config_files(reg_files, NULL, pfilenames);
     812            free(reg_files);
     813
     814            return code;
     815        }
     816    }
     817#endif
     818
    631819    if (files == NULL)
    632820        files = krb5_config_file;
     
    647835 */
    648836
    649 void KRB5_LIB_FUNCTION
     837KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    650838krb5_free_config_files(char **filenames)
    651839{
     
    669857 */
    670858
    671 const krb5_enctype * KRB5_LIB_FUNCTION
     859KRB5_LIB_FUNCTION const krb5_enctype * KRB5_LIB_CALL
    672860krb5_kerberos_enctypes(krb5_context context)
    673861{
     
    730918 */
    731919
    732 krb5_error_code KRB5_LIB_FUNCTION
     920KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    733921krb5_set_default_in_tkt_etypes(krb5_context context,
    734922                               const krb5_enctype *etypes)
    735923{
     924    krb5_error_code ret;
    736925    krb5_enctype *p = NULL;
    737     int i;
     926    unsigned int n, m;
    738927
    739928    if(etypes) {
    740         for (i = 0; etypes[i]; ++i) {
    741             krb5_error_code ret;
    742             ret = krb5_enctype_valid(context, etypes[i]);
     929        for (n = 0; etypes[n]; n++)
     930            ;
     931        n++;
     932        ALLOC(p, n);
     933        if(!p) {
     934            krb5_set_error_message (context, ENOMEM,
     935                                    N_("malloc: out of memory", ""));
     936            return ENOMEM;
     937        }
     938        for (n = 0, m = 0; etypes[n]; n++) {
     939            ret = krb5_enctype_valid(context, etypes[n]);
    743940            if (ret)
    744                 return ret;
    745         }
    746         ++i;
    747         ALLOC(p, i);
    748         if(!p) {
    749             krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    750             return ENOMEM;
    751         }
    752         memmove(p, etypes, i * sizeof(krb5_enctype));
     941                continue;
     942            p[m++] = etypes[n];
     943        }
     944        p[m] = ETYPE_NULL;
     945        if (m == 0) {
     946            free(p);
     947            krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP,
     948                                    N_("no valid enctype set", ""));
     949            return KRB5_PROG_ETYPE_NOSUPP;
     950        }
    753951    }
    754952    if(context->etypes)
     
    772970 */
    773971
    774 krb5_error_code KRB5_LIB_FUNCTION
     972KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    775973krb5_get_default_in_tkt_etypes(krb5_context context,
    776974                               krb5_enctype **etypes)
     
    799997
    800998/**
    801  * Return the error string for the error code. The caller must not
    802  * free the string.
    803  *
    804  * @param context Kerberos 5 context.
    805  * @param code Kerberos error code.
    806  *
    807  * @return the error message matching code
    808  *
    809  * @ingroup krb5
    810  */
    811 
    812 const char* KRB5_LIB_FUNCTION
    813 krb5_get_err_text(krb5_context context, krb5_error_code code)
    814 {
    815     const char *p = NULL;
    816     if(context != NULL)
    817         p = com_right(context->et_list, code);
    818     if(p == NULL)
    819         p = strerror(code);
    820     if (p == NULL)
    821         p = "Unknown error";
    822     return p;
    823 }
    824 
    825 /**
    826999 * Init the built-in ets in the Kerberos library.
    8271000 *
     
    8311004 */
    8321005
    833 void KRB5_LIB_FUNCTION
     1006KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8341007krb5_init_ets(krb5_context context)
    8351008{
    8361009    if(context->et_list == NULL){
    8371010        krb5_add_et_list(context, initialize_krb5_error_table_r);
     1011        krb5_add_et_list(context, initialize_asn1_error_table_r);
     1012        krb5_add_et_list(context, initialize_heim_error_table_r);
     1013
     1014        krb5_add_et_list(context, initialize_k524_error_table_r);
     1015
     1016#ifdef COM_ERR_BINDDOMAIN_krb5
    8381017        bindtextdomain(COM_ERR_BINDDOMAIN_krb5, HEIMDAL_LOCALEDIR);
    839 
    840         krb5_add_et_list(context, initialize_asn1_error_table_r);
    8411018        bindtextdomain(COM_ERR_BINDDOMAIN_asn1, HEIMDAL_LOCALEDIR);
    842 
    843         krb5_add_et_list(context, initialize_heim_error_table_r);
    8441019        bindtextdomain(COM_ERR_BINDDOMAIN_heim, HEIMDAL_LOCALEDIR);
    845 
    846         krb5_add_et_list(context, initialize_k524_error_table_r);
    8471020        bindtextdomain(COM_ERR_BINDDOMAIN_k524, HEIMDAL_LOCALEDIR);
     1021#endif
    8481022
    8491023#ifdef PKINIT
    8501024        krb5_add_et_list(context, initialize_hx_error_table_r);
     1025#ifdef COM_ERR_BINDDOMAIN_hx
    8511026        bindtextdomain(COM_ERR_BINDDOMAIN_hx, HEIMDAL_LOCALEDIR);
    8521027#endif
     1028#endif
    8531029    }
    8541030}
     
    8631039 */
    8641040
    865 void KRB5_LIB_FUNCTION
     1041KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8661042krb5_set_use_admin_kdc (krb5_context context, krb5_boolean flag)
    8671043{
     
    8791055 */
    8801056
    881 krb5_boolean KRB5_LIB_FUNCTION
     1057KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    8821058krb5_get_use_admin_kdc (krb5_context context)
    8831059{
     
    8981074 */
    8991075
    900 krb5_error_code KRB5_LIB_FUNCTION
     1076KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9011077krb5_add_extra_addresses(krb5_context context, krb5_addresses *addresses)
    9021078{
     
    9221098 */
    9231099
    924 krb5_error_code KRB5_LIB_FUNCTION
     1100KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9251101krb5_set_extra_addresses(krb5_context context, const krb5_addresses *addresses)
    9261102{
     
    9581134 */
    9591135
    960 krb5_error_code KRB5_LIB_FUNCTION
     1136KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9611137krb5_get_extra_addresses(krb5_context context, krb5_addresses *addresses)
    9621138{
     
    9811157 */
    9821158
    983 krb5_error_code KRB5_LIB_FUNCTION
     1159KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9841160krb5_add_ignore_addresses(krb5_context context, krb5_addresses *addresses)
    9851161{
     
    10051181 */
    10061182
    1007 krb5_error_code KRB5_LIB_FUNCTION
     1183KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10081184krb5_set_ignore_addresses(krb5_context context, const krb5_addresses *addresses)
    10091185{
     
    10401216 */
    10411217
    1042 krb5_error_code KRB5_LIB_FUNCTION
     1218KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10431219krb5_get_ignore_addresses(krb5_context context, krb5_addresses *addresses)
    10441220{
     
    10621238 */
    10631239
    1064 krb5_error_code KRB5_LIB_FUNCTION
     1240KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10651241krb5_set_fcache_version(krb5_context context, int version)
    10661242{
     
    10811257 */
    10821258
    1083 krb5_error_code KRB5_LIB_FUNCTION
     1259KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10841260krb5_get_fcache_version(krb5_context context, int *version)
    10851261{
     
    10971273
    10981274
    1099 krb5_boolean KRB5_LIB_FUNCTION
     1275KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    11001276krb5_is_thread_safe(void)
    11011277{
     
    11161292 */
    11171293
    1118 void KRB5_LIB_FUNCTION
     1294KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    11191295krb5_set_dns_canonicalize_hostname (krb5_context context, krb5_boolean flag)
    11201296{
     
    11351311 */
    11361312
    1137 krb5_boolean KRB5_LIB_FUNCTION
     1313KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    11381314krb5_get_dns_canonicalize_hostname (krb5_context context)
    11391315{
     
    11531329 */
    11541330
    1155 krb5_error_code KRB5_LIB_FUNCTION
     1331KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11561332krb5_get_kdc_sec_offset (krb5_context context, int32_t *sec, int32_t *usec)
    11571333{
     
    11751351 */
    11761352
    1177 krb5_error_code KRB5_LIB_FUNCTION
     1353KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11781354krb5_set_kdc_sec_offset (krb5_context context, int32_t sec, int32_t usec)
    11791355{
     
    11941370 */
    11951371
    1196 time_t KRB5_LIB_FUNCTION
     1372KRB5_LIB_FUNCTION time_t KRB5_LIB_CALL
    11971373krb5_get_max_time_skew (krb5_context context)
    11981374{
     
    12091385 */
    12101386
    1211 void KRB5_LIB_FUNCTION
     1387KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    12121388krb5_set_max_time_skew (krb5_context context, time_t t)
    12131389{
     
    12291405 */
    12301406
    1231 krb5_error_code KRB5_LIB_FUNCTION
     1407KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12321408krb5_init_etype (krb5_context context,
    12331409                 unsigned *len,
     
    12771453    krb5_boolean allow;
    12781454
     1455#ifdef HAVE_GETEUID
    12791456    /* is never allowed for root */
    12801457    if (geteuid() == 0)
    12811458        return FALSE;
     1459#endif
    12821460
    12831461    if (context && (context->flags & KRB5_CTX_F_HOMEDIR_ACCESS) == 0)
     
    13051483 * @return the old value
    13061484 *
    1307  */
    1308 
    1309 krb5_boolean
     1485 * @ingroup krb5
     1486 */
     1487
     1488KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    13101489krb5_set_home_dir_access(krb5_context context, krb5_boolean allow)
    13111490{
  • trunk/server/source4/heimdal/lib/krb5/convert_creds.c

    r414 r745  
    3232 */
    3333
     34#define KRB5_DEPRECATED
     35
    3436#include "krb5_locl.h"
    3537#include "krb5-v4compat.h"
    3638
    3739#ifndef HEIMDAL_SMALLER
    38 
    39 static krb5_error_code
    40 check_ticket_flags(TicketFlags f)
    41 {
    42     return 0; /* maybe add some more tests here? */
    43 }
    4440
    4541/**
     
    5955 */
    6056
    61 krb5_error_code KRB5_LIB_FUNCTION
     57KRB5_DEPRECATED
     58KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6259krb524_convert_creds_kdc(krb5_context context,
    6360                         krb5_creds *in_cred,
    6461                         struct credentials *v4creds)
    6562{
    66     krb5_error_code ret;
    67     krb5_data reply;
    68     krb5_storage *sp;
    69     int32_t tmp;
    70     krb5_data ticket;
    71     char realm[REALM_SZ];
    72     krb5_creds *v5_creds = in_cred;
    73 
    74     ret = check_ticket_flags(v5_creds->flags.b);
    75     if(ret)
    76         goto out2;
    77 
    78     {
    79         krb5_krbhst_handle handle;
    80 
    81         ret = krb5_krbhst_init(context,
    82                                krb5_principal_get_realm(context,
    83                                                         v5_creds->server),
    84                                KRB5_KRBHST_KRB524,
    85                                &handle);
    86         if (ret)
    87             goto out2;
    88 
    89         ret = krb5_sendto (context,
    90                            &v5_creds->ticket,
    91                            handle,
    92                            &reply);
    93         krb5_krbhst_free(context, handle);
    94         if (ret)
    95             goto out2;
    96     }
    97     sp = krb5_storage_from_mem(reply.data, reply.length);
    98     if(sp == NULL) {
    99         ret = ENOMEM;
    100         krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    101         goto out2;
    102     }
    103     krb5_ret_int32(sp, &tmp);
    104     ret = tmp;
    105     if(ret == 0) {
    106         memset(v4creds, 0, sizeof(*v4creds));
    107         ret = krb5_ret_int32(sp, &tmp);
    108         if(ret)
    109             goto out;
    110         v4creds->kvno = tmp;
    111         ret = krb5_ret_data(sp, &ticket);
    112         if(ret)
    113             goto out;
    114         v4creds->ticket_st.length = ticket.length;
    115         memcpy(v4creds->ticket_st.dat, ticket.data, ticket.length);
    116         krb5_data_free(&ticket);
    117         ret = krb5_524_conv_principal(context,
    118                                       v5_creds->server,
    119                                       v4creds->service,
    120                                       v4creds->instance,
    121                                       v4creds->realm);
    122         if(ret)
    123             goto out;
    124         v4creds->issue_date = v5_creds->times.starttime;
    125         v4creds->lifetime = _krb5_krb_time_to_life(v4creds->issue_date,
    126                                                    v5_creds->times.endtime);
    127         ret = krb5_524_conv_principal(context, v5_creds->client,
    128                                       v4creds->pname,
    129                                       v4creds->pinst,
    130                                       realm);
    131         if(ret)
    132             goto out;
    133         memcpy(v4creds->session, v5_creds->session.keyvalue.data, 8);
    134     } else {
    135         krb5_set_error_message (context, ret,
    136                                 N_("converting credentials: %s",
    137                                   "already localized"),
    138                                 krb5_get_err_text(context, ret));
    139     }
    140 out:
    141     krb5_storage_free(sp);
    142     krb5_data_free(&reply);
    143 out2:
    144     if (v5_creds != in_cred)
    145         krb5_free_creds (context, v5_creds);
    146     return ret;
     63    memset(v4creds, 0, sizeof(*v4creds));
     64    krb5_set_error_message(context, EINVAL,
     65                           N_("krb524_convert_creds_kdc not supported", ""));
     66    return EINVAL;
    14767}
    14868
     
    16282 */
    16383
    164 krb5_error_code KRB5_LIB_FUNCTION
     84KRB5_DEPRECATED
     85KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    16586krb524_convert_creds_kdc_ccache(krb5_context context,
    16687                                krb5_ccache ccache,
     
    16889                                struct credentials *v4creds)
    16990{
    170     krb5_error_code ret;
    171     krb5_creds *v5_creds = in_cred;
    172     krb5_keytype keytype;
    173 
    174     keytype = v5_creds->session.keytype;
    175 
    176     if (keytype != ENCTYPE_DES_CBC_CRC) {
    177         /* MIT krb524d doesn't like nothing but des-cbc-crc tickets,
    178            so go get one */
    179         krb5_creds template;
    180 
    181         memset (&template, 0, sizeof(template));
    182         template.session.keytype = ENCTYPE_DES_CBC_CRC;
    183         ret = krb5_copy_principal (context, in_cred->client, &template.client);
    184         if (ret) {
    185             krb5_free_cred_contents (context, &template);
    186             return ret;
    187         }
    188         ret = krb5_copy_principal (context, in_cred->server, &template.server);
    189         if (ret) {
    190             krb5_free_cred_contents (context, &template);
    191             return ret;
    192         }
    193 
    194         ret = krb5_get_credentials (context, 0, ccache,
    195                                     &template, &v5_creds);
    196         krb5_free_cred_contents (context, &template);
    197         if (ret)
    198             return ret;
    199     }
    200 
    201     ret = krb524_convert_creds_kdc(context, v5_creds, v4creds);
    202 
    203     if (v5_creds != in_cred)
    204         krb5_free_creds (context, v5_creds);
    205     return ret;
     91    memset(v4creds, 0, sizeof(*v4creds));
     92    krb5_set_error_message(context, EINVAL,
     93                           N_("krb524_convert_creds_kdc_ccache not supported", ""));
     94    return EINVAL;
    20695}
    20796
  • trunk/server/source4/heimdal/lib/krb5/copy_host_realm.c

    r414 r745  
    4747 */
    4848
    49 krb5_error_code KRB5_LIB_FUNCTION
     49KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5050krb5_copy_host_realm(krb5_context context,
    5151                     const krb5_realm *from,
  • trunk/server/source4/heimdal/lib/krb5/creds.c

    r414 r745  
    4646 */
    4747
    48 krb5_error_code KRB5_LIB_FUNCTION
     48KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4949krb5_free_cred_contents (krb5_context context, krb5_creds *c)
    5050{
     
    7575 */
    7676
    77 krb5_error_code KRB5_LIB_FUNCTION
     77KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    7878krb5_copy_creds_contents (krb5_context context,
    7979                          const krb5_creds *incred,
     
    132132 */
    133133
    134 krb5_error_code KRB5_LIB_FUNCTION
     134KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    135135krb5_copy_creds (krb5_context context,
    136136                 const krb5_creds *incred,
     
    162162 */
    163163
    164 krb5_error_code KRB5_LIB_FUNCTION
     164KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    165165krb5_free_creds (krb5_context context, krb5_creds *c)
    166166{
     
    184184 * determines what equal means).
    185185 *
     186 *
     187 * The following flags, set in whichfields affects the comparison:
     188 * - KRB5_TC_MATCH_SRV_NAMEONLY Consider all realms equal when comparing the service principal.
     189 * - KRB5_TC_MATCH_KEYTYPE Compare enctypes.
     190 * - KRB5_TC_MATCH_FLAGS_EXACT Make sure that the ticket flags are identical.
     191 * - KRB5_TC_MATCH_FLAGS Make sure that all ticket flags set in mcreds are also present in creds .
     192 * - KRB5_TC_MATCH_TIMES_EXACT Compares the ticket times exactly.
     193 * - KRB5_TC_MATCH_TIMES Compares only the expiration times of the creds.
     194 * - KRB5_TC_MATCH_AUTHDATA Compares the authdata fields.
     195 * - KRB5_TC_MATCH_2ND_TKT Compares the second tickets (used by user-to-user authentication).
     196 * - KRB5_TC_MATCH_IS_SKEY Compares the existance of the second ticket.
     197 *
    186198 * @param context Kerberos 5 context.
    187199 * @param whichfields which fields to compare.
     
    194206 */
    195207
    196 krb5_boolean KRB5_LIB_FUNCTION
     208KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    197209krb5_compare_creds(krb5_context context, krb5_flags whichfields,
    198210                   const krb5_creds * mcreds, const krb5_creds * creds)
     
    267279 */
    268280
    269 unsigned long
     281KRB5_LIB_FUNCTION unsigned long KRB5_LIB_CALL
    270282krb5_creds_get_ticket_flags(krb5_creds *creds)
    271283{
  • trunk/server/source4/heimdal/lib/krb5/crypto.c

    r414 r745  
    3535
    3636#include "krb5_locl.h"
    37 #include <pkinit_asn1.h>
    38 
    39 #define WEAK_ENCTYPES 1
     37
     38struct _krb5_key_usage {
     39    unsigned usage;
     40    struct _krb5_key_data key;
     41};
     42
    4043
    4144#ifndef HEIMDAL_SMALLER
     
    4346#endif
    4447
    45 
    46 #ifdef HAVE_OPENSSL /* XXX forward decl for hcrypto glue */
    47 const EVP_CIPHER * _krb5_EVP_hcrypto_aes_128_cts(void);
    48 const EVP_CIPHER * _krb5_EVP_hcrypto_aes_256_cts(void);
    49 #define EVP_hcrypto_aes_128_cts _krb5_EVP_hcrypto_aes_128_cts
    50 #define EVP_hcrypto_aes_256_cts _krb5_EVP_hcrypto_aes_256_cts
    51 #endif
    52 
    53 struct key_data {
    54     krb5_keyblock *key;
    55     krb5_data *schedule;
    56 };
    57 
    58 struct key_usage {
    59     unsigned usage;
    60     struct key_data key;
    61 };
    62 
    63 struct krb5_crypto_data {
    64     struct encryption_type *et;
    65     struct key_data key;
    66     int num_key_usage;
    67     struct key_usage *key_usage;
    68 };
    69 
    70 #define CRYPTO_ETYPE(C) ((C)->et->type)
    71 
    72 /* bits for `flags' below */
    73 #define F_KEYED          1      /* checksum is keyed */
    74 #define F_CPROOF         2      /* checksum is collision proof */
    75 #define F_DERIVED        4      /* uses derived keys */
    76 #define F_VARIANT        8      /* uses `variant' keys (6.4.3) */
    77 #define F_PSEUDO        16      /* not a real protocol type */
    78 #define F_SPECIAL       32      /* backwards */
    79 #define F_DISABLED      64      /* enctype/checksum disabled */
    80 
    81 struct salt_type {
    82     krb5_salttype type;
    83     const char *name;
    84     krb5_error_code (*string_to_key)(krb5_context, krb5_enctype, krb5_data,
    85                                      krb5_salt, krb5_data, krb5_keyblock*);
    86 };
    87 
    88 struct key_type {
    89     krb5_keytype type; /* XXX */
    90     const char *name;
    91     size_t bits;
    92     size_t size;
    93     size_t schedule_size;
    94     void (*random_key)(krb5_context, krb5_keyblock*);
    95     void (*schedule)(krb5_context, struct key_type *, struct key_data *);
    96     struct salt_type *string_to_key;
    97     void (*random_to_key)(krb5_context, krb5_keyblock*, const void*, size_t);
    98     void (*cleanup)(krb5_context, struct key_data *);
    99     const EVP_CIPHER *(*evp)(void);
    100 };
    101 
    102 struct checksum_type {
    103     krb5_cksumtype type;
    104     const char *name;
    105     size_t blocksize;
    106     size_t checksumsize;
    107     unsigned flags;
    108     krb5_enctype (*checksum)(krb5_context context,
    109                              struct key_data *key,
    110                              const void *buf, size_t len,
    111                              unsigned usage,
    112                              Checksum *csum);
    113     krb5_error_code (*verify)(krb5_context context,
    114                               struct key_data *key,
    115                               const void *buf, size_t len,
    116                               unsigned usage,
    117                               Checksum *csum);
    118 };
    119 
    120 struct encryption_type {
    121     krb5_enctype type;
    122     const char *name;
    123     size_t blocksize;
    124     size_t padsize;
    125     size_t confoundersize;
    126     struct key_type *keytype;
    127     struct checksum_type *checksum;
    128     struct checksum_type *keyed_checksum;
    129     unsigned flags;
    130     krb5_error_code (*encrypt)(krb5_context context,
    131                                struct key_data *key,
    132                                void *data, size_t len,
    133                                krb5_boolean encryptp,
    134                                int usage,
    135                                void *ivec);
    136     size_t prf_length;
    137     krb5_error_code (*prf)(krb5_context,
    138                            krb5_crypto, const krb5_data *, krb5_data *);
    139 };
    140 
    141 #define ENCRYPTION_USAGE(U) (((U) << 8) | 0xAA)
    142 #define INTEGRITY_USAGE(U) (((U) << 8) | 0x55)
    143 #define CHECKSUM_USAGE(U) (((U) << 8) | 0x99)
    144 
    145 static struct checksum_type *_find_checksum(krb5_cksumtype type);
    146 static struct encryption_type *_find_enctype(krb5_enctype type);
    14748static krb5_error_code _get_derived_key(krb5_context, krb5_crypto,
    148                                         unsigned, struct key_data**);
    149 static struct key_data *_new_derived_key(krb5_crypto crypto, unsigned usage);
    150 static krb5_error_code derive_key(krb5_context context,
    151                                   struct encryption_type *et,
    152                                   struct key_data *key,
    153                                   const void *constant,
    154                                   size_t len);
    155 static krb5_error_code hmac(krb5_context context,
    156                             struct checksum_type *cm,
    157                             const void *data,
    158                             size_t len,
    159                             unsigned usage,
    160                             struct key_data *keyblock,
    161                             Checksum *result);
    162 static void free_key_data(krb5_context,
    163                           struct key_data *,
    164                           struct encryption_type *);
     49                                        unsigned, struct _krb5_key_data**);
     50static struct _krb5_key_data *_new_derived_key(krb5_crypto crypto, unsigned usage);
     51
    16552static void free_key_schedule(krb5_context,
    166                               struct key_data *,
    167                               struct encryption_type *);
    168 static krb5_error_code usage2arcfour (krb5_context, unsigned *);
    169 static void xor (DES_cblock *, const unsigned char *);
     53                              struct _krb5_key_data *,
     54                              struct _krb5_encryption_type *);
    17055
    17156/************************************************************
     
    17358 ************************************************************/
    17459
    175 struct evp_schedule {
    176     EVP_CIPHER_CTX ectx;
    177     EVP_CIPHER_CTX dctx;
    178 };
    179 
    180 
    181 static HEIMDAL_MUTEX crypto_mutex = HEIMDAL_MUTEX_INITIALIZER;
    182 
    183 #ifdef WEAK_ENCTYPES
    184 static void
    185 krb5_DES_random_key(krb5_context context,
    186                     krb5_keyblock *key)
    187 {
    188     DES_cblock *k = key->keyvalue.data;
    189     do {
    190         krb5_generate_random_block(k, sizeof(DES_cblock));
    191         DES_set_odd_parity(k);
    192     } while(DES_is_weak_key(k));
    193 }
    194 
    195 static void
    196 krb5_DES_schedule_old(krb5_context context,
    197                       struct key_type *kt,
    198                       struct key_data *key)
    199 {
    200     DES_set_key_unchecked(key->key->keyvalue.data, key->schedule->data);
    201 }
    202 
    203 #ifdef ENABLE_AFS_STRING_TO_KEY
    204 
    205 /* This defines the Andrew string_to_key function.  It accepts a password
    206  * string as input and converts it via a one-way encryption algorithm to a DES
    207  * encryption key.  It is compatible with the original Andrew authentication
    208  * service password database.
    209  */
    210 
    211 /*
    212  * Short passwords, i.e 8 characters or less.
    213  */
    214 static void
    215 krb5_DES_AFS3_CMU_string_to_key (krb5_data pw,
    216                                  krb5_data cell,
    217                                  DES_cblock *key)
    218 {
    219     char  password[8+1];        /* crypt is limited to 8 chars anyway */
    220     int   i;
    221 
    222     for(i = 0; i < 8; i++) {
    223         char c = ((i < pw.length) ? ((char*)pw.data)[i] : 0) ^
    224             ((i < cell.length) ?
    225              tolower(((unsigned char*)cell.data)[i]) : 0);
    226         password[i] = c ? c : 'X';
    227     }
    228     password[8] = '\0';
    229 
    230     memcpy(key, crypt(password, "p1") + 2, sizeof(DES_cblock));
    231 
    232     /* parity is inserted into the LSB so left shift each byte up one
    233        bit. This allows ascii characters with a zero MSB to retain as
    234        much significance as possible. */
    235     for (i = 0; i < sizeof(DES_cblock); i++)
    236         ((unsigned char*)key)[i] <<= 1;
    237     DES_set_odd_parity (key);
    238 }
    239 
    240 /*
    241  * Long passwords, i.e 9 characters or more.
    242  */
    243 static void
    244 krb5_DES_AFS3_Transarc_string_to_key (krb5_data pw,
    245                                       krb5_data cell,
    246                                       DES_cblock *key)
    247 {
    248     DES_key_schedule schedule;
    249     DES_cblock temp_key;
    250     DES_cblock ivec;
    251     char password[512];
    252     size_t passlen;
    253 
    254     memcpy(password, pw.data, min(pw.length, sizeof(password)));
    255     if(pw.length < sizeof(password)) {
    256         int len = min(cell.length, sizeof(password) - pw.length);
    257         int i;
    258 
    259         memcpy(password + pw.length, cell.data, len);
    260         for (i = pw.length; i < pw.length + len; ++i)
    261             password[i] = tolower((unsigned char)password[i]);
    262     }
    263     passlen = min(sizeof(password), pw.length + cell.length);
    264     memcpy(&ivec, "kerberos", 8);
    265     memcpy(&temp_key, "kerberos", 8);
    266     DES_set_odd_parity (&temp_key);
    267     DES_set_key_unchecked (&temp_key, &schedule);
    268     DES_cbc_cksum ((void*)password, &ivec, passlen, &schedule, &ivec);
    269 
    270     memcpy(&temp_key, &ivec, 8);
    271     DES_set_odd_parity (&temp_key);
    272     DES_set_key_unchecked (&temp_key, &schedule);
    273     DES_cbc_cksum ((void*)password, key, passlen, &schedule, &ivec);
    274     memset(&schedule, 0, sizeof(schedule));
    275     memset(&temp_key, 0, sizeof(temp_key));
    276     memset(&ivec, 0, sizeof(ivec));
    277     memset(password, 0, sizeof(password));
    278 
    279     DES_set_odd_parity (key);
    280 }
    281 
    282 static krb5_error_code
    283 DES_AFS3_string_to_key(krb5_context context,
    284                        krb5_enctype enctype,
    285                        krb5_data password,
    286                        krb5_salt salt,
    287                        krb5_data opaque,
    288                        krb5_keyblock *key)
    289 {
    290     DES_cblock tmp;
    291     if(password.length > 8)
    292         krb5_DES_AFS3_Transarc_string_to_key(password, salt.saltvalue, &tmp);
    293     else
    294         krb5_DES_AFS3_CMU_string_to_key(password, salt.saltvalue, &tmp);
    295     key->keytype = enctype;
    296     krb5_data_copy(&key->keyvalue, tmp, sizeof(tmp));
    297     memset(&key, 0, sizeof(key));
    298     return 0;
    299 }
    300 #endif /* ENABLE_AFS_STRING_TO_KEY */
    301 
    302 static void
    303 DES_string_to_key_int(unsigned char *data, size_t length, DES_cblock *key)
    304 {
    305     DES_key_schedule schedule;
    306     int i;
    307     int reverse = 0;
    308     unsigned char *p;
    309 
    310     unsigned char swap[] = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
    311                              0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf };
    312     memset(key, 0, 8);
    313 
    314     p = (unsigned char*)key;
    315     for (i = 0; i < length; i++) {
    316         unsigned char tmp = data[i];
    317         if (!reverse)
    318             *p++ ^= (tmp << 1);
    319         else
    320             *--p ^= (swap[tmp & 0xf] << 4) | swap[(tmp & 0xf0) >> 4];
    321         if((i % 8) == 7)
    322             reverse = !reverse;
    323     }
    324     DES_set_odd_parity(key);
    325     if(DES_is_weak_key(key))
    326         (*key)[7] ^= 0xF0;
    327     DES_set_key_unchecked(key, &schedule);
    328     DES_cbc_cksum((void*)data, key, length, &schedule, key);
    329     memset(&schedule, 0, sizeof(schedule));
    330     DES_set_odd_parity(key);
    331     if(DES_is_weak_key(key))
    332         (*key)[7] ^= 0xF0;
    333 }
    334 
    335 static krb5_error_code
    336 krb5_DES_string_to_key(krb5_context context,
    337                        krb5_enctype enctype,
    338                        krb5_data password,
    339                        krb5_salt salt,
    340                        krb5_data opaque,
    341                        krb5_keyblock *key)
    342 {
    343     unsigned char *s;
    344     size_t len;
    345     DES_cblock tmp;
    346 
    347 #ifdef ENABLE_AFS_STRING_TO_KEY
    348     if (opaque.length == 1) {
    349         unsigned long v;
    350         _krb5_get_int(opaque.data, &v, 1);
    351         if (v == 1)
    352             return DES_AFS3_string_to_key(context, enctype, password,
    353                                           salt, opaque, key);
    354     }
    355 #endif
    356 
    357     len = password.length + salt.saltvalue.length;
    358     s = malloc(len);
    359     if(len > 0 && s == NULL) {
    360         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    361         return ENOMEM;
    362     }
    363     memcpy(s, password.data, password.length);
    364     memcpy(s + password.length, salt.saltvalue.data, salt.saltvalue.length);
    365     DES_string_to_key_int(s, len, &tmp);
    366     key->keytype = enctype;
    367     krb5_data_copy(&key->keyvalue, tmp, sizeof(tmp));
    368     memset(&tmp, 0, sizeof(tmp));
    369     memset(s, 0, len);
    370     free(s);
    371     return 0;
    372 }
    373 
    374 static void
    375 krb5_DES_random_to_key(krb5_context context,
    376                        krb5_keyblock *key,
    377                        const void *data,
    378                        size_t size)
    379 {
    380     DES_cblock *k = key->keyvalue.data;
    381     memcpy(k, data, key->keyvalue.length);
    382     DES_set_odd_parity(k);
    383     if(DES_is_weak_key(k))
    384         xor(k, (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
    385 }
    386 #endif
    387 
    388 /*
    389  *
    390  */
    391 
    392 static void
    393 DES3_random_key(krb5_context context,
    394                 krb5_keyblock *key)
    395 {
    396     DES_cblock *k = key->keyvalue.data;
    397     do {
    398         krb5_generate_random_block(k, 3 * sizeof(DES_cblock));
    399         DES_set_odd_parity(&k[0]);
    400         DES_set_odd_parity(&k[1]);
    401         DES_set_odd_parity(&k[2]);
    402     } while(DES_is_weak_key(&k[0]) ||
    403             DES_is_weak_key(&k[1]) ||
    404             DES_is_weak_key(&k[2]));
    405 }
    406 
    407 /*
    408  * A = A xor B. A & B are 8 bytes.
    409  */
    410 
    411 static void
    412 xor (DES_cblock *key, const unsigned char *b)
    413 {
    414     unsigned char *a = (unsigned char*)key;
    415     a[0] ^= b[0];
    416     a[1] ^= b[1];
    417     a[2] ^= b[2];
    418     a[3] ^= b[3];
    419     a[4] ^= b[4];
    420     a[5] ^= b[5];
    421     a[6] ^= b[6];
    422     a[7] ^= b[7];
    423 }
    424 
    425 #ifdef DES3_OLD_ENCTYPE
    426 static krb5_error_code
    427 DES3_string_to_key(krb5_context context,
    428                    krb5_enctype enctype,
    429                    krb5_data password,
    430                    krb5_salt salt,
    431                    krb5_data opaque,
    432                    krb5_keyblock *key)
    433 {
    434     char *str;
    435     size_t len;
    436     unsigned char tmp[24];
    437     DES_cblock keys[3];
    438     krb5_error_code ret;
    439 
    440     len = password.length + salt.saltvalue.length;
    441     str = malloc(len);
    442     if(len != 0 && str == NULL) {
    443         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    444         return ENOMEM;
    445     }
    446     memcpy(str, password.data, password.length);
    447     memcpy(str + password.length, salt.saltvalue.data, salt.saltvalue.length);
    448     {
    449         DES_cblock ivec;
    450         DES_key_schedule s[3];
    451         int i;
    452        
    453         ret = _krb5_n_fold(str, len, tmp, 24);
    454         if (ret) {
    455             memset(str, 0, len);
    456             free(str);
    457             krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
    458             return ret;
    459         }
    460        
    461         for(i = 0; i < 3; i++){
    462             memcpy(keys + i, tmp + i * 8, sizeof(keys[i]));
    463             DES_set_odd_parity(keys + i);
    464             if(DES_is_weak_key(keys + i))
    465                 xor(keys + i, (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
    466             DES_set_key_unchecked(keys + i, &s[i]);
    467         }
    468         memset(&ivec, 0, sizeof(ivec));
    469         DES_ede3_cbc_encrypt(tmp,
    470                              tmp, sizeof(tmp),
    471                              &s[0], &s[1], &s[2], &ivec, DES_ENCRYPT);
    472         memset(s, 0, sizeof(s));
    473         memset(&ivec, 0, sizeof(ivec));
    474         for(i = 0; i < 3; i++){
    475             memcpy(keys + i, tmp + i * 8, sizeof(keys[i]));
    476             DES_set_odd_parity(keys + i);
    477             if(DES_is_weak_key(keys + i))
    478                 xor(keys + i, (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
    479         }
    480         memset(tmp, 0, sizeof(tmp));
    481     }
    482     key->keytype = enctype;
    483     krb5_data_copy(&key->keyvalue, keys, sizeof(keys));
    484     memset(keys, 0, sizeof(keys));
    485     memset(str, 0, len);
    486     free(str);
    487     return 0;
    488 }
    489 #endif
    490 
    491 static krb5_error_code
    492 DES3_string_to_key_derived(krb5_context context,
    493                            krb5_enctype enctype,
    494                            krb5_data password,
    495                            krb5_salt salt,
    496                            krb5_data opaque,
    497                            krb5_keyblock *key)
    498 {
    499     krb5_error_code ret;
    500     size_t len = password.length + salt.saltvalue.length;
    501     char *s;
    502 
    503     s = malloc(len);
    504     if(len != 0 && s == NULL) {
    505         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    506         return ENOMEM;
    507     }
    508     memcpy(s, password.data, password.length);
    509     memcpy(s + password.length, salt.saltvalue.data, salt.saltvalue.length);
    510     ret = krb5_string_to_key_derived(context,
    511                                      s,
    512                                      len,
    513                                      enctype,
    514                                      key);
    515     memset(s, 0, len);
    516     free(s);
    517     return ret;
    518 }
    519 
    520 static void
    521 DES3_random_to_key(krb5_context context,
    522                    krb5_keyblock *key,
    523                    const void *data,
    524                    size_t size)
    525 {
    526     unsigned char *x = key->keyvalue.data;
    527     const u_char *q = data;
    528     DES_cblock *k;
    529     int i, j;
    530 
    531     memset(x, 0, sizeof(x));
    532     for (i = 0; i < 3; ++i) {
    533         unsigned char foo;
    534         for (j = 0; j < 7; ++j) {
    535             unsigned char b = q[7 * i + j];
    536 
    537             x[8 * i + j] = b;
    538         }
    539         foo = 0;
    540         for (j = 6; j >= 0; --j) {
    541             foo |= q[7 * i + j] & 1;
    542             foo <<= 1;
    543         }
    544         x[8 * i + 7] = foo;
    545     }
    546     k = key->keyvalue.data;
    547     for (i = 0; i < 3; i++) {
    548         DES_set_odd_parity(&k[i]);
    549         if(DES_is_weak_key(&k[i]))
    550             xor(&k[i], (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
    551     }
    552 }
    553 
    554 /*
    555  * ARCFOUR
    556  */
    557 
    558 static void
    559 ARCFOUR_schedule(krb5_context context,
    560                  struct key_type *kt,
    561                  struct key_data *kd)
    562 {
    563     RC4_set_key (kd->schedule->data,
    564                  kd->key->keyvalue.length, kd->key->keyvalue.data);
    565 }
    566 
    567 static krb5_error_code
    568 ARCFOUR_string_to_key(krb5_context context,
    569                       krb5_enctype enctype,
    570                       krb5_data password,
    571                       krb5_salt salt,
    572                       krb5_data opaque,
    573                       krb5_keyblock *key)
    574 {
    575     krb5_error_code ret;
    576     uint16_t *s = NULL;
    577     size_t len, i;
    578     EVP_MD_CTX *m;
    579 
    580     m = EVP_MD_CTX_create();
    581     if (m == NULL) {
    582         ret = ENOMEM;
    583         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
    584         goto out;
    585     }
    586 
    587     EVP_DigestInit_ex(m, EVP_md4(), NULL);
    588 
    589     ret = wind_utf8ucs2_length(password.data, &len);
    590     if (ret) {
    591         krb5_set_error_message (context, ret,
    592                                 N_("Password not an UCS2 string", ""));
    593         goto out;
    594     }
    595        
    596     s = malloc (len * sizeof(s[0]));
    597     if (len != 0 && s == NULL) {
    598         krb5_set_error_message (context, ENOMEM,
    599                                 N_("malloc: out of memory", ""));
    600         ret = ENOMEM;
    601         goto out;
    602     }
    603 
    604     ret = wind_utf8ucs2(password.data, s, &len);
    605     if (ret) {
    606         krb5_set_error_message (context, ret,
    607                                 N_("Password not an UCS2 string", ""));
    608         goto out;
    609     }
    610 
    611     /* LE encoding */
    612     for (i = 0; i < len; i++) {
    613         unsigned char p;
    614         p = (s[i] & 0xff);
    615         EVP_DigestUpdate (m, &p, 1);
    616         p = (s[i] >> 8) & 0xff;
    617         EVP_DigestUpdate (m, &p, 1);
    618     }
    619 
    620     key->keytype = enctype;
    621     ret = krb5_data_alloc (&key->keyvalue, 16);
    622     if (ret) {
    623         krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    624         goto out;
    625     }
    626     EVP_DigestFinal_ex (m, key->keyvalue.data, NULL);
    627 
    628  out:
    629     EVP_MD_CTX_destroy(m);
    630     if (s)
    631         memset (s, 0, len);
    632     free (s);
    633     return ret;
    634 }
    635 
    636 /*
    637  * AES
    638  */
    639 
    640 int _krb5_AES_string_to_default_iterator = 4096;
    641 
    642 static krb5_error_code
    643 AES_string_to_key(krb5_context context,
    644                   krb5_enctype enctype,
    645                   krb5_data password,
    646                   krb5_salt salt,
    647                   krb5_data opaque,
    648                   krb5_keyblock *key)
    649 {
    650     krb5_error_code ret;
    651     uint32_t iter;
    652     struct encryption_type *et;
    653     struct key_data kd;
    654 
    655     if (opaque.length == 0)
    656         iter = _krb5_AES_string_to_default_iterator;
    657     else if (opaque.length == 4) {
    658         unsigned long v;
    659         _krb5_get_int(opaque.data, &v, 4);
    660         iter = ((uint32_t)v);
    661     } else
    662         return KRB5_PROG_KEYTYPE_NOSUPP; /* XXX */
    663        
    664     et = _find_enctype(enctype);
    665     if (et == NULL)
    666         return KRB5_PROG_KEYTYPE_NOSUPP;
    667 
    668     kd.schedule = NULL;
    669     ALLOC(kd.key, 1);
    670     if(kd.key == NULL) {
    671         krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    672         return ENOMEM;
    673     }
    674     kd.key->keytype = enctype;
    675     ret = krb5_data_alloc(&kd.key->keyvalue, et->keytype->size);
    676     if (ret) {
    677         krb5_set_error_message (context, ret, N_("malloc: out of memory", ""));
    678         return ret;
    679     }
    680 
    681     ret = PKCS5_PBKDF2_HMAC_SHA1(password.data, password.length,
    682                                  salt.saltvalue.data, salt.saltvalue.length,
    683                                  iter,
    684                                  et->keytype->size, kd.key->keyvalue.data);
    685     if (ret != 1) {
    686         free_key_data(context, &kd, et);
    687         krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
    688                                "Error calculating s2k");
    689         return KRB5_PROG_KEYTYPE_NOSUPP;
    690     }
    691 
    692     ret = derive_key(context, et, &kd, "kerberos", strlen("kerberos"));
    693     if (ret == 0)
    694         ret = krb5_copy_keyblock_contents(context, kd.key, key);
    695     free_key_data(context, &kd, et);
    696 
    697     return ret;
    698 }
    699 
    700 static void
    701 evp_schedule(krb5_context context, struct key_type *kt, struct key_data *kd)
    702 {
    703     struct evp_schedule *key = kd->schedule->data;
    704     const EVP_CIPHER *c = (*kt->evp)();
    705 
    706     EVP_CIPHER_CTX_init(&key->ectx);
    707     EVP_CIPHER_CTX_init(&key->dctx);
    708 
    709     EVP_CipherInit_ex(&key->ectx, c, NULL, kd->key->keyvalue.data, NULL, 1);
    710     EVP_CipherInit_ex(&key->dctx, c, NULL, kd->key->keyvalue.data, NULL, 0);
    711 }
    712 
    713 static void
    714 evp_cleanup(krb5_context context, struct key_data *kd)
    715 {
    716     struct evp_schedule *key = kd->schedule->data;
    717     EVP_CIPHER_CTX_cleanup(&key->ectx);
    718     EVP_CIPHER_CTX_cleanup(&key->dctx);
    719 }
    720 
    721 /*
    722  *
    723  */
    724 
    725 #ifdef WEAK_ENCTYPES
    726 static struct salt_type des_salt[] = {
    727     {
    728         KRB5_PW_SALT,
    729         "pw-salt",
    730         krb5_DES_string_to_key
    731     },
    732 #ifdef ENABLE_AFS_STRING_TO_KEY
    733     {
    734         KRB5_AFS3_SALT,
    735         "afs3-salt",
    736         DES_AFS3_string_to_key
    737     },
    738 #endif
    739     { 0 }
    740 };
    741 #endif
    742 
    743 #ifdef DES3_OLD_ENCTYPE
    744 static struct salt_type des3_salt[] = {
    745     {
    746         KRB5_PW_SALT,
    747         "pw-salt",
    748         DES3_string_to_key
    749     },
    750     { 0 }
    751 };
    752 #endif
    753 
    754 static struct salt_type des3_salt_derived[] = {
    755     {
    756         KRB5_PW_SALT,
    757         "pw-salt",
    758         DES3_string_to_key_derived
    759     },
    760     { 0 }
    761 };
    762 
    763 static struct salt_type AES_salt[] = {
    764     {
    765         KRB5_PW_SALT,
    766         "pw-salt",
    767         AES_string_to_key
    768     },
    769     { 0 }
    770 };
    771 
    772 static struct salt_type arcfour_salt[] = {
    773     {
    774         KRB5_PW_SALT,
    775         "pw-salt",
    776         ARCFOUR_string_to_key
    777     },
    778     { 0 }
    779 };
    780 
    781 /*
    782  *
    783  */
    784 
    785 static struct key_type keytype_null = {
    786     KEYTYPE_NULL,
    787     "null",
    788     0,
    789     0,
    790     0,
    791     NULL,
    792     NULL,
    793     NULL
    794 };
    795 
    796 #ifdef WEAK_ENCTYPES
    797 static struct key_type keytype_des_old = {
    798     KEYTYPE_DES,
    799     "des-old",
    800     56,
    801     8,
    802     sizeof(DES_key_schedule),
    803     krb5_DES_random_key,
    804     krb5_DES_schedule_old,
    805     des_salt,
    806     krb5_DES_random_to_key
    807 };
    808 
    809 static struct key_type keytype_des = {
    810     KEYTYPE_DES,
    811     "des",
    812     56,
    813     8,
    814     sizeof(struct evp_schedule),
    815     krb5_DES_random_key,
    816     evp_schedule,
    817     des_salt,
    818     krb5_DES_random_to_key,
    819     evp_cleanup,
    820     EVP_des_cbc
    821 };
    822 #endif /* WEAK_ENCTYPES */
    823 
    824 #ifdef DES3_OLD_ENCTYPE
    825 static struct key_type keytype_des3 = {
    826     KEYTYPE_DES3,
    827     "des3",
    828     168,
    829     24,
    830     sizeof(struct evp_schedule),
    831     DES3_random_key,
    832     evp_schedule,
    833     des3_salt,
    834     DES3_random_to_key,
    835     evp_cleanup,
    836     EVP_des_ede3_cbc
    837 };
    838 #endif
    839 
    840 static struct key_type keytype_des3_derived = {
    841     KEYTYPE_DES3,
    842     "des3",
    843     168,
    844     24,
    845     sizeof(struct evp_schedule),
    846     DES3_random_key,
    847     evp_schedule,
    848     des3_salt_derived,
    849     DES3_random_to_key,
    850     evp_cleanup,
    851     EVP_des_ede3_cbc
    852 };
    853 
    854 static struct key_type keytype_aes128 = {
    855     KEYTYPE_AES128,
    856     "aes-128",
    857     128,
    858     16,
    859     sizeof(struct evp_schedule),
    860     NULL,
    861     evp_schedule,
    862     AES_salt,
    863     NULL,
    864     evp_cleanup,
    865     EVP_hcrypto_aes_128_cts
    866 };
    867 
    868 static struct key_type keytype_aes256 = {
    869     KEYTYPE_AES256,
    870     "aes-256",
    871     256,
    872     32,
    873     sizeof(struct evp_schedule),
    874     NULL,
    875     evp_schedule,
    876     AES_salt,
    877     NULL,
    878     evp_cleanup,
    879     EVP_hcrypto_aes_256_cts
    880 };
    881 
    882 static struct key_type keytype_arcfour = {
    883     KEYTYPE_ARCFOUR,
    884     "arcfour",
    885     128,
    886     16,
    887     sizeof(RC4_KEY),
    888     NULL,
    889     ARCFOUR_schedule,
    890     arcfour_salt
    891 };
    892 
    893 krb5_error_code KRB5_LIB_FUNCTION
    894 krb5_salttype_to_string (krb5_context context,
    895                          krb5_enctype etype,
    896                          krb5_salttype stype,
    897                          char **string)
    898 {
    899     struct encryption_type *e;
    900     struct salt_type *st;
    901 
    902     e = _find_enctype (etype);
    903     if (e == NULL) {
    904         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    905                                "encryption type %d not supported",
    906                                etype);
    907         return KRB5_PROG_ETYPE_NOSUPP;
    908     }
    909     for (st = e->keytype->string_to_key; st && st->type; st++) {
    910         if (st->type == stype) {
    911             *string = strdup (st->name);
    912             if (*string == NULL) {
    913                 krb5_set_error_message (context, ENOMEM,
    914                                         N_("malloc: out of memory", ""));
    915                 return ENOMEM;
    916             }
    917             return 0;
    918         }
    919     }
    920     krb5_set_error_message (context, HEIM_ERR_SALTTYPE_NOSUPP,
    921                             "salttype %d not supported", stype);
    922     return HEIM_ERR_SALTTYPE_NOSUPP;
    923 }
    924 
    925 krb5_error_code KRB5_LIB_FUNCTION
    926 krb5_string_to_salttype (krb5_context context,
    927                          krb5_enctype etype,
    928                          const char *string,
    929                          krb5_salttype *salttype)
    930 {
    931     struct encryption_type *e;
    932     struct salt_type *st;
    933 
    934     e = _find_enctype (etype);
    935     if (e == NULL) {
    936         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    937                                N_("encryption type %d not supported", ""),
    938                                etype);
    939         return KRB5_PROG_ETYPE_NOSUPP;
    940     }
    941     for (st = e->keytype->string_to_key; st && st->type; st++) {
    942         if (strcasecmp (st->name, string) == 0) {
    943             *salttype = st->type;
    944             return 0;
    945         }
    946     }
    947     krb5_set_error_message(context, HEIM_ERR_SALTTYPE_NOSUPP,
    948                            N_("salttype %s not supported", ""), string);
    949     return HEIM_ERR_SALTTYPE_NOSUPP;
    950 }
    951 
    952 krb5_error_code KRB5_LIB_FUNCTION
    953 krb5_get_pw_salt(krb5_context context,
    954                  krb5_const_principal principal,
    955                  krb5_salt *salt)
    956 {
    957     size_t len;
    958     int i;
    959     krb5_error_code ret;
    960     char *p;
    961 
    962     salt->salttype = KRB5_PW_SALT;
    963     len = strlen(principal->realm);
    964     for (i = 0; i < principal->name.name_string.len; ++i)
    965         len += strlen(principal->name.name_string.val[i]);
    966     ret = krb5_data_alloc (&salt->saltvalue, len);
    967     if (ret)
    968         return ret;
    969     p = salt->saltvalue.data;
    970     memcpy (p, principal->realm, strlen(principal->realm));
    971     p += strlen(principal->realm);
    972     for (i = 0; i < principal->name.name_string.len; ++i) {
    973         memcpy (p,
    974                 principal->name.name_string.val[i],
    975                 strlen(principal->name.name_string.val[i]));
    976         p += strlen(principal->name.name_string.val[i]);
    977     }
    978     return 0;
    979 }
    980 
    981 krb5_error_code KRB5_LIB_FUNCTION
    982 krb5_free_salt(krb5_context context,
    983                krb5_salt salt)
    984 {
    985     krb5_data_free(&salt.saltvalue);
    986     return 0;
    987 }
    988 
    989 krb5_error_code KRB5_LIB_FUNCTION
    990 krb5_string_to_key_data (krb5_context context,
    991                          krb5_enctype enctype,
    992                          krb5_data password,
    993                          krb5_principal principal,
    994                          krb5_keyblock *key)
    995 {
    996     krb5_error_code ret;
    997     krb5_salt salt;
    998 
    999     ret = krb5_get_pw_salt(context, principal, &salt);
    1000     if(ret)
    1001         return ret;
    1002     ret = krb5_string_to_key_data_salt(context, enctype, password, salt, key);
    1003     krb5_free_salt(context, salt);
    1004     return ret;
    1005 }
    1006 
    1007 krb5_error_code KRB5_LIB_FUNCTION
    1008 krb5_string_to_key (krb5_context context,
    1009                     krb5_enctype enctype,
    1010                     const char *password,
    1011                     krb5_principal principal,
    1012                     krb5_keyblock *key)
    1013 {
    1014     krb5_data pw;
    1015     pw.data = rk_UNCONST(password);
    1016     pw.length = strlen(password);
    1017     return krb5_string_to_key_data(context, enctype, pw, principal, key);
    1018 }
    1019 
    1020 krb5_error_code KRB5_LIB_FUNCTION
    1021 krb5_string_to_key_data_salt (krb5_context context,
    1022                               krb5_enctype enctype,
    1023                               krb5_data password,
    1024                               krb5_salt salt,
    1025                               krb5_keyblock *key)
    1026 {
    1027     krb5_data opaque;
    1028     krb5_data_zero(&opaque);
    1029     return krb5_string_to_key_data_salt_opaque(context, enctype, password,
    1030                                                salt, opaque, key);
    1031 }
    1032 
    1033 /*
    1034  * Do a string -> key for encryption type `enctype' operation on
    1035  * `password' (with salt `salt' and the enctype specific data string
    1036  * `opaque'), returning the resulting key in `key'
    1037  */
    1038 
    1039 krb5_error_code KRB5_LIB_FUNCTION
    1040 krb5_string_to_key_data_salt_opaque (krb5_context context,
    1041                                      krb5_enctype enctype,
    1042                                      krb5_data password,
    1043                                      krb5_salt salt,
    1044                                      krb5_data opaque,
    1045                                      krb5_keyblock *key)
    1046 {
    1047     struct encryption_type *et =_find_enctype(enctype);
    1048     struct salt_type *st;
    1049     if(et == NULL) {
    1050         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    1051                                N_("encryption type %d not supported", ""),
    1052                                enctype);
    1053         return KRB5_PROG_ETYPE_NOSUPP;
    1054     }
    1055     for(st = et->keytype->string_to_key; st && st->type; st++)
    1056         if(st->type == salt.salttype)
    1057             return (*st->string_to_key)(context, enctype, password,
    1058                                         salt, opaque, key);
    1059     krb5_set_error_message(context, HEIM_ERR_SALTTYPE_NOSUPP,
    1060                            N_("salt type %d not supported", ""),
    1061                            salt.salttype);
    1062     return HEIM_ERR_SALTTYPE_NOSUPP;
    1063 }
    1064 
    1065 /*
    1066  * Do a string -> key for encryption type `enctype' operation on the
    1067  * string `password' (with salt `salt'), returning the resulting key
    1068  * in `key'
    1069  */
    1070 
    1071 krb5_error_code KRB5_LIB_FUNCTION
    1072 krb5_string_to_key_salt (krb5_context context,
    1073                          krb5_enctype enctype,
    1074                          const char *password,
    1075                          krb5_salt salt,
    1076                          krb5_keyblock *key)
    1077 {
    1078     krb5_data pw;
    1079     pw.data = rk_UNCONST(password);
    1080     pw.length = strlen(password);
    1081     return krb5_string_to_key_data_salt(context, enctype, pw, salt, key);
    1082 }
    1083 
    1084 krb5_error_code KRB5_LIB_FUNCTION
    1085 krb5_string_to_key_salt_opaque (krb5_context context,
    1086                                 krb5_enctype enctype,
    1087                                 const char *password,
    1088                                 krb5_salt salt,
    1089                                 krb5_data opaque,
    1090                                 krb5_keyblock *key)
    1091 {
    1092     krb5_data pw;
    1093     pw.data = rk_UNCONST(password);
    1094     pw.length = strlen(password);
    1095     return krb5_string_to_key_data_salt_opaque(context, enctype,
    1096                                                pw, salt, opaque, key);
    1097 }
    1098 
    1099 krb5_error_code KRB5_LIB_FUNCTION
     60KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    110061krb5_enctype_keysize(krb5_context context,
    110162                     krb5_enctype type,
    110263                     size_t *keysize)
    110364{
    1104     struct encryption_type *et = _find_enctype(type);
     65    struct _krb5_encryption_type *et = _krb5_find_enctype(type);
    110566    if(et == NULL) {
    110667        krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
     
    111374}
    111475
    1115 krb5_error_code KRB5_LIB_FUNCTION
     76KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    111677krb5_enctype_keybits(krb5_context context,
    111778                     krb5_enctype type,
    111879                     size_t *keybits)
    111980{
    1120     struct encryption_type *et = _find_enctype(type);
     81    struct _krb5_encryption_type *et = _krb5_find_enctype(type);
    112182    if(et == NULL) {
    112283        krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
     
    112990}
    113091
    1131 krb5_error_code KRB5_LIB_FUNCTION
     92KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    113293krb5_generate_random_keyblock(krb5_context context,
    113394                              krb5_enctype type,
     
    113596{
    113697    krb5_error_code ret;
    1137     struct encryption_type *et = _find_enctype(type);
     98    struct _krb5_encryption_type *et = _krb5_find_enctype(type);
    113899    if(et == NULL) {
    1139100        krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
     
    1156117static krb5_error_code
    1157118_key_schedule(krb5_context context,
    1158               struct key_data *key)
     119              struct _krb5_key_data *key)
    1159120{
    1160121    krb5_error_code ret;
    1161     struct encryption_type *et = _find_enctype(key->key->keytype);
    1162     struct key_type *kt;
     122    struct _krb5_encryption_type *et = _krb5_find_enctype(key->key->keytype);
     123    struct _krb5_key_type *kt;
    1163124
    1164125    if (et == NULL) {
     
    1195156
    1196157static krb5_error_code
    1197 NONE_checksum(krb5_context context,
    1198               struct key_data *key,
     158SHA1_checksum(krb5_context context,
     159              struct _krb5_key_data *key,
    1199160              const void *data,
    1200161              size_t len,
     
    1202163              Checksum *C)
    1203164{
    1204     return 0;
    1205 }
    1206 
    1207 static krb5_error_code
    1208 CRC32_checksum(krb5_context context,
    1209                struct key_data *key,
    1210                const void *data,
    1211                size_t len,
    1212                unsigned usage,
    1213                Checksum *C)
    1214 {
    1215     uint32_t crc;
    1216     unsigned char *r = C->checksum.data;
    1217     _krb5_crc_init_table ();
    1218     crc = _krb5_crc_update (data, len, 0);
    1219     r[0] = crc & 0xff;
    1220     r[1] = (crc >> 8)  & 0xff;
    1221     r[2] = (crc >> 16) & 0xff;
    1222     r[3] = (crc >> 24) & 0xff;
    1223     return 0;
    1224 }
    1225 
    1226 static krb5_error_code
    1227 RSA_MD4_checksum(krb5_context context,
    1228                  struct key_data *key,
    1229                  const void *data,
    1230                  size_t len,
    1231                  unsigned usage,
    1232                  Checksum *C)
    1233 {
    1234     if (EVP_Digest(data, len, C->checksum.data, NULL, EVP_md4(), NULL) != 1)
    1235         krb5_abortx(context, "md4 checksum failed");
    1236     return 0;
    1237 }
    1238 
    1239 static krb5_error_code
    1240 des_checksum(krb5_context context,
    1241              const EVP_MD *evp_md,
    1242              struct key_data *key,
    1243              const void *data,
    1244              size_t len,
    1245              Checksum *cksum)
    1246 {
    1247     struct evp_schedule *ctx = key->schedule->data;
    1248     EVP_MD_CTX *m;
    1249     DES_cblock ivec;
    1250     unsigned char *p = cksum->checksum.data;
    1251 
    1252     krb5_generate_random_block(p, 8);
    1253 
    1254     m = EVP_MD_CTX_create();
    1255     if (m == NULL) {
    1256         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    1257         return ENOMEM;
    1258     }
    1259 
    1260     EVP_DigestInit_ex(m, evp_md, NULL);
    1261     EVP_DigestUpdate(m, p, 8);
    1262     EVP_DigestUpdate(m, data, len);
    1263     EVP_DigestFinal_ex (m, p + 8, NULL);
    1264     EVP_MD_CTX_destroy(m);
    1265     memset (&ivec, 0, sizeof(ivec));
    1266     EVP_CipherInit_ex(&ctx->ectx, NULL, NULL, NULL, (void *)&ivec, -1);
    1267     EVP_Cipher(&ctx->ectx, p, p, 24);
    1268 
    1269     return 0;
    1270 }
    1271 
    1272 static krb5_error_code
    1273 des_verify(krb5_context context,
    1274            const EVP_MD *evp_md,
    1275            struct key_data *key,
    1276            const void *data,
    1277            size_t len,
    1278            Checksum *C)
    1279 {
    1280     struct evp_schedule *ctx = key->schedule->data;
    1281     EVP_MD_CTX *m;
    1282     unsigned char tmp[24];
    1283     unsigned char res[16];
    1284     DES_cblock ivec;
    1285     krb5_error_code ret = 0;
    1286 
    1287     m = EVP_MD_CTX_create();
    1288     if (m == NULL) {
    1289         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    1290         return ENOMEM;
    1291     }
    1292 
    1293     memset(&ivec, 0, sizeof(ivec));
    1294     EVP_CipherInit_ex(&ctx->dctx, NULL, NULL, NULL, (void *)&ivec, -1);
    1295     EVP_Cipher(&ctx->dctx, tmp, C->checksum.data, 24);
    1296 
    1297     EVP_DigestInit_ex(m, evp_md, NULL);
    1298     EVP_DigestUpdate(m, tmp, 8); /* confounder */
    1299     EVP_DigestUpdate(m, data, len);
    1300     EVP_DigestFinal_ex (m, res, NULL);
    1301     EVP_MD_CTX_destroy(m);
    1302     if(memcmp(res, tmp + 8, sizeof(res)) != 0) {
    1303         krb5_clear_error_message (context);
    1304         ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
    1305     }
    1306     memset(tmp, 0, sizeof(tmp));
    1307     memset(res, 0, sizeof(res));
    1308     return ret;
    1309 }
    1310 
    1311 static krb5_error_code
    1312 RSA_MD4_DES_checksum(krb5_context context,
    1313                      struct key_data *key,
    1314                      const void *data,
    1315                      size_t len,
    1316                      unsigned usage,
    1317                      Checksum *cksum)
    1318 {
    1319     return des_checksum(context, EVP_md4(), key, data, len, cksum);
    1320 }
    1321 
    1322 static krb5_error_code
    1323 RSA_MD4_DES_verify(krb5_context context,
    1324                    struct key_data *key,
    1325                    const void *data,
    1326                    size_t len,
    1327                    unsigned usage,
    1328                    Checksum *C)
    1329 {
    1330     return des_verify(context, EVP_md5(), key, data, len, C);
    1331 }
    1332 
    1333 static krb5_error_code
    1334 RSA_MD5_checksum(krb5_context context,
    1335                  struct key_data *key,
    1336                  const void *data,
    1337                  size_t len,
    1338                  unsigned usage,
    1339                  Checksum *C)
    1340 {
    1341     if (EVP_Digest(data, len, C->checksum.data, NULL, EVP_md5(), NULL) != 1)
    1342         krb5_abortx(context, "md5 checksum failed");
    1343     return 0;
    1344 }
    1345 
    1346 static krb5_error_code
    1347 RSA_MD5_DES_checksum(krb5_context context,
    1348                      struct key_data *key,
    1349                      const void *data,
    1350                      size_t len,
    1351                      unsigned usage,
    1352                      Checksum *C)
    1353 {
    1354     return des_checksum(context, EVP_md5(), key, data, len, C);
    1355 }
    1356 
    1357 static krb5_error_code
    1358 RSA_MD5_DES_verify(krb5_context context,
    1359                    struct key_data *key,
    1360                    const void *data,
    1361                    size_t len,
    1362                    unsigned usage,
    1363                    Checksum *C)
    1364 {
    1365     return des_verify(context, EVP_md5(), key, data, len, C);
    1366 }
    1367 
    1368 #ifdef DES3_OLD_ENCTYPE
    1369 static krb5_error_code
    1370 RSA_MD5_DES3_checksum(krb5_context context,
    1371                       struct key_data *key,
    1372                       const void *data,
    1373                       size_t len,
    1374                       unsigned usage,
    1375                       Checksum *C)
    1376 {
    1377     return des_checksum(context, EVP_md5(), key, data, len, C);
    1378 }
    1379 
    1380 static krb5_error_code
    1381 RSA_MD5_DES3_verify(krb5_context context,
    1382                     struct key_data *key,
     165    if (EVP_Digest(data, len, C->checksum.data, NULL, EVP_sha1(), NULL) != 1)
     166        krb5_abortx(context, "sha1 checksum failed");
     167    return 0;
     168}
     169
     170/* HMAC according to RFC2104 */
     171krb5_error_code
     172_krb5_internal_hmac(krb5_context context,
     173                    struct _krb5_checksum_type *cm,
    1383174                    const void *data,
    1384175                    size_t len,
    1385176                    unsigned usage,
    1386                     Checksum *C)
    1387 {
    1388     return des_verify(context, EVP_md5(), key, data, len, C);
    1389 }
    1390 #endif
    1391 
    1392 static krb5_error_code
    1393 SHA1_checksum(krb5_context context,
    1394               struct key_data *key,
    1395               const void *data,
    1396               size_t len,
    1397               unsigned usage,
    1398               Checksum *C)
    1399 {
    1400     if (EVP_Digest(data, len, C->checksum.data, NULL, EVP_sha1(), NULL) != 1)
    1401         krb5_abortx(context, "sha1 checksum failed");
    1402     return 0;
    1403 }
    1404 
    1405 /* HMAC according to RFC2104 */
    1406 static krb5_error_code
    1407 hmac(krb5_context context,
    1408      struct checksum_type *cm,
    1409      const void *data,
    1410      size_t len,
    1411      unsigned usage,
    1412      struct key_data *keyblock,
    1413      Checksum *result)
     177                    struct _krb5_key_data *keyblock,
     178                    Checksum *result)
    1414179{
    1415180    unsigned char *ipad, *opad;
     
    1461226}
    1462227
    1463 krb5_error_code KRB5_LIB_FUNCTION
     228KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1464229krb5_hmac(krb5_context context,
    1465230          krb5_cksumtype cktype,
     
    1470235          Checksum *result)
    1471236{
    1472     struct checksum_type *c = _find_checksum(cktype);
    1473     struct key_data kd;
     237    struct _krb5_checksum_type *c = _krb5_find_checksum(cktype);
     238    struct _krb5_key_data kd;
    1474239    krb5_error_code ret;
    1475240
     
    1484249    kd.schedule = NULL;
    1485250
    1486     ret = hmac(context, c, data, len, usage, &kd, result);
     251    ret = _krb5_internal_hmac(context, c, data, len, usage, &kd, result);
    1487252
    1488253    if (kd.schedule)
     
    1492257}
    1493258
    1494 static krb5_error_code
    1495 SP_HMAC_SHA1_checksum(krb5_context context,
    1496                       struct key_data *key,
    1497                       const void *data,
    1498                       size_t len,
    1499                       unsigned usage,
    1500                       Checksum *result)
    1501 {
    1502     struct checksum_type *c = _find_checksum(CKSUMTYPE_SHA1);
     259krb5_error_code
     260_krb5_SP_HMAC_SHA1_checksum(krb5_context context,
     261                            struct _krb5_key_data *key,
     262                            const void *data,
     263                            size_t len,
     264                            unsigned usage,
     265                            Checksum *result)
     266{
     267    struct _krb5_checksum_type *c = _krb5_find_checksum(CKSUMTYPE_SHA1);
    1503268    Checksum res;
    1504269    char sha1_data[20];
     
    1508273    res.checksum.length = sizeof(sha1_data);
    1509274
    1510     ret = hmac(context, c, data, len, usage, key, &res);
     275    ret = _krb5_internal_hmac(context, c, data, len, usage, key, &res);
    1511276    if (ret)
    1512277        krb5_abortx(context, "hmac failed");
     
    1515280}
    1516281
    1517 /*
    1518  * checksum according to section 5. of draft-brezak-win2k-krb-rc4-hmac-03.txt
    1519  */
    1520 
    1521 static krb5_error_code
    1522 HMAC_MD5_checksum(krb5_context context,
    1523                   struct key_data *key,
    1524                   const void *data,
    1525                   size_t len,
    1526                   unsigned usage,
    1527                   Checksum *result)
    1528 {
    1529     EVP_MD_CTX *m;
    1530     struct checksum_type *c = _find_checksum (CKSUMTYPE_RSA_MD5);
    1531     const char signature[] = "signaturekey";
    1532     Checksum ksign_c;
    1533     struct key_data ksign;
    1534     krb5_keyblock kb;
    1535     unsigned char t[4];
    1536     unsigned char tmp[16];
    1537     unsigned char ksign_c_data[16];
    1538     krb5_error_code ret;
    1539 
    1540     m = EVP_MD_CTX_create();
    1541     if (m == NULL) {
    1542         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    1543         return ENOMEM;
    1544     }
    1545     ksign_c.checksum.length = sizeof(ksign_c_data);
    1546     ksign_c.checksum.data   = ksign_c_data;
    1547     ret = hmac(context, c, signature, sizeof(signature), 0, key, &ksign_c);
    1548     if (ret) {
    1549         EVP_MD_CTX_destroy(m);
    1550         return ret;
    1551     }
    1552     ksign.key = &kb;
    1553     kb.keyvalue = ksign_c.checksum;
    1554     EVP_DigestInit_ex(m, EVP_md5(), NULL);
    1555     t[0] = (usage >>  0) & 0xFF;
    1556     t[1] = (usage >>  8) & 0xFF;
    1557     t[2] = (usage >> 16) & 0xFF;
    1558     t[3] = (usage >> 24) & 0xFF;
    1559     EVP_DigestUpdate(m, t, 4);
    1560     EVP_DigestUpdate(m, data, len);
    1561     EVP_DigestFinal_ex (m, tmp, NULL);
    1562     EVP_MD_CTX_destroy(m);
    1563 
    1564     ret = hmac(context, c, tmp, sizeof(tmp), 0, &ksign, result);
    1565     if (ret)
    1566         return ret;
    1567     return 0;
    1568 }
    1569 
    1570 static struct checksum_type checksum_none = {
    1571     CKSUMTYPE_NONE,
    1572     "none",
    1573     1,
    1574     0,
    1575     0,
    1576     NONE_checksum,
    1577     NULL
    1578 };
    1579 static struct checksum_type checksum_crc32 = {
    1580     CKSUMTYPE_CRC32,
    1581     "crc32",
    1582     1,
    1583     4,
    1584     0,
    1585     CRC32_checksum,
    1586     NULL
    1587 };
    1588 static struct checksum_type checksum_rsa_md4 = {
    1589     CKSUMTYPE_RSA_MD4,
    1590     "rsa-md4",
    1591     64,
    1592     16,
    1593     F_CPROOF,
    1594     RSA_MD4_checksum,
    1595     NULL
    1596 };
    1597 static struct checksum_type checksum_rsa_md4_des = {
    1598     CKSUMTYPE_RSA_MD4_DES,
    1599     "rsa-md4-des",
    1600     64,
    1601     24,
    1602     F_KEYED | F_CPROOF | F_VARIANT,
    1603     RSA_MD4_DES_checksum,
    1604     RSA_MD4_DES_verify
    1605 };
    1606 static struct checksum_type checksum_rsa_md5 = {
    1607     CKSUMTYPE_RSA_MD5,
    1608     "rsa-md5",
    1609     64,
    1610     16,
    1611     F_CPROOF,
    1612     RSA_MD5_checksum,
    1613     NULL
    1614 };
    1615 static struct checksum_type checksum_rsa_md5_des = {
    1616     CKSUMTYPE_RSA_MD5_DES,
    1617     "rsa-md5-des",
    1618     64,
    1619     24,
    1620     F_KEYED | F_CPROOF | F_VARIANT,
    1621     RSA_MD5_DES_checksum,
    1622     RSA_MD5_DES_verify
    1623 };
    1624 #ifdef DES3_OLD_ENCTYPE
    1625 static struct checksum_type checksum_rsa_md5_des3 = {
    1626     CKSUMTYPE_RSA_MD5_DES3,
    1627     "rsa-md5-des3",
    1628     64,
    1629     24,
    1630     F_KEYED | F_CPROOF | F_VARIANT,
    1631     RSA_MD5_DES3_checksum,
    1632     RSA_MD5_DES3_verify
    1633 };
    1634 #endif
    1635 static struct checksum_type checksum_sha1 = {
     282struct _krb5_checksum_type _krb5_checksum_sha1 = {
    1636283    CKSUMTYPE_SHA1,
    1637284    "sha1",
     
    1642289    NULL
    1643290};
    1644 static struct checksum_type checksum_hmac_sha1_des3 = {
    1645     CKSUMTYPE_HMAC_SHA1_DES3,
    1646     "hmac-sha1-des3",
    1647     64,
    1648     20,
    1649     F_KEYED | F_CPROOF | F_DERIVED,
    1650     SP_HMAC_SHA1_checksum,
    1651     NULL
    1652 };
    1653 
    1654 static struct checksum_type checksum_hmac_sha1_aes128 = {
    1655     CKSUMTYPE_HMAC_SHA1_96_AES_128,
    1656     "hmac-sha1-96-aes128",
    1657     64,
    1658     12,
    1659     F_KEYED | F_CPROOF | F_DERIVED,
    1660     SP_HMAC_SHA1_checksum,
    1661     NULL
    1662 };
    1663 
    1664 static struct checksum_type checksum_hmac_sha1_aes256 = {
    1665     CKSUMTYPE_HMAC_SHA1_96_AES_256,
    1666     "hmac-sha1-96-aes256",
    1667     64,
    1668     12,
    1669     F_KEYED | F_CPROOF | F_DERIVED,
    1670     SP_HMAC_SHA1_checksum,
    1671     NULL
    1672 };
    1673 
    1674 static struct checksum_type checksum_hmac_md5 = {
    1675     CKSUMTYPE_HMAC_MD5,
    1676     "hmac-md5",
    1677     64,
    1678     16,
    1679     F_KEYED | F_CPROOF,
    1680     HMAC_MD5_checksum,
    1681     NULL
    1682 };
    1683 
    1684 static struct checksum_type *checksum_types[] = {
    1685     &checksum_none,
    1686     &checksum_crc32,
    1687     &checksum_rsa_md4,
    1688     &checksum_rsa_md4_des,
    1689     &checksum_rsa_md5,
    1690     &checksum_rsa_md5_des,
    1691 #ifdef DES3_OLD_ENCTYPE
    1692     &checksum_rsa_md5_des3,
    1693 #endif
    1694     &checksum_sha1,
    1695     &checksum_hmac_sha1_des3,
    1696     &checksum_hmac_sha1_aes128,
    1697     &checksum_hmac_sha1_aes256,
    1698     &checksum_hmac_md5
    1699 };
    1700 
    1701 static int num_checksums = sizeof(checksum_types) / sizeof(checksum_types[0]);
    1702 
    1703 static struct checksum_type *
    1704 _find_checksum(krb5_cksumtype type)
     291
     292struct _krb5_checksum_type *
     293_krb5_find_checksum(krb5_cksumtype type)
    1705294{
    1706295    int i;
    1707     for(i = 0; i < num_checksums; i++)
    1708         if(checksum_types[i]->type == type)
    1709             return checksum_types[i];
     296    for(i = 0; i < _krb5_num_checksums; i++)
     297        if(_krb5_checksum_types[i]->type == type)
     298            return _krb5_checksum_types[i];
    1710299    return NULL;
    1711300}
     
    1715304                 krb5_crypto crypto,
    1716305                 unsigned usage,  /* not krb5_key_usage */
    1717                  struct checksum_type *ct,
    1718                  struct key_data **key)
     306                 struct _krb5_checksum_type *ct,
     307                 struct _krb5_key_data **key)
    1719308{
    1720309    krb5_error_code ret = 0;
     
    1745334static krb5_error_code
    1746335create_checksum (krb5_context context,
    1747                  struct checksum_type *ct,
     336                 struct _krb5_checksum_type *ct,
    1748337                 krb5_crypto crypto,
    1749338                 unsigned usage,
     
    1753342{
    1754343    krb5_error_code ret;
    1755     struct key_data *dkey;
     344    struct _krb5_key_data *dkey;
    1756345    int keyed_checksum;
    1757346
     
    1782371
    1783372static int
    1784 arcfour_checksum_p(struct checksum_type *ct, krb5_crypto crypto)
     373arcfour_checksum_p(struct _krb5_checksum_type *ct, krb5_crypto crypto)
    1785374{
    1786375    return (ct->type == CKSUMTYPE_HMAC_MD5) &&
     
    1788377}
    1789378
    1790 krb5_error_code KRB5_LIB_FUNCTION
     379KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1791380krb5_create_checksum(krb5_context context,
    1792381                     krb5_crypto crypto,
     
    1797386                     Checksum *result)
    1798387{
    1799     struct checksum_type *ct = NULL;
     388    struct _krb5_checksum_type *ct = NULL;
    1800389    unsigned keyusage;
    1801390
    1802391    /* type 0 -> pick from crypto */
    1803392    if (type) {
    1804         ct = _find_checksum(type);
     393        ct = _krb5_find_checksum(type);
    1805394    } else if (crypto) {
    1806395        ct = crypto->et->keyed_checksum;
     
    1818407    if (arcfour_checksum_p(ct, crypto)) {
    1819408        keyusage = usage;
    1820         usage2arcfour(context, &keyusage);
     409        _krb5_usage2arcfour(context, &keyusage);
    1821410    } else
    1822411        keyusage = CHECKSUM_USAGE(usage);
     
    1835424{
    1836425    krb5_error_code ret;
    1837     struct key_data *dkey;
     426    struct _krb5_key_data *dkey;
    1838427    int keyed_checksum;
    1839428    Checksum c;
    1840     struct checksum_type *ct;
    1841 
    1842     ct = _find_checksum(cksum->cksumtype);
     429    struct _krb5_checksum_type *ct;
     430
     431    ct = _krb5_find_checksum(cksum->cksumtype);
    1843432    if (ct == NULL || (ct->flags & F_DISABLED)) {
    1844433        krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
     
    1849438    if(ct->checksumsize != cksum->checksum.length) {
    1850439        krb5_clear_error_message (context);
     440        krb5_set_error_message(context, KRB5KRB_AP_ERR_BAD_INTEGRITY,
     441                               N_("Decrypt integrity check failed for checksum type %s, "
     442                                  "length was %u, expected %u", ""),
     443                               ct->name, (unsigned)cksum->checksum.length,
     444                               (unsigned)ct->checksumsize);
     445
    1851446        return KRB5KRB_AP_ERR_BAD_INTEGRITY; /* XXX */
    1852447    }
    1853448    keyed_checksum = (ct->flags & F_KEYED) != 0;
    1854449    if(keyed_checksum) {
    1855         struct checksum_type *kct;
     450        struct _krb5_checksum_type *kct;
    1856451        if (crypto == NULL) {
    1857             krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
    1858                                     N_("Checksum type %s is keyed but no "
    1859                                        "crypto context (key) was passed in", ""),
    1860                                     ct->name);
     452            krb5_set_error_message(context, KRB5_PROG_SUMTYPE_NOSUPP,
     453                                   N_("Checksum type %s is keyed but no "
     454                                      "crypto context (key) was passed in", ""),
     455                                   ct->name);
    1861456            return KRB5_PROG_SUMTYPE_NOSUPP; /* XXX */
    1862457        }
    1863458        kct = crypto->et->keyed_checksum;
    1864459        if (kct != NULL && kct->type != ct->type) {
    1865             krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
    1866                                     N_("Checksum type %s is keyed, but "
    1867                                        "the key type %s passed didnt have that checksum "
    1868                                        "type as the keyed type", ""),
     460            krb5_set_error_message(context, KRB5_PROG_SUMTYPE_NOSUPP,
     461                                   N_("Checksum type %s is keyed, but "
     462                                      "the key type %s passed didnt have that checksum "
     463                                      "type as the keyed type", ""),
    1869464                                    ct->name, crypto->et->name);
    1870465            return KRB5_PROG_SUMTYPE_NOSUPP; /* XXX */
     
    1876471    } else
    1877472        dkey = NULL;
    1878     if(ct->verify)
    1879         return (*ct->verify)(context, dkey, data, len, usage, cksum);
     473
     474    /*
     475     * If checksum have a verify function, lets use that instead of
     476     * calling ->checksum and then compare result.
     477     */
     478
     479    if(ct->verify) {
     480        ret = (*ct->verify)(context, dkey, data, len, usage, cksum);
     481        if (ret)
     482            krb5_set_error_message(context, ret,
     483                                   N_("Decrypt integrity check failed for checksum "
     484                                      "type %s, key type %s", ""),
     485                                   ct->name, (crypto != NULL)? crypto->et->name : "(none)");
     486        return ret;
     487    }
    1880488
    1881489    ret = krb5_data_alloc (&c.checksum, ct->checksumsize);
     
    1889497    }
    1890498
    1891     if(c.checksum.length != cksum->checksum.length ||
    1892        memcmp(c.checksum.data, cksum->checksum.data, c.checksum.length)) {
    1893         krb5_clear_error_message (context);
     499    if(krb5_data_ct_cmp(&c.checksum, &cksum->checksum) != 0) {
    1894500        ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
     501        krb5_set_error_message(context, ret,
     502                               N_("Decrypt integrity check failed for checksum "
     503                                  "type %s, key type %s", ""),
     504                               ct->name, crypto ? crypto->et->name : "(unkeyed)");
    1895505    } else {
    1896506        ret = 0;
     
    1900510}
    1901511
    1902 krb5_error_code KRB5_LIB_FUNCTION
     512KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1903513krb5_verify_checksum(krb5_context context,
    1904514                     krb5_crypto crypto,
     
    1908518                     Checksum *cksum)
    1909519{
    1910     struct checksum_type *ct;
     520    struct _krb5_checksum_type *ct;
    1911521    unsigned keyusage;
    1912522
    1913     ct = _find_checksum(cksum->cksumtype);
     523    ct = _krb5_find_checksum(cksum->cksumtype);
    1914524    if(ct == NULL) {
    1915525        krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
     
    1921531    if (arcfour_checksum_p(ct, crypto)) {
    1922532        keyusage = usage;
    1923         usage2arcfour(context, &keyusage);
     533        _krb5_usage2arcfour(context, &keyusage);
    1924534    } else
    1925535        keyusage = CHECKSUM_USAGE(usage);
     
    1929539}
    1930540
    1931 krb5_error_code KRB5_LIB_FUNCTION
     541KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1932542krb5_crypto_get_checksum_type(krb5_context context,
    1933543                              krb5_crypto crypto,
    1934544                              krb5_cksumtype *type)
    1935545{
    1936     struct checksum_type *ct = NULL;
     546    struct _krb5_checksum_type *ct = NULL;
    1937547
    1938548    if (crypto != NULL) {
     
    1954564
    1955565
    1956 krb5_error_code KRB5_LIB_FUNCTION
     566KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    1957567krb5_checksumsize(krb5_context context,
    1958568                  krb5_cksumtype type,
    1959569                  size_t *size)
    1960570{
    1961     struct checksum_type *ct = _find_checksum(type);
     571    struct _krb5_checksum_type *ct = _krb5_find_checksum(type);
    1962572    if(ct == NULL) {
    1963573        krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
     
    1970580}
    1971581
    1972 krb5_boolean KRB5_LIB_FUNCTION
     582KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    1973583krb5_checksum_is_keyed(krb5_context context,
    1974584                       krb5_cksumtype type)
    1975585{
    1976     struct checksum_type *ct = _find_checksum(type);
     586    struct _krb5_checksum_type *ct = _krb5_find_checksum(type);
    1977587    if(ct == NULL) {
    1978588        if (context)
     
    1985595}
    1986596
    1987 krb5_boolean KRB5_LIB_FUNCTION
     597KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    1988598krb5_checksum_is_collision_proof(krb5_context context,
    1989599                                 krb5_cksumtype type)
    1990600{
    1991     struct checksum_type *ct = _find_checksum(type);
     601    struct _krb5_checksum_type *ct = _krb5_find_checksum(type);
    1992602    if(ct == NULL) {
    1993603        if (context)
     
    2000610}
    2001611
    2002 krb5_error_code KRB5_LIB_FUNCTION
     612KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2003613krb5_checksum_disable(krb5_context context,
    2004614                      krb5_cksumtype type)
    2005615{
    2006     struct checksum_type *ct = _find_checksum(type);
     616    struct _krb5_checksum_type *ct = _krb5_find_checksum(type);
    2007617    if(ct == NULL) {
    2008618        if (context)
     
    2020630 ************************************************************/
    2021631
    2022 static krb5_error_code
    2023 NULL_encrypt(krb5_context context,
    2024              struct key_data *key,
    2025              void *data,
    2026              size_t len,
    2027              krb5_boolean encryptp,
    2028              int usage,
    2029              void *ivec)
    2030 {
    2031     return 0;
    2032 }
    2033 
    2034 static krb5_error_code
    2035 evp_encrypt(krb5_context context,
    2036             struct key_data *key,
    2037             void *data,
    2038             size_t len,
    2039             krb5_boolean encryptp,
    2040             int usage,
    2041             void *ivec)
    2042 {
    2043     struct evp_schedule *ctx = key->schedule->data;
    2044     EVP_CIPHER_CTX *c;
    2045     c = encryptp ? &ctx->ectx : &ctx->dctx;
    2046     if (ivec == NULL) {
    2047         /* alloca ? */
    2048         size_t len = EVP_CIPHER_CTX_iv_length(c);
    2049         void *loiv = malloc(len);
    2050         if (loiv == NULL) {
    2051             krb5_clear_error_message(context);
    2052             return ENOMEM;
    2053         }
    2054         memset(loiv, 0, len);
    2055         EVP_CipherInit_ex(c, NULL, NULL, NULL, loiv, -1);
    2056         free(loiv);
    2057     } else
    2058         EVP_CipherInit_ex(c, NULL, NULL, NULL, ivec, -1);
    2059     EVP_Cipher(c, data, data, len);
    2060     return 0;
    2061 }
    2062 
    2063 #ifdef WEAK_ENCTYPES
    2064 static krb5_error_code
    2065 evp_des_encrypt_null_ivec(krb5_context context,
    2066                           struct key_data *key,
    2067                           void *data,
    2068                           size_t len,
    2069                           krb5_boolean encryptp,
    2070                           int usage,
    2071                           void *ignore_ivec)
    2072 {
    2073     struct evp_schedule *ctx = key->schedule->data;
    2074     EVP_CIPHER_CTX *c;
    2075     DES_cblock ivec;
    2076     memset(&ivec, 0, sizeof(ivec));
    2077     c = encryptp ? &ctx->ectx : &ctx->dctx;
    2078     EVP_CipherInit_ex(c, NULL, NULL, NULL, (void *)&ivec, -1);
    2079     EVP_Cipher(c, data, data, len);
    2080     return 0;
    2081 }
    2082 
    2083 static krb5_error_code
    2084 evp_des_encrypt_key_ivec(krb5_context context,
    2085                          struct key_data *key,
    2086                          void *data,
    2087                          size_t len,
    2088                          krb5_boolean encryptp,
    2089                          int usage,
    2090                          void *ignore_ivec)
    2091 {
    2092     struct evp_schedule *ctx = key->schedule->data;
    2093     EVP_CIPHER_CTX *c;
    2094     DES_cblock ivec;
    2095     memcpy(&ivec, key->key->keyvalue.data, sizeof(ivec));
    2096     c = encryptp ? &ctx->ectx : &ctx->dctx;
    2097     EVP_CipherInit_ex(c, NULL, NULL, NULL, (void *)&ivec, -1);
    2098     EVP_Cipher(c, data, data, len);
    2099     return 0;
    2100 }
    2101 
    2102 static krb5_error_code
    2103 DES_CFB64_encrypt_null_ivec(krb5_context context,
    2104                             struct key_data *key,
    2105                             void *data,
    2106                             size_t len,
    2107                             krb5_boolean encryptp,
    2108                             int usage,
    2109                             void *ignore_ivec)
    2110 {
    2111     DES_cblock ivec;
    2112     int num = 0;
    2113     DES_key_schedule *s = key->schedule->data;
    2114     memset(&ivec, 0, sizeof(ivec));
    2115 
    2116     DES_cfb64_encrypt(data, data, len, s, &ivec, &num, encryptp);
    2117     return 0;
    2118 }
    2119 
    2120 static krb5_error_code
    2121 DES_PCBC_encrypt_key_ivec(krb5_context context,
    2122                           struct key_data *key,
    2123                           void *data,
    2124                           size_t len,
    2125                           krb5_boolean encryptp,
    2126                           int usage,
    2127                           void *ignore_ivec)
    2128 {
    2129     DES_cblock ivec;
    2130     DES_key_schedule *s = key->schedule->data;
    2131     memcpy(&ivec, key->key->keyvalue.data, sizeof(ivec));
    2132 
    2133     DES_pcbc_encrypt(data, data, len, s, &ivec, encryptp);
    2134     return 0;
    2135 }
    2136 #endif
    2137 
    2138 /*
    2139  * section 6 of draft-brezak-win2k-krb-rc4-hmac-03
    2140  *
    2141  * warning: not for small children
    2142  */
    2143 
    2144 static krb5_error_code
    2145 ARCFOUR_subencrypt(krb5_context context,
    2146                    struct key_data *key,
    2147                    void *data,
    2148                    size_t len,
    2149                    unsigned usage,
    2150                    void *ivec)
    2151 {
    2152     struct checksum_type *c = _find_checksum (CKSUMTYPE_RSA_MD5);
    2153     Checksum k1_c, k2_c, k3_c, cksum;
    2154     struct key_data ke;
    2155     krb5_keyblock kb;
    2156     unsigned char t[4];
    2157     RC4_KEY rc4_key;
    2158     unsigned char *cdata = data;
    2159     unsigned char k1_c_data[16], k2_c_data[16], k3_c_data[16];
    2160     krb5_error_code ret;
    2161 
    2162     t[0] = (usage >>  0) & 0xFF;
    2163     t[1] = (usage >>  8) & 0xFF;
    2164     t[2] = (usage >> 16) & 0xFF;
    2165     t[3] = (usage >> 24) & 0xFF;
    2166 
    2167     k1_c.checksum.length = sizeof(k1_c_data);
    2168     k1_c.checksum.data   = k1_c_data;
    2169 
    2170     ret = hmac(NULL, c, t, sizeof(t), 0, key, &k1_c);
    2171     if (ret)
    2172         krb5_abortx(context, "hmac failed");
    2173 
    2174     memcpy (k2_c_data, k1_c_data, sizeof(k1_c_data));
    2175 
    2176     k2_c.checksum.length = sizeof(k2_c_data);
    2177     k2_c.checksum.data   = k2_c_data;
    2178 
    2179     ke.key = &kb;
    2180     kb.keyvalue = k2_c.checksum;
    2181 
    2182     cksum.checksum.length = 16;
    2183     cksum.checksum.data   = data;
    2184 
    2185     ret = hmac(NULL, c, cdata + 16, len - 16, 0, &ke, &cksum);
    2186     if (ret)
    2187         krb5_abortx(context, "hmac failed");
    2188 
    2189     ke.key = &kb;
    2190     kb.keyvalue = k1_c.checksum;
    2191 
    2192     k3_c.checksum.length = sizeof(k3_c_data);
    2193     k3_c.checksum.data   = k3_c_data;
    2194 
    2195     ret = hmac(NULL, c, data, 16, 0, &ke, &k3_c);
    2196     if (ret)
    2197         krb5_abortx(context, "hmac failed");
    2198 
    2199     RC4_set_key (&rc4_key, k3_c.checksum.length, k3_c.checksum.data);
    2200     RC4 (&rc4_key, len - 16, cdata + 16, cdata + 16);
    2201     memset (k1_c_data, 0, sizeof(k1_c_data));
    2202     memset (k2_c_data, 0, sizeof(k2_c_data));
    2203     memset (k3_c_data, 0, sizeof(k3_c_data));
    2204     return 0;
    2205 }
    2206 
    2207 static krb5_error_code
    2208 ARCFOUR_subdecrypt(krb5_context context,
    2209                    struct key_data *key,
    2210                    void *data,
    2211                    size_t len,
    2212                    unsigned usage,
    2213                    void *ivec)
    2214 {
    2215     struct checksum_type *c = _find_checksum (CKSUMTYPE_RSA_MD5);
    2216     Checksum k1_c, k2_c, k3_c, cksum;
    2217     struct key_data ke;
    2218     krb5_keyblock kb;
    2219     unsigned char t[4];
    2220     RC4_KEY rc4_key;
    2221     unsigned char *cdata = data;
    2222     unsigned char k1_c_data[16], k2_c_data[16], k3_c_data[16];
    2223     unsigned char cksum_data[16];
    2224     krb5_error_code ret;
    2225 
    2226     t[0] = (usage >>  0) & 0xFF;
    2227     t[1] = (usage >>  8) & 0xFF;
    2228     t[2] = (usage >> 16) & 0xFF;
    2229     t[3] = (usage >> 24) & 0xFF;
    2230 
    2231     k1_c.checksum.length = sizeof(k1_c_data);
    2232     k1_c.checksum.data   = k1_c_data;
    2233 
    2234     ret = hmac(NULL, c, t, sizeof(t), 0, key, &k1_c);
    2235     if (ret)
    2236         krb5_abortx(context, "hmac failed");
    2237 
    2238     memcpy (k2_c_data, k1_c_data, sizeof(k1_c_data));
    2239 
    2240     k2_c.checksum.length = sizeof(k2_c_data);
    2241     k2_c.checksum.data   = k2_c_data;
    2242 
    2243     ke.key = &kb;
    2244     kb.keyvalue = k1_c.checksum;
    2245 
    2246     k3_c.checksum.length = sizeof(k3_c_data);
    2247     k3_c.checksum.data   = k3_c_data;
    2248 
    2249     ret = hmac(NULL, c, cdata, 16, 0, &ke, &k3_c);
    2250     if (ret)
    2251         krb5_abortx(context, "hmac failed");
    2252 
    2253     RC4_set_key (&rc4_key, k3_c.checksum.length, k3_c.checksum.data);
    2254     RC4 (&rc4_key, len - 16, cdata + 16, cdata + 16);
    2255 
    2256     ke.key = &kb;
    2257     kb.keyvalue = k2_c.checksum;
    2258 
    2259     cksum.checksum.length = 16;
    2260     cksum.checksum.data   = cksum_data;
    2261 
    2262     ret = hmac(NULL, c, cdata + 16, len - 16, 0, &ke, &cksum);
    2263     if (ret)
    2264         krb5_abortx(context, "hmac failed");
    2265 
    2266     memset (k1_c_data, 0, sizeof(k1_c_data));
    2267     memset (k2_c_data, 0, sizeof(k2_c_data));
    2268     memset (k3_c_data, 0, sizeof(k3_c_data));
    2269 
    2270     if (memcmp (cksum.checksum.data, data, 16) != 0) {
    2271         krb5_clear_error_message (context);
    2272         return KRB5KRB_AP_ERR_BAD_INTEGRITY;
    2273     } else {
    2274         return 0;
    2275     }
    2276 }
    2277 
    2278 /*
    2279  * convert the usage numbers used in
    2280  * draft-ietf-cat-kerb-key-derivation-00.txt to the ones in
    2281  * draft-brezak-win2k-krb-rc4-hmac-04.txt
    2282  */
    2283 
    2284 static krb5_error_code
    2285 usage2arcfour (krb5_context context, unsigned *usage)
    2286 {
    2287     switch (*usage) {
    2288     case KRB5_KU_AS_REP_ENC_PART : /* 3 */
    2289     case KRB5_KU_TGS_REP_ENC_PART_SUB_KEY : /* 9 */
    2290         *usage = 8;
    2291         return 0;
    2292     case KRB5_KU_USAGE_SEAL :  /* 22 */
    2293         *usage = 13;
    2294         return 0;
    2295     case KRB5_KU_USAGE_SIGN : /* 23 */
    2296         *usage = 15;
    2297         return 0;
    2298     case KRB5_KU_USAGE_SEQ: /* 24 */
    2299         *usage = 0;
    2300         return 0;
    2301     default :
    2302         return 0;
    2303     }
    2304 }
    2305 
    2306 static krb5_error_code
    2307 ARCFOUR_encrypt(krb5_context context,
    2308                 struct key_data *key,
    2309                 void *data,
    2310                 size_t len,
    2311                 krb5_boolean encryptp,
    2312                 int usage,
    2313                 void *ivec)
    2314 {
    2315     krb5_error_code ret;
    2316     unsigned keyusage = usage;
    2317 
    2318     if((ret = usage2arcfour (context, &keyusage)) != 0)
    2319         return ret;
    2320 
    2321     if (encryptp)
    2322         return ARCFOUR_subencrypt (context, key, data, len, keyusage, ivec);
    2323     else
    2324         return ARCFOUR_subdecrypt (context, key, data, len, keyusage, ivec);
    2325 }
    2326 
    2327 
    2328 /*
    2329  *
    2330  */
    2331 
    2332 static krb5_error_code
    2333 AES_PRF(krb5_context context,
    2334         krb5_crypto crypto,
    2335         const krb5_data *in,
    2336         krb5_data *out)
    2337 {
    2338     struct checksum_type *ct = crypto->et->checksum;
    2339     krb5_error_code ret;
    2340     Checksum result;
    2341     krb5_keyblock *derived;
    2342 
    2343     result.cksumtype = ct->type;
    2344     ret = krb5_data_alloc(&result.checksum, ct->checksumsize);
    2345     if (ret) {
    2346         krb5_set_error_message(context, ret, N_("malloc: out memory", ""));
    2347         return ret;
    2348     }
    2349 
    2350     ret = (*ct->checksum)(context, NULL, in->data, in->length, 0, &result);
    2351     if (ret) {
    2352         krb5_data_free(&result.checksum);
    2353         return ret;
    2354     }
    2355 
    2356     if (result.checksum.length < crypto->et->blocksize)
    2357         krb5_abortx(context, "internal prf error");
    2358 
    2359     derived = NULL;
    2360     ret = krb5_derive_key(context, crypto->key.key,
    2361                           crypto->et->type, "prf", 3, &derived);
    2362     if (ret)
    2363         krb5_abortx(context, "krb5_derive_key");
    2364 
    2365     ret = krb5_data_alloc(out, crypto->et->blocksize);
    2366     if (ret)
    2367         krb5_abortx(context, "malloc failed");
    2368 
    2369     {
    2370         const EVP_CIPHER *c = (*crypto->et->keytype->evp)();
    2371         EVP_CIPHER_CTX ctx;
    2372 
    2373         EVP_CIPHER_CTX_init(&ctx); /* ivec all zero */
    2374         EVP_CipherInit_ex(&ctx, c, NULL, derived->keyvalue.data, NULL, 1);
    2375         EVP_Cipher(&ctx, out->data, result.checksum.data,
    2376                    crypto->et->blocksize);
    2377         EVP_CIPHER_CTX_cleanup(&ctx);
    2378     }
    2379 
    2380     krb5_data_free(&result.checksum);
    2381     krb5_free_keyblock(context, derived);
    2382 
    2383     return ret;
    2384 }
    2385 
    2386 /*
    2387  * these should currently be in reverse preference order.
    2388  * (only relevant for !F_PSEUDO) */
    2389 
    2390 static struct encryption_type enctype_null = {
    2391     ETYPE_NULL,
    2392     "null",
    2393     1,
    2394     1,
    2395     0,
    2396     &keytype_null,
    2397     &checksum_none,
    2398     NULL,
    2399     F_DISABLED,
    2400     NULL_encrypt,
    2401     0,
    2402     NULL
    2403 };
    2404 static struct encryption_type enctype_arcfour_hmac_md5 = {
    2405     ETYPE_ARCFOUR_HMAC_MD5,
    2406     "arcfour-hmac-md5",
    2407     1,
    2408     1,
    2409     8,
    2410     &keytype_arcfour,
    2411     &checksum_hmac_md5,
    2412     NULL,
    2413     F_SPECIAL,
    2414     ARCFOUR_encrypt,
    2415     0,
    2416     NULL
    2417 };
    2418 #ifdef DES3_OLD_ENCTYPE
    2419 static struct encryption_type enctype_des3_cbc_md5 = {
    2420     ETYPE_DES3_CBC_MD5,
    2421     "des3-cbc-md5",
    2422     8,
    2423     8,
    2424     8,
    2425     &keytype_des3,
    2426     &checksum_rsa_md5,
    2427     &checksum_rsa_md5_des3,
    2428     0,
    2429     evp_encrypt,
    2430     0,
    2431     NULL
    2432 };
    2433 #endif
    2434 static struct encryption_type enctype_des3_cbc_sha1 = {
    2435     ETYPE_DES3_CBC_SHA1,
    2436     "des3-cbc-sha1",
    2437     8,
    2438     8,
    2439     8,
    2440     &keytype_des3_derived,
    2441     &checksum_sha1,
    2442     &checksum_hmac_sha1_des3,
    2443     F_DERIVED,
    2444     evp_encrypt,
    2445     0,
    2446     NULL
    2447 };
    2448 #ifdef DES3_OLD_ENCTYPE
    2449 static struct encryption_type enctype_old_des3_cbc_sha1 = {
    2450     ETYPE_OLD_DES3_CBC_SHA1,
    2451     "old-des3-cbc-sha1",
    2452     8,
    2453     8,
    2454     8,
    2455     &keytype_des3,
    2456     &checksum_sha1,
    2457     &checksum_hmac_sha1_des3,
    2458     0,
    2459     evp_encrypt,
    2460     0,
    2461     NULL
    2462 };
    2463 #endif
    2464 static struct encryption_type enctype_aes128_cts_hmac_sha1 = {
    2465     ETYPE_AES128_CTS_HMAC_SHA1_96,
    2466     "aes128-cts-hmac-sha1-96",
    2467     16,
    2468     1,
    2469     16,
    2470     &keytype_aes128,
    2471     &checksum_sha1,
    2472     &checksum_hmac_sha1_aes128,
    2473     F_DERIVED,
    2474     evp_encrypt,
    2475     16,
    2476     AES_PRF
    2477 };
    2478 static struct encryption_type enctype_aes256_cts_hmac_sha1 = {
    2479     ETYPE_AES256_CTS_HMAC_SHA1_96,
    2480     "aes256-cts-hmac-sha1-96",
    2481     16,
    2482     1,
    2483     16,
    2484     &keytype_aes256,
    2485     &checksum_sha1,
    2486     &checksum_hmac_sha1_aes256,
    2487     F_DERIVED,
    2488     evp_encrypt,
    2489     16,
    2490     AES_PRF
    2491 };
    2492 static struct encryption_type enctype_des3_cbc_none = {
    2493     ETYPE_DES3_CBC_NONE,
    2494     "des3-cbc-none",
    2495     8,
    2496     8,
    2497     0,
    2498     &keytype_des3_derived,
    2499     &checksum_none,
    2500     NULL,
    2501     F_PSEUDO,
    2502     evp_encrypt,
    2503     0,
    2504     NULL
    2505 };
    2506 #ifdef WEAK_ENCTYPES
    2507 static struct encryption_type enctype_des_cbc_crc = {
    2508     ETYPE_DES_CBC_CRC,
    2509     "des-cbc-crc",
    2510     8,
    2511     8,
    2512     8,
    2513     &keytype_des,
    2514     &checksum_crc32,
    2515     NULL,
    2516     F_DISABLED,
    2517     evp_des_encrypt_key_ivec,
    2518     0,
    2519     NULL
    2520 };
    2521 static struct encryption_type enctype_des_cbc_md4 = {
    2522     ETYPE_DES_CBC_MD4,
    2523     "des-cbc-md4",
    2524     8,
    2525     8,
    2526     8,
    2527     &keytype_des,
    2528     &checksum_rsa_md4,
    2529     &checksum_rsa_md4_des,
    2530     F_DISABLED,
    2531     evp_des_encrypt_null_ivec,
    2532     0,
    2533     NULL
    2534 };
    2535 static struct encryption_type enctype_des_cbc_md5 = {
    2536     ETYPE_DES_CBC_MD5,
    2537     "des-cbc-md5",
    2538     8,
    2539     8,
    2540     8,
    2541     &keytype_des,
    2542     &checksum_rsa_md5,
    2543     &checksum_rsa_md5_des,
    2544     F_DISABLED,
    2545     evp_des_encrypt_null_ivec,
    2546     0,
    2547     NULL
    2548 };
    2549 static struct encryption_type enctype_des_cbc_none = {
    2550     ETYPE_DES_CBC_NONE,
    2551     "des-cbc-none",
    2552     8,
    2553     8,
    2554     0,
    2555     &keytype_des,
    2556     &checksum_none,
    2557     NULL,
    2558     F_PSEUDO|F_DISABLED,
    2559     evp_des_encrypt_null_ivec,
    2560     0,
    2561     NULL
    2562 };
    2563 static struct encryption_type enctype_des_cfb64_none = {
    2564     ETYPE_DES_CFB64_NONE,
    2565     "des-cfb64-none",
    2566     1,
    2567     1,
    2568     0,
    2569     &keytype_des_old,
    2570     &checksum_none,
    2571     NULL,
    2572     F_PSEUDO|F_DISABLED,
    2573     DES_CFB64_encrypt_null_ivec,
    2574     0,
    2575     NULL
    2576 };
    2577 static struct encryption_type enctype_des_pcbc_none = {
    2578     ETYPE_DES_PCBC_NONE,
    2579     "des-pcbc-none",
    2580     8,
    2581     8,
    2582     0,
    2583     &keytype_des_old,
    2584     &checksum_none,
    2585     NULL,
    2586     F_PSEUDO|F_DISABLED,
    2587     DES_PCBC_encrypt_key_ivec,
    2588     0,
    2589     NULL
    2590 };
    2591 #endif /* WEAK_ENCTYPES */
    2592 
    2593 static struct encryption_type *etypes[] = {
    2594     &enctype_aes256_cts_hmac_sha1,
    2595     &enctype_aes128_cts_hmac_sha1,
    2596     &enctype_des3_cbc_sha1,
    2597     &enctype_des3_cbc_none, /* used by the gss-api mech */
    2598     &enctype_arcfour_hmac_md5,
    2599 #ifdef DES3_OLD_ENCTYPE
    2600     &enctype_des3_cbc_md5,
    2601     &enctype_old_des3_cbc_sha1,
    2602 #endif
    2603 #ifdef WEAK_ENCTYPES
    2604     &enctype_des_cbc_crc,
    2605     &enctype_des_cbc_md4,
    2606     &enctype_des_cbc_md5,
    2607     &enctype_des_cbc_none,
    2608     &enctype_des_cfb64_none,
    2609     &enctype_des_pcbc_none,
    2610 #endif
    2611     &enctype_null
    2612 };
    2613 
    2614 static unsigned num_etypes = sizeof(etypes) / sizeof(etypes[0]);
    2615 
    2616 
    2617 static struct encryption_type *
    2618 _find_enctype(krb5_enctype type)
     632struct _krb5_encryption_type *
     633_krb5_find_enctype(krb5_enctype type)
    2619634{
    2620635    int i;
    2621     for(i = 0; i < num_etypes; i++)
    2622         if(etypes[i]->type == type)
    2623             return etypes[i];
     636    for(i = 0; i < _krb5_num_etypes; i++)
     637        if(_krb5_etypes[i]->type == type)
     638            return _krb5_etypes[i];
    2624639    return NULL;
    2625640}
    2626641
    2627642
    2628 krb5_error_code KRB5_LIB_FUNCTION
     643KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2629644krb5_enctype_to_string(krb5_context context,
    2630645                       krb5_enctype etype,
    2631646                       char **string)
    2632647{
    2633     struct encryption_type *e;
    2634     e = _find_enctype(etype);
     648    struct _krb5_encryption_type *e;
     649    e = _krb5_find_enctype(etype);
    2635650    if(e == NULL) {
    2636651        krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP,
     
    2648663}
    2649664
    2650 krb5_error_code KRB5_LIB_FUNCTION
     665KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2651666krb5_string_to_enctype(krb5_context context,
    2652667                       const char *string,
     
    2654669{
    2655670    int i;
    2656     for(i = 0; i < num_etypes; i++)
    2657         if(strcasecmp(etypes[i]->name, string) == 0){
    2658             *etype = etypes[i]->type;
     671    for(i = 0; i < _krb5_num_etypes; i++)
     672        if(strcasecmp(_krb5_etypes[i]->name, string) == 0){
     673            *etype = _krb5_etypes[i]->type;
    2659674            return 0;
    2660675        }
     
    2665680}
    2666681
    2667 krb5_error_code KRB5_LIB_FUNCTION
     682KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2668683krb5_enctype_to_keytype(krb5_context context,
    2669684                        krb5_enctype etype,
    2670685                        krb5_keytype *keytype)
    2671686{
    2672     struct encryption_type *e = _find_enctype(etype);
     687    struct _krb5_encryption_type *e = _krb5_find_enctype(etype);
    2673688    if(e == NULL) {
    2674689        krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP,
     
    2681696}
    2682697
    2683 krb5_error_code KRB5_LIB_FUNCTION
     698KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2684699krb5_enctype_valid(krb5_context context,
    2685700                   krb5_enctype etype)
    2686701{
    2687     struct encryption_type *e = _find_enctype(etype);
     702    struct _krb5_encryption_type *e = _krb5_find_enctype(etype);
    2688703    if(e == NULL) {
    2689704        krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP,
     
    2714729
    2715730
    2716 krb5_error_code KRB5_LIB_FUNCTION
     731KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2717732krb5_cksumtype_to_enctype(krb5_context context,
    2718733                          krb5_cksumtype ctype,
     
    2723738    *etype = ETYPE_NULL;
    2724739
    2725     for(i = 0; i < num_etypes; i++) {
    2726         if(etypes[i]->keyed_checksum &&
    2727            etypes[i]->keyed_checksum->type == ctype)
     740    for(i = 0; i < _krb5_num_etypes; i++) {
     741        if(_krb5_etypes[i]->keyed_checksum &&
     742           _krb5_etypes[i]->keyed_checksum->type == ctype)
    2728743            {
    2729                 *etype = etypes[i]->type;
     744                *etype = _krb5_etypes[i]->type;
    2730745                return 0;
    2731746            }
     
    2739754
    2740755
    2741 krb5_error_code KRB5_LIB_FUNCTION
     756KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    2742757krb5_cksumtype_valid(krb5_context context,
    2743758                     krb5_cksumtype ctype)
    2744759{
    2745     struct checksum_type *c = _find_checksum(ctype);
     760    struct _krb5_checksum_type *c = _krb5_find_checksum(ctype);
    2746761    if (c == NULL) {
    2747762        krb5_set_error_message (context, KRB5_PROG_SUMTYPE_NOSUPP,
     
    2790805    unsigned char *p, *q;
    2791806    krb5_error_code ret;
    2792     struct key_data *dkey;
    2793     const struct encryption_type *et = crypto->et;
     807    struct _krb5_key_data *dkey;
     808    const struct _krb5_encryption_type *et = crypto->et;
    2794809
    2795810    checksum_sz = CHECKSUMSIZE(et->keyed_checksum);
     
    2856871    unsigned char *p, *q;
    2857872    krb5_error_code ret;
    2858     const struct encryption_type *et = crypto->et;
     873    const struct _krb5_encryption_type *et = crypto->et;
    2859874
    2860875    checksum_sz = CHECKSUMSIZE(et->checksum);
     
    2918933                         void *ivec)
    2919934{
    2920     struct encryption_type *et = crypto->et;
     935    struct _krb5_encryption_type *et = crypto->et;
    2921936    size_t cksum_sz = CHECKSUMSIZE(et->checksum);
    2922937    size_t sz = len + cksum_sz + et->confoundersize;
     
    2959974    unsigned char *p;
    2960975    krb5_error_code ret;
    2961     struct key_data *dkey;
    2962     struct encryption_type *et = crypto->et;
     976    struct _krb5_key_data *dkey;
     977    struct _krb5_encryption_type *et = crypto->et;
    2963978    unsigned long l;
    2964979
     
    30391054    Checksum cksum;
    30401055    size_t checksum_sz, l;
    3041     struct encryption_type *et = crypto->et;
     1056    struct _krb5_encryption_type *et = crypto->et;
    30421057
    30431058    if ((len % et->padsize) != 0) {
     
    30451060        return KRB5_BAD_MSIZE;
    30461061    }
    3047 
    30481062    checksum_sz = CHECKSUMSIZE(et->checksum);
     1063    if (len < checksum_sz + et->confoundersize) {
     1064        krb5_set_error_message(context, KRB5_BAD_MSIZE,
     1065                               N_("Encrypted data shorter then "
     1066                                  "checksum + confunder", ""));
     1067        return KRB5_BAD_MSIZE;
     1068    }
     1069
    30491070    p = malloc(len);
    30501071    if(len != 0 && p == NULL) {
     
    30981119                         void *ivec)
    30991120{
    3100     struct encryption_type *et = crypto->et;
     1121    struct _krb5_encryption_type *et = crypto->et;
    31011122    size_t cksum_sz = CHECKSUMSIZE(et->checksum);
    31021123    size_t sz = len - cksum_sz - et->confoundersize;
     
    31061127    if ((len % et->padsize) != 0) {
    31071128        krb5_clear_error_message(context);
     1129        return KRB5_BAD_MSIZE;
     1130    }
     1131    if (len < cksum_sz + et->confoundersize) {
     1132        krb5_set_error_message(context, KRB5_BAD_MSIZE,
     1133                               N_("Encrypted data shorter then "
     1134                                  "checksum + confunder", ""));
    31081135        return KRB5_BAD_MSIZE;
    31091136    }
     
    31671194 */
    31681195
    3169 krb5_error_code KRB5_LIB_FUNCTION
     1196KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    31701197krb5_encrypt_iov_ivec(krb5_context context,
    31711198                      krb5_crypto crypto,
     
    31811208    unsigned char *p, *q;
    31821209    krb5_error_code ret;
    3183     struct key_data *dkey;
    3184     const struct encryption_type *et = crypto->et;
     1210    struct _krb5_key_data *dkey;
     1211    const struct _krb5_encryption_type *et = crypto->et;
    31851212    krb5_crypto_iov *tiv, *piv, *hiv;
    31861213
     
    33601387 */
    33611388
    3362 krb5_error_code KRB5_LIB_FUNCTION
     1389KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    33631390krb5_decrypt_iov_ivec(krb5_context context,
    33641391                      krb5_crypto crypto,
     
    33731400    unsigned char *p, *q;
    33741401    krb5_error_code ret;
    3375     struct key_data *dkey;
    3376     struct encryption_type *et = crypto->et;
     1402    struct _krb5_key_data *dkey;
     1403    struct _krb5_encryption_type *et = crypto->et;
    33771404    krb5_crypto_iov *tiv, *hiv;
    33781405
     
    35081535 */
    35091536
    3510 krb5_error_code KRB5_LIB_FUNCTION
     1537KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    35111538krb5_create_checksum_iov(krb5_context context,
    35121539                         krb5_crypto crypto,
     
    35851612 * @param data array of buffers to process
    35861613 * @param num_data length of array
     1614 * @param type return checksum type if not NULL
    35871615 *
    35881616 * @return Return an error code or 0.
     
    35901618 */
    35911619
    3592 krb5_error_code KRB5_LIB_FUNCTION
     1620KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    35931621krb5_verify_checksum_iov(krb5_context context,
    35941622                         krb5_crypto crypto,
     
    35981626                         krb5_cksumtype *type)
    35991627{
    3600     struct encryption_type *et = crypto->et;
     1628    struct _krb5_encryption_type *et = crypto->et;
    36011629    Checksum cksum;
    36021630    krb5_crypto_iov *civ;
     
    36521680
    36531681
    3654 krb5_error_code KRB5_LIB_FUNCTION
     1682KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    36551683krb5_crypto_length(krb5_context context,
    36561684                   krb5_crypto crypto,
     
    36961724
    36971725
    3698 krb5_error_code KRB5_LIB_FUNCTION
     1726KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    36991727krb5_crypto_length_iov(krb5_context context,
    37001728                       krb5_crypto crypto,
     
    37161744
    37171745
    3718 krb5_error_code KRB5_LIB_FUNCTION
     1746KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37191747krb5_encrypt_ivec(krb5_context context,
    37201748                  krb5_crypto crypto,
     
    37351763}
    37361764
    3737 krb5_error_code KRB5_LIB_FUNCTION
     1765KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37381766krb5_encrypt(krb5_context context,
    37391767             krb5_crypto crypto,
     
    37461774}
    37471775
    3748 krb5_error_code KRB5_LIB_FUNCTION
     1776KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37491777krb5_encrypt_EncryptedData(krb5_context context,
    37501778                           krb5_crypto crypto,
     
    37641792}
    37651793
    3766 krb5_error_code KRB5_LIB_FUNCTION
     1794KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37671795krb5_decrypt_ivec(krb5_context context,
    37681796                  krb5_crypto crypto,
     
    37831811}
    37841812
    3785 krb5_error_code KRB5_LIB_FUNCTION
     1813KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37861814krb5_decrypt(krb5_context context,
    37871815             krb5_crypto crypto,
     
    37951823}
    37961824
    3797 krb5_error_code KRB5_LIB_FUNCTION
     1825KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    37981826krb5_decrypt_EncryptedData(krb5_context context,
    37991827                           krb5_crypto crypto,
     
    38101838 ************************************************************/
    38111839
    3812 #define ENTROPY_NEEDED 128
    3813 
    3814 static int
    3815 seed_something(void)
    3816 {
    3817     char buf[1024], seedfile[256];
    3818 
    3819     /* If there is a seed file, load it. But such a file cannot be trusted,
    3820        so use 0 for the entropy estimate */
    3821     if (RAND_file_name(seedfile, sizeof(seedfile))) {
    3822         int fd;
    3823         fd = open(seedfile, O_RDONLY | O_BINARY | O_CLOEXEC);
    3824         if (fd >= 0) {
    3825             ssize_t ret;
    3826             rk_cloexec(fd);
    3827             ret = read(fd, buf, sizeof(buf));
    3828             if (ret > 0)
    3829                 RAND_add(buf, ret, 0.0);
    3830             close(fd);
    3831         } else
    3832             seedfile[0] = '\0';
    3833     } else
    3834         seedfile[0] = '\0';
    3835 
    3836     /* Calling RAND_status() will try to use /dev/urandom if it exists so
    3837        we do not have to deal with it. */
    3838     if (RAND_status() != 1) {
    3839         krb5_context context;
    3840         const char *p;
    3841 
    3842         /* Try using egd */
    3843         if (!krb5_init_context(&context)) {
    3844             p = krb5_config_get_string(context, NULL, "libdefaults",
    3845                                        "egd_socket", NULL);
    3846             if (p != NULL)
    3847                 RAND_egd_bytes(p, ENTROPY_NEEDED);
    3848             krb5_free_context(context);
    3849         }
    3850     }
    3851 
    3852     if (RAND_status() == 1)     {
    3853         /* Update the seed file */
    3854         if (seedfile[0])
    3855             RAND_write_file(seedfile);
    3856 
    3857         return 0;
    3858     } else
    3859         return -1;
    3860 }
    3861 
    3862 void KRB5_LIB_FUNCTION
    3863 krb5_generate_random_block(void *buf, size_t len)
    3864 {
    3865     static int rng_initialized = 0;
    3866 
    3867     HEIMDAL_MUTEX_lock(&crypto_mutex);
    3868     if (!rng_initialized) {
    3869         if (seed_something())
    3870             krb5_abortx(NULL, "Fatal: could not seed the "
    3871                         "random number generator");
    3872        
    3873         rng_initialized = 1;
    3874     }
    3875     HEIMDAL_MUTEX_unlock(&crypto_mutex);
    3876     if (RAND_bytes(buf, len) != 1)
    3877         krb5_abortx(NULL, "Failed to generate random block");
    3878 }
    3879 
    3880 static krb5_error_code
    3881 derive_key(krb5_context context,
    3882            struct encryption_type *et,
    3883            struct key_data *key,
    3884            const void *constant,
    3885            size_t len)
     1840krb5_error_code
     1841_krb5_derive_key(krb5_context context,
     1842                 struct _krb5_encryption_type *et,
     1843                 struct _krb5_key_data *key,
     1844                 const void *constant,
     1845                 size_t len)
    38861846{
    38871847    unsigned char *k = NULL;
    38881848    unsigned int nblocks = 0, i;
    38891849    krb5_error_code ret = 0;
    3890     struct key_type *kt = et->keytype;
     1850    struct _krb5_key_type *kt = et->keytype;
    38911851
    38921852    ret = _key_schedule(context, key);
     
    39451905    switch(kt->type) {
    39461906    case KEYTYPE_DES3:
    3947         DES3_random_to_key(context, key->key, k, nblocks * et->blocksize);
     1907        _krb5_DES3_random_to_key(context, key->key, k, nblocks * et->blocksize);
    39481908        break;
    39491909    case KEYTYPE_AES128:
     
    39701930}
    39711931
    3972 static struct key_data *
     1932static struct _krb5_key_data *
    39731933_new_derived_key(krb5_crypto crypto, unsigned usage)
    39741934{
    3975     struct key_usage *d = crypto->key_usage;
     1935    struct _krb5_key_usage *d = crypto->key_usage;
    39761936    d = realloc(d, (crypto->num_key_usage + 1) * sizeof(*d));
    39771937    if(d == NULL)
     
    39841944}
    39851945
    3986 krb5_error_code KRB5_LIB_FUNCTION
     1946KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    39871947krb5_derive_key(krb5_context context,
    39881948                const krb5_keyblock *key,
     
    39931953{
    39941954    krb5_error_code ret;
    3995     struct encryption_type *et;
    3996     struct key_data d;
     1955    struct _krb5_encryption_type *et;
     1956    struct _krb5_key_data d;
    39971957
    39981958    *derived_key = NULL;
    39991959
    4000     et = _find_enctype (etype);
     1960    et = _krb5_find_enctype (etype);
    40011961    if (et == NULL) {
    40021962        krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
     
    40111971
    40121972    d.schedule = NULL;
    4013     ret = derive_key(context, et, &d, constant, constant_len);
     1973    ret = _krb5_derive_key(context, et, &d, constant, constant_len);
    40141974    if (ret == 0)
    40151975        ret = krb5_copy_keyblock(context, d.key, derived_key);
    4016     free_key_data(context, &d, et);
     1976    _krb5_free_key_data(context, &d, et);
    40171977    return ret;
    40181978}
     
    40221982                 krb5_crypto crypto,
    40231983                 unsigned usage,
    4024                  struct key_data **key)
     1984                 struct _krb5_key_data **key)
    40251985{
    40261986    int i;
    4027     struct key_data *d;
     1987    struct _krb5_key_data *d;
    40281988    unsigned char constant[5];
    40291989
     
    40402000    krb5_copy_keyblock(context, crypto->key.key, &d->key);
    40412001    _krb5_put_int(constant, usage, 5);
    4042     derive_key(context, crypto->et, d, constant, sizeof(constant));
     2002    _krb5_derive_key(context, crypto->et, d, constant, sizeof(constant));
    40432003    *key = d;
    40442004    return 0;
    40452005}
    40462006
    4047 
    4048 krb5_error_code KRB5_LIB_FUNCTION
     2007/**
     2008 * Create a crypto context used for all encryption and signature
     2009 * operation. The encryption type to use is taken from the key, but
     2010 * can be overridden with the enctype parameter.  This can be useful
     2011 * for encryptions types which is compatiable (DES for example).
     2012 *
     2013 * To free the crypto context, use krb5_crypto_destroy().
     2014 *
     2015 * @param context Kerberos context
     2016 * @param key the key block information with all key data
     2017 * @param etype the encryption type
     2018 * @param crypto the resulting crypto context
     2019 *
     2020 * @return Return an error code or 0.
     2021 *
     2022 * @ingroup krb5_crypto
     2023 */
     2024
     2025KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    40492026krb5_crypto_init(krb5_context context,
    40502027                 const krb5_keyblock *key,
     
    40602037    if(etype == ETYPE_NULL)
    40612038        etype = key->keytype;
    4062     (*crypto)->et = _find_enctype(etype);
     2039    (*crypto)->et = _krb5_find_enctype(etype);
    40632040    if((*crypto)->et == NULL || ((*crypto)->et->flags & F_DISABLED)) {
    40642041        free(*crypto);
     
    40902067static void
    40912068free_key_schedule(krb5_context context,
    4092                   struct key_data *key,
    4093                   struct encryption_type *et)
     2069                  struct _krb5_key_data *key,
     2070                  struct _krb5_encryption_type *et)
    40942071{
    40952072    if (et->keytype->cleanup)
     
    40992076}
    41002077
    4101 static void
    4102 free_key_data(krb5_context context, struct key_data *key,
    4103               struct encryption_type *et)
     2078void
     2079_krb5_free_key_data(krb5_context context, struct _krb5_key_data *key,
     2080              struct _krb5_encryption_type *et)
    41042081{
    41052082    krb5_free_keyblock(context, key->key);
     
    41112088
    41122089static void
    4113 free_key_usage(krb5_context context, struct key_usage *ku,
    4114                struct encryption_type *et)
    4115 {
    4116     free_key_data(context, &ku->key, et);
    4117 }
    4118 
    4119 krb5_error_code KRB5_LIB_FUNCTION
     2090free_key_usage(krb5_context context, struct _krb5_key_usage *ku,
     2091               struct _krb5_encryption_type *et)
     2092{
     2093    _krb5_free_key_data(context, &ku->key, et);
     2094}
     2095
     2096/**
     2097 * Free a crypto context created by krb5_crypto_init().
     2098 *
     2099 * @param context Kerberos context
     2100 * @param crypto crypto context to free
     2101 *
     2102 * @return Return an error code or 0.
     2103 *
     2104 * @ingroup krb5_crypto
     2105 */
     2106
     2107KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41202108krb5_crypto_destroy(krb5_context context,
    41212109                    krb5_crypto crypto)
     
    41262114        free_key_usage(context, &crypto->key_usage[i], crypto->et);
    41272115    free(crypto->key_usage);
    4128     free_key_data(context, &crypto->key, crypto->et);
     2116    _krb5_free_key_data(context, &crypto->key, crypto->et);
    41292117    free (crypto);
    41302118    return 0;
    41312119}
    41322120
    4133 krb5_error_code KRB5_LIB_FUNCTION
     2121/**
     2122 * Return the blocksize used algorithm referenced by the crypto context
     2123 *
     2124 * @param context Kerberos context
     2125 * @param crypto crypto context to query
     2126 * @param blocksize the resulting blocksize
     2127 *
     2128 * @return Return an error code or 0.
     2129 *
     2130 * @ingroup krb5_crypto
     2131 */
     2132
     2133KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41342134krb5_crypto_getblocksize(krb5_context context,
    41352135                         krb5_crypto crypto,
     
    41402140}
    41412141
    4142 krb5_error_code KRB5_LIB_FUNCTION
     2142/**
     2143 * Return the encryption type used by the crypto context
     2144 *
     2145 * @param context Kerberos context
     2146 * @param crypto crypto context to query
     2147 * @param enctype the resulting encryption type
     2148 *
     2149 * @return Return an error code or 0.
     2150 *
     2151 * @ingroup krb5_crypto
     2152 */
     2153
     2154KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41432155krb5_crypto_getenctype(krb5_context context,
    41442156                       krb5_crypto crypto,
     
    41492161}
    41502162
    4151 krb5_error_code KRB5_LIB_FUNCTION
     2163/**
     2164 * Return the padding size used by the crypto context
     2165 *
     2166 * @param context Kerberos context
     2167 * @param crypto crypto context to query
     2168 * @param padsize the return padding size
     2169 *
     2170 * @return Return an error code or 0.
     2171 *
     2172 * @ingroup krb5_crypto
     2173 */
     2174
     2175KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41522176krb5_crypto_getpadsize(krb5_context context,
    41532177                       krb5_crypto crypto,
     
    41582182}
    41592183
    4160 krb5_error_code KRB5_LIB_FUNCTION
     2184/**
     2185 * Return the confounder size used by the crypto context
     2186 *
     2187 * @param context Kerberos context
     2188 * @param crypto crypto context to query
     2189 * @param confoundersize the returned confounder size
     2190 *
     2191 * @return Return an error code or 0.
     2192 *
     2193 * @ingroup krb5_crypto
     2194 */
     2195
     2196KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41612197krb5_crypto_getconfoundersize(krb5_context context,
    41622198                              krb5_crypto crypto,
     
    41792215 */
    41802216
    4181 krb5_error_code KRB5_LIB_FUNCTION
     2217KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    41822218krb5_enctype_disable(krb5_context context,
    41832219                     krb5_enctype enctype)
    41842220{
    4185     struct encryption_type *et = _find_enctype(enctype);
     2221    struct _krb5_encryption_type *et = _krb5_find_enctype(enctype);
    41862222    if(et == NULL) {
    41872223        if (context)
     
    42062242 */
    42072243
    4208 krb5_error_code KRB5_LIB_FUNCTION
     2244KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    42092245krb5_enctype_enable(krb5_context context,
    42102246                    krb5_enctype enctype)
    42112247{
    4212     struct encryption_type *et = _find_enctype(enctype);
     2248    struct _krb5_encryption_type *et = _krb5_find_enctype(enctype);
    42132249    if(et == NULL) {
    42142250        if (context)
     
    42222258}
    42232259
    4224 
    4225 krb5_error_code KRB5_LIB_FUNCTION
    4226 krb5_string_to_key_derived(krb5_context context,
    4227                            const void *str,
    4228                            size_t len,
    4229                            krb5_enctype etype,
    4230                            krb5_keyblock *key)
    4231 {
    4232     struct encryption_type *et = _find_enctype(etype);
    4233     krb5_error_code ret;
    4234     struct key_data kd;
    4235     size_t keylen;
    4236     u_char *tmp;
    4237 
    4238     if(et == NULL) {
    4239         krb5_set_error_message (context, KRB5_PROG_ETYPE_NOSUPP,
    4240                                 N_("encryption type %d not supported", ""),
    4241                                 etype);
    4242         return KRB5_PROG_ETYPE_NOSUPP;
    4243     }
    4244     keylen = et->keytype->bits / 8;
    4245 
    4246     ALLOC(kd.key, 1);
    4247     if(kd.key == NULL) {
    4248         krb5_set_error_message (context, ENOMEM,
    4249                                 N_("malloc: out of memory", ""));
    4250         return ENOMEM;
    4251     }
    4252     ret = krb5_data_alloc(&kd.key->keyvalue, et->keytype->size);
    4253     if(ret) {
    4254         free(kd.key);
    4255         return ret;
    4256     }
    4257     kd.key->keytype = etype;
    4258     tmp = malloc (keylen);
    4259     if(tmp == NULL) {
    4260         krb5_free_keyblock(context, kd.key);
    4261         krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    4262         return ENOMEM;
    4263     }
    4264     ret = _krb5_n_fold(str, len, tmp, keylen);
    4265     if (ret) {
    4266         free(tmp);
    4267         krb5_set_error_message (context, ENOMEM, N_("malloc: out of memory", ""));
    4268         return ret;
    4269     }
    4270     kd.schedule = NULL;
    4271     DES3_random_to_key(context, kd.key, tmp, keylen);
    4272     memset(tmp, 0, keylen);
    4273     free(tmp);
    4274     ret = derive_key(context,
    4275                      et,
    4276                      &kd,
    4277                      "kerberos", /* XXX well known constant */
    4278                      strlen("kerberos"));
    4279     if (ret) {
    4280         free_key_data(context, &kd, et);
    4281         return ret;
    4282     }
    4283     ret = krb5_copy_keyblock_contents(context, kd.key, key);
    4284     free_key_data(context, &kd, et);
    4285     return ret;
     2260/**
     2261 * Enable or disable all weak encryption types
     2262 *
     2263 * @param context Kerberos 5 context
     2264 * @param enable true to enable, false to disable
     2265 *
     2266 * @return Return an error code or 0.
     2267 *
     2268 * @ingroup krb5_crypto
     2269 */
     2270
     2271KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     2272krb5_allow_weak_crypto(krb5_context context,
     2273                       krb5_boolean enable)
     2274{
     2275    int i;
     2276
     2277    for(i = 0; i < _krb5_num_etypes; i++)
     2278        if(_krb5_etypes[i]->flags & F_WEAK) {
     2279            if(enable)
     2280                _krb5_etypes[i]->flags &= ~F_DISABLED;
     2281            else
     2282                _krb5_etypes[i]->flags |= F_DISABLED;
     2283        }
     2284    return 0;
    42862285}
    42872286
     
    42912290                size_t       data_len)
    42922291{
    4293     struct encryption_type *et = crypto->et;
     2292    struct _krb5_encryption_type *et = crypto->et;
    42942293    size_t padsize = et->padsize;
    42952294    size_t checksumsize = CHECKSUMSIZE(et->checksum);
     
    43062305                        size_t       data_len)
    43072306{
    4308     struct encryption_type *et = crypto->et;
     2307    struct _krb5_encryption_type *et = crypto->et;
    43092308    size_t padsize = et->padsize;
    43102309    size_t res;
     
    43232322 */
    43242323
    4325 size_t
     2324KRB5_LIB_FUNCTION size_t KRB5_LIB_CALL
    43262325krb5_get_wrapped_length (krb5_context context,
    43272326                         krb5_crypto  crypto,
     
    43422341                 krb5_crypto  crypto)
    43432342{
    4344     struct encryption_type *et = crypto->et;
     2343    struct _krb5_encryption_type *et = crypto->et;
    43452344    size_t res;
    43462345
     
    43562355                         krb5_crypto  crypto)
    43572356{
    4358     struct encryption_type *et = crypto->et;
     2357    struct _krb5_encryption_type *et = crypto->et;
    43592358    size_t res;
    43602359
     
    43692368}
    43702369
    4371 size_t
     2370KRB5_LIB_FUNCTION size_t KRB5_LIB_CALL
    43722371krb5_crypto_overhead (krb5_context context, krb5_crypto crypto)
    43732372{
     
    43872386 * @param type the enctype resulting key will be of
    43882387 * @param data input random data to convert to a key
    4389  * @param data size of input random data, at least krb5_enctype_keysize() long
    4390  * @param data key, output key, free with krb5_free_keyblock_contents()
     2388 * @param size size of input random data, at least krb5_enctype_keysize() long
     2389 * @param key key, output key, free with krb5_free_keyblock_contents()
    43912390 *
    43922391 * @return Return an error code or 0.
     
    43952394 */
    43962395
    4397 krb5_error_code KRB5_LIB_FUNCTION
     2396KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    43982397krb5_random_to_key(krb5_context context,
    43992398                   krb5_enctype type,
     
    44032402{
    44042403    krb5_error_code ret;
    4405     struct encryption_type *et = _find_enctype(type);
     2404    struct _krb5_encryption_type *et = _krb5_find_enctype(type);
    44062405    if(et == NULL) {
    44072406        krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
     
    44302429}
    44312430
    4432 krb5_error_code
    4433 _krb5_pk_octetstring2key(krb5_context context,
    4434                          krb5_enctype type,
    4435                          const void *dhdata,
    4436                          size_t dhsize,
    4437                          const heim_octet_string *c_n,
    4438                          const heim_octet_string *k_n,
    4439                          krb5_keyblock *key)
    4440 {
    4441     struct encryption_type *et = _find_enctype(type);
    4442     krb5_error_code ret;
    4443     size_t keylen, offset;
    4444     void *keydata;
    4445     unsigned char counter;
    4446     unsigned char shaoutput[SHA_DIGEST_LENGTH];
    4447 
    4448     if(et == NULL) {
    4449         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    4450                                N_("encryption type %d not supported", ""),
    4451                                type);
    4452         return KRB5_PROG_ETYPE_NOSUPP;
    4453     }
    4454     keylen = (et->keytype->bits + 7) / 8;
    4455 
    4456     keydata = malloc(keylen);
    4457     if (keydata == NULL) {
    4458         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    4459         return ENOMEM;
    4460     }
    4461 
    4462     counter = 0;
    4463     offset = 0;
    4464     do {
    4465         SHA_CTX m;
    4466        
    4467         SHA1_Init(&m);
    4468         SHA1_Update(&m, &counter, 1);
    4469         SHA1_Update(&m, dhdata, dhsize);
    4470         if (c_n)
    4471             SHA1_Update(&m, c_n->data, c_n->length);
    4472         if (k_n)
    4473             SHA1_Update(&m, k_n->data, k_n->length);
    4474         SHA1_Final(shaoutput, &m);
    4475 
    4476         memcpy((unsigned char *)keydata + offset,
    4477                shaoutput,
    4478                min(keylen - offset, sizeof(shaoutput)));
    4479 
    4480         offset += sizeof(shaoutput);
    4481         counter++;
    4482     } while(offset < keylen);
    4483     memset(shaoutput, 0, sizeof(shaoutput));
    4484 
    4485     ret = krb5_random_to_key(context, type, keydata, keylen, key);
    4486     memset(keydata, 0, sizeof(keylen));
    4487     free(keydata);
    4488     return ret;
    4489 }
    4490 
    4491 static krb5_error_code
    4492 encode_uvinfo(krb5_context context, krb5_const_principal p, krb5_data *data)
    4493 {
    4494     KRB5PrincipalName pn;
    4495     krb5_error_code ret;
    4496     size_t size;
    4497 
    4498     pn.principalName = p->name;
    4499     pn.realm = p->realm;
    4500 
    4501     ASN1_MALLOC_ENCODE(KRB5PrincipalName, data->data, data->length,
    4502                        &pn, &size, ret);
    4503     if (ret) {
    4504         krb5_data_zero(data);
    4505         krb5_set_error_message(context, ret,
    4506                                N_("Failed to encode KRB5PrincipalName", ""));
    4507         return ret;
    4508     }
    4509     if (data->length != size)
    4510         krb5_abortx(context, "asn1 compiler internal error");
    4511     return 0;
    4512 }
    4513 
    4514 static krb5_error_code
    4515 encode_otherinfo(krb5_context context,
    4516                  const AlgorithmIdentifier *ai,
    4517                  krb5_const_principal client,
    4518                  krb5_const_principal server,
    4519                  krb5_enctype enctype,
    4520                  const krb5_data *as_req,
    4521                  const krb5_data *pk_as_rep,
    4522                  const Ticket *ticket,
    4523                  krb5_data *other)
    4524 {
    4525     PkinitSP80056AOtherInfo otherinfo;
    4526     PkinitSuppPubInfo pubinfo;
    4527     krb5_error_code ret;
    4528     krb5_data pub;
    4529     size_t size;
    4530 
    4531     krb5_data_zero(other);
    4532     memset(&otherinfo, 0, sizeof(otherinfo));
    4533     memset(&pubinfo, 0, sizeof(pubinfo));
    4534 
    4535     pubinfo.enctype = enctype;
    4536     pubinfo.as_REQ = *as_req;
    4537     pubinfo.pk_as_rep = *pk_as_rep;
    4538     pubinfo.ticket = *ticket;
    4539     ASN1_MALLOC_ENCODE(PkinitSuppPubInfo, pub.data, pub.length,
    4540                        &pubinfo, &size, ret);
    4541     if (ret) {
    4542         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
    4543         return ret;
    4544     }
    4545     if (pub.length != size)
    4546         krb5_abortx(context, "asn1 compiler internal error");
    4547 
    4548     ret = encode_uvinfo(context, client, &otherinfo.partyUInfo);
    4549     if (ret) {
    4550         free(pub.data);
    4551         return ret;
    4552     }
    4553     ret = encode_uvinfo(context, server, &otherinfo.partyVInfo);
    4554     if (ret) {
    4555         free(otherinfo.partyUInfo.data);
    4556         free(pub.data);
    4557         return ret;
    4558     }
    4559 
    4560     otherinfo.algorithmID = *ai;
    4561     otherinfo.suppPubInfo = &pub;
    4562 
    4563     ASN1_MALLOC_ENCODE(PkinitSP80056AOtherInfo, other->data, other->length,
    4564                        &otherinfo, &size, ret);
    4565     free(otherinfo.partyUInfo.data);
    4566     free(otherinfo.partyVInfo.data);
    4567     free(pub.data);
    4568     if (ret) {
    4569         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
    4570         return ret;
    4571     }
    4572     if (other->length != size)
    4573         krb5_abortx(context, "asn1 compiler internal error");
    4574 
    4575     return 0;
    4576 }
    4577 
    4578 krb5_error_code
    4579 _krb5_pk_kdf(krb5_context context,
    4580              const struct AlgorithmIdentifier *ai,
    4581              const void *dhdata,
    4582              size_t dhsize,
    4583              krb5_const_principal client,
    4584              krb5_const_principal server,
    4585              krb5_enctype enctype,
    4586              const krb5_data *as_req,
    4587              const krb5_data *pk_as_rep,
    4588              const Ticket *ticket,
    4589              krb5_keyblock *key)
    4590 {
    4591     struct encryption_type *et;
    4592     krb5_error_code ret;
    4593     krb5_data other;
    4594     size_t keylen, offset;
    4595     uint32_t counter;
    4596     unsigned char *keydata;
    4597     unsigned char shaoutput[SHA_DIGEST_LENGTH];
    4598 
    4599     if (der_heim_oid_cmp(&asn1_oid_id_pkinit_kdf_ah_sha1, &ai->algorithm) != 0) {
    4600         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    4601                                N_("KDF not supported", ""));
    4602         return KRB5_PROG_ETYPE_NOSUPP;
    4603     }
    4604     if (ai->parameters != NULL &&
    4605         (ai->parameters->length != 2 ||
    4606          memcmp(ai->parameters->data, "\x05\x00", 2) != 0))
    4607         {
    4608             krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    4609                                    N_("kdf params not NULL or the NULL-type",
    4610                                       ""));
    4611             return KRB5_PROG_ETYPE_NOSUPP;
    4612         }
    4613 
    4614     et = _find_enctype(enctype);
    4615     if(et == NULL) {
    4616         krb5_set_error_message(context, KRB5_PROG_ETYPE_NOSUPP,
    4617                                N_("encryption type %d not supported", ""),
    4618                                enctype);
    4619         return KRB5_PROG_ETYPE_NOSUPP;
    4620     }
    4621     keylen = (et->keytype->bits + 7) / 8;
    4622 
    4623     keydata = malloc(keylen);
    4624     if (keydata == NULL) {
    4625         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    4626         return ENOMEM;
    4627     }
    4628 
    4629     ret = encode_otherinfo(context, ai, client, server,
    4630                            enctype, as_req, pk_as_rep, ticket, &other);
    4631     if (ret) {
    4632         free(keydata);
    4633         return ret;
    4634     }
    4635 
    4636     offset = 0;
    4637     counter = 1;
    4638     do {
    4639         unsigned char cdata[4];
    4640         SHA_CTX m;
    4641        
    4642         SHA1_Init(&m);
    4643         _krb5_put_int(cdata, counter, 4);
    4644         SHA1_Update(&m, cdata, 4);
    4645         SHA1_Update(&m, dhdata, dhsize);
    4646         SHA1_Update(&m, other.data, other.length);
    4647         SHA1_Final(shaoutput, &m);
    4648 
    4649         memcpy((unsigned char *)keydata + offset,
    4650                shaoutput,
    4651                min(keylen - offset, sizeof(shaoutput)));
    4652 
    4653         offset += sizeof(shaoutput);
    4654         counter++;
    4655     } while(offset < keylen);
    4656     memset(shaoutput, 0, sizeof(shaoutput));
    4657 
    4658     free(other.data);
    4659 
    4660     ret = krb5_random_to_key(context, enctype, keydata, keylen, key);
    4661     memset(keydata, 0, sizeof(keylen));
    4662     free(keydata);
    4663 
    4664     return ret;
    4665 }
    4666 
    4667 
    4668 krb5_error_code KRB5_LIB_FUNCTION
     2431
     2432
     2433KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    46692434krb5_crypto_prf_length(krb5_context context,
    46702435                       krb5_enctype type,
    46712436                       size_t *length)
    46722437{
    4673     struct encryption_type *et = _find_enctype(type);
     2438    struct _krb5_encryption_type *et = _krb5_find_enctype(type);
    46742439
    46752440    if(et == NULL || et->prf_length == 0) {
     
    46842449}
    46852450
    4686 krb5_error_code KRB5_LIB_FUNCTION
     2451KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    46872452krb5_crypto_prf(krb5_context context,
    46882453                const krb5_crypto crypto,
     
    46902455                krb5_data *output)
    46912456{
    4692     struct encryption_type *et = crypto->et;
     2457    struct _krb5_encryption_type *et = crypto->et;
    46932458
    46942459    krb5_data_zero(output);
     
    47662531 * @param crypto2 second key to combine
    47672532 * @param pepper1 factor to combine with first key to garante uniqueness
    4768  * @param pepper1 factor to combine with second key to garante uniqueness
     2533 * @param pepper2 factor to combine with second key to garante uniqueness
    47692534 * @param enctype the encryption type of the resulting key
    47702535 * @param res allocated key, free with krb5_free_keyblock_contents()
     
    47752540 */
    47762541
    4777 krb5_error_code KRB5_LIB_FUNCTION
     2542KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    47782543krb5_crypto_fx_cf2(krb5_context context,
    47792544                   const krb5_crypto crypto1,
     
    48232588#ifndef HEIMDAL_SMALLER
    48242589
    4825 krb5_error_code KRB5_LIB_FUNCTION
     2590/**
     2591 * Deprecated: keytypes doesn't exists, they are really enctypes.
     2592 *
     2593 * @ingroup krb5_deprecated
     2594 */
     2595
     2596KRB5_DEPRECATED
     2597KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    48262598krb5_keytype_to_enctypes (krb5_context context,
    48272599                          krb5_keytype keytype,
    48282600                          unsigned *len,
    48292601                          krb5_enctype **val)
    4830     KRB5_DEPRECATED
    48312602{
    48322603    int i;
     
    48342605    krb5_enctype *ret;
    48352606
    4836     for (i = num_etypes - 1; i >= 0; --i) {
    4837         if (etypes[i]->keytype->type == keytype
    4838             && !(etypes[i]->flags & F_PSEUDO)
    4839             && krb5_enctype_valid(context, etypes[i]->type) == 0)
     2607    for (i = _krb5_num_etypes - 1; i >= 0; --i) {
     2608        if (_krb5_etypes[i]->keytype->type == keytype
     2609            && !(_krb5_etypes[i]->flags & F_PSEUDO)
     2610            && krb5_enctype_valid(context, _krb5_etypes[i]->type) == 0)
    48402611            ++n;
    48412612    }
     
    48522623    }
    48532624    n = 0;
    4854     for (i = num_etypes - 1; i >= 0; --i) {
    4855         if (etypes[i]->keytype->type == keytype
    4856             && !(etypes[i]->flags & F_PSEUDO)
    4857             && krb5_enctype_valid(context, etypes[i]->type) == 0)
    4858             ret[n++] = etypes[i]->type;
     2625    for (i = _krb5_num_etypes - 1; i >= 0; --i) {
     2626        if (_krb5_etypes[i]->keytype->type == keytype
     2627            && !(_krb5_etypes[i]->flags & F_PSEUDO)
     2628            && krb5_enctype_valid(context, _krb5_etypes[i]->type) == 0)
     2629            ret[n++] = _krb5_etypes[i]->type;
    48592630    }
    48602631    *len = n;
     
    48632634}
    48642635
     2636/**
     2637 * Deprecated: keytypes doesn't exists, they are really enctypes.
     2638 *
     2639 * @ingroup krb5_deprecated
     2640 */
     2641
    48652642/* if two enctypes have compatible keys */
    4866 krb5_boolean KRB5_LIB_FUNCTION
     2643KRB5_DEPRECATED
     2644KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    48672645krb5_enctypes_compatible_keys(krb5_context context,
    48682646                              krb5_enctype etype1,
    48692647                              krb5_enctype etype2)
    4870     KRB5_DEPRECATED
    4871 {
    4872     struct encryption_type *e1 = _find_enctype(etype1);
    4873     struct encryption_type *e2 = _find_enctype(etype2);
     2648{
     2649    struct _krb5_encryption_type *e1 = _krb5_find_enctype(etype1);
     2650    struct _krb5_encryption_type *e2 = _krb5_find_enctype(etype2);
    48742651    return e1 != NULL && e2 != NULL && e1->keytype == e2->keytype;
    48752652}
  • trunk/server/source4/heimdal/lib/krb5/data.c

    r414 r745  
    4242 */
    4343
    44 void KRB5_LIB_FUNCTION
     44KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    4545krb5_data_zero(krb5_data *p)
    4646{
     
    6060 */
    6161
    62 void KRB5_LIB_FUNCTION
     62KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    6363krb5_data_free(krb5_data *p)
    6464{
     
    7777 */
    7878
    79 void KRB5_LIB_FUNCTION
     79KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8080krb5_free_data(krb5_context context,
    8181               krb5_data *p)
     
    8888 * Allocate data of and krb5_data.
    8989 *
    90  * @param p krb5_data to free.
     90 * @param p krb5_data to allocate.
    9191 * @param len size to allocate.
    9292 *
     
    9797 */
    9898
    99 krb5_error_code KRB5_LIB_FUNCTION
     99KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    100100krb5_data_alloc(krb5_data *p, int len)
    101101{
     
    119119 */
    120120
    121 krb5_error_code KRB5_LIB_FUNCTION
     121KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    122122krb5_data_realloc(krb5_data *p, int len)
    123123{
     
    144144 */
    145145
    146 krb5_error_code KRB5_LIB_FUNCTION
     146KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    147147krb5_data_copy(krb5_data *p, const void *data, size_t len)
    148148{
     
    170170 */
    171171
    172 krb5_error_code KRB5_LIB_FUNCTION
     172KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    173173krb5_copy_data(krb5_context context,
    174174               const krb5_data *indata,
     
    201201 */
    202202
    203 int KRB5_LIB_FUNCTION
     203KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    204204krb5_data_cmp(const krb5_data *data1, const krb5_data *data2)
    205205{
     
    208208    return memcmp(data1->data, data2->data, data1->length);
    209209}
     210
     211/**
     212 * Compare to data not exposing timing information from the checksum data
     213 *
     214 * @param data1 krb5_data to compare
     215 * @param data2 krb5_data to compare
     216 *
     217 * @return returns zero for same data, otherwise non zero.
     218 *
     219 * @ingroup krb5
     220 */
     221
     222KRB5_LIB_FUNCTION int KRB5_LIB_CALL
     223krb5_data_ct_cmp(const krb5_data *data1, const krb5_data *data2)
     224{
     225    if (data1->length != data2->length)
     226        return data1->length - data2->length;
     227    return ct_memcmp(data1->data, data2->data, data1->length);
     228}
  • trunk/server/source4/heimdal/lib/krb5/eai_to_heim_errno.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    3636/**
     
    4545 */
    4646
    47 krb5_error_code KRB5_LIB_FUNCTION
     47KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4848krb5_eai_to_heim_errno(int eai_errno, int system_error)
    4949{
     
    7575    case EAI_SOCKTYPE:
    7676        return HEIM_EAI_SOCKTYPE;
     77#ifdef EAI_SYSTEM
    7778    case EAI_SYSTEM:
    7879        return system_error;
     80#endif
    7981    default:
    8082        return HEIM_EAI_UNKNOWN; /* XXX */
     
    9395 */
    9496
    95 krb5_error_code KRB5_LIB_FUNCTION
     97KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9698krb5_h_errno_to_heim_errno(int eai_errno)
    9799{
  • trunk/server/source4/heimdal/lib/krb5/error_string.c

    r414 r745  
    4545 */
    4646
    47 void KRB5_LIB_FUNCTION
     47KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    4848krb5_clear_error_message(krb5_context context)
    4949{
     
    6868 */
    6969
    70 void KRB5_LIB_FUNCTION
     70KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    7171krb5_set_error_message(krb5_context context, krb5_error_code ret,
    7272                       const char *fmt, ...)
     
    9292
    9393
    94 void KRB5_LIB_FUNCTION
     94KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    9595krb5_vset_error_message (krb5_context context, krb5_error_code ret,
    9696                         const char *fmt, va_list args)
    9797    __attribute__ ((format (printf, 3, 0)))
    9898{
    99 
    100     krb5_clear_error_message(context);
    101     HEIMDAL_MUTEX_lock(context->mutex);
     99    int r;
     100
     101    HEIMDAL_MUTEX_lock(context->mutex);
     102    if (context->error_string) {
     103        free(context->error_string);
     104        context->error_string = NULL;
     105    }
    102106    context->error_code = ret;
    103     vasprintf(&context->error_string, fmt, args);
     107    r = vasprintf(&context->error_string, fmt, args);
     108    if (r < 0)
     109        context->error_string = NULL;
     110    HEIMDAL_MUTEX_unlock(context->mutex);
     111}
     112
     113/**
     114 * Prepend the context full error string for a specific error code.
     115 * The error that is stored should be internationalized.
     116 *
     117 * @param context Kerberos 5 context
     118 * @param ret The error code
     119 * @param fmt Error string for the error code
     120 * @param ... printf(3) style parameters.
     121 *
     122 * @ingroup krb5_error
     123 */
     124
     125KRB5_LIB_FUNCTION void KRB5_LIB_CALL
     126krb5_prepend_error_message(krb5_context context, krb5_error_code ret,
     127                           const char *fmt, ...)
     128    __attribute__ ((format (printf, 3, 4)))
     129{
     130    va_list ap;
     131
     132    va_start(ap, fmt);
     133    krb5_vprepend_error_message(context, ret, fmt, ap);
     134    va_end(ap);
     135}
     136
     137/**
     138 * Prepend the contexts's full error string for a specific error code.
     139 *
     140 * @param context Kerberos 5 context
     141 * @param ret The error code
     142 * @param fmt Error string for the error code
     143 * @param args printf(3) style parameters.
     144 *
     145 * @ingroup krb5_error
     146 */
     147
     148KRB5_LIB_FUNCTION void KRB5_LIB_CALL
     149krb5_vprepend_error_message(krb5_context context, krb5_error_code ret,
     150                            const char *fmt, va_list args)
     151    __attribute__ ((format (printf, 3, 0)))
     152{
     153    char *str = NULL, *str2 = NULL;
     154    HEIMDAL_MUTEX_lock(context->mutex);
     155    if (context->error_code != ret) {
     156        HEIMDAL_MUTEX_unlock(context->mutex);
     157        return;
     158    }
     159    if (vasprintf(&str, fmt, args) < 0 || str == NULL) {
     160        HEIMDAL_MUTEX_unlock(context->mutex);
     161        return;
     162    }
     163    if (context->error_string) {
     164        int e;
     165
     166        e = asprintf(&str2, "%s: %s", str, context->error_string);
     167        free(context->error_string);
     168        if (e < 0 || str2 == NULL)
     169            context->error_string = NULL;
     170        else
     171            context->error_string = str2;
     172        free(str);
     173    } else
     174        context->error_string = str;
    104175    HEIMDAL_MUTEX_unlock(context->mutex);
    105176}
     
    118189 */
    119190
    120 char * KRB5_LIB_FUNCTION
     191KRB5_LIB_FUNCTION char * KRB5_LIB_CALL
    121192krb5_get_error_string(krb5_context context)
    122193{
     
    130201}
    131202
    132 krb5_boolean KRB5_LIB_FUNCTION
     203KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    133204krb5_have_error_string(krb5_context context)
    134205{
     
    153224 */
    154225
    155 const char * KRB5_LIB_FUNCTION
     226KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL
    156227krb5_get_error_message(krb5_context context, krb5_error_code code)
    157228{
    158     const char *cstr;
    159229    char *str;
    160230
     
    173243    if (code == 0)
    174244        return strdup("Success");
    175 
    176     cstr = krb5_get_err_text(context, code);
    177     if (cstr)
    178         return strdup(cstr);
    179 
    180     if (asprintf(&str, "<unknown error: %d>", (int)code) == -1)
     245    {
     246        const char *msg;
     247        char buf[128];
     248        msg = com_right_r(context->et_list, code, buf, sizeof(buf));
     249        if (msg)
     250            return strdup(msg);
     251    }
     252
     253    if (asprintf(&str, "<unknown error: %d>", (int)code) == -1 || str == NULL)
    181254        return NULL;
    182255
     
    195268 */
    196269
    197 void KRB5_LIB_FUNCTION
     270KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    198271krb5_free_error_message(krb5_context context, const char *msg)
    199272{
    200273    free(rk_UNCONST(msg));
    201274}
     275
     276
     277/**
     278 * Return the error string for the error code. The caller must not
     279 * free the string.
     280 *
     281 * This function is deprecated since its not threadsafe.
     282 *
     283 * @param context Kerberos 5 context.
     284 * @param code Kerberos error code.
     285 *
     286 * @return the error message matching code
     287 *
     288 * @ingroup krb5
     289 */
     290
     291KRB5_DEPRECATED
     292KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
     293krb5_get_err_text(krb5_context context, krb5_error_code code)
     294{
     295    const char *p = NULL;
     296    if(context != NULL)
     297        p = com_right(context->et_list, code);
     298    if(p == NULL)
     299        p = strerror(code);
     300    if (p == NULL)
     301        p = "Unknown error";
     302    return p;
     303}
  • trunk/server/source4/heimdal/lib/krb5/expand_hostname.c

    r414 r745  
    6464 */
    6565
    66 krb5_error_code KRB5_LIB_FUNCTION
     66KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6767krb5_expand_hostname (krb5_context context,
    6868                      const char *orig_hostname,
     
    141141 */
    142142
    143 krb5_error_code KRB5_LIB_FUNCTION
     143KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    144144krb5_expand_hostname_realms (krb5_context context,
    145145                             const char *orig_hostname,
  • trunk/server/source4/heimdal/lib/krb5/fcache.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    5759#define FCC_CURSOR(C) ((struct fcc_cursor*)(C))
    5860
    59 static const char*
     61static const char* KRB5_CALLCONV
    6062fcc_get_name(krb5_context context,
    6163             krb5_ccache id)
     
    9698                               filename);
    9799        break;
    98     default:
     100    default: {
     101        char buf[128];
     102        rk_strerror_r(ret, buf, sizeof(buf));
    99103        krb5_set_error_message(context, ret,
    100104                               N_("error locking cache file %s: %s",
    101                                   "file, error"),
    102                                filename, strerror(ret));
    103         break;
     105                                  "file, error"), filename, buf);
     106        break;
     107    }
    104108    }
    105109    return ret;
     
    128132        ret = 0;
    129133        break;
    130     default:
     134    default: {
     135        char buf[128];
     136        rk_strerror_r(ret, buf, sizeof(buf));
    131137        krb5_set_error_message(context, ret,
    132                                N_("Failed to unlock file: %s", ""),
    133                                strerror(ret));
    134         break;
     138                               N_("Failed to unlock file: %s", ""), buf);
     139        break;
     140    }
    135141    }
    136142    return ret;
     
    162168
    163169
    164 static krb5_error_code
     170static krb5_error_code KRB5_CALLCONV
    165171fcc_lock(krb5_context context, krb5_ccache id,
    166172         int fd, krb5_boolean exclusive)
     
    169175}
    170176
    171 static krb5_error_code
     177static krb5_error_code KRB5_CALLCONV
    172178fcc_unlock(krb5_context context, int fd)
    173179{
     
    175181}
    176182
    177 static krb5_error_code
     183static krb5_error_code KRB5_CALLCONV
    178184fcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
    179185{
     
    221227        pos -= tmp;
    222228    }
     229#ifdef _MSC_VER
     230    _commit (fd);
     231#else
    223232    fsync (fd);
     233#endif
    224234    return 0;
    225235}
     
    295305}
    296306
    297 static krb5_error_code
     307static krb5_error_code KRB5_CALLCONV
    298308fcc_gen_new(krb5_context context, krb5_ccache *id)
    299309{
     310    char *file = NULL, *exp_file = NULL;
     311    krb5_error_code ret;
    300312    krb5_fcache *f;
    301313    int fd;
    302     char *file;
    303314
    304315    f = malloc(sizeof(*f));
     
    308319        return KRB5_CC_NOMEM;
    309320    }
    310     asprintf (&file, "%sXXXXXX", KRB5_DEFAULT_CCFILE_ROOT);
    311     if(file == NULL) {
     321    ret = asprintf (&file, "%sXXXXXX", KRB5_DEFAULT_CCFILE_ROOT);
     322    if(ret < 0 || file == NULL) {
    312323        free(f);
    313324        krb5_set_error_message(context, KRB5_CC_NOMEM,
     
    315326        return KRB5_CC_NOMEM;
    316327    }
    317     fd = mkstemp(file);
     328    ret = _krb5_expand_path_tokens(context, file, &exp_file);
     329    free(file);
     330    if (ret)
     331        return ret;
     332
     333    file = exp_file;
     334
     335    fd = mkstemp(exp_file);
    318336    if(fd < 0) {
    319337        int ret = errno;
    320         krb5_set_error_message(context, ret, N_("mkstemp %s failed", ""), file);
     338        krb5_set_error_message(context, ret, N_("mkstemp %s failed", ""), exp_file);
    321339        free(f);
    322         free(file);
     340        free(exp_file);
    323341        return ret;
    324342    }
    325343    close(fd);
    326     f->filename = file;
     344    f->filename = exp_file;
    327345    f->version = 0;
    328346    (*id)->data.data = f;
     
    356374}
    357375
    358 static krb5_error_code
     376static krb5_error_code KRB5_CALLCONV
    359377fcc_open(krb5_context context,
    360378         krb5_ccache id,
     
    370388    fd = open(filename, flags, mode);
    371389    if(fd < 0) {
     390        char buf[128];
    372391        ret = errno;
     392        rk_strerror_r(ret, buf, sizeof(buf));
    373393        krb5_set_error_message(context, ret, N_("open(%s): %s", "file, error"),
    374                                filename, strerror(ret));
     394                               filename, buf);
    375395        return ret;
    376396    }
     
    385405}
    386406
    387 static krb5_error_code
     407static krb5_error_code KRB5_CALLCONV
    388408fcc_initialize(krb5_context context,
    389409               krb5_ccache id,
     
    432452    if (close(fd) < 0)
    433453        if (ret == 0) {
     454            char buf[128];
    434455            ret = errno;
     456            rk_strerror_r(ret, buf, sizeof(buf));
    435457            krb5_set_error_message (context, ret, N_("close %s: %s", ""),
    436                                     FILENAME(id), strerror(ret));
     458                                    FILENAME(id), buf);
    437459        }
    438460    return ret;
    439461}
    440462
    441 static krb5_error_code
     463static krb5_error_code KRB5_CALLCONV
    442464fcc_close(krb5_context context,
    443465          krb5_ccache id)
     
    448470}
    449471
    450 static krb5_error_code
     472static krb5_error_code KRB5_CALLCONV
    451473fcc_destroy(krb5_context context,
    452474            krb5_ccache id)
     
    456478}
    457479
    458 static krb5_error_code
     480static krb5_error_code KRB5_CALLCONV
    459481fcc_store_cred(krb5_context context,
    460482               krb5_ccache id,
     
    486508    if (close(fd) < 0) {
    487509        if (ret == 0) {
     510            char buf[128];
     511            rk_strerror_r(ret, buf, sizeof(buf));
    488512            ret = errno;
    489513            krb5_set_error_message (context, ret, N_("close %s: %s", ""),
    490                                     FILENAME(id), strerror(ret));
     514                                    FILENAME(id), buf);
    491515        }
    492516    }
     
    498522          krb5_ccache id,
    499523          krb5_storage **ret_sp,
    500           int *ret_fd)
     524          int *ret_fd,
     525          krb5_deltat *kdc_offset)
    501526{
    502527    int fd;
     
    504529    krb5_storage *sp;
    505530    krb5_error_code ret;
     531
     532    if (kdc_offset)
     533        *kdc_offset = 0;
    506534
    507535    ret = fcc_open(context, id, &fd, O_RDONLY | O_BINARY | O_CLOEXEC, 0);
     
    580608            }
    581609            switch (dtag) {
    582             case FCC_TAG_DELTATIME :
    583                 ret = krb5_ret_int32 (sp, &context->kdc_sec_offset);
     610            case FCC_TAG_DELTATIME : {
     611                int32_t offset;
     612
     613                ret = krb5_ret_int32 (sp, &offset);
     614                ret |= krb5_ret_int32 (sp, &context->kdc_usec_offset);
    584615                if(ret) {
    585616                    ret = KRB5_CC_FORMAT;
     
    590621                    goto out;
    591622                }
    592                 ret = krb5_ret_int32 (sp, &context->kdc_usec_offset);
    593                 if(ret) {
    594                     ret = KRB5_CC_FORMAT;
    595                     krb5_set_error_message(context, ret,
    596                                            N_("Error reading kdc_usec in "
    597                                               "cache file: %s", ""),
    598                                            FILENAME(id));
    599                     goto out;
    600                 }
     623                context->kdc_sec_offset = offset;
     624                if (kdc_offset)
     625                    *kdc_offset = offset;
    601626                break;
     627            }
    602628            default :
    603629                for (i = 0; i < data_len; ++i) {
     
    642668}
    643669
    644 static krb5_error_code
     670static krb5_error_code KRB5_CALLCONV
    645671fcc_get_principal(krb5_context context,
    646672                  krb5_ccache id,
     
    651677    krb5_storage *sp;
    652678
    653     ret = init_fcc (context, id, &sp, &fd);
     679    ret = init_fcc (context, id, &sp, &fd, NULL);
    654680    if (ret)
    655681        return ret;
     
    663689}
    664690
    665 static krb5_error_code
     691static krb5_error_code KRB5_CALLCONV
    666692fcc_end_get (krb5_context context,
    667693             krb5_ccache id,
    668694             krb5_cc_cursor *cursor);
    669695
    670 static krb5_error_code
     696static krb5_error_code KRB5_CALLCONV
    671697fcc_get_first (krb5_context context,
    672698               krb5_ccache id,
     
    684710
    685711    ret = init_fcc (context, id, &FCC_CURSOR(*cursor)->sp,
    686                     &FCC_CURSOR(*cursor)->fd);
     712                    &FCC_CURSOR(*cursor)->fd, NULL);
    687713    if (ret) {
    688714        free(*cursor);
     
    701727}
    702728
    703 static krb5_error_code
     729static krb5_error_code KRB5_CALLCONV
    704730fcc_get_next (krb5_context context,
    705731              krb5_ccache id,
     
    719745}
    720746
    721 static krb5_error_code
     747static krb5_error_code KRB5_CALLCONV
    722748fcc_end_get (krb5_context context,
    723749             krb5_ccache id,
     
    731757}
    732758
    733 static krb5_error_code
     759static krb5_error_code KRB5_CALLCONV
    734760fcc_remove_cred(krb5_context context,
    735761                 krb5_ccache id,
     
    739765    krb5_error_code ret;
    740766    krb5_ccache copy, newfile;
    741     char *newname;
     767    char *newname = NULL;
    742768    int fd;
    743769
     
    758784    }
    759785
    760     asprintf(&newname, "FILE:%s.XXXXXX", FILENAME(id));
    761     if (newname == NULL) {
     786    ret = asprintf(&newname, "FILE:%s.XXXXXX", FILENAME(id));
     787    if (ret < 0 || newname == NULL) {
    762788        krb5_cc_destroy(context, copy);
    763         return ret;
     789        return ENOMEM;
    764790    }
    765791
     
    788814    }
    789815
    790     ret = rename(&newname[5], FILENAME(id));
     816    ret = rk_rename(&newname[5], FILENAME(id));
    791817    if (ret)
    792818        ret = errno;
     
    797823}
    798824
    799 static krb5_error_code
     825static krb5_error_code KRB5_CALLCONV
    800826fcc_set_flags(krb5_context context,
    801827              krb5_ccache id,
     
    805831}
    806832
    807 static int
     833static int KRB5_CALLCONV
    808834fcc_get_version(krb5_context context,
    809835                krb5_ccache id)
     
    816842};
    817843
    818 static krb5_error_code
     844static krb5_error_code KRB5_CALLCONV
    819845fcc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
    820846{
     
    831857}
    832858
    833 static krb5_error_code
     859static krb5_error_code KRB5_CALLCONV
    834860fcc_get_cache_next(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
    835861{
     
    854880        fn = expandedfn;
    855881    }
     882    /* check if file exists, don't return a non existant "next" */
     883    if (strncasecmp(fn, "FILE:", 5) == 0) {
     884        struct stat sb;
     885        ret = stat(fn + 5, &sb);
     886        if (ret) {
     887            ret = KRB5_CC_END;
     888            goto out;
     889        }
     890    }
    856891    ret = krb5_cc_resolve(context, fn, id);
     892 out:
    857893    if (expandedfn)
    858894        free(expandedfn);
     
    861897}
    862898
    863 static krb5_error_code
     899static krb5_error_code KRB5_CALLCONV
    864900fcc_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
    865901{
     
    869905}
    870906
    871 static krb5_error_code
     907static krb5_error_code KRB5_CALLCONV
    872908fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
    873909{
    874910    krb5_error_code ret = 0;
    875911
    876     ret = rename(FILENAME(from), FILENAME(to));
     912    ret = rk_rename(FILENAME(from), FILENAME(to));
     913
    877914    if (ret && errno != EXDEV) {
     915        char buf[128];
    878916        ret = errno;
     917        rk_strerror_r(ret, buf, sizeof(buf));
    879918        krb5_set_error_message(context, ret,
    880919                               N_("Rename of file from %s "
    881920                                  "to %s failed: %s", ""),
    882                                FILENAME(from), FILENAME(to),
    883                                strerror(ret));
     921                               FILENAME(from), FILENAME(to), buf);
    884922        return ret;
    885923    } else if (ret && errno == EXDEV) {
     
    937975        krb5_storage *sp;
    938976        int fd;
    939         ret = init_fcc (context, to, &sp, &fd);
    940         if (sp)
    941             krb5_storage_free(sp);
    942         fcc_unlock(context, fd);
    943         close(fd);
    944     }
    945 
    946     fcc_destroy(context, from);
    947 
    948     return ret;
    949 }
    950 
    951 static krb5_error_code
     977        if ((ret = init_fcc (context, to, &sp, &fd, NULL)) == 0) {
     978            if (sp)
     979                krb5_storage_free(sp);
     980            fcc_unlock(context, fd);
     981            close(fd);
     982        }
     983    }
     984
     985    fcc_close(context, from);
     986
     987    return ret;
     988}
     989
     990static krb5_error_code KRB5_CALLCONV
    952991fcc_get_default_name(krb5_context context, char **str)
    953992{
     
    957996}
    958997
    959 static krb5_error_code
     998static krb5_error_code KRB5_CALLCONV
    960999fcc_lastchange(krb5_context context, krb5_ccache id, krb5_timestamp *mtime)
    9611000{
     
    9771016    return 0;
    9781017}
     1018
     1019static krb5_error_code KRB5_CALLCONV
     1020fcc_set_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat kdc_offset)
     1021{
     1022    return 0;
     1023}
     1024
     1025static krb5_error_code KRB5_CALLCONV
     1026fcc_get_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat *kdc_offset)
     1027{
     1028    krb5_error_code ret;
     1029    krb5_storage *sp = NULL;
     1030    int fd;
     1031    ret = init_fcc(context, id, &sp, &fd, kdc_offset);
     1032    if (sp)
     1033        krb5_storage_free(sp);
     1034    fcc_unlock(context, fd);
     1035    close(fd);
     1036
     1037    return ret;
     1038}
     1039
    9791040
    9801041/**
     
    10081069    fcc_get_default_name,
    10091070    NULL,
    1010     fcc_lastchange
     1071    fcc_lastchange,
     1072    fcc_set_kdc_offset,
     1073    fcc_get_kdc_offset
    10111074};
  • trunk/server/source4/heimdal/lib/krb5/free.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_free_kdc_rep(krb5_context context, krb5_kdc_rep *rep)
    3838{
     
    4444}
    4545
    46 krb5_error_code KRB5_LIB_FUNCTION
     46KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4747krb5_xfree (void *ptr)
    4848{
  • trunk/server/source4/heimdal/lib/krb5/free_host_realm.c

    r414 r745  
    4545 */
    4646
    47 krb5_error_code KRB5_LIB_FUNCTION
     47KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4848krb5_free_host_realm(krb5_context context,
    4949                     krb5_realm *realmlist)
  • trunk/server/source4/heimdal/lib/krb5/generate_seq_number.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_generate_seq_number(krb5_context context,
    3838                         const krb5_keyblock *key,
    3939                         uint32_t *seqno)
    4040{
    41     krb5_error_code ret;
    42     krb5_keyblock *subkey;
    43     uint32_t q;
    44     u_char *p;
    45     int i;
    46 
    47     ret = krb5_generate_subkey (context, key, &subkey);
    48     if (ret)
    49         return ret;
    50 
    51     q = 0;
    52     for (p = (u_char *)subkey->keyvalue.data, i = 0;
    53          i < subkey->keyvalue.length;
    54          ++i, ++p)
    55         q = (q << 8) | *p;
    56     q &= 0xffffffff;
    57     *seqno = q;
    58     krb5_free_keyblock (context, subkey);
     41    if (RAND_bytes((void *)seqno, sizeof(*seqno)) <= 0)
     42        krb5_abortx(context, "Failed to generate random block");
     43    /* MIT used signed numbers, lets not stomp into that space directly */
     44    *seqno &= 0x3fffffff;
     45    if (*seqno == 0)
     46        *seqno = 1;
    5947    return 0;
    6048}
  • trunk/server/source4/heimdal/lib/krb5/generate_subkey.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
    37 krb5_generate_subkey(krb5_context context,
    38                      const krb5_keyblock *key,
    39                      krb5_keyblock **subkey)
    40 {
    41     return krb5_generate_subkey_extended(context, key, key->keytype, subkey);
    42 }
     36/**
     37 * Generate subkey, from keyblock
     38 *
     39 * @param context kerberos context
     40 * @param key session key
     41 * @param etype encryption type of subkey, if ETYPE_NULL, use key's enctype
     42 * @param subkey returned new, free with krb5_free_keyblock().
     43 *
     44 * @return 0 on success or a Kerberos 5 error code
     45 *
     46* @ingroup krb5_crypto
     47 */
    4348
    44 krb5_error_code KRB5_LIB_FUNCTION
     49KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4550krb5_generate_subkey_extended(krb5_context context,
    4651                              const krb5_keyblock *key,
  • trunk/server/source4/heimdal/lib/krb5/get_addrs.c

    r414 r745  
    267267 */
    268268
    269 krb5_error_code KRB5_LIB_FUNCTION
     269KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    270270krb5_get_all_client_addrs (krb5_context context, krb5_addresses *res)
    271271{
     
    283283 */
    284284
    285 krb5_error_code KRB5_LIB_FUNCTION
     285KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    286286krb5_get_all_server_addrs (krb5_context context, krb5_addresses *res)
    287287{
  • trunk/server/source4/heimdal/lib/krb5/get_cred.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    3234 */
    3335
    34 #include <krb5_locl.h>
     36#include "krb5_locl.h"
     37#include <assert.h>
     38
     39static krb5_error_code
     40get_cred_kdc_capath(krb5_context, krb5_kdc_flags,
     41                    krb5_ccache, krb5_creds *, krb5_principal,
     42                    Ticket *, krb5_creds **, krb5_creds ***);
    3543
    3644/*
     
    8088               KDC_REQ_BODY *req_body,
    8189               krb5_authdata *authdata,
    82                krb5_keyblock *key)
     90               krb5_keyblock *subkey)
    8391{
    8492    if(authdata->len) {
     
    102110            return ENOMEM;
    103111        }
    104         ret = krb5_crypto_init(context, key, 0, &crypto);
     112        ret = krb5_crypto_init(context, subkey, 0, &crypto);
    105113        if (ret) {
    106114            free (buf);
     
    112120                                   crypto,
    113121                                   KRB5_KU_TGS_REQ_AUTH_DAT_SUBKEY,
    114                                    /* KRB5_KU_TGS_REQ_AUTH_DAT_SESSION? */
    115122                                   buf,
    116123                                   len,
     
    144151              TGS_REQ *t)
    145152{
     153    krb5_auth_context ac = NULL;
    146154    krb5_error_code ret = 0;
    147155
     
    239247    }
    240248
    241     {
    242         krb5_auth_context ac;
    243         krb5_keyblock *key = NULL;
    244 
    245         ret = krb5_auth_con_init(context, &ac);
    246         if(ret)
    247             goto fail;
    248 
    249         if (krb5_config_get_bool_default(context, NULL, FALSE,
    250                                          "realms",
    251                                          krbtgt->server->realm,
    252                                          "tgs_require_subkey",
    253                                          NULL))
    254         {
    255             ret = krb5_generate_subkey (context, &krbtgt->session, &key);
    256             if (ret) {
    257                 krb5_auth_con_free (context, ac);
    258                 goto fail;
    259             }
    260 
    261             ret = krb5_auth_con_setlocalsubkey(context, ac, key);
    262             if (ret) {
    263                 if (key)
    264                     krb5_free_keyblock (context, key);
    265                 krb5_auth_con_free (context, ac);
    266                 goto fail;
    267             }
    268         }
    269 
    270         ret = set_auth_data (context, &t->req_body, &in_creds->authdata,
    271                              key ? key : &krbtgt->session);
    272         if (ret) {
    273             if (key)
    274                 krb5_free_keyblock (context, key);
    275             krb5_auth_con_free (context, ac);
    276             goto fail;
    277         }
    278 
    279         ret = make_pa_tgs_req(context,
    280                               ac,
    281                               &t->req_body,
    282                               &t->padata->val[0],
    283                               krbtgt);
    284         if(ret) {
    285             if (key)
    286                 krb5_free_keyblock (context, key);
    287             krb5_auth_con_free(context, ac);
    288             goto fail;
    289         }
    290         *subkey = key;
    291        
     249    ret = krb5_auth_con_init(context, &ac);
     250    if(ret)
     251        goto fail;
     252   
     253    ret = krb5_auth_con_generatelocalsubkey(context, ac, &krbtgt->session);
     254    if (ret)
     255        goto fail;
     256   
     257    ret = set_auth_data (context, &t->req_body, &in_creds->authdata,
     258                         ac->local_subkey);
     259    if (ret)
     260        goto fail;
     261   
     262    ret = make_pa_tgs_req(context,
     263                          ac,
     264                          &t->req_body,
     265                          &t->padata->val[0],
     266                          krbtgt);
     267    if(ret)
     268        goto fail;
     269
     270    ret = krb5_auth_con_getlocalsubkey(context, ac, subkey);
     271    if (ret)
     272        goto fail;
     273
     274fail:
     275    if (ac)
    292276        krb5_auth_con_free(context, ac);
    293     }
    294 fail:
    295277    if (ret) {
    296278        t->req_body.addresses = NULL;
     
    338320
    339321/* DCE compatible decrypt proc */
    340 static krb5_error_code
     322static krb5_error_code KRB5_CALLCONV
    341323decrypt_tkt_with_subkey (krb5_context context,
    342324                         krb5_keyblock *key,
    343325                         krb5_key_usage usage,
    344                          krb5_const_pointer subkey,
     326                         krb5_const_pointer skey,
    345327                         krb5_kdc_rep *dec_rep)
    346328{
    347     krb5_error_code ret;
     329    const krb5_keyblock *subkey = skey;
     330    krb5_error_code ret = 0;
    348331    krb5_data data;
    349332    size_t size;
    350333    krb5_crypto crypto;
    351334
    352     ret = krb5_crypto_init(context, key, 0, &crypto);
    353     if (ret)
    354         return ret;
    355     ret = krb5_decrypt_EncryptedData (context,
    356                                       crypto,
    357                                       usage,
    358                                       &dec_rep->kdc_rep.enc_part,
    359                                       &data);
    360     krb5_crypto_destroy(context, crypto);
    361     if(ret && subkey){
    362         /* DCE compat -- try to decrypt with subkey */
     335    assert(usage == 0);
     336
     337    /*
     338     * start out with trying with subkey if we have one
     339     */
     340    if (subkey) {
    363341        ret = krb5_crypto_init(context, subkey, 0, &crypto);
    364342        if (ret)
     
    367345                                          crypto,
    368346                                          KRB5_KU_TGS_REP_ENC_PART_SUB_KEY,
     347                                          &dec_rep->kdc_rep.enc_part,
     348                                          &data);
     349        /*
     350         * If the is Windows 2000 DC, we need to retry with key usage
     351         * 8 when doing ARCFOUR.
     352         */
     353        if (ret && subkey->keytype == ETYPE_ARCFOUR_HMAC_MD5) {
     354            ret = krb5_decrypt_EncryptedData(context,
     355                                             crypto,
     356                                             8,
     357                                             &dec_rep->kdc_rep.enc_part,
     358                                             &data);
     359        }
     360        krb5_crypto_destroy(context, crypto);
     361    }
     362    if (subkey == NULL || ret) {
     363        ret = krb5_crypto_init(context, key, 0, &crypto);
     364        if (ret)
     365            return ret;
     366        ret = krb5_decrypt_EncryptedData (context,
     367                                          crypto,
     368                                          KRB5_KU_TGS_REP_ENC_PART_SESSION,
    369369                                          &dec_rep->kdc_rep.enc_part,
    370370                                          &data);
     
    550550                                   &krbtgt->session,
    551551                                   NULL,
    552                                    KRB5_KU_TGS_REP_ENC_PART_SESSION,
     552                                   0,
    553553                                   &krbtgt->addresses,
    554554                                   nonce,
     
    575575    krb5_data_free(&resp);
    576576    krb5_data_free(&enc);
    577     if(subkey){
    578         krb5_free_keyblock_contents(context, subkey);
    579         free(subkey);
    580     }
     577    if(subkey)
     578        krb5_free_keyblock(context, subkey);
    581579    return ret;
    582580
     
    628626}
    629627
    630 krb5_error_code KRB5_LIB_FUNCTION
     628KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    631629krb5_get_kdc_cred(krb5_context context,
    632630                  krb5_ccache id,
     
    730728}
    731729
    732 /*
    733 get_cred(server)
    734         creds = cc_get_cred(server)
    735         if(creds) return creds
    736         tgt = cc_get_cred(krbtgt/server_realm@any_realm)
    737         if(tgt)
    738                 return get_cred_tgt(server, tgt)
    739         if(client_realm == server_realm)
    740                 return NULL
    741         tgt = get_cred(krbtgt/server_realm@client_realm)
    742         while(tgt_inst != server_realm)
    743                 tgt = get_cred(krbtgt/server_realm@tgt_inst)
    744         return get_cred_tgt(server, tgt)
    745         */
    746 
    747730static krb5_error_code
    748 get_cred_kdc_capath(krb5_context context,
    749                     krb5_kdc_flags flags,
    750                     krb5_ccache ccache,
    751                     krb5_creds *in_creds,
    752                     krb5_principal impersonate_principal,
    753                     Ticket *second_ticket,                     
    754                     krb5_creds **out_creds,
    755                     krb5_creds ***ret_tgts)
     731get_cred_kdc_capath_worker(krb5_context context,
     732                           krb5_kdc_flags flags,
     733                           krb5_ccache ccache,
     734                           krb5_creds *in_creds,
     735                           krb5_const_realm try_realm,
     736                           krb5_principal impersonate_principal,
     737                           Ticket *second_ticket,                       
     738                           krb5_creds **out_creds,
     739                           krb5_creds ***ret_tgts)
    756740{
    757741    krb5_error_code ret;
    758742    krb5_creds *tgt, tmp_creds;
    759     krb5_const_realm client_realm, server_realm, try_realm;
     743    krb5_const_realm client_realm, server_realm;
    760744    int ok_as_delegate = 1;
    761745
     
    768752    if(ret)
    769753        return ret;
    770 
    771     try_realm = krb5_config_get_string(context, NULL, "capaths",
    772                                        client_realm, server_realm, NULL);
    773     if (try_realm == NULL)
    774         try_realm = client_realm;
    775754
    776755    ret = krb5_make_principal(context,
     
    790769                        *ret_tgts, &tgts);
    791770        if(ret == 0){
    792             if (try_realm != client_realm)
     771            /* only allow implicit ok_as_delegate if the realm is the clients realm */
     772            if (strcmp(try_realm, client_realm) != 0 || strcmp(try_realm, server_realm) != 0)
    793773                ok_as_delegate = tgts.flags.b.ok_as_delegate;
    794774
     
    881861    krb5_free_creds(context, tgt);
    882862    return ret;
     863}                           
     864
     865/*
     866get_cred(server)
     867        creds = cc_get_cred(server)
     868        if(creds) return creds
     869        tgt = cc_get_cred(krbtgt/server_realm@any_realm)
     870        if(tgt)
     871                return get_cred_tgt(server, tgt)
     872        if(client_realm == server_realm)
     873                return NULL
     874        tgt = get_cred(krbtgt/server_realm@client_realm)
     875        while(tgt_inst != server_realm)
     876                tgt = get_cred(krbtgt/server_realm@tgt_inst)
     877        return get_cred_tgt(server, tgt)
     878        */
     879
     880static krb5_error_code
     881get_cred_kdc_capath(krb5_context context,
     882                    krb5_kdc_flags flags,
     883                    krb5_ccache ccache,
     884                    krb5_creds *in_creds,
     885                    krb5_principal impersonate_principal,
     886                    Ticket *second_ticket,                     
     887                    krb5_creds **out_creds,
     888                    krb5_creds ***ret_tgts)
     889{
     890    krb5_error_code ret;
     891    krb5_const_realm client_realm, server_realm, try_realm;
     892
     893    client_realm = krb5_principal_get_realm(context, in_creds->client);
     894    server_realm = krb5_principal_get_realm(context, in_creds->server);
     895
     896    try_realm = client_realm;
     897    ret = get_cred_kdc_capath_worker(context, flags, ccache, in_creds, try_realm,
     898                                     impersonate_principal, second_ticket, out_creds,
     899                                     ret_tgts);
     900
     901    if (ret == KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN) {
     902        try_realm = krb5_config_get_string(context, NULL, "capaths",
     903                                           client_realm, server_realm, NULL);
     904
     905        if (try_realm != NULL && strcmp(try_realm, client_realm)) {
     906            ret = get_cred_kdc_capath_worker(context, flags, ccache, in_creds,
     907                                             try_realm, impersonate_principal,
     908                                             second_ticket, out_creds, ret_tgts);
     909        }
     910    }
     911
     912    return ret;
    883913}
    884914
     
    898928    int loop = 0;
    899929    int ok_as_delegate = 1;
     930
     931    if (in_creds->server->name.name_string.len < 2 && !flags.b.canonicalize) {
     932        krb5_set_error_message(context, KRB5KDC_ERR_PATH_NOT_ACCEPTED,
     933                               N_("Name too short to do referals, skipping", ""));
     934        return KRB5KDC_ERR_PATH_NOT_ACCEPTED;
     935    }
    900936
    901937    memset(&tgt, 0, sizeof(tgt));
     
    953989
    954990        if (ret) {
    955             ret = get_cred_kdc_address (context, ccache, flags, NULL,
    956                                         &referral, &tgt, impersonate_principal,
    957                                         second_ticket, &ticket);
     991            ret = get_cred_kdc_address(context, ccache, flags, NULL,
     992                                       &referral, &tgt, impersonate_principal,
     993                                       second_ticket, &ticket);
    958994            if (ret)
    959995                goto out;
     
    9661002            break;
    9671003
    968         if (ticket.server->name.name_string.len != 2 &&
    969             strcmp(ticket.server->name.name_string.val[0], KRB5_TGS_NAME) != 0)
    970         {
     1004        if (!krb5_principal_is_krbtgt(context, ticket.server)) {
    9711005            krb5_set_error_message(context, KRB5KRB_AP_ERR_NOT_US,
    9721006                                   N_("Got back an non krbtgt "
    9731007                                      "ticket referrals", ""));
    974             krb5_free_cred_contents(context, &ticket);
    975             return KRB5KRB_AP_ERR_NOT_US;
     1008            ret = KRB5KRB_AP_ERR_NOT_US;
     1009            goto out;
    9761010        }
    9771011
     
    9951029                                       tgt.server->realm,
    9961030                                       referral_realm);
    997                 krb5_free_cred_contents(context, &ticket);
    998                 return KRB5_GET_IN_TKT_LOOP;
     1031                ret = KRB5_GET_IN_TKT_LOOP;
     1032                goto out;
    9991033            }
    10001034            tickets++;
     
    10121046
    10131047        ret = add_cred(context, &ticket, ret_tgts);
    1014         if (ret) {
    1015             krb5_free_cred_contents(context, &ticket);
     1048        if (ret)
    10161049            goto out;
    1017         }
    10181050
    10191051        /* try realm in the referral */
     
    10331065    krb5_free_principal(context, referral.server);
    10341066    krb5_free_cred_contents(context, &tgt);
     1067    krb5_free_cred_contents(context, &ticket);
    10351068    return ret;
    10361069}
     
    10531086{
    10541087    krb5_error_code ret;
     1088    krb5_deltat offset;
     1089
     1090    ret = krb5_cc_get_kdc_offset(context, ccache, &offset);
     1091    if (ret) {
     1092        context->kdc_sec_offset = offset;
     1093        context->kdc_usec_offset = 0;
     1094    }
    10551095
    10561096    ret = get_cred_kdc_referral(context,
     
    10751115
    10761116
    1077 krb5_error_code KRB5_LIB_FUNCTION
     1117KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10781118krb5_get_credentials_with_flags(krb5_context context,
    10791119                                krb5_flags options,
     
    10871127    krb5_creds *res_creds;
    10881128    int i;
     1129
     1130    if (in_creds->session.keytype) {
     1131        ret = krb5_enctype_valid(context, in_creds->session.keytype);
     1132        if (ret)
     1133            return ret;
     1134    }
    10891135
    10901136    *out_creds = NULL;
     
    11551201}
    11561202
    1157 krb5_error_code KRB5_LIB_FUNCTION
     1203KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11581204krb5_get_credentials(krb5_context context,
    11591205                     krb5_flags options,
     
    11761222
    11771223
    1178 krb5_error_code KRB5_LIB_FUNCTION
     1224KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11791225krb5_get_creds_opt_alloc(krb5_context context, krb5_get_creds_opt *opt)
    11801226{
     
    11881234}
    11891235
    1190 void KRB5_LIB_FUNCTION
     1236KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    11911237krb5_get_creds_opt_free(krb5_context context, krb5_get_creds_opt opt)
    11921238{
     
    12011247}
    12021248
    1203 void KRB5_LIB_FUNCTION
     1249KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    12041250krb5_get_creds_opt_set_options(krb5_context context,
    12051251                               krb5_get_creds_opt opt,
     
    12091255}
    12101256
    1211 void KRB5_LIB_FUNCTION
     1257KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    12121258krb5_get_creds_opt_add_options(krb5_context context,
    12131259                               krb5_get_creds_opt opt,
     
    12171263}
    12181264
    1219 void KRB5_LIB_FUNCTION
     1265KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    12201266krb5_get_creds_opt_set_enctype(krb5_context context,
    12211267                               krb5_get_creds_opt opt,
     
    12251271}
    12261272
    1227 krb5_error_code KRB5_LIB_FUNCTION
     1273KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12281274krb5_get_creds_opt_set_impersonate(krb5_context context,
    12291275                                   krb5_get_creds_opt opt,
     
    12351281}
    12361282
    1237 krb5_error_code KRB5_LIB_FUNCTION
     1283KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12381284krb5_get_creds_opt_set_ticket(krb5_context context,
    12391285                              krb5_get_creds_opt opt,
     
    12681314
    12691315
    1270 krb5_error_code KRB5_LIB_FUNCTION
     1316KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12711317krb5_get_creds(krb5_context context,
    12721318               krb5_get_creds_opt opt,
     
    12831329    int i;
    12841330
     1331    if (opt && opt->enctype) {
     1332        ret = krb5_enctype_valid(context, opt->enctype);
     1333        if (ret)
     1334            return ret;
     1335    }
     1336
    12851337    memset(&in_creds, 0, sizeof(in_creds));
    12861338    in_creds.server = rk_UNCONST(inprinc);
     
    12901342        return ret;
    12911343
    1292     options = opt->options;
     1344    if (opt)
     1345        options = opt->options;
     1346    else
     1347        options = 0;
    12931348    flags.i = 0;
    12941349
     
    13021357    }
    13031358
    1304     if (opt->enctype) {
     1359    if (opt && opt->enctype) {
    13051360        in_creds.session.keytype = opt->enctype;
    13061361        options |= KRB5_TC_MATCH_KEYTYPE;
     
    13131368    ret = krb5_cc_retrieve_cred(context,
    13141369                                ccache,
    1315                                 opt->enctype ? KRB5_TC_MATCH_KEYTYPE : 0,
     1370                                options & KRB5_TC_MATCH_KEYTYPE,
    13161371                                &in_creds, res_creds);
    13171372    /*
     
    13261381            *out_creds = res_creds;
    13271382            krb5_free_principal(context, in_creds.client);
    1328             return 0;
     1383            goto out;
    13291384        }
    13301385       
     
    13331388            *out_creds = res_creds;
    13341389            krb5_free_principal(context, in_creds.client);
    1335             return 0;
     1390            goto out;
    13361391        }
    13371392        if(options & KRB5_GC_CACHED)
     
    13411396        free(res_creds);
    13421397        krb5_free_principal(context, in_creds.client);
    1343         return ret;
     1398        goto out;
    13441399    }
    13451400    free(res_creds);
    13461401    if(options & KRB5_GC_CACHED) {
    13471402        krb5_free_principal(context, in_creds.client);
    1348         return not_found(context, in_creds.server, KRB5_CC_NOTFOUND);
     1403        ret = not_found(context, in_creds.server, KRB5_CC_NOTFOUND);
     1404        goto out;
    13491405    }
    13501406    if(options & KRB5_GC_USER_USER) {
     
    13751431    if(ret == 0 && (options & KRB5_GC_NO_STORE) == 0)
    13761432        krb5_cc_store_cred(context, ccache, *out_creds);
     1433
     1434 out:
     1435    _krb5_debug(context, 5, "krb5_get_creds: ret = %d", ret);
     1436
    13771437    return ret;
    13781438}
     
    13821442 */
    13831443
    1384 krb5_error_code KRB5_LIB_FUNCTION
     1444KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13851445krb5_get_renewed_creds(krb5_context context,
    13861446                       krb5_creds *creds,
  • trunk/server/source4/heimdal/lib/krb5/get_default_principal.c

    r414 r745  
    4949}
    5050
     51#ifndef _WIN32
     52
    5153/*
    5254 * Will only use operating-system dependant operation to get the
     
    9496}
    9597
    96 krb5_error_code KRB5_LIB_FUNCTION
     98#else  /* _WIN32 */
     99
     100#define SECURITY_WIN32
     101#include <security.h>
     102
     103krb5_error_code
     104_krb5_get_default_principal_local(krb5_context context,
     105                                  krb5_principal *princ)
     106{
     107    /* See if we can get the principal first.  We only expect this to
     108       work if logged into a domain. */
     109    {
     110        char username[1024];
     111        ULONG sz = sizeof(username);
     112
     113        if (GetUserNameEx(NameUserPrincipal, username, &sz)) {
     114            return krb5_parse_name_flags(context, username,
     115                                         KRB5_PRINCIPAL_PARSE_ENTERPRISE,
     116                                         princ);
     117        }
     118    }
     119
     120    /* Just get the Windows username.  This should pretty much always
     121       work. */
     122    {
     123        char username[1024];
     124        DWORD dsz = sizeof(username);
     125
     126        if (GetUserName(username, &dsz)) {
     127            return krb5_make_principal(context, princ, NULL, username, NULL);
     128        }
     129    }
     130
     131    /* Failing that, we look at the environment */
     132    {
     133        const char * username = get_env_user();
     134
     135        if (username == NULL) {
     136            krb5_set_error_string(context,
     137                                  "unable to figure out current principal");
     138            return ENOTTY;      /* Really? */
     139        }
     140
     141        return krb5_make_principal(context, princ, NULL, username, NULL);
     142    }
     143}
     144
     145#endif
     146
     147KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    97148krb5_get_default_principal (krb5_context context,
    98149                            krb5_principal *princ)
  • trunk/server/source4/heimdal/lib/krb5/get_default_realm.c

    r414 r745  
    3939 */
    4040
    41 krb5_error_code KRB5_LIB_FUNCTION
     41KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4242krb5_get_default_realms (krb5_context context,
    4343                         krb5_realm **realms)
     
    5858 */
    5959
    60 krb5_error_code KRB5_LIB_FUNCTION
     60KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6161krb5_get_default_realm(krb5_context context,
    6262                       krb5_realm *realm)
  • trunk/server/source4/heimdal/lib/krb5/get_for_creds.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    3636static krb5_error_code
     
    101101 */
    102102
    103 krb5_error_code KRB5_LIB_FUNCTION
     103KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    104104krb5_fwd_tgt_creds (krb5_context        context,
    105105                    krb5_auth_context   auth_context,
     
    138138    creds.client = client;
    139139
    140     ret = krb5_build_principal(context,
    141                                &creds.server,
    142                                strlen(client_realm),
    143                                client_realm,
    144                                KRB5_TGS_NAME,
    145                                client_realm,
    146                                NULL);
     140    ret = krb5_make_principal(context,
     141                              &creds.server,
     142                              client_realm,
     143                              KRB5_TGS_NAME,
     144                              client_realm,
     145                              NULL);
    147146    if (ret)
    148147        return ret;
     
    185184 */
    186185
    187 krb5_error_code KRB5_LIB_FUNCTION
     186KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    188187krb5_get_forwarded_creds (krb5_context      context,
    189188                          krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/get_host_realm.c

    r414 r745  
    159159 */
    160160
    161 krb5_error_code KRB5_LIB_FUNCTION
     161KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    162162_krb5_get_host_realm_int (krb5_context context,
    163163                          const char *host,
     
    216216 */
    217217
    218 krb5_error_code KRB5_LIB_FUNCTION
     218KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    219219krb5_get_host_realm(krb5_context context,
    220220                    const char *targethost,
  • trunk/server/source4/heimdal/lib/krb5/get_in_tkt.c

    r414 r745  
    362362}
    363363
    364 krb5_error_code KRB5_LIB_FUNCTION
     364KRB5_DEPRECATED
     365KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    365366krb5_get_in_cred(krb5_context context,
    366367                 krb5_flags options,
     
    375376                 krb5_creds *creds,
    376377                 krb5_kdc_rep *ret_as_reply)
    377     KRB5_DEPRECATED
    378378{
    379379    krb5_error_code ret;
     
    499499       
    500500    {
    501         unsigned flags = 0;
     501        unsigned flags = EXTRACT_TICKET_TIMESYNC;
    502502        if (opts.request_anonymous)
    503503            flags |= EXTRACT_TICKET_ALLOW_SERVER_MISMATCH;
     
    527527}
    528528
    529 krb5_error_code KRB5_LIB_FUNCTION
     529KRB5_DEPRECATED
     530KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    530531krb5_get_in_tkt(krb5_context context,
    531532                krb5_flags options,
     
    540541                krb5_ccache ccache,
    541542                krb5_kdc_rep *ret_as_reply)
    542     KRB5_DEPRECATED
    543543{
    544544    krb5_error_code ret;
  • trunk/server/source4/heimdal/lib/krb5/get_port.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 int KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    3737krb5_getportbyname (krb5_context context,
    3838                    const char *service,
  • trunk/server/source4/heimdal/lib/krb5/init_creds.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    5153 */
    5254
    53 krb5_error_code KRB5_LIB_FUNCTION
     55KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5456krb5_get_init_creds_opt_alloc(krb5_context context,
    5557                              krb5_get_init_creds_opt **opt)
     
    8385 */
    8486
    85 void KRB5_LIB_FUNCTION
     87KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8688krb5_get_init_creds_opt_free(krb5_context context,
    8789                             krb5_get_init_creds_opt *opt)
     
    125127static krb5_boolean
    126128get_config_bool (krb5_context context,
     129                 krb5_boolean def_value,
    127130                 const char *realm,
    128131                 const char *name)
    129132{
    130     return krb5_config_get_bool (context,
    131                                  NULL,
    132                                  "realms",
    133                                  realm,
    134                                  name,
    135                                  NULL)
    136         || krb5_config_get_bool (context,
    137                                  NULL,
    138                                  "libdefaults",
    139                                  name,
    140                                  NULL);
     133    krb5_boolean b;
     134
     135    b = krb5_config_get_bool_default(context, NULL, def_value,
     136                                     "realms", realm, name, NULL);
     137    if (b != def_value)
     138        return b;
     139    b = krb5_config_get_bool_default (context, NULL, def_value,
     140                                      "libdefaults", name, NULL);
     141    if (b != def_value)
     142        return b;
     143    return def_value;
    141144}
    142145
     
    148151 */
    149152
    150 void KRB5_LIB_FUNCTION
     153KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    151154krb5_get_init_creds_opt_set_default_flags(krb5_context context,
    152155                                          const char *appname,
     
    157160    time_t t;
    158161
    159     b = get_config_bool (context, realm, "forwardable");
     162    b = get_config_bool (context, KRB5_FORWARDABLE_DEFAULT,
     163                         realm, "forwardable");
    160164    krb5_appdefault_boolean(context, appname, realm, "forwardable", b, &b);
    161165    krb5_get_init_creds_opt_set_forwardable(opt, b);
    162166
    163     b = get_config_bool (context, realm, "proxiable");
     167    b = get_config_bool (context, FALSE, realm, "proxiable");
    164168    krb5_appdefault_boolean(context, appname, realm, "proxiable", b, &b);
    165169    krb5_get_init_creds_opt_set_proxiable (opt, b);
     
    198202
    199203
    200 void KRB5_LIB_FUNCTION
     204KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    201205krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt *opt,
    202206                                     krb5_deltat tkt_life)
     
    206210}
    207211
    208 void KRB5_LIB_FUNCTION
     212KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    209213krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt *opt,
    210214                                       krb5_deltat renew_life)
     
    214218}
    215219
    216 void KRB5_LIB_FUNCTION
     220KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    217221krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt *opt,
    218222                                        int forwardable)
     
    222226}
    223227
    224 void KRB5_LIB_FUNCTION
     228KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    225229krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt *opt,
    226230                                      int proxiable)
     
    230234}
    231235
    232 void KRB5_LIB_FUNCTION
     236KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    233237krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt *opt,
    234238                                       krb5_enctype *etype_list,
     
    240244}
    241245
    242 void KRB5_LIB_FUNCTION
     246KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    243247krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt *opt,
    244248                                         krb5_addresses *addresses)
     
    248252}
    249253
    250 void KRB5_LIB_FUNCTION
     254KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    251255krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt *opt,
    252256                                         krb5_preauthtype *preauth_list,
     
    258262}
    259263
    260 void KRB5_LIB_FUNCTION
     264KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    261265krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt *opt,
    262266                                 krb5_data *salt)
     
    266270}
    267271
    268 void KRB5_LIB_FUNCTION
     272KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    269273krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt *opt,
    270274                                      int anonymous)
     
    287291}
    288292
    289 krb5_error_code KRB5_LIB_FUNCTION
     293KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    290294krb5_get_init_creds_opt_set_pa_password(krb5_context context,
    291295                                        krb5_get_init_creds_opt *opt,
     
    302306}
    303307
    304 krb5_error_code KRB5_LIB_FUNCTION
     308KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    305309krb5_get_init_creds_opt_set_pac_request(krb5_context context,
    306310                                        krb5_get_init_creds_opt *opt,
     
    317321}
    318322
    319 krb5_error_code KRB5_LIB_FUNCTION
     323KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    320324krb5_get_init_creds_opt_set_addressless(krb5_context context,
    321325                                        krb5_get_init_creds_opt *opt,
     
    333337}
    334338
    335 krb5_error_code KRB5_LIB_FUNCTION
     339KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    336340krb5_get_init_creds_opt_set_canonicalize(krb5_context context,
    337341                                         krb5_get_init_creds_opt *opt,
     
    349353}
    350354
    351 krb5_error_code KRB5_LIB_FUNCTION
     355KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    352356krb5_get_init_creds_opt_set_win2k(krb5_context context,
    353357                                  krb5_get_init_creds_opt *opt,
     
    358362    if (ret)
    359363        return ret;
    360     if (req)
     364    if (req) {
    361365        opt->opt_private->flags |= KRB5_INIT_CREDS_NO_C_CANON_CHECK;
    362     else
     366        opt->opt_private->flags |= KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK;
     367    } else {
    363368        opt->opt_private->flags &= ~KRB5_INIT_CREDS_NO_C_CANON_CHECK;
    364     return 0;
    365 }
    366 
    367 
    368 krb5_error_code KRB5_LIB_FUNCTION
     369        opt->opt_private->flags &= ~KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK;
     370    }
     371    return 0;
     372}
     373
     374
     375KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    369376krb5_get_init_creds_opt_set_process_last_req(krb5_context context,
    370377                                             krb5_get_init_creds_opt *opt,
     
    386393#ifndef HEIMDAL_SMALLER
    387394
    388 void KRB5_LIB_FUNCTION
     395/**
     396 * Deprecated: use krb5_get_init_creds_opt_alloc().
     397 *
     398 * The reason krb5_get_init_creds_opt_init() is deprecated is that
     399 * krb5_get_init_creds_opt is a static structure and for ABI reason it
     400 * can't grow, ie can't add new functionality.
     401 *
     402 * @ingroup krb5_deprecated
     403 */
     404
     405KRB5_DEPRECATED
     406KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    389407krb5_get_init_creds_opt_init(krb5_get_init_creds_opt *opt)
    390     KRB5_DEPRECATED
    391408{
    392409    memset (opt, 0, sizeof(*opt));
     
    400417 */
    401418
    402 krb5_error_code KRB5_LIB_FUNCTION
     419KRB5_DEPRECATED
     420KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    403421krb5_get_init_creds_opt_get_error(krb5_context context,
    404422                                  krb5_get_init_creds_opt *opt,
    405423                                  KRB_ERROR **error)
    406     KRB5_DEPRECATED
    407424{
    408425    *error = calloc(1, sizeof(**error));
  • trunk/server/source4/heimdal/lib/krb5/init_creds_pw.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    6062    int ic_flags;
    6163
     64    int used_pa_types;
     65#define  USED_PKINIT    1
     66#define  USED_PKINIT_W2K        2
     67#define  USED_ENC_TS_GUESS      4
     68#define  USED_ENC_TS_INFO       8
     69
    6270    METHOD_DATA md;
    6371    KRB_ERROR error;
     
    6876    void *prompter_data;
    6977
     78    struct pa_info_data *ppaid;
     79
    7080} krb5_get_init_creds_ctx;
    7181
    72 static krb5_error_code
     82
     83struct pa_info_data {
     84    krb5_enctype etype;
     85    krb5_salt salt;
     86    krb5_data *s2kparams;
     87};
     88
     89static void
     90free_paid(krb5_context context, struct pa_info_data *ppaid)
     91{
     92    krb5_free_salt(context, ppaid->salt);
     93    if (ppaid->s2kparams)
     94        krb5_free_data(context, ppaid->s2kparams);
     95}
     96
     97static krb5_error_code KRB5_CALLCONV
    7398default_s2k_func(krb5_context context, krb5_enctype type,
    7499                 krb5_const_pointer keyseed,
     
    79104    krb5_data password;
    80105    krb5_data opaque;
     106
     107    _krb5_debug(context, 5, "krb5_get_init_creds: using default_s2k_func");
    81108
    82109    password.data = rk_UNCONST(keyseed);
     
    110137    if (ctx->keytab_data)
    111138        free(ctx->keytab_data);
     139    if (ctx->password) {
     140        memset(ctx->password, 0, strlen(ctx->password));
     141        free(ctx->password);
     142    }
    112143    krb5_data_free(&ctx->req_buffer);
    113144    krb5_free_cred_contents(context, &ctx->cred);
     
    117148    free_KRB_ERROR(&ctx->error);
    118149    free_AS_REQ(&ctx->as_req);
     150    if (ctx->ppaid) {
     151        free_paid(context, ctx->ppaid);
     152        free(ctx->ppaid);
     153    }
    119154    memset(ctx, 0, sizeof(*ctx));
    120155}
     
    200235                   time_t now)
    201236{
    202     char *p;
    203 
    204     asprintf (&p, "%s%s", str, ctime(&now));
    205     (*prompter) (context, data, NULL, p, 0, NULL);
    206     free (p);
     237    char *p = NULL;
     238
     239    if (asprintf(&p, "%s%s", str, ctime(&now)) < 0 || p == NULL)
     240        return;
     241    (*prompter)(context, data, NULL, p, 0, NULL);
     242    free(p);
    207243}
    208244
     
    399435    }
    400436    if (options->flags & KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST) {
     437        if (ctx->etypes)
     438            free(ctx->etypes);
     439
    401440        etypes = malloc((options->etype_list_length + 1)
    402441                        * sizeof(krb5_enctype));
     
    525564    if (ret)
    526565        goto out;
    527     asprintf (&p, "%s: %.*s\n",
    528               result_code ? "Error" : "Success",
    529               (int)result_string.length,
    530               result_string.length > 0 ? (char*)result_string.data : "");
     566    if (asprintf(&p, "%s: %.*s\n",
     567                 result_code ? "Error" : "Success",
     568                 (int)result_string.length,
     569                 result_string.length > 0 ? (char*)result_string.data : "") < 0)
     570    {
     571        ret = ENOMEM;
     572        goto out;
     573    }
    531574
    532575    /* return the result */
     
    553596
    554597
    555 krb5_error_code KRB5_LIB_FUNCTION
     598KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    556599krb5_keyblock_key_proc (krb5_context context,
    557600                        krb5_keytype type,
     
    673716    memset(a, 0, sizeof(*a));
    674717    return ret;
    675 }
    676 
    677 struct pa_info_data {
    678     krb5_enctype etype;
    679     krb5_salt salt;
    680     krb5_data *s2kparams;
    681 };
    682 
    683 static void
    684 free_paid(krb5_context context, struct pa_info_data *ppaid)
    685 {
    686     krb5_free_salt(context, ppaid->salt);
    687     if (ppaid->s2kparams)
    688         krb5_free_data(context, ppaid->s2kparams);
    689718}
    690719
     
    9801009        krb5_keyblock *key;
    9811010
     1011        _krb5_debug(context, 5, "krb5_get_init_creds: using ENC-TS with enctype %d", enctypes[i]);
     1012
    9821013        ret = (*keyproc)(context, enctypes[i], keyseed,
    9831014                         *salt, s2kparams, &key);
     
    10131044        krb5_salt salt;
    10141045
     1046        _krb5_debug(context, 5, "krb5_get_init_creds: pa-info not found, guessing salt");
     1047
    10151048        /* make a v5 salted pa-data */
    10161049        add_enc_ts_padata(context, md, client,
     
    10511084                     const AS_REQ *a,
    10521085                     const krb5_principal client,
     1086                     int win2k,
    10531087                     krb5_get_init_creds_ctx *ctx,
    10541088                     METHOD_DATA *md)
     
    10581092#ifdef PKINIT
    10591093    return _krb5_pk_mk_padata(context,
    1060                              ctx->pk_init_ctx,
    1061                              &a->req_body,
    1062                              ctx->pk_nonce,
    1063                              md);
     1094                              ctx->pk_init_ctx,
     1095                              ctx->ic_flags,
     1096                              win2k,
     1097                              &a->req_body,
     1098                              ctx->pk_nonce,
     1099                              md);
    10641100#else
    10651101    krb5_set_error_message(context, EINVAL,
     
    11271163    (*out_md)->val = NULL;
    11281164
     1165    if (_krb5_have_debug(context, 5)) {
     1166        unsigned i;
     1167        _krb5_debug(context, 5, "KDC send %d patypes", in_md->len);
     1168        for (i = 0; i < in_md->len; i++)
     1169            _krb5_debug(context, 5, "KDC send PA-DATA type: %d", in_md->val[i].padata_type);
     1170    }
     1171
    11291172    /*
    11301173     * Make sure we don't sent both ENC-TS and PK-INIT pa data, no
     
    11341177    if (ctx->pk_init_ctx) {
    11351178
    1136         ret = pa_data_to_md_pkinit(context, a, creds->client, ctx, *out_md);
     1179        _krb5_debug(context, 5, "krb5_get_init_creds: "
     1180                    "prepareing PKINIT padata (%s)",
     1181                    (ctx->used_pa_types & USED_PKINIT_W2K) ? "win2k" : "ietf");
     1182       
     1183        if (ctx->used_pa_types & USED_PKINIT_W2K) {
     1184            krb5_set_error_message(context, KRB5_GET_IN_TKT_LOOP,
     1185                                   "Already tried pkinit, looping");
     1186            return KRB5_GET_IN_TKT_LOOP;
     1187        }
     1188
     1189        ret = pa_data_to_md_pkinit(context, a, creds->client,
     1190                                   (ctx->used_pa_types & USED_PKINIT),
     1191                                   ctx, *out_md);
    11371192        if (ret)
    11381193            return ret;
    11391194
     1195        if (ctx->used_pa_types & USED_PKINIT)
     1196            ctx->used_pa_types |= USED_PKINIT_W2K;
     1197        else
     1198            ctx->used_pa_types |= USED_PKINIT;
     1199
    11401200    } else if (in_md->len != 0) {
    1141         struct pa_info_data paid, *ppaid;
    1142 
    1143         memset(&paid, 0, sizeof(paid));
    1144 
    1145         paid.etype = ENCTYPE_NULL;
    1146         ppaid = process_pa_info(context, creds->client, a, &paid, in_md);
     1201        struct pa_info_data *paid, *ppaid;
     1202        unsigned flag;
     1203
     1204        paid = calloc(1, sizeof(*paid));
     1205
     1206        paid->etype = ENCTYPE_NULL;
     1207        ppaid = process_pa_info(context, creds->client, a, paid, in_md);
     1208
     1209        if (ppaid)
     1210            flag = USED_ENC_TS_INFO;
     1211        else
     1212            flag = USED_ENC_TS_GUESS;
     1213
     1214        if (ctx->used_pa_types & flag) {
     1215            if (ppaid)
     1216                free_paid(context, ppaid);
     1217            krb5_set_error_message(context, KRB5_GET_IN_TKT_LOOP,
     1218                                   "Already tried ENC-TS-%s, looping",
     1219                                   flag == USED_ENC_TS_INFO ? "info" : "guess");
     1220            return KRB5_GET_IN_TKT_LOOP;
     1221        }
    11471222
    11481223        pa_data_to_md_ts_enc(context, a, creds->client, ctx, ppaid, *out_md);
    1149         if (ppaid)
    1150             free_paid(context, ppaid);
     1224
     1225        ctx->used_pa_types |= flag;
     1226
     1227        if (ppaid) {
     1228            if (ctx->ppaid) {
     1229                free_paid(context, ctx->ppaid);
     1230                free(ctx->ppaid);
     1231            }
     1232            ctx->ppaid = ppaid;
     1233        } else
     1234            free(paid);
    11511235    }
    11521236
     
    11841268                                rep->padata);
    11851269    }
     1270    if (ppaid == NULL)
     1271        ppaid = ctx->ppaid;
    11861272    if (ppaid == NULL) {
    11871273        ret = krb5_get_pw_salt (context, creds->client, &paid.salt);
     
    11901276        paid.etype = etype;
    11911277        paid.s2kparams = NULL;
     1278        ppaid = &paid;
    11921279    }
    11931280
     
    12091296    if (pa && ctx->pk_init_ctx) {
    12101297#ifdef PKINIT
     1298        _krb5_debug(context, 5, "krb5_get_init_creds: using PKINIT");
     1299
    12111300        ret = _krb5_pk_rd_pa_reply(context,
    12121301                                   a->req_body.realm,
     
    12221311        krb5_set_error_message(context, ret, N_("no support for PKINIT compiled in", ""));
    12231312#endif
    1224     } else if (ctx->keyseed)
     1313    } else if (ctx->keyseed) {
     1314        _krb5_debug(context, 5, "krb5_get_init_creds: using keyproc");
    12251315        ret = pa_data_to_key_plain(context, creds->client, ctx,
    1226                                    paid.salt, paid.s2kparams, etype, key);
    1227     else {
     1316                                   ppaid->salt, ppaid->s2kparams, etype, key);
     1317    } else {
    12281318        ret = EINVAL;
    12291319        krb5_set_error_message(context, ret, N_("No usable pa data type", ""));
     
    12521342 */
    12531343
    1254 krb5_error_code KRB5_LIB_FUNCTION
     1344KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12551345krb5_init_creds_init(krb5_context context,
    12561346                     krb5_principal client,
     
    13061396 */
    13071397
    1308 krb5_error_code KRB5_LIB_FUNCTION
     1398KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13091399krb5_init_creds_set_service(krb5_context context,
    13101400                            krb5_init_creds_context ctx,
     
    13291419            return ret;
    13301420    }
     1421
     1422    /*
     1423     * This is for Windows RODC that are picky about what name type
     1424     * the server principal have, and the really strange part is that
     1425     * they are picky about the AS-REQ name type and not the TGS-REQ
     1426     * later. Oh well.
     1427     */
     1428
     1429    if (krb5_principal_is_krbtgt(context, principal))
     1430        krb5_principal_set_type(context, principal, KRB5_NT_SRV_INST);
     1431
    13311432    krb5_free_principal(context, ctx->cred.server);
    13321433    ctx->cred.server = principal;
     
    13461447 */
    13471448
    1348 krb5_error_code KRB5_LIB_FUNCTION
     1449KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13491450krb5_init_creds_set_password(krb5_context context,
    13501451                             krb5_init_creds_context ctx,
    13511452                             const char *password)
    13521453{
    1353     if (ctx->password)
     1454    if (ctx->password) {
    13541455        memset(ctx->password, 0, strlen(ctx->password));
     1456        free(ctx->password);
     1457    }
    13551458    if (password) {
    13561459        ctx->password = strdup(password);
     
    13681471}
    13691472
    1370 static krb5_error_code
     1473static krb5_error_code KRB5_CALLCONV
    13711474keytab_key_proc(krb5_context context, krb5_enctype enctype,
    13721475                krb5_const_pointer keyseed,
     
    14121515 */
    14131516
    1414 krb5_error_code KRB5_LIB_FUNCTION
     1517KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14151518krb5_init_creds_set_keytab(krb5_context context,
    14161519                           krb5_init_creds_context ctx,
     
    14181521{
    14191522    krb5_keytab_key_proc_args *a;
     1523    krb5_keytab_entry entry;
     1524    krb5_kt_cursor cursor;
     1525    krb5_enctype *etypes = NULL;
     1526    krb5_error_code ret;
     1527    size_t netypes = 0;
     1528    int kvno = 0;
    14201529   
    14211530    a = malloc(sizeof(*a));
    14221531    if (a == NULL) {
    1423         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
     1532        krb5_set_error_message(context, ENOMEM,
     1533                               N_("malloc: out of memory", ""));
    14241534        return ENOMEM;
    14251535    }
     
    14321542    ctx->keyproc = keytab_key_proc;
    14331543
     1544    /*
     1545     * We need to the KDC what enctypes we support for this keytab,
     1546     * esp if the keytab is really a password based entry, then the
     1547     * KDC might have more enctypes in the database then what we have
     1548     * in the keytab.
     1549     */
     1550
     1551    ret = krb5_kt_start_seq_get(context, keytab, &cursor);
     1552    if(ret)
     1553        goto out;
     1554
     1555    while(krb5_kt_next_entry(context, keytab, &entry, &cursor) == 0){
     1556        void *ptr;
     1557
     1558        if (!krb5_principal_compare(context, entry.principal, ctx->cred.client))
     1559            goto next;
     1560
     1561        /* check if we ahve this kvno already */
     1562        if (entry.vno > kvno) {
     1563            /* remove old list of etype */
     1564            if (etypes)
     1565                free(etypes);
     1566            etypes = NULL;
     1567            netypes = 0;
     1568            kvno = entry.vno;
     1569        } else if (entry.vno != kvno)
     1570            goto next;
     1571               
     1572        /* check if enctype is supported */
     1573        if (krb5_enctype_valid(context, entry.keyblock.keytype) != 0)
     1574            goto next;
     1575
     1576        /* add enctype to supported list */
     1577        ptr = realloc(etypes, sizeof(etypes[0]) * (netypes + 2));
     1578        if (ptr == NULL)
     1579            goto next;
     1580
     1581        etypes = ptr;
     1582        etypes[netypes] = entry.keyblock.keytype;
     1583        etypes[netypes + 1] = ETYPE_NULL;
     1584        netypes++;
     1585    next:
     1586        krb5_kt_free_entry(context, &entry);
     1587    }
     1588    krb5_kt_end_seq_get(context, keytab, &cursor);
     1589
     1590    if (etypes) {
     1591        if (ctx->etypes)
     1592            free(ctx->etypes);
     1593        ctx->etypes = etypes;
     1594    }
     1595
     1596 out:
    14341597    return 0;
    14351598}
    14361599
    1437 static krb5_error_code
     1600static krb5_error_code KRB5_CALLCONV
    14381601keyblock_key_proc(krb5_context context, krb5_enctype enctype,
    14391602                  krb5_const_pointer keyseed,
     
    14441607}
    14451608
    1446 krb5_error_code KRB5_LIB_FUNCTION
     1609KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14471610krb5_init_creds_set_keyblock(krb5_context context,
    14481611                             krb5_init_creds_context ctx,
     
    14671630 * @param out reply to KDC.
    14681631 * @param hostinfo KDC address info, first round it can be NULL.
    1469  * @param flags status of the round, if 1 is set, continue one more round.
     1632 * @param flags status of the round, if
     1633 *        KRB5_INIT_CREDS_STEP_FLAG_CONTINUE is set, continue one more round.
    14701634 *
    14711635 * @return 0 for success, or an Kerberos 5 error code, see
     
    14751639 */
    14761640
    1477 krb5_error_code KRB5_LIB_FUNCTION
     1641KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    14781642krb5_init_creds_step(krb5_context context,
    14791643                     krb5_init_creds_context ctx,
     
    15081672    ctx->pa_counter++;
    15091673
     1674    _krb5_debug(context, 5, "krb5_get_init_creds: loop %d", ctx->pa_counter);
     1675
    15101676    /* Lets process the input packet */
    15111677    if (in && in->length) {
     
    15141680        memset(&rep, 0, sizeof(rep));
    15151681
     1682        _krb5_debug(context, 5, "krb5_get_init_creds: processing input");
     1683
    15161684        ret = decode_AS_REP(in->data, in->length, &rep.kdc_rep, &size);
    15171685        if (ret == 0) {
    15181686            krb5_keyblock *key = NULL;
    1519             unsigned eflags = EXTRACT_TICKET_AS_REQ;
     1687            unsigned eflags = EXTRACT_TICKET_AS_REQ | EXTRACT_TICKET_TIMESYNC;
    15201688
    15211689            if (ctx->flags.canonicalize) {
     
    15321700                goto out;
    15331701            }
     1702
     1703            _krb5_debug(context, 5, "krb5_get_init_creds: extracting ticket");
    15341704
    15351705            ret = _krb5_extract_ticket(context,
     
    15591729            /* let's try to parse it as a KRB-ERROR */
    15601730
     1731            _krb5_debug(context, 5, "krb5_get_init_creds: got an error");
     1732
    15611733            free_KRB_ERROR(&ctx->error);
    15621734
     
    15641736            if(ret && in->length && ((char*)in->data)[0] == 4)
    15651737                ret = KRB5KRB_AP_ERR_V4_REPLY;
    1566             if (ret)
     1738            if (ret) {
     1739                _krb5_debug(context, 5, "krb5_get_init_creds: failed to read error");
    15671740                goto out;
     1741            }
    15681742
    15691743            ret = krb5_error_from_rd_error(context, &ctx->error, &ctx->cred);
     1744
     1745            _krb5_debug(context, 5, "krb5_get_init_creds: KRB-ERROR %d", ret);
    15701746
    15711747            /*
     
    16001776                if (context->kdc_sec_offset)
    16011777                    ret = 0;
     1778
     1779                _krb5_debug(context, 10, "init_creds: err skew updateing kdc offset to %d",
     1780                            context->kdc_sec_offset);
     1781
     1782                ctx->used_pa_types = 0;
     1783
    16021784            } else if (ret == KRB5_KDC_ERR_WRONG_REALM && ctx->flags.canonicalize) {
    16031785                /* client referal to a new realm */
     1786
    16041787                if (ctx->error.crealm == NULL) {
    16051788                    krb5_set_error_message(context, ret,
     
    16071790                    goto out;
    16081791                }
     1792                _krb5_debug(context, 5,
     1793                            "krb5_get_init_creds: got referal to realm %s",
     1794                            *ctx->error.crealm);
     1795
    16091796                ret = krb5_principal_set_realm(context,
    16101797                                               ctx->cred.client,
    16111798                                               *ctx->error.crealm);
     1799
     1800                ctx->used_pa_types = 0;
    16121801            }
    16131802            if (ret)
     
    16451834    out->length = ctx->req_buffer.length;
    16461835
    1647     *flags = 1;
     1836    *flags = KRB5_INIT_CREDS_STEP_FLAG_CONTINUE;
    16481837
    16491838    return 0;
     
    16631852 */
    16641853
    1665 krb5_error_code KRB5_LIB_FUNCTION
     1854KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    16661855krb5_init_creds_get_creds(krb5_context context,
    16671856                          krb5_init_creds_context ctx,
     
    16791868 */
    16801869
    1681 krb5_error_code KRB5_LIB_FUNCTION
     1870KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    16821871krb5_init_creds_get_error(krb5_context context,
    16831872                          krb5_init_creds_context ctx,
     
    17021891 */
    17031892
    1704 void KRB5_LIB_FUNCTION
     1893KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    17051894krb5_init_creds_free(krb5_context context,
    17061895                     krb5_init_creds_context ctx)
     
    17191908 */
    17201909
    1721 krb5_error_code KRB5_LIB_FUNCTION
     1910KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    17221911krb5_init_creds_get(krb5_context context, krb5_init_creds_context ctx)
    17231912{
     
    17671956
    17681957
    1769 krb5_error_code KRB5_LIB_FUNCTION
     1958KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    17701959krb5_get_init_creds_password(krb5_context context,
    17711960                             krb5_creds *creds,
     
    18312020
    18322021    if (ret == KRB5KDC_ERR_KEY_EXPIRED && chpw == 0) {
    1833         char buf[1024];
     2022        char buf2[1024];
    18342023
    18352024        /* try to avoid recursion */
     
    18442033                               client,
    18452034                               ctx->password,
    1846                                buf,
     2035                               buf2,
    18472036                               sizeof(buf),
    18482037                               prompter,
     
    18732062 */
    18742063
    1875 krb5_error_code KRB5_LIB_FUNCTION
     2064KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    18762065krb5_get_init_creds_keyblock(krb5_context context,
    18772066                             krb5_creds *creds,
     
    19202109 */
    19212110
    1922 krb5_error_code KRB5_LIB_FUNCTION
     2111KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    19232112krb5_get_init_creds_keytab(krb5_context context,
    19242113                           krb5_creds *creds,
  • trunk/server/source4/heimdal/lib/krb5/kcm.c

    r414 r745  
    22 * Copyright (c) 2005, PADL Software Pty Ltd.
    33 * All rights reserved.
     4 *
     5 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    46 *
    57 * Redistribution and use in source and binary forms, with or without
     
    3840 */
    3941
    40 #ifdef HAVE_SYS_UN_H
    41 #include <sys/un.h>
    42 #endif
    43 
    4442#include "kcm.h"
     43#include <heim-ipc.h>
     44
     45static krb5_error_code
     46kcm_set_kdc_offset(krb5_context, krb5_ccache, krb5_deltat);
     47
     48static const char *kcm_ipc_name = "ANY:org.h5l.kcm";
    4549
    4650typedef struct krb5_kcmcache {
    4751    char *name;
    48     struct sockaddr_un path;
    49     char *door_path;
    5052} krb5_kcmcache;
    5153
     
    6163#define KCMCURSOR(C)    ((krb5_kcm_cursor)(C))
    6264
    63 #ifdef HAVE_DOOR_CREATE
    64 
    65 static krb5_error_code
    66 try_door(krb5_context context,
    67          krb5_kcmcache *k,
    68          krb5_data *request_data,
    69          krb5_data *response_data)
    70 {
    71     door_arg_t arg;
    72     int fd;
    73     int ret;
    74 
    75     memset(&arg, 0, sizeof(arg));
    76        
    77     fd = open(k->door_path, O_RDWR);
    78     if (fd < 0)
    79         return KRB5_CC_IO;
    80     rk_cloexec(fd);
    81 
    82     arg.data_ptr = request_data->data;
    83     arg.data_size = request_data->length;
    84     arg.desc_ptr = NULL;
    85     arg.desc_num = 0;
    86     arg.rbuf = NULL;
    87     arg.rsize = 0;
    88 
    89     ret = door_call(fd, &arg);
    90     close(fd);
    91     if (ret != 0)
    92         return KRB5_CC_IO;
    93 
    94     ret = krb5_data_copy(response_data, arg.rbuf, arg.rsize);
    95     munmap(arg.rbuf, arg.rsize);
    96     if (ret)
    97         return ret;
    98 
    99     return 0;
    100 }
    101 #endif /* HAVE_DOOR_CREATE */
    102 
    103 static krb5_error_code
    104 try_unix_socket(krb5_context context,
    105                 krb5_kcmcache *k,
    106                 krb5_data *request_data,
    107                 krb5_data *response_data)
    108 {
    109     krb5_error_code ret;
    110     int fd;
    111 
    112     fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
    113     if (fd < 0)
    114         return KRB5_CC_IO;
    115     rk_cloexec(fd);
    116 
    117     if (connect(fd, rk_UNCONST(&k->path), sizeof(k->path)) != 0) {
    118         close(fd);
    119         return KRB5_CC_IO;
    120     }
    121 
    122     ret = _krb5_send_and_recv_tcp(fd, context->kdc_timeout,
    123                                   request_data, response_data);
    124     close(fd);
    125     return ret;
    126 }
     65static HEIMDAL_MUTEX kcm_mutex = HEIMDAL_MUTEX_INITIALIZER;
     66static heim_ipc kcm_ipc = NULL;
    12767
    12868static krb5_error_code
    12969kcm_send_request(krb5_context context,
    130                  krb5_kcmcache *k,
    13170                 krb5_storage *request,
    13271                 krb5_data *response_data)
    13372{
    134     krb5_error_code ret;
     73    krb5_error_code ret = 0;
    13574    krb5_data request_data;
    136     int i;
    137 
    138     response_data->data = NULL;
    139     response_data->length = 0;
     75
     76    HEIMDAL_MUTEX_lock(&kcm_mutex);
     77    if (kcm_ipc == NULL)
     78        ret = heim_ipc_init_context(kcm_ipc_name, &kcm_ipc);
     79    HEIMDAL_MUTEX_unlock(&kcm_mutex);
     80    if (ret)
     81        return KRB5_CC_NOSUPP;
    14082
    14183    ret = krb5_storage_to_data(request, &request_data);
     
    14587    }
    14688
    147     ret = KRB5_CC_NOSUPP;
    148 
    149     for (i = 0; i < context->max_retries; i++) {
    150 #ifdef HAVE_DOOR_CREATE
    151         ret = try_door(context, k, &request_data, response_data);
    152         if (ret == 0 && response_data->length != 0)
    153             break;
    154 #endif
    155         ret = try_unix_socket(context, k, &request_data, response_data);
    156         if (ret == 0 && response_data->length != 0)
    157             break;
    158     }
    159 
     89    ret = heim_ipc_call(kcm_ipc, &request_data, response_data, NULL);
    16090    krb5_data_free(&request_data);
    16191
     
    16898}
    16999
    170 static krb5_error_code
    171 kcm_storage_request(krb5_context context,
    172                     kcm_operation opcode,
    173                     krb5_storage **storage_p)
     100KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     101krb5_kcm_storage_request(krb5_context context,
     102                         uint16_t opcode,
     103                        krb5_storage **storage_p)
    174104{
    175105    krb5_storage *sp;
     
    210140{
    211141    krb5_kcmcache *k;
    212     const char *path;
    213142
    214143    k = malloc(sizeof(*k));
     
    229158    } else
    230159        k->name = NULL;
    231 
    232     path = krb5_config_get_string_default(context, NULL,
    233                                           _PATH_KCM_SOCKET,
    234                                           "libdefaults",
    235                                           "kcm_socket",
    236                                           NULL);
    237 
    238     k->path.sun_family = AF_UNIX;
    239     strlcpy(k->path.sun_path, path, sizeof(k->path.sun_path));
    240 
    241     path = krb5_config_get_string_default(context, NULL,
    242                                           _PATH_KCM_DOOR,
    243                                           "libdefaults",
    244                                           "kcm_door",
    245                                           NULL);
    246     k->door_path = strdup(path);
    247 
     160   
    248161    (*id)->data.data = k;
    249162    (*id)->data.length = sizeof(*k);
     
    252165}
    253166
    254 static krb5_error_code
    255 kcm_call(krb5_context context,
    256          krb5_kcmcache *k,
    257          krb5_storage *request,
    258          krb5_storage **response_p,
    259          krb5_data *response_data_p)
     167KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     168krb5_kcm_call(krb5_context context,
     169              krb5_storage *request,
     170              krb5_storage **response_p,
     171              krb5_data *response_data_p)
    260172{
    261173    krb5_data response_data;
     
    267179        *response_p = NULL;
    268180
    269     ret = kcm_send_request(context, k, request, &response_data);
    270     if (ret) {
    271         return ret;
    272     }
     181    krb5_data_zero(&response_data);
     182
     183    ret = kcm_send_request(context, request, &response_data);
     184    if (ret)
     185        return ret;
    273186
    274187    response = krb5_storage_from_data(&response_data);
     
    312225        if (k->name != NULL)
    313226            free(k->name);
    314         if (k->door_path)
    315             free(k->door_path);
    316227        memset(k, 0, sizeof(*k));
    317228        krb5_data_free(&(*id)->data);
     
    352263    k = KCMCACHE(*id);
    353264
    354     ret = kcm_storage_request(context, KCM_OP_GEN_NEW, &request);
     265    ret = krb5_kcm_storage_request(context, KCM_OP_GEN_NEW, &request);
    355266    if (ret) {
    356267        kcm_free(context, id);
     
    358269    }
    359270
    360     ret = kcm_call(context, k, request, &response, &response_data);
     271    ret = krb5_kcm_call(context, request, &response, &response_data);
    361272    if (ret) {
    362273        krb5_storage_free(request);
     
    396307    krb5_storage *request;
    397308
    398     ret = kcm_storage_request(context, KCM_OP_INITIALIZE, &request);
     309    ret = krb5_kcm_storage_request(context, KCM_OP_INITIALIZE, &request);
    399310    if (ret)
    400311        return ret;
     
    412323    }
    413324
    414     ret = kcm_call(context, k, request, NULL, NULL);
    415 
    416     krb5_storage_free(request);
     325    ret = krb5_kcm_call(context, request, NULL, NULL);
     326
     327    krb5_storage_free(request);
     328
     329    if (context->kdc_sec_offset)
     330        kcm_set_kdc_offset(context, id, context->kdc_sec_offset);
     331
    417332    return ret;
    418333}
     
    441356    krb5_storage *request;
    442357
    443     ret = kcm_storage_request(context, KCM_OP_DESTROY, &request);
     358    ret = krb5_kcm_storage_request(context, KCM_OP_DESTROY, &request);
    444359    if (ret)
    445360        return ret;
     
    451366    }
    452367
    453     ret = kcm_call(context, k, request, NULL, NULL);
     368    ret = krb5_kcm_call(context, request, NULL, NULL);
    454369
    455370    krb5_storage_free(request);
     
    474389    krb5_storage *request;
    475390
    476     ret = kcm_storage_request(context, KCM_OP_STORE, &request);
     391    ret = krb5_kcm_storage_request(context, KCM_OP_STORE, &request);
    477392    if (ret)
    478393        return ret;
     
    490405    }
    491406
    492     ret = kcm_call(context, k, request, NULL, NULL);
    493 
    494     krb5_storage_free(request);
    495     return ret;
    496 }
    497 
     407    ret = krb5_kcm_call(context, request, NULL, NULL);
     408
     409    krb5_storage_free(request);
     410    return ret;
     411}
     412
     413#if 0
    498414/*
    499415 * Request:
     
    518434    krb5_data response_data;
    519435
    520     ret = kcm_storage_request(context, KCM_OP_RETRIEVE, &request);
     436    ret = krb5_kcm_storage_request(context, KCM_OP_RETRIEVE, &request);
    521437    if (ret)
    522438        return ret;
     
    540456    }
    541457
    542     ret = kcm_call(context, k, request, &response, &response_data);
     458    ret = krb5_kcm_call(context, request, &response, &response_data);
    543459    if (ret) {
    544460        krb5_storage_free(request);
     
    556472    return ret;
    557473}
     474#endif
    558475
    559476/*
     
    574491    krb5_data response_data;
    575492
    576     ret = kcm_storage_request(context, KCM_OP_GET_PRINCIPAL, &request);
     493    ret = krb5_kcm_storage_request(context, KCM_OP_GET_PRINCIPAL, &request);
    577494    if (ret)
    578495        return ret;
     
    584501    }
    585502
    586     ret = kcm_call(context, k, request, &response, &response_data);
     503    ret = krb5_kcm_call(context, request, &response, &response_data);
    587504    if (ret) {
    588505        krb5_storage_free(request);
     
    620537    krb5_data response_data;
    621538
    622     ret = kcm_storage_request(context, KCM_OP_GET_FIRST, &request);
     539    ret = krb5_kcm_storage_request(context, KCM_OP_GET_CRED_UUID_LIST, &request);
    623540    if (ret)
    624541        return ret;
     
    630547    }
    631548
    632     ret = kcm_call(context, k, request, &response, &response_data);
     549    ret = krb5_kcm_call(context, request, &response, &response_data);
    633550    krb5_storage_free(request);
    634551    if (ret)
     
    711628        return KRB5_CC_END;
    712629
    713     ret = kcm_storage_request(context, KCM_OP_GET_NEXT, &request);
     630    ret = krb5_kcm_storage_request(context, KCM_OP_GET_CRED_BY_UUID, &request);
    714631    if (ret)
    715632        return ret;
     
    731648    }
    732649
    733     ret = kcm_call(context, k, request, &response, &response_data);
     650    ret = krb5_kcm_call(context, request, &response, &response_data);
    734651    krb5_storage_free(request);
    735652    if (ret == KRB5_CC_END) {
     
    760677             krb5_cc_cursor *cursor)
    761678{
    762     krb5_error_code ret;
    763     krb5_kcmcache *k = KCMCACHE(id);
    764679    krb5_kcm_cursor c = KCMCURSOR(*cursor);
    765     krb5_storage *request;
    766 
    767     ret = kcm_storage_request(context, KCM_OP_END_GET, &request);
    768     if (ret)
    769         return ret;
    770 
    771     ret = krb5_store_stringz(request, k->name);
    772     if (ret) {
    773         krb5_storage_free(request);
    774         return ret;
    775     }
    776 
    777     ret = kcm_call(context, k, request, NULL, NULL);
    778     krb5_storage_free(request);
    779     if (ret)
    780         return ret;
    781680
    782681    free(c->uuids);
     
    785684    *cursor = NULL;
    786685
    787     return ret;
     686    return 0;
    788687}
    789688
     
    807706    krb5_storage *request;
    808707
    809     ret = kcm_storage_request(context, KCM_OP_REMOVE_CRED, &request);
     708    ret = krb5_kcm_storage_request(context, KCM_OP_REMOVE_CRED, &request);
    810709    if (ret)
    811710        return ret;
     
    829728    }
    830729
    831     ret = kcm_call(context, k, request, NULL, NULL);
     730    ret = krb5_kcm_call(context, request, NULL, NULL);
    832731
    833732    krb5_storage_free(request);
     
    844743    krb5_storage *request;
    845744
    846     ret = kcm_storage_request(context, KCM_OP_SET_FLAGS, &request);
     745    ret = krb5_kcm_storage_request(context, KCM_OP_SET_FLAGS, &request);
    847746    if (ret)
    848747        return ret;
     
    860759    }
    861760
    862     ret = kcm_call(context, k, request, NULL, NULL);
     761    ret = krb5_kcm_call(context, request, NULL, NULL);
    863762
    864763    krb5_storage_free(request);
     
    873772}
    874773
     774/*
     775 * Send nothing
     776 * get back list of uuids
     777 */
     778
     779static krb5_error_code
     780kcm_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
     781{
     782    krb5_error_code ret;
     783    krb5_kcm_cursor c;
     784    krb5_storage *request, *response;
     785    krb5_data response_data;
     786
     787    *cursor = NULL;
     788
     789    c = calloc(1, sizeof(*c));
     790    if (c == NULL) {
     791        ret = ENOMEM;
     792        krb5_set_error_message(context, ret,
     793                               N_("malloc: out of memory", ""));
     794        goto out;
     795    }
     796
     797    ret = krb5_kcm_storage_request(context, KCM_OP_GET_CACHE_UUID_LIST, &request);
     798    if (ret)
     799        goto out;
     800
     801    ret = krb5_kcm_call(context, request, &response, &response_data);
     802    krb5_storage_free(request);
     803    if (ret)
     804        goto out;
     805
     806    while (1) {
     807        ssize_t sret;
     808        kcmuuid_t uuid;
     809        void *ptr;
     810
     811        sret = krb5_storage_read(response, &uuid, sizeof(uuid));
     812        if (sret == 0) {
     813            ret = 0;
     814            break;
     815        } else if (sret != sizeof(uuid)) {
     816            ret = EINVAL;
     817            goto out;
     818        }
     819
     820        ptr = realloc(c->uuids, sizeof(c->uuids[0]) * (c->length + 1));
     821        if (ptr == NULL) {
     822            ret = ENOMEM;
     823            krb5_set_error_message(context, ret,
     824                                   N_("malloc: out of memory", ""));
     825            goto out;
     826        }
     827        c->uuids = ptr;
     828
     829        memcpy(&c->uuids[c->length], &uuid, sizeof(uuid));
     830        c->length += 1;
     831    }
     832
     833    krb5_storage_free(response);
     834    krb5_data_free(&response_data);
     835
     836 out:
     837    if (ret && c) {
     838        free(c->uuids);
     839        free(c);
     840    } else
     841        *cursor = c;
     842
     843    return ret;
     844}
     845
     846/*
     847 * Send uuid
     848 * Recv cache name
     849 */
     850
     851static krb5_error_code
     852kcm_get_cache_next(krb5_context context, krb5_cc_cursor cursor, const krb5_cc_ops *ops, krb5_ccache *id)
     853{
     854    krb5_error_code ret;
     855    krb5_kcm_cursor c = KCMCURSOR(cursor);
     856    krb5_storage *request, *response;
     857    krb5_data response_data;
     858    ssize_t sret;
     859    char *name;
     860
     861    *id = NULL;
     862
     863 again:
     864
     865    if (c->offset >= c->length)
     866        return KRB5_CC_END;
     867
     868    ret = krb5_kcm_storage_request(context, KCM_OP_GET_CACHE_BY_UUID, &request);
     869    if (ret)
     870        return ret;
     871
     872    sret = krb5_storage_write(request,
     873                              &c->uuids[c->offset],
     874                              sizeof(c->uuids[c->offset]));
     875    c->offset++;
     876    if (sret != sizeof(c->uuids[c->offset])) {
     877        krb5_storage_free(request);
     878        krb5_clear_error_message(context);
     879        return ENOMEM;
     880    }
     881
     882    ret = krb5_kcm_call(context, request, &response, &response_data);
     883    krb5_storage_free(request);
     884    if (ret == KRB5_CC_END)
     885        goto again;
     886
     887    ret = krb5_ret_stringz(response, &name);
     888    krb5_storage_free(response);
     889    krb5_data_free(&response_data);
     890
     891    if (ret == 0) {
     892        ret = _krb5_cc_allocate(context, ops, id);
     893        if (ret == 0)
     894            ret = kcm_alloc(context, name, id);
     895        krb5_xfree(name);
     896    }
     897
     898    return ret;
     899}
     900
     901static krb5_error_code
     902kcm_get_cache_next_kcm(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
     903{
     904#ifndef KCM_IS_API_CACHE
     905    return kcm_get_cache_next(context, cursor, &krb5_kcm_ops, id);
     906#else
     907    return KRB5_CC_END;
     908#endif
     909}
     910
     911static krb5_error_code
     912kcm_get_cache_next_api(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
     913{
     914    return kcm_get_cache_next(context, cursor, &krb5_akcm_ops, id);
     915}
     916
     917
     918static krb5_error_code
     919kcm_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
     920{
     921    krb5_kcm_cursor c = KCMCURSOR(cursor);
     922
     923    free(c->uuids);
     924    free(c);
     925    return 0;
     926}
     927
     928
    875929static krb5_error_code
    876930kcm_move(krb5_context context, krb5_ccache from, krb5_ccache to)
     
    881935    krb5_storage *request;
    882936
    883     ret = kcm_storage_request(context, KCM_OP_MOVE_CACHE, &request);
     937    ret = krb5_kcm_storage_request(context, KCM_OP_MOVE_CACHE, &request);
    884938    if (ret)
    885939        return ret;
     
    896950        return ret;
    897951    }
    898     ret = kcm_call(context, oldk, request, NULL, NULL);
    899 
    900     krb5_storage_free(request);
    901     return ret;
    902 }
    903 
    904 static krb5_error_code
    905 kcm_default_name(krb5_context context, char **str)
    906 {
    907     return _krb5_expand_default_cc_name(context,
    908                                         KRB5_DEFAULT_CCNAME_KCM,
    909                                         str);
     952    ret = krb5_kcm_call(context, request, NULL, NULL);
     953
     954    krb5_storage_free(request);
     955    return ret;
     956}
     957
     958static krb5_error_code
     959kcm_get_default_name(krb5_context context, const krb5_cc_ops *ops,
     960                     const char *defstr, char **str)
     961{
     962    krb5_error_code ret;
     963    krb5_storage *request, *response;
     964    krb5_data response_data;
     965    char *name;
     966   
     967    *str = NULL;
     968
     969    ret = krb5_kcm_storage_request(context, KCM_OP_GET_DEFAULT_CACHE, &request);
     970    if (ret)
     971        return ret;
     972
     973    ret = krb5_kcm_call(context, request, &response, &response_data);
     974    krb5_storage_free(request);
     975    if (ret)
     976        return _krb5_expand_default_cc_name(context, defstr, str);
     977
     978    ret = krb5_ret_stringz(response, &name);
     979    krb5_storage_free(response);
     980    krb5_data_free(&response_data);
     981    if (ret)
     982        return ret;
     983
     984    asprintf(str, "%s:%s", ops->prefix, name);
     985    free(name);
     986    if (str == NULL)
     987        return ENOMEM;
     988
     989    return 0;
     990}
     991
     992static krb5_error_code
     993kcm_get_default_name_api(krb5_context context, char **str)
     994{
     995    return kcm_get_default_name(context, &krb5_akcm_ops,
     996                                KRB5_DEFAULT_CCNAME_KCM_API, str);
     997}
     998
     999static krb5_error_code
     1000kcm_get_default_name_kcm(krb5_context context, char **str)
     1001{
     1002    return kcm_get_default_name(context, &krb5_kcm_ops,
     1003                                KRB5_DEFAULT_CCNAME_KCM_KCM, str);
     1004}
     1005
     1006static krb5_error_code
     1007kcm_set_default(krb5_context context, krb5_ccache id)
     1008{
     1009    krb5_error_code ret;
     1010    krb5_storage *request;
     1011    krb5_kcmcache *k = KCMCACHE(id);
     1012
     1013    ret = krb5_kcm_storage_request(context, KCM_OP_SET_DEFAULT_CACHE, &request);
     1014    if (ret)
     1015        return ret;
     1016
     1017    ret = krb5_store_stringz(request, k->name);
     1018    if (ret) {
     1019        krb5_storage_free(request);
     1020        return ret;
     1021    }
     1022
     1023    ret = krb5_kcm_call(context, request, NULL, NULL);
     1024    krb5_storage_free(request);
     1025
     1026    return ret;
    9101027}
    9111028
     
    9141031{
    9151032    *mtime = time(NULL);
     1033    return 0;
     1034}
     1035
     1036static krb5_error_code
     1037kcm_set_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat kdc_offset)
     1038{
     1039    krb5_kcmcache *k = KCMCACHE(id);
     1040    krb5_error_code ret;
     1041    krb5_storage *request;
     1042   
     1043    ret = krb5_kcm_storage_request(context, KCM_OP_SET_KDC_OFFSET, &request);
     1044    if (ret)
     1045        return ret;
     1046
     1047    ret = krb5_store_stringz(request, k->name);
     1048    if (ret) {
     1049        krb5_storage_free(request);
     1050        return ret;
     1051    }
     1052    ret = krb5_store_int32(request, kdc_offset);
     1053    if (ret) {
     1054        krb5_storage_free(request);
     1055        return ret;
     1056    }
     1057
     1058    ret = krb5_kcm_call(context, request, NULL, NULL);
     1059    krb5_storage_free(request);
     1060
     1061    return ret;
     1062}
     1063
     1064static krb5_error_code
     1065kcm_get_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat *kdc_offset)
     1066{
     1067    krb5_kcmcache *k = KCMCACHE(id);
     1068    krb5_error_code ret;
     1069    krb5_storage *request, *response;
     1070    krb5_data response_data;
     1071    int32_t offset;
     1072   
     1073    ret = krb5_kcm_storage_request(context, KCM_OP_GET_KDC_OFFSET, &request);
     1074    if (ret)
     1075        return ret;
     1076
     1077    ret = krb5_store_stringz(request, k->name);
     1078    if (ret) {
     1079        krb5_storage_free(request);
     1080        return ret;
     1081    }
     1082
     1083    ret = krb5_kcm_call(context, request, &response, &response_data);
     1084    krb5_storage_free(request);
     1085    if (ret)
     1086        return ret;
     1087
     1088    ret = krb5_ret_int32(response, &offset);
     1089    krb5_storage_free(response);
     1090    krb5_data_free(&response_data);
     1091    if (ret)
     1092        return ret;
     1093
     1094    *kdc_offset = offset;
     1095
    9161096    return 0;
    9171097}
     
    9331113    kcm_close,
    9341114    kcm_store_cred,
    935     kcm_retrieve,
     1115    NULL /* kcm_retrieve */,
    9361116    kcm_get_principal,
    9371117    kcm_get_first,
     
    9411121    kcm_set_flags,
    9421122    kcm_get_version,
    943     NULL,
    944     NULL,
    945     NULL,
     1123    kcm_get_cache_first,
     1124    kcm_get_cache_next_kcm,
     1125    kcm_end_cache_get,
    9461126    kcm_move,
    947     kcm_default_name,
    948     NULL,
     1127    kcm_get_default_name_kcm,
     1128    kcm_set_default,
     1129    kcm_lastchange,
     1130    kcm_set_kdc_offset,
     1131    kcm_get_kdc_offset
     1132};
     1133
     1134KRB5_LIB_VARIABLE const krb5_cc_ops krb5_akcm_ops = {
     1135    KRB5_CC_OPS_VERSION,
     1136    "API",
     1137    kcm_get_name,
     1138    kcm_resolve,
     1139    kcm_gen_new,
     1140    kcm_initialize,
     1141    kcm_destroy,
     1142    kcm_close,
     1143    kcm_store_cred,
     1144    NULL /* kcm_retrieve */,
     1145    kcm_get_principal,
     1146    kcm_get_first,
     1147    kcm_get_next,
     1148    kcm_end_get,
     1149    kcm_remove_cred,
     1150    kcm_set_flags,
     1151    kcm_get_version,
     1152    kcm_get_cache_first,
     1153    kcm_get_cache_next_api,
     1154    kcm_end_cache_get,
     1155    kcm_move,
     1156    kcm_get_default_name_api,
     1157    kcm_set_default,
    9491158    kcm_lastchange
    9501159};
     1160
    9511161
    9521162krb5_boolean
     
    9801190{
    9811191    krb5_error_code ret;
    982     krb5_kcmcache *k = KCMCACHE(id);
    9831192    krb5_storage *request;
    9841193
    985     ret = kcm_storage_request(context, KCM_OP_NOOP, &request);
    986     if (ret)
    987         return ret;
    988 
    989     ret = kcm_call(context, k, request, NULL, NULL);
    990 
    991     krb5_storage_free(request);
    992     return ret;
    993 }
    994 
    995 
    996 /*
    997  * Request:
    998  *      NameZ
    999  *      Mode
    1000  *
    1001  * Response:
    1002  *
    1003  */
    1004 krb5_error_code
    1005 _krb5_kcm_chmod(krb5_context context,
    1006                 krb5_ccache id,
    1007                 uint16_t mode)
    1008 {
    1009     krb5_error_code ret;
    1010     krb5_kcmcache *k = KCMCACHE(id);
    1011     krb5_storage *request;
    1012 
    1013     ret = kcm_storage_request(context, KCM_OP_CHMOD, &request);
    1014     if (ret)
    1015         return ret;
    1016 
    1017     ret = krb5_store_stringz(request, k->name);
    1018     if (ret) {
    1019         krb5_storage_free(request);
    1020         return ret;
    1021     }
    1022 
    1023     ret = krb5_store_int16(request, mode);
    1024     if (ret) {
    1025         krb5_storage_free(request);
    1026         return ret;
    1027     }
    1028 
    1029     ret = kcm_call(context, k, request, NULL, NULL);
    1030 
    1031     krb5_storage_free(request);
    1032     return ret;
    1033 }
    1034 
    1035 
    1036 /*
    1037  * Request:
    1038  *      NameZ
    1039  *      UID
    1040  *      GID
    1041  *
    1042  * Response:
    1043  *
    1044  */
    1045 krb5_error_code
    1046 _krb5_kcm_chown(krb5_context context,
    1047                 krb5_ccache id,
    1048                 uint32_t uid,
    1049                 uint32_t gid)
    1050 {
    1051     krb5_error_code ret;
    1052     krb5_kcmcache *k = KCMCACHE(id);
    1053     krb5_storage *request;
    1054 
    1055     ret = kcm_storage_request(context, KCM_OP_CHOWN, &request);
    1056     if (ret)
    1057         return ret;
    1058 
    1059     ret = krb5_store_stringz(request, k->name);
    1060     if (ret) {
    1061         krb5_storage_free(request);
    1062         return ret;
    1063     }
    1064 
    1065     ret = krb5_store_int32(request, uid);
    1066     if (ret) {
    1067         krb5_storage_free(request);
    1068         return ret;
    1069     }
    1070 
    1071     ret = krb5_store_int32(request, gid);
    1072     if (ret) {
    1073         krb5_storage_free(request);
    1074         return ret;
    1075     }
    1076 
    1077     ret = kcm_call(context, k, request, NULL, NULL);
     1194    ret = krb5_kcm_storage_request(context, KCM_OP_NOOP, &request);
     1195    if (ret)
     1196        return ret;
     1197
     1198    ret = krb5_kcm_call(context, request, NULL, NULL);
    10781199
    10791200    krb5_storage_free(request);
     
    11021223    krb5_storage *request;
    11031224
    1104     ret = kcm_storage_request(context, KCM_OP_GET_INITIAL_TICKET, &request);
     1225    ret = krb5_kcm_storage_request(context, KCM_OP_GET_INITIAL_TICKET, &request);
    11051226    if (ret)
    11061227        return ret;
     
    11321253    }
    11331254
    1134     ret = kcm_call(context, k, request, NULL, NULL);
     1255    ret = krb5_kcm_call(context, request, NULL, NULL);
    11351256
    11361257    krb5_storage_free(request);
     
    11601281    krb5_storage *request;
    11611282
    1162     ret = kcm_storage_request(context, KCM_OP_GET_TICKET, &request);
     1283    ret = krb5_kcm_storage_request(context, KCM_OP_GET_TICKET, &request);
    11631284    if (ret)
    11641285        return ret;
     
    11881309    }
    11891310
    1190     ret = kcm_call(context, k, request, NULL, NULL);
     1311    ret = krb5_kcm_call(context, request, NULL, NULL);
    11911312
    11921313    krb5_storage_free(request);
  • trunk/server/source4/heimdal/lib/krb5/keyblock.c

    r414 r745  
    4242 */
    4343
    44 void KRB5_LIB_FUNCTION
     44KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    4545krb5_keyblock_zero(krb5_keyblock *keyblock)
    4646{
     
    5858 */
    5959
    60 void KRB5_LIB_FUNCTION
     60KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    6161krb5_free_keyblock_contents(krb5_context context,
    6262                            krb5_keyblock *keyblock)
     
    8080 */
    8181
    82 void KRB5_LIB_FUNCTION
     82KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8383krb5_free_keyblock(krb5_context context,
    8484                   krb5_keyblock *keyblock)
     
    9898 * @param to the output key.
    9999 *
    100  * @param 0 on success or a Kerberos 5 error code
    101  *
    102  * @ingroup krb5_crypto
    103  */
    104 
    105 krb5_error_code KRB5_LIB_FUNCTION
     100 * @return 0 on success or a Kerberos 5 error code
     101 *
     102 * @ingroup krb5_crypto
     103 */
     104
     105KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    106106krb5_copy_keyblock_contents (krb5_context context,
    107107                             const krb5_keyblock *inblock,
     
    119119 * @param to the output key.
    120120 *
    121  * @param 0 on success or a Kerberos 5 error code
    122  *
    123  * @ingroup krb5_crypto
    124  */
    125 
    126 
    127 krb5_error_code KRB5_LIB_FUNCTION
     121 * @return 0 on success or a Kerberos 5 error code
     122 *
     123 * @ingroup krb5_crypto
     124 */
     125
     126
     127KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    128128krb5_copy_keyblock (krb5_context context,
    129129                    const krb5_keyblock *inblock,
     
    156156 */
    157157
    158 krb5_enctype
     158KRB5_LIB_FUNCTION krb5_enctype KRB5_LIB_CALL
    159159krb5_keyblock_get_enctype(const krb5_keyblock *block)
    160160{
     
    166166 * `size'. Key should be freed using krb5_free_keyblock_contents().
    167167 *
    168  * @ingroup krb5_crypto
    169  */
    170 
    171 krb5_error_code KRB5_LIB_FUNCTION
     168 * @return 0 on success or a Kerberos 5 error code
     169 *
     170 * @ingroup krb5_crypto
     171 */
     172
     173KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    172174krb5_keyblock_init(krb5_context context,
    173175                   krb5_enctype type,
  • trunk/server/source4/heimdal/lib/krb5/keytab.c

    r414 r745  
    7474 *   the type's name is AFSKEYFILE. The residual part is a filename.
    7575 *
    76  * - krb4
    77  *   the keytab is a Kerberos 4 srvtab that is on-the-fly converted to
    78  *   a keytab. The type's name is krb4 The residual part is a
    79  *   filename.
    80  *
    8176 * - memory
    8277 *   The keytab is stored in a memory segment. This allows sensitive
     
    8479 *   is MEMORY. Each MEMORY keytab is referenced counted by and
    8580 *   opened by the residual name, so two handles can point to the
    86  *   same memory area.  When the last user closes the entry, it
    87  *   disappears.
     81 *   same memory area.  When the last user closes using krb5_kt_close()
     82 *   the keytab, the keys in they keytab is memset() to zero and freed
     83 *   and can no longer be looked up by name.
    8884 *
    8985 *
     
    114110        krb5_err(context, 1, ret, "krb5_kt_start_seq_get");
    115111    while((ret = krb5_kt_next_entry(context, keytab, &entry, &cursor)) == 0){
    116         krb5_unparse_name_short(context, entry.principal, &principal);
     112        krb5_unparse_name(context, entry.principal, &principal);
    117113        printf("principal: %s\n", principal);
    118114        free(principal);
     
    144140 */
    145141
    146 krb5_error_code KRB5_LIB_FUNCTION
     142KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    147143krb5_kt_register(krb5_context context,
    148144                 const krb5_kt_ops *ops)
     
    170166}
    171167
     168static const char *
     169keytab_name(const char * name, const char ** ptype, size_t * ptype_len)
     170{
     171    const char * residual;
     172
     173    residual = strchr(name, ':');
     174
     175    if (residual == NULL
     176
     177#ifdef _WIN32
     178
     179        /* Avoid treating <drive>:<path> as a keytab type
     180         * specification */
     181
     182        || name + 1 == residual
     183#endif
     184        ) {
     185
     186        *ptype = "FILE";
     187        *ptype_len = strlen(*ptype);
     188        residual = name;
     189    } else {
     190        *ptype = name;
     191        *ptype_len = residual - name;
     192        residual++;
     193    }
     194
     195    return residual;
     196}
     197
    172198/**
    173199 * Resolve the keytab name (of the form `type:residual') in `name'
     
    184210
    185211
    186 krb5_error_code KRB5_LIB_FUNCTION
     212KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    187213krb5_kt_resolve(krb5_context context,
    188214                const char *name,
     
    195221    krb5_error_code ret;
    196222
    197     residual = strchr(name, ':');
    198     if(residual == NULL) {
    199         type = "FILE";
    200         type_len = strlen(type);
    201         residual = name;
    202     } else {
    203         type = name;
    204         type_len = residual - name;
    205         residual++;
    206     }
     223    residual = keytab_name(name, &type, &type_len);
    207224
    208225    for(i = 0; i < context->num_kt_types; i++) {
     
    245262 */
    246263
    247 krb5_error_code KRB5_LIB_FUNCTION
     264KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    248265krb5_kt_default_name(krb5_context context, char *name, size_t namesize)
    249266{
     
    267284 */
    268285
    269 krb5_error_code KRB5_LIB_FUNCTION
     286KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    270287krb5_kt_default_modify_name(krb5_context context, char *name, size_t namesize)
    271288{
     
    304321 */
    305322
    306 krb5_error_code KRB5_LIB_FUNCTION
     323KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    307324krb5_kt_default(krb5_context context, krb5_keytab *id)
    308325{
     
    326343 */
    327344
    328 krb5_error_code KRB5_LIB_FUNCTION
     345KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    329346krb5_kt_read_service_key(krb5_context context,
    330347                         krb5_pointer keyprocarg,
     
    369386 */
    370387
    371 krb5_error_code KRB5_LIB_FUNCTION
     388KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    372389krb5_kt_get_type(krb5_context context,
    373390                 krb5_keytab keytab,
     
    392409 */
    393410
    394 krb5_error_code KRB5_LIB_FUNCTION
     411KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    395412krb5_kt_get_name(krb5_context context,
    396413                 krb5_keytab keytab,
     
    415432 */
    416433
    417 krb5_error_code KRB5_LIB_FUNCTION
     434KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    418435krb5_kt_get_full_name(krb5_context context,
    419436                      krb5_keytab keytab,
     
    455472 */
    456473
    457 krb5_error_code KRB5_LIB_FUNCTION
     474KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    458475krb5_kt_close(krb5_context context,
    459476              krb5_keytab id)
     
    479496 */
    480497
    481 krb5_error_code KRB5_LIB_FUNCTION
     498KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    482499krb5_kt_destroy(krb5_context context,
    483500                krb5_keytab id)
     
    524541 */
    525542
    526 krb5_boolean KRB5_LIB_FUNCTION
     543KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    527544krb5_kt_compare(krb5_context context,
    528545                krb5_keytab_entry *entry,
     
    591608 */
    592609
    593 krb5_error_code KRB5_LIB_FUNCTION
     610KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    594611krb5_kt_get_entry(krb5_context context,
    595612                  krb5_keytab id,
     
    652669 */
    653670
    654 krb5_error_code KRB5_LIB_FUNCTION
     671KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    655672krb5_kt_copy_entry_contents(krb5_context context,
    656673                            const krb5_keytab_entry *in,
     
    688705 */
    689706
    690 krb5_error_code KRB5_LIB_FUNCTION
     707KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    691708krb5_kt_free_entry(krb5_context context,
    692709                   krb5_keytab_entry *entry)
     
    710727 */
    711728
    712 krb5_error_code KRB5_LIB_FUNCTION
     729KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    713730krb5_kt_start_seq_get(krb5_context context,
    714731                      krb5_keytab id,
     
    739756 */
    740757
    741 krb5_error_code KRB5_LIB_FUNCTION
     758KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    742759krb5_kt_next_entry(krb5_context context,
    743760                   krb5_keytab id,
     
    767784 */
    768785
    769 krb5_error_code KRB5_LIB_FUNCTION
     786KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    770787krb5_kt_end_seq_get(krb5_context context,
    771788                    krb5_keytab id,
     
    793810 */
    794811
    795 krb5_error_code KRB5_LIB_FUNCTION
     812KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    796813krb5_kt_add_entry(krb5_context context,
    797814                  krb5_keytab id,
     
    821838 */
    822839
    823 krb5_error_code KRB5_LIB_FUNCTION
     840KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    824841krb5_kt_remove_entry(krb5_context context,
    825842                     krb5_keytab id,
  • trunk/server/source4/heimdal/lib/krb5/keytab_any.c

    r414 r745  
    5454}
    5555
    56 static krb5_error_code
     56static krb5_error_code KRB5_CALLCONV
    5757any_resolve(krb5_context context, const char *name, krb5_keytab id)
    5858{
     
    6262
    6363    while (strsep_copy(&name, ",", buf, sizeof(buf)) != -1) {
    64         a = malloc(sizeof(*a));
     64        a = calloc(1, sizeof(*a));
    6565        if (a == NULL) {
    6666            ret = ENOMEM;
     
    9696}
    9797
    98 static krb5_error_code
     98static krb5_error_code KRB5_CALLCONV
    9999any_get_name (krb5_context context,
    100100              krb5_keytab id,
     
    107107}
    108108
    109 static krb5_error_code
     109static krb5_error_code KRB5_CALLCONV
    110110any_close (krb5_context context,
    111111           krb5_keytab id)
     
    122122};
    123123
    124 static krb5_error_code
     124static krb5_error_code KRB5_CALLCONV
    125125any_start_seq_get(krb5_context context,
    126126                  krb5_keytab id,
     
    151151}
    152152
    153 static krb5_error_code
     153static krb5_error_code KRB5_CALLCONV
    154154any_next_entry (krb5_context context,
    155155                krb5_keytab id,
     
    183183}
    184184
    185 static krb5_error_code
     185static krb5_error_code KRB5_CALLCONV
    186186any_end_seq_get(krb5_context context,
    187187                krb5_keytab id,
     
    199199}
    200200
    201 static krb5_error_code
     201static krb5_error_code KRB5_CALLCONV
    202202any_add_entry(krb5_context context,
    203203              krb5_keytab id,
     
    219219}
    220220
    221 static krb5_error_code
     221static krb5_error_code KRB5_CALLCONV
    222222any_remove_entry(krb5_context context,
    223223                 krb5_keytab id,
  • trunk/server/source4/heimdal/lib/krb5/keytab_file.c

    r414 r745  
    287287}
    288288
    289 static krb5_error_code
     289static krb5_error_code KRB5_CALLCONV
    290290fkt_resolve(krb5_context context, const char *name, krb5_keytab id)
    291291{
     
    308308}
    309309
    310 static krb5_error_code
     310static krb5_error_code KRB5_CALLCONV
    311311fkt_resolve_java14(krb5_context context, const char *name, krb5_keytab id)
    312312{
     
    321321}
    322322
    323 static krb5_error_code
     323static krb5_error_code KRB5_CALLCONV
    324324fkt_close(krb5_context context, krb5_keytab id)
    325325{
     
    330330}
    331331
    332 static krb5_error_code
     332static krb5_error_code KRB5_CALLCONV
    333333fkt_destroy(krb5_context context, krb5_keytab id)
    334334{
     
    338338}
    339339
    340 static krb5_error_code
     340static krb5_error_code KRB5_CALLCONV
    341341fkt_get_name(krb5_context context,
    342342             krb5_keytab id,
     
    431431}
    432432
    433 static krb5_error_code
     433static krb5_error_code KRB5_CALLCONV
    434434fkt_start_seq_get(krb5_context context,
    435435                  krb5_keytab id,
     
    504504}
    505505
    506 static krb5_error_code
     506static krb5_error_code KRB5_CALLCONV
    507507fkt_next_entry(krb5_context context,
    508508               krb5_keytab id,
     
    513513}
    514514
    515 static krb5_error_code
     515static krb5_error_code KRB5_CALLCONV
    516516fkt_end_seq_get(krb5_context context,
    517517                krb5_keytab id,
     
    524524}
    525525
    526 static krb5_error_code
     526static krb5_error_code KRB5_CALLCONV
    527527fkt_setup_keytab(krb5_context context,
    528528                 krb5_keytab id,
     
    538538}
    539539               
    540 static krb5_error_code
     540static krb5_error_code KRB5_CALLCONV
    541541fkt_add_entry(krb5_context context,
    542542              krb5_keytab id,
     
    724724}
    725725
    726 static krb5_error_code
     726static krb5_error_code KRB5_CALLCONV
    727727fkt_remove_entry(krb5_context context,
    728728                 krb5_keytab id,
  • trunk/server/source4/heimdal/lib/krb5/keytab_keyfile.c

    r414 r745  
    129129 */
    130130
    131 static krb5_error_code
     131static krb5_error_code KRB5_CALLCONV
    132132akf_resolve(krb5_context context, const char *name, krb5_keytab id)
    133133{
     
    165165 */
    166166
    167 static krb5_error_code
     167static krb5_error_code KRB5_CALLCONV
    168168akf_close(krb5_context context, krb5_keytab id)
    169169{
     
    180180 */
    181181
    182 static krb5_error_code
     182static krb5_error_code KRB5_CALLCONV
    183183akf_get_name(krb5_context context,
    184184             krb5_keytab id,
     
    196196 */
    197197
    198 static krb5_error_code
     198static krb5_error_code KRB5_CALLCONV
    199199akf_start_seq_get(krb5_context context,
    200200                  krb5_keytab id,
     
    227227}
    228228
    229 static krb5_error_code
     229static krb5_error_code KRB5_CALLCONV
    230230akf_next_entry(krb5_context context,
    231231               krb5_keytab id,
     
    282282}
    283283
    284 static krb5_error_code
     284static krb5_error_code KRB5_CALLCONV
    285285akf_end_seq_get(krb5_context context,
    286286                krb5_keytab id,
     
    292292}
    293293
    294 static krb5_error_code
     294static krb5_error_code KRB5_CALLCONV
    295295akf_add_entry(krb5_context context,
    296296              krb5_keytab id,
  • trunk/server/source4/heimdal/lib/krb5/keytab_memory.c

    r414 r745  
    5151
    5252
    53 static krb5_error_code
     53static krb5_error_code KRB5_CALLCONV
    5454mkt_resolve(krb5_context context, const char *name, krb5_keytab id)
    5555{
     
    9696}
    9797
    98 static krb5_error_code
     98static krb5_error_code KRB5_CALLCONV
    9999mkt_close(krb5_context context, krb5_keytab id)
    100100{
     
    127127}
    128128
    129 static krb5_error_code
     129static krb5_error_code KRB5_CALLCONV
    130130mkt_get_name(krb5_context context,
    131131             krb5_keytab id,
     
    138138}
    139139
    140 static krb5_error_code
     140static krb5_error_code KRB5_CALLCONV
    141141mkt_start_seq_get(krb5_context context,
    142142                  krb5_keytab id,
     
    148148}
    149149
    150 static krb5_error_code
     150static krb5_error_code KRB5_CALLCONV
    151151mkt_next_entry(krb5_context context,
    152152               krb5_keytab id,
     
    160160}
    161161
    162 static krb5_error_code
     162static krb5_error_code KRB5_CALLCONV
    163163mkt_end_seq_get(krb5_context context,
    164164                krb5_keytab id,
     
    168168}
    169169
    170 static krb5_error_code
     170static krb5_error_code KRB5_CALLCONV
    171171mkt_add_entry(krb5_context context,
    172172              krb5_keytab id,
     
    186186}
    187187
    188 static krb5_error_code
     188static krb5_error_code KRB5_CALLCONV
    189189mkt_remove_entry(krb5_context context,
    190190                 krb5_keytab id,
  • trunk/server/source4/heimdal/lib/krb5/krb5-v4compat.h

    r414 r745  
    106106
    107107#ifndef TKT_ROOT
     108#ifdef KRB5_USE_PATH_TOKENS
     109#define TKT_ROOT "%{TEMP}/tkt"
     110#else
    108111#define TKT_ROOT "/tmp/tkt"
     112#endif
    109113#endif
    110114
     
    121125};
    122126
    123 time_t          _krb5_krb_life_to_time (int, int);
    124 int             _krb5_krb_time_to_life (time_t, time_t);
    125 krb5_error_code _krb5_krb_tf_setup (krb5_context, struct credentials *,
    126                                     const char *, int);
    127 krb5_error_code _krb5_krb_dest_tkt(krb5_context, const char *);
     127KRB5_LIB_FUNCTION time_t KRB5_LIB_CALL
     128_krb5_krb_life_to_time (int, int);
     129
     130KRB5_LIB_FUNCTION int KRB5_LIB_CALL
     131_krb5_krb_time_to_life (time_t, time_t);
     132
     133KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     134_krb5_krb_tf_setup (krb5_context, struct credentials *,
     135                    const char *, int);
     136
     137KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     138_krb5_krb_dest_tkt(krb5_context, const char *);
    128139
    129140#define krb_time_to_life        _krb5_krb_time_to_life
  • trunk/server/source4/heimdal/lib/krb5/krb5.h

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    6264#endif
    6365
     66#ifdef _WIN32
     67#define KRB5_CALLCONV __stdcall
     68#else
     69#define KRB5_CALLCONV
     70#endif
     71
    6472/* simple constants */
    6573
     
    7381typedef int32_t krb5_error_code;
    7482
    75 typedef int krb5_kvno;
     83typedef int32_t krb5_kvno;
    7684
    7785typedef uint32_t krb5_flags;
     
    234242    KRB5_KU_PA_PKINIT_KX = 44,
    235243    /* Encryption type of the kdc session contribution in pk-init */
     244    KRB5_KU_AS_REQ = 56,
     245    /* Checksum of over the AS-REQ send by the KDC in PA-REQ-ENC-PA-REP */
    236246    KRB5_KU_DIGEST_ENCRYPT = -18,
    237247    /* Encryption key usage used in the digest encryption field */
     
    302312struct krb5_cc_ops;
    303313
     314#ifdef _WIN32
     315#define KRB5_USE_PATH_TOKENS 1
     316#endif
     317
     318#ifdef KRB5_USE_PATH_TOKENS
     319#define KRB5_DEFAULT_CCFILE_ROOT "%{TEMP}/krb5cc_"
     320#else
    304321#define KRB5_DEFAULT_CCFILE_ROOT "/tmp/krb5cc_"
     322#endif
    305323
    306324#define KRB5_DEFAULT_CCROOT "FILE:" KRB5_DEFAULT_CCFILE_ROOT
     
    312330
    313331typedef void *krb5_cc_cursor;
    314 typedef struct krb5_cccol_cursor *krb5_cccol_cursor;
     332typedef struct krb5_cccol_cursor_data *krb5_cccol_cursor;
    315333
    316334typedef struct krb5_ccache_data {
     
    395413#define KRB5_TC_MATCH_IS_SKEY           (1 << 22)
    396414
     415/* constants for get_flags and set_flags */
     416#define KRB5_TC_OPENCLOSE 0x00000001
     417#define KRB5_TC_NOTICKET  0x00000002
     418
    397419typedef AuthorizationData krb5_authdata;
    398420
     
    413435typedef struct krb5_cc_cache_cursor_data *krb5_cc_cache_cursor;
    414436
    415 #define KRB5_CC_OPS_VERSION 2
     437#define KRB5_CC_OPS_VERSION 3
    416438
    417439typedef struct krb5_cc_ops {
    418440    int version;
    419441    const char *prefix;
    420     const char* (*get_name)(krb5_context, krb5_ccache);
    421     krb5_error_code (*resolve)(krb5_context, krb5_ccache *, const char *);
    422     krb5_error_code (*gen_new)(krb5_context, krb5_ccache *);
    423     krb5_error_code (*init)(krb5_context, krb5_ccache, krb5_principal);
    424     krb5_error_code (*destroy)(krb5_context, krb5_ccache);
    425     krb5_error_code (*close)(krb5_context, krb5_ccache);
    426     krb5_error_code (*store)(krb5_context, krb5_ccache, krb5_creds*);
    427     krb5_error_code (*retrieve)(krb5_context, krb5_ccache,
    428                                 krb5_flags, const krb5_creds*, krb5_creds *);
    429     krb5_error_code (*get_princ)(krb5_context, krb5_ccache, krb5_principal*);
    430     krb5_error_code (*get_first)(krb5_context, krb5_ccache, krb5_cc_cursor *);
    431     krb5_error_code (*get_next)(krb5_context, krb5_ccache,
    432                                 krb5_cc_cursor*, krb5_creds*);
    433     krb5_error_code (*end_get)(krb5_context, krb5_ccache, krb5_cc_cursor*);
    434     krb5_error_code (*remove_cred)(krb5_context, krb5_ccache,
    435                                    krb5_flags, krb5_creds*);
    436     krb5_error_code (*set_flags)(krb5_context, krb5_ccache, krb5_flags);
    437     int (*get_version)(krb5_context, krb5_ccache);
    438     krb5_error_code (*get_cache_first)(krb5_context, krb5_cc_cursor *);
    439     krb5_error_code (*get_cache_next)(krb5_context, krb5_cc_cursor, krb5_ccache *);
    440     krb5_error_code (*end_cache_get)(krb5_context, krb5_cc_cursor);
    441     krb5_error_code (*move)(krb5_context, krb5_ccache, krb5_ccache);
    442     krb5_error_code (*get_default_name)(krb5_context, char **);
    443     krb5_error_code (*set_default)(krb5_context, krb5_ccache);
    444     krb5_error_code (*lastchange)(krb5_context, krb5_ccache, krb5_timestamp *);
     442    const char* (KRB5_CALLCONV * get_name)(krb5_context, krb5_ccache);
     443    krb5_error_code (KRB5_CALLCONV * resolve)(krb5_context, krb5_ccache *, const char *);
     444    krb5_error_code (KRB5_CALLCONV * gen_new)(krb5_context, krb5_ccache *);
     445    krb5_error_code (KRB5_CALLCONV * init)(krb5_context, krb5_ccache, krb5_principal);
     446    krb5_error_code (KRB5_CALLCONV * destroy)(krb5_context, krb5_ccache);
     447    krb5_error_code (KRB5_CALLCONV * close)(krb5_context, krb5_ccache);
     448    krb5_error_code (KRB5_CALLCONV * store)(krb5_context, krb5_ccache, krb5_creds*);
     449    krb5_error_code (KRB5_CALLCONV * retrieve)(krb5_context, krb5_ccache,
     450                                               krb5_flags, const krb5_creds*, krb5_creds *);
     451    krb5_error_code (KRB5_CALLCONV * get_princ)(krb5_context, krb5_ccache, krb5_principal*);
     452    krb5_error_code (KRB5_CALLCONV * get_first)(krb5_context, krb5_ccache, krb5_cc_cursor *);
     453    krb5_error_code (KRB5_CALLCONV * get_next)(krb5_context, krb5_ccache,
     454                                               krb5_cc_cursor*, krb5_creds*);
     455    krb5_error_code (KRB5_CALLCONV * end_get)(krb5_context, krb5_ccache, krb5_cc_cursor*);
     456    krb5_error_code (KRB5_CALLCONV * remove_cred)(krb5_context, krb5_ccache,
     457                                                  krb5_flags, krb5_creds*);
     458    krb5_error_code (KRB5_CALLCONV * set_flags)(krb5_context, krb5_ccache, krb5_flags);
     459    int (KRB5_CALLCONV * get_version)(krb5_context, krb5_ccache);
     460    krb5_error_code (KRB5_CALLCONV * get_cache_first)(krb5_context, krb5_cc_cursor *);
     461    krb5_error_code (KRB5_CALLCONV * get_cache_next)(krb5_context, krb5_cc_cursor,
     462                                                     krb5_ccache *);
     463    krb5_error_code (KRB5_CALLCONV * end_cache_get)(krb5_context, krb5_cc_cursor);
     464    krb5_error_code (KRB5_CALLCONV * move)(krb5_context, krb5_ccache, krb5_ccache);
     465    krb5_error_code (KRB5_CALLCONV * get_default_name)(krb5_context, char **);
     466    krb5_error_code (KRB5_CALLCONV * set_default)(krb5_context, krb5_ccache);
     467    krb5_error_code (KRB5_CALLCONV * lastchange)(krb5_context, krb5_ccache, krb5_timestamp *);
     468    krb5_error_code (KRB5_CALLCONV * set_kdc_offset)(krb5_context, krb5_ccache, krb5_deltat);
     469    krb5_error_code (KRB5_CALLCONV * get_kdc_offset)(krb5_context, krb5_ccache, krb5_deltat *);
    445470} krb5_cc_ops;
    446471
     
    512537struct krb5_keytab_data {
    513538    const char *prefix;
    514     krb5_error_code (*resolve)(krb5_context, const char*, krb5_keytab);
    515     krb5_error_code (*get_name)(krb5_context, krb5_keytab, char*, size_t);
    516     krb5_error_code (*close)(krb5_context, krb5_keytab);
    517     krb5_error_code (*destroy)(krb5_context, krb5_keytab);
    518     krb5_error_code (*get)(krb5_context, krb5_keytab, krb5_const_principal,
    519                            krb5_kvno, krb5_enctype, krb5_keytab_entry*);
    520     krb5_error_code (*start_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
    521     krb5_error_code (*next_entry)(krb5_context, krb5_keytab,
    522                                   krb5_keytab_entry*, krb5_kt_cursor*);
    523     krb5_error_code (*end_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
    524     krb5_error_code (*add)(krb5_context, krb5_keytab, krb5_keytab_entry*);
    525     krb5_error_code (*remove)(krb5_context, krb5_keytab, krb5_keytab_entry*);
     539    krb5_error_code (KRB5_CALLCONV * resolve)(krb5_context, const char*, krb5_keytab);
     540    krb5_error_code (KRB5_CALLCONV * get_name)(krb5_context, krb5_keytab, char*, size_t);
     541    krb5_error_code (KRB5_CALLCONV * close)(krb5_context, krb5_keytab);
     542    krb5_error_code (KRB5_CALLCONV * destroy)(krb5_context, krb5_keytab);
     543    krb5_error_code (KRB5_CALLCONV * get)(krb5_context, krb5_keytab, krb5_const_principal,
     544                                          krb5_kvno, krb5_enctype, krb5_keytab_entry*);
     545    krb5_error_code (KRB5_CALLCONV * start_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
     546    krb5_error_code (KRB5_CALLCONV * next_entry)(krb5_context, krb5_keytab,
     547                                                krb5_keytab_entry*, krb5_kt_cursor*);
     548    krb5_error_code (KRB5_CALLCONV * end_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
     549    krb5_error_code (KRB5_CALLCONV * add)(krb5_context, krb5_keytab, krb5_keytab_entry*);
     550    krb5_error_code (KRB5_CALLCONV * remove)(krb5_context, krb5_keytab, krb5_keytab_entry*);
    526551    void *data;
    527552    int32_t version;
     
    595620extern const char *heimdal_version, *heimdal_long_version;
    596621
    597 typedef void (*krb5_log_log_func_t)(const char*, const char*, void*);
    598 typedef void (*krb5_log_close_func_t)(void*);
     622typedef void (KRB5_CALLCONV * krb5_log_log_func_t)(const char*, const char*, void*);
     623typedef void (KRB5_CALLCONV * krb5_log_close_func_t)(void*);
    599624
    600625typedef struct krb5_log_facility {
     
    631656} krb5_prompt;
    632657
    633 typedef int (*krb5_prompter_fct)(krb5_context /*context*/,
    634                                  void * /*data*/,
    635                                  const char * /*name*/,
    636                                  const char * /*banner*/,
    637                                  int /*num_prompts*/,
    638                                  krb5_prompt /*prompts*/[]);
    639 typedef krb5_error_code (*krb5_key_proc)(krb5_context /*context*/,
    640                                          krb5_enctype /*type*/,
    641                                          krb5_salt /*salt*/,
    642                                          krb5_const_pointer /*keyseed*/,
    643                                          krb5_keyblock ** /*key*/);
    644 typedef krb5_error_code (*krb5_decrypt_proc)(krb5_context /*context*/,
    645                                              krb5_keyblock * /*key*/,
    646                                              krb5_key_usage /*usage*/,
    647                                              krb5_const_pointer /*decrypt_arg*/,
    648                                              krb5_kdc_rep * /*dec_rep*/);
    649 typedef krb5_error_code (*krb5_s2k_proc)(krb5_context /*context*/,
    650                                          krb5_enctype /*type*/,
    651                                          krb5_const_pointer /*keyseed*/,
    652                                          krb5_salt /*salt*/,
    653                                          krb5_data * /*s2kparms*/,
    654                                          krb5_keyblock ** /*key*/);
     658typedef int (KRB5_CALLCONV * krb5_prompter_fct)(krb5_context /*context*/,
     659                                                void * /*data*/,
     660                                                const char * /*name*/,
     661                                                const char * /*banner*/,
     662                                                int /*num_prompts*/,
     663                                                krb5_prompt /*prompts*/[]);
     664typedef krb5_error_code (KRB5_CALLCONV * krb5_key_proc)(krb5_context /*context*/,
     665                                                        krb5_enctype /*type*/,
     666                                                        krb5_salt /*salt*/,
     667                                                        krb5_const_pointer /*keyseed*/,
     668                                                        krb5_keyblock ** /*key*/);
     669typedef krb5_error_code (KRB5_CALLCONV * krb5_decrypt_proc)(krb5_context /*context*/,
     670                                                            krb5_keyblock * /*key*/,
     671                                                            krb5_key_usage /*usage*/,
     672                                                            krb5_const_pointer /*decrypt_arg*/,
     673                                                            krb5_kdc_rep * /*dec_rep*/);
     674typedef krb5_error_code (KRB5_CALLCONV * krb5_s2k_proc)(krb5_context /*context*/,
     675                                                        krb5_enctype /*type*/,
     676                                                        krb5_const_pointer /*keyseed*/,
     677                                                        krb5_salt /*salt*/,
     678                                                        krb5_data * /*s2kparms*/,
     679                                                        krb5_keyblock ** /*key*/);
    655680
    656681struct _krb5_get_init_creds_opt_private;
     
    687712#define KRB5_GET_INIT_CREDS_OPT_DISABLE_TRANSITED_CHECK 0x0200
    688713
     714/* krb5_init_creds_step flags argument */
     715#define KRB5_INIT_CREDS_STEP_FLAG_CONTINUE      0x0001
     716
    689717typedef struct _krb5_verify_init_creds_opt {
    690718    krb5_flags flags;
     
    746774};
    747775
    748 typedef krb5_error_code (*krb5_send_to_kdc_func)(krb5_context,
    749                                                  void *,
    750                                                  krb5_krbhst_info *,
    751                                                  time_t,
    752                                                  const krb5_data *,
    753                                                  krb5_data *);
     776typedef krb5_error_code
     777(KRB5_CALLCONV * krb5_send_to_kdc_func)(krb5_context, void *, krb5_krbhst_info *, time_t,
     778                                        const krb5_data *, krb5_data *);
    754779
    755780/** flags for krb5_parse_name_flags */
     
    773798#define KRB5_SENDTO_CONTINUE    2
    774799
    775 typedef krb5_error_code (*krb5_sendto_ctx_func)(krb5_context, krb5_sendto_ctx, void *, const krb5_data *, int *);
     800typedef krb5_error_code
     801(KRB5_CALLCONV * krb5_sendto_ctx_func)(krb5_context, krb5_sendto_ctx, void *,
     802                                       const krb5_data *, int *);
    776803
    777804struct krb5_plugin;
     
    817844
    818845typedef krb5_error_code
    819 (*krb5_gic_process_last_req)(krb5_context, krb5_last_req_entry **, void *);
     846(KRB5_CALLCONV * krb5_gic_process_last_req)(krb5_context, krb5_last_req_entry **, void *);
    820847
    821848/*
    822849 *
    823850 */
     851
     852struct hx509_certs_data;
    824853
    825854#include <krb5-protos.h>
     
    835864extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_mcc_ops;
    836865extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_kcm_ops;
     866extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_akcm_ops;
    837867extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_scc_ops;
    838868
     
    842872extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_mkt_ops;
    843873extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_akf_ops;
    844 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb4_fkt_ops;
    845 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_srvtab_fkt_ops;
    846874extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_any_ops;
    847875
  • trunk/server/source4/heimdal/lib/krb5/krb5_locl.h

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    4648#include <limits.h>
    4749
     50#include <krb5-types.h>
     51
    4852#ifdef HAVE_SYS_TYPES_H
    4953#include <sys/types.h>
     
    114118#include <sys/file.h>
    115119#endif
     120
     121#include <com_err.h>
     122
     123#include <heimbase.h>
    116124
    117125#define HEIMDAL_TEXTDOMAIN "heimdal_krb5"
     
    152160
    153161/* XXX glue for pkinit */
     162struct hx509_certs_data;
    154163struct krb5_pk_identity;
    155164struct krb5_pk_cert;
     
    170179#include <hx509.h>
    171180#endif
     181
     182#include "crypto.h"
     183
    172184#include <krb5-private.h>
    173185
     
    176188#define ALLOC(X, N) (X) = calloc((N), sizeof(*(X)))
    177189#define ALLOC_SEQ(X, N) do { (X)->len = (N); ALLOC((X)->val, (N)); } while(0)
     190
     191#ifndef PATH_SEP
     192#define PATH_SEP ":"
     193#endif
    178194
    179195/* should this be public? */
     
    181197#define KEYTAB_DEFAULT_MODIFY "FILE:" SYSCONFDIR "/krb5.keytab"
    182198
     199
    183200#define MODULI_FILE SYSCONFDIR "/krb5.moduli"
    184201
     
    196213
    197214
    198 #define KRB5_BUFSIZ 1024
     215#define KRB5_BUFSIZ 2048
    199216
    200217typedef enum {
     
    217234#define KRB5_INIT_CREDS_CANONICALIZE            1
    218235#define KRB5_INIT_CREDS_NO_C_CANON_CHECK        2
     236#define KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK       4
    219237    struct {
    220238        krb5_gic_process_last_req func;
     
    235253    struct et_list *et_list;
    236254    struct krb5_log_facility *warn_dest;
    237     krb5_cc_ops *cc_ops;
     255    struct krb5_log_facility *debug_dest;
     256    const krb5_cc_ops **cc_ops;
    238257    int num_cc_ops;
    239258    const char *http_proxy;
     
    264283#define KRB5_CTX_F_CHECK_PAC                    2
    265284#define KRB5_CTX_F_HOMEDIR_ACCESS               4
     285#define KRB5_CTX_F_SOCKETS_INITIALIZED          8
     286#define KRB5_CTX_F_RD_REQ_IGNORE                16
    266287    struct send_to_kdc *send_to_kdc;
     288#ifdef PKINIT
     289    hx509_context hx509ctx;
     290#endif
    267291} krb5_context_data;
    268292
     293#ifndef KRB5_USE_PATH_TOKENS
    269294#define KRB5_DEFAULT_CCNAME_FILE "FILE:/tmp/krb5cc_%{uid}"
     295#else
     296#define KRB5_DEFAULT_CCNAME_FILE "FILE:%{TEMP}/krb5cc_%{uid}"
     297#endif
    270298#define KRB5_DEFAULT_CCNAME_API "API:"
    271 #define KRB5_DEFAULT_CCNAME_KCM "KCM:%{uid}"
     299#define KRB5_DEFAULT_CCNAME_KCM_KCM "KCM:%{uid}"
     300#define KRB5_DEFAULT_CCNAME_KCM_API "API:%{uid}"
    272301
    273302#define EXTRACT_TICKET_ALLOW_CNAME_MISMATCH             1
     
    275304#define EXTRACT_TICKET_MATCH_REALM                      4
    276305#define EXTRACT_TICKET_AS_REQ                           8
     306#define EXTRACT_TICKET_TIMESYNC                         16
    277307
    278308/*
     
    292322#endif
    293323
     324#ifndef KRB5_FORWARDABLE_DEFAULT
     325#define KRB5_FORWARDABLE_DEFAULT TRUE
     326#endif
     327
    294328#ifdef PKINIT
    295329
    296330struct krb5_pk_identity {
    297     hx509_context hx509ctx;
    298331    hx509_verify_ctx verify_ctx;
    299332    hx509_certs certs;
     
    302335    hx509_certs certpool;
    303336    hx509_revoke_ctx revokectx;
     337    int flags;
     338#define PKINIT_BTMM 1
    304339};
    305340
  • trunk/server/source4/heimdal/lib/krb5/krbhst.c

    r414 r745  
    8787
    8888    r = rk_dns_lookup(domain, dns_type);
    89     if(r == NULL)
     89    if(r == NULL) {
     90        _krb5_debug(context, 0,
     91                    "DNS lookup failed domain: %s", domain);
    9092        return KRB5_KDC_UNREACH;
     93    }
    9194
    9295    for(num_srv = 0, rr = r->head; rr; rr = rr->next)
     
    177180}
    178181
     182/*
     183 *
     184 */
     185
     186const char *
     187_krb5_krbhst_get_realm(krb5_krbhst_handle handle)
     188{
     189    return handle->realm;
     190}
    179191
    180192/*
     
    187199               const char *spec, int def_port, int port)
    188200{
    189     const char *p = spec;
     201    const char *p = spec, *q;
    190202    struct krb5_krbhst_info *hi;
    191203
     
    210222    }
    211223
    212     if(strsep_copy(&p, ":", hi->hostname, strlen(spec) + 1) < 0) {
     224    if (p[0] == '[' && (q = strchr(p, ']')) != NULL) {
     225        /* if address looks like [foo:bar] or [foo:bar]: its a ipv6
     226           adress, strip of [] */
     227        memcpy(hi->hostname, &p[1], q - p - 1);
     228        hi->hostname[q - p - 1] = '\0';
     229        p = q + 1;
     230        /* get trailing : */
     231        if (p[0] == ':')
     232            p++;
     233    } else if(strsep_copy(&p, ":", hi->hostname, strlen(spec) + 1) < 0) {
     234        /* copy everything before : */
    213235        free(hi);
    214236        return NULL;
     
    219241
    220242    hi->port = hi->def_port = def_port;
    221     if(p != NULL) {
     243    if(p != NULL && p[0]) {
    222244        char *end;
    223245        hi->port = strtol(p, &end, 0);
     
    299321 */
    300322
    301 krb5_error_code KRB5_LIB_FUNCTION
     323KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    302324krb5_krbhst_format_string(krb5_context context, const krb5_krbhst_info *host,
    303325                          char *hostname, size_t hostlen)
     
    335357}
    336358
    337 /*
    338  * return an `struct addrinfo *' in `ai' corresponding to the information
    339  * in `host'.  free:ing is handled by krb5_krbhst_free.
    340  */
    341 
    342 krb5_error_code KRB5_LIB_FUNCTION
     359/**
     360 * Return an `struct addrinfo *' for a KDC host.
     361 *
     362 * Returns an the struct addrinfo in in that corresponds to the
     363 * information in `host'.  free:ing is handled by krb5_krbhst_free, so
     364 * the returned ai must not be released.
     365 *
     366 * @ingroup krb5
     367 */
     368
     369KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    343370krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host,
    344371                         struct addrinfo **ai)
    345372{
    346     struct addrinfo hints;
    347     char portstr[NI_MAXSERV];
    348     int ret;
     373    int ret = 0;
    349374
    350375    if (host->ai == NULL) {
     376        struct addrinfo hints;
     377        char portstr[NI_MAXSERV];
     378        char *hostname = host->hostname;
     379
     380        snprintf (portstr, sizeof(portstr), "%d", host->port);
    351381        make_hints(&hints, host->proto);
    352         snprintf (portstr, sizeof(portstr), "%d", host->port);
     382
     383        /**
     384         * First try this as an IP address, this allows us to add a
     385         * dot at the end to stop using the search domains.
     386         */
     387
     388        hints.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;
     389
    353390        ret = getaddrinfo(host->hostname, portstr, &hints, &host->ai);
    354         if (ret)
    355             return krb5_eai_to_heim_errno(ret, errno);
    356     }
     391        if (ret == 0)
     392            goto out;
     393
     394        /**
     395         * If the hostname contains a dot, assumes it's a FQDN and
     396         * don't use search domains since that might be painfully slow
     397         * when machine is disconnected from that network.
     398         */
     399
     400        hints.ai_flags &= ~(AI_NUMERICHOST);
     401
     402        if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] != '.') {
     403            ret = asprintf(&hostname, "%s.", host->hostname);
     404            if (ret < 0 || hostname == NULL)
     405                return ENOMEM;
     406        }
     407
     408        ret = getaddrinfo(hostname, portstr, &hints, &host->ai);
     409        if (hostname != host->hostname)
     410            free(hostname);
     411        if (ret) {
     412            ret = krb5_eai_to_heim_errno(ret, errno);
     413            goto out;
     414        }
     415    }
     416 out:
    357417    *ai = host->ai;
    358     return 0;
     418    return ret;
    359419}
    360420
     
    375435              const char *proto, const char *service)
    376436{
     437    krb5_error_code ret;
    377438    krb5_krbhst_info **res;
    378439    int count, i;
    379440
    380     if (srv_find_realm(context, &res, &count, kd->realm, "SRV", proto, service,
    381                        kd->port))
     441    ret = srv_find_realm(context, &res, &count, kd->realm, "SRV", proto, service,
     442                         kd->port);
     443    _krb5_debug(context, 2, "searching DNS for realm %s %s.%s -> %d",
     444                kd->realm, proto, service, ret);
     445    if (ret)
    382446        return;
    383447    for(i = 0; i < count; i++)
     
    396460{
    397461    int i;
    398        
    399462    char **hostlist;
    400463    hostlist = krb5_config_get_strings(context, NULL,
    401464                                       "realms", kd->realm, conf_string, NULL);
     465
     466    _krb5_debug(context, 2, "configuration file for realm %s%s found",
     467                kd->realm, hostlist ? "" : " not");
    402468
    403469    if(hostlist == NULL)
     
    421487                   const char *serv_string, int port, int proto)
    422488{
    423     char *host;
     489    char *host = NULL;
    424490    int ret;
    425491    struct addrinfo *ai;
    426492    struct addrinfo hints;
    427493    char portstr[NI_MAXSERV];
     494
     495    _krb5_debug(context, 2, "fallback lookup %d for realm %s (service %s)",
     496                kd->fallback_count, kd->realm, serv_string);
    428497
    429498    /*
     
    437506
    438507    if(kd->fallback_count == 0)
    439         asprintf(&host, "%s.%s.", serv_string, kd->realm);
     508        ret = asprintf(&host, "%s.%s.", serv_string, kd->realm);
    440509    else
    441         asprintf(&host, "%s-%d.%s.",
    442                  serv_string, kd->fallback_count, kd->realm);   
    443 
    444     if (host == NULL)
     510        ret = asprintf(&host, "%s-%d.%s.",
     511                       serv_string, kd->fallback_count, kd->realm);     
     512
     513    if (ret < 0 || host == NULL)
    445514        return ENOMEM;
    446515
     
    546615                                   kd->realm, ret);
    547616            break;
    548         } else if (ret == 0)
     617        } else if (ret == 0) {
     618            _krb5_debug(context, 2, "plugin found result for realm %s", kd->realm);
    549619            kd->flags |= KD_CONFIG_EXISTS;
     620        }
    550621
    551622    }
     
    578649    }
    579650
    580     if (kd->flags & KD_CONFIG_EXISTS)
    581         return KRB5_KDC_UNREACH; /* XXX */
     651    if (kd->flags & KD_CONFIG_EXISTS) {
     652        _krb5_debug(context, 1,
     653                    "Configuration exists for realm %s, wont go to DNS",
     654                    kd->realm);
     655        return KRB5_KDC_UNREACH;
     656    }
    582657
    583658    if(context->srv_lookup) {
     
    613688    }
    614689
     690    _krb5_debug(context, 0, "No KDC entries found for %s", kd->realm);
     691
    615692    return KRB5_KDC_UNREACH; /* XXX */
    616693}
     
    637714    }
    638715
    639     if (kd->flags & KD_CONFIG_EXISTS)
    640         return KRB5_KDC_UNREACH; /* XXX */
     716    if (kd->flags & KD_CONFIG_EXISTS) {
     717        _krb5_debug(context, 1,
     718                    "Configuration exists for realm %s, wont go to DNS",
     719                    kd->realm);
     720        return KRB5_KDC_UNREACH;
     721    }
    641722
    642723    if(context->srv_lookup) {
     
    661742    }
    662743
     744    _krb5_debug(context, 0, "No admin entries found for realm %s", kd->realm);
     745
    663746    return KRB5_KDC_UNREACH;    /* XXX */
    664747}
     
    685768    }
    686769
    687     if (kd->flags & KD_CONFIG_EXISTS)
    688         return KRB5_KDC_UNREACH; /* XXX */
     770    if (kd->flags & KD_CONFIG_EXISTS) {
     771        _krb5_debug(context, 1,
     772                    "Configuration exists for realm %s, wont go to DNS",
     773                    kd->realm);
     774        return KRB5_KDC_UNREACH;
     775    }
    689776
    690777    if(context->srv_lookup) {
     
    715802    }
    716803
    717     return KRB5_KDC_UNREACH; /* XXX */
     804    _krb5_debug(context, 0, "No kpasswd entries found for realm %s", kd->realm);
     805
     806    return KRB5_KDC_UNREACH;
    718807}
    719808
     
    737826    }
    738827
    739     if (kd->flags & KD_CONFIG_EXISTS)
    740         return KRB5_KDC_UNREACH; /* XXX */
     828    if (kd->flags & KD_CONFIG_EXISTS) {
     829        _krb5_debug(context, 1,
     830                    "Configuration exists for realm %s, wont go to DNS",
     831                    kd->realm);
     832        return KRB5_KDC_UNREACH;
     833    }
    741834
    742835    if(context->srv_lookup) {
     
    765858    }
    766859
    767     return KRB5_KDC_UNREACH; /* XXX */
     860    _krb5_debug(context, 0, "No kpasswd entries found for realm %s", kd->realm);
     861
     862    return KRB5_KDC_UNREACH;
    768863}
    769864
    770865static struct krb5_krbhst_data*
    771866common_init(krb5_context context,
     867            const char *service,
    772868            const char *realm,
    773869            int flags)
     
    782878        return NULL;
    783879    }
     880
     881    _krb5_debug(context, 2, "Trying to find service %s for realm %s flags %x",
     882                service, realm, flags);
    784883
    785884    /* For 'realms' without a . do not even think of going to DNS */
     
    797896 */
    798897
    799 krb5_error_code KRB5_LIB_FUNCTION
     898KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    800899krb5_krbhst_init(krb5_context context,
    801900                 const char *realm,
     
    806905}
    807906
    808 krb5_error_code KRB5_LIB_FUNCTION
     907KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    809908krb5_krbhst_init_flags(krb5_context context,
    810909                       const char *realm,
     
    817916                            krb5_krbhst_info **);
    818917    int def_port;
     918    const char *service;
    819919
    820920    switch(type) {
     
    822922        next = kdc_get_next;
    823923        def_port = ntohs(krb5_getportbyname (context, "kerberos", "udp", 88));
     924        service = "kdc";
    824925        break;
    825926    case KRB5_KRBHST_ADMIN:
     
    827928        def_port = ntohs(krb5_getportbyname (context, "kerberos-adm",
    828929                                             "tcp", 749));
     930        service = "admin";
    829931        break;
    830932    case KRB5_KRBHST_CHANGEPW:
     
    832934        def_port = ntohs(krb5_getportbyname (context, "kpasswd", "udp",
    833935                                             KPASSWD_PORT));
     936        service = "change_password";
    834937        break;
    835938    case KRB5_KRBHST_KRB524:
    836939        next = krb524_get_next;
    837940        def_port = ntohs(krb5_getportbyname (context, "krb524", "udp", 4444));
     941        service = "524";
    838942        break;
    839943    default:
     
    842946        return ENOTTY;
    843947    }
    844     if((kd = common_init(context, realm, flags)) == NULL)
     948    if((kd = common_init(context, service, realm, flags)) == NULL)
    845949        return ENOMEM;
    846950    kd->get_next = next;
     
    854958 */
    855959
    856 krb5_error_code KRB5_LIB_FUNCTION
     960KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    857961krb5_krbhst_next(krb5_context context,
    858962                 krb5_krbhst_handle handle,
     
    870974 */
    871975
    872 krb5_error_code KRB5_LIB_FUNCTION
     976KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    873977krb5_krbhst_next_as_string(krb5_context context,
    874978                           krb5_krbhst_handle handle,
     
    885989
    886990
    887 void KRB5_LIB_FUNCTION
     991KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    888992krb5_krbhst_reset(krb5_context context, krb5_krbhst_handle handle)
    889993{
     
    891995}
    892996
    893 void KRB5_LIB_FUNCTION
     997KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    894998krb5_krbhst_free(krb5_context context, krb5_krbhst_handle handle)
    895999{
     
    9561060 */
    9571061
    958 krb5_error_code KRB5_LIB_FUNCTION
     1062KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9591063krb5_get_krb_admin_hst (krb5_context context,
    9601064                        const krb5_realm *realm,
     
    9681072 */
    9691073
    970 krb5_error_code KRB5_LIB_FUNCTION
     1074KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9711075krb5_get_krb_changepw_hst (krb5_context context,
    9721076                           const krb5_realm *realm,
     
    9801084 */
    9811085
    982 krb5_error_code KRB5_LIB_FUNCTION
     1086KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9831087krb5_get_krb524hst (krb5_context context,
    9841088                    const krb5_realm *realm,
     
    9931097 */
    9941098
    995 krb5_error_code KRB5_LIB_FUNCTION
     1099KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9961100krb5_get_krbhst (krb5_context context,
    9971101                 const krb5_realm *realm,
     
    10051109 */
    10061110
    1007 krb5_error_code KRB5_LIB_FUNCTION
     1111KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10081112krb5_free_krbhst (krb5_context context,
    10091113                  char **hostlist)
  • trunk/server/source4/heimdal/lib/krb5/log.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    114116}
    115117
    116 krb5_error_code KRB5_LIB_FUNCTION
     118KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    117119krb5_initlog(krb5_context context,
    118120             const char *program,
     
    136138}
    137139
    138 krb5_error_code KRB5_LIB_FUNCTION
     140KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    139141krb5_addlog_func(krb5_context context,
    140142                 krb5_log_facility *fac,
     
    164166};
    165167
    166 static void
     168static void KRB5_CALLCONV
    167169log_syslog(const char *timestr,
    168170           const char *msg,
     
    174176}
    175177
    176 static void
     178static void KRB5_CALLCONV
    177179close_syslog(void *data)
    178180{
     
    214216};
    215217
    216 static void
     218static void KRB5_CALLCONV
    217219log_file(const char *timestr,
    218220         const char *msg,
     
    240242}
    241243
    242 static void
     244static void KRB5_CALLCONV
    243245close_file(void *data)
    244246{
     
    269271
    270272
    271 krb5_error_code KRB5_LIB_FUNCTION
     273KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    272274krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig)
    273275{
     
    360362
    361363
    362 krb5_error_code KRB5_LIB_FUNCTION
     364KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    363365krb5_openlog(krb5_context context,
    364366             const char *program,
     
    384386}
    385387
    386 krb5_error_code KRB5_LIB_FUNCTION
     388KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    387389krb5_closelog(krb5_context context,
    388390              krb5_log_facility *fac)
     
    403405#define __attribute__(X)
    404406
    405 krb5_error_code KRB5_LIB_FUNCTION
     407KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    406408krb5_vlog_msg(krb5_context context,
    407409              krb5_log_facility *fac,
     
    427429            }
    428430            if(actual == NULL) {
    429                 vasprintf(&msg, fmt, ap);
    430                 if(msg == NULL)
     431                int ret = vasprintf(&msg, fmt, ap);
     432                if(ret < 0 || msg == NULL)
    431433                    actual = fmt;
    432434                else
     
    442444}
    443445
    444 krb5_error_code KRB5_LIB_FUNCTION
     446KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    445447krb5_vlog(krb5_context context,
    446448          krb5_log_facility *fac,
     
    453455}
    454456
    455 krb5_error_code KRB5_LIB_FUNCTION
     457KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    456458krb5_log_msg(krb5_context context,
    457459             krb5_log_facility *fac,
     
    472474
    473475
    474 krb5_error_code KRB5_LIB_FUNCTION
     476KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    475477krb5_log(krb5_context context,
    476478         krb5_log_facility *fac,
     
    489491}
    490492
     493void KRB5_LIB_FUNCTION
     494_krb5_debug(krb5_context context,
     495            int level,
     496            const char *fmt,
     497            ...)
     498    __attribute__((format (printf, 3, 4)))
     499{
     500    va_list ap;
     501
     502    if (context == NULL || context->debug_dest == NULL)
     503        return;
     504       
     505    va_start(ap, fmt);
     506    krb5_vlog(context, context->debug_dest, level, fmt, ap);
     507    va_end(ap);
     508}
     509
     510krb5_boolean KRB5_LIB_FUNCTION
     511_krb5_have_debug(krb5_context context, int level)
     512{
     513    if (context == NULL || context->debug_dest == NULL)
     514        return 0 ;
     515    return 1;
     516}
  • trunk/server/source4/heimdal/lib/krb5/mcache.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    4547    struct krb5_mcache *next;
    4648    time_t mtime;
     49    krb5_deltat kdc_offset;
    4750} krb5_mcache;
    4851
     
    5457#define MISDEAD(X)      ((X)->dead)
    5558
    56 static const char*
     59static const char* KRB5_CALLCONV
    5760mcc_get_name(krb5_context context,
    5861             krb5_ccache id)
     
    6164}
    6265
    63 static krb5_mcache *
     66static krb5_mcache * KRB5_CALLCONV
    6467mcc_alloc(const char *name)
    6568{
    6669    krb5_mcache *m, *m_c;
     70    int ret = 0;
    6771
    6872    ALLOC(m, 1);
     
    7074        return NULL;
    7175    if(name == NULL)
    72         asprintf(&m->name, "%p", m);
     76        ret = asprintf(&m->name, "%p", m);
    7377    else
    7478        m->name = strdup(name);
    75     if(m->name == NULL) {
     79    if(ret < 0 || m->name == NULL) {
    7680        free(m);
    7781        return NULL;
     
    9498    m->creds = NULL;
    9599    m->mtime = time(NULL);
     100    m->kdc_offset = 0;
    96101    m->next = mcc_head;
    97102    mcc_head = m;
     
    100105}
    101106
    102 static krb5_error_code
     107static krb5_error_code KRB5_CALLCONV
    103108mcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
    104109{
     
    132137
    133138
    134 static krb5_error_code
     139static krb5_error_code KRB5_CALLCONV
    135140mcc_gen_new(krb5_context context, krb5_ccache *id)
    136141{
     
    151156}
    152157
    153 static krb5_error_code
     158static krb5_error_code KRB5_CALLCONV
    154159mcc_initialize(krb5_context context,
    155160               krb5_ccache id,
     
    177182}
    178183
    179 static krb5_error_code
     184static krb5_error_code KRB5_CALLCONV
    180185mcc_close(krb5_context context,
    181186          krb5_ccache id)
     
    186191}
    187192
    188 static krb5_error_code
     193static krb5_error_code KRB5_CALLCONV
    189194mcc_destroy(krb5_context context,
    190195            krb5_ccache id)
     
    227232}
    228233
    229 static krb5_error_code
     234static krb5_error_code KRB5_CALLCONV
    230235mcc_store_cred(krb5_context context,
    231236               krb5_ccache id,
     
    258263}
    259264
    260 static krb5_error_code
     265static krb5_error_code KRB5_CALLCONV
    261266mcc_get_principal(krb5_context context,
    262267                  krb5_ccache id,
     
    272277}
    273278
    274 static krb5_error_code
     279static krb5_error_code KRB5_CALLCONV
    275280mcc_get_first (krb5_context context,
    276281               krb5_ccache id,
     
    286291}
    287292
    288 static krb5_error_code
     293static krb5_error_code KRB5_CALLCONV
    289294mcc_get_next (krb5_context context,
    290295              krb5_ccache id,
     
    308313}
    309314
    310 static krb5_error_code
     315static krb5_error_code KRB5_CALLCONV
    311316mcc_end_get (krb5_context context,
    312317             krb5_ccache id,
     
    316321}
    317322
    318 static krb5_error_code
     323static krb5_error_code KRB5_CALLCONV
    319324mcc_remove_cred(krb5_context context,
    320325                 krb5_ccache id,
     
    336341}
    337342
    338 static krb5_error_code
     343static krb5_error_code KRB5_CALLCONV
    339344mcc_set_flags(krb5_context context,
    340345              krb5_ccache id,
     
    348353};
    349354
    350 static krb5_error_code
     355static krb5_error_code KRB5_CALLCONV
    351356mcc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
    352357{
     
    370375}
    371376
    372 static krb5_error_code
     377static krb5_error_code KRB5_CALLCONV
    373378mcc_get_cache_next(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
    374379{
     
    397402}
    398403
    399 static krb5_error_code
     404static krb5_error_code KRB5_CALLCONV
    400405mcc_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
    401406{
     
    409414}
    410415
    411 static krb5_error_code
     416static krb5_error_code KRB5_CALLCONV
    412417mcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
    413418{
     
    444449}
    445450
    446 static krb5_error_code
     451static krb5_error_code KRB5_CALLCONV
    447452mcc_default_name(krb5_context context, char **str)
    448453{
     
    456461}
    457462
    458 static krb5_error_code
     463static krb5_error_code KRB5_CALLCONV
    459464mcc_lastchange(krb5_context context, krb5_ccache id, krb5_timestamp *mtime)
    460465{
    461466    *mtime = MCACHE(id)->mtime;
     467    return 0;
     468}
     469
     470static krb5_error_code KRB5_CALLCONV
     471mcc_set_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat kdc_offset)
     472{
     473    krb5_mcache *m = MCACHE(id);
     474    m->kdc_offset = kdc_offset;
     475    return 0;
     476}
     477
     478static krb5_error_code KRB5_CALLCONV
     479mcc_get_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat *kdc_offset)
     480{
     481    krb5_mcache *m = MCACHE(id);
     482    *kdc_offset = m->kdc_offset;
    462483    return 0;
    463484}
     
    494515    mcc_default_name,
    495516    NULL,
    496     mcc_lastchange
     517    mcc_lastchange,
     518    mcc_set_kdc_offset,
     519    mcc_get_kdc_offset
    497520};
  • trunk/server/source4/heimdal/lib/krb5/misc.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737_krb5_s4u2self_to_checksumdata(krb5_context context,
    3838                               const PA_S4U2Self *self,
     
    8383    return ret;
    8484}
     85
     86krb5_error_code
     87krb5_enomem(krb5_context context)
     88{
     89    krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
     90    return ENOMEM;
     91}
  • trunk/server/source4/heimdal/lib/krb5/mit_glue.c

    r414 r745  
    4242 */
    4343
    44 krb5_error_code KRB5_LIB_FUNCTION
     44KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4545krb5_c_make_checksum(krb5_context context,
    4646                     krb5_cksumtype cksumtype,
     
    6464}
    6565
    66 krb5_error_code KRB5_LIB_FUNCTION
     66KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6767krb5_c_verify_checksum(krb5_context context, const krb5_keyblock *key,
    6868                       krb5_keyusage usage, const krb5_data *data,
     
    8080
    8181    if (data_cksum.cksumtype == cksum->cksumtype
    82         && data_cksum.checksum.length == cksum->checksum.length
    83         && memcmp(data_cksum.checksum.data, cksum->checksum.data, cksum->checksum.length) == 0)
     82        && krb5_data_ct_cmp(&data_cksum.checksum, &cksum->checksum) == 0)
    8483        *valid = 1;
    8584
     
    8988}
    9089
    91 krb5_error_code KRB5_LIB_FUNCTION
     90KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9291krb5_c_get_checksum(krb5_context context, const krb5_checksum *cksum,
    9392                    krb5_cksumtype *type, krb5_data **data)
     
    112111}
    113112
    114 krb5_error_code KRB5_LIB_FUNCTION
     113KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    115114krb5_c_set_checksum(krb5_context context, krb5_checksum *cksum,
    116115                    krb5_cksumtype type, const krb5_data *data)
     
    120119}
    121120
    122 void KRB5_LIB_FUNCTION
     121KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    123122krb5_free_checksum (krb5_context context, krb5_checksum *cksum)
    124123{
     
    127126}
    128127
    129 void KRB5_LIB_FUNCTION
     128KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    130129krb5_free_checksum_contents(krb5_context context, krb5_checksum *cksum)
    131130{
     
    134133}
    135134
    136 void KRB5_LIB_FUNCTION
     135KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    137136krb5_checksum_free(krb5_context context, krb5_checksum *cksum)
    138137{
     
    140139}
    141140
    142 krb5_boolean KRB5_LIB_FUNCTION
     141KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    143142krb5_c_valid_enctype (krb5_enctype etype)
    144143{
     
    146145}
    147146
    148 krb5_boolean KRB5_LIB_FUNCTION
     147KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    149148krb5_c_valid_cksumtype(krb5_cksumtype ctype)
    150149{
     
    152151}
    153152
    154 krb5_boolean KRB5_LIB_FUNCTION
     153KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    155154krb5_c_is_coll_proof_cksum(krb5_cksumtype ctype)
    156155{
     
    158157}
    159158
    160 krb5_boolean KRB5_LIB_FUNCTION
     159KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    161160krb5_c_is_keyed_cksum(krb5_cksumtype ctype)
    162161{
     
    164163}
    165164
    166 krb5_error_code KRB5_LIB_FUNCTION
     165KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    167166krb5_copy_checksum (krb5_context context,
    168167                    const krb5_checksum *old,
     
    175174}
    176175
    177 krb5_error_code KRB5_LIB_FUNCTION
     176KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    178177krb5_c_checksum_length (krb5_context context, krb5_cksumtype cksumtype,
    179178                        size_t *length)
     
    182181}
    183182
    184 krb5_error_code KRB5_LIB_FUNCTION
     183KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    185184krb5_c_block_size(krb5_context context,
    186185                  krb5_enctype enctype,
     
    205204}
    206205
    207 krb5_error_code KRB5_LIB_FUNCTION
     206KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    208207krb5_c_decrypt(krb5_context context,
    209208               const krb5_keyblock key,
     
    245244}
    246245
    247 krb5_error_code KRB5_LIB_FUNCTION
     246KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    248247krb5_c_encrypt(krb5_context context,
    249248               const krb5_keyblock *key,
     
    287286}
    288287
    289 krb5_error_code KRB5_LIB_FUNCTION
     288KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    290289krb5_c_encrypt_length(krb5_context context,
    291290                      krb5_enctype enctype,
     
    312311}
    313312
    314 krb5_error_code KRB5_LIB_FUNCTION
     313/**
     314 * Deprecated: keytypes doesn't exists, they are really enctypes.
     315 *
     316 * @ingroup krb5_deprecated
     317 */
     318
     319KRB5_DEPRECATED
     320KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    315321krb5_c_enctype_compare(krb5_context context,
    316322                       krb5_enctype e1,
    317323                       krb5_enctype e2,
    318324                       krb5_boolean *similar)
    319     KRB5_DEPRECATED
    320325{
    321326    *similar = (e1 == e2);
     
    323328}
    324329
    325 krb5_error_code KRB5_LIB_FUNCTION
     330KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    326331krb5_c_make_random_key(krb5_context context,
    327332                       krb5_enctype enctype,
     
    331336}
    332337
    333 krb5_error_code KRB5_LIB_FUNCTION
     338KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    334339krb5_c_keylengths(krb5_context context,
    335340                  krb5_enctype enctype,
     
    346351}
    347352
    348 krb5_error_code KRB5_LIB_FUNCTION
     353KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    349354krb5_c_prf_length(krb5_context context,
    350355                  krb5_enctype type,
     
    354359}
    355360
    356 krb5_error_code KRB5_LIB_FUNCTION
     361KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    357362krb5_c_prf(krb5_context context,
    358363           const krb5_keyblock *key,
     
    373378}
    374379
     380KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     381krb5_c_random_make_octets(krb5_context context, krb5_data * data)
     382{
     383    return krb5_generate_random_keyblock(context, data->length, data->data);
     384}
     385
    375386/**
    376387 * MIT compat glue
     
    379390 */
    380391
    381 krb5_error_code KRB5_LIB_FUNCTION
     392KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    382393krb5_cc_copy_creds(krb5_context context,
    383394                   const krb5_ccache from,
     
    387398}
    388399
     400KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     401krb5_auth_con_getsendsubkey(krb5_context context, krb5_auth_context auth_context,
     402                            krb5_keyblock **keyblock)
     403{
     404    return krb5_auth_con_getlocalsubkey(context, auth_context, keyblock);
     405}
     406
     407KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     408krb5_auth_con_getrecvsubkey(krb5_context context, krb5_auth_context auth_context,
     409                            krb5_keyblock **keyblock)
     410{
     411    return krb5_auth_con_getremotesubkey(context, auth_context, keyblock);
     412}
     413
     414KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     415krb5_auth_con_setsendsubkey(krb5_context context, krb5_auth_context auth_context,
     416                            krb5_keyblock *keyblock)
     417{
     418    return krb5_auth_con_setlocalsubkey(context, auth_context, keyblock);
     419}
     420
     421KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     422krb5_auth_con_setrecvsubkey(krb5_context context, krb5_auth_context auth_context,
     423                            krb5_keyblock *keyblock)
     424{
     425    return krb5_auth_con_setremotesubkey(context, auth_context, keyblock);
     426}
     427
     428KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     429krb5_free_default_realm(krb5_context context, krb5_realm realm)
     430{
     431    return krb5_xfree(realm);
     432}
     433
    389434#endif /* HEIMDAL_SMALLER */
  • trunk/server/source4/heimdal/lib/krb5/mk_error.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_mk_error(krb5_context context,
    3838              krb5_error_code error_code,
     
    4545              krb5_data *reply)
    4646{
     47    const char *e_text2 = NULL;
    4748    KRB_ERROR msg;
    4849    krb5_timestamp sec;
     
    6364    if(error_code < KRB5KDC_ERR_NONE || error_code >= KRB5_ERR_RCSID) {
    6465        if(e_text == NULL)
    65             e_text = krb5_get_err_text(context, error_code);
     66            e_text = e_text2 = krb5_get_error_message(context, error_code);
    6667        error_code = KRB5KRB_ERR_GENERIC;
    6768    }
     
    8384
    8485    ASN1_MALLOC_ENCODE(KRB_ERROR, reply->data, reply->length, &msg, &len, ret);
     86    if (e_text2)
     87        krb5_free_error_message(context, e_text2);
    8588    if (ret)
    8689        return ret;
  • trunk/server/source4/heimdal/lib/krb5/mk_priv.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_mk_priv(krb5_context context,
    3838             krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/mk_rep.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_mk_rep(krb5_context context,
    3838            krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/mk_req.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_mk_req_exact(krb5_context context,
    3838                  krb5_auth_context *auth_context,
     
    7878}
    7979
    80 krb5_error_code KRB5_LIB_FUNCTION
     80KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    8181krb5_mk_req(krb5_context context,
    8282            krb5_auth_context *auth_context,
  • trunk/server/source4/heimdal/lib/krb5/mk_req_ext.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    3636krb5_error_code
     
    124124        goto out;
    125125
    126     ret = krb5_build_authenticator (context,
     126    ret = _krb5_build_authenticator(context,
    127127                                    ac,
    128128                                    ac->keyblock->keytype,
    129129                                    in_creds,
    130130                                    c_opt,
    131                                     NULL,
    132131                                    &authenticator,
    133132                                    encrypt_usage);
     
    145144}
    146145
    147 krb5_error_code KRB5_LIB_FUNCTION
     146KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    148147krb5_mk_req_extended(krb5_context context,
    149148                     krb5_auth_context *auth_context,
  • trunk/server/source4/heimdal/lib/krb5/n-fold.c

    r414 r745  
    9797}
    9898
    99 krb5_error_code KRB5_LIB_FUNCTION
     99KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    100100_krb5_n_fold(const void *str, size_t len, void *key, size_t size)
    101101{
  • trunk/server/source4/heimdal/lib/krb5/pac.c

    r414 r745  
    7777
    7878/*
    79  *
     79 * HMAC-MD5 checksum over any key (needed for the PAC routines)
    8080 */
    8181
    82 krb5_error_code
     82static krb5_error_code
     83HMAC_MD5_any_checksum(krb5_context context,
     84                      const krb5_keyblock *key,
     85                      const void *data,
     86                      size_t len,
     87                      unsigned usage,
     88                      Checksum *result)
     89{
     90    struct _krb5_key_data local_key;
     91    krb5_error_code ret;
     92
     93    memset(&local_key, 0, sizeof(local_key));
     94
     95    ret = krb5_copy_keyblock(context, key, &local_key.key);
     96    if (ret)
     97        return ret;
     98
     99    ret = krb5_data_alloc (&result->checksum, 16);
     100    if (ret) {
     101        krb5_free_keyblock(context, local_key.key);
     102        return ret;
     103    }
     104
     105    result->cksumtype = CKSUMTYPE_HMAC_MD5;
     106    ret = _krb5_HMAC_MD5_checksum(context, &local_key, data, len, usage, result);
     107    if (ret)
     108        krb5_data_free(&result->checksum);
     109   
     110    krb5_free_keyblock(context, local_key.key);
     111    return ret;
     112}
     113
     114
     115/*
     116 *
     117 */
     118
     119KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    83120krb5_pac_parse(krb5_context context, const void *ptr, size_t len,
    84121               krb5_pac *pac)
     
    91128    p = calloc(1, sizeof(*p));
    92129    if (p == NULL) {
    93         ret = ENOMEM;
    94         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     130        ret = krb5_enomem(context);
    95131        goto out;
    96132    }
     
    98134    sp = krb5_storage_from_readonly_mem(ptr, len);
    99135    if (sp == NULL) {
    100         ret = ENOMEM;
    101         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     136        ret = krb5_enomem(context);
    102137        goto out;
    103138    }
     
    122157                    sizeof(*p->pac) + (sizeof(p->pac->buffers[0]) * (tmp - 1)));
    123158    if (p->pac == NULL) {
    124         ret = ENOMEM;
    125         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     159        ret = krb5_enomem(context);
    126160        goto out;
    127161    }
     
    225259}
    226260
    227 krb5_error_code
     261KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    228262krb5_pac_init(krb5_context context, krb5_pac *pac)
    229263{
     
    233267    p = calloc(1, sizeof(*p));
    234268    if (p == NULL) {
    235         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    236         return ENOMEM;
     269        return krb5_enomem(context);
    237270    }
    238271
     
    240273    if (p->pac == NULL) {
    241274        free(p);
    242         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    243         return ENOMEM;
     275        return krb5_enomem(context);
    244276    }
    245277
     
    248280        free (p->pac);
    249281        free(p);
    250         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
    251         return ret;
    252     }
    253 
     282        return krb5_enomem(context);
     283    }
    254284
    255285    *pac = p;
     
    257287}
    258288
    259 krb5_error_code
     289KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    260290krb5_pac_add_buffer(krb5_context context, krb5_pac p,
    261291                    uint32_t type, const krb5_data *data)
     
    270300    ptr = realloc(p->pac,
    271301                  sizeof(*p->pac) + (sizeof(p->pac->buffers[0]) * len));
    272     if (ptr == NULL) {
    273         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    274         return ENOMEM;
    275     }
     302    if (ptr == NULL)
     303        return krb5_enomem(context);
     304
    276305    p->pac = ptr;
    277306
     
    339368 */
    340369
    341 krb5_error_code
     370KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    342371krb5_pac_get_buffer(krb5_context context, krb5_pac p,
    343372                    uint32_t type, krb5_data *data)
     
    369398 */
    370399
    371 krb5_error_code
     400KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    372401krb5_pac_get_types(krb5_context context,
    373402                   krb5_pac p,
     
    380409    if (*types == NULL) {
    381410        *len = 0;
    382         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    383         return ENOMEM;
     411        return krb5_enomem(context);
    384412    }
    385413    for (i = 0; i < p->pac->numbuffers; i++)
     
    394422 */
    395423
    396 void
     424KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    397425krb5_pac_free(krb5_context context, krb5_pac pac)
    398426{
     
    413441                const krb5_keyblock *key)
    414442{
    415     krb5_crypto crypto = NULL;
    416443    krb5_storage *sp = NULL;
    417444    uint32_t type;
     
    423450    sp = krb5_storage_from_mem((char *)data->data + sig->offset_lo,
    424451                               sig->buffersize);
    425     if (sp == NULL) {
    426         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    427         return ENOMEM;
    428     }
     452    if (sp == NULL)
     453        return krb5_enomem(context);
     454
    429455    krb5_storage_set_flags(sp, KRB5_STORAGE_BYTEORDER_LE);
    430456
     
    435461    cksum.checksum.data = malloc(cksum.checksum.length);
    436462    if (cksum.checksum.data == NULL) {
    437         ret = ENOMEM;
    438         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     463        ret = krb5_enomem(context);
    439464        goto out;
    440465    }
     
    453478    }
    454479
    455     ret = krb5_crypto_init(context, key, 0, &crypto);
    456     if (ret)
    457         goto out;
    458 
    459     ret = krb5_verify_checksum(context, crypto, KRB5_KU_OTHER_CKSUM,
    460                                ptr, len, &cksum);
     480    /* If the checksum is HMAC-MD5, the checksum type is not tied to
     481     * the key type, instead the HMAC-MD5 checksum is applied blindly
     482     * on whatever key is used for this connection, avoiding issues
     483     * with unkeyed checksums on des-cbc-md5 and des-cbc-crc.  See
     484     * http://comments.gmane.org/gmane.comp.encryption.kerberos.devel/8743
     485     * for the same issue in MIT, and
     486     * http://blogs.msdn.com/b/openspecification/archive/2010/01/01/verifying-the-server-signature-in-kerberos-privilege-account-certificate.aspx
     487     * for Microsoft's explaination */
     488
     489    if (cksum.cksumtype == CKSUMTYPE_HMAC_MD5) {
     490        Checksum local_checksum;
     491
     492        memset(&local_checksum, 0, sizeof(local_checksum));
     493
     494        ret = HMAC_MD5_any_checksum(context, key, ptr, len,
     495                                    KRB5_KU_OTHER_CKSUM, &local_checksum);
     496
     497        if (ret != 0 || krb5_data_ct_cmp(&local_checksum.checksum, &cksum.checksum) != 0) {
     498            ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
     499            krb5_set_error_message(context, ret,
     500                                   N_("PAC integrity check failed for "
     501                                      "hmac-md5 checksum", ""));
     502        }
     503        krb5_data_free(&local_checksum.checksum);
     504
     505   } else {
     506        krb5_crypto crypto = NULL;
     507
     508        ret = krb5_crypto_init(context, key, 0, &crypto);
     509        if (ret)
     510                goto out;
     511
     512        ret = krb5_verify_checksum(context, crypto, KRB5_KU_OTHER_CKSUM,
     513                                   ptr, len, &cksum);
     514        krb5_crypto_destroy(context, crypto);
     515    }
    461516    free(cksum.checksum.data);
    462     krb5_crypto_destroy(context, crypto);
    463517    krb5_storage_free(sp);
    464518
     
    470524    if (sp)
    471525        krb5_storage_free(sp);
    472     if (crypto)
    473         krb5_crypto_destroy(context, crypto);
    474526    return ret;
    475527}
     
    478530create_checksum(krb5_context context,
    479531                const krb5_keyblock *key,
     532                uint32_t cksumtype,
    480533                void *data, size_t datalen,
    481534                void *sig, size_t siglen)
     
    485538    Checksum cksum;
    486539
    487     ret = krb5_crypto_init(context, key, 0, &crypto);
    488     if (ret)
    489         return ret;
    490 
    491     ret = krb5_create_checksum(context, crypto, KRB5_KU_OTHER_CKSUM, 0,
    492                                data, datalen, &cksum);
    493     krb5_crypto_destroy(context, crypto);
    494     if (ret)
    495         return ret;
    496 
     540    /* If the checksum is HMAC-MD5, the checksum type is not tied to
     541     * the key type, instead the HMAC-MD5 checksum is applied blindly
     542     * on whatever key is used for this connection, avoiding issues
     543     * with unkeyed checksums on des-cbc-md5 and des-cbc-crc.  See
     544     * http://comments.gmane.org/gmane.comp.encryption.kerberos.devel/8743
     545     * for the same issue in MIT, and
     546     * http://blogs.msdn.com/b/openspecification/archive/2010/01/01/verifying-the-server-signature-in-kerberos-privilege-account-certificate.aspx
     547     * for Microsoft's explaination */
     548
     549    if (cksumtype == CKSUMTYPE_HMAC_MD5) {
     550        ret = HMAC_MD5_any_checksum(context, key, data, datalen,
     551                                    KRB5_KU_OTHER_CKSUM, &cksum);
     552    } else {
     553        ret = krb5_crypto_init(context, key, 0, &crypto);
     554        if (ret)
     555            return ret;
     556
     557        ret = krb5_create_checksum(context, crypto, KRB5_KU_OTHER_CKSUM, 0,
     558                                   data, datalen, &cksum);
     559        krb5_crypto_destroy(context, crypto);
     560        if (ret)
     561            return ret;
     562    }
    497563    if (cksum.checksum.length != siglen) {
    498564        krb5_set_error_message(context, EINVAL, "pac checksum wrong length");
     
    538604    sp = krb5_storage_from_readonly_mem((const char *)data->data + logon_name->offset_lo,
    539605                                        logon_name->buffersize);
    540     if (sp == NULL) {
    541         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    542         return ENOMEM;
    543     }
     606    if (sp == NULL)
     607        return krb5_enomem(context);
    544608
    545609    krb5_storage_set_flags(sp, KRB5_STORAGE_BYTEORDER_LE);
     
    568632    if (s == NULL) {
    569633        krb5_storage_free(sp);
    570         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    571         return ENOMEM;
     634        return krb5_enomem(context);
    572635    }
    573636    ret = krb5_storage_read(sp, s, len);
     
    585648
    586649        ucs2 = malloc(sizeof(ucs2[0]) * ucs2len);
    587         if (ucs2 == NULL) {
    588             krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    589             return ENOMEM;
    590         }
     650        if (ucs2 == NULL)
     651            return krb5_enomem(context);
     652
    591653        ret = wind_ucs2read(s, len, &flags, ucs2, &ucs2len);
    592654        free(s);
     
    606668        if (s == NULL) {
    607669            free(ucs2);
    608             krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    609             return ENOMEM;
     670            return krb5_enomem(context);
    610671        }
    611672        ret = wind_ucs2utf8(ucs2, ucs2len, s, &u8len);
     
    653714
    654715    sp = krb5_storage_emem();
    655     if (sp == NULL) {
    656         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    657         return ENOMEM;
    658     }
     716    if (sp == NULL)
     717        return krb5_enomem(context);
     718
    659719    krb5_storage_set_flags(sp, KRB5_STORAGE_BYTEORDER_LE);
    660720
     
    674734    s2 = malloc(len * 2);
    675735    if (s2 == NULL) {
    676         ret = ENOMEM;
     736        ret = krb5_enomem(context);
    677737        free(s);
    678738        goto out;
     
    690750    free(s2);
    691751    if (ret != len * 2) {
    692         ret = ENOMEM;
     752        ret = krb5_enomem(context);
    693753        goto out;
    694754    }
     
    721781 */
    722782
    723 krb5_error_code
     783KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    724784krb5_pac_verify(krb5_context context,
    725785                const krb5_pac pac,
     
    817877            l = sizeof(zeros);
    818878        sret = krb5_storage_write(sp, zeros, l);
    819         if (sret <= 0) {
    820             krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    821             return ENOMEM;
    822         }
     879        if (sret <= 0)
     880            return krb5_enomem(context);
     881
    823882        len -= sret;
    824883    }
     
    846905
    847906    if (krb5_checksum_is_keyed(context, cktype) == FALSE) {
    848         krb5_set_error_message(context, EINVAL, "PAC checksum type is not keyed");
    849         return EINVAL;
     907        *cksumtype = CKSUMTYPE_HMAC_MD5;
     908        *cksumsize = 16;
    850909    }
    851910
     
    890949
    891950        ptr = realloc(p->pac, sizeof(*p->pac) + (sizeof(p->pac->buffers[0]) * (p->pac->numbuffers + num - 1)));
    892         if (ptr == NULL) {
    893             krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    894             return ENOMEM;
    895         }
     951        if (ptr == NULL)
     952            return krb5_enomem(context);
     953
    896954        p->pac = ptr;
    897955
     
    928986    /* Encode PAC */
    929987    sp = krb5_storage_emem();
    930     if (sp == NULL) {
    931         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    932         return ENOMEM;
    933     }
     988    if (sp == NULL)
     989        return krb5_enomem(context);
     990
    934991    krb5_storage_set_flags(sp, KRB5_STORAGE_BYTEORDER_LE);
    935992
     
    937994    if (spdata == NULL) {
    938995        krb5_storage_free(sp);
    939         krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
    940         return ENOMEM;
     996        return krb5_enomem(context);
    941997    }
    942998    krb5_storage_set_flags(spdata, KRB5_STORAGE_BYTEORDER_LE);
     
    9761032            sret = krb5_storage_write(spdata, ptr, len);
    9771033            if (sret != len) {
    978                 ret = ENOMEM;
    979                 krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     1034                ret = krb5_enomem(context);
    9801035                goto out;
    9811036            }
     
    10141069    if (ret != d.length) {
    10151070        krb5_data_free(&d);
    1016         ret = ENOMEM;
    1017         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     1071        ret = krb5_enomem(context);
    10181072        goto out;
    10191073    }
     
    10221076    ret = krb5_storage_to_data(sp, &d);
    10231077    if (ret) {
    1024         krb5_set_error_message(context, ret, N_("malloc: out of memory", ""));
     1078        ret = krb5_enomem(context);
    10251079        goto out;
    10261080    }
    10271081
    10281082    /* sign */
    1029 
    1030     ret = create_checksum(context, server_key,
     1083    ret = create_checksum(context, server_key, server_cksumtype,
    10311084                          d.data, d.length,
    10321085                          (char *)d.data + server_offset, server_size);
     
    10351088        goto out;
    10361089    }
    1037 
    1038     ret = create_checksum(context, priv_key,
     1090    ret = create_checksum(context, priv_key, priv_cksumtype,
    10391091                          (char *)d.data + server_offset, server_size,
    10401092                          (char *)d.data + priv_offset, priv_size);
  • trunk/server/source4/heimdal/lib/krb5/padata.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 PA_DATA *
     36KRB5_LIB_FUNCTION PA_DATA * KRB5_LIB_CALL
    3737krb5_find_padata(PA_DATA *val, unsigned len, int type, int *idx)
    3838{
     
    4343}
    4444
    45 int KRB5_LIB_FUNCTION
     45KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    4646krb5_padata_add(krb5_context context, METHOD_DATA *md,
    4747                int type, void *buf, size_t len)
  • trunk/server/source4/heimdal/lib/krb5/pkinit.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    7577    unsigned int require_hostname_match:1;
    7678    unsigned int trustedCertifiers:1;
     79    unsigned int anonymous:1;
    7780};
    7881
     
    8992 */
    9093
    91 void KRB5_LIB_FUNCTION
     94KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    9295_krb5_pk_cert_free(struct krb5_pk_cert *cert)
    9396{
     
    180183          hx509_query *q, hx509_cert *cert)
    181184{
    182     struct certfind cf[3] = {
     185    struct certfind cf[4] = {
     186        { "MobileMe EKU" },
    183187        { "PKINIT EKU" },
    184188        { "MS EKU" },
    185189        { "any (or no)" }
    186190    };
    187     int i, ret;
    188 
    189     cf[0].oid = &asn1_oid_id_pkekuoid;
    190     cf[1].oid = &asn1_oid_id_pkinit_ms_eku;
    191     cf[2].oid = NULL;
    192 
    193     for (i = 0; i < sizeof(cf)/sizeof(cf[0]); i++) {
     191    int i, ret, start = 1;
     192    unsigned oids[] = { 1, 2, 840, 113635, 100, 3, 2, 1 };
     193    const heim_oid mobileMe = { sizeof(oids)/sizeof(oids[0]), oids };
     194
     195
     196    if (id->flags & PKINIT_BTMM)
     197        start = 0;
     198
     199    cf[0].oid = &mobileMe;
     200    cf[1].oid = &asn1_oid_id_pkekuoid;
     201    cf[2].oid = &asn1_oid_id_pkinit_ms_eku;
     202    cf[3].oid = NULL;
     203
     204    for (i = start; i < sizeof(cf)/sizeof(cf[0]); i++) {
    194205        ret = hx509_query_match_eku(q, cf[i].oid);
    195206        if (ret) {
    196             pk_copy_error(context, id->hx509ctx, ret,
     207            pk_copy_error(context, context->hx509ctx, ret,
    197208                          "Failed setting %s OID", cf[i].type);
    198209            return ret;
    199210        }
    200211
    201         ret = hx509_certs_find(id->hx509ctx, id->certs, q, cert);
     212        ret = hx509_certs_find(context->hx509ctx, id->certs, q, cert);
    202213        if (ret == 0)
    203214            break;
    204         pk_copy_error(context, id->hx509ctx, ret,
     215        pk_copy_error(context, context->hx509ctx, ret,
    205216                      "Failed finding certificate with %s OID", cf[i].type);
    206217    }
     
    222233        flags |= HX509_CMS_SIGNATURE_NO_SIGNER;
    223234
    224     ret = hx509_cms_create_signed_1(id->hx509ctx,
     235    ret = hx509_cms_create_signed_1(context->hx509ctx,
    225236                                    flags,
    226237                                    eContentType,
     
    234245                                    sd_data);
    235246    if (ret) {
    236         pk_copy_error(context, id->hx509ctx, ret,
     247        pk_copy_error(context, context->hx509ctx, ret,
    237248                      "Create CMS signedData");
    238249        return ret;
     
    344355          ExternalPrincipalIdentifiers *ids)
    345356{
    346     return hx509_certs_iter(hx509ctx, certs, cert2epi, ids);
     357    return hx509_certs_iter_f(hx509ctx, certs, cert2epi, ids);
    347358}
    348359
     
    597608            return ENOMEM;
    598609
    599         ret = hx509_crypto_available(ctx->id->hx509ctx, HX509_SELECT_ALL, NULL,
     610        ret = hx509_crypto_available(context->hx509ctx, HX509_SELECT_ALL, NULL,
    600611                                     &a->supportedCMSTypes->val,
    601612                                     &a->supportedCMSTypes->len);
     
    607618}
    608619
    609 krb5_error_code KRB5_LIB_FUNCTION
     620KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    610621_krb5_pk_mk_ContentInfo(krb5_context context,
    611622                        const krb5_data *buf,
     
    757768                goto out;
    758769            }
    759             ret = build_edi(context, ctx->id->hx509ctx,
     770            ret = build_edi(context, context->hx509ctx,
    760771                            ctx->id->anchors, req.trustedCertifiers);
    761772            if (ret) {
     
    797808
    798809
    799 krb5_error_code KRB5_LIB_FUNCTION
     810KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    800811_krb5_pk_mk_padata(krb5_context context,
    801812                   void *c,
     813                   int ic_flags,
     814                   int win2k,
    802815                   const KDC_REQ_BODY *req_body,
    803816                   unsigned nonce,
     
    807820    int win2k_compat;
    808821
     822    if (ctx->id->certs == NULL && ctx->anonymous == 0) {
     823        krb5_set_error_message(context, HEIM_PKINIT_NO_PRIVATE_KEY,
     824                               N_("PKINIT: No user certificate given", ""));
     825        return HEIM_PKINIT_NO_PRIVATE_KEY;
     826    }
     827
    809828    win2k_compat = krb5_config_get_bool_default(context, NULL,
    810                                                 FALSE,
     829                                                win2k,
    811830                                                "realms",
    812831                                                req_body->realm,
     
    817836        ctx->require_binding =
    818837            krb5_config_get_bool_default(context, NULL,
    819                                          FALSE,
     838                                         TRUE,
    820839                                         "realms",
    821840                                         req_body->realm,
     
    833852                                     "pkinit_require_eku",
    834853                                     NULL);
     854    if (ic_flags & KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK)
     855        ctx->require_eku = 0;
     856    if (ctx->id->flags & PKINIT_BTMM)
     857        ctx->require_eku = 0;
     858
    835859    ctx->require_krbtgt_otherName =
    836860        krb5_config_get_bool_default(context, NULL,
     
    870894{
    871895    hx509_certs signer_certs;
    872     int ret;
     896    int ret, flags = 0;
     897
     898    /* BTMM is broken in Leo and SnowLeo */
     899    if (id->flags & PKINIT_BTMM) {
     900        flags |= HX509_CMS_VS_ALLOW_DATA_OID_MISMATCH;
     901        flags |= HX509_CMS_VS_NO_KU_CHECK;
     902        flags |= HX509_CMS_VS_NO_VALIDATE;
     903    }
    873904
    874905    *signer = NULL;
    875906
    876     ret = hx509_cms_verify_signed(id->hx509ctx,
     907    ret = hx509_cms_verify_signed(context->hx509ctx,
    877908                                  id->verify_ctx,
    878                                   HX509_CMS_VS_ALLOW_DATA_OID_MISMATCH|HX509_CMS_VS_NO_KU_CHECK,
     909                                  flags,
    879910                                  data,
    880911                                  length,
     
    885916                                  &signer_certs);
    886917    if (ret) {
    887         pk_copy_error(context, id->hx509ctx, ret,
     918        pk_copy_error(context, context->hx509ctx, ret,
    888919                      "CMS verify signed failed");
    889920        return ret;
     
    897928    }
    898929       
    899     ret = hx509_get_one_cert(id->hx509ctx, signer_certs, &(*signer)->cert);
    900     if (ret) {
    901         pk_copy_error(context, id->hx509ctx, ret,
     930    ret = hx509_get_one_cert(context->hx509ctx, signer_certs, &(*signer)->cert);
     931    if (ret) {
     932        pk_copy_error(context, context->hx509ctx, ret,
    902933                      "Failed to get on of the signer certs");
    903934        goto out;
     
    10411072
    10421073    if (ctx->require_eku) {
    1043         ret = hx509_cert_check_eku(ctx->id->hx509ctx, host->cert,
     1074        ret = hx509_cert_check_eku(context->hx509ctx, host->cert,
    10441075                                   &asn1_oid_id_pkkdcekuoid, 0);
    10451076        if (ret) {
     
    10531084        int i;
    10541085
    1055         ret = hx509_cert_find_subjectAltName_otherName(ctx->id->hx509ctx,
     1086        ret = hx509_cert_find_subjectAltName_otherName(context->hx509ctx,
    10561087                                                       host->cert,
    10571088                                                       &asn1_oid_id_pkinit_san,
     
    11031134
    11041135    if (hi) {
    1105         ret = hx509_verify_hostname(ctx->id->hx509ctx, host->cert,
     1136        ret = hx509_verify_hostname(context->hx509ctx, host->cert,
    11061137                                    ctx->require_hostname_match,
    11071138                                    HX509_HN_HOSTNAME,
     
    11461177        flags |= HX509_CMS_UE_ALLOW_WEAK;
    11471178
    1148     ret = hx509_cms_unenvelope(ctx->id->hx509ctx,
     1179    ret = hx509_cms_unenvelope(context->hx509ctx,
    11491180                               ctx->id->certs,
    11501181                               flags,
     
    11561187                               &content);
    11571188    if (ret) {
    1158         pk_copy_error(context, ctx->id->hx509ctx, ret,
     1189        pk_copy_error(context, context->hx509ctx, ret,
    11591190                      "Failed to unenvelope CMS data in PK-INIT reply");
    11601191        return ret;
     
    11621193    der_free_oid(&contentType);
    11631194
    1164 #if 0 /* windows LH with interesting CMS packets, leaks memory */
    1165     {
    1166         size_t ph = 1 + der_length_len (length);
    1167         unsigned char *ptr = malloc(length + ph);
    1168         size_t l;
    1169 
    1170         memcpy(ptr + ph, p, length);
    1171 
    1172         ret = der_put_length_and_tag (ptr + ph - 1, ph, length,
    1173                                       ASN1_C_UNIV, CONS, UT_Sequence, &l);
    1174         if (ret)
    1175             return ret;
    1176         ptr += ph - l;
    1177         length += l;
    1178         p = ptr;
    1179     }
    1180 #endif
    1181 
    11821195    /* win2k uses ContentInfo */
    11831196    if (type == PKINIT_WIN2K) {
    1184         heim_oid type;
     1197        heim_oid type2;
    11851198        heim_octet_string out;
    11861199
    1187         ret = hx509_cms_unwrap_ContentInfo(&content, &type, &out, NULL);
    1188         if (ret)
    1189             goto out;
    1190         if (der_heim_oid_cmp(&type, &asn1_oid_id_pkcs7_signedData)) {
     1200        ret = hx509_cms_unwrap_ContentInfo(&content, &type2, &out, NULL);
     1201        if (ret) {
     1202            /* windows LH with interesting CMS packets */
     1203            size_t ph = 1 + der_length_len(content.length);
     1204            unsigned char *ptr = malloc(content.length + ph);
     1205            size_t l;
     1206           
     1207            memcpy(ptr + ph, content.data, content.length);
     1208           
     1209            ret = der_put_length_and_tag (ptr + ph - 1, ph, content.length,
     1210                                          ASN1_C_UNIV, CONS, UT_Sequence, &l);
     1211            if (ret)
     1212                return ret;
     1213            free(content.data);
     1214            content.data = ptr;
     1215            content.length += ph;
     1216
     1217            ret = hx509_cms_unwrap_ContentInfo(&content, &type2, &out, NULL);
     1218            if (ret)
     1219                goto out;
     1220        }
     1221        if (der_heim_oid_cmp(&type2, &asn1_oid_id_pkcs7_signedData)) {
    11911222            ret = EINVAL; /* XXX */
    11921223            krb5_set_error_message(context, ret,
    11931224                                   N_("PKINIT: Invalid content type", ""));
    1194             der_free_oid(&type);
     1225            der_free_oid(&type2);
    11951226            der_free_octet_string(&out);
    11961227            goto out;
    11971228        }
    1198         der_free_oid(&type);
     1229        der_free_oid(&type2);
    11991230        krb5_data_free(&content);
    12001231        ret = krb5_data_copy(&content, out.data, out.length);
     
    13861417
    13871418
    1388         dh_gen_keylen = DH_size(ctx->u.dh);
    1389         size = BN_num_bytes(ctx->u.dh->p);
    1390         if (size < dh_gen_keylen)
    1391             size = dh_gen_keylen;
     1419        size = DH_size(ctx->u.dh);
    13921420
    13931421        dh_gen_key = malloc(size);
     
    13971425            goto out;
    13981426        }
    1399         memset(dh_gen_key, 0, size - dh_gen_keylen);
    14001427       
    1401         dh_gen_keylen = DH_compute_key(dh_gen_key + (size - dh_gen_keylen),
    1402                                        kdc_dh_pubkey, ctx->u.dh);
     1428        dh_gen_keylen = DH_compute_key(dh_gen_key, kdc_dh_pubkey, ctx->u.dh);
    14031429        if (dh_gen_keylen == -1) {
    14041430            ret = KRB5KRB_ERR_GENERIC;
     
    14081434            goto out;
    14091435        }
     1436        if (dh_gen_keylen < size) {
     1437            size -= dh_gen_keylen;
     1438            memmove(dh_gen_key + size, dh_gen_key, dh_gen_keylen);
     1439            memset(dh_gen_key, 0, size);
     1440        }
     1441
    14101442    } else {
    14111443#ifdef HAVE_OPENSSL
     
    15041536}
    15051537
    1506 krb5_error_code KRB5_LIB_FUNCTION
     1538KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    15071539_krb5_pk_rd_pa_reply(krb5_context context,
    15081540                     const char *realm,
     
    15431575        switch (rep.element) {
    15441576        case choice_PA_PK_AS_REP_dhInfo:
     1577            _krb5_debug(context, 5, "krb5_get_init_creds: using pkinit dh");
    15451578            os = rep.u.dhInfo.dhSignedData;
    15461579            break;
    15471580        case choice_PA_PK_AS_REP_encKeyPack:
     1581            _krb5_debug(context, 5, "krb5_get_init_creds: using kinit enc reply key");
    15481582            os = rep.u.encKeyPack;
    15491583            break;
     
    15531587            memset(&rep, 0, sizeof(rep));
    15541588           
     1589            _krb5_debug(context, 5, "krb5_get_init_creds: using BTMM kinit enc reply key");
     1590
    15551591            ret = decode_PA_PK_AS_REP_BTMM(pa->padata_value.data,
    15561592                                           pa->padata_value.length,
     
    17191755}
    17201756
    1721 krb5_error_code KRB5_LIB_FUNCTION
     1757static krb5_error_code
     1758_krb5_pk_set_user_id(krb5_context context,
     1759                     krb5_principal principal,
     1760                     krb5_pk_init_ctx ctx,
     1761                     struct hx509_certs_data *certs)
     1762{
     1763    hx509_certs c = hx509_certs_ref(certs);
     1764    hx509_query *q = NULL;
     1765    int ret;
     1766
     1767    if (ctx->id->certs)
     1768        hx509_certs_free(&ctx->id->certs);
     1769    if (ctx->id->cert) {
     1770        hx509_cert_free(ctx->id->cert);
     1771        ctx->id->cert = NULL;
     1772    }
     1773
     1774    ctx->id->certs = c;
     1775    ctx->anonymous = 0;
     1776
     1777    ret = hx509_query_alloc(context->hx509ctx, &q);
     1778    if (ret) {
     1779        pk_copy_error(context, context->hx509ctx, ret,
     1780                      "Allocate query to find signing certificate");
     1781        return ret;
     1782    }
     1783       
     1784    hx509_query_match_option(q, HX509_QUERY_OPTION_PRIVATE_KEY);
     1785    hx509_query_match_option(q, HX509_QUERY_OPTION_KU_DIGITALSIGNATURE);
     1786       
     1787    if (principal && strncmp("LKDC:SHA1.", krb5_principal_get_realm(context, principal), 9) == 0) {
     1788        ctx->id->flags |= PKINIT_BTMM;
     1789    }
     1790
     1791    ret = find_cert(context, ctx->id, q, &ctx->id->cert);
     1792    hx509_query_free(context->hx509ctx, q);
     1793
     1794    if (ret == 0 && _krb5_have_debug(context, 2)) {
     1795        hx509_name name;
     1796        char *str, *sn;
     1797        heim_integer i;
     1798
     1799        ret = hx509_cert_get_subject(ctx->id->cert, &name);
     1800        if (ret)
     1801            goto out;
     1802   
     1803        ret = hx509_name_to_string(name, &str);
     1804        hx509_name_free(&name);
     1805        if (ret)
     1806            goto out;
     1807
     1808        ret = hx509_cert_get_serialnumber(ctx->id->cert, &i);
     1809        if (ret) {
     1810            free(str);
     1811            goto out;
     1812        }
     1813
     1814        ret = der_print_hex_heim_integer(&i, &sn);
     1815        der_free_heim_integer(&i);
     1816        if (ret) {
     1817            free(name);
     1818            goto out;
     1819        }
     1820
     1821        _krb5_debug(context, 2, "using cert: subject: %s sn: %s", str, sn);
     1822        free(str);
     1823        free(sn);
     1824    }
     1825 out:
     1826
     1827    return ret;
     1828}
     1829
     1830KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    17221831_krb5_pk_load_id(krb5_context context,
    17231832                 struct krb5_pk_identity **ret_id,
    1724                  int flags,
    17251833                 const char *user_id,
    17261834                 const char *anchor_id,
     
    17321840{
    17331841    struct krb5_pk_identity *id = NULL;
    1734     hx509_lock lock = NULL;
    17351842    struct prompter p;
    17361843    int ret;
     
    17421849                               N_("PKINIT: No anchor given", ""));
    17431850        return HEIM_PKINIT_NO_VALID_CA;
    1744     }
    1745 
    1746     if (user_id == NULL && (flags & 4) == 0) {
    1747         krb5_set_error_message(context, HEIM_PKINIT_NO_PRIVATE_KEY,
    1748                                N_("PKINIT: No user certificate given", ""));
    1749         return HEIM_PKINIT_NO_PRIVATE_KEY;
    17501851    }
    17511852
     
    17591860    }   
    17601861
    1761     ret = hx509_context_init(&id->hx509ctx);
    1762     if (ret)
    1763         goto out;
    1764 
    1765     ret = hx509_lock_init(id->hx509ctx, &lock);
    1766     if (ret) {
    1767         pk_copy_error(context, id->hx509ctx, ret, "Failed init lock");
    1768         goto out;
    1769     }
    1770 
    1771     if (password && password[0])
    1772         hx509_lock_add_password(lock, password);
    1773 
    1774     if (prompter) {
    1775         p.context = context;
    1776         p.prompter = prompter;
    1777         p.prompter_data = prompter_data;
    1778 
    1779         ret = hx509_lock_set_prompter(lock, hx_pass_prompter, &p);
    1780         if (ret)
    1781             goto out;
    1782     }
    1783 
    17841862    if (user_id) {
    1785         ret = hx509_certs_init(id->hx509ctx, user_id, 0, lock, &id->certs);
    1786         if (ret) {
    1787             pk_copy_error(context, id->hx509ctx, ret,
     1863        hx509_lock lock;
     1864
     1865        ret = hx509_lock_init(context->hx509ctx, &lock);
     1866        if (ret) {
     1867            pk_copy_error(context, context->hx509ctx, ret, "Failed init lock");
     1868            goto out;
     1869        }
     1870       
     1871        if (password && password[0])
     1872            hx509_lock_add_password(lock, password);
     1873       
     1874        if (prompter) {
     1875            p.context = context;
     1876            p.prompter = prompter;
     1877            p.prompter_data = prompter_data;
     1878           
     1879            ret = hx509_lock_set_prompter(lock, hx_pass_prompter, &p);
     1880            if (ret) {
     1881                hx509_lock_free(lock);
     1882                goto out;
     1883            }
     1884        }
     1885
     1886        ret = hx509_certs_init(context->hx509ctx, user_id, 0, lock, &id->certs);
     1887        hx509_lock_free(lock);
     1888        if (ret) {
     1889            pk_copy_error(context, context->hx509ctx, ret,
    17881890                          "Failed to init cert certs");
    17891891            goto out;
     
    17931895    }
    17941896
    1795     ret = hx509_certs_init(id->hx509ctx, anchor_id, 0, NULL, &id->anchors);
    1796     if (ret) {
    1797         pk_copy_error(context, id->hx509ctx, ret,
     1897    ret = hx509_certs_init(context->hx509ctx, anchor_id, 0, NULL, &id->anchors);
     1898    if (ret) {
     1899        pk_copy_error(context, context->hx509ctx, ret,
    17981900                      "Failed to init anchors");
    17991901        goto out;
    18001902    }
    18011903
    1802     ret = hx509_certs_init(id->hx509ctx, "MEMORY:pkinit-cert-chain",
     1904    ret = hx509_certs_init(context->hx509ctx, "MEMORY:pkinit-cert-chain",
    18031905                           0, NULL, &id->certpool);
    18041906    if (ret) {
    1805         pk_copy_error(context, id->hx509ctx, ret,
     1907        pk_copy_error(context, context->hx509ctx, ret,
    18061908                      "Failed to init chain");
    18071909        goto out;
     
    18091911
    18101912    while (chain_list && *chain_list) {
    1811         ret = hx509_certs_append(id->hx509ctx, id->certpool,
     1913        ret = hx509_certs_append(context->hx509ctx, id->certpool,
    18121914                                 NULL, *chain_list);
    18131915        if (ret) {
    1814             pk_copy_error(context, id->hx509ctx, ret,
     1916            pk_copy_error(context, context->hx509ctx, ret,
    18151917                          "Failed to laod chain %s",
    18161918                          *chain_list);
     
    18211923
    18221924    if (revoke_list) {
    1823         ret = hx509_revoke_init(id->hx509ctx, &id->revokectx);
    1824         if (ret) {
    1825             pk_copy_error(context, id->hx509ctx, ret,
     1925        ret = hx509_revoke_init(context->hx509ctx, &id->revokectx);
     1926        if (ret) {
     1927            pk_copy_error(context, context->hx509ctx, ret,
    18261928                          "Failed init revoke list");
    18271929            goto out;
     
    18291931
    18301932        while (*revoke_list) {
    1831             ret = hx509_revoke_add_crl(id->hx509ctx,
     1933            ret = hx509_revoke_add_crl(context->hx509ctx,
    18321934                                       id->revokectx,
    18331935                                       *revoke_list);
    18341936            if (ret) {
    1835                 pk_copy_error(context, id->hx509ctx, ret,
     1937                pk_copy_error(context, context->hx509ctx, ret,
    18361938                              "Failed load revoke list");
    18371939                goto out;
     
    18401942        }
    18411943    } else
    1842         hx509_context_set_missing_revoke(id->hx509ctx, 1);
    1843 
    1844     ret = hx509_verify_init_ctx(id->hx509ctx, &id->verify_ctx);
    1845     if (ret) {
    1846         pk_copy_error(context, id->hx509ctx, ret,
     1944        hx509_context_set_missing_revoke(context->hx509ctx, 1);
     1945
     1946    ret = hx509_verify_init_ctx(context->hx509ctx, &id->verify_ctx);
     1947    if (ret) {
     1948        pk_copy_error(context, context->hx509ctx, ret,
    18471949                      "Failed init verify context");
    18481950        goto out;
     
    18591961        hx509_certs_free(&id->certpool);
    18601962        hx509_revoke_free(&id->revokectx);
    1861         hx509_context_free(&id->hx509ctx);
    18621963        free(id);
    18631964    } else
    18641965        *ret_id = id;
    1865 
    1866     if (lock)
    1867         hx509_lock_free(lock);
    18681966
    18691967    return ret;
     
    18831981    va_list va;
    18841982    char *s, *f;
     1983    int ret;
    18851984
    18861985    va_start(va, fmt);
    1887     vasprintf(&f, fmt, va);
     1986    ret = vasprintf(&f, fmt, va);
    18881987    va_end(va);
    1889     if (f == NULL) {
     1988    if (ret == -1 || f == NULL) {
    18901989        krb5_clear_error_message(context);
    18911990        return;
     
    21162215        file = MODULI_FILE;
    21172216
     2217#ifdef KRB5_USE_PATH_TOKENS
     2218    {
     2219        char * exp_file;
     2220
     2221        if (_krb5_expand_path_tokens(context, file, &exp_file) == 0) {
     2222            f = fopen(exp_file, "r");
     2223            krb5_xfree(exp_file);
     2224        } else {
     2225            f = NULL;
     2226        }
     2227    }
     2228#else
    21182229    f = fopen(file, "r");
     2230#endif
     2231
    21192232    if (f == NULL) {
    21202233        *moduli = m;
     
    21932306#endif /* PKINIT */
    21942307
    2195 void KRB5_LIB_FUNCTION
     2308KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    21962309_krb5_get_init_creds_opt_free_pkinit(krb5_get_init_creds_opt *opt)
    21972310{
     
    22042317    switch (ctx->keyex) {
    22052318    case USE_DH:
    2206         DH_free(ctx->u.dh);
     2319        if (ctx->u.dh)
     2320            DH_free(ctx->u.dh);
    22072321        break;
    22082322    case USE_RSA:
     
    22102324    case USE_ECDH:
    22112325#ifdef HAVE_OPENSSL
    2212         EC_KEY_free(ctx->u.eckey);
     2326        if (ctx->u.eckey)
     2327            EC_KEY_free(ctx->u.eckey);
    22132328#endif
    22142329        break;
     
    22202335        hx509_certs_free(&ctx->id->anchors);
    22212336        hx509_certs_free(&ctx->id->certpool);
    2222         hx509_context_free(&ctx->id->hx509ctx);
    22232337
    22242338        if (ctx->clientDHNonce) {
     
    22362350}
    22372351
    2238 krb5_error_code KRB5_LIB_FUNCTION
     2352KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    22392353krb5_get_init_creds_opt_set_pkinit(krb5_context context,
    22402354                                   krb5_get_init_creds_opt *opt,
     
    22912405    }
    22922406
     2407    if (flags & 4)
     2408        opt->opt_private->pk_init_ctx->anonymous = 1;
     2409
    22932410    ret = _krb5_pk_load_id(context,
    22942411                           &opt->opt_private->pk_init_ctx->id,
    2295                            flags,
    22962412                           user_id,
    22972413                           x509_anchors,
     
    23082424
    23092425    if (opt->opt_private->pk_init_ctx->id->certs) {
    2310         hx509_query *q = NULL;
    2311         hx509_cert cert = NULL;
    2312         hx509_context hx509ctx = opt->opt_private->pk_init_ctx->id->hx509ctx;
    2313 
    2314         ret = hx509_query_alloc(hx509ctx, &q);
    2315         if (ret) {
    2316             pk_copy_error(context, hx509ctx, ret,
    2317                           "Allocate query to find signing certificate");
    2318             return ret;
    2319         }
    2320        
    2321         hx509_query_match_option(q, HX509_QUERY_OPTION_PRIVATE_KEY);
    2322         hx509_query_match_option(q, HX509_QUERY_OPTION_KU_DIGITALSIGNATURE);
    2323        
    2324         ret = find_cert(context, opt->opt_private->pk_init_ctx->id, q, &cert);
    2325         hx509_query_free(hx509ctx, q);
    2326         if (ret)
    2327             return ret;
    2328 
    2329         opt->opt_private->pk_init_ctx->id->cert = cert;
     2426        _krb5_pk_set_user_id(context,
     2427                             principal,
     2428                             opt->opt_private->pk_init_ctx,
     2429                             opt->opt_private->pk_init_ctx->id->certs);
    23302430    } else
    23312431        opt->opt_private->pk_init_ctx->id->cert = NULL;
    23322432
    23332433    if ((flags & 2) == 0) {
    2334         hx509_context hx509ctx = opt->opt_private->pk_init_ctx->id->hx509ctx;
     2434        hx509_context hx509ctx = context->hx509ctx;
    23352435        hx509_cert cert = opt->opt_private->pk_init_ctx->id->cert;
    23362436
     
    23692469}
    23702470
     2471krb5_error_code KRB5_LIB_FUNCTION
     2472krb5_get_init_creds_opt_set_pkinit_user_certs(krb5_context context,
     2473                                              krb5_get_init_creds_opt *opt,
     2474                                              struct hx509_certs_data *certs)
     2475{
     2476#ifdef PKINIT
     2477    if (opt->opt_private == NULL) {
     2478        krb5_set_error_message(context, EINVAL,
     2479                               N_("PKINIT: on non extendable opt", ""));
     2480        return EINVAL;
     2481    }
     2482    if (opt->opt_private->pk_init_ctx == NULL) {
     2483        krb5_set_error_message(context, EINVAL,
     2484                               N_("PKINIT: on pkinit context", ""));
     2485        return EINVAL;
     2486    }
     2487   
     2488    _krb5_pk_set_user_id(context, NULL, opt->opt_private->pk_init_ctx, certs);
     2489
     2490    return 0;
     2491#else
     2492    krb5_set_error_message(context, EINVAL,
     2493                           N_("no support for PKINIT compiled in", ""));
     2494    return EINVAL;
     2495#endif
     2496}
     2497
    23712498#ifdef PKINIT
    23722499
     
    24162543 */
    24172544
    2418 krb5_error_code  KRB5_LIB_FUNCTION
    2419 _krb5_pk_enterprise_cert(krb5_context context,
    2420                          const char *user_id,
    2421                          krb5_const_realm realm,
    2422                          krb5_principal *principal)
     2545KRB5_LIB_FUNCTION krb5_error_code  KRB5_LIB_CALL
     2546krb5_pk_enterprise_cert(krb5_context context,
     2547                        const char *user_id,
     2548                        krb5_const_realm realm,
     2549                        krb5_principal *principal,
     2550                        struct hx509_certs_data **res)
    24232551{
    24242552#ifdef PKINIT
    24252553    krb5_error_code ret;
    2426     hx509_context hx509ctx;
    24272554    hx509_certs certs, result;
    24282555    hx509_cert cert;
     
    24312558
    24322559    *principal = NULL;
     2560    if (res)
     2561        *res = NULL;
    24332562   
    2434     if (user_id == NULL)
     2563    if (user_id == NULL) {
     2564        krb5_set_error_message(context, ENOENT, "no user id");
    24352565        return ENOENT;
    2436 
    2437     ret = hx509_context_init(&hx509ctx);
    2438     if (ret)
    2439         return ret;
    2440 
    2441     ret = hx509_certs_init(hx509ctx, user_id, 0, NULL, &certs);
    2442     if (ret) {
    2443         pk_copy_error(context, hx509ctx, ret,
     2566    }
     2567
     2568    ret = hx509_certs_init(context->hx509ctx, user_id, 0, NULL, &certs);
     2569    if (ret) {
     2570        pk_copy_error(context, context->hx509ctx, ret,
    24442571                      "Failed to init cert certs");
    2445         return ret;
    2446     }
    2447 
    2448     ret = hx509_query_alloc(hx509ctx, &q);
    2449     if (ret) {
     2572        goto out;
     2573    }
     2574
     2575    ret = hx509_query_alloc(context->hx509ctx, &q);
     2576    if (ret) {
     2577        krb5_set_error_message(context, ret, "out of memory");
    24502578        hx509_certs_free(&certs);
    2451         return ret;
     2579        goto out;
    24522580    }
    24532581
     
    24572585    hx509_query_match_cmp_func(q, find_ms_san, NULL);
    24582586
    2459     ret = hx509_certs_filter(hx509ctx, certs, q, &result);
    2460     hx509_query_free(hx509ctx, q);
     2587    ret = hx509_certs_filter(context->hx509ctx, certs, q, &result);
     2588    hx509_query_free(context->hx509ctx, q);
    24612589    hx509_certs_free(&certs);
    2462     if (ret)
     2590    if (ret) {
     2591        pk_copy_error(context, context->hx509ctx, ret,
     2592                      "Failed to find PKINIT certificate");
    24632593        return ret;
     2594    }
    24642595   
    2465     ret = hx509_get_one_cert(hx509ctx, result, &cert);
     2596    ret = hx509_get_one_cert(context->hx509ctx, result, &cert);
    24662597    hx509_certs_free(&result);
    2467     if (ret)
    2468         return ret;
    2469 
    2470     ret = get_ms_san(hx509ctx, cert, &name);
    2471     if (ret)
    2472         return ret;
     2598    if (ret) {
     2599        pk_copy_error(context, context->hx509ctx, ret,
     2600                      "Failed to get one cert");
     2601        goto out;
     2602    }
     2603
     2604    ret = get_ms_san(context->hx509ctx, cert, &name);
     2605    if (ret) {
     2606        pk_copy_error(context, context->hx509ctx, ret,
     2607                      "Failed to get MS SAN");
     2608        goto out;
     2609    }
    24732610
    24742611    ret = krb5_make_principal(context, principal, realm, name, NULL);
    24752612    free(name);
    2476     hx509_context_free(&hx509ctx);
    24772613    if (ret)
    2478         return ret;
     2614        goto out;
    24792615
    24802616    krb5_principal_set_type(context, *principal, KRB5_NT_ENTERPRISE_PRINCIPAL);
    2481    
     2617
     2618    if (res) {
     2619        ret = hx509_certs_init(context->hx509ctx, "MEMORY:", 0, NULL, res);
     2620        if (ret) {
     2621            hx509_cert_free(cert);
     2622            goto out;
     2623        }
     2624       
     2625        ret = hx509_certs_add(context->hx509ctx, *res, cert);
     2626        if (ret) {
     2627            hx509_certs_free(res);
     2628            goto out;
     2629        }
     2630    }
     2631
     2632 out:
     2633    hx509_cert_free(cert);
     2634
    24822635    return ret;
    24832636#else
  • trunk/server/source4/heimdal/lib/krb5/plugin.c

    r414 r745  
    136136 */
    137137
    138 krb5_error_code
     138KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    139139krb5_plugin_register(krb5_context context,
    140140                     enum krb5_plugin_type type,
     
    180180}
    181181
     182static int
     183is_valid_plugin_filename(const char * n)
     184{
     185    if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
     186        return 0;
     187
     188#ifdef _WIN32
     189    /* On Windows, we only attempt to load .dll files as plug-ins. */
     190    {
     191        const char * ext;
     192
     193        ext = strrchr(n, '.');
     194        if (ext == NULL)
     195            return 0;
     196
     197        return !stricmp(ext, ".dll");
     198    }
     199#endif
     200
     201    return 1;
     202}
     203
     204static void
     205trim_trailing_slash(char * path)
     206{
     207    size_t l;
     208
     209    l = strlen(path);
     210    while (l > 0 && (path[l - 1] == '/'
     211#ifdef BACKSLASH_PATH_DELIM
     212                     || path[l - 1] == '\\'
     213#endif
     214               )) {
     215        path[--l] = '\0';
     216    }
     217}
     218
    182219static krb5_error_code
    183220load_plugins(krb5_context context)
     
    202239
    203240    for (di = dirs; *di != NULL; di++) {
    204 
    205         d = opendir(*di);
     241        char * dir = *di;
     242
     243#ifdef KRB5_USE_PATH_TOKENS
     244        if (_krb5_expand_path_tokens(context, *di, &dir))
     245            goto next_dir;
     246#endif
     247
     248        trim_trailing_slash(dir);
     249
     250        d = opendir(dir);
     251
    206252        if (d == NULL)
    207             continue;
    208         rk_cloexec(dirfd(d));
     253            goto next_dir;
     254
     255        rk_cloexec_dir(d);
    209256
    210257        while ((entry = readdir(d)) != NULL) {
     
    212259
    213260            /* skip . and .. */
    214             if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
     261            if (!is_valid_plugin_filename(n))
    215262                continue;
    216263
    217264            path = NULL;
     265            ret = 0;
    218266#ifdef __APPLE__
    219267            { /* support loading bundles on MacOS */
    220268                size_t len = strlen(n);
    221269                if (len > 7 && strcmp(&n[len - 7],  ".bundle") == 0)
    222                     asprintf(&path, "%s/%s/Contents/MacOS/%.*s", *di, n, (int)(len - 7), n);
     270                    ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", dir, n, (int)(len - 7), n);
    223271            }
    224272#endif
    225             if (path == NULL)
    226                 asprintf(&path, "%s/%s", *di, n);
    227 
    228             if (path == NULL) {
     273            if (ret < 0 || path == NULL)
     274                ret = asprintf(&path, "%s/%s", dir, n);
     275
     276            if (ret < 0 || path == NULL) {
    229277                ret = ENOMEM;
    230278                krb5_set_error_message(context, ret, "malloc: out of memory");
     
    243291        }
    244292        closedir(d);
     293
     294    next_dir:
     295        if (dir != *di)
     296            free(dir);
    245297    }
    246298    if (dirs != rk_UNCONST(sysplugin_dirs))
     
    325377    }
    326378}
     379/*
     380 * module - dict of {
     381 *      ModuleName = [
     382 *          plugin = object{
     383 *              array = { ptr, ctx }
     384 *          }
     385 *      ]
     386 * }
     387 */
     388
     389static heim_dict_t modules;
     390
     391struct plugin2 {
     392    heim_string_t path;
     393    void *dsohandle;
     394    heim_dict_t names;
     395};
     396
     397static void
     398plug_dealloc(void *ptr)
     399{
     400    struct plugin2 *p = ptr;
     401    heim_release(p->path);
     402    heim_release(p->names);
     403    if (p->dsohandle)
     404        dlclose(p->dsohandle);
     405}
     406
     407
     408void
     409_krb5_load_plugins(krb5_context context, const char *name, const char **paths)
     410{
     411#ifdef HAVE_DLOPEN
     412    heim_string_t s = heim_string_create(name);
     413    heim_dict_t module;
     414    struct dirent *entry;
     415    krb5_error_code ret;
     416    const char **di;
     417    DIR *d;
     418
     419    HEIMDAL_MUTEX_lock(&plugin_mutex);
     420
     421    if (modules == NULL) {
     422        modules = heim_dict_create(11);
     423        if (modules == NULL) {
     424            HEIMDAL_MUTEX_unlock(&plugin_mutex);
     425            return;
     426        }
     427    }
     428
     429    module = heim_dict_copy_value(modules, s);
     430    if (module == NULL) {
     431        module = heim_dict_create(11);
     432        if (module == NULL) {
     433            HEIMDAL_MUTEX_unlock(&plugin_mutex);
     434            heim_release(s);
     435            return;
     436        }
     437        heim_dict_add_value(modules, s, module);
     438    }
     439    heim_release(s);
     440
     441    for (di = paths; *di != NULL; di++) {
     442        d = opendir(*di);
     443        if (d == NULL)
     444            continue;
     445        rk_cloexec_dir(d);
     446
     447        while ((entry = readdir(d)) != NULL) {
     448            char *n = entry->d_name;
     449            char *path = NULL;
     450            heim_string_t spath;
     451            struct plugin2 *p;
     452
     453            /* skip . and .. */
     454            if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
     455                continue;
     456
     457            ret = 0;
     458#ifdef __APPLE__
     459            { /* support loading bundles on MacOS */
     460                size_t len = strlen(n);
     461                if (len > 7 && strcmp(&n[len - 7],  ".bundle") == 0)
     462                    ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", *di, n, (int)(len - 7), n);
     463            }
     464#endif
     465            if (ret < 0 || path == NULL)
     466                ret = asprintf(&path, "%s/%s", *di, n);
     467
     468            if (ret < 0 || path == NULL)
     469                continue;
     470
     471            spath = heim_string_create(n);
     472            if (spath == NULL) {
     473                free(path);
     474                continue;
     475            }
     476
     477            /* check if already cached */
     478            p = heim_dict_copy_value(module, spath);
     479            if (p == NULL) {
     480                p = heim_alloc(sizeof(*p), "krb5-plugin", plug_dealloc);
     481                if (p)
     482                    p->dsohandle = dlopen(path, RTLD_LOCAL|RTLD_LAZY);
     483
     484                if (p->dsohandle) {
     485                    p->path = heim_retain(spath);
     486                    p->names = heim_dict_create(11);
     487                    heim_dict_add_value(module, spath, p);
     488                }
     489            }
     490            heim_release(spath);
     491            heim_release(p);
     492            free(path);
     493        }
     494        closedir(d);
     495    }
     496    heim_release(module);
     497    HEIMDAL_MUTEX_unlock(&plugin_mutex);
     498#endif /* HAVE_DLOPEN */
     499}
     500
     501void
     502_krb5_unload_plugins(krb5_context context, const char *name)
     503{
     504    HEIMDAL_MUTEX_lock(&plugin_mutex);
     505    heim_release(modules);
     506    modules = NULL;
     507    HEIMDAL_MUTEX_unlock(&plugin_mutex);
     508}
     509
     510/*
     511 *
     512 */
     513
     514struct common_plugin_method {
     515    int                 version;
     516    krb5_error_code     (*init)(krb5_context, void **);
     517    void                (*fini)(void *);
     518};
     519
     520struct plug {
     521    void *dataptr;
     522    void *ctx;
     523};
     524
     525static void
     526plug_free(void *ptr)
     527{
     528    struct plug *pl = ptr;
     529    if (pl->dataptr) {
     530        struct common_plugin_method *cpm = pl->dataptr;
     531        cpm->fini(pl->ctx);
     532    }
     533}
     534
     535struct iter_ctx {
     536    krb5_context context;
     537    heim_string_t n;
     538    const char *name;
     539    int min_version;
     540    heim_array_t result;
     541    krb5_error_code (*func)(krb5_context, const void *, void *, void *);
     542    void *userctx;
     543    krb5_error_code ret;
     544};
     545
     546static void
     547search_modules(void *ctx, heim_object_t key, heim_object_t value)
     548{
     549    struct iter_ctx *s = ctx;
     550    struct plugin2 *p = value;
     551    struct plug *pl = heim_dict_copy_value(p->names, s->n);
     552    struct common_plugin_method *cpm;
     553
     554    if (pl == NULL) {
     555        if (p->dsohandle == NULL)
     556            return;
     557
     558        pl = heim_alloc(sizeof(*pl), "struct-plug", plug_free);
     559               
     560        cpm = pl->dataptr = dlsym(p->dsohandle, s->name);
     561        if (cpm) {
     562            int ret;
     563
     564            ret = cpm->init(s->context, &pl->ctx);
     565            if (ret)
     566                cpm = pl->dataptr = NULL;
     567        }
     568        heim_dict_add_value(p->names, s->n, pl);
     569    } else {
     570        cpm = pl->dataptr;
     571    }
     572           
     573    if (cpm && cpm->version >= s->min_version)
     574        heim_array_append_value(s->result, pl);
     575   
     576    heim_release(pl);
     577}
     578
     579static void
     580eval_results(heim_object_t value, void *ctx)
     581{
     582    struct plug *pl = value;
     583    struct iter_ctx *s = ctx;
     584
     585    if (s->ret != KRB5_PLUGIN_NO_HANDLE)
     586        return;
     587
     588    s->ret = s->func(s->context, pl->dataptr, pl->ctx, s->userctx);
     589}
     590
     591krb5_error_code
     592_krb5_plugin_run_f(krb5_context context,
     593                   const char *module,
     594                   const char *name,
     595                   int min_version,
     596                   int flags,
     597                   void *userctx,
     598                   krb5_error_code (*func)(krb5_context, const void *, void *, void *))
     599{
     600    heim_string_t m = heim_string_create(module);
     601    heim_dict_t dict;
     602    struct iter_ctx s;
     603
     604    HEIMDAL_MUTEX_lock(&plugin_mutex);
     605
     606    dict = heim_dict_copy_value(modules, m);
     607    heim_release(m);
     608    if (dict == NULL) {
     609        HEIMDAL_MUTEX_unlock(&plugin_mutex);
     610        return KRB5_PLUGIN_NO_HANDLE;
     611    }
     612
     613    s.context = context;
     614    s.name = name;
     615    s.n = heim_string_create(name);
     616    s.min_version = min_version;
     617    s.result = heim_array_create();
     618    s.func = func;
     619    s.userctx = userctx;
     620
     621    heim_dict_iterate_f(dict, search_modules, &s);
     622   
     623    heim_release(dict);
     624   
     625    HEIMDAL_MUTEX_unlock(&plugin_mutex);
     626   
     627    s.ret = KRB5_PLUGIN_NO_HANDLE;
     628
     629    heim_array_iterate_f(s.result, eval_results, &s);
     630
     631    heim_release(s.result);
     632    heim_release(s.n);
     633
     634    return s.ret;
     635}
  • trunk/server/source4/heimdal/lib/krb5/principal.c

    r414 r745  
    7777 */
    7878
    79 void KRB5_LIB_FUNCTION
     79KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    8080krb5_free_principal(krb5_context context,
    8181                    krb5_principal p)
     
    9999 */
    100100
    101 void KRB5_LIB_FUNCTION
     101KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    102102krb5_principal_set_type(krb5_context context,
    103103                        krb5_principal principal,
     
    107107}
    108108
    109 int KRB5_LIB_FUNCTION
     109/**
     110 * Get the type of the principal
     111 *
     112 * @param context A Kerberos context.
     113 * @param principal principal to get the type for
     114 *
     115 * @return the type of principal
     116 *
     117 * @ingroup krb5_principal
     118 */
     119
     120KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    110121krb5_principal_get_type(krb5_context context,
    111122                        krb5_const_principal principal)
     
    114125}
    115126
    116 const char* KRB5_LIB_FUNCTION
     127/**
     128 * Get the realm of the principal
     129 *
     130 * @param context A Kerberos context.
     131 * @param principal principal to get the realm for
     132 *
     133 * @return realm of the principal, don't free or use after krb5_principal is freed
     134 *
     135 * @ingroup krb5_principal
     136 */
     137
     138KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    117139krb5_principal_get_realm(krb5_context context,
    118140                         krb5_const_principal principal)
     
    121143}                       
    122144
    123 const char* KRB5_LIB_FUNCTION
     145KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    124146krb5_principal_get_comp_string(krb5_context context,
    125147                               krb5_const_principal principal,
     
    142164 */
    143165
    144 unsigned int KRB5_LIB_FUNCTION
     166KRB5_LIB_FUNCTION unsigned int KRB5_LIB_CALL
    145167krb5_principal_get_num_comp(krb5_context context,
    146168                            krb5_const_principal principal)
     
    149171}
    150172
    151 krb5_error_code KRB5_LIB_FUNCTION
     173/**
     174 * Parse a name into a krb5_principal structure, flags controls the behavior.
     175 *
     176 * @param context Kerberos 5 context
     177 * @param name name to parse into a Kerberos principal
     178 * @param flags flags to control the behavior
     179 * @param principal returned principal, free with krb5_free_principal().
     180 *
     181 * @return An krb5 error code, see krb5_get_error_message().
     182 *
     183 * @ingroup krb5_principal
     184 */
     185
     186KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    152187krb5_parse_name_flags(krb5_context context,
    153188                      const char *name,
     
    338373}
    339374
    340 krb5_error_code KRB5_LIB_FUNCTION
     375/**
     376 * Parse a name into a krb5_principal structure
     377 *
     378 * @param context Kerberos 5 context
     379 * @param name name to parse into a Kerberos principal
     380 * @param principal returned principal, free with krb5_free_principal().
     381 *
     382 * @return An krb5 error code, see krb5_get_error_message().
     383 *
     384 * @ingroup krb5_principal
     385 */
     386
     387KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    341388krb5_parse_name(krb5_context context,
    342389                const char *name,
     
    426473}
    427474
    428 krb5_error_code KRB5_LIB_FUNCTION
     475/**
     476 * Unparse the principal name to a fixed buffer
     477 *
     478 * @param context A Kerberos context.
     479 * @param principal principal to unparse
     480 * @param name buffer to write name to
     481 * @param len length of buffer
     482 *
     483 * @return An krb5 error code, see krb5_get_error_message().
     484 *
     485 * @ingroup krb5_principal
     486 */
     487
     488KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    429489krb5_unparse_name_fixed(krb5_context context,
    430490                        krb5_const_principal principal,
     
    435495}
    436496
    437 krb5_error_code KRB5_LIB_FUNCTION
     497/**
     498 * Unparse the principal name to a fixed buffer. The realm is skipped
     499 * if its a default realm.
     500 *
     501 * @param context A Kerberos context.
     502 * @param principal principal to unparse
     503 * @param name buffer to write name to
     504 * @param len length of buffer
     505 *
     506 * @return An krb5 error code, see krb5_get_error_message().
     507 *
     508 * @ingroup krb5_principal
     509 */
     510
     511KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    438512krb5_unparse_name_fixed_short(krb5_context context,
    439513                              krb5_const_principal principal,
     
    445519}
    446520
    447 krb5_error_code KRB5_LIB_FUNCTION
     521/**
     522 * Unparse the principal name with unparse flags to a fixed buffer.
     523 *
     524 * @param context A Kerberos context.
     525 * @param principal principal to unparse
     526 * @param flags unparse flags
     527 * @param name buffer to write name to
     528 * @param len length of buffer
     529 *
     530 * @return An krb5 error code, see krb5_get_error_message().
     531 *
     532 * @ingroup krb5_principal
     533 */
     534
     535KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    448536krb5_unparse_name_fixed_flags(krb5_context context,
    449537                              krb5_const_principal principal,
     
    509597 */
    510598
    511 krb5_error_code KRB5_LIB_FUNCTION
     599KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    512600krb5_unparse_name(krb5_context context,
    513601                  krb5_const_principal principal,
     
    530618 */
    531619
    532 krb5_error_code KRB5_LIB_FUNCTION
     620KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    533621krb5_unparse_name_flags(krb5_context context,
    534622                        krb5_const_principal principal,
     
    539627}
    540628
    541 krb5_error_code KRB5_LIB_FUNCTION
     629/**
     630 * Unparse the principal name to a allocated buffer. The realm is
     631 * skipped if its a default realm.
     632 *
     633 * @param context A Kerberos context.
     634 * @param principal principal to unparse
     635 * @param name returned buffer, free with krb5_xfree()
     636 *
     637 * @return An krb5 error code, see krb5_get_error_message().
     638 *
     639 * @ingroup krb5_principal
     640 */
     641
     642KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    542643krb5_unparse_name_short(krb5_context context,
    543644                        krb5_const_principal principal,
     
    547648}
    548649
    549 #if 0 /* not implemented */
    550 
    551 krb5_error_code KRB5_LIB_FUNCTION
    552 krb5_unparse_name_ext(krb5_context context,
    553                       krb5_const_principal principal,
    554                       char **name,
    555                       size_t *size)
    556 {
    557     krb5_abortx(context, "unimplemented krb5_unparse_name_ext called");
    558 }
    559 
    560 #endif
    561 
    562 krb5_error_code KRB5_LIB_FUNCTION
     650/**
     651 * Set a new realm for a principal, and as a side-effect free the
     652 * previous realm.
     653 *
     654 * @param context A Kerberos context.
     655 * @param principal principal set the realm for
     656 * @param realm the new realm to set
     657 *
     658 * @return An krb5 error code, see krb5_get_error_message().
     659 *
     660 * @ingroup krb5_principal
     661 */
     662
     663KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    563664krb5_principal_set_realm(krb5_context context,
    564665                         krb5_principal principal,
     
    577678}
    578679
    579 
    580 krb5_error_code KRB5_LIB_FUNCTION
     680#ifndef HEIMDAL_SMALLER
     681/**
     682 * Build a principal using vararg style building
     683 *
     684 * @param context A Kerberos context.
     685 * @param principal returned principal
     686 * @param rlen length of realm
     687 * @param realm realm name
     688 * @param ... a list of components ended with NULL.
     689 *
     690 * @return An krb5 error code, see krb5_get_error_message().
     691 *
     692 * @ingroup krb5_principal
     693 */
     694
     695KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    581696krb5_build_principal(krb5_context context,
    582697                     krb5_principal *principal,
     
    590705    ret = krb5_build_principal_va(context, principal, rlen, realm, ap);
    591706    va_end(ap);
     707    return ret;
     708}
     709#endif
     710
     711/**
     712 * Build a principal using vararg style building
     713 *
     714 * @param context A Kerberos context.
     715 * @param principal returned principal
     716 * @param realm realm name
     717 * @param ... a list of components ended with NULL.
     718 *
     719 * @return An krb5 error code, see krb5_get_error_message().
     720 *
     721 * @ingroup krb5_principal
     722 */
     723
     724KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
     725krb5_make_principal(krb5_context context,
     726                    krb5_principal *principal,
     727                    krb5_const_realm realm,
     728                    ...)
     729{
     730    krb5_error_code ret;
     731    krb5_realm r = NULL;
     732    va_list ap;
     733    if(realm == NULL) {
     734        ret = krb5_get_default_realm(context, &r);
     735        if(ret)
     736            return ret;
     737        realm = r;
     738    }
     739    va_start(ap, realm);
     740    ret = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
     741    va_end(ap);
     742    if(r)
     743        free(r);
    592744    return ret;
    593745}
     
    677829}
    678830
    679 krb5_error_code KRB5_LIB_FUNCTION
    680 krb5_make_principal(krb5_context context,
    681                     krb5_principal *principal,
    682                     krb5_const_realm realm,
    683                     ...)
    684 {
    685     krb5_error_code ret;
    686     krb5_realm r = NULL;
    687     va_list ap;
    688     if(realm == NULL) {
    689         ret = krb5_get_default_realm(context, &r);
    690         if(ret)
    691             return ret;
    692         realm = r;
    693     }
    694     va_start(ap, realm);
    695     ret = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
    696     va_end(ap);
    697     if(r)
    698         free(r);
    699     return ret;
    700 }
    701 
    702 krb5_error_code KRB5_LIB_FUNCTION
     831KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    703832krb5_build_principal_va(krb5_context context,
    704833                        krb5_principal *principal,
     
    710839}
    711840
    712 krb5_error_code KRB5_LIB_FUNCTION
     841KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    713842krb5_build_principal_va_ext(krb5_context context,
    714843                            krb5_principal *principal,
     
    721850
    722851
    723 krb5_error_code KRB5_LIB_FUNCTION
     852KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    724853krb5_build_principal_ext(krb5_context context,
    725854                         krb5_principal *principal,
     
    736865}
    737866
    738 
    739 krb5_error_code KRB5_LIB_FUNCTION
     867/**
     868 * Copy a principal
     869 *
     870 * @param context A Kerberos context.
     871 * @param inprinc principal to copy
     872 * @param outprinc copied principal, free with krb5_free_principal()
     873 *
     874 * @return An krb5 error code, see krb5_get_error_message().
     875 *
     876 * @ingroup krb5_principal
     877 */
     878
     879
     880KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    740881krb5_copy_principal(krb5_context context,
    741882                    krb5_const_principal inprinc,
     
    768909 *
    769910 * @ingroup krb5_principal
    770  */
    771 
    772 krb5_boolean KRB5_LIB_FUNCTION
     911 * @see krb5_principal_compare()
     912 * @see krb5_realm_compare()
     913 */
     914
     915KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    773916krb5_principal_compare_any_realm(krb5_context context,
    774917                                 krb5_const_principal princ1,
     
    785928}
    786929
    787 krb5_boolean KRB5_LIB_FUNCTION
     930KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    788931_krb5_principal_compare_PrincipalName(krb5_context context,
    789932                                      krb5_const_principal princ1,
     
    801944
    802945
     946/**
     947 * Compares the two principals, including realm of the principals and returns
     948 * TRUE if they are the same and FALSE if not.
     949 *
     950 * @param context Kerberos 5 context
     951 * @param princ1 first principal to compare
     952 * @param princ2 second principal to compare
     953 *
     954 * @ingroup krb5_principal
     955 * @see krb5_principal_compare_any_realm()
     956 * @see krb5_realm_compare()
     957 */
     958
    803959/*
    804960 * return TRUE iff princ1 == princ2
    805961 */
    806962
    807 krb5_boolean KRB5_LIB_FUNCTION
     963KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    808964krb5_principal_compare(krb5_context context,
    809965                       krb5_const_principal princ1,
     
    815971}
    816972
    817 /*
     973/**
    818974 * return TRUE iff realm(princ1) == realm(princ2)
    819  */
    820 
    821 krb5_boolean KRB5_LIB_FUNCTION
     975 *
     976 * @param context Kerberos 5 context
     977 * @param princ1 first principal to compare
     978 * @param princ2 second principal to compare
     979 *
     980 * @ingroup krb5_principal
     981 * @see krb5_principal_compare_any_realm()
     982 * @see krb5_principal_compare()
     983 */
     984
     985KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    822986krb5_realm_compare(krb5_context context,
    823987                   krb5_const_principal princ1,
     
    827991}
    828992
    829 /*
     993/**
    830994 * return TRUE iff princ matches pattern
    831  */
    832 
    833 krb5_boolean KRB5_LIB_FUNCTION
     995 *
     996 * @ingroup krb5_principal
     997 */
     998
     999KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    8341000krb5_principal_match(krb5_context context,
    8351001                     krb5_const_principal princ,
     
    8481014}
    8491015
    850 #if defined(KRB4) || !defined(HEIMDAL_SMALLER)
    851 
    852 static struct v4_name_convert {
    853     const char *from;
    854     const char *to;
    855 } default_v4_name_convert[] = {
    856     { "ftp",    "ftp" },
    857     { "hprop",  "hprop" },
    858     { "pop",    "pop" },
    859     { "imap",   "imap" },
    860     { "rcmd",   "host" },
    861     { "smtp",   "smtp" },
    862     { NULL, NULL }
    863 };
    864 
    865 #endif
    866 
    867 #ifdef KRB4
    868 
    869 /*
    870  * return the converted instance name of `name' in `realm'.
    871  * look in the configuration file and then in the default set above.
    872  * return NULL if no conversion is appropriate.
    873  */
    874 
    875 static const char*
    876 get_name_conversion(krb5_context context, const char *realm, const char *name)
    877 {
    878     struct v4_name_convert *q;
    879     const char *p;
    880 
    881     p = krb5_config_get_string(context, NULL, "realms", realm,
    882                                "v4_name_convert", "host", name, NULL);
    883     if(p == NULL)
    884         p = krb5_config_get_string(context, NULL, "libdefaults",
    885                                    "v4_name_convert", "host", name, NULL);
    886     if(p)
    887         return p;
    888 
    889     /* XXX should be possible to override default list */
    890     p = krb5_config_get_string(context, NULL,
    891                                "realms",
    892                                realm,
    893                                "v4_name_convert",
    894                                "plain",
    895                                name,
    896                                NULL);
    897     if(p)
    898         return NULL;
    899     p = krb5_config_get_string(context, NULL,
    900                                "libdefaults",
    901                                "v4_name_convert",
    902                                "plain",
    903                                name,
    904                                NULL);
    905     if(p)
    906         return NULL;
    907     for(q = default_v4_name_convert; q->from; q++)
    908         if(strcmp(q->from, name) == 0)
    909             return q->to;
    910     return NULL;
    911 }
    912 
    913 /*
    914  * convert the v4 principal `name.instance@realm' to a v5 principal in `princ'.
    915  * if `resolve', use DNS.
    916  * if `func', use that function for validating the conversion
    917  */
    918 
    919 krb5_error_code KRB5_LIB_FUNCTION
    920 krb5_425_conv_principal_ext2(krb5_context context,
    921                              const char *name,
    922                              const char *instance,
    923                              const char *realm,
    924                              krb5_boolean (*func)(krb5_context,
    925                                                   void *, krb5_principal),
    926                              void *funcctx,
    927                              krb5_boolean resolve,
    928                              krb5_principal *princ)
    929 {
    930     const char *p;
    931     krb5_error_code ret;
    932     krb5_principal pr;
    933     char host[MAXHOSTNAMELEN];
    934     char local_hostname[MAXHOSTNAMELEN];
    935 
    936     /* do the following: if the name is found in the
    937        `v4_name_convert:host' part, is assumed to be a `host' type
    938        principal, and the instance is looked up in the
    939        `v4_instance_convert' part. if not found there the name is
    940        (optionally) looked up as a hostname, and if that doesn't yield
    941        anything, the `default_domain' is appended to the instance
    942        */
    943 
    944     if(instance == NULL)
    945         goto no_host;
    946     if(instance[0] == 0){
    947         instance = NULL;
    948         goto no_host;
    949     }
    950     p = get_name_conversion(context, realm, name);
    951     if(p == NULL)
    952         goto no_host;
    953     name = p;
    954     p = krb5_config_get_string(context, NULL, "realms", realm,
    955                                "v4_instance_convert", instance, NULL);
    956     if(p){
    957         instance = p;
    958         ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
    959         if (ret)
    960             return ret;
    961         if(func == NULL || (*func)(context, funcctx, pr)){
    962             *princ = pr;
    963             return 0;
    964         }
    965         krb5_free_principal(context, pr);
    966         *princ = NULL;
    967         krb5_clear_error_message (context);
    968         return HEIM_ERR_V4_PRINC_NO_CONV;
    969     }
    970     if(resolve){
    971         krb5_boolean passed = FALSE;
    972         char *inst = NULL;
    973 #ifdef USE_RESOLVER
    974         struct rk_dns_reply *r;
    975 
    976         r = rk_dns_lookup(instance, "aaaa");
    977         if (r) {
    978             if (r->head && r->head->type == rk_ns_t_aaaa) {
    979                 inst = strdup(r->head->domain);
    980                 passed = TRUE;
    981             }
    982             rk_dns_free_data(r);
    983         } else {
    984             r = rk_dns_lookup(instance, "a");
    985             if (r) {
    986                 if(r->head && r->head->type == rk_ns_t_a) {
    987                     inst = strdup(r->head->domain);
    988                     passed = TRUE;
    989                 }
    990                 rk_dns_free_data(r);
    991             }
    992         }
    993 #else
    994         struct addrinfo hints, *ai;
    995        
    996         memset (&hints, 0, sizeof(hints));
    997         hints.ai_flags = AI_CANONNAME;
    998         ret = getaddrinfo(instance, NULL, &hints, &ai);
    999         if (ret == 0) {
    1000             const struct addrinfo *a;
    1001             for (a = ai; a != NULL; a = a->ai_next) {
    1002                 if (a->ai_canonname != NULL) {
    1003                     inst = strdup (a->ai_canonname);
    1004                     passed = TRUE;
    1005                     break;
    1006                 }
    1007             }
    1008             freeaddrinfo (ai);
    1009         }
    1010 #endif
    1011         if (passed) {
    1012             if (inst == NULL) {
    1013                 krb5_set_error_message(context, ENOMEM,
    1014                                        N_("malloc: out of memory", ""));
    1015                 return ENOMEM;
    1016             }
    1017             strlwr(inst);
    1018             ret = krb5_make_principal(context, &pr, realm, name, inst,
    1019                                       NULL);
    1020             free (inst);
    1021             if(ret == 0) {
    1022                 if(func == NULL || (*func)(context, funcctx, pr)){
    1023                     *princ = pr;
    1024                     return 0;
    1025                 }
    1026                 krb5_free_principal(context, pr);
    1027             }
    1028         }
    1029     }
    1030     if(func != NULL) {
    1031         snprintf(host, sizeof(host), "%s.%s", instance, realm);
    1032         strlwr(host);
    1033         ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1034         if (ret)
    1035             return ret;
    1036         if((*func)(context, funcctx, pr)){
    1037             *princ = pr;
    1038             return 0;
    1039         }
    1040         krb5_free_principal(context, pr);
    1041     }
    1042 
    1043     /*
    1044      * if the instance is the first component of the local hostname,
    1045      * the converted host should be the long hostname.
    1046      */
    1047 
    1048     if (func == NULL &&
    1049         gethostname (local_hostname, sizeof(local_hostname)) == 0 &&
    1050         strncmp(instance, local_hostname, strlen(instance)) == 0 &&
    1051         local_hostname[strlen(instance)] == '.') {
    1052         strlcpy(host, local_hostname, sizeof(host));
    1053         goto local_host;
    1054     }
    1055 
    1056     {
    1057         char **domains, **d;
    1058         domains = krb5_config_get_strings(context, NULL, "realms", realm,
    1059                                           "v4_domains", NULL);
    1060         for(d = domains; d && *d; d++){
    1061             snprintf(host, sizeof(host), "%s.%s", instance, *d);
    1062             ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1063             if (ret) {
    1064                 krb5_config_free_strings(domains);
    1065                 return ret;
    1066             }
    1067             if(func == NULL || (*func)(context, funcctx, pr)){
    1068                 *princ = pr;
    1069                 krb5_config_free_strings(domains);
    1070                 return 0;
    1071             }
    1072             krb5_free_principal(context, pr);
    1073         }
    1074         krb5_config_free_strings(domains);
    1075     }
    1076 
    1077 
    1078     p = krb5_config_get_string(context, NULL, "realms", realm,
    1079                                "default_domain", NULL);
    1080     if(p == NULL){
    1081         /* this should be an error, just faking a name is not good */
    1082         krb5_clear_error_message (context);
    1083         return HEIM_ERR_V4_PRINC_NO_CONV;
    1084     }
    1085        
    1086     if (*p == '.')
    1087         ++p;
    1088     snprintf(host, sizeof(host), "%s.%s", instance, p);
    1089 local_host:
    1090     ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
    1091     if (ret)
    1092         return ret;
    1093     if(func == NULL || (*func)(context, funcctx, pr)){
    1094         *princ = pr;
    1095         return 0;
    1096     }
    1097     krb5_free_principal(context, pr);
    1098     krb5_clear_error_message (context);
    1099     return HEIM_ERR_V4_PRINC_NO_CONV;
    1100 no_host:
    1101     p = krb5_config_get_string(context, NULL,
    1102                                "realms",
    1103                                realm,
    1104                                "v4_name_convert",
    1105                                "plain",
    1106                                name,
    1107                                NULL);
    1108     if(p == NULL)
    1109         p = krb5_config_get_string(context, NULL,
    1110                                    "libdefaults",
    1111                                    "v4_name_convert",
    1112                                    "plain",
    1113                                    name,
    1114                                    NULL);
    1115     if(p)
    1116         name = p;
    1117 
    1118     ret = krb5_make_principal(context, &pr, realm, name, instance, NULL);
    1119     if (ret)
    1120         return ret;
    1121     if(func == NULL || (*func)(context, funcctx, pr)){
    1122         *princ = pr;
    1123         return 0;
    1124     }
    1125     krb5_free_principal(context, pr);
    1126     krb5_clear_error_message (context);
    1127     return HEIM_ERR_V4_PRINC_NO_CONV;
    1128 }
    1129 
    1130 #endif /* KRB4 */
    1131 
    1132 #ifndef HEIMDAL_SMALLER
    1133 
    1134 static int
    1135 check_list(const krb5_config_binding *l, const char *name, const char **out)
    1136 {
    1137     while(l){
    1138         if (l->type != krb5_config_string)
    1139             continue;
    1140         if(strcmp(name, l->u.string) == 0) {
    1141             *out = l->name;
    1142             return 1;
    1143         }
    1144         l = l->next;
    1145     }
    1146     return 0;
    1147 }
    1148 
    1149 static int
    1150 name_convert(krb5_context context, const char *name, const char *realm,
    1151              const char **out)
    1152 {
    1153     const krb5_config_binding *l;
    1154     l = krb5_config_get_list (context,
    1155                               NULL,
    1156                               "realms",
    1157                               realm,
    1158                               "v4_name_convert",
    1159                               "host",
    1160                               NULL);
    1161     if(l && check_list(l, name, out))
    1162         return KRB5_NT_SRV_HST;
    1163     l = krb5_config_get_list (context,
    1164                               NULL,
    1165                               "libdefaults",
    1166                               "v4_name_convert",
    1167                               "host",
    1168                               NULL);
    1169     if(l && check_list(l, name, out))
    1170         return KRB5_NT_SRV_HST;
    1171     l = krb5_config_get_list (context,
    1172                               NULL,
    1173                               "realms",
    1174                               realm,
    1175                               "v4_name_convert",
    1176                               "plain",
    1177                               NULL);
    1178     if(l && check_list(l, name, out))
    1179         return KRB5_NT_UNKNOWN;
    1180     l = krb5_config_get_list (context,
    1181                               NULL,
    1182                               "libdefaults",
    1183                               "v4_name_convert",
    1184                               "host",
    1185                               NULL);
    1186     if(l && check_list(l, name, out))
    1187         return KRB5_NT_UNKNOWN;
    1188 
    1189     /* didn't find it in config file, try built-in list */
    1190 #ifdef KRB4
    1191     {
    1192         struct v4_name_convert *q;
    1193         for(q = default_v4_name_convert; q->from; q++) {
    1194             if(strcmp(name, q->to) == 0) {
    1195                 *out = q->from;
    1196                 return KRB5_NT_SRV_HST;
    1197             }
    1198         }
    1199     }
    1200 #endif
    1201     return -1;
    1202 }
    1203 
    1204 /*
    1205  * convert the v5 principal in `principal' into a v4 corresponding one
    1206  * in `name, instance, realm'
    1207  * this is limited interface since there's no length given for these
    1208  * three parameters.  They have to be 40 bytes each (ANAME_SZ).
    1209  */
    1210 
    1211 krb5_error_code KRB5_LIB_FUNCTION
    1212 krb5_524_conv_principal(krb5_context context,
    1213                         const krb5_principal principal,
    1214                         char *name,
    1215                         char *instance,
    1216                         char *realm)
    1217 {
    1218     const char *n, *i, *r;
    1219     char tmpinst[40];
    1220     int type = princ_type(principal);
    1221     const int aname_sz = 40;
    1222 
    1223     r = principal->realm;
    1224 
    1225     switch(principal->name.name_string.len){
    1226     case 1:
    1227         n = principal->name.name_string.val[0];
    1228         i = "";
    1229         break;
    1230     case 2:
    1231         n = principal->name.name_string.val[0];
    1232         i = principal->name.name_string.val[1];
    1233         break;
    1234     default:
    1235         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1236                                N_("cannot convert a %d "
    1237                                   "component principal", ""),
    1238                                principal->name.name_string.len);
    1239         return KRB5_PARSE_MALFORMED;
    1240     }
    1241 
    1242     {
    1243         const char *tmp;
    1244         int t = name_convert(context, n, r, &tmp);
    1245         if(t >= 0) {
    1246             type = t;
    1247             n = tmp;
    1248         }
    1249     }
    1250 
    1251     if(type == KRB5_NT_SRV_HST){
    1252         char *p;
    1253 
    1254         strlcpy (tmpinst, i, sizeof(tmpinst));
    1255         p = strchr(tmpinst, '.');
    1256         if(p)
    1257             *p = 0;
    1258         i = tmpinst;
    1259     }
    1260 
    1261     if (strlcpy (name, n, aname_sz) >= aname_sz) {
    1262         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1263                                N_("too long name component to convert", ""));
    1264         return KRB5_PARSE_MALFORMED;
    1265     }
    1266     if (strlcpy (instance, i, aname_sz) >= aname_sz) {
    1267         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1268                                N_("too long instance component to convert", ""));
    1269         return KRB5_PARSE_MALFORMED;
    1270     }
    1271     if (strlcpy (realm, r, aname_sz) >= aname_sz) {
    1272         krb5_set_error_message(context, KRB5_PARSE_MALFORMED,
    1273                                N_("too long realm component to convert", ""));
    1274         return KRB5_PARSE_MALFORMED;
    1275     }
    1276     return 0;
    1277 }
    1278 
    1279 #endif /* !HEIMDAL_SMALLER */
    1280 
    12811016/**
    12821017 * Create a principal for the service running on hostname. If
     
    12951030 */
    12961031                       
    1297 krb5_error_code KRB5_LIB_FUNCTION
     1032KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12981033krb5_sname_to_principal (krb5_context context,
    12991034                         const char *hostname,
     
    13651100};
    13661101
    1367 krb5_error_code
     1102/**
     1103 * Parse nametype string and return a nametype integer
     1104 *
     1105 * @ingroup krb5_principal
     1106 */
     1107
     1108KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    13681109krb5_parse_nametype(krb5_context context, const char *str, int32_t *nametype)
    13691110{
     
    13801121    return KRB5_PARSE_MALFORMED;
    13811122}
     1123
     1124/**
     1125 * Check if the cname part of the principal is a krbtgt principal
     1126 *
     1127 * @ingroup krb5_principal
     1128 */
     1129
     1130KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
     1131krb5_principal_is_krbtgt(krb5_context context, krb5_const_principal p)
     1132{
     1133    return p->name.name_string.len == 2 &&
     1134        strcmp(p->name.name_string.val[0], KRB5_TGS_NAME) == 0;
     1135
     1136}
  • trunk/server/source4/heimdal/lib/krb5/prog_setup.c

    r414 r745  
    3636#include <err.h>
    3737
    38 void KRB5_LIB_FUNCTION
     38KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    3939krb5_std_usage(int code, struct getargs *args, int num_args)
    4040{
     
    4343}
    4444
    45 int KRB5_LIB_FUNCTION
     45KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    4646krb5_program_setup(krb5_context *context, int argc, char **argv,
    4747                   struct getargs *args, int num_args,
    48                    void (*usage)(int, struct getargs*, int))
     48                   void (KRB5_LIB_CALL *usage)(int, struct getargs*, int))
    4949{
    5050    krb5_error_code ret;
  • trunk/server/source4/heimdal/lib/krb5/prompter_posix.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 int KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION int KRB5_CALLCONV
    3737krb5_prompter_posix (krb5_context context,
    3838                     void *data,
  • trunk/server/source4/heimdal/lib/krb5/rd_cred.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    3636static krb5_error_code
     
    5353}
    5454
    55 krb5_error_code KRB5_LIB_FUNCTION
     55KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5656krb5_rd_cred(krb5_context context,
    5757             krb5_auth_context auth_context,
     
    323323}
    324324
    325 krb5_error_code KRB5_LIB_FUNCTION
     325KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    326326krb5_rd_cred2 (krb5_context      context,
    327327               krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/rd_error.c

    r414 r745  
    3434#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_rd_error(krb5_context context,
    3838              const krb5_data *msg,
     
    5252}
    5353
    54 void KRB5_LIB_FUNCTION
     54KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    5555krb5_free_error_contents (krb5_context context,
    5656                          krb5_error *error)
     
    6060}
    6161
    62 void KRB5_LIB_FUNCTION
     62KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    6363krb5_free_error (krb5_context context,
    6464                 krb5_error *error)
     
    6868}
    6969
    70 krb5_error_code KRB5_LIB_FUNCTION
     70KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    7171krb5_error_from_rd_error(krb5_context context,
    7272                         const krb5_error *error,
  • trunk/server/source4/heimdal/lib/krb5/rd_priv.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_rd_priv(krb5_context context,
    3838             krb5_auth_context auth_context,
  • trunk/server/source4/heimdal/lib/krb5/rd_rep.c

    r414 r745  
    3232 */
    3333
    34 #include <krb5_locl.h>
     34#include "krb5_locl.h"
    3535
    36 krb5_error_code KRB5_LIB_FUNCTION
     36KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3737krb5_rd_rep(krb5_context context,
    3838            krb5_auth_context auth_context,
     
    109109}
    110110
    111 void KRB5_LIB_FUNCTION
     111KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    112112krb5_free_ap_rep_enc_part (krb5_context context,
    113113                           krb5_ap_rep_enc_part *val)
  • trunk/server/source4/heimdal/lib/krb5/rd_req.c

    r414 r745  
     1
    12/*
    23 * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
     
    3233 */
    3334
    34 #include <krb5_locl.h>
     35#include "krb5_locl.h"
    3536
    3637static krb5_error_code
     
    103104}
    104105
    105 krb5_error_code KRB5_LIB_FUNCTION
     106KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    106107krb5_decode_ap_req(krb5_context context,
    107108                   const krb5_data *inbuf,
     
    218219}
    219220
    220 krb5_error_code KRB5_LIB_FUNCTION
     221KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    221222krb5_decrypt_ticket(krb5_context context,
    222223                    Ticket *ticket,
     
    267268}
    268269
    269 krb5_error_code KRB5_LIB_FUNCTION
     270KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    270271krb5_verify_authenticator_checksum(krb5_context context,
    271272                                   krb5_auth_context ac,
     
    309310
    310311
    311 krb5_error_code KRB5_LIB_FUNCTION
     312KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    312313krb5_verify_ap_req(krb5_context context,
    313314                   krb5_auth_context *auth_context,
     
    330331}
    331332
    332 krb5_error_code KRB5_LIB_FUNCTION
     333KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    333334krb5_verify_ap_req2(krb5_context context,
    334335                    krb5_auth_context *auth_context,
     
    539540 */
    540541
    541 krb5_error_code KRB5_LIB_FUNCTION
     542KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    542543krb5_rd_req_in_ctx_alloc(krb5_context context, krb5_rd_req_in_ctx *ctx)
    543544{
     
    566567 */
    567568
    568 krb5_error_code KRB5_LIB_FUNCTION
     569KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    569570krb5_rd_req_in_set_keytab(krb5_context context,
    570571                          krb5_rd_req_in_ctx in,
     
    587588 */
    588589
    589 krb5_error_code KRB5_LIB_FUNCTION
     590KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    590591krb5_rd_req_in_set_pac_check(krb5_context context,
    591592                             krb5_rd_req_in_ctx in,
     
    597598
    598599
    599 krb5_error_code KRB5_LIB_FUNCTION
     600KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    600601krb5_rd_req_in_set_keyblock(krb5_context context,
    601602                            krb5_rd_req_in_ctx in,
     
    606607}
    607608
    608 krb5_error_code KRB5_LIB_FUNCTION
     609KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    609610krb5_rd_req_out_get_ap_req_options(krb5_context context,
    610611                                   krb5_rd_req_out_ctx out,
     
    615616}
    616617
    617 krb5_error_code KRB5_LIB_FUNCTION
     618KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    618619krb5_rd_req_out_get_ticket(krb5_context context,
    619620                            krb5_rd_req_out_ctx out,
     
    623624}
    624625
    625 krb5_error_code KRB5_LIB_FUNCTION
     626KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    626627krb5_rd_req_out_get_keyblock(krb5_context context,
    627628                            krb5_rd_req_out_ctx out,
     
    643644 */
    644645
    645 krb5_error_code KRB5_LIB_FUNCTION
     646KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    646647krb5_rd_req_out_get_server(krb5_context context,
    647648                            krb5_rd_req_out_ctx out,
     
    651652}
    652653
    653 void  KRB5_LIB_FUNCTION
     654KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    654655krb5_rd_req_in_ctx_free(krb5_context context, krb5_rd_req_in_ctx ctx)
    655656{
     
    666667 */
    667668
    668 void  KRB5_LIB_FUNCTION
     669KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    669670krb5_rd_req_out_ctx_free(krb5_context context, krb5_rd_req_out_ctx ctx)
    670671{
     
    682683 */
    683684
    684 krb5_error_code KRB5_LIB_FUNCTION
     685KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    685686krb5_rd_req(krb5_context context,
    686687            krb5_auth_context *auth_context,
     
    727728 */
    728729
    729 krb5_error_code KRB5_LIB_FUNCTION
     730KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    730731krb5_rd_req_with_keyblock(krb5_context context,
    731732                          krb5_auth_context *auth_context,
     
    821822 *
    822823 * @param server the server with authenticate as, if NULL the function
    823  *        will try to find any avaiable credentintial in the keytab
     824 *        will try to find any available credential in the keytab
    824825 *        that will verify the reply. The function will prefer the
    825826 *        server the server client specified in the AP-REQ, but if
     
    835836 */
    836837
    837 krb5_error_code KRB5_LIB_FUNCTION
     838KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    838839krb5_rd_req_ctx(krb5_context context,
    839840                krb5_auth_context *auth_context,
     
    926927        if (ret) {
    927928            /* If caller specified a server, fail. */
    928             if (service == NULL)
     929            if (service == NULL && (context->flags & KRB5_CTX_F_RD_REQ_IGNORE) == 0)
    929930                goto out;
    930931            /* Otherwise, fall back to iterating over the keytab. This
  • trunk/server/source4/heimdal/lib/krb5/replay.c

    r414 r745  
    3939};
    4040
    41 krb5_error_code KRB5_LIB_FUNCTION
     41KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4242krb5_rc_resolve(krb5_context context,
    4343                krb5_rcache id,
     
    5353}
    5454
    55 krb5_error_code KRB5_LIB_FUNCTION
     55KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5656krb5_rc_resolve_type(krb5_context context,
    5757                     krb5_rcache *id,
     
    7474}
    7575
    76 krb5_error_code KRB5_LIB_FUNCTION
     76KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    7777krb5_rc_resolve_full(krb5_context context,
    7878                     krb5_rcache *id,
     
    100100}
    101101
    102 const char* KRB5_LIB_FUNCTION
     102KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    103103krb5_rc_default_name(krb5_context context)
    104104{
     
    106106}
    107107
    108 const char* KRB5_LIB_FUNCTION
     108KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    109109krb5_rc_default_type(krb5_context context)
    110110{
     
    112112}
    113113
    114 krb5_error_code KRB5_LIB_FUNCTION
     114KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    115115krb5_rc_default(krb5_context context,
    116116                krb5_rcache *id)
     
    124124};
    125125
    126 krb5_error_code KRB5_LIB_FUNCTION
     126KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    127127krb5_rc_initialize(krb5_context context,
    128128                   krb5_rcache id,
     
    134134
    135135    if(f == NULL) {
     136        char buf[128];
    136137        ret = errno;
    137         krb5_set_error_message(context, ret, "open(%s): %s", id->name,
    138                                strerror(ret));
     138        rk_strerror_r(ret, buf, sizeof(buf));
     139        krb5_set_error_message(context, ret, "open(%s): %s", id->name, buf);
    139140        return ret;
    140141    }
     
    145146}
    146147
    147 krb5_error_code KRB5_LIB_FUNCTION
     148KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    148149krb5_rc_recover(krb5_context context,
    149150                krb5_rcache id)
     
    152153}
    153154
    154 krb5_error_code KRB5_LIB_FUNCTION
     155KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    155156krb5_rc_destroy(krb5_context context,
    156157                krb5_rcache id)
     
    159160
    160161    if(remove(id->name) < 0) {
     162        char buf[128];
    161163        ret = errno;
    162         krb5_set_error_message(context, ret, "remove(%s): %s", id->name,
    163                                strerror(ret));
     164        rk_strerror_r(ret, buf, sizeof(buf));
     165        krb5_set_error_message(context, ret, "remove(%s): %s", id->name, buf);
    164166        return ret;
    165167    }
     
    167169}
    168170
    169 krb5_error_code KRB5_LIB_FUNCTION
     171KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    170172krb5_rc_close(krb5_context context,
    171173              krb5_rcache id)
     
    179181checksum_authenticator(Authenticator *auth, void *data)
    180182{
    181     MD5_CTX md5;
    182     int i;
    183 
    184     MD5_Init (&md5);
    185     MD5_Update (&md5, auth->crealm, strlen(auth->crealm));
     183    EVP_MD_CTX *m = EVP_MD_CTX_create();
     184    unsigned i;
     185
     186    EVP_DigestInit_ex(m, EVP_md5(), NULL);
     187
     188    EVP_DigestUpdate(m, auth->crealm, strlen(auth->crealm));
    186189    for(i = 0; i < auth->cname.name_string.len; i++)
    187         MD5_Update(&md5, auth->cname.name_string.val[i],
     190        EVP_DigestUpdate(m, auth->cname.name_string.val[i],
    188191                   strlen(auth->cname.name_string.val[i]));
    189     MD5_Update (&md5, &auth->ctime, sizeof(auth->ctime));
    190     MD5_Update (&md5, &auth->cusec, sizeof(auth->cusec));
    191     MD5_Final (data, &md5);
    192 }
    193 
    194 krb5_error_code KRB5_LIB_FUNCTION
     192    EVP_DigestUpdate(m, &auth->ctime, sizeof(auth->ctime));
     193    EVP_DigestUpdate(m, &auth->cusec, sizeof(auth->cusec));
     194
     195    EVP_DigestFinal_ex(m, data, NULL);
     196    EVP_MD_CTX_destroy(m);
     197}
     198
     199KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    195200krb5_rc_store(krb5_context context,
    196201              krb5_rcache id,
     
    206211    f = fopen(id->name, "r");
    207212    if(f == NULL) {
     213        char buf[128];
    208214        ret = errno;
    209         krb5_set_error_message(context, ret, "open(%s): %s", id->name,
    210                                strerror(ret));
     215        rk_strerror_r(ret, buf, sizeof(buf));
     216        krb5_set_error_message(context, ret, "open(%s): %s", id->name, buf);
    211217        return ret;
    212218    }
     
    224230    }
    225231    if(ferror(f)){
     232        char buf[128];
    226233        ret = errno;
    227234        fclose(f);
     235        rk_strerror_r(ret, buf, sizeof(buf));
    228236        krb5_set_error_message(context, ret, "%s: %s",
    229                                id->name, strerror(ret));
     237                               id->name, buf);
    230238        return ret;
    231239    }
     
    233241    f = fopen(id->name, "a");
    234242    if(f == NULL) {
     243        char buf[128];
     244        rk_strerror_r(errno, buf, sizeof(buf));
    235245        krb5_set_error_message(context, KRB5_RC_IO_UNKNOWN,
    236                                "open(%s): %s", id->name,
    237                                strerror(errno));
     246                               "open(%s): %s", id->name, buf);
    238247        return KRB5_RC_IO_UNKNOWN;
    239248    }
     
    243252}
    244253
    245 krb5_error_code KRB5_LIB_FUNCTION
     254KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    246255krb5_rc_expunge(krb5_context context,
    247256                krb5_rcache id)
     
    250259}
    251260
    252 krb5_error_code KRB5_LIB_FUNCTION
     261KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    253262krb5_rc_get_lifespan(krb5_context context,
    254263                     krb5_rcache id,
     
    268277}
    269278
    270 const char* KRB5_LIB_FUNCTION
     279KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    271280krb5_rc_get_name(krb5_context context,
    272281                 krb5_rcache id)
     
    275284}
    276285               
    277 const char* KRB5_LIB_FUNCTION
     286KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL
    278287krb5_rc_get_type(krb5_context context,
    279288                 krb5_rcache id)
     
    282291}
    283292               
    284 krb5_error_code KRB5_LIB_FUNCTION
     293KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    285294krb5_get_server_rcache(krb5_context context,
    286295                       const krb5_data *piece,
     
    300309    strvisx(tmp, piece->data, piece->length, VIS_WHITE | VIS_OCTAL);
    301310#ifdef HAVE_GETEUID
    302     asprintf(&name, "FILE:rc_%s_%u", tmp, (unsigned)geteuid());
     311    ret = asprintf(&name, "FILE:rc_%s_%u", tmp, (unsigned)geteuid());
    303312#else
    304     asprintf(&name, "FILE:rc_%s", tmp);
     313    ret = asprintf(&name, "FILE:rc_%s", tmp);
    305314#endif
    306315    free(tmp);
    307     if(name == NULL) {
     316    if(ret < 0 || name == NULL) {
    308317        krb5_set_error_message(context, ENOMEM,
    309318                               N_("malloc: out of memory", ""));
  • trunk/server/source4/heimdal/lib/krb5/send_to_kdc.c

    r414 r745  
    4848
    4949static int
    50 recv_loop (int fd,
     50recv_loop (krb5_socket_t fd,
    5151           time_t tmout,
    5252           int udp,
     
    5959     int nbytes;
    6060
     61#ifndef NO_LIMIT_FD_SETSIZE
    6162     if (fd >= FD_SETSIZE) {
    6263         return -1;
    6364     }
     65#endif
    6466
    6567     krb5_data_zero(rep);
     
    7981             void *tmp;
    8082
    81              if (ioctl (fd, FIONREAD, &nbytes) < 0) {
     83             if (rk_SOCK_IOCTL (fd, FIONREAD, &nbytes) < 0) {
    8284                 krb5_data_free (rep);
    8385                 return -1;
     
    112114
    113115static int
    114 send_and_recv_udp(int fd,
     116send_and_recv_udp(krb5_socket_t fd,
    115117                  time_t tmout,
    116118                  const krb5_data *req,
     
    131133
    132134static int
    133 send_and_recv_tcp(int fd,
     135send_and_recv_tcp(krb5_socket_t fd,
    134136                  time_t tmout,
    135137                  const krb5_data *req,
     
    141143
    142144    _krb5_put_int(len, req->length, 4);
    143     if(net_write(fd, len, sizeof(len)) < 0)
    144         return -1;
    145     if(net_write(fd, req->data, req->length) < 0)
     145    if(net_write (fd, len, sizeof(len)) < 0)
     146        return -1;
     147    if(net_write (fd, req->data, req->length) < 0)
    146148        return -1;
    147149    if (recv_loop (fd, tmout, 0, 4, &len_data) < 0)
     
    163165
    164166int
    165 _krb5_send_and_recv_tcp(int fd,
     167_krb5_send_and_recv_tcp(krb5_socket_t fd,
    166168                        time_t tmout,
    167169                        const krb5_data *req,
     
    176178
    177179static int
    178 send_and_recv_http(int fd,
     180send_and_recv_http(krb5_socket_t fd,
    179181                   time_t tmout,
    180182                   const char *prefix,
     
    182184                   krb5_data *rep)
    183185{
    184     char *request;
     186    char *request = NULL;
    185187    char *str;
    186188    int ret;
     
    189191    if(len < 0)
    190192        return -1;
    191     asprintf(&request, "GET %s%s HTTP/1.0\r\n\r\n", prefix, str);
     193    ret = asprintf(&request, "GET %s%s HTTP/1.0\r\n\r\n", prefix, str);
    192194    free(str);
    193     if (request == NULL)
     195    if (ret < 0 || request == NULL)
    194196        return -1;
    195197    ret = net_write (fd, request, strlen(request));
     
    260262    char *proxy2 = strdup(context->http_proxy);
    261263    char *proxy  = proxy2;
    262     char *prefix;
     264    char *prefix = NULL;
    263265    char *colon;
    264266    struct addrinfo hints;
    265267    struct addrinfo *ai, *a;
    266268    int ret;
    267     int s = -1;
     269    krb5_socket_t s = rk_INVALID_SOCKET;
    268270    char portstr[NI_MAXSERV];
    269271               
     
    287289
    288290    for (a = ai; a != NULL; a = a->ai_next) {
    289         s = socket (a->ai_family, a->ai_socktype, a->ai_protocol | SOCK_CLOEXEC);
     291        s = socket (a->ai_family, a->ai_socktype | SOCK_CLOEXEC, a->ai_protocol);
    290292        if (s < 0)
    291293            continue;
    292294        rk_cloexec(s);
    293295        if (connect (s, a->ai_addr, a->ai_addrlen) < 0) {
    294             close (s);
     296            rk_closesocket (s);
    295297            continue;
    296298        }
     
    303305    freeaddrinfo (ai);
    304306
    305     asprintf(&prefix, "http://%s/", hi->hostname);
    306     if(prefix == NULL) {
     307    ret = asprintf(&prefix, "http://%s/", hi->hostname);
     308    if(ret < 0 || prefix == NULL) {
    307309        close(s);
    308310        return 1;
     
    310312    ret = send_and_recv_http(s, context->kdc_timeout,
    311313                             prefix, send_data, receive);
    312     close (s);
     314    rk_closesocket (s);
    313315    free(prefix);
    314316    if(ret == 0 && receive->length != 0)
     
    362364 */
    363365
    364 krb5_error_code KRB5_LIB_FUNCTION
     366KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    365367krb5_sendto (krb5_context context,
    366368             const krb5_data *send_data,
     
    369371{
    370372     krb5_error_code ret;
    371      int fd;
     373     krb5_socket_t fd;
    372374     int i;
    373375
     
    379381         while (krb5_krbhst_next(context, handle, &hi) == 0) {
    380382             struct addrinfo *ai, *a;
     383
     384             _krb5_debug(context, 2,
     385                         "trying to communicate with host %s in realm %s",
     386                         hi->hostname, _krb5_krbhst_get_realm(handle));
    381387
    382388             if (context->send_to_kdc) {
     
    411417             for (a = ai; a != NULL; a = a->ai_next) {
    412418                 fd = socket (a->ai_family, a->ai_socktype | SOCK_CLOEXEC, a->ai_protocol);
    413                  if (fd < 0)
     419                 if (rk_IS_BAD_SOCKET(fd))
    414420                     continue;
    415421                 rk_cloexec(fd);
    416422                 if (connect (fd, a->ai_addr, a->ai_addrlen) < 0) {
    417                      close (fd);
     423                     rk_closesocket (fd);
    418424                     continue;
    419425                 }
     
    432438                     break;
    433439                 }
    434                  close (fd);
     440                 rk_closesocket (fd);
    435441                 if(ret == 0 && receive->length != 0)
    436442                     goto out;
     
    442448     ret = KRB5_KDC_UNREACH;
    443449out:
     450     _krb5_debug(context, 2,
     451                 "result of trying to talk to realm %s = %d",
     452                 _krb5_krbhst_get_realm(handle), ret);
    444453     return ret;
    445454}
    446455
    447 krb5_error_code KRB5_LIB_FUNCTION
     456KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    448457krb5_sendto_kdc(krb5_context context,
    449458                const krb5_data *send_data,
     
    454463}
    455464
    456 krb5_error_code KRB5_LIB_FUNCTION
     465KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    457466krb5_sendto_kdc_flags(krb5_context context,
    458467                      const krb5_data *send_data,
     
    475484}
    476485
    477 krb5_error_code KRB5_LIB_FUNCTION
     486KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    478487krb5_set_send_to_kdc_func(krb5_context context,
    479488                          krb5_send_to_kdc_func func,
     
    498507}
    499508
    500 krb5_error_code KRB5_LIB_FUNCTION
     509KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    501510_krb5_copy_send_to_kdc_func(krb5_context context, krb5_context to)
    502511{
     
    518527};
    519528
    520 krb5_error_code KRB5_LIB_FUNCTION
     529KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    521530krb5_sendto_ctx_alloc(krb5_context context, krb5_sendto_ctx *ctx)
    522531{
     
    530539}
    531540
    532 void KRB5_LIB_FUNCTION
     541KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    533542krb5_sendto_ctx_add_flags(krb5_sendto_ctx ctx, int flags)
    534543{
     
    536545}
    537546
    538 int KRB5_LIB_FUNCTION
     547KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    539548krb5_sendto_ctx_get_flags(krb5_sendto_ctx ctx)
    540549{
     
    542551}
    543552
    544 void KRB5_LIB_FUNCTION
     553KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    545554krb5_sendto_ctx_set_type(krb5_sendto_ctx ctx, int type)
    546555{
     
    549558
    550559
    551 void KRB5_LIB_FUNCTION
     560KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    552561krb5_sendto_ctx_set_func(krb5_sendto_ctx ctx,
    553562                         krb5_sendto_ctx_func func,
     
    558567}
    559568
    560 void KRB5_LIB_FUNCTION
     569KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    561570krb5_sendto_ctx_free(krb5_context context, krb5_sendto_ctx ctx)
    562571{
     
    565574}
    566575
    567 krb5_error_code KRB5_LIB_FUNCTION
     576KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    568577krb5_sendto_context(krb5_context context,
    569578                    krb5_sendto_ctx ctx,
     
    640649}
    641650
    642 krb5_error_code
     651krb5_error_code KRB5_CALLCONV
    643652_krb5_kdc_retry(krb5_context context, krb5_sendto_ctx ctx, void *data,
    644653                const krb5_data *reply, int *action)
  • trunk/server/source4/heimdal/lib/krb5/set_default_realm.c

    r414 r745  
    6666 */
    6767
    68 krb5_error_code KRB5_LIB_FUNCTION
     68KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    6969krb5_set_default_realm(krb5_context context,
    7070                       const char *realm)
  • trunk/server/source4/heimdal/lib/krb5/store.c

    r414 r745  
    4141                               krb5_storage_is_flags((SP), KRB5_STORAGE_HOST_BYTEORDER))
    4242
    43 void KRB5_LIB_FUNCTION
     43/**
     44 * Add the flags on a storage buffer by or-ing in the flags to the buffer.
     45 *
     46 * @param sp the storage buffer to set the flags on
     47 * @param flags the flags to set
     48 *
     49 * @ingroup krb5_storage
     50 */
     51
     52KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    4453krb5_storage_set_flags(krb5_storage *sp, krb5_flags flags)
    4554{
     
    4756}
    4857
    49 void KRB5_LIB_FUNCTION
     58/**
     59 * Clear the flags on a storage buffer
     60 *
     61 * @param sp the storage buffer to clear the flags on
     62 * @param flags the flags to clear
     63 *
     64 * @ingroup krb5_storage
     65 */
     66
     67KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    5068krb5_storage_clear_flags(krb5_storage *sp, krb5_flags flags)
    5169{
     
    6583 */
    6684
    67 krb5_boolean KRB5_LIB_FUNCTION
     85KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
    6886krb5_storage_is_flags(krb5_storage *sp, krb5_flags flags)
    6987{
     
    83101 */
    84102
    85 void KRB5_LIB_FUNCTION
     103KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    86104krb5_storage_set_byteorder(krb5_storage *sp, krb5_flags byteorder)
    87105{
     
    96114 */
    97115
    98 krb5_flags KRB5_LIB_FUNCTION
     116KRB5_LIB_FUNCTION krb5_flags KRB5_LIB_CALL
    99117krb5_storage_get_byteorder(krb5_storage *sp)
    100118{
     
    115133 */
    116134
    117 off_t KRB5_LIB_FUNCTION
     135KRB5_LIB_FUNCTION off_t KRB5_LIB_CALL
    118136krb5_storage_seek(krb5_storage *sp, off_t offset, int whence)
    119137{
     
    132150 */
    133151
    134 int KRB5_LIB_FUNCTION
     152KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    135153krb5_storage_truncate(krb5_storage *sp, off_t offset)
    136154{
     
    150168 */
    151169
    152 krb5_ssize_t KRB5_LIB_FUNCTION
     170KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
    153171krb5_storage_read(krb5_storage *sp, void *buf, size_t len)
    154172{
     
    168186 */
    169187
    170 krb5_ssize_t KRB5_LIB_FUNCTION
     188KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
    171189krb5_storage_write(krb5_storage *sp, const void *buf, size_t len)
    172190{
     
    183201 */
    184202
    185 void KRB5_LIB_FUNCTION
     203KRB5_LIB_FUNCTION void KRB5_LIB_CALL
    186204krb5_storage_set_eof_code(krb5_storage *sp, int code)
    187205{
     
    199217 */
    200218
    201 int KRB5_LIB_FUNCTION
     219KRB5_LIB_FUNCTION int KRB5_LIB_CALL
    202220krb5_storage_get_eof_code(krb5_storage *sp)
    203221{
     
    205223}
    206224
    207 krb5_ssize_t KRB5_LIB_FUNCTION
    208 _krb5_put_int(void *buffer, unsigned long value, size_t size)
    209 {
    210     unsigned char *p = buffer;
    211     int i;
    212     for (i = size - 1; i >= 0; i--) {
    213         p[i] = value & 0xff;
    214         value >>= 8;
    215     }
    216     return size;
    217 }
    218 
    219 krb5_ssize_t KRB5_LIB_FUNCTION
    220 _krb5_get_int(void *buffer, unsigned long *value, size_t size)
    221 {
    222     unsigned char *p = buffer;
    223     unsigned long v = 0;
    224     int i;
    225     for (i = 0; i < size; i++)
    226         v = (v << 8) + p[i];
    227     *value = v;
    228     return size;
    229 }
    230 
    231225/**
    232226 * Free a krb5 storage.
     
    239233 */
    240234
    241 krb5_error_code KRB5_LIB_FUNCTION
     235KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    242236krb5_storage_free(krb5_storage *sp)
    243237{
     
    260254 */
    261255
    262 krb5_error_code KRB5_LIB_FUNCTION
     256KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    263257krb5_storage_to_data(krb5_storage *sp, krb5_data *data)
    264258{
     
    314308 */
    315309
    316 krb5_error_code KRB5_LIB_FUNCTION
     310KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    317311krb5_store_int32(krb5_storage *sp,
    318312                 int32_t value)
     
    337331 */
    338332
    339 krb5_error_code KRB5_LIB_FUNCTION
     333KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    340334krb5_store_uint32(krb5_storage *sp,
    341335                  uint32_t value)
     
    360354}
    361355
    362 krb5_error_code KRB5_LIB_FUNCTION
     356/**
     357 * Read a int32 from storage, byte order is controlled by the settings
     358 * on the storage, see krb5_storage_set_byteorder().
     359 *
     360 * @param sp the storage to write too
     361 * @param value the value read from the buffer
     362 *
     363 * @return 0 for success, or a Kerberos 5 error code on failure.
     364 *
     365 * @ingroup krb5_storage
     366 */
     367
     368KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    363369krb5_ret_int32(krb5_storage *sp,
    364370               int32_t *value)
     
    374380}
    375381
    376 krb5_error_code KRB5_LIB_FUNCTION
     382/**
     383 * Read a uint32 from storage, byte order is controlled by the settings
     384 * on the storage, see krb5_storage_set_byteorder().
     385 *
     386 * @param sp the storage to write too
     387 * @param value the value read from the buffer
     388 *
     389 * @return 0 for success, or a Kerberos 5 error code on failure.
     390 *
     391 * @ingroup krb5_storage
     392 */
     393
     394KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    377395krb5_ret_uint32(krb5_storage *sp,
    378396                uint32_t *value)
     
    400418 */
    401419
    402 krb5_error_code KRB5_LIB_FUNCTION
     420KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    403421krb5_store_int16(krb5_storage *sp,
    404422                 int16_t value)
     
    423441 */
    424442
    425 krb5_error_code KRB5_LIB_FUNCTION
     443KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    426444krb5_store_uint16(krb5_storage *sp,
    427445                  uint16_t value)
     
    430448}
    431449
    432 krb5_error_code KRB5_LIB_FUNCTION
     450/**
     451 * Read a int16 from storage, byte order is controlled by the settings
     452 * on the storage, see krb5_storage_set_byteorder().
     453 *
     454 * @param sp the storage to write too
     455 * @param value the value read from the buffer
     456 *
     457 * @return 0 for success, or a Kerberos 5 error code on failure.
     458 *
     459 * @ingroup krb5_storage
     460 */
     461
     462KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    433463krb5_ret_int16(krb5_storage *sp,
    434464               int16_t *value)
     
    447477}
    448478
    449 krb5_error_code KRB5_LIB_FUNCTION
     479/**
     480 * Read a int16 from storage, byte order is controlled by the settings
     481 * on the storage, see krb5_storage_set_byteorder().
     482 *
     483 * @param sp the storage to write too
     484 * @param value the value read from the buffer
     485 *
     486 * @return 0 for success, or a Kerberos 5 error code on failure.
     487 *
     488 * @ingroup krb5_storage
     489 */
     490
     491KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    450492krb5_ret_uint16(krb5_storage *sp,
    451493                uint16_t *value)
     
    472514 */
    473515
    474 krb5_error_code KRB5_LIB_FUNCTION
     516KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    475517krb5_store_int8(krb5_storage *sp,
    476518                int8_t value)
     
    495537 */
    496538
    497 krb5_error_code KRB5_LIB_FUNCTION
     539KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    498540krb5_store_uint8(krb5_storage *sp,
    499541                 uint8_t value)
     
    502544}
    503545
    504 krb5_error_code KRB5_LIB_FUNCTION
     546/**
     547 * Read a int8 from storage
     548 *
     549 * @param sp the storage to write too
     550 * @param value the value read from the buffer
     551 *
     552 * @return 0 for success, or a Kerberos 5 error code on failure.
     553 *
     554 * @ingroup krb5_storage
     555 */
     556
     557KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    505558krb5_ret_int8(krb5_storage *sp,
    506559              int8_t *value)
     
    514567}
    515568
    516 krb5_error_code KRB5_LIB_FUNCTION
     569/**
     570 * Read a uint8 from storage
     571 *
     572 * @param sp the storage to write too
     573 * @param value the value read from the buffer
     574 *
     575 * @return 0 for success, or a Kerberos 5 error code on failure.
     576 *
     577 * @ingroup krb5_storage
     578 */
     579
     580KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    517581krb5_ret_uint8(krb5_storage *sp,
    518582               uint8_t *value)
     
    529593
    530594/**
    531  * Store a data to the storage.
     595 * Store a data to the storage. The data is stored with an int32 as
     596 * lenght plus the data (not padded).
    532597 *
    533598 * @param sp the storage buffer to write to
     
    539604 */
    540605
    541 krb5_error_code KRB5_LIB_FUNCTION
     606KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    542607krb5_store_data(krb5_storage *sp,
    543608                krb5_data data)
     
    567632 */
    568633
    569 krb5_error_code KRB5_LIB_FUNCTION
     634KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    570635krb5_ret_data(krb5_storage *sp,
    571636              krb5_data *data)
     
    588653}
    589654
    590 krb5_error_code KRB5_LIB_FUNCTION
     655/**
     656 * Store a string to the buffer. The data is formated as an len:uint32
     657 * plus the string itself (not padded).
     658 *
     659 * @param sp the storage buffer to write to
     660 * @param s the string to store.
     661 *
     662 * @return 0 on success, a Kerberos 5 error code on failure.
     663 *
     664 * @ingroup krb5_storage
     665 */
     666
     667KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    591668krb5_store_string(krb5_storage *sp, const char *s)
    592669{
     
    597674}
    598675
    599 krb5_error_code KRB5_LIB_FUNCTION
     676/**
     677 * Parse a string from the storage.
     678 *
     679 * @param sp the storage buffer to read from
     680 * @param string the parsed string
     681 *
     682 * @return 0 on success, a Kerberos 5 error code on failure.
     683 *
     684 * @ingroup krb5_storage
     685 */
     686
     687
     688KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    600689krb5_ret_string(krb5_storage *sp,
    601690                char **string)
     
    615704}
    616705
    617 krb5_error_code KRB5_LIB_FUNCTION
     706/**
     707 * Store a zero terminated string to the buffer. The data is stored
     708 * one character at a time until a NUL is stored.
     709 *
     710 * @param sp the storage buffer to write to
     711 * @param s the string to store.
     712 *
     713 * @return 0 on success, a Kerberos 5 error code on failure.
     714 *
     715 * @ingroup krb5_storage
     716 */
     717
     718KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    618719krb5_store_stringz(krb5_storage *sp, const char *s)
    619720{
     
    631732}
    632733
    633 krb5_error_code KRB5_LIB_FUNCTION
     734/**
     735 * Parse zero terminated string from the storage.
     736 *
     737 * @param sp the storage buffer to read from
     738 * @param string the parsed string
     739 *
     740 * @return 0 on success, a Kerberos 5 error code on failure.
     741 *
     742 * @ingroup krb5_storage
     743 */
     744
     745KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    634746krb5_ret_stringz(krb5_storage *sp,
    635747                char **string)
     
    664776}
    665777
    666 krb5_error_code KRB5_LIB_FUNCTION
     778KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    667779krb5_store_stringnl(krb5_storage *sp, const char *s)
    668780{
     
    689801}
    690802
    691 krb5_error_code KRB5_LIB_FUNCTION
     803KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    692804krb5_ret_stringnl(krb5_storage *sp,
    693805                  char **string)
     
    734846}
    735847
    736 
    737 krb5_error_code KRB5_LIB_FUNCTION
     848/**
     849 * Write a principal block to storage.
     850 *
     851 * @param sp the storage buffer to write to
     852 * @param p the principal block to write.
     853 *
     854 * @return 0 on success, a Kerberos 5 error code on failure.
     855 *
     856 * @ingroup krb5_storage
     857 */
     858
     859KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    738860krb5_store_principal(krb5_storage *sp,
    739861                     krb5_const_principal p)
     
    761883}
    762884
    763 krb5_error_code KRB5_LIB_FUNCTION
     885/**
     886 * Parse principal from the storage.
     887 *
     888 * @param sp the storage buffer to read from
     889 * @param princ the parsed principal
     890 *
     891 * @return 0 on success, a Kerberos 5 error code on failure.
     892 *
     893 * @ingroup krb5_storage
     894 */
     895
     896KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    764897krb5_ret_principal(krb5_storage *sp,
    765898                   krb5_principal *princ)
     
    829962 */
    830963
    831 krb5_error_code KRB5_LIB_FUNCTION
     964KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    832965krb5_store_keyblock(krb5_storage *sp, krb5_keyblock p)
    833966{
     
    858991 */
    859992
    860 krb5_error_code KRB5_LIB_FUNCTION
     993KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    861994krb5_ret_keyblock(krb5_storage *sp, krb5_keyblock *p)
    862995{
     
    8881021 */
    8891022
    890 krb5_error_code KRB5_LIB_FUNCTION
     1023KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    8911024krb5_store_times(krb5_storage *sp, krb5_times times)
    8921025{
     
    9131046 */
    9141047
    915 krb5_error_code KRB5_LIB_FUNCTION
     1048KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9161049krb5_ret_times(krb5_storage *sp, krb5_times *times)
    9171050{
     
    9321065}
    9331066
    934 krb5_error_code KRB5_LIB_FUNCTION
     1067/**
     1068 * Write a address block to storage.
     1069 *
     1070 * @param sp the storage buffer to write to
     1071 * @param p the address block to write.
     1072 *
     1073 * @return 0 on success, a Kerberos 5 error code on failure.
     1074 *
     1075 * @ingroup krb5_storage
     1076 */
     1077
     1078KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9351079krb5_store_address(krb5_storage *sp, krb5_address p)
    9361080{
     
    9421086}
    9431087
    944 krb5_error_code KRB5_LIB_FUNCTION
     1088/**
     1089 * Read a address block from the storage.
     1090 *
     1091 * @param sp the storage buffer to write to
     1092 * @param adr the address block read from storage
     1093 *
     1094 * @return 0 on success, a Kerberos 5 error code on failure.
     1095 *
     1096 * @ingroup krb5_storage
     1097 */
     1098
     1099KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9451100krb5_ret_address(krb5_storage *sp, krb5_address *adr)
    9461101{
     
    9541109}
    9551110
    956 krb5_error_code KRB5_LIB_FUNCTION
     1111/**
     1112 * Write a addresses block to storage.
     1113 *
     1114 * @param sp the storage buffer to write to
     1115 * @param p the addresses block to write.
     1116 *
     1117 * @return 0 on success, a Kerberos 5 error code on failure.
     1118 *
     1119 * @ingroup krb5_storage
     1120 */
     1121
     1122KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9571123krb5_store_addrs(krb5_storage *sp, krb5_addresses p)
    9581124{
     
    9681134}
    9691135
    970 krb5_error_code KRB5_LIB_FUNCTION
     1136/**
     1137 * Read a addresses block from the storage.
     1138 *
     1139 * @param sp the storage buffer to write to
     1140 * @param adr the addresses block read from storage
     1141 *
     1142 * @return 0 on success, a Kerberos 5 error code on failure.
     1143 *
     1144 * @ingroup krb5_storage
     1145 */
     1146
     1147KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9711148krb5_ret_addrs(krb5_storage *sp, krb5_addresses *adr)
    9721149{
     
    9881165}
    9891166
    990 krb5_error_code KRB5_LIB_FUNCTION
     1167/**
     1168 * Write a auth data block to storage.
     1169 *
     1170 * @param sp the storage buffer to write to
     1171 * @param auth the auth data block to write.
     1172 *
     1173 * @return 0 on success, a Kerberos 5 error code on failure.
     1174 *
     1175 * @ingroup krb5_storage
     1176 */
     1177
     1178KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9911179krb5_store_authdata(krb5_storage *sp, krb5_authdata auth)
    9921180{
     
    10041192}
    10051193
    1006 krb5_error_code KRB5_LIB_FUNCTION
     1194/**
     1195 * Read a auth data from the storage.
     1196 *
     1197 * @param sp the storage buffer to write to
     1198 * @param auth the auth data block read from storage
     1199 *
     1200 * @return 0 on success, a Kerberos 5 error code on failure.
     1201 *
     1202 * @ingroup krb5_storage
     1203 */
     1204
     1205KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10071206krb5_ret_authdata(krb5_storage *sp, krb5_authdata *auth)
    10081207{
     
    10381237}
    10391238
    1040 
    1041 /*
    1042  *
    1043  */
    1044 
    1045 krb5_error_code KRB5_LIB_FUNCTION
     1239/**
     1240 * Write a credentials block to storage.
     1241 *
     1242 * @param sp the storage buffer to write to
     1243 * @param creds the creds block to write.
     1244 *
     1245 * @return 0 on success, a Kerberos 5 error code on failure.
     1246 *
     1247 * @ingroup krb5_storage
     1248 */
     1249
     1250KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10461251krb5_store_creds(krb5_storage *sp, krb5_creds *creds)
    10471252{
     
    10841289}
    10851290
    1086 krb5_error_code KRB5_LIB_FUNCTION
     1291/**
     1292 * Read a credentials block from the storage.
     1293 *
     1294 * @param sp the storage buffer to write to
     1295 * @param creds the credentials block read from storage
     1296 *
     1297 * @return 0 on success, a Kerberos 5 error code on failure.
     1298 *
     1299 * @ingroup krb5_storage
     1300 */
     1301
     1302KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    10871303krb5_ret_creds(krb5_storage *sp, krb5_creds *creds)
    10881304{
     
    11451361#define SC_ADDRESSES                0x0040
    11461362
    1147 /*
    1148  *
    1149  */
    1150 
    1151 krb5_error_code KRB5_LIB_FUNCTION
     1363/**
     1364 * Write a tagged credentials block to storage.
     1365 *
     1366 * @param sp the storage buffer to write to
     1367 * @param creds the creds block to write.
     1368 *
     1369 * @return 0 on success, a Kerberos 5 error code on failure.
     1370 *
     1371 * @ingroup krb5_storage
     1372 */
     1373
     1374KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    11521375krb5_store_creds_tag(krb5_storage *sp, krb5_creds *creds)
    11531376{
     
    12301453}
    12311454
    1232 krb5_error_code KRB5_LIB_FUNCTION
     1455/**
     1456 * Read a tagged credentials block from the storage.
     1457 *
     1458 * @param sp the storage buffer to write to
     1459 * @param creds the credentials block read from storage
     1460 *
     1461 * @return 0 on success, a Kerberos 5 error code on failure.
     1462 *
     1463 * @ingroup krb5_storage
     1464 */
     1465
     1466KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    12331467krb5_ret_creds_tag(krb5_storage *sp,
    12341468                   krb5_creds *creds)
  • trunk/server/source4/heimdal/lib/krb5/store_emem.c

    r414 r745  
    159159 */
    160160
    161 krb5_storage * KRB5_LIB_FUNCTION
     161KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
    162162krb5_storage_emem(void)
    163163{
  • trunk/server/source4/heimdal/lib/krb5/store_fd.c

    r414 r745  
    8686 */
    8787
    88 krb5_storage * KRB5_LIB_FUNCTION
    89 krb5_storage_from_fd(int fd)
     88KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
     89krb5_storage_from_fd(krb5_socket_t fd_in)
    9090{
    9191    krb5_storage *sp;
     92    int fd;
    9293
    93     fd = dup(fd);
     94#ifdef SOCKET_IS_NOT_AN_FD
     95#ifdef _MSC_VER
     96    if (_get_osfhandle(fd_in) != -1) {
     97        fd = dup(fd_in);
     98    } else {
     99        fd = _open_osfhandle(fd_in, 0);
     100    }
     101#else
     102#error Dont know how to deal with fd that may or may not be a socket.
     103#endif
     104#else  /* SOCKET_IS_NOT_AN_FD */
     105    fd = dup(fd_in);
     106#endif
     107
    94108    if (fd < 0)
    95109        return NULL;
  • trunk/server/source4/heimdal/lib/krb5/store_mem.c

    r414 r745  
    111111
    112112/**
    113  *
     113 * Create a fixed size memory storage block
    114114 *
    115115 * @return A krb5_storage on success, or NULL on out of memory error.
     
    123123 */
    124124
    125 krb5_storage * KRB5_LIB_FUNCTION
     125KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
    126126krb5_storage_from_mem(void *buf, size_t len)
    127127{
     
    150150
    151151/**
    152  *
     152 * Create a fixed size memory storage block
    153153 *
    154154 * @return A krb5_storage on success, or NULL on out of memory error.
     
    162162 */
    163163
    164 krb5_storage * KRB5_LIB_FUNCTION
     164KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
    165165krb5_storage_from_data(krb5_data *data)
    166166{
     
    169169
    170170/**
    171  *
     171 * Create a fixed size memory storage block that is read only
    172172 *
    173173 * @return A krb5_storage on success, or NULL on out of memory error.
     
    181181 */
    182182
    183 krb5_storage * KRB5_LIB_FUNCTION
     183KRB5_LIB_FUNCTION krb5_storage * KRB5_LIB_CALL
    184184krb5_storage_from_readonly_mem(const void *buf, size_t len)
    185185{
  • trunk/server/source4/heimdal/lib/krb5/ticket.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    3436#include "krb5_locl.h"
    3537
    36 krb5_error_code KRB5_LIB_FUNCTION
     38/**
     39 * Free ticket and content
     40 *
     41 * @param context a Kerberos 5 context
     42 * @param ticket ticket to free
     43 *
     44 * @return Returns 0 to indicate success.  Otherwise an kerberos et
     45 * error code is returned, see krb5_get_error_message().
     46 *
     47 * @ingroup krb5
     48 */
     49
     50KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    3751krb5_free_ticket(krb5_context context,
    3852                 krb5_ticket *ticket)
     
    4559}
    4660
    47 krb5_error_code KRB5_LIB_FUNCTION
     61/**
     62 * Copy ticket and content
     63 *
     64 * @param context a Kerberos 5 context
     65 * @param from ticket to copy
     66 * @param to new copy of ticket, free with krb5_free_ticket()
     67 *
     68 * @return Returns 0 to indicate success.  Otherwise an kerberos et
     69 * error code is returned, see krb5_get_error_message().
     70 *
     71 * @ingroup krb5
     72 */
     73
     74KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    4875krb5_copy_ticket(krb5_context context,
    4976                 const krb5_ticket *from,
     
    81108}
    82109
    83 krb5_error_code KRB5_LIB_FUNCTION
     110/**
     111 * Return client principal in ticket
     112 *
     113 * @param context a Kerberos 5 context
     114 * @param ticket ticket to copy
     115 * @param client client principal, free with krb5_free_principal()
     116 *
     117 * @return Returns 0 to indicate success.  Otherwise an kerberos et
     118 * error code is returned, see krb5_get_error_message().
     119 *
     120 * @ingroup krb5
     121 */
     122
     123KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    84124krb5_ticket_get_client(krb5_context context,
    85125                       const krb5_ticket *ticket,
     
    89129}
    90130
    91 krb5_error_code KRB5_LIB_FUNCTION
     131/**
     132 * Return server principal in ticket
     133 *
     134 * @param context a Kerberos 5 context
     135 * @param ticket ticket to copy
     136 * @param server server principal, free with krb5_free_principal()
     137 *
     138 * @return Returns 0 to indicate success.  Otherwise an kerberos et
     139 * error code is returned, see krb5_get_error_message().
     140 *
     141 * @ingroup krb5
     142 */
     143
     144KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    92145krb5_ticket_get_server(krb5_context context,
    93146                       const krb5_ticket *ticket,
     
    97150}
    98151
    99 time_t KRB5_LIB_FUNCTION
     152/**
     153 * Return end time of ticket
     154 *
     155 * @param context a Kerberos 5 context
     156 * @param ticket ticket to copy
     157 *
     158 * @return end time of ticket
     159 *
     160 * @ingroup krb5
     161 */
     162
     163KRB5_LIB_FUNCTION time_t KRB5_LIB_CALL
    100164krb5_ticket_get_endtime(krb5_context context,
    101165                        const krb5_ticket *ticket)
     
    114178 * @ingroup krb5_ticket
    115179 */
    116 unsigned long
     180KRB5_LIB_FUNCTION unsigned long KRB5_LIB_CALL
    117181krb5_ticket_get_flags(krb5_context context,
    118182                      const krb5_ticket *ticket)
     
    262326}
    263327
    264 /*
    265  * Extract the authorization data type of `type' from the
    266  * 'ticket'. Store the field in `data'. This function is to use for
    267  * kerberos applications.
     328/**
     329 * Extract the authorization data type of type from the ticket. Store
     330 * the field in data. This function is to use for kerberos
     331 * applications.
     332 *
     333 * @param context a Kerberos 5 context
     334 * @param ticket Kerberos ticket
     335 * @param type type to fetch
     336 * @param data returned data, free with krb5_data_free()
     337 *
     338 * @ingroup krb5
    268339 */
    269340
    270 krb5_error_code KRB5_LIB_FUNCTION
     341KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    271342krb5_ticket_get_authorization_data_type(krb5_context context,
    272343                                        krb5_ticket *ticket,
     
    373444    }
    374445
    375     if (returned->name.name_string.len == 2 &&
    376         strcmp(returned->name.name_string.val[0], KRB5_TGS_NAME) == 0)
    377     {
     446    if (krb5_principal_is_krbtgt(context, returned)) {
    378447        const char *realm = returned->name.name_string.val[1];
    379448
     
    415484    return ret;
    416485noreferral:
    417     if (krb5_principal_compare(context, requested, returned) == FALSE) {
     486    /*
     487     * Expect excact match or that we got a krbtgt
     488     */
     489    if (krb5_principal_compare(context, requested, returned) != TRUE &&
     490        (krb5_realm_compare(context, requested, returned) != TRUE &&
     491         krb5_principal_is_krbtgt(context, returned) != TRUE))
     492    {
    418493        krb5_set_error_message(context, KRB5KRB_AP_ERR_MODIFIED,
    419494                               N_("Not same server principal returned "
     
    528603
    529604
    530 static krb5_error_code
     605static krb5_error_code KRB5_CALLCONV
    531606decrypt_tkt (krb5_context context,
    532607             krb5_keyblock *key,
     
    693768    krb5_timeofday (context, &sec_now);
    694769    if (rep->enc_part.flags.initial
     770        && (flags & EXTRACT_TICKET_TIMESYNC)
    695771        && context->kdc_sec_offset == 0
    696772        && krb5_config_get_bool (context, NULL,
  • trunk/server/source4/heimdal/lib/krb5/time.c

    r414 r745  
    4848 */
    4949
    50 krb5_error_code KRB5_LIB_FUNCTION
     50KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    5151krb5_set_real_time (krb5_context context,
    5252                    krb5_timestamp sec,
     
    8080 */
    8181
    82 krb5_error_code KRB5_LIB_FUNCTION
     82KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    8383krb5_timeofday (krb5_context context,
    8484                krb5_timestamp *timeret)
     
    9292 */
    9393
    94 krb5_error_code KRB5_LIB_FUNCTION
     94KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    9595krb5_us_timeofday (krb5_context context,
    9696                   krb5_timestamp *sec,
     
    106106}
    107107
    108 krb5_error_code KRB5_LIB_FUNCTION
     108KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    109109krb5_format_time(krb5_context context, time_t t,
    110110                 char *s, size_t len, krb5_boolean include_time)
     
    121121}
    122122
    123 krb5_error_code KRB5_LIB_FUNCTION
     123KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    124124krb5_string_to_deltat(const char *string, krb5_deltat *deltat)
    125125{
  • trunk/server/source4/heimdal/lib/krb5/transited.c

    r414 r745  
    329329
    330330
    331 krb5_error_code KRB5_LIB_FUNCTION
     331KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    332332krb5_domain_x500_decode(krb5_context context,
    333333                        krb5_data tr, char ***realms, unsigned int *num_realms,
     
    390390}
    391391
    392 krb5_error_code KRB5_LIB_FUNCTION
     392KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    393393krb5_domain_x500_encode(char **realms, unsigned int num_realms,
    394394                        krb5_data *encoding)
     
    422422}
    423423
    424 krb5_error_code KRB5_LIB_FUNCTION
     424KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    425425krb5_check_transited(krb5_context context,
    426426                     krb5_const_realm client_realm,
     
    462462}
    463463
    464 krb5_error_code KRB5_LIB_FUNCTION
     464KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    465465krb5_check_transited_realms(krb5_context context,
    466466                            const char *const *realms,
  • trunk/server/source4/heimdal/lib/krb5/version.c

    r414 r745  
    3636/* this is just to get a version stamp in the library file */
    3737
    38 #define heimdal_version __heimdal_version
    39 #define heimdal_long_version __heimdal_long_version
    4038#include "version.h"
    4139
  • trunk/server/source4/heimdal/lib/krb5/warn.c

    r414 r745  
    4747    char *msg = NULL;
    4848    const char *err_str = NULL;
     49    krb5_error_code ret;
    4950
    5051    args[0] = args[1] = NULL;
     
    5455        if(do_errtext)
    5556            strlcat(xfmt, ": ", sizeof(xfmt));
    56         vasprintf(&msg, fmt, ap);
    57         if(msg == NULL)
     57        ret = vasprintf(&msg, fmt, ap);
     58        if(ret < 0 || msg == NULL)
    5859            return ENOMEM;
    5960        *arg++ = msg;
    6061    }
    6162    if(context && do_errtext){
    62         const char *err_msg;
    63 
    6463        strlcat(xfmt, "%s", sizeof(xfmt));
    6564
     
    6867            *arg = err_str;
    6968        } else {
    70             err_msg = krb5_get_err_text(context, code);
    71             if (err_msg)
    72                 *arg = err_msg;
    73             else
    74                 *arg= "<unknown error>";
     69            *arg= "<unknown error>";
    7570        }
    7671    }
     
    107102 */
    108103
    109 krb5_error_code KRB5_LIB_FUNCTION
     104KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    110105krb5_vwarn(krb5_context context, krb5_error_code code,
    111106           const char *fmt, va_list ap)
     
    126121 */
    127122
    128 krb5_error_code KRB5_LIB_FUNCTION
     123KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    129124krb5_warn(krb5_context context, krb5_error_code code, const char *fmt, ...)
    130125     __attribute__ ((format (printf, 3, 4)))
     
    144139 */
    145140
    146 krb5_error_code KRB5_LIB_FUNCTION
     141KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    147142krb5_vwarnx(krb5_context context, const char *fmt, va_list ap)
    148143     __attribute__ ((format (printf, 2, 0)))
     
    160155 */
    161156
    162 krb5_error_code KRB5_LIB_FUNCTION
     157KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    163158krb5_warnx(krb5_context context, const char *fmt, ...)
    164159     __attribute__ ((format (printf, 2, 3)))
     
    181176 */
    182177
    183 krb5_error_code KRB5_LIB_FUNCTION
     178KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    184179krb5_verr(krb5_context context, int eval, krb5_error_code code,
    185180          const char *fmt, va_list ap)
     
    188183    _warnerr(context, 1, code, 0, fmt, ap);
    189184    exit(eval);
     185    UNREACHABLE(return 0);
    190186}
    191187
     
    202198 */
    203199
    204 krb5_error_code KRB5_LIB_FUNCTION
     200KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    205201krb5_err(krb5_context context, int eval, krb5_error_code code,
    206202         const char *fmt, ...)
     
    209205    FUNC(1, code, 0);
    210206    exit(eval);
     207    UNREACHABLE(return 0);
    211208}
    212209
     
    222219 */
    223220
    224 krb5_error_code KRB5_LIB_FUNCTION
     221KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    225222krb5_verrx(krb5_context context, int eval, const char *fmt, va_list ap)
    226223     __attribute__ ((noreturn, format (printf, 3, 0)))
     
    228225    _warnerr(context, 0, 0, 0, fmt, ap);
    229226    exit(eval);
     227    UNREACHABLE(return 0);
    230228}
    231229
     
    240238 */
    241239
    242 krb5_error_code KRB5_LIB_FUNCTION
     240KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    243241krb5_errx(krb5_context context, int eval, const char *fmt, ...)
    244242     __attribute__ ((noreturn, format (printf, 3, 4)))
     
    246244    FUNC(0, 0, 0);
    247245    exit(eval);
     246    UNREACHABLE(return 0);
    248247}
    249248
     
    260259 */
    261260
    262 krb5_error_code KRB5_LIB_FUNCTION
     261KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    263262krb5_vabort(krb5_context context, krb5_error_code code,
    264263            const char *fmt, va_list ap)
     
    267266    _warnerr(context, 1, code, 0, fmt, ap);
    268267    abort();
    269 }
    270 
    271 /**
    272  * Log a warning to the log, default stderr, include bthe error from
     268    UNREACHABLE(return 0);
     269}
     270
     271/**
     272 * Log a warning to the log, default stderr, include the error from
    273273 * the last failure and then abort.
    274274 *
     
    280280 */
    281281
    282 krb5_error_code KRB5_LIB_FUNCTION
     282KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    283283krb5_abort(krb5_context context, krb5_error_code code, const char *fmt, ...)
    284284     __attribute__ ((noreturn, format (printf, 3, 4)))
     
    286286    FUNC(1, code, 0);
    287287    abort();
    288 }
    289 
    290 krb5_error_code KRB5_LIB_FUNCTION
     288    UNREACHABLE(return 0);
     289}
     290
     291KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    291292krb5_vabortx(krb5_context context, const char *fmt, va_list ap)
    292293     __attribute__ ((noreturn, format (printf, 2, 0)))
     
    294295    _warnerr(context, 0, 0, 0, fmt, ap);
    295296    abort();
     297    UNREACHABLE(return 0);
    296298}
    297299
     
    306308 */
    307309
    308 krb5_error_code KRB5_LIB_FUNCTION
     310KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    309311krb5_abortx(krb5_context context, const char *fmt, ...)
    310312     __attribute__ ((noreturn, format (printf, 2, 3)))
     
    312314    FUNC(0, 0, 0);
    313315    abort();
     316    UNREACHABLE(return 0);
    314317}
    315318
     
    323326 */
    324327
    325 krb5_error_code KRB5_LIB_FUNCTION
     328KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
    326329krb5_set_warn_dest(krb5_context context, krb5_log_facility *fac)
    327330{
     
    338341 */
    339342
    340 krb5_log_facility * KRB5_LIB_FUNCTION
     343KRB5_LIB_FUNCTION krb5_log_facility * KRB5_LIB_CALL
    341344krb5_get_warn_dest(krb5_context context)
    342345{
Note: See TracChangeset for help on using the changeset viewer.