/* attrv.c - Attribute Value routines */
static char *rcsid
= "$Header: /f/osi/dsap/common/RCS/attrv.c,v 7.6 91/02/22 09:18:31 mrose Interim $";
* $Header: /f/osi/dsap/common/RCS/attrv.c,v 7.6 91/02/22 09:18:31 mrose Interim $
* Revision 7.6 91/02/22 09:18:31 mrose
* Revision 7.5 90/10/17 11:41:12 mrose
* Revision 7.4 90/07/09 14:34:00 mrose
* Revision 7.3 90/04/18 08:50:00 mrose
* Revision 7.2 90/03/15 11:17:26 mrose
* Revision 7.1 90/01/11 18:35:30 mrose
* Revision 7.0 89/11/23 21:41:44 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
#include "quipu/ds_error.h"
#include "quipu/malloc.h"
extern struct PSAPaddr
* psap_cpy ();
extern str2asn (), pe_print() ;
AttributeValue
str2file ();
static short num_syntax
= 1;
static sntx_table syntax_table
[MAX_AV_SYNTAX
] = { {
"ASN", /* ASN - default type */
(IFP
)pe_cpy
, /* default encode */
NULLIFP
, /* no decoding needed */
NULLIFP
, /* default parse */
NULLIFP
, /* default print */
(IFP
)pe_cpy
, /* default copy */
quipu_pe_cmp
, /* default compare */
pe_free
, /* default free */
NULLCP
, /* no pe_printer */
NULLIFP
, /* NO approx matching */
short add_attribute_syntax (sntx
,enc
,dec
,parse
,print
,cpy
,cmp
,sfree
,print_pe
,approx
,multiline
)
IFP enc
,dec
,parse
,print
,cpy
,cmp
,sfree
,approx
;
if (num_syntax
>= MAX_AV_SYNTAX
)
syntax_table
[num_syntax
].s_sntx
= sntx
;
set_attribute_syntax (num_syntax
,enc
,dec
,parse
,print
,cpy
,cmp
,sfree
,print_pe
,approx
,multiline
);
set_attribute_syntax (sntx
,enc
,dec
,parse
,print
,cpy
,cmp
,sfree
,print_pe
,approx
,multiline
)
IFP enc
,dec
,parse
,print
,cpy
,cmp
,sfree
,approx
;
syntax_table
[sntx
].s_encode
= enc
;
syntax_table
[sntx
].s_decode
= dec
;
syntax_table
[sntx
].s_parse
= parse
;
syntax_table
[sntx
].s_print
= print
;
syntax_table
[sntx
].s_copy
= cpy
;
syntax_table
[sntx
].s_compare
= cmp
;
syntax_table
[sntx
].s_free
= sfree
;
syntax_table
[sntx
].s_pe_print
= print_pe
;
syntax_table
[sntx
].s_approx
= approx
;
syntax_table
[sntx
].s_multiline
= multiline
;
set_av_pe_print (sntx
,print_pe
)
syntax_table
[sntx
].s_pe_print
= print_pe
;
if (as
->attr_type
== NULLTABLE_ATTR
)
return (syntax_table
[as
->attr_type
->oa_syntax
].s_multiline
);
return (syntax_table
[x
].s_approx
);
return (syntax_table
[sntx
].s_sntx
);
register sntx_table
* ptr
;
for (i
=0, ptr
= &syntax_table
[0] ; i
<num_syntax
; i
++,ptr
++)
if ( lexequ (ptr
->s_sntx
,str
) == 0)
sntx_table
* get_syntax_table (x
)
return ( &syntax_table
[x
]);
register AttributeValue x
;
if (x
->av_syntax
== AV_FILE
) {
file_free ((struct file_syntax
*)x
->av_struct
);
if (( x
->av_syntax
< AV_WRITE_FILE
)
&& (syntax_table
[x
->av_syntax
].s_free
!= NULLIFP
)
&& (x
->av_struct
!= NULL
))
(*syntax_table
[x
->av_syntax
].s_free
) (x
->av_struct
);
if (av
->av_syntax
== AV_FILE
)
ret_pe
= grab_filepe (av
);
else if (syntax_table
[av
->av_syntax
].s_encode
!= NULLIFP
)
ret_pe
= (PE
)((*syntax_table
[av
->av_syntax
].s_encode
) (av
->av_struct
));
register AttributeType x
;
register AttributeValue y
;
if ((y
== NULLAttrV
) || (y
->av_syntax
!= 0))
if (y
->av_struct
== NULL
)
y
->av_syntax
= x
->oa_syntax
;
if ( (y_syntax
= y
->av_syntax
) >= AV_WRITE_FILE
)
y_syntax
= y
->av_syntax
- AV_WRITE_FILE
;
if (syntax_table
[y_syntax
].s_decode
!= NULLIFP
) {
PE oldpe
= (PE
)y
->av_struct
;
if ((y
->av_struct
= (caddr_t
)((*syntax_table
[y_syntax
].s_decode
) (oldpe
))) == NULL
) {
y
->av_struct
= (caddr_t
)oldpe
;
if (((y
->av_syntax
== 0) && (((PE
)y
->av_struct
)->pe_len
> LINESIZE
))
/* The PE is too long for EDB file */
||( y
->av_syntax
>= AV_WRITE_FILE
))
/* Told to write it to a file */
register char * ptr
, *save
, val
;
static CMD_TABLE cmd_syntax
[] = {
if (( *str
= index (ptr
,'}')) == 0) {
parse_error ("syntax close bracket missing '%s'",--ptr
);
if ((syntax
= cmd_srch (ptr
,cmd_syntax
)) == 0) {
parse_error ("unknown syntax '%s'",ptr
);
if ((syntax
== 4) && ! dsa_mode
) {
parse_error ("{CRYPT} not allowed",ptr
);
str_at2AttrV_aux (str
,at
,rav
)
switch (strip_header (&str
)) {
return (str2file_aux (str
,at
,rav
));
(void) str2AttrV_aux (str
,0,rav
);
if (AttrV_decode (at
,rav
) == NOTOK
) {
parse_error ("ASN attribute decode failed",NULLCP
);
return (str2AttrV_aux (SkipSpace(str
),at
->oa_syntax
,rav
));
return (str2AttrV_aux (str
,at
->oa_syntax
,rav
));
AttributeValue
str_at2AttrV (str
,at
)
switch (strip_header(&str
)) {
return (str2file (str
,at
));
if (AttrV_decode (at
,av
) == NOTOK
) {
parse_error ("ASN attribute decode failed (2)",NULLCP
);
return (str2AttrV (str
,at
->oa_syntax
));
return (str2AttrV (str
,at
->oa_syntax
));
AttributeValue
str2AttrV (str
,syntax
)
if (str2AttrV_aux (str
,syntax
,x
) == OK
)
str2AttrV_aux (str
,syntax
,x
)
if ((x
->av_syntax
= syntax
) > AV_WRITE_FILE
)
x
->av_syntax
= syntax
- AV_WRITE_FILE
;
if (syntax_table
[syntax
].s_parse
!= NULLIFP
) {
if ((x
->av_struct
= (caddr_t
)(*syntax_table
[syntax
].s_parse
) (str
)) == NULL
)
parse_error ("invalid use of {T.61}",NULLCP
);
parse_error ("invalid use of {CRYPT}",NULLCP
);
} else if ((x
->av_struct
= (caddr_t
) asn2pe (str
)) == NULL
) {
parse_error ("invalid ASN attribute",NULLCP
);
AttributeValue
AttrV_cpy (x
)
register AttributeValue x
;
register AttributeValue y
= NULLAttrV
;
register AttributeValue x
;
register AttributeValue y
;
struct file_syntax
* fileattr_cpy();
y
->av_syntax
= x
->av_syntax
;
if (x
->av_struct
== NULL
) {
if (x
->av_syntax
== AV_FILE
)
y
->av_struct
= (caddr_t
) fileattr_cpy ((struct file_syntax
*)x
->av_struct
);
else if (syntax_table
[x
->av_syntax
].s_copy
!= NULLIFP
)
y
->av_struct
= (caddr_t
)(*syntax_table
[x
->av_syntax
].s_copy
) (x
->av_struct
);
register AttributeValue x
;
register AttributeValue y
;
struct file_syntax
* fileattr_cpy();
/* Encode a copy of x into y */
if (x
->av_struct
== NULL
) {
if (x
->av_syntax
== AV_FILE
)
y
->av_struct
= (caddr_t
) grab_filepe (x
);
else if (syntax_table
[x
->av_syntax
].s_encode
!= NULLIFP
)
y
->av_struct
= (caddr_t
)(*syntax_table
[x
->av_syntax
].s_encode
) (x
->av_struct
);
for (; (a
!= NULLRDN
) && (b
!= NULLRDN
) ; a
= a
->rdn_next
, b
= b
->rdn_next
) {
if (a
->rdn_at
!= b
->rdn_at
)
return ((a
->rdn_at
> b
->rdn_at
) ? 1 : -1);
if (syntax_table
[a
->rdn_av
.av_syntax
].s_compare
== NULLIFP
)
return (2); /* can't compare */
if (( i
= (*syntax_table
[a
->rdn_av
.av_syntax
].s_compare
) (a
->rdn_av
.av_struct
,b
->rdn_av
.av_struct
)) != 0)
if ( (a
== NULLRDN
) && (b
== NULLRDN
) ) {
for (; (a
!= NULLRDN
) && (b
!= NULLRDN
) ; a
= a
->rdn_next
, b
= b
->rdn_next
) {
if (a
->rdn_at
!= b
->rdn_at
)
return ((a
->rdn_at
> b
->rdn_at
) ? -1 : 1);
if (syntax_table
[a
->rdn_av
.av_syntax
].s_compare
== NULLIFP
)
return (2); /* can't compare */
if (( i
= (*syntax_table
[a
->rdn_av
.av_syntax
].s_compare
) (a
->rdn_av
.av_struct
,b
->rdn_av
.av_struct
)) != 0)
if ( (a
== NULLRDN
) && (b
== NULLRDN
) ) {
register AttributeValue x
,y
;
if (x
->av_syntax
!= y
->av_syntax
)
if (x
->av_syntax
== AV_FILE
)
return (file_cmp ((struct file_syntax
*)x
->av_struct
,(struct file_syntax
*)y
->av_struct
));
if (syntax_table
[x
->av_syntax
].s_compare
!= NULLIFP
)
return ((*syntax_table
[x
->av_syntax
].s_compare
) (x
->av_struct
,y
->av_struct
));
return (2); /* can't compare */
if ( syntax
>= AV_WRITE_FILE
)
if (syntax_table
[syntax
].s_compare
!= NULLIFP
)
return (syntax_table
[syntax
].s_compare
);
AttrV_print (ps
,x
,format
)
if (x
->av_syntax
== AV_FILE
)
fileattr_print (ps
,x
,format
);
else if ((format
== READOUT
) && (syntax_table
[x
->av_syntax
].s_pe_print
!= NULLCP
))
exec_print (ps
,x
,syntax_table
[x
->av_syntax
].s_pe_print
);
else if (syntax_table
[x
->av_syntax
].s_print
!= NULLIFP
) {
if (x
->av_struct
!= NULL
)
(*syntax_table
[x
->av_syntax
].s_print
) (ps
,x
->av_struct
,format
);
} else if (format
== READOUT
) {
vunknown ((PE
)x
->av_struct
);
pe_print (ps
,(PE
)x
->av_struct
,format
);