|
|
1.1 root 1: /* cpair.c - CertificatePair attribute syntax */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/cpair.c,v 7.1 90/01/11 18:35:34 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/dsap/common/RCS/cpair.c,v 7.1 90/01/11 18:35:34 mrose Exp $
9: *
10: *
11: * $Log: cpair.c,v $
12: * Revision 7.1 90/01/11 18:35:34 mrose
13: * real-sync
14: *
15: * Revision 7.0 89/11/23 21:41:59 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: #include "quipu/authen.h"
32:
33: /* We import these functions, which ought to be internal to certificate.c */
34: struct certificate *cert_cpy();
35: struct certificate *str2cert();
36:
37: PE cpair_enc(parm)
38: struct certificate_list *parm;
39: {
40: PE pe;
41:
42: encode_AF_CertificatePair(&pe, 0, 0, NULLCP, parm);
43: return (pe);
44: }
45:
46: struct certificate_list *cpair_dec(pe)
47: PE pe;
48: {
49: struct certificate_list *result;
50:
51: if (decode_AF_CertificatePair(pe, 0, NULLIP, NULLVP, &result) == NOTOK)
52: return (struct certificate_list *) 0;
53: return (result);
54: }
55:
56: struct certificate_list *str2cpair(str)
57: char *str;
58: {
59: struct certificate_list *result;
60: char *ptr;
61:
62: result = (struct certificate_list *) calloc(1, sizeof(*result));
63: if (result == (struct certificate_list *) 0)
64: return (result);
65:
66:
67: /* If there isn't a '|', the pair is technically illegal. However,
68: * allow this case to mean : "the string contains a certificate,
69: * which is the forward cross certificate".
70: */
71:
72: ptr = index(str, '|');
73: if (ptr != NULLCP)
74: {
75: *ptr = '\0';
76: ptr++;
77: }
78:
79: /* Need to cook up a quick test for whether a string contains a certificate
80: * or whitespace. A certificate will always contain a '#', so use this.
81: */
82:
83: if (index(str, '#') != NULLCP)
84: {
85: result->cert = str2cert(str);
86: if (result->cert == (struct certificate *) 0)
87: {
88: free((char *) result);
89: return ((struct certificate_list *) 0);
90: }
91: }
92:
93: str = ptr;
94: if ((str != NULLCP) && (index(str, '#') != NULLCP))
95: {
96: result->cert = str2cert(str);
97: if (result->cert == (struct certificate *) 0)
98: {
99: free((char *) result);
100: return ((struct certificate_list *) 0);
101: }
102: }
103:
104: return (result);
105: }
106:
107: int printcpair(ps, parm, format)
108: PS ps;
109: struct certificate_list *parm;
110: int format;
111: {
112: if (parm->cert)
113: printcert(ps, parm->cert, format);
114:
115: ps_printf(ps, "|");
116:
117: if (parm->reverse)
118: printcert(ps, parm->reverse, format);
119: }
120:
121: struct certificate_list *cpair_cpy(parm)
122: struct certificate_list *parm;
123: {
124: struct certificate_list *result;
125:
126: result = (struct certificate_list *) calloc(1, sizeof(*result));
127: if (result == (struct certificate_list *) 0)
128: return (result);
129: if (parm->cert)
130: result->cert = cert_cpy(parm->cert);
131: if (parm->reverse)
132: result->reverse = cert_cpy(parm->reverse);
133:
134: return (result);
135: }
136:
137:
138: int cpair_cmp(a, b)
139: struct certificate_list *a, *b;
140: {
141: int retval;
142:
143: if (a->cert == (struct certificate *) 0)
144: {
145: if (b->cert == (struct certificate *) 0)
146: retval = 0;
147: else
148: retval = 1;
149: }
150: else
151: {
152: if (b->cert == (struct certificate *) 0)
153: retval = -1;
154: else
155: retval = cert_cmp(a->cert, b->cert);
156: }
157:
158: if (retval != 0)
159: return (retval);
160:
161: if (a->reverse == (struct certificate *) 0)
162: {
163: if (b->reverse == (struct certificate *) 0)
164: retval = 0;
165: else
166: retval = 1;
167: }
168: else
169: {
170: if (b->reverse == (struct certificate *) 0)
171: retval = -1;
172: else
173: retval = cert_cmp(a->reverse, b->reverse);
174: }
175:
176: return (retval);
177: }
178:
179: cpair_free(parm)
180: struct certificate_list *parm;
181: {
182: if (parm->cert)
183: cert_free(parm->cert);
184: if (parm->reverse)
185: cert_free(parm->reverse);
186: free((char *) parm);
187: }
188:
189: certificate_pair_syntax()
190: {
191: (void) add_attribute_syntax(
192: "CertificatePair",
193: (IFP) cpair_enc, (IFP) cpair_dec,
194: (IFP) str2cpair, printcpair,
195: (IFP) cpair_cpy, cpair_cmp,
196: cpair_free, NULLCP,
197: NULLIFP, TRUE);
198: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.