startup.c 14.7 KB
Newer Older
P
Peter Eisentraut 已提交
1 2 3
/*
 * psql - the PostgreSQL interactive terminal
 *
P
Peter Eisentraut 已提交
4
 * Copyright 2000 by PostgreSQL Global Development Group
P
Peter Eisentraut 已提交
5
 *
6
 * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.63 2002/08/27 20:16:48 petere Exp $
P
Peter Eisentraut 已提交
7
 */
8
#include "postgres_fe.h"
9 10 11

#include <sys/types.h>

12 13
#ifndef WIN32
#include <unistd.h>
14
#else /* WIN32 */
15
#include <io.h>
B
Hi!  
Bruce Momjian 已提交
16
#include <windows.h>
17
#include <win32.h>
18
#endif   /* WIN32 */
19 20 21 22 23

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

P
Peter Eisentraut 已提交
24 25
#include <locale.h>

26
#include "libpq-fe.h"
27 28 29

#include "command.h"
#include "common.h"
30 31
#include "describe.h"
#include "help.h"
32
#include "input.h"
33
#include "mainloop.h"
34
#include "print.h"
35 36
#include "settings.h"
#include "variables.h"
37

38 39
#include "mb/pg_wchar.h"

40 41 42
/*
 * Global psql options
 */
43
PsqlSettings pset;
44 45


46 47
/*
 * Structures to pass information between the option parsing routine
48 49
 * and the main function
 */
B
Bruce Momjian 已提交
50 51
enum _actions
{
52 53 54 55 56
	ACT_NOTHING = 0,
	ACT_SINGLE_SLASH,
	ACT_LIST_DB,
	ACT_SINGLE_QUERY,
	ACT_FILE
57 58
};

B
Bruce Momjian 已提交
59 60 61 62 63 64 65 66 67
struct adhoc_opts
{
	char	   *dbname;
	char	   *host;
	char	   *port;
	char	   *username;
	enum _actions action;
	char	   *action_string;
	bool		no_readline;
68
	bool		no_psqlrc;
69 70 71
};

static void
72
			parse_psql_options(int argc, char *argv[], struct adhoc_opts * options);
73

74
static void
75
			process_psqlrc(void);
76 77

static void
78
			showVersion(void);
79

B
Bruce Momjian 已提交
80 81
#ifdef USE_SSL
static void
B
Bruce Momjian 已提交
82
			printSSLInfo(void);
B
Bruce Momjian 已提交
83
#endif
84

85 86 87

/*
 *
88
 * main
89 90 91
 *
 */
int
92
main(int argc, char *argv[])
93
{
B
Bruce Momjian 已提交
94 95
	struct adhoc_opts options;
	int			successResult;
96

B
Bruce Momjian 已提交
97 98 99
	char	   *username = NULL;
	char	   *password = NULL;
	bool		need_pass;
100

P
Peter Eisentraut 已提交
101
	setlocale(LC_ALL, "");
102
#ifdef ENABLE_NLS
P
Peter Eisentraut 已提交
103 104 105 106
	bindtextdomain("psql", LOCALEDIR);
	textdomain("psql");
#endif

107
	if (!strrchr(argv[0], '/'))
108 109
		pset.progname = argv[0];
	else
110
		pset.progname = strrchr(argv[0], '/') + 1;
111

112 113
	if (argc > 1)
	{
B
Bruce Momjian 已提交
114
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
115 116 117 118
		{
			usage();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
119
		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
120 121 122 123
		{
			showVersion();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
124
	}
125

126 127
	pset.cur_cmd_source = stdin;
	pset.cur_cmd_interactive = false;
128
	pset.encoding = PQenv2encoding();
129

130
	pset.vars = CreateVariableSpace();
131 132
	if (!pset.vars)
	{
P
Peter Eisentraut 已提交
133
		fprintf(stderr, gettext("%s: out of memory\n"), pset.progname);
134 135
		exit(EXIT_FAILURE);
	}
136 137 138
	pset.popt.topt.format = PRINT_ALIGNED;
	pset.queryFout = stdout;
	pset.popt.topt.border = 1;
P
Peter Eisentraut 已提交
139
	pset.popt.topt.pager = true;
140
	pset.popt.default_footer = true;
141

142
	SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
143

144
	pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
145

146
	/* This is obsolete and should be removed sometime. */
147
#ifdef PSQL_ALWAYS_GET_PASSWORDS
148
	pset.getPassword = true;
149
#else
150
	pset.getPassword = false;
151 152
#endif

153
	parse_psql_options(argc, argv, &options);
154

155 156 157 158
	if (!pset.popt.topt.fieldSep)
		pset.popt.topt.fieldSep = xstrdup(DEFAULT_FIELD_SEP);
	if (!pset.popt.topt.recordSep)
		pset.popt.topt.recordSep = xstrdup(DEFAULT_RECORD_SEP);
159

B
Bruce Momjian 已提交
160 161
	if (options.username)
	{
162 163 164 165 166
		/*
		 * The \001 is a hack to support the deprecated -u option which
		 * issues a username prompt. The recommended option is -U followed
		 * by the name on the command line.
		 */
167
		if (strcmp(options.username, "\001") == 0)
168
			username = simple_prompt("User name: ", 100, true);
B
Bruce Momjian 已提交
169 170
		else
			username = strdup(options.username);
171 172
	}

173
	if (pset.getPassword)
B
Bruce Momjian 已提交
174
		password = simple_prompt("Password: ", 100, false);
175

B
Bruce Momjian 已提交
176 177 178 179
	/* loop until we have a password if requested by backend */
	do
	{
		need_pass = false;
180
		pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL,
181 182
			options.action == ACT_LIST_DB ? "template1" : options.dbname,
							   username, password);
B
Bruce Momjian 已提交
183

184
		if (PQstatus(pset.db) == CONNECTION_BAD &&
185 186
			strcmp(PQerrorMessage(pset.db), "fe_sendauth: no password supplied\n") == 0 &&
			!feof(stdin))
B
Bruce Momjian 已提交
187
		{
188
			PQfinish(pset.db);
B
Bruce Momjian 已提交
189 190 191 192 193 194
			need_pass = true;
			free(password);
			password = NULL;
			password = simple_prompt("Password: ", 100, false);
		}
	} while (need_pass);
195

B
Bruce Momjian 已提交
196 197 198
	free(username);
	free(password);

199
	if (PQstatus(pset.db) == CONNECTION_BAD)
B
Bruce Momjian 已提交
200
	{
201
		fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
202
		PQfinish(pset.db);
B
Bruce Momjian 已提交
203 204 205
		exit(EXIT_BADCONN);
	}

206 207 208 209 210 211 212
	PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);

	/*
	 * We need to save the encoding because we want to have it available
	 * even if the database connection goes bad.
	 */
	pset.encoding = PQclientEncoding(pset.db);
P
Peter Eisentraut 已提交
213

B
Bruce Momjian 已提交
214 215
	if (options.action == ACT_LIST_DB)
	{
216
		int			success = listAllDbs(false);
B
Bruce Momjian 已提交
217

218
		PQfinish(pset.db);
219
		exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
B
Bruce Momjian 已提交
220 221
	}

222 223 224 225 226
	SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
	SetVariable(pset.vars, "USER", PQuser(pset.db));
	SetVariable(pset.vars, "HOST", PQhost(pset.db));
	SetVariable(pset.vars, "PORT", PQport(pset.db));
	SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
227

228
	/*
229 230
	 * Now find something to do
	 */
B
Bruce Momjian 已提交
231

232
	/*
233 234
	 * process file given by -f
	 */
235
	if (options.action == ACT_FILE && strcmp(options.action_string, "-") != 0)
236 237 238
	{
		if (!options.no_psqlrc)
			process_psqlrc();
239

240
		successResult = process_file(options.action_string);
241 242
	}

243
	/*
244 245
	 * process slash command if one was given to -c
	 */
B
Bruce Momjian 已提交
246
	else if (options.action == ACT_SINGLE_SLASH)
247 248
	{
		const char *value;
249

250 251
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
252
		successResult = HandleSlashCmds(options.action_string, NULL, NULL, NULL) != CMD_ERROR
253 254 255
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

256
	/*
257 258
	 * If the query given to -c was a normal one, send it
	 */
B
Bruce Momjian 已提交
259
	else if (options.action == ACT_SINGLE_QUERY)
260 261
	{
		const char *value;
262

263 264
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
265
		successResult = SendQuery(options.action_string)
266 267 268
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

269
	/*
270 271
	 * or otherwise enter interactive main loop
	 */
B
Bruce Momjian 已提交
272
	else
273 274 275 276
	{
		pset.issuper = test_superuser(PQuser(pset.db));
		if (!QUIET() && !pset.notty)
		{
277
			printf(gettext("Welcome to %s %s, the PostgreSQL interactive terminal.\n\n"
P
Peter Eisentraut 已提交
278 279
						   "Type:  \\copyright for distribution terms\n"
						   "       \\h for help with SQL commands\n"
280 281
					   "       \\? for help on internal slash commands\n"
			  "       \\g or terminate with semicolon to execute query\n"
P
Peter Eisentraut 已提交
282
						   "       \\q to quit\n\n"),
283
				   pset.progname, PG_VERSION);
B
Bruce Momjian 已提交
284
#ifdef USE_SSL
285
			printSSLInfo();
B
Bruce Momjian 已提交
286
#endif
287 288
		}

289 290 291 292 293 294 295
		SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1);
		SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2);
		SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3);
		if (!options.no_psqlrc)
			process_psqlrc();
		if (!pset.notty)
			initializeInput(options.no_readline ? 0 : 1);
296
		if (options.action_string)		/* -f - was used */
297
			pset.inputfile = "<stdin>";
P
Peter Eisentraut 已提交
298
		successResult = MainLoop(stdin);
299
	}
B
Bruce Momjian 已提交
300 301

	/* clean up */
302 303
	PQfinish(pset.db);
	setQFout(NULL);
B
Bruce Momjian 已提交
304 305

	return successResult;
306 307 308 309 310 311 312 313 314 315
}



/*
 * Parse command line options
 */

#ifdef WIN32
/* getopt is not in the standard includes on Win32 */
B
Bruce Momjian 已提交
316
int			getopt(int, char *const[], const char *);
317

B
Hi!  
Bruce Momjian 已提交
318
/* And it requires progname to be set */
319
char	   *__progname = "psql";
320 321 322
#endif

static void
323
parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
324 325
{
#ifdef HAVE_GETOPT_LONG
326
	static struct option long_options[] =
327 328
	{
		{"echo-all", no_argument, NULL, 'a'},
B
Bruce Momjian 已提交
329 330 331
		{"no-align", no_argument, NULL, 'A'},
		{"command", required_argument, NULL, 'c'},
		{"dbname", required_argument, NULL, 'd'},
332
		{"echo-queries", no_argument, NULL, 'e'},
333
		{"echo-hidden", no_argument, NULL, 'E'},
B
Bruce Momjian 已提交
334
		{"file", required_argument, NULL, 'f'},
335
		{"field-separator", required_argument, NULL, 'F'},
B
Bruce Momjian 已提交
336 337 338
		{"host", required_argument, NULL, 'h'},
		{"html", no_argument, NULL, 'H'},
		{"list", no_argument, NULL, 'l'},
339
		{"no-readline", no_argument, NULL, 'n'},
340
		{"output", required_argument, NULL, 'o'},
B
Bruce Momjian 已提交
341 342 343
		{"port", required_argument, NULL, 'p'},
		{"pset", required_argument, NULL, 'P'},
		{"quiet", no_argument, NULL, 'q'},
344
		{"record-separator", required_argument, NULL, 'R'},
B
Bruce Momjian 已提交
345 346 347 348 349 350 351 352 353
		{"single-step", no_argument, NULL, 's'},
		{"single-line", no_argument, NULL, 'S'},
		{"tuples-only", no_argument, NULL, 't'},
		{"table-attr", required_argument, NULL, 'T'},
		{"username", required_argument, NULL, 'U'},
		{"set", required_argument, NULL, 'v'},
		{"variable", required_argument, NULL, 'v'},
		{"version", no_argument, NULL, 'V'},
		{"password", no_argument, NULL, 'W'},
354
		{"expanded", no_argument, NULL, 'x'},
355
		{"no-psqlrc", no_argument, NULL, 'X'},
B
Bruce Momjian 已提交
356
		{"help", no_argument, NULL, '?'},
T
Tatsuo Ishii 已提交
357
		{NULL, 0, NULL, 0}
B
Bruce Momjian 已提交
358 359 360
	};

	int			optindex;
361
#endif   /* HAVE_GETOPT_LONG */
362

B
Bruce Momjian 已提交
363 364 365
	extern char *optarg;
	extern int	optind;
	int			c;
366
	bool		used_old_u_option = false;
367

368
	memset(options, 0, sizeof *options);
369 370

#ifdef HAVE_GETOPT_LONG
371
	while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1)
372 373
#else							/* not HAVE_GETOPT_LONG */

B
Bruce Momjian 已提交
374 375 376 377
	/*
	 * Be sure to leave the '-' in here, so we can catch accidental long
	 * options.
	 */
378
	while ((c = getopt(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1)
379
#endif   /* not HAVE_GETOPT_LONG */
380
	{
B
Bruce Momjian 已提交
381 382
		switch (c)
		{
383 384 385
			case 'a':
				SetVariable(pset.vars, "ECHO", "all");
				break;
B
Bruce Momjian 已提交
386
			case 'A':
387
				pset.popt.topt.format = PRINT_UNALIGNED;
B
Bruce Momjian 已提交
388 389 390 391
				break;
			case 'c':
				options->action_string = optarg;
				if (optarg[0] == '\\')
P
Peter Eisentraut 已提交
392
				{
B
Bruce Momjian 已提交
393
					options->action = ACT_SINGLE_SLASH;
P
Peter Eisentraut 已提交
394 395
					options->action_string++;
				}
B
Bruce Momjian 已提交
396 397 398 399 400 401 402
				else
					options->action = ACT_SINGLE_QUERY;
				break;
			case 'd':
				options->dbname = optarg;
				break;
			case 'e':
403
				SetVariable(pset.vars, "ECHO", "queries");
B
Bruce Momjian 已提交
404 405
				break;
			case 'E':
406
				SetVariableBool(pset.vars, "ECHO_HIDDEN");
B
Bruce Momjian 已提交
407 408 409 410 411 412
				break;
			case 'f':
				options->action = ACT_FILE;
				options->action_string = optarg;
				break;
			case 'F':
413
				pset.popt.topt.fieldSep = xstrdup(optarg);
B
Bruce Momjian 已提交
414 415 416 417 418
				break;
			case 'h':
				options->host = optarg;
				break;
			case 'H':
419
				pset.popt.topt.format = PRINT_HTML;
B
Bruce Momjian 已提交
420 421 422 423 424 425 426 427
				break;
			case 'l':
				options->action = ACT_LIST_DB;
				break;
			case 'n':
				options->no_readline = true;
				break;
			case 'o':
428
				setQFout(optarg);
B
Bruce Momjian 已提交
429 430 431 432 433 434 435 436 437 438 439 440 441
				break;
			case 'p':
				options->port = optarg;
				break;
			case 'P':
				{
					char	   *value;
					char	   *equal_loc;
					bool		result;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
442
						result = do_pset(value, NULL, &pset.popt, true);
B
Bruce Momjian 已提交
443 444 445
					else
					{
						*equal_loc = '\0';
446
						result = do_pset(value, equal_loc + 1, &pset.popt, true);
B
Bruce Momjian 已提交
447 448 449 450
					}

					if (!result)
					{
P
Peter Eisentraut 已提交
451
						fprintf(stderr, gettext("%s: couldn't set printing parameter %s\n"), pset.progname, value);
B
Bruce Momjian 已提交
452 453 454 455 456 457 458
						exit(EXIT_FAILURE);
					}

					free(value);
					break;
				}
			case 'q':
459
				SetVariableBool(pset.vars, "QUIET");
B
Bruce Momjian 已提交
460
				break;
461 462 463
			case 'R':
				pset.popt.topt.recordSep = xstrdup(optarg);
				break;
B
Bruce Momjian 已提交
464
			case 's':
465
				SetVariableBool(pset.vars, "SINGLESTEP");
B
Bruce Momjian 已提交
466 467
				break;
			case 'S':
468
				SetVariableBool(pset.vars, "SINGLELINE");
B
Bruce Momjian 已提交
469 470
				break;
			case 't':
471
				pset.popt.topt.tuples_only = true;
B
Bruce Momjian 已提交
472 473
				break;
			case 'T':
474
				pset.popt.topt.tableAttr = xstrdup(optarg);
B
Bruce Momjian 已提交
475 476
				break;
			case 'u':
477
				pset.getPassword = true;
478 479 480 481
				options->username = "\001";		/* hopefully nobody has
												 * that username */
				/* this option is out */
				used_old_u_option = true;
B
Bruce Momjian 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494
				break;
			case 'U':
				options->username = optarg;
				break;
			case 'v':
				{
					char	   *value;
					char	   *equal_loc;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
					{
495
						if (!DeleteVariable(pset.vars, value))
B
Bruce Momjian 已提交
496
						{
P
Peter Eisentraut 已提交
497
							fprintf(stderr, gettext("%s: could not delete variable %s\n"),
498
									pset.progname, value);
B
Bruce Momjian 已提交
499 500 501 502 503 504
							exit(EXIT_FAILURE);
						}
					}
					else
					{
						*equal_loc = '\0';
505
						if (!SetVariable(pset.vars, value, equal_loc + 1))
B
Bruce Momjian 已提交
506
						{
P
Peter Eisentraut 已提交
507
							fprintf(stderr, gettext("%s: could not set variable %s\n"),
508
									pset.progname, value);
B
Bruce Momjian 已提交
509 510 511 512 513 514 515 516
							exit(EXIT_FAILURE);
						}
					}

					free(value);
					break;
				}
			case 'V':
517 518
				showVersion();
				exit(EXIT_SUCCESS);
B
Bruce Momjian 已提交
519
			case 'W':
520
				pset.getPassword = true;
B
Bruce Momjian 已提交
521
				break;
522 523 524
			case 'x':
				pset.popt.topt.expanded = true;
				break;
525 526 527
			case 'X':
				options->no_psqlrc = true;
				break;
B
Bruce Momjian 已提交
528
			case '?':
529 530 531 532 533 534 535 536 537
				/* Actual help option given */
				if (strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0)
				{
					usage();
					exit(EXIT_SUCCESS);
				}
				/* unknown option reported by getopt */
				else
				{
P
Peter Eisentraut 已提交
538
					fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
539
							pset.progname);
540
					exit(EXIT_FAILURE);
541
				}
B
Bruce Momjian 已提交
542
				break;
543
#ifndef HAVE_GETOPT_LONG
544
			/* FreeBSD has a broken getopt that causes this test to fail. */
B
Bruce Momjian 已提交
545
			case '-':
P
Peter Eisentraut 已提交
546 547
				fprintf(stderr,
						gettext("%s was compiled without support for long options.\n"
548
						 "Use --help for help on invocation options.\n"),
P
Peter Eisentraut 已提交
549
						pset.progname);
B
Bruce Momjian 已提交
550 551
				exit(EXIT_FAILURE);
				break;
552
#endif
B
Bruce Momjian 已提交
553
			default:
P
Peter Eisentraut 已提交
554
				fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
555
						pset.progname);
556
				exit(EXIT_FAILURE);
B
Bruce Momjian 已提交
557 558
				break;
		}
559 560
	}

B
Bruce Momjian 已提交
561 562 563 564 565 566 567 568 569 570
	/*
	 * if we still have arguments, use it as the database name and
	 * username
	 */
	while (argc - optind >= 1)
	{
		if (!options->dbname)
			options->dbname = argv[optind];
		else if (!options->username)
			options->username = argv[optind];
571
		else if (!QUIET())
P
Peter Eisentraut 已提交
572
			fprintf(stderr, gettext("%s: warning: extra option %s ignored\n"),
573
					pset.progname, argv[optind]);
B
Bruce Momjian 已提交
574 575 576

		optind++;
	}
577

578
	if (used_old_u_option && !QUIET())
P
Peter Eisentraut 已提交
579
		fprintf(stderr, gettext("%s: Warning: The -u option is deprecated. Use -U.\n"), pset.progname);
580

581 582 583 584 585
}



/*
P
Peter Eisentraut 已提交
586
 * Load .psqlrc file, if found.
587 588
 */
static void
589
process_psqlrc(void)
590
{
B
Bruce Momjian 已提交
591 592
	char	   *psqlrc;
	char	   *home;
593 594 595 596 597

#ifdef WIN32
#define R_OK 0
#endif

B
Bruce Momjian 已提交
598 599
	/* Look for one in the home dir */
	home = getenv("HOME");
600

B
Bruce Momjian 已提交
601 602
	if (home)
	{
603
		psqlrc = malloc(strlen(home) + 20);
B
Bruce Momjian 已提交
604 605
		if (!psqlrc)
		{
P
Peter Eisentraut 已提交
606
			fprintf(stderr, gettext("%s: out of memory\n"), pset.progname);
B
Bruce Momjian 已提交
607 608
			exit(EXIT_FAILURE);
		}
609

610
		sprintf(psqlrc, "%s/.psqlrc-" PG_VERSION, home);
B
Bruce Momjian 已提交
611
		if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
612
			process_file(psqlrc);
B
Bruce Momjian 已提交
613 614 615 616
		else
		{
			sprintf(psqlrc, "%s/.psqlrc", home);
			if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
617
				process_file(psqlrc);
B
Bruce Momjian 已提交
618 619
		}
		free(psqlrc);
620 621 622 623 624 625 626
	}
}



/* showVersion
 *
627
 * This output format is intended to match GNU standards.
628 629
 */
static void
630
showVersion(void)
631
{
632
	puts("psql (PostgreSQL) " PG_VERSION);
633

634 635
#if defined(USE_READLINE)
	puts(gettext("contains support for readline"));
636
#endif
637

B
Bruce Momjian 已提交
638
	puts(gettext("Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group\n"
P
Peter Eisentraut 已提交
639
				 "Portions Copyright (c) 1996, Regents of the University of California\n"
640
	"Read the file COPYRIGHT or use the command \\copyright to see the\n"
P
Peter Eisentraut 已提交
641
				 "usage and distribution terms."));
642
}
B
Bruce Momjian 已提交
643 644 645 646 647 648 649 650 651



/*
 * printSSLInfo
 *
 * Prints information about the current SSL connection, if SSL is in use
 */
#ifdef USE_SSL
B
Bruce Momjian 已提交
652
static void
B
Bruce Momjian 已提交
653 654
printSSLInfo(void)
{
B
Bruce Momjian 已提交
655 656
	int			sslbits = -1;
	SSL		   *ssl;
B
Bruce Momjian 已提交
657 658 659

	ssl = PQgetssl(pset.db);
	if (!ssl)
B
Bruce Momjian 已提交
660
		return;					/* no SSL */
B
Bruce Momjian 已提交
661 662

	SSL_get_cipher_bits(ssl, &sslbits);
663
	printf(gettext("SSL connection (cipher: %s, bits: %i)\n\n"),
B
Bruce Momjian 已提交
664
		   SSL_get_cipher(ssl), sslbits);
B
Bruce Momjian 已提交
665
}
666

B
Bruce Momjian 已提交
667
#endif