~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/lib/ccapi/unit-test/t_ccache.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman, Russ Allbery, Sam Hartman
  • Date: 2008-08-21 10:41:41 UTC
  • mfrom: (11.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080821104141-a0f9c4o4cpo8xd0o
Tags: 1.6.dfsg.4~beta1-4
[ Russ Allbery ]
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #487669, #491774)
  - Italian, thanks Luca Monducci.  (Closes: #493962)

[ Sam Hartman ]
* Translation Updates:
    - Dutch, Thanks Vincent Zweije, Closes: #495733

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Copyright:
2
 
 *
3
 
 * Copyright 2004 by the Massachusetts Institute of Technology.
4
 
 * 
5
 
 * All rights reserved.
6
 
 * 
7
 
 * Export of this software from the United States of America may require a
8
 
 * specific license from the United States Government.  It is the
9
 
 * responsibility of any person or organization contemplating export to
10
 
 * obtain such a license before exporting.
11
 
 * 
12
 
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
13
 
 * this software and its documentation for any purpose and without fee is
14
 
 * hereby granted, provided that the above copyright notice appear in all
15
 
 * copies and that both that copyright notice and this permission notice
16
 
 * appear in supporting documentation, and that the name of M.I.T. not be
17
 
 * used in advertising or publicity pertaining to distribution of the
18
 
 * software without specific, written prior permission.  Furthermore if you
19
 
 * modify this software you must label your software as modified software
20
 
 * and not distribute it in such a fashion that it might be confused with
21
 
 * the original MIT software. M.I.T. makes no representations about the
22
 
 * suitability of this software for any purpose.  It is provided "as is"
23
 
 * without express or implied warranty.
24
 
 * 
25
 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
26
 
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
27
 
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28
 
 * 
29
 
 * Individual source code files are copyright MIT, Cygnus Support,
30
 
 * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
31
 
 * 
32
 
 * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
33
 
 * and Zephyr are trademarks of the Massachusetts Institute of Technology
34
 
 * (MIT).  No commercial use of these trademarks may be made without prior
35
 
 * written permission of MIT.
36
 
 * 
37
 
 * "Commercial use" means use of a name in a product or other for-profit
38
 
 * manner.  It does NOT prevent a commercial firm from referring to the MIT
39
 
 * trademarks in order to convey information (although in doing so,
40
 
 * recognition of their trademark status should be given).
41
 
 * $
42
 
 */
43
 
 
44
 
#include <stdio.h>
45
 
#include <stdlib.h>
46
 
#include <string.h>
47
 
#include <time.h>
48
 
#include "CredentialsCache.h"
49
 
#include "datastore.h"
50
 
 
51
 
int main() {
52
 
    cc_server_credentials_t *cred1, *cred2, *cred3;
53
 
    cc_credentials_iterate_t* iterator;
54
 
    cc_server_credentials_t* stored_cred;
55
 
    cc_credentials_list_node_t *node;
56
 
    cc_server_ccache_t *c1, *c2;
57
 
    char p1[] = "Spike";
58
 
    char p2[] = "Jeff";
59
 
    int i;
60
 
    cc_int32 code;
61
 
 
62
 
    code = cci_ccache_new("The first", p1, cc_credentials_v4_v5, &c1);
63
 
    code = cci_ccache_new("The 2nd", p2, cc_credentials_v4_v5, &c2);
64
 
 
65
 
    cred1 = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t));
66
 
    memset(cred1,0,sizeof(cc_server_credentials_t));
67
 
    cred2 = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t));
68
 
    memset(cred2,0,sizeof(cc_server_credentials_t));
69
 
    cred3 = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t));
70
 
    memset(cred3,0,sizeof(cc_server_credentials_t));
71
 
 
72
 
    cred1->creds.version = cred2->creds.version = cc_credentials_v4;
73
 
    cred3->creds.version = cc_credentials_v5;
74
 
 
75
 
    cred1->creds.credentials.credentials_v4 = (cc_credentials_v4_t*)malloc(sizeof(cc_credentials_v4_t));
76
 
    memset(cred1->creds.credentials.credentials_v4,0,sizeof(cc_credentials_v4_t));
77
 
    cred2->creds.credentials.credentials_v4 = (cc_credentials_v4_t*)malloc(sizeof(cc_credentials_v4_t));
78
 
    memset(cred2->creds.credentials.credentials_v4,0,sizeof(cc_credentials_v4_t));
79
 
    cred3->creds.credentials.credentials_v5 = (cc_credentials_v5_t*)malloc(sizeof(cc_credentials_v5_t));
80
 
    memset(cred3->creds.credentials.credentials_v5,0,sizeof(cc_credentials_v5_t));
81
 
 
82
 
    strncpy(cred1->creds.credentials.credentials_v4->principal, p1, strlen(p1));
83
 
    strncpy(cred2->creds.credentials.credentials_v4->principal, p1, strlen(p1));
84
 
    cred3->creds.credentials.credentials_v5->client = p1;
85
 
 
86
 
    code = cci_ccache_store_creds(c1, &cred1->creds);
87
 
    printf("(c1, cred1) -> %d\n",code);
88
 
 
89
 
    code = cci_ccache_store_creds(c1, &cred2->creds);
90
 
    printf("(c1, cred2) -> %d\n",code);
91
 
 
92
 
    code = cci_ccache_store_creds(c2, &cred3->creds);
93
 
    printf("(c2, cred3) -> %d\n",code);
94
 
 
95
 
    code = cci_ccache_store_creds(c1, &cred3->creds);
96
 
    printf("(c1, cred3) -> %d\n",code);
97
 
 
98
 
    i = 0;
99
 
    code = cci_ccache_move(c1, c2);
100
 
    code = cci_ccache_destroy(c1);
101
 
    code = cci_ccache_new_iterator(c2, &iterator);
102
 
    while (cci_credentials_iterate_has_next(iterator)) {
103
 
        i++;
104
 
        code = cci_credentials_iterate_next(iterator, &node);
105
 
        stored_cred = (cc_server_credentials_t *)node->data;
106
 
        printf("%d %d %s\n", stored_cred->is_default, stored_cred->creds.version, stored_cred->creds.credentials.credentials_v4->principal);
107
 
 
108
 
        if (i == 1) {
109
 
            code = cci_ccache_rem_creds(c2,&cred2->creds);
110
 
            printf("(c2 rem cred2) -> %d\n",code);
111
 
        }
112
 
    }
113
 
    return 0;
114
 
}
115