9285198a1e3c1453d396a39fd88308cc928c20f0
[krb5.git] / src / lib / krb5 / ccache / memory / mcc_reslv.c
1 /*
2  * lib/krb5/ccache/file/mcc_reslv.c
3  *
4  * Copyright 1990 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  * 
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  M.I.T. makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  * 
23  *
24  * This file contains the source code for krb5_mcc_resolve.
25  */
26
27
28
29 #include "mcc.h"
30
31 extern krb5_cc_ops krb5_mcc_ops;
32
33 /*
34  * Requires:
35  * residual is a legal path name, and a null-terminated string
36  *
37  * Modifies:
38  * id
39  * 
40  * Effects:
41  * creates a file-based cred cache that will reside in the file
42  * residual.  The cache is not opened, but the filename is reserved.
43  * 
44  * Returns:
45  * A filled in krb5_ccache structure "id".
46  *
47  * Errors:
48  * KRB5_CC_NOMEM - there was insufficient memory to allocate the
49  *              krb5_ccache.  id is undefined.
50  * permission errors
51  */
52 krb5_error_code KRB5_CALLCONV
53 krb5_mcc_resolve (context, id, residual)
54    krb5_context context;
55    krb5_ccache *id;
56    const char *residual;
57 {
58      krb5_ccache lid;
59      krb5_mcc_data *ptr;
60
61      
62      lid = (krb5_ccache) malloc(sizeof(struct _krb5_ccache));
63      if (lid == NULL)
64           return KRB5_CC_NOMEM;
65
66      lid->ops = &krb5_mcc_ops;
67      
68      for (ptr = mcc_head; ptr; ptr=ptr->next)
69         if (!strcmp(ptr->name, residual))
70             break;
71      if (ptr) {
72      lid->data = ptr;
73      } else {
74      lid->data = (krb5_pointer) malloc(sizeof(krb5_mcc_data));
75      if (lid->data == NULL) {
76           krb5_xfree(lid);
77           return KRB5_CC_NOMEM;
78      }
79
80      ((krb5_mcc_data *) lid->data)->name = (char *)
81         malloc(strlen(residual) + 1);
82      if (((krb5_mcc_data *)lid->data)->name == NULL) {
83         krb5_xfree(((krb5_mcc_data *)lid->data));
84         krb5_xfree(lid);
85         return KRB5_CC_NOMEM;
86      }
87      strcpy(((krb5_mcc_data *)lid->data)->name, residual);
88      ((krb5_mcc_data *)lid->data)->link = 0L;
89      ((krb5_mcc_data *)lid->data)->prin = 0L;
90
91
92      ((krb5_mcc_data *)lid->data)->next = mcc_head;
93      mcc_head = (krb5_mcc_data *)lid->data;
94 #if 0
95      ++krb5_cache_sessions;
96 #endif
97      }
98      *id = lid; 
99      return KRB5_OK;
100 }