rusthound_ce/json/maker/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use std::collections::HashMap;
use std::error::Error;

extern crate zip;
use crate::args::Options;
use crate::utils::date::return_current_fulldate;
use crate::objects::{
   user::User,
   computer::Computer,
   group::Group,
   ou::Ou,
   container::Container,
   gpo::Gpo,
   domain::Domain,
   ntauthstore::NtAuthStore,
   aiaca::AIACA,
   rootca::RootCA,
   enterpriseca::EnterpriseCA,
   certtemplate::CertTemplate,
   inssuancepolicie::IssuancePolicie,
};
pub mod common;

/// This function will create json output and zip output
pub fn make_result(
   common_args:            &Options,
   vec_users:              Vec<User>,
   vec_groups:             Vec<Group>,
   vec_computers:          Vec<Computer>,
   vec_ous:                Vec<Ou>,
   vec_domains:            Vec<Domain>,
   vec_gpos:               Vec<Gpo>,
   vec_containers:         Vec<Container>,
   vec_ntauthstores:       Vec<NtAuthStore>,
   vec_aiacas:             Vec<AIACA>,
   vec_rootcas:            Vec<RootCA>,
   vec_enterprisecas:      Vec<EnterpriseCA>,
   vec_certtemplates:      Vec<CertTemplate>,
   vec_issuancepolicies:   Vec<IssuancePolicie>,
) -> Result<(), Box<dyn Error>> {
   // Format domain name
   let filename = common_args.domain.replace(".", "-").to_lowercase();

   // Hashmap for json files
   let mut json_result: HashMap<String, String> = HashMap::new();

   // Datetime for output file
   let datetime = return_current_fulldate();

   // Add all in json files
   common::add_file(
      &datetime,
      "users".to_string(),
		&filename,
      vec_users,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "groups".to_string(),
		&filename,
      vec_groups,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "computers".to_string(),
		&filename,
      vec_computers,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "ous".to_string(),
		&filename,
      vec_ous,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "domains".to_string(),
		&filename,
      vec_domains,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "gpos".to_string(),
      &filename,
      vec_gpos,
      &mut json_result,
      common_args,
   )?;
   // }
   common::add_file(
      &datetime,
      "containers".to_string(),
		&filename,
      vec_containers,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "ntauthstores".to_string(),
		&filename,
      vec_ntauthstores,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "aiacas".to_string(),
		&filename,
      vec_aiacas,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "rootcas".to_string(),
		&filename,
      vec_rootcas,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "enterprisecas".to_string(),
		&filename,
      vec_enterprisecas,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "certtemplates".to_string(),
		&filename,
      vec_certtemplates,
      &mut json_result,
      common_args,
   )?;
   common::add_file(
      &datetime,
      "issuancepolicies".to_string(),
		&filename,
      vec_issuancepolicies,
      &mut json_result,
      common_args,
   )?;
   // All in zip file
   if common_args.zip {
      common::make_a_zip(
         &datetime,
         &filename,
         &common_args.path,
         &json_result);
   }
   Ok(())
}