Revert "s3: vfs: add user_vfs_evg to connection_struct"
[Samba.git] / lib / mscat / dumpmscat.c
blobeac2184e7ad15d3909cc5c4b4a5a45edb0f89bff
1 /*
2 * Copyright (c) 2016 Andreas Schneider <asn@samba.org>
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.
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.
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/>.
18 #include <errno.h>
19 #include <stdbool.h>
20 #include <stdarg.h>
21 #include <stdint.h>
22 #include <stdio.h>
24 #include <talloc.h>
26 #include <libtasn1.h>
27 #include <gnutls/pkcs7.h>
29 #include "mscat.h"
31 static const char *mac_to_string(enum mscat_mac_algorithm algo) {
32 switch(algo) {
33 case MSCAT_MAC_NULL:
34 return "NULL";
35 case MSCAT_MAC_MD5:
36 return "MD5";
37 case MSCAT_MAC_SHA1:
38 return "SHA1";
39 case MSCAT_MAC_SHA256:
40 return "SHA256";
41 case MSCAT_MAC_SHA512:
42 return "SHA512";
43 case MSCAT_MAC_UNKNOWN:
44 return "UNKNOWN";
47 return "UNKNOWN";
50 int main(int argc, char *argv[]) {
51 TALLOC_CTX *mem_ctx;
52 const char *filename = NULL;
53 const char *ca_file = NULL;
54 struct mscat_pkcs7 *cat_pkcs7;
55 struct mscat_ctl *msctl;
56 unsigned int member_count = 0;
57 unsigned int attribute_count = 0;
58 unsigned int i;
59 int rc;
61 if (argc < 1) {
62 return -1;
64 filename = argv[1];
66 if (filename == NULL || filename[0] == '\0') {
67 return -1;
70 mem_ctx = talloc_init("dumpmscat");
71 if (mem_ctx == NULL) {
72 fprintf(stderr, "Failed to initialize talloc\n");
73 exit(1);
76 /* READ MS ROOT CERTIFICATE */
78 cat_pkcs7 = mscat_pkcs7_init(mem_ctx);
79 if (cat_pkcs7 == NULL) {
80 exit(1);
83 rc = mscat_pkcs7_import_catfile(cat_pkcs7,
84 filename);
85 if (rc != 0) {
86 exit(1);
89 if (argc >= 2) {
90 ca_file = argv[2];
93 rc = mscat_pkcs7_verify(cat_pkcs7, ca_file);
94 if (rc != 0) {
95 printf("FAILED TO VERIFY CATALOG FILE!\n");
96 exit(1);
98 printf("CATALOG FILE VERIFIED!\n\n");
100 msctl = mscat_ctl_init(mem_ctx);
101 if (msctl == NULL) {
102 exit(1);
105 rc = mscat_ctl_import(msctl, cat_pkcs7);
106 if (rc != 0) {
107 exit(1);
110 member_count = mscat_ctl_get_member_count(msctl);
111 printf("CATALOG MEMBER COUNT=%d\n", member_count);
113 for (i = 0; i < member_count; i++) {
114 struct mscat_ctl_member *m;
115 size_t j;
117 rc = mscat_ctl_get_member(msctl,
118 mem_ctx,
119 i + 1,
120 &m);
121 if (rc != 0) {
122 exit(1);
125 printf("CATALOG MEMBER\n");
126 if (m->checksum.type == MSCAT_CHECKSUM_STRING) {
127 printf(" CHECKSUM: %s\n", m->checksum.string);
128 } else if (m->checksum.type == MSCAT_CHECKSUM_BLOB) {
129 printf(" CHECKSUM: ");
130 for (j = 0; j < m->checksum.size; j++) {
131 printf("%X", m->checksum.blob[j]);
133 printf("\n");
135 printf("\n");
137 if (m->file.name != NULL) {
138 printf(" FILE: %s, FLAGS=0x%08x\n",
139 m->file.name,
140 m->file.flags);
143 if (m->info.guid != NULL) {
144 printf(" GUID: %s, ID=0x%08x\n",
145 m->info.guid,
146 m->info.id);
149 if (m->osattr.value != NULL) {
150 printf(" OSATTR: %s, FLAGS=0x%08x\n",
151 m->osattr.value,
152 m->osattr.flags);
155 if (m->mac.type != MSCAT_MAC_UNKNOWN) {
156 printf(" MAC: %s, DIGEST: ",
157 mac_to_string(m->mac.type));
158 for (j = 0; j < m->mac.digest_size; j++) {
159 printf("%X", m->mac.digest[j]);
161 printf("\n");
163 printf("\n");
165 printf("\n");
167 attribute_count = mscat_ctl_get_attribute_count(msctl);
168 printf("CATALOG ATTRIBUTE COUNT=%d\n", attribute_count);
170 for (i = 0; i < attribute_count; i++) {
171 struct mscat_ctl_attribute *a;
173 rc = mscat_ctl_get_attribute(msctl,
174 mem_ctx,
175 i + 1,
176 &a);
177 if (rc != 0) {
178 exit(1);
181 printf(" NAME=%s, FLAGS=0x%08x, VALUE=%s\n",
182 a->name,
183 a->flags,
184 a->value);
186 talloc_free(mem_ctx);
187 return 0;