lib: Add support to parse MS Catalog files
[samba.git] / lib / mscat / mscat.h
1 /*
2  * Copyright (c) 2016      Andreas Schneider <asn@samba.org>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef _MSCAT_H
19 #define _MSCAT_H
20
21 #include <stdbool.h>
22 #include <talloc.h>
23 #include <gnutls/pkcs7.h>
24 #include <libtasn1.h>
25
26 enum mscat_mac_algorithm {
27         MSCAT_MAC_UNKNOWN,
28         MSCAT_MAC_NULL,
29         MSCAT_MAC_MD5,
30         MSCAT_MAC_SHA1,
31         MSCAT_MAC_SHA256,
32         MSCAT_MAC_SHA512
33 };
34
35 struct mscat_pkcs7;
36
37 struct mscat_pkcs7 *mscat_pkcs7_init(TALLOC_CTX *mem_ctx);
38
39 int mscat_pkcs7_import_catfile(struct mscat_pkcs7 *mp7,
40                                const char *catfile);
41
42 int mscat_pkcs7_verify(struct mscat_pkcs7 *mp7,
43                        const char *ca_file);
44
45 struct mscat_ctl;
46
47 struct mscat_ctl *mscat_ctl_init(TALLOC_CTX *mem_ctx);
48
49 int mscat_ctl_import(struct mscat_ctl *ctl,
50                      struct mscat_pkcs7 *pkcs7);
51
52 int mscat_ctl_get_member_count(struct mscat_ctl *ctl);
53
54 enum mscat_checksum_type {
55         MSCAT_CHECKSUM_STRING = 1,
56         MSCAT_CHECKSUM_BLOB
57 };
58
59 struct mscat_ctl_member {
60         struct {
61                 enum mscat_checksum_type type;
62                 union {
63                         const char *string;
64                         uint8_t *blob;
65                 };
66                 size_t size;
67         } checksum;
68         struct {
69                 const char *name;
70                 uint32_t flags;
71         } file;
72         struct {
73                 const char *value;
74                 uint32_t flags;
75         } osattr;
76         struct {
77                 const char *guid;
78                 uint32_t id;
79         } info;
80         struct {
81                 enum mscat_mac_algorithm type;
82                 uint8_t *digest;
83                 size_t digest_size;
84         } mac;
85 };
86
87 int mscat_ctl_get_member(struct mscat_ctl *ctl,
88                          TALLOC_CTX *mem_ctx,
89                          unsigned int idx,
90                          struct mscat_ctl_member **member);
91
92 int mscat_ctl_get_attribute_count(struct mscat_ctl *ctl);
93
94 struct mscat_ctl_attribute {
95         const char *name;
96         uint32_t flags;
97         const char *value;
98 };
99
100 int mscat_ctl_get_attribute(struct mscat_ctl *ctl,
101                             TALLOC_CTX *mem_ctx,
102                             unsigned int idx,
103                             struct mscat_ctl_attribute **pattribute);
104
105 #endif /* _MSCAT_H */