ReactOS 0.4.16-dev-927-g467dec4
certutil.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS certutil
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: CertUtil commandline handling
5 * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org)
6 *
7 * Note: Only -hashfile and -asn are implemented for now, the rest is not present!
8 */
9
10#include "precomp.h"
11#include <wincrypt.h>
12#include <stdlib.h>
13
14typedef struct
15{
18} Verb;
19
20
22 { L"hashfile", hash_file },
23 { L"asn", asn_dump },
24};
25
26static void print_usage()
27{
28 ConPuts(StdOut, L"Verbs:\n");
29 ConPuts(StdOut, L" -hashfile -- Display cryptographic hash over a file\n");
30 ConPuts(StdOut, L" -asn -- Display ASN.1 encoding of a file\n");
31 ConPuts(StdOut, L"\n");
32 ConPuts(StdOut, L"CertUtil -? -- Display a list of all verbs\n");
33 ConPuts(StdOut, L"CertUtil -hashfile -? -- Display help text for the 'hashfile' verb\n");
34}
35
36
38{
39 if (arg[0] != '-' && arg[0] != '/')
40 return NULL;
41
42 for (size_t n = 0; n < RTL_NUMBER_OF(verbs); ++n)
43 {
44 if (!_wcsicmp(verbs[n].Name, arg + 1))
45 {
46 return verbs + n;
47 }
48 }
49
50 return NULL;
51}
52
53int wmain(int argc, WCHAR *argv[])
54{
55 int n;
56
57 /* Initialize the Console Standard Streams */
59
60 if (argc == 1) /* i.e. no commandline arguments given */
61 {
63 return EXIT_SUCCESS;
64 }
65
66 for (n = 1; n < argc; ++n)
67 {
68 if (!_wcsicmp(argv[n], L"-?"))
69 {
71 return EXIT_SUCCESS;
72 }
73
74 Verb* verb = MatchVerb(argv[n]);
75
76 if (verb)
77 {
78 if (argc != 3)
79 {
80 ConPrintf(StdOut, L"CertUtil: -%s expected 1 argument, got %d\n", verb->Name, argc - 2);
81 return EXIT_FAILURE;
82 }
83
84 if (!_wcsicmp(argv[n+1], L"-?"))
85 {
87 return EXIT_SUCCESS;
88 }
89
90 if (!verb->pfn(argv[n+1]))
91 {
92 /* The verb prints the failure */
93 return EXIT_FAILURE;
94 }
95
96 ConPrintf(StdOut, L"CertUtil: -%s command completed successfully\n", verb->Name);
97 return EXIT_SUCCESS;
98 }
99 else
100 {
101 ConPrintf(StdOut, L"CertUtil: Unknown verb: %s\n", argv[n]);
102 return EXIT_FAILURE;
103 }
104 }
105
106 return EXIT_SUCCESS;
107}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static int argc
Definition: ServiceArgs.c:12
BOOL asn_dump(LPCWSTR Filename)
Definition: asn.cpp:456
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
Verb verbs[]
Definition: certutil.cpp:21
static void print_usage()
Definition: certutil.cpp:26
Verb * MatchVerb(LPCWSTR arg)
Definition: certutil.cpp:37
#define NULL
Definition: types.h:112
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:940
GLdouble n
Definition: glext.h:7729
BOOL hash_file(LPCWSTR Filename)
Definition: hashfile.cpp:13
#define EXIT_FAILURE
Definition: jerror.c:33
#define argv
Definition: mplay32.c:18
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
int wmain()
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL(* pfn)(LPCWSTR Filename)
Definition: certutil.cpp:17
LPCWSTR Name
Definition: certutil.cpp:16
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185