mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-02 04:46:46 -05:00
Lock unsafe command-line options after enabling --lock-options
This commit is contained in:
parent
209b902301
commit
d92d296bcd
2 changed files with 56 additions and 0 deletions
|
|
@ -213,6 +213,7 @@ int main(int argc, char* argv[])
|
||||||
int i;
|
int i;
|
||||||
int pos;
|
int pos;
|
||||||
int mode;
|
int mode;
|
||||||
|
int lock_options;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
@ -246,7 +247,11 @@ int main(int argc, char* argv[])
|
||||||
utf8_argc = 1;
|
utf8_argc = 1;
|
||||||
|
|
||||||
mode = MODE_DEFAULT;
|
mode = MODE_DEFAULT;
|
||||||
|
lock_options = 0;
|
||||||
for (i = 1; i < wide_argc; i++) {
|
for (i = 1; i < wide_argc; i++) {
|
||||||
|
if (wcscmp(wide_argv[i], L"--lock-options") == 0)
|
||||||
|
lock_options = 1;
|
||||||
|
|
||||||
if (wcscmp(wide_argv[i], L"-s") == 0 || wcscmp(wide_argv[i], L"--spin-down-on-error") == 0) {
|
if (wcscmp(wide_argv[i], L"-s") == 0 || wcscmp(wide_argv[i], L"--spin-down-on-error") == 0) {
|
||||||
mode = MODE_SPINDOWN;
|
mode = MODE_SPINDOWN;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -264,6 +269,11 @@ int main(int argc, char* argv[])
|
||||||
utf8_argv[utf8_argc] = 0;
|
utf8_argv[utf8_argc] = 0;
|
||||||
cmd_buffer[pos] = 0;
|
cmd_buffer[pos] = 0;
|
||||||
|
|
||||||
|
if (mode == MODE_SPINDOWN && lock_options) {
|
||||||
|
fprintf(stderr, "The --spin-down-on-error option cannot be used with --lock-options.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
LocalFree(wide_argv);
|
LocalFree(wide_argv);
|
||||||
|
|
||||||
if (mode == MODE_DEFAULT) {
|
if (mode == MODE_DEFAULT) {
|
||||||
|
|
@ -370,12 +380,17 @@ static void forward_signal(int sig)
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int mode;
|
int mode;
|
||||||
|
int lock_options;
|
||||||
int i, j;
|
int i, j;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mode = MODE_DEFAULT;
|
mode = MODE_DEFAULT;
|
||||||
|
lock_options = 0;
|
||||||
j = 1;
|
j = 1;
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
|
if (strcmp(argv[i], "--lock-options") == 0)
|
||||||
|
lock_options = 1;
|
||||||
|
|
||||||
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0) {
|
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0) {
|
||||||
mode = MODE_SPINDOWN;
|
mode = MODE_SPINDOWN;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -386,6 +401,11 @@ int main(int argc, char* argv[])
|
||||||
argc = j;
|
argc = j;
|
||||||
argv[argc] = 0;
|
argv[argc] = 0;
|
||||||
|
|
||||||
|
if (mode == MODE_SPINDOWN && lock_options) {
|
||||||
|
fprintf(stderr, "The --spin-down-on-error option cannot be used with --lock-options.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == MODE_DEFAULT) {
|
if (mode == MODE_DEFAULT) {
|
||||||
ret = snapraid_main(argc, argv);
|
ret = snapraid_main(argc, argv);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -203,10 +203,12 @@ void log_close(const char* file)
|
||||||
#define OPT_GUI_TOUCH_BEFORE 504
|
#define OPT_GUI_TOUCH_BEFORE 504
|
||||||
#define OPT_GUI_THRESHOLD_REMOVES 505
|
#define OPT_GUI_THRESHOLD_REMOVES 505
|
||||||
#define OPT_GUI_THRESHOLD_UPDATES 506
|
#define OPT_GUI_THRESHOLD_UPDATES 506
|
||||||
|
#define OPT_LOCK_OPTIONS 507
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test options
|
* Test options
|
||||||
*/
|
*/
|
||||||
|
#define OPT_TEST_FIRST 256
|
||||||
#define OPT_TEST_SKIP_SELF 256
|
#define OPT_TEST_SKIP_SELF 256
|
||||||
#define OPT_TEST_KILL_AFTER_SYNC 257
|
#define OPT_TEST_KILL_AFTER_SYNC 257
|
||||||
#define OPT_TEST_EXPECT_UNRECOVERABLE 258
|
#define OPT_TEST_EXPECT_UNRECOVERABLE 258
|
||||||
|
|
@ -257,6 +259,7 @@ void log_close(const char* file)
|
||||||
#define OPT_TEST_SPEED_BLOCKS_SIZE 309
|
#define OPT_TEST_SPEED_BLOCKS_SIZE 309
|
||||||
#define OPT_TEST_KILL_BEFORE_SYNC 310
|
#define OPT_TEST_KILL_BEFORE_SYNC 310
|
||||||
#define OPT_TEST_KILL_AFTER_RESIZE 311
|
#define OPT_TEST_KILL_AFTER_RESIZE 311
|
||||||
|
#define OPT_TEST_LAST 311
|
||||||
|
|
||||||
#if HAVE_GETOPT_LONG
|
#if HAVE_GETOPT_LONG
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
|
|
@ -298,6 +301,7 @@ static struct option long_options[] = {
|
||||||
{ "version", 0, 0, 'V' },
|
{ "version", 0, 0, 'V' },
|
||||||
|
|
||||||
{ "no-warnings", 0, 0, OPT_NO_WARNINGS }, /* disable annoying warnings */
|
{ "no-warnings", 0, 0, OPT_NO_WARNINGS }, /* disable annoying warnings */
|
||||||
|
{ "lock-options", 0, 0, OPT_LOCK_OPTIONS }, /* lock options to avoid unintended injection */
|
||||||
{ "gui", 0, 0, OPT_GUI }, /* undocumented GUI interface option (it was also 'G' in the past) */
|
{ "gui", 0, 0, OPT_GUI }, /* undocumented GUI interface option (it was also 'G' in the past) */
|
||||||
{ "gui-verbose", 0, 0, OPT_GUI_VERBOSE }, /* undocumented GUI interface option */
|
{ "gui-verbose", 0, 0, OPT_GUI_VERBOSE }, /* undocumented GUI interface option */
|
||||||
{ "gui-rescan-after", 0, 0, OPT_GUI_RESCAN_AFTER }, /* undocumented GUI, force a rescan after the command to log differences */
|
{ "gui-rescan-after", 0, 0, OPT_GUI_RESCAN_AFTER }, /* undocumented GUI, force a rescan after the command to log differences */
|
||||||
|
|
@ -458,6 +462,24 @@ static struct option long_options[] = {
|
||||||
*/
|
*/
|
||||||
#define OPTIONS "t:c:f:d:mebp:o:S:B:L:i:l:AZEUDNFRW:ahTC:vqHVw:"
|
#define OPTIONS "t:c:f:d:mebp:o:S:B:L:i:l:AZEUDNFRW:ahTC:vqHVw:"
|
||||||
|
|
||||||
|
static int option_locked(int c)
|
||||||
|
{
|
||||||
|
if (c >= OPT_TEST_FIRST && c <= OPT_TEST_LAST)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case 'c' : /* --conf */
|
||||||
|
case 'C' : /* --gen-conf */
|
||||||
|
case 'l' : /* --log */
|
||||||
|
case 'H' : /* --help */
|
||||||
|
case 'V' : /* --version */
|
||||||
|
case 'T' : /* --speed-test */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int parse_option_size(const char* arg, uint64_t* out_size)
|
static int parse_option_size(const char* arg, uint64_t* out_size)
|
||||||
{
|
{
|
||||||
char* e;
|
char* e;
|
||||||
|
|
@ -544,6 +566,7 @@ int snapraid_main(int argc, char* argv[])
|
||||||
const char* import_content;
|
const char* import_content;
|
||||||
const char* log_file;
|
const char* log_file;
|
||||||
int lock;
|
int lock;
|
||||||
|
int lock_options;
|
||||||
const char* gen_conf;
|
const char* gen_conf;
|
||||||
#if HAVE_CHECKER
|
#if HAVE_CHECKER
|
||||||
const char* run;
|
const char* run;
|
||||||
|
|
@ -584,6 +607,7 @@ int snapraid_main(int argc, char* argv[])
|
||||||
import_content = 0;
|
import_content = 0;
|
||||||
log_file = 0;
|
log_file = 0;
|
||||||
lock = 0;
|
lock = 0;
|
||||||
|
lock_options = 0;
|
||||||
gen_conf = 0;
|
gen_conf = 0;
|
||||||
speedtest = 0;
|
speedtest = 0;
|
||||||
#if HAVE_CHECKER
|
#if HAVE_CHECKER
|
||||||
|
|
@ -598,6 +622,11 @@ int snapraid_main(int argc, char* argv[])
|
||||||
getopt(argc, argv, OPTIONS))
|
getopt(argc, argv, OPTIONS))
|
||||||
#endif
|
#endif
|
||||||
!= EOF) {
|
!= EOF) {
|
||||||
|
if (lock_options && option_locked(c)) {
|
||||||
|
log_fatal(EUSER, "Option not allowed after --lock-options.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c' :
|
case 'c' :
|
||||||
pathimport(conf, sizeof(conf), optarg);
|
pathimport(conf, sizeof(conf), optarg);
|
||||||
|
|
@ -805,6 +834,13 @@ int snapraid_main(int argc, char* argv[])
|
||||||
case OPT_NO_WARNINGS :
|
case OPT_NO_WARNINGS :
|
||||||
opt.no_warnings = 1;
|
opt.no_warnings = 1;
|
||||||
break;
|
break;
|
||||||
|
case OPT_LOCK_OPTIONS :
|
||||||
|
if (strcmp(argv[optind - 1], "--lock-options") != 0) {
|
||||||
|
log_fatal(EUSER, "Option '--lock-options' cannot be abbreviated.\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
lock_options = 1;
|
||||||
|
break;
|
||||||
case OPT_GUI :
|
case OPT_GUI :
|
||||||
opt.gui = 1;
|
opt.gui = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue