Imported Upstream version 1.10.2
[platform/upstream/krb5.git] / src / lib / krb5 / ccache / t_memory.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/ccache/t_memory.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.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27 #include "mcc.h"
28
29 krb5_data client1 = {
30 #define DATA "client1-comp1"
31     sizeof(DATA),
32     DATA,
33 #undef DATA
34 };
35
36 krb5_data client2 = {
37 #define DATA "client1-comp2"
38     sizeof(DATA),
39     DATA,
40 #undef DATA
41 };
42
43 krb5_data server1 = {
44 #define DATA "server1-comp1"
45     sizeof(DATA),
46     DATA,
47 #undef DATA
48 };
49
50 krb5_data server2 = {
51 #define DATA "server1-comp2"
52     sizeof(DATA),
53     DATA,
54 #undef DATA
55 };
56
57 krb5_creds test_creds = {
58     NULL,
59     NULL,
60     {
61         1,
62         1,
63         (unsigned char *) "1"
64     },
65     {
66         1111,
67         2222,
68         3333,
69         4444
70     },
71     1,
72     5555,
73     {
74 #define TICKET "This is ticket 1"
75         sizeof(TICKET),
76         TICKET,
77 #undef TICKET
78     },
79     {
80 #define TICKET "This is ticket 2"
81         sizeof(TICKET),
82         TICKET,
83 #undef TICKET
84     },
85 };
86
87 void
88 init_test_cred()
89 {
90     test_creds.client = (krb5_principal) malloc(sizeof(krb5_data *)*3);
91     test_creds.client[0] = &client1;
92     test_creds.client[1] = &client2;
93     test_creds.client[2] = NULL;
94
95     test_creds.server = (krb5_principal) malloc(sizeof(krb5_data *)*3);
96     test_creds.server[0] = &server1;
97     test_creds.server[1] = &server2;
98     test_creds.server[2] = NULL;
99 }
100
101 #define CHECK(kret,msg)                         \
102     if (kret != KRB5_OK) {                      \
103         printf("%s returned %d\n", msg, kret);  \
104     };
105
106 void
107 mcc_test()
108 {
109     krb5_ccache id;
110     krb5_creds creds;
111     krb5_error_code kret;
112     krb5_cc_cursor cursor;
113
114     init_test_cred();
115
116     kret = krb5_mcc_resolve(context, &id, "/tmp/tkt_test");
117     CHECK(kret, "resolve");
118     kret = krb5_mcc_initialize(context, id, test_creds.client);
119     CHECK(kret, "initialize");
120     kret = krb5_mcc_store(context, id, &test_creds);
121     CHECK(kret, "store");
122
123     kret = krb5_mcc_start_seq_get(context, id, &cursor);
124     CHECK(kret, "start_seq_get");
125     kret = 0;
126     while (kret != KRB5_CC_END) {
127         printf("Calling next_cred\n");
128         kret = krb5_mcc_next_cred(context, id, &cursor, &creds);
129         CHECK(kret, "next_cred");
130     }
131     kret = krb5_mcc_end_seq_get(context, id, &cursor);
132     CHECK(kret, "end_seq_get");
133
134     kret = krb5_mcc_destroy(context, id);
135     CHECK(kret, "destroy");
136     kret = krb5_mcc_close(context, id);
137     CHECK(kret, "close");
138 }