LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/krb5 - mcache.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 202 297 68.0 %
Date: 2024-04-13 12:30:31 Functions: 20 25 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 1997-2004 Kungliga Tekniska Högskolan
       3             :  * (Royal Institute of Technology, Stockholm, Sweden).
       4             :  * All rights reserved.
       5             :  *
       6             :  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
       7             :  *
       8             :  * Redistribution and use in source and binary forms, with or without
       9             :  * modification, are permitted provided that the following conditions
      10             :  * are met:
      11             :  *
      12             :  * 1. Redistributions of source code must retain the above copyright
      13             :  *    notice, this list of conditions and the following disclaimer.
      14             :  *
      15             :  * 2. Redistributions in binary form must reproduce the above copyright
      16             :  *    notice, this list of conditions and the following disclaimer in the
      17             :  *    documentation and/or other materials provided with the distribution.
      18             :  *
      19             :  * 3. Neither the name of the Institute nor the names of its contributors
      20             :  *    may be used to endorse or promote products derived from this software
      21             :  *    without specific prior written permission.
      22             :  *
      23             :  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
      24             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      25             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      26             :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
      27             :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      28             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      29             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      30             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      31             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      32             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      33             :  * SUCH DAMAGE.
      34             :  */
      35             : 
      36             : #include "krb5_locl.h"
      37             : 
      38             : typedef struct krb5_mcache {
      39             :     char *name;
      40             :     unsigned int refcnt;
      41             :     unsigned int anonymous:1;
      42             :     unsigned int dead:1;
      43             :     krb5_principal primary_principal;
      44             :     struct link {
      45             :         krb5_creds cred;
      46             :         struct link *next;
      47             :     } *creds;
      48             :     struct krb5_mcache *next;
      49             :     time_t mtime;
      50             :     krb5_deltat kdc_offset;
      51             :     HEIMDAL_MUTEX mutex;
      52             : } krb5_mcache;
      53             : 
      54             : static HEIMDAL_MUTEX mcc_mutex = HEIMDAL_MUTEX_INITIALIZER;
      55             : static struct krb5_mcache *mcc_head;
      56             : 
      57             : #define MCACHE(X)       ((krb5_mcache *)(X)->data.data)
      58             : 
      59             : #define MISDEAD(X)      ((X)->dead)
      60             : 
      61             : static krb5_error_code KRB5_CALLCONV
      62      101435 : mcc_get_name_2(krb5_context context,
      63             :                krb5_ccache id,
      64             :                const char **name,
      65             :                const char **col,
      66             :                const char **sub)
      67             : {
      68      101435 :     if (name)
      69      101435 :         *name = MCACHE(id)->name;
      70      101435 :     if (col)
      71           0 :         *col = NULL;
      72      101435 :     if (sub)
      73           0 :         *sub = MCACHE(id)->name;
      74      101435 :     return 0;
      75             : }
      76             : 
      77             : static krb5_error_code
      78      282279 : mcc_alloc(krb5_context context, const char *name, krb5_mcache **out)
      79             : {
      80        3849 :     krb5_mcache *m, *m_c;
      81      282279 :     size_t counter = 0;
      82      282279 :     int ret = 0;
      83      282279 :     unsigned create_anonymous = 0;
      84             : 
      85      282279 :     *out = NULL;
      86      282279 :     ALLOC(m, 1);
      87      282279 :     if(m == NULL)
      88           0 :         return krb5_enomem(context);
      89             : 
      90      282279 : again:
      91      282279 :     if (counter > 3) {
      92           0 :         free(m->name);
      93           0 :         free(m);
      94           0 :         return EAGAIN; /* XXX */
      95             :     }
      96      282279 :     if(name == NULL) {
      97       23113 :         ret = asprintf(&m->name, "u%p-%llu", m, (unsigned long long)counter);
      98      259166 :     } else if (strcmp(name, "anonymous") == 0) {
      99       48730 :         ret = asprintf(&m->name, "anonymous-%p-%llu", m, (unsigned long long)counter);
     100       48730 :         create_anonymous = 1;
     101             :     } else {
     102      210436 :         m->name = strdup(name);
     103             :     }
     104      282279 :     if(ret < 0 || m->name == NULL) {
     105           0 :         free(m);
     106           0 :         return krb5_enomem(context);
     107             :     }
     108             : 
     109             :     /* check for dups first */
     110        3849 :     HEIMDAL_MUTEX_lock(&mcc_mutex);
     111     1220825 :     for (m_c = mcc_head; m_c != NULL; m_c = m_c->next)
     112     1058367 :         if (strcmp(m->name, m_c->name) == 0)
     113      118355 :             break;
     114      282279 :     if (m_c) {
     115      119821 :         if (name && !create_anonymous) {
     116             :             /* We raced with another thread to create this cache */
     117      119821 :             free(m->name);
     118      119821 :             free(m);
     119      119821 :             m = m_c;
     120        1466 :             HEIMDAL_MUTEX_lock(&(m->mutex));
     121      119821 :             m->refcnt++;
     122      119821 :             HEIMDAL_MUTEX_unlock(&(m->mutex));
     123             :         } else {
     124             :             /* How likely are we to conflict on new_unique anyways?? */
     125           0 :             counter++;
     126           0 :             free(m->name);
     127           0 :             m->name = NULL;
     128           0 :             HEIMDAL_MUTEX_unlock(&mcc_mutex);
     129           0 :             goto again;
     130             :         }
     131        1466 :         HEIMDAL_MUTEX_unlock(&mcc_mutex);
     132      119821 :         *out = m;
     133      119821 :         return 0;
     134             :     }
     135             : 
     136      162458 :     m->anonymous = create_anonymous;
     137      162458 :     m->dead = 0;
     138      162458 :     m->refcnt = 1;
     139      162458 :     m->primary_principal = NULL;
     140      162458 :     m->creds = NULL;
     141      162458 :     m->mtime = time(NULL);
     142      162458 :     m->kdc_offset = 0;
     143      162458 :     m->next = mcc_head;
     144        2383 :     HEIMDAL_MUTEX_init(&(m->mutex));
     145      162458 :     mcc_head = m;
     146        2383 :     HEIMDAL_MUTEX_unlock(&mcc_mutex);
     147      162458 :     *out = m;
     148      162458 :     return 0;
     149             : }
     150             : 
     151             : static krb5_error_code KRB5_CALLCONV
     152      259166 : mcc_resolve_2(krb5_context context,
     153             :               krb5_ccache *id,
     154             :               const char *res,
     155             :               const char *sub)
     156             : {
     157        3849 :     krb5_error_code ret;
     158        3849 :     krb5_mcache *m;
     159             : 
     160      263015 :     if ((ret = mcc_alloc(context, sub && *sub ? sub : res, &m)))
     161           0 :         return ret;
     162             : 
     163      259166 :     (*id)->data.data = m;
     164      259166 :     (*id)->data.length = sizeof(*m);
     165             : 
     166      259166 :     return 0;
     167             : }
     168             : 
     169             : 
     170             : static krb5_error_code KRB5_CALLCONV
     171       23113 : mcc_gen_new(krb5_context context, krb5_ccache *id)
     172             : {
     173           0 :     krb5_error_code ret;
     174           0 :     krb5_mcache *m;
     175             : 
     176       23113 :     if ((ret = mcc_alloc(context, NULL, &m)))
     177           0 :         return ret;
     178             : 
     179       23113 :     (*id)->data.data = m;
     180       23113 :     (*id)->data.length = sizeof(*m);
     181             : 
     182       23113 :     return 0;
     183             : }
     184             : 
     185             : static void KRB5_CALLCONV
     186      384232 : mcc_destroy_internal(krb5_context context,
     187             :                      krb5_mcache *m)
     188             : {
     189        5646 :     struct link *l;
     190             : 
     191      384232 :     if (m->primary_principal != NULL) {
     192      228038 :         krb5_free_principal (context, m->primary_principal);
     193      228038 :         m->primary_principal = NULL;
     194             :     }
     195      384232 :     m->dead = 1;
     196             : 
     197      384232 :     l = m->creds;
     198      713283 :     while (l != NULL) {
     199        5422 :         struct link *old;
     200             : 
     201      329051 :         krb5_free_cred_contents (context, &l->cred);
     202      329051 :         old = l;
     203      329051 :         l = l->next;
     204      329051 :         free (old);
     205             :     }
     206             : 
     207      384232 :     m->creds = NULL;
     208      384232 :     return;
     209             : }
     210             : 
     211             : static krb5_error_code KRB5_CALLCONV
     212      229123 : mcc_initialize(krb5_context context,
     213             :                krb5_ccache id,
     214             :                krb5_principal primary_principal)
     215             : {
     216      229123 :     krb5_mcache *m = MCACHE(id);
     217      229123 :     krb5_error_code ret = 0;
     218        3264 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     219      229123 :     heim_assert(m->refcnt != 0, "resurection released mcache");
     220             :     /*
     221             :      * It's important to destroy any existing
     222             :      * creds here, that matches the baheviour
     223             :      * of all other backends and also the
     224             :      * MEMORY: backend in MIT.
     225             :      */
     226      229123 :     mcc_destroy_internal(context, m);
     227      229123 :     m->dead = 0;
     228      229123 :     m->kdc_offset = 0;
     229      229123 :     m->mtime = time(NULL);
     230      229123 :     ret = krb5_copy_principal (context,
     231             :                                primary_principal,
     232             :                                &m->primary_principal);
     233        3264 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     234      229123 :     return ret;
     235             : }
     236             : 
     237             : static int
     238      280741 : mcc_close_internal(krb5_mcache *m)
     239             : {
     240        3842 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     241      280741 :     heim_assert(m->refcnt != 0, "closed dead cache mcache");
     242      280741 :     if (--m->refcnt != 0) {
     243             :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     244      101492 :         return 0;
     245             :     }
     246      177784 :     if (MISDEAD(m)) {
     247      155089 :         free(m->name);
     248        2377 :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     249      155089 :         return 1;
     250             :     }
     251             :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     252       22695 :     return 0;
     253             : }
     254             : 
     255             : static krb5_error_code KRB5_CALLCONV
     256      280741 : mcc_close(krb5_context context,
     257             :           krb5_ccache id)
     258             : {
     259      280741 :     krb5_mcache *m = MCACHE(id);
     260             : 
     261      280741 :     if (mcc_close_internal(MCACHE(id))) {
     262        2377 :         HEIMDAL_MUTEX_destroy(&(m->mutex));
     263      155089 :         krb5_data_free(&id->data);
     264             :     }
     265      280741 :     return 0;
     266             : }
     267             : 
     268             : static krb5_error_code KRB5_CALLCONV
     269      155109 : mcc_destroy(krb5_context context,
     270             :             krb5_ccache id)
     271             : {
     272      155109 :     krb5_mcache **n, *m = MCACHE(id);
     273             : 
     274        2382 :     HEIMDAL_MUTEX_lock(&mcc_mutex);
     275        2382 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     276      155109 :     if (m->refcnt == 0)
     277             :     {
     278           0 :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     279           0 :         HEIMDAL_MUTEX_unlock(&mcc_mutex);
     280           0 :         krb5_abortx(context, "mcc_destroy: refcnt already 0");
     281             :     }
     282             : 
     283      155109 :     if (!MISDEAD(m)) {
     284             :         /* if this is an active mcache, remove it from the linked
     285             :            list, and free all data */
     286      277937 :         for(n = &mcc_head; n && *n; n = &(*n)->next) {
     287      277937 :             if(m == *n) {
     288      155109 :                 *n = m->next;
     289      155109 :                 break;
     290             :             }
     291             :         }
     292      155109 :         mcc_destroy_internal(context, m);
     293             :     }
     294        2382 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     295        2382 :     HEIMDAL_MUTEX_unlock(&mcc_mutex);
     296      155109 :     return 0;
     297             : }
     298             : 
     299             : static krb5_error_code KRB5_CALLCONV
     300      333142 : mcc_store_cred(krb5_context context,
     301             :                krb5_ccache id,
     302             :                krb5_creds *creds)
     303             : {
     304      333142 :     krb5_mcache *m = MCACHE(id);
     305        5425 :     krb5_error_code ret;
     306        5425 :     struct link *l;
     307             : 
     308        5425 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     309      333142 :     if (MISDEAD(m))
     310             :     {
     311             :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     312           0 :         return ENOENT;
     313             :     }
     314             : 
     315      333142 :     l = malloc (sizeof(*l));
     316      333142 :     if (l == NULL)
     317           0 :         return krb5_enomem(context);
     318      333142 :     l->next = m->creds;
     319      333142 :     m->creds = l;
     320      333142 :     memset (&l->cred, 0, sizeof(l->cred));
     321      333142 :     ret = krb5_copy_creds_contents (context, creds, &l->cred);
     322      333142 :     if (ret) {
     323           0 :         m->creds = l->next;
     324           0 :         free (l);
     325           0 :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     326           0 :         return ret;
     327             :     }
     328      333142 :     m->mtime = time(NULL);
     329        5425 :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     330      333142 :     return 0;
     331             : }
     332             : 
     333             : static krb5_error_code KRB5_CALLCONV
     334      792789 : mcc_get_principal(krb5_context context,
     335             :                   krb5_ccache id,
     336             :                   krb5_principal *principal)
     337             : {
     338      792789 :     krb5_mcache *m = MCACHE(id);
     339      792789 :     krb5_error_code ret = 0;
     340             : 
     341       15472 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     342      792789 :     if (MISDEAD(m) || m->primary_principal == NULL) {
     343             :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     344       18930 :         return ENOENT;
     345             :     }
     346      773859 :     ret = krb5_copy_principal (context,
     347      758387 :                                m->primary_principal,
     348             :                                principal);
     349       15472 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     350      773859 :     return ret;
     351             : }
     352             : 
     353             : static krb5_error_code KRB5_CALLCONV
     354      703148 : mcc_get_first (krb5_context context,
     355             :                 krb5_ccache id,
     356             :                 krb5_cc_cursor *cursor)
     357             : {
     358      703148 :     krb5_mcache *m = MCACHE(id);
     359             : 
     360       15043 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     361      703148 :     if (MISDEAD(m)) {
     362             :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     363           0 :         return ENOENT;
     364             :     }
     365      703148 :     *cursor = m->creds;
     366             : 
     367       15043 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     368      703148 :     return 0;
     369             : }
     370             : 
     371             : static krb5_error_code KRB5_CALLCONV
     372     1883688 : mcc_get_next (krb5_context context,
     373             :               krb5_ccache id,
     374             :               krb5_cc_cursor *cursor,
     375             :               krb5_creds *creds)
     376             : {
     377     1883688 :     krb5_mcache *m = MCACHE(id);
     378       40465 :     struct link *l;
     379             : 
     380       40465 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     381     1883688 :     if (MISDEAD(m)) {
     382             :         HEIMDAL_MUTEX_unlock(&(m->mutex));
     383           0 :         return ENOENT;
     384             :     }
     385       40465 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     386             : 
     387     1883688 :     l = *cursor;
     388     1883688 :     if (l != NULL) {
     389     1567088 :         *cursor = l->next;
     390     1567088 :         return krb5_copy_creds_contents (context,
     391     1567088 :                                          &l->cred,
     392             :                                          creds);
     393             :     } else
     394      310391 :         return KRB5_CC_END;
     395             : }
     396             : 
     397             : static krb5_error_code KRB5_CALLCONV
     398      703148 : mcc_end_get (krb5_context context,
     399             :              krb5_ccache id,
     400             :              krb5_cc_cursor *cursor)
     401             : {
     402      703148 :     return 0;
     403             : }
     404             : 
     405             : static krb5_error_code KRB5_CALLCONV
     406       85382 : mcc_remove_cred(krb5_context context,
     407             :                  krb5_ccache id,
     408             :                  krb5_flags which,
     409             :                  krb5_creds *mcreds)
     410             : {
     411       85382 :     krb5_mcache *m = MCACHE(id);
     412        1466 :     struct link **q, *p;
     413             : 
     414        1466 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     415             : 
     416      170764 :     for(q = &m->creds, p = *q; p; p = *q) {
     417       85382 :         if(krb5_compare_creds(context, which, mcreds, &p->cred)) {
     418           0 :             *q = p->next;
     419           0 :             krb5_free_cred_contents(context, &p->cred);
     420           0 :             free(p);
     421           0 :             m->mtime = time(NULL);
     422             :         } else
     423       85382 :             q = &p->next;
     424             :     }
     425        1466 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     426       85382 :     return 0;
     427             : }
     428             : 
     429             : static krb5_error_code KRB5_CALLCONV
     430           0 : mcc_set_flags(krb5_context context,
     431             :               krb5_ccache id,
     432             :               krb5_flags flags)
     433             : {
     434           0 :     return 0; /* XXX */
     435             : }
     436             : 
     437             : struct mcache_iter {
     438             :     krb5_mcache *cache;
     439             : };
     440             : 
     441             : static krb5_mcache *
     442          52 : mcc_get_cache_find_next_internal(krb5_mcache *next)
     443             : {
     444           0 :     HEIMDAL_MUTEX_lock(&mcc_mutex);
     445          52 :     for (; next != NULL && next->anonymous; next = next->next) {
     446             :         /* noop: iterate over all anonymous entries */
     447           0 :     }
     448          52 :     if (next != NULL) {
     449           0 :         HEIMDAL_MUTEX_lock(&(next->mutex));
     450           0 :         next->refcnt++;
     451           0 :         HEIMDAL_MUTEX_unlock(&(next->mutex));
     452           0 :         next = next->next;
     453             :     }
     454           0 :     HEIMDAL_MUTEX_unlock(&mcc_mutex);
     455             : 
     456          52 :     return next;
     457             : }
     458             : 
     459             : static krb5_error_code KRB5_CALLCONV
     460          52 : mcc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
     461             : {
     462           0 :     struct mcache_iter *iter;
     463             : 
     464          52 :     iter = calloc(1, sizeof(*iter));
     465          52 :     if (iter == NULL)
     466           0 :         return krb5_enomem(context);
     467             : 
     468          52 :     iter->cache = mcc_get_cache_find_next_internal(mcc_head);
     469             : 
     470          52 :     *cursor = iter;
     471          52 :     return 0;
     472             : }
     473             : 
     474             : static krb5_error_code KRB5_CALLCONV
     475          52 : mcc_get_cache_next(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id)
     476             : {
     477          52 :     struct mcache_iter *iter = cursor;
     478           0 :     krb5_error_code ret;
     479           0 :     krb5_mcache *m;
     480             : 
     481          52 :     if (iter->cache == NULL)
     482          52 :         return KRB5_CC_END;
     483             : 
     484           0 :     m = iter->cache;
     485           0 :     iter->cache = mcc_get_cache_find_next_internal(m);
     486             : 
     487           0 :     ret = _krb5_cc_allocate(context, &krb5_mcc_ops, id);
     488           0 :     if (ret)
     489           0 :         return ret;
     490             : 
     491           0 :     (*id)->data.data = m;
     492           0 :     (*id)->data.length = sizeof(*m);
     493             : 
     494           0 :     return 0;
     495             : }
     496             : 
     497             : static krb5_error_code KRB5_CALLCONV
     498          52 : mcc_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
     499             : {
     500          52 :     struct mcache_iter *iter = cursor;
     501             : 
     502          52 :     if (iter->cache)
     503           0 :         mcc_close_internal(iter->cache);
     504          52 :     iter->cache = NULL;
     505          52 :     free(iter);
     506          52 :     return 0;
     507             : }
     508             : 
     509             : static krb5_error_code KRB5_CALLCONV
     510           0 : mcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
     511             : {
     512           0 :     krb5_mcache *mfrom = MCACHE(from), *mto = MCACHE(to);
     513           0 :     struct link *creds;
     514           0 :     krb5_principal principal;
     515           0 :     krb5_mcache **n;
     516             : 
     517           0 :     HEIMDAL_MUTEX_lock(&mcc_mutex);
     518             : 
     519             :     /* drop the from cache from the linked list to avoid lookups */
     520           0 :     for(n = &mcc_head; n && *n; n = &(*n)->next) {
     521           0 :         if(mfrom == *n) {
     522           0 :             *n = mfrom->next;
     523           0 :             break;
     524             :         }
     525             :     }
     526             : 
     527           0 :     HEIMDAL_MUTEX_lock(&(mfrom->mutex));
     528           0 :     HEIMDAL_MUTEX_lock(&(mto->mutex));
     529             :     /* swap creds */
     530           0 :     creds = mto->creds;
     531           0 :     mto->creds = mfrom->creds;
     532           0 :     mfrom->creds = creds;
     533             :     /* swap principal */
     534           0 :     principal = mto->primary_principal;
     535           0 :     mto->primary_principal = mfrom->primary_principal;
     536           0 :     mfrom->primary_principal = principal;
     537             : 
     538           0 :     mto->mtime = mfrom->mtime = time(NULL);
     539             : 
     540           0 :     HEIMDAL_MUTEX_unlock(&(mfrom->mutex));
     541           0 :     HEIMDAL_MUTEX_unlock(&(mto->mutex));
     542           0 :     HEIMDAL_MUTEX_unlock(&mcc_mutex);
     543             : 
     544           0 :     krb5_cc_destroy(context, from);
     545           0 :     return 0;
     546             : }
     547             : 
     548             : static krb5_error_code KRB5_CALLCONV
     549           0 : mcc_default_name(krb5_context context, char **str)
     550             : {
     551           0 :     *str = strdup("MEMORY:");
     552           0 :     if (*str == NULL)
     553           0 :         return krb5_enomem(context);
     554           0 :     return 0;
     555             : }
     556             : 
     557             : static krb5_error_code KRB5_CALLCONV
     558           0 : mcc_lastchange(krb5_context context, krb5_ccache id, krb5_timestamp *mtime)
     559             : {
     560           0 :     krb5_mcache *m = MCACHE(id);
     561           0 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     562           0 :     *mtime = m->mtime;
     563           0 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     564           0 :     return 0;
     565             : }
     566             : 
     567             : static krb5_error_code KRB5_CALLCONV
     568           0 : mcc_set_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat kdc_offset)
     569             : {
     570           0 :     krb5_mcache *m = MCACHE(id);
     571           0 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     572           0 :     m->kdc_offset = kdc_offset;
     573           0 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     574           0 :     return 0;
     575             : }
     576             : 
     577             : static krb5_error_code KRB5_CALLCONV
     578       20766 : mcc_get_kdc_offset(krb5_context context, krb5_ccache id, krb5_deltat *kdc_offset)
     579             : {
     580       20766 :     krb5_mcache *m = MCACHE(id);
     581         623 :     HEIMDAL_MUTEX_lock(&(m->mutex));
     582       20766 :     *kdc_offset = m->kdc_offset;
     583         623 :     HEIMDAL_MUTEX_unlock(&(m->mutex));
     584       20766 :     return 0;
     585             : }
     586             : 
     587             : 
     588             : /**
     589             :  * Variable containing the MEMORY based credential cache implemention.
     590             :  *
     591             :  * @ingroup krb5_ccache
     592             :  */
     593             : 
     594             : KRB5_LIB_VARIABLE const krb5_cc_ops krb5_mcc_ops = {
     595             :     KRB5_CC_OPS_VERSION_5,
     596             :     "MEMORY",
     597             :     NULL,
     598             :     NULL,
     599             :     mcc_gen_new,
     600             :     mcc_initialize,
     601             :     mcc_destroy,
     602             :     mcc_close,
     603             :     mcc_store_cred,
     604             :     NULL, /* mcc_retrieve */
     605             :     mcc_get_principal,
     606             :     mcc_get_first,
     607             :     mcc_get_next,
     608             :     mcc_end_get,
     609             :     mcc_remove_cred,
     610             :     mcc_set_flags,
     611             :     NULL,
     612             :     mcc_get_cache_first,
     613             :     mcc_get_cache_next,
     614             :     mcc_end_cache_get,
     615             :     mcc_move,
     616             :     mcc_default_name,
     617             :     NULL,
     618             :     mcc_lastchange,
     619             :     mcc_set_kdc_offset,
     620             :     mcc_get_kdc_offset,
     621             :     mcc_get_name_2,
     622             :     mcc_resolve_2
     623             : };

Generated by: LCOV version 1.14