-
Notifications
You must be signed in to change notification settings - Fork 1
/
PatchExclusion.cs
130 lines (128 loc) · 3.81 KB
/
PatchExclusion.cs
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
using System;
using System.Data;
using Symantec.CWoC.APIWrappers;
namespace Symantec.CWoC {
class PatchExclusion {
public static int Main(string[] Args) {
if (Args.Length == 0) {
help();
return -1;
} else {
if (SecurityAPI.is_user_admin()) {
try {
DatabaseAPI.ExecuteNonQuery(Constant.PATCH_EXCLUSION_CREATION);
} catch {
Console.WriteLine("Failed to access the Symantec CMDB... Patch Exclusion will stop now.");
return -1;
}
switch (Args[0]) {
case "version":
return version();
case "++":
case "add":
return add(Args);
case "--":
case "del":
return del(Args);
case "ls":
case "list":
return list();
case "reset":
return rst();
case "forceinit":
return forceinit();
case "help":
case "/?":
help();
return 0;
default:
help();
return -1;
}
} else {
Console.WriteLine("Access denied - Only Administrators are allowed to use this tool.");
return -1;
}
}
}
public static int list() {
Console.WriteLine("Exclusion list:");
try {
DataTable t = DatabaseAPI.GetTable(Constant.PATCH_EXCLUSION_LIST);
foreach (DataRow r in t.Rows) {
Console.WriteLine("\t{0} ({1})", r[0].ToString(), r[1].ToString());
}
return 0;
} catch {
Console.WriteLine("Failed to access the exclusion table...");
Console.WriteLine("If you can add or remove entries you may want to use the force init switch to reset the patch exclusion tasble schema as it may be out-of-date.");
return -1;
}
}
public static int add(string[] bulls) {
int rc = 0;
foreach (string bulletin_name in bulls) {
if (bulletin_name == "++" || bulletin_name == "add" || bulletin_name.Contains("'") || bulletin_name.Contains("\"")) {
continue;
}
Console.Write("Adding bulletin {0} to the exclusion table...", bulletin_name);
string sql = "if not exists (select 1 from patchautomation_excluded where bulletin = '" + bulletin_name + "') insert patchautomation_excluded (bulletin) values ('" + bulletin_name + "')";
try {
DatabaseAPI.ExecuteNonQuery(sql);
Console.WriteLine(" the bulletin was succesfully added.");
} catch {
Console.WriteLine(" the bulletin was not added. [ERROR]");
rc = -1;
}
}
return rc;
}
public static int del(string[] bulls) {
int rc = 0;
foreach (string bulletin_name in bulls) {
if (bulletin_name == "--" || bulletin_name == "del" || bulletin_name.Contains("'") || bulletin_name.Contains("\"")) {
continue;
}
Console.Write("removing bulletin {0} to the exclusion table...", bulletin_name);
try {
DatabaseAPI.ExecuteNonQuery("delete patchautomation_excluded where bulletin = '" + bulletin_name + "'");
Console.WriteLine(" the bulletin was succesfully removed.");
} catch {
Console.WriteLine(" the bulletin was not removed. [ERROR]");
rc = -1;
}
}
return rc;
}
public static int rst() {
Console.Write("Clearing the exclusion table now...");
try {
DatabaseAPI.ExecuteNonQuery("truncate table patchautomation_excluded");
Console.WriteLine(" done!");
return 0;
} catch {
Console.WriteLine(" failed. [ERROR]");
return -1;
}
}
public static int forceinit() {
Console.Write("Deleting the exclusion table now...");
try {
DatabaseAPI.ExecuteNonQuery("drop table patchautomation_excluded");
Console.WriteLine(" done!");
return 0;
} catch {
Console.WriteLine(" failed. [ERROR]");
return -1;
}
}
public static void help() {
Console.WriteLine(Constant.PATCH_EXCLUSION_HELP);
}
public static int version() {
Console.WriteLine(VERSION_MESSAGE);
return 0;
}
public static string VERSION_MESSAGE = "{CWoC} Patch Exclusion version " + Constant.VERSION + ".";
}
}