29{
30 static struct option long_options[] = {
60 {NULL, 0, NULL, 0}
61 };
62
64 int optindex;
66 const char *newuser = NULL;
67 char *host = NULL;
75 bool echo = false;
76 bool interactive = false;
77 int conn_limit = -2;
79 char *newpassword = NULL;
80 char *pwexpiry = NULL;
81
82
90
92
95
99
101
102 while ((
c =
getopt_long(argc, argv,
"a:c:dDeEg:h:iIlLm:p:PrRsSU:v:wW",
103 long_options, &optindex)) != -1)
104 {
106 {
107 case 'a':
109 break;
110 case 'c':
112 -1, INT_MAX, &conn_limit))
114 break;
115 case 'd':
117 break;
118 case 'D':
120 break;
121 case 'e':
122 echo = true;
123 break;
124 case 'E':
125
126 break;
127 case 'g':
129 break;
130 case 'h':
132 break;
133 case 'i':
135 break;
136 case 'I':
138 break;
139 case 'l':
141 break;
142 case 'L':
144 break;
145 case 'm':
147 break;
148 case 'p':
150 break;
151 case 'P':
153 break;
154 case 'r':
156 break;
157 case 'R':
159 break;
160 case 's':
162 break;
163 case 'S':
165 break;
166 case 'U':
168 break;
169 case 'v':
171 break;
172 case 'w':
174 break;
175 case 'W':
177 break;
178 case 1:
180 break;
181 case 2:
183 break;
184 case 3:
185 interactive = true;
186 break;
187 case 4:
189 break;
190 case 5:
192 break;
193 default:
194
197 }
198 }
199
201 {
202 case 0:
203 break;
204 case 1:
206 break;
207 default:
208 pg_log_error(
"too many command-line arguments (first is \"%s\")",
212 }
213
214 if (newuser == NULL)
215 {
216 if (interactive)
217 {
218 newuser =
simple_prompt(
"Enter name of role to add: ",
true);
219 }
220 else
221 {
222 if (getenv("PGUSER"))
223 newuser = getenv("PGUSER");
224 else
226 }
227 }
228
230 {
231 char *pw2;
232
233 newpassword =
simple_prompt(
"Enter password for new role: ",
false);
235 if (strcmp(newpassword, pw2) != 0)
236 {
237 fprintf(stderr,
_(
"Passwords didn't match.\n"));
239 }
241 }
242
244 {
245 if (interactive &&
yesno_prompt(
"Shall the new role be a superuser?"))
247 else
249 }
250
252 {
253
256 }
257
259 {
260 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create databases?"))
262 else
264 }
265
267 {
268 if (interactive &&
yesno_prompt(
"Shall the new role be allowed to create more new roles?"))
270 else
272 }
273
276
279
282
285
292
294
296
298 if (newpassword)
299 {
300 char *encrypted_password;
301
303
305 newpassword,
306 newuser,
307 NULL);
308 if (!encrypted_password)
309 pg_fatal(
"password encryption failed: %s",
313 }
336 if (replication ==
TRI_NO)
342 if (conn_limit >= -1)
344 if (pwexpiry != NULL)
345 {
348 }
349 if (roles.
head != NULL)
350 {
352
354
355 for (cell = roles.
head; cell; cell = cell->
next)
356 {
359 else
361 }
362 }
363 if (members.
head != NULL)
364 {
366
368
369 for (cell = members.
head; cell; cell = cell->
next)
370 {
373 else
375 }
376 }
377 if (admins.
head != NULL)
378 {
380
382
383 for (cell = admins.
head; cell; cell = cell->
next)
384 {
387 else
389 }
390 }
391
393
394 if (echo)
397
399 {
403 }
404
408}
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)
static void help(const char *progname)
#define fprintf(file, fmt, msg)
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
void PQfinish(PGconn *conn)
char * PQerrorMessage(const 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)
const char * fmtId(const char *rawid)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
char val[FLEXIBLE_ARRAY_MEMBER]
struct SimpleStringListCell * next
SimpleStringListCell * head
enum trivalue prompt_password
const char * get_user_name_or_exit(const char *progname)