28 main(
int argc,
char *argv[])
30 static struct option long_options[] = {
66 const char *newuser = NULL;
76 bool interactive =
false;
79 char *newpassword = NULL;
80 char *pwexpiry = NULL;
102 while ((
c =
getopt_long(argc, argv,
"a:c:dDeEg:h:iIlLm:p:PrRsSU:v:wW",
103 long_options, &optindex)) != -1)
112 -1, INT_MAX, &conn_limit))
208 pg_log_error(
"too many command-line arguments (first is \"%s\")",
218 newuser =
simple_prompt(
"Enter name of role to add: ",
true);
222 if (getenv(
"PGUSER"))
223 newuser = getenv(
"PGUSER");
233 newpassword =
simple_prompt(
"Enter password for new role: ",
false);
235 if (strcmp(newpassword, pw2) != 0)
237 fprintf(stderr,
_(
"Passwords didn't match.\n"));
245 if (interactive &&
yesno_prompt(
"Shall the new role be a superuser?"))
260 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create databases?"))
268 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create more new roles?"))
300 char *encrypted_password;
308 if (!encrypted_password)
309 pg_fatal(
"password encryption failed: %s",
336 if (replication ==
TRI_NO)
342 if (conn_limit >= -1)
344 if (pwexpiry != NULL)
349 if (roles.
head != NULL)
355 for (cell = roles.
head; cell; cell = cell->
next)
363 if (members.
head != NULL)
369 for (cell = members.
head; cell; cell = cell->
next)
377 if (admins.
head != NULL)
383 for (cell = admins.
head; cell; cell = cell->
next)
418 printf(
_(
" -a, --with-admin=ROLE ROLE will be a member of new role with admin\n"
420 printf(
_(
" -c, --connection-limit=N connection limit for role (default: no limit)\n"));
421 printf(
_(
" -d, --createdb role can create new databases\n"));
422 printf(
_(
" -D, --no-createdb role cannot create databases (default)\n"));
423 printf(
_(
" -e, --echo show the commands being sent to the server\n"));
424 printf(
_(
" -g, --member-of=ROLE new role will be a member of ROLE\n"));
425 printf(
_(
" --role=ROLE (same as --member-of, deprecated)\n"));
426 printf(
_(
" -i, --inherit role inherits privileges of roles it is a\n"
427 " member of (default)\n"));
428 printf(
_(
" -I, --no-inherit role does not inherit privileges\n"));
429 printf(
_(
" -l, --login role can login (default)\n"));
430 printf(
_(
" -L, --no-login role cannot login\n"));
431 printf(
_(
" -m, --with-member=ROLE ROLE will be a member of new role\n"));
432 printf(
_(
" -P, --pwprompt assign a password to new role\n"));
433 printf(
_(
" -r, --createrole role can create new roles\n"));
434 printf(
_(
" -R, --no-createrole role cannot create roles (default)\n"));
435 printf(
_(
" -s, --superuser role will be superuser\n"));
436 printf(
_(
" -S, --no-superuser role will not be superuser (default)\n"));
437 printf(
_(
" -v, --valid-until=TIMESTAMP\n"
438 " password expiration date and time for role\n"));
439 printf(
_(
" -V, --version output version information, then exit\n"));
440 printf(
_(
" --interactive prompt for missing role name and attributes rather\n"
441 " than using defaults\n"));
442 printf(
_(
" --bypassrls role can bypass row-level security (RLS) policy\n"));
443 printf(
_(
" --no-bypassrls role cannot bypass row-level security (RLS) policy\n"
445 printf(
_(
" --replication role can initiate replication\n"));
446 printf(
_(
" --no-replication role cannot initiate replication (default)\n"));
447 printf(
_(
" -?, --help show this help, then exit\n"));
448 printf(
_(
"\nConnection options:\n"));
449 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
450 printf(
_(
" -p, --port=PORT database server port\n"));
451 printf(
_(
" -U, --username=USERNAME user name to connect as (not the one to create)\n"));
452 printf(
_(
" -w, --no-password never prompt for password\n"));
453 printf(
_(
" -W, --password force password prompt\n"));
454 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
455 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
bool yesno_prompt(const char *question)
#define PG_TEXTDOMAIN(domain)
void set_pglocale_pgservice(const char *argv0, const char *app)
PGconn * connectMaintenanceDatabase(ConnParams *cparams, const char *progname, bool echo)
int main(int argc, char *argv[])
static void help(const char *progname)
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
char * PQerrorMessage(const PGconn *conn)
void PQfinish(PGconn *conn)
void PQfreemem(void *ptr)
ExecStatusType PQresultStatus(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
char * pg_strdup(const char *in)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
bool option_parse_int(const char *optarg, const char *optname, int min_range, int max_range, int *result)
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
PGDLLIMPORT char * optarg
const char * get_progname(const char *argv0)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void simple_string_list_append(SimpleStringList *list, const char *val)
char * simple_prompt(const char *prompt, bool echo)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
const char * fmtId(const char *rawid)
char val[FLEXIBLE_ARRAY_MEMBER]
struct SimpleStringListCell * next
SimpleStringListCell * head
enum trivalue prompt_password
const char * get_user_name_or_exit(const char *progname)