diff options
| author | waja <waja@users.noreply.github.com> | 2022-11-04 19:16:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-04 19:16:01 +0100 |
| commit | 2d9c6276d0a380f831bf94734359f071d0c7e958 (patch) | |
| tree | 592f5a808494edaf138de5aee0563564adba4f9a /plugins | |
| parent | eb2dfdd5c24b87198b66397b224d6406c468a0bc (diff) | |
| download | monitoring-plugins-2d9c6276d0a380f831bf94734359f071d0c7e958.tar.gz | |
Removing is_pg_dbname alltogether,using postgres API. (Closes: #1660) (#1803)
The problem is that check_pgsql validates the Database name and has different assumptions
that postgres itself.
I fail to see a reason to validate the database name here. Postgres'es API should
do this - So i would suggest a fix like this by removing is_pg_dbname alltogether.
Co-authored-by: Florian Lohoff <f@zz.de>
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_pgsql.c | 48 |
1 files changed, 4 insertions, 44 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index c893386c..c26cd439 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
| @@ -69,7 +69,6 @@ int process_arguments (int, char **); | |||
| 69 | int validate_arguments (void); | 69 | int validate_arguments (void); |
| 70 | void print_usage (void); | 70 | void print_usage (void); |
| 71 | void print_help (void); | 71 | void print_help (void); |
| 72 | int is_pg_dbname (char *); | ||
| 73 | int is_pg_logname (char *); | 72 | int is_pg_logname (char *); |
| 74 | int do_query (PGconn *, char *); | 73 | int do_query (PGconn *, char *); |
| 75 | 74 | ||
| @@ -347,10 +346,10 @@ process_arguments (int argc, char **argv) | |||
| 347 | pgport = optarg; | 346 | pgport = optarg; |
| 348 | break; | 347 | break; |
| 349 | case 'd': /* database name */ | 348 | case 'd': /* database name */ |
| 350 | if (!is_pg_dbname (optarg)) /* checks length and valid chars */ | 349 | if (strlen(optarg) >= NAMEDATALEN) { |
| 351 | usage2 (_("Database name is not valid"), optarg); | 350 | usage2 (_("Database name exceeds the maximum length"), optarg); |
| 352 | else /* we know length, and know optarg is terminated, so us strcpy */ | 351 | } |
| 353 | snprintf(dbName, NAMEDATALEN, "%s", optarg); | 352 | snprintf(dbName, NAMEDATALEN, "%s", optarg); |
| 354 | break; | 353 | break; |
| 355 | case 'l': /* login name */ | 354 | case 'l': /* login name */ |
| 356 | if (!is_pg_logname (optarg)) | 355 | if (!is_pg_logname (optarg)) |
| @@ -414,45 +413,6 @@ validate_arguments () | |||
| 414 | return OK; | 413 | return OK; |
| 415 | } | 414 | } |
| 416 | 415 | ||
| 417 | |||
| 418 | /****************************************************************************** | ||
| 419 | |||
| 420 | @@- | ||
| 421 | <sect3> | ||
| 422 | <title>is_pg_dbname</title> | ||
| 423 | |||
| 424 | <para>&PROTO_is_pg_dbname;</para> | ||
| 425 | |||
| 426 | <para>Given a database name, this function returns TRUE if the string | ||
| 427 | is a valid PostgreSQL database name, and returns false if it is | ||
| 428 | not.</para> | ||
| 429 | |||
| 430 | <para>Valid PostgreSQL database names are less than &NAMEDATALEN; | ||
| 431 | characters long and consist of letters, numbers, and underscores. The | ||
| 432 | first character cannot be a number, however.</para> | ||
| 433 | |||
| 434 | </sect3> | ||
| 435 | -@@ | ||
| 436 | ******************************************************************************/ | ||
| 437 | |||
| 438 | |||
| 439 | |||
| 440 | int | ||
| 441 | is_pg_dbname (char *dbname) | ||
| 442 | { | ||
| 443 | char txt[NAMEDATALEN]; | ||
| 444 | char tmp[NAMEDATALEN]; | ||
| 445 | if (strlen (dbname) > NAMEDATALEN - 1) | ||
| 446 | return (FALSE); | ||
| 447 | strncpy (txt, dbname, NAMEDATALEN - 1); | ||
| 448 | txt[NAMEDATALEN - 1] = 0; | ||
| 449 | if (sscanf (txt, "%[_a-zA-Z]%[^_a-zA-Z0-9-]", tmp, tmp) == 1) | ||
| 450 | return (TRUE); | ||
| 451 | if (sscanf (txt, "%[_a-zA-Z]%[_a-zA-Z0-9-]%[^_a-zA-Z0-9-]", tmp, tmp, tmp) == | ||
| 452 | 2) return (TRUE); | ||
| 453 | return (FALSE); | ||
| 454 | } | ||
| 455 | |||
| 456 | /** | 416 | /** |
| 457 | 417 | ||
| 458 | the tango program should eventually create an entity here based on the | 418 | the tango program should eventually create an entity here based on the |
