25 main(
int argc,
char *argv[])
27 static struct option long_options[] = {
57 const char *newuser = NULL;
65 bool interactive =
false;
68 char *newpassword = NULL;
89 while ((c =
getopt_long(argc, argv,
"h:p:U:g:wWedDsSrRiIlLc:PE",
90 long_options, &optindex)) != -1)
148 conn_limit = strtol(
optarg, &endptr, 10);
149 if (*endptr !=
'\0' || conn_limit < -1)
151 pg_log_error(
"invalid value for --connection-limit: %s",
172 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"), progname);
185 pg_log_error(
"too many command-line arguments (first is \"%s\")",
187 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"), progname);
195 newuser =
simple_prompt(
"Enter name of role to add: ",
true);
199 if (getenv(
"PGUSER"))
200 newuser = getenv(
"PGUSER");
210 newpassword =
simple_prompt(
"Enter password for new role: ",
false);
212 if (strcmp(newpassword, pw2) != 0)
214 fprintf(stderr,
_(
"Passwords didn't match.\n"));
222 if (interactive &&
yesno_prompt(
"Shall the new role be a superuser?"))
237 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create databases?"))
245 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create more new roles?"))
271 char *encrypted_password;
279 if (!encrypted_password)
310 if (replication ==
TRI_NO)
312 if (conn_limit >= -1)
314 if (roles.
head != NULL)
320 for (cell = roles.
head; cell; cell = cell->
next)
350 printf(
_(
"%s creates a new PostgreSQL role.\n\n"), progname);
352 printf(
_(
" %s [OPTION]... [ROLENAME]\n"), progname);
354 printf(
_(
" -c, --connection-limit=N connection limit for role (default: no limit)\n"));
355 printf(
_(
" -d, --createdb role can create new databases\n"));
356 printf(
_(
" -D, --no-createdb role cannot create databases (default)\n"));
357 printf(
_(
" -e, --echo show the commands being sent to the server\n"));
358 printf(
_(
" -g, --role=ROLE new role will be a member of this role\n"));
359 printf(
_(
" -i, --inherit role inherits privileges of roles it is a\n" 360 " member of (default)\n"));
361 printf(
_(
" -I, --no-inherit role does not inherit privileges\n"));
362 printf(
_(
" -l, --login role can login (default)\n"));
363 printf(
_(
" -L, --no-login role cannot login\n"));
364 printf(
_(
" -P, --pwprompt assign a password to new role\n"));
365 printf(
_(
" -r, --createrole role can create new roles\n"));
366 printf(
_(
" -R, --no-createrole role cannot create roles (default)\n"));
367 printf(
_(
" -s, --superuser role will be superuser\n"));
368 printf(
_(
" -S, --no-superuser role will not be superuser (default)\n"));
369 printf(
_(
" -V, --version output version information, then exit\n"));
370 printf(
_(
" --interactive prompt for missing role name and attributes rather\n" 371 " than using defaults\n"));
372 printf(
_(
" --replication role can initiate replication\n"));
373 printf(
_(
" --no-replication role cannot initiate replication\n"));
374 printf(
_(
" -?, --help show this help, then exit\n"));
375 printf(
_(
"\nConnection options:\n"));
376 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
377 printf(
_(
" -p, --port=PORT database server port\n"));
378 printf(
_(
" -U, --username=USERNAME user name to connect as (not the one to create)\n"));
379 printf(
_(
" -w, --no-password never prompt for password\n"));
380 printf(
_(
" -W, --password force password prompt\n"));
381 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
382 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
char * PQerrorMessage(const PGconn *conn)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
bool yesno_prompt(const char *question)
const char * fmtId(const char *rawid)
const char * get_progname(const char *argv0)
#define pg_log_error(...)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void pg_logging_init(const char *argv0)
void PQfinish(PGconn *conn)
char * simple_prompt(const char *prompt, bool echo)
ExecStatusType PQresultStatus(const PGresult *res)
#define required_argument
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
struct SimpleStringListCell * next
char * pg_strdup(const char *in)
int main(int argc, char *argv[])
enum trivalue prompt_password
#define PG_TEXTDOMAIN(domain)
void simple_string_list_append(SimpleStringList *list, const char *val)
PGconn * connectMaintenanceDatabase(ConnParams *cparams, const char *progname, bool echo)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void PQclear(PGresult *res)
SimpleStringListCell * head
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
void set_pglocale_pgservice(const char *argv0, const char *app)
char val[FLEXIBLE_ARRAY_MEMBER]
PGresult * PQexec(PGconn *conn, const char *query)
static void help(const char *progname)
void PQfreemem(void *ptr)
void initPQExpBuffer(PQExpBuffer str)
const char * get_user_name_or_exit(const char *progname)