28 main(
int argc,
char *argv[])
30 static struct option long_options[] = {
65 const char *newuser = NULL;
75 bool interactive =
false;
78 char *newpassword = NULL;
79 char *pwexpiry = NULL;
101 while ((
c =
getopt_long(argc, argv,
"a:c:dDeEg:h:iIlLm:p:PrRsSU:v:wW",
102 long_options, &optindex)) != -1)
111 -1, INT_MAX, &conn_limit))
207 pg_log_error(
"too many command-line arguments (first is \"%s\")",
217 newuser =
simple_prompt(
"Enter name of role to add: ",
true);
221 if (getenv(
"PGUSER"))
222 newuser = getenv(
"PGUSER");
232 newpassword =
simple_prompt(
"Enter password for new role: ",
false);
234 if (strcmp(newpassword, pw2) != 0)
236 fprintf(stderr,
_(
"Passwords didn't match.\n"));
244 if (interactive &&
yesno_prompt(
"Shall the new role be a superuser?"))
259 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create databases?"))
267 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create more new roles?"))
293 char *encrypted_password;
301 if (!encrypted_password)
302 pg_fatal(
"password encryption failed: %s",
329 if (replication ==
TRI_NO)
335 if (conn_limit >= -1)
337 if (pwexpiry != NULL)
342 if (roles.
head != NULL)
348 for (cell = roles.
head; cell; cell = cell->
next)
356 if (members.
head != NULL)
362 for (cell = members.
head; cell; cell = cell->
next)
370 if (admins.
head != NULL)
376 for (cell = admins.
head; cell; cell = cell->
next)
411 printf(
_(
" -a, --admin=ROLE this role will be a member of new role with admin\n"
413 printf(
_(
" -c, --connection-limit=N connection limit for role (default: no limit)\n"));
414 printf(
_(
" -d, --createdb role can create new databases\n"));
415 printf(
_(
" -D, --no-createdb role cannot create databases (default)\n"));
416 printf(
_(
" -e, --echo show the commands being sent to the server\n"));
417 printf(
_(
" -g, --role=ROLE new role will be a member of this role\n"));
418 printf(
_(
" -i, --inherit role inherits privileges of roles it is a\n"
419 " member of (default)\n"));
420 printf(
_(
" -I, --no-inherit role does not inherit privileges\n"));
421 printf(
_(
" -l, --login role can login (default)\n"));
422 printf(
_(
" -L, --no-login role cannot login\n"));
423 printf(
_(
" -m, --member=ROLE this role will be a member of new role\n"));
424 printf(
_(
" -P, --pwprompt assign a password to new role\n"));
425 printf(
_(
" -r, --createrole role can create new roles\n"));
426 printf(
_(
" -R, --no-createrole role cannot create roles (default)\n"));
427 printf(
_(
" -s, --superuser role will be superuser\n"));
428 printf(
_(
" -S, --no-superuser role will not be superuser (default)\n"));
429 printf(
_(
" -v, --valid-until=TIMESTAMP\n"
430 " password expiration date for role\n"));
431 printf(
_(
" -V, --version output version information, then exit\n"));
432 printf(
_(
" --interactive prompt for missing role name and attributes rather\n"
433 " than using defaults\n"));
434 printf(
_(
" --bypassrls role can bypass row-level security (RLS) policy\n"));
435 printf(
_(
" --no-bypassrls role cannot bypass row-level security (RLS) policy\n"));
436 printf(
_(
" --replication role can initiate replication\n"));
437 printf(
_(
" --no-replication role cannot initiate replication\n"));
438 printf(
_(
" -?, --help show this help, then exit\n"));
439 printf(
_(
"\nConnection options:\n"));
440 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
441 printf(
_(
" -p, --port=PORT database server port\n"));
442 printf(
_(
" -U, --username=USERNAME user name to connect as (not the one to create)\n"));
443 printf(
_(
" -w, --no-password never prompt for password\n"));
444 printf(
_(
" -W, --password force password prompt\n"));
445 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
446 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)