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
|
diff -urN ./plugins/check_mysql.c ../plugins/plugins/check_mysql.c
--- ./plugins/check_mysql.c 2005-01-05 21:53:16.000000000 +0100
+++ ../plugins/plugins/check_mysql.c 2005-02-17 16:08:30.000000000 +0100
@@ -155,7 +155,7 @@
int
process_arguments (int argc, char **argv)
{
- int c;
+ int c, i;
int option = 0;
static struct option longopts[] = {
@@ -193,10 +193,19 @@
db = optarg;
break;
case 'u': /* username */
- db_user = optarg;
+ if((db_user = strdup(optarg))) {
+ for(i = 0; i < strlen(argv[optind]); i++) argv[optind][i] = 'x';
+ }
+ else
+ db_user = optarg;
break;
case 'p': /* authentication information: password */
- db_pass = optarg;
+ if((db_pass = strdup(optarg))) {
+ /* strdup was successful, so obscure passwd from ps view */
+ for(i = 0; i < strlen(argv[optind]); i++) argv[optind][i] = 'x';
+ }
+ else /* strdup failed, so point it to password input string */
+ db_pass = optarg;
break;
case 'P': /* critical time threshold */
db_port = atoi (optarg);
@@ -219,18 +228,27 @@
while ( argc > c ) {
- if (strlen(db_host) == 0)
+ if (db_host == NULL || strlen(db_host) == 0) {
if (is_host (argv[c])) {
db_host = argv[c++];
}
else {
usage2 (_("Invalid hostname/address"), optarg);
}
- else if (strlen(db_user) == 0)
- db_user = argv[c++];
- else if (strlen(db_pass) == 0)
- db_pass = argv[c++];
- else if (strlen(db) == 0)
+ }
+ else if (db_user == NULL || strlen(db_user) == 0) {
+ if((db_user = strdup(argv[c++])))
+ for(i = 0; i < strlen(argv[c]); i++) argv[c][i] = 'x';
+ else
+ db_user = argv[c];
+ }
+ else if (db_pass == NULL || strlen(db_pass) == 0) {
+ if((db_pass = strdup(argv[c++])))
+ for(i = 0; i < strlen(argv[c]); i++) argv[c][i] = 'x';
+ else
+ db_pass = argv[c];
+ }
+ else if (db == NULL || strlen(db) == 0)
db = argv[c++];
else if (is_intnonneg (argv[c]))
db_port = atoi (argv[c++]);
@@ -246,16 +264,16 @@
validate_arguments (void)
{
if (db_user == NULL)
- db_user = strdup("");
+ db_user = "";
if (db_host == NULL)
- db_host = strdup("");
+ db_host = "";
if (db_pass == NULL)
- db_pass == strdup("");
+ db_pass == "";
if (db == NULL)
- db = strdup("");
+ db = "";
return OK;
}
|