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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/**
* NetNuke - Erases all storage media detected by the system
* Copyright (C) 2009-2010 Joseph Hunkeler <jhunkeler@gmail.com, jhunk@stsci.edu>
*
* This file is part of NetNuke.
*
* NetNuke is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NetNuke is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NetNuke. If not, see <http://www.gnu.org/licenses/>.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <libgen.h> /* for basename() */
#include <fcntl.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <glob.h>
#include <pthread.h>
#include "netnuke.h"
pthread_mutex_t lock_global = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock_write = PTHREAD_MUTEX_INITIALIZER;
extern unsigned long long total_written_bytes;
unsigned int blksz_override = 0;
int list_flag = 0;
int ignore_first_flag = 0;
int ignore_flag = 0;
int safety_flag = 0;
int logging_flag = 0;
int verbose_flag = 0;
int bus_mask = 0;
int device_timeout = 0;
char** bus_flags = NULL;
char** ignore_list = NULL;
nndevice_t** device;
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, &verbose_flag, 1},
{"quiet", no_argument, &verbose_flag, 0},
{"list", no_argument, &list_flag, 1},
{"safety-off", no_argument, &safety_flag, 0},
{"ignore-first", no_argument, &ignore_first_flag, 1},
{"ignore", required_argument, 0, 'i'},
{"logging", no_argument, &logging_flag, 1},
{"timeout", required_argument, 0, 't'},
{"scheme", required_argument, 0, 's'},
{"device-type", required_argument, 0, 'd'},
{"block-size", required_argument, 0, 'b'},
{NULL, 0, 0, 0}
};
/* The usage function will apply these strings */
static const char* long_options_help[] =
{
"\tThis message",
"More output",
"Suppress output",
"\tPrint device list, then exit",
"Enable destructive write mode",
"Ignore first device",
"Ignore comma delimited list of devices",
"Log all output to netnuke.log",
"Set timeout-to-failure (in seconds)",
"Set nuking scheme:\n\
0 = zero\n\
1 = static pattern\n\
2 = pure random",
"Select bus:\n\
ide\n\
scsi",
"Block size in bytes",
NULL
};
char *scsi_device_glob[] =
{
"/dev/sd*[!0-9]",
"/dev/nsr*",
"/dev/tape*",
NULL
};
char *ide_device_glob[] =
{
"/dev/hd*[!0-9]",
NULL
};
void usage(const char* progname)
{
int i;
printf("%s %s %s <%s>\n", PACKAGE_STRING, LICENSE, AUTHOR, PACKAGE_BUGREPORT);
printf("usage: %s ", progname);
for( i = 0 ; long_options[i].name != NULL ; i++ )
{
if(!long_options[i].has_arg)
{
if(strncasecmp("help", long_options[i].name, strlen(long_options[i].name)) != 0)
printf("[--%s] ", long_options[i].name);
}
if(long_options[i].has_arg)
printf("[-%c val] ", (char)long_options[i].val);
}
putchar('\n');
for( i = 0 ; long_options[i].name != NULL ; i++)
{
printf(" --%s\t", long_options[i].name);
if(long_options[i].has_arg)
{
printf("-%c\t", (char)long_options[i].val);
}
else
{
printf("\t");
}
printf("%s\n", long_options_help[i]);
}
exit(0);
}
int main(int argc, char* argv[])
{
/* Re-enable this later... jesus testing is getting annoying.
uid_t uid=getuid(), euid=geteuid();
if (uid != 0 || uid != euid)
{
COM(self, "Need root... exiting\n");
exit(1);
}
*/
if((nnlogcleanup()) != 0)
{
fprintf(stderr, "Failed to cleanup %s: %s\n", NNLOGFILE, strerror(errno));
}
if(argc < 2) usage(basename(argv[0]));
int c;
int option_index = 0;
while((c = getopt_long (argc, argv, "ib:s:d:t:", long_options, &option_index)) != -1)
{
switch (c)
{
case 0:
{
if (long_options[option_index].flag != 0) break;
printf ("option %s", long_options[option_index].name);
if (optarg) printf (" with arg %s", optarg);
printf ("\n");
break;
}
case 'b':
{
blksz_override = atoi(optarg);
if(blksz_override < 512)
{
fprintf(stderr, "Block size must be a multiple of 512\n");
exit(1);
}
break;
}
case 's':
{
break;
}
case 't':
{
device_timeout = atoi(optarg);
break;
}
case 'i':
{
ignore_flag = 1;
int i = 0;
char* tok = strtok(optarg, ",");
ignore_list = (char**)malloc(1024);
while(tok != NULL)
{
ignore_list[i] = (char*)malloc(strlen(tok)+1);
strncpy(ignore_list[i], tok, strlen(tok)+1);
i++;
tok = strtok(NULL, ",");
}
break;
}
case 'd':
{
int i = 0;
char* tok = strtok(optarg, ",");
bus_flags = (char**)malloc(1024);
while(tok != NULL)
{
bus_flags[i] = (char*)malloc(strlen(tok)+1);
strncpy(bus_flags[i], tok, strlen(tok)+1);
i++;
tok = strtok(NULL, ",");
}
break;
}
case 'h':
case '?':
usage(basename(argv[0]));
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
putchar ('\n');
}
/* Initialize ncurses */
initscr();
/* Initialize secondary main thread */
main_init();
endwin();
return 0;
}
|