Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / lib / krb5 / ccache / t_stdio.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/ccache/t_stdio.c */
3 /*
4  * Copyright 1991 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 "scc.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 int x = 0x12345;
58 krb5_address addr = {
59     ADDRTYPE_INET,
60     4,
61     (krb5_octet *) &x,
62 };
63
64 krb5_address *addrs[] = {
65     &addr,
66     0,
67 };
68
69 krb5_creds test_creds = {
70     NULL,
71     NULL,
72     {
73         1,
74         1,
75         (unsigned char *) "1"
76     },
77     {
78         1111,
79         2222,
80         3333,
81         4444,
82     },
83     1,
84     5555,
85     addrs,
86     {
87 #define TICKET "This is ticket 1"
88         sizeof(TICKET),
89         TICKET,
90 #undef TICKET
91     },
92     {
93 #define TICKET "This is ticket 2"
94         sizeof(TICKET),
95         TICKET,
96 #undef TICKET
97     },
98 };
99
100 void
101 init_test_cred()
102 {
103     test_creds.client = (krb5_principal) malloc(sizeof(krb5_data *)*3);
104     test_creds.client[0] = &client1;
105     test_creds.client[1] = &client2;
106     test_creds.client[2] = NULL;
107
108     test_creds.server = (krb5_principal) malloc(sizeof(krb5_data *)*3);
109     test_creds.server[0] = &server1;
110     test_creds.server[1] = &server2;
111     test_creds.server[2] = NULL;
112 }
113
114 #define CHECK(kret,msg)                         \
115     if (kret != KRB5_OK) {                      \
116         com_err(msg, kret, "");                 \
117     } else printf("%s went ok\n", msg);
118
119 int flags = 0;
120 void
121 scc_test()
122 {
123     krb5_ccache id;
124     krb5_creds creds;
125     krb5_error_code kret;
126     krb5_cc_cursor cursor;
127
128     init_test_cred();
129
130     kret = krb5_scc_resolve(context, &id, "/tmp/tkt_test");
131     CHECK(kret, "resolve");
132     kret = krb5_scc_initialize(context, id, test_creds.client);
133     CHECK(kret, "initialize");
134     kret = krb5_scc_store(id, &test_creds);
135     CHECK(kret, "store");
136
137     kret = krb5_scc_set_flags (id, flags);
138     CHECK(kret, "set_flags");
139     kret = krb5_scc_start_seq_get(id, &cursor);
140     CHECK(kret, "start_seq_get");
141     kret = 0;
142     while (kret != KRB5_CC_END) {
143         printf("Calling next_cred\n");
144         kret = krb5_scc_next_cred(id, &cursor, &creds);
145         CHECK(kret, "next_cred");
146     }
147     kret = krb5_scc_end_seq_get(id, &cursor);
148     CHECK(kret, "end_seq_get");
149
150     kret = krb5_scc_close(id);
151     CHECK(kret, "close");
152
153
154     kret = krb5_scc_resolve(&id, "/tmp/tkt_test");
155     CHECK(kret, "resolve");
156     kret = krb5_scc_destroy(id);
157     CHECK(kret, "destroy");
158 }
159
160 int remove (s) char*s; { return unlink(s); }
161 int main () {
162     initialize_krb5_error_table ();
163     init_test_cred ();
164     scc_test ();
165     flags = !flags;
166     scc_test ();
167     return 0;
168 }