Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
8ae0d476
Commit
8ae0d476
authored
Aug 14, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the createuser utility for the ROLEs world. Alvaro Herrera
parent
e36de181
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
243 additions
and
108 deletions
+243
-108
doc/src/sgml/ref/createuser.sgml
doc/src/sgml/ref/createuser.sgml
+124
-60
src/bin/scripts/createuser.c
src/bin/scripts/createuser.c
+119
-48
No files found.
doc/src/sgml/ref/createuser.sgml
View file @
8ae0d476
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/createuser.sgml,v 1.4
1 2005/05/29 03:32:18 momjian
Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/createuser.sgml,v 1.4
2 2005/08/14 20:16:02 tgl
Exp $
PostgreSQL documentation
PostgreSQL documentation
-->
-->
...
@@ -32,24 +32,24 @@ PostgreSQL documentation
...
@@ -32,24 +32,24 @@ PostgreSQL documentation
<title>Description</title>
<title>Description</title>
<para>
<para>
<application>createuser</application> creates a
<application>createuser</application> creates a
new <productname>PostgreSQL</productname> user.
new <productname>PostgreSQL</productname> user (or more precisely, a role).
Only superusers (users with <literal>usesuper</literal> set in
Only superusers and users with <literal>CREATEROLE</> privilege can create
the <literal>pg_shadow</literal> table) can create
new users, so <application>createuser</application> must be
new <productname>PostgreSQL</productname> users,
invoked by someone who can connect as a superuser or a user with
so <application>createuser</application> must be
<literal>CREATEROLE</> privilege.
invoked by someone who can connect as a <productname>PostgreSQL</productname>
superuser.
</para>
</para>
<para>
<para>
Being a superuser also implies the ability to bypass access permission
If you wish to create a new superuser, you must connect as a
superuser, not merely with <literal>CREATEROLE</> privilege.
Being a superuser implies the ability to bypass all access permission
checks within the database, so superuserdom should not be granted lightly.
checks within the database, so superuserdom should not be granted lightly.
</para>
</para>
<para>
<para>
<application>createuser</application> is a wrapper around the
<application>createuser</application> is a wrapper around the
<acronym>SQL</acronym> command <xref linkend="SQL-CREATE
USER
"
<acronym>SQL</acronym> command <xref linkend="SQL-CREATE
ROLE
"
endterm="SQL-CREATE
USER
-title">.
endterm="SQL-CREATE
ROLE
-title">.
There is no effective difference between creating users via
There is no effective difference between creating users via
this utility and via other methods for accessing the server.
this utility and via other methods for accessing the server.
</para>
</para>
...
@@ -70,32 +70,28 @@ PostgreSQL documentation
...
@@ -70,32 +70,28 @@ PostgreSQL documentation
<para>
<para>
Specifies the name of the <productname>PostgreSQL</productname> user
Specifies the name of the <productname>PostgreSQL</productname> user
to be created.
to be created.
This name must be
unique among all users of
this
This name must be
different from all existing roles in
this
<productname>PostgreSQL</productname> installation.
<productname>PostgreSQL</productname> installation.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
a
</></term>
<term><option>-
s
</></term>
<term><option>--
add
user</></term>
<term><option>--
super
user</></term>
<listitem>
<listitem>
<para>
<para>
The new user is allowed to create other users.
The new user will be a superuser.
(Note: Actually, this makes the new user a <emphasis>superuser</>.
The option is poorly named.)
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
A
</></term>
<term><option>-
S
</></term>
<term><option>--no-
add
user</></term>
<term><option>--no-
super
user</></term>
<listitem>
<listitem>
<para>
<para>
The new user is not allowed to create other users (i.e.,
The new user will not be a superuser.
the new user is a regular user, not a superuser).
This is the default.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -105,7 +101,7 @@ PostgreSQL documentation
...
@@ -105,7 +101,7 @@ PostgreSQL documentation
<term><option>--createdb</></term>
<term><option>--createdb</></term>
<listitem>
<listitem>
<para>
<para>
The new user is
allowed to create databases.
The new user will be
allowed to create databases.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -115,52 +111,86 @@ PostgreSQL documentation
...
@@ -115,52 +111,86 @@ PostgreSQL documentation
<term><option>--no-createdb</></term>
<term><option>--no-createdb</></term>
<listitem>
<listitem>
<para>
<para>
The new user is not allowed to create databases.
The new user will not be allowed to create databases.
This is the default.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
e
</></term>
<term><option>-
r
</></term>
<term><option>--
echo
</></term>
<term><option>--
createrole
</></term>
<listitem>
<listitem>
<para>
<para>
Echo the commands that <application>createuser</application> generates
The new user will be allowed to create new roles (that is,
and sends to the server
.
this user will have <literal>CREATEROLE</> privilege)
.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
E
</></term>
<term><option>-
R
</></term>
<term><option>--
encrypted
</></term>
<term><option>--
no-createrole
</></term>
<listitem>
<listitem>
<para>
<para>
Encrypts the user's password stored in the database. If not
The new user will not be allowed to create new roles.
specified, the default password behavior is used.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
i <replaceable class="parameter">number</replaceable>
</></term>
<term><option>-
l
</></term>
<term><option>--
sysid <replaceable class="parameter">number</replaceable>
</></term>
<term><option>--
login
</></term>
<listitem>
<listitem>
<para>
<para>
Allows you to pick a non-default user ID for the new user. This is not
The new user will be allowed to log in (that is, the user name
necessary, but some people like it.
can be used as the initial session user identifier).
This is the default.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-
N
</></term>
<term><option>-
L
</></term>
<term><option>--
unencrypted
</></term>
<term><option>--
no-login
</></term>
<listitem>
<listitem>
<para>
<para>
Does not encrypt the user's password stored in the database. If
The new user will not be allowed to log in.
not specified, the default password behavior is used.
(A role without login privilege is still useful as a means of
managing database permissions.)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-i</></term>
<term><option>--inherit</></term>
<listitem>
<para>
The new role will automatically inherit privileges of roles
it is a member of.
This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-I</></term>
<term><option>--no-inherit</></term>
<listitem>
<para>
The new role will not automatically inherit privileges of roles
it is a member of.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-c <replaceable class="parameter">number</replaceable></></term>
<term><option>--conn-limit <replaceable class="parameter">number</replaceable></></term>
<listitem>
<para>
Set a maximum number of connections for the new user.
The default is to set no limit.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -177,6 +207,39 @@ PostgreSQL documentation
...
@@ -177,6 +207,39 @@ PostgreSQL documentation
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><option>-E</></term>
<term><option>--encrypted</></term>
<listitem>
<para>
Encrypts the user's password stored in the database. If not
specified, the default password behavior is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-N</></term>
<term><option>--unencrypted</></term>
<listitem>
<para>
Does not encrypt the user's password stored in the database. If
not specified, the default password behavior is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-e</></term>
<term><option>--echo</></term>
<listitem>
<para>
Echo the commands that <application>createuser</application> generates
and sends to the server.
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry>
<term><option>-q</></term>
<term><option>-q</></term>
<term><option>--quiet</></term>
<term><option>--quiet</></term>
...
@@ -204,10 +267,10 @@ PostgreSQL documentation
...
@@ -204,10 +267,10 @@ PostgreSQL documentation
<term><option>--host <replaceable class="parameter">host</replaceable></></term>
<term><option>--host <replaceable class="parameter">host</replaceable></></term>
<listitem>
<listitem>
<para>
<para>
Specifies the host name of the machine on which the
Specifies the host name of the machine on which the
server
server
is running. If the value begins with a slash, it is used
is running. If the value begins with a slash, it is used
as the directory for the Unix domain socket.
as the directory for the Unix domain socket.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -217,9 +280,9 @@ PostgreSQL documentation
...
@@ -217,9 +280,9 @@ PostgreSQL documentation
<term><option>--port <replaceable class="parameter">port</replaceable></></term>
<term><option>--port <replaceable class="parameter">port</replaceable></></term>
<listitem>
<listitem>
<para>
<para>
Specifies the TCP port or local Unix domain socket file
Specifies the TCP port or local Unix domain socket file
extension on which the server
extension on which the server
is listening for connections.
is listening for connections.
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
...
@@ -272,8 +335,8 @@ PostgreSQL documentation
...
@@ -272,8 +335,8 @@ PostgreSQL documentation
<title>Diagnostics</title>
<title>Diagnostics</title>
<para>
<para>
In case of difficulty, see <xref linkend="SQL-CREATE
USER
"
In case of difficulty, see <xref linkend="SQL-CREATE
ROLE
"
endterm="sql-create
user
-title"> and <xref linkend="APP-PSQL"> for
endterm="sql-create
role
-title"> and <xref linkend="APP-PSQL"> for
discussions of potential problems and error messages.
discussions of potential problems and error messages.
The database server must be running at the
The database server must be running at the
targeted host. Also, any default connection settings and environment
targeted host. Also, any default connection settings and environment
...
@@ -292,8 +355,9 @@ PostgreSQL documentation
...
@@ -292,8 +355,9 @@ PostgreSQL documentation
server:
server:
<screen>
<screen>
<prompt>$ </prompt><userinput>createuser joe</userinput>
<prompt>$ </prompt><userinput>createuser joe</userinput>
<computeroutput>Shall the new user be allowed to create databases? (y/n) </computeroutput><userinput>n</userinput>
<computeroutput>Shall the new role be a superuser? (y/n) </computeroutput><userinput>n</userinput>
<computeroutput>Shall the new user be allowed to create more new users? (y/n) </computeroutput><userinput>n</userinput>
<computeroutput>Shall the new role be allowed to create databases? (y/n) </computeroutput><userinput>n</userinput>
<computeroutput>Shall the new role be allowed to create more new roles? (y/n) </computeroutput><userinput>n</userinput>
<computeroutput>CREATE USER</computeroutput>
<computeroutput>CREATE USER</computeroutput>
</screen>
</screen>
</para>
</para>
...
@@ -303,9 +367,9 @@ PostgreSQL documentation
...
@@ -303,9 +367,9 @@ PostgreSQL documentation
server on host <literal>eden</>, port 5000, avoiding the prompts and
server on host <literal>eden</>, port 5000, avoiding the prompts and
taking a look at the underlying command:
taking a look at the underlying command:
<screen>
<screen>
<prompt>$ </prompt><userinput>createuser -h eden -p 5000 -
D -A
-e joe</userinput>
<prompt>$ </prompt><userinput>createuser -h eden -p 5000 -
S -D -R
-e joe</userinput>
<computeroutput>CREATE
USER joe NOCREATEDB NOCREATEUSER
;</computeroutput>
<computeroutput>CREATE
ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN
;</computeroutput>
<computeroutput>CREATE
USER
</computeroutput>
<computeroutput>CREATE
ROLE
</computeroutput>
</screen>
</screen>
</para>
</para>
...
@@ -313,11 +377,11 @@ PostgreSQL documentation
...
@@ -313,11 +377,11 @@ PostgreSQL documentation
To create the user <literal>joe</literal> as a superuser,
To create the user <literal>joe</literal> as a superuser,
and assign a password immediately:
and assign a password immediately:
<screen>
<screen>
<prompt>$ </prompt><userinput>createuser -P -
d -a
-e joe</userinput>
<prompt>$ </prompt><userinput>createuser -P -
s
-e joe</userinput>
<computeroutput>Enter password for new
user
: </computeroutput><userinput>xyzzy</userinput>
<computeroutput>Enter password for new
role
: </computeroutput><userinput>xyzzy</userinput>
<computeroutput>Enter it again: </computeroutput><userinput>xyzzy</userinput>
<computeroutput>Enter it again: </computeroutput><userinput>xyzzy</userinput>
<computeroutput>CREATE
USER joe PASSWORD 'xyzzy' CREATEDB CREATEUSER
;</computeroutput>
<computeroutput>CREATE
ROLE joe PASSWORD 'xyzzy' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN
;</computeroutput>
<computeroutput>CREATE
USER
</computeroutput>
<computeroutput>CREATE
ROLE
</computeroutput>
</screen>
</screen>
In the above example, the new password isn't actually echoed when typed,
In the above example, the new password isn't actually echoed when typed,
but we show what was typed for clarity. However the password
but we show what was typed for clarity. However the password
...
@@ -333,7 +397,7 @@ PostgreSQL documentation
...
@@ -333,7 +397,7 @@ PostgreSQL documentation
<simplelist type="inline">
<simplelist type="inline">
<member><xref linkend="app-dropuser"></member>
<member><xref linkend="app-dropuser"></member>
<member><xref linkend="sql-create
user" endterm="sql-createuser
-title"></member>
<member><xref linkend="sql-create
role" endterm="sql-createrole
-title"></member>
<member>Environment Variables (<xref linkend="libpq-envars">)</member>
<member>Environment Variables (<xref linkend="libpq-envars">)</member>
</simplelist>
</simplelist>
</refsect1>
</refsect1>
...
...
src/bin/scripts/createuser.c
View file @
8ae0d476
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.1
7 2005/06/21 04:02:3
3 tgl Exp $
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.1
8 2005/08/14 20:16:0
3 tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -30,9 +30,18 @@ main(int argc, char *argv[])
...
@@ -30,9 +30,18 @@ main(int argc, char *argv[])
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
{
"quiet"
,
no_argument
,
NULL
,
'q'
},
{
"createdb"
,
no_argument
,
NULL
,
'd'
},
{
"createdb"
,
no_argument
,
NULL
,
'd'
},
{
"no-createdb"
,
no_argument
,
NULL
,
'D'
},
{
"no-createdb"
,
no_argument
,
NULL
,
'D'
},
{
"superuser"
,
no_argument
,
NULL
,
's'
},
{
"no-superuser"
,
no_argument
,
NULL
,
'S'
},
{
"createrole"
,
no_argument
,
NULL
,
'r'
},
{
"no-createrole"
,
no_argument
,
NULL
,
'R'
},
{
"inherit"
,
no_argument
,
NULL
,
'i'
},
{
"no-inherit"
,
no_argument
,
NULL
,
'I'
},
{
"login"
,
no_argument
,
NULL
,
'l'
},
{
"no-login"
,
no_argument
,
NULL
,
'L'
},
/* adduser is obsolete, undocumented spelling of superuser */
{
"adduser"
,
no_argument
,
NULL
,
'a'
},
{
"adduser"
,
no_argument
,
NULL
,
'a'
},
{
"no-adduser"
,
no_argument
,
NULL
,
'A'
},
{
"no-adduser"
,
no_argument
,
NULL
,
'A'
},
{
"
sysid"
,
required_argument
,
NULL
,
'i
'
},
{
"
conn-limit"
,
required_argument
,
NULL
,
'c
'
},
{
"pwprompt"
,
no_argument
,
NULL
,
'P'
},
{
"pwprompt"
,
no_argument
,
NULL
,
'P'
},
{
"encrypted"
,
no_argument
,
NULL
,
'E'
},
{
"encrypted"
,
no_argument
,
NULL
,
'E'
},
{
"unencrypted"
,
no_argument
,
NULL
,
'N'
},
{
"unencrypted"
,
no_argument
,
NULL
,
'N'
},
...
@@ -51,8 +60,11 @@ main(int argc, char *argv[])
...
@@ -51,8 +60,11 @@ main(int argc, char *argv[])
bool
echo
=
false
;
bool
echo
=
false
;
bool
quiet
=
false
;
bool
quiet
=
false
;
int
createdb
=
0
;
int
createdb
=
0
;
int
adduser
=
0
;
int
superuser
=
0
;
char
*
sysid
=
NULL
;
int
createrole
=
0
;
int
inherit
=
0
;
int
login
=
0
;
char
*
conn_limit
=
NULL
;
bool
pwprompt
=
false
;
bool
pwprompt
=
false
;
int
encrypted
=
0
;
/* 0 uses server default */
int
encrypted
=
0
;
/* 0 uses server default */
char
*
newpassword
=
NULL
;
char
*
newpassword
=
NULL
;
...
@@ -67,7 +79,8 @@ main(int argc, char *argv[])
...
@@ -67,7 +79,8 @@ main(int argc, char *argv[])
handle_help_version_opts
(
argc
,
argv
,
"createuser"
,
help
);
handle_help_version_opts
(
argc
,
argv
,
"createuser"
,
help
);
while
((
c
=
getopt_long
(
argc
,
argv
,
"h:p:U:WeqaAdDi:PEN"
,
long_options
,
&
optindex
))
!=
-
1
)
while
((
c
=
getopt_long
(
argc
,
argv
,
"h:p:U:WeqdDsSaArRiIlLc:PEN"
,
long_options
,
&
optindex
))
!=
-
1
)
{
{
switch
(
c
)
switch
(
c
)
{
{
...
@@ -89,20 +102,40 @@ main(int argc, char *argv[])
...
@@ -89,20 +102,40 @@ main(int argc, char *argv[])
case
'q'
:
case
'q'
:
quiet
=
true
;
quiet
=
true
;
break
;
break
;
case
'a'
:
adduser
=
+
1
;
break
;
case
'A'
:
adduser
=
-
1
;
break
;
case
'd'
:
case
'd'
:
createdb
=
+
1
;
createdb
=
+
1
;
break
;
break
;
case
'D'
:
case
'D'
:
createdb
=
-
1
;
createdb
=
-
1
;
break
;
break
;
case
's'
:
case
'a'
:
superuser
=
+
1
;
break
;
case
'S'
:
case
'A'
:
superuser
=
-
1
;
break
;
case
'r'
:
createrole
=
+
1
;
break
;
case
'R'
:
createrole
=
-
1
;
break
;
case
'i'
:
case
'i'
:
sysid
=
optarg
;
inherit
=
+
1
;
break
;
case
'I'
:
inherit
=
-
1
;
break
;
case
'l'
:
login
=
+
1
;
break
;
case
'L'
:
login
=
-
1
;
break
;
case
'c'
:
conn_limit
=
optarg
;
break
;
break
;
case
'P'
:
case
'P'
:
pwprompt
=
true
;
pwprompt
=
true
;
...
@@ -133,26 +166,15 @@ main(int argc, char *argv[])
...
@@ -133,26 +166,15 @@ main(int argc, char *argv[])
exit
(
1
);
exit
(
1
);
}
}
if
(
sysid
)
{
char
*
endptr
;
if
(
strtol
(
sysid
,
&
endptr
,
10
)
<=
0
||
*
endptr
!=
'\0'
)
{
fprintf
(
stderr
,
_
(
"%s: user ID must be a positive number
\n
"
),
progname
);
exit
(
1
);
}
}
if
(
newuser
==
NULL
)
if
(
newuser
==
NULL
)
newuser
=
simple_prompt
(
"Enter name of
user
to add: "
,
128
,
true
);
newuser
=
simple_prompt
(
"Enter name of
role
to add: "
,
128
,
true
);
if
(
pwprompt
)
if
(
pwprompt
)
{
{
char
*
pw1
,
char
*
pw1
,
*
pw2
;
*
pw2
;
pw1
=
simple_prompt
(
"Enter password for new
user
: "
,
100
,
false
);
pw1
=
simple_prompt
(
"Enter password for new
role
: "
,
100
,
false
);
pw2
=
simple_prompt
(
"Enter it again: "
,
100
,
false
);
pw2
=
simple_prompt
(
"Enter it again: "
,
100
,
false
);
if
(
strcmp
(
pw1
,
pw2
)
!=
0
)
if
(
strcmp
(
pw1
,
pw2
)
!=
0
)
{
{
...
@@ -163,33 +185,61 @@ main(int argc, char *argv[])
...
@@ -163,33 +185,61 @@ main(int argc, char *argv[])
free
(
pw2
);
free
(
pw2
);
}
}
if
(
superuser
==
0
)
{
char
*
reply
;
reply
=
simple_prompt
(
"Shall the new role be a superuser? (y/n) "
,
1
,
true
);
if
(
check_yesno_response
(
reply
)
==
1
)
superuser
=
+
1
;
else
superuser
=
-
1
;
}
if
(
superuser
==
+
1
)
{
/* Not much point in trying to restrict a superuser */
createdb
=
+
1
;
createrole
=
+
1
;
}
if
(
createdb
==
0
)
if
(
createdb
==
0
)
{
{
char
*
reply
;
char
*
reply
;
reply
=
simple_prompt
(
"Shall the new
user
be allowed to create databases? (y/n) "
,
1
,
true
);
reply
=
simple_prompt
(
"Shall the new
role
be allowed to create databases? (y/n) "
,
1
,
true
);
if
(
check_yesno_response
(
reply
)
==
1
)
if
(
check_yesno_response
(
reply
)
==
1
)
createdb
=
+
1
;
createdb
=
+
1
;
else
else
createdb
=
-
1
;
createdb
=
-
1
;
}
}
if
(
adduser
==
0
)
if
(
createrole
==
0
)
{
{
char
*
reply
;
char
*
reply
;
reply
=
simple_prompt
(
"Shall the new
user be allowed to create more new user
s? (y/n) "
,
1
,
true
);
reply
=
simple_prompt
(
"Shall the new
role be allowed to create more new role
s? (y/n) "
,
1
,
true
);
if
(
check_yesno_response
(
reply
)
==
1
)
if
(
check_yesno_response
(
reply
)
==
1
)
adduser
=
+
1
;
createrole
=
+
1
;
else
else
adduser
=
-
1
;
createrole
=
-
1
;
}
if
(
inherit
==
0
)
{
/* silently default to YES */
inherit
=
+
1
;
}
if
(
login
==
0
)
{
/* silently default to YES */
login
=
+
1
;
}
}
initPQExpBuffer
(
&
sql
);
initPQExpBuffer
(
&
sql
);
printfPQExpBuffer
(
&
sql
,
"CREATE USER %s"
,
fmtId
(
newuser
));
printfPQExpBuffer
(
&
sql
,
"CREATE ROLE %s"
,
fmtId
(
newuser
));
if
(
sysid
)
appendPQExpBuffer
(
&
sql
,
" SYSID %s"
,
sysid
);
if
(
newpassword
)
if
(
newpassword
)
{
{
if
(
encrypted
==
+
1
)
if
(
encrypted
==
+
1
)
...
@@ -199,14 +249,28 @@ main(int argc, char *argv[])
...
@@ -199,14 +249,28 @@ main(int argc, char *argv[])
appendPQExpBuffer
(
&
sql
,
" PASSWORD "
);
appendPQExpBuffer
(
&
sql
,
" PASSWORD "
);
appendStringLiteral
(
&
sql
,
newpassword
,
false
);
appendStringLiteral
(
&
sql
,
newpassword
,
false
);
}
}
if
(
superuser
==
+
1
)
appendPQExpBuffer
(
&
sql
,
" SUPERUSER"
);
if
(
superuser
==
-
1
)
appendPQExpBuffer
(
&
sql
,
" NOSUPERUSER"
);
if
(
createdb
==
+
1
)
if
(
createdb
==
+
1
)
appendPQExpBuffer
(
&
sql
,
" CREATEDB"
);
appendPQExpBuffer
(
&
sql
,
" CREATEDB"
);
if
(
createdb
==
-
1
)
if
(
createdb
==
-
1
)
appendPQExpBuffer
(
&
sql
,
" NOCREATEDB"
);
appendPQExpBuffer
(
&
sql
,
" NOCREATEDB"
);
if
(
adduser
==
+
1
)
if
(
createrole
==
+
1
)
appendPQExpBuffer
(
&
sql
,
" CREATEUSER"
);
appendPQExpBuffer
(
&
sql
,
" CREATEROLE"
);
if
(
adduser
==
-
1
)
if
(
createrole
==
-
1
)
appendPQExpBuffer
(
&
sql
,
" NOCREATEUSER"
);
appendPQExpBuffer
(
&
sql
,
" NOCREATEROLE"
);
if
(
inherit
==
+
1
)
appendPQExpBuffer
(
&
sql
,
" INHERIT"
);
if
(
inherit
==
-
1
)
appendPQExpBuffer
(
&
sql
,
" NOINHERIT"
);
if
(
login
==
+
1
)
appendPQExpBuffer
(
&
sql
,
" LOGIN"
);
if
(
login
==
-
1
)
appendPQExpBuffer
(
&
sql
,
" NOLOGIN"
);
if
(
conn_limit
!=
NULL
)
appendPQExpBuffer
(
&
sql
,
" CONNECTION LIMIT %s"
,
conn_limit
);
appendPQExpBuffer
(
&
sql
,
";
\n
"
);
appendPQExpBuffer
(
&
sql
,
";
\n
"
);
conn
=
connectDatabase
(
"postgres"
,
host
,
port
,
username
,
password
,
progname
);
conn
=
connectDatabase
(
"postgres"
,
host
,
port
,
username
,
password
,
progname
);
...
@@ -217,7 +281,7 @@ main(int argc, char *argv[])
...
@@ -217,7 +281,7 @@ main(int argc, char *argv[])
if
(
PQresultStatus
(
result
)
!=
PGRES_COMMAND_OK
)
if
(
PQresultStatus
(
result
)
!=
PGRES_COMMAND_OK
)
{
{
fprintf
(
stderr
,
_
(
"%s: creation of new
user
failed: %s"
),
fprintf
(
stderr
,
_
(
"%s: creation of new
role
failed: %s"
),
progname
,
PQerrorMessage
(
conn
));
progname
,
PQerrorMessage
(
conn
));
PQfinish
(
conn
);
PQfinish
(
conn
);
exit
(
1
);
exit
(
1
);
...
@@ -226,7 +290,7 @@ main(int argc, char *argv[])
...
@@ -226,7 +290,7 @@ main(int argc, char *argv[])
PQfinish
(
conn
);
PQfinish
(
conn
);
if
(
!
quiet
)
if
(
!
quiet
)
{
{
puts
(
"CREATE
USER
"
);
puts
(
"CREATE
ROLE
"
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
exit
(
0
);
exit
(
0
);
...
@@ -236,18 +300,25 @@ main(int argc, char *argv[])
...
@@ -236,18 +300,25 @@ main(int argc, char *argv[])
static
void
static
void
help
(
const
char
*
progname
)
help
(
const
char
*
progname
)
{
{
printf
(
_
(
"%s creates a new PostgreSQL
user
.
\n\n
"
),
progname
);
printf
(
_
(
"%s creates a new PostgreSQL
role
.
\n\n
"
),
progname
);
printf
(
_
(
"Usage:
\n
"
));
printf
(
_
(
"Usage:
\n
"
));
printf
(
_
(
" %s [OPTION]... [USERNAME]
\n
"
),
progname
);
printf
(
_
(
" %s [OPTION]... [USERNAME]
\n
"
),
progname
);
printf
(
_
(
"
\n
Options:
\n
"
));
printf
(
_
(
"
\n
Options:
\n
"
));
printf
(
_
(
" -a, --adduser user can add new users
\n
"
));
printf
(
_
(
" -s, --superuser role will be superuser
\n
"
));
printf
(
_
(
" -A, --no-adduser user cannot add new users
\n
"
));
printf
(
_
(
" -S, --no-superuser role will not be superuser
\n
"
));
printf
(
_
(
" -d, --createdb user can create new databases
\n
"
));
printf
(
_
(
" -d, --createdb role can create new databases
\n
"
));
printf
(
_
(
" -D, --no-createdb user cannot create databases
\n
"
));
printf
(
_
(
" -D, --no-createdb role cannot create databases
\n
"
));
printf
(
_
(
" -P, --pwprompt assign a password to new user
\n
"
));
printf
(
_
(
" -r, --createrole role can create new roles
\n
"
));
printf
(
_
(
" -R, --no-createrole role cannot create roles
\n
"
));
printf
(
_
(
" -l, --login role can login (default)
\n
"
));
printf
(
_
(
" -L, --no-login role cannot login
\n
"
));
printf
(
_
(
" -i, --inherit role inherits permissions of roles
\n
"
));
printf
(
_
(
" it is a member of (default)
\n
"
));
printf
(
_
(
" -I, --no-inherit role does not inherit permissions
\n
"
));
printf
(
_
(
" -c, --conn-limit=N max connections for role (default: no limit)
\n
"
));
printf
(
_
(
" -P, --pwprompt assign a password to new role
\n
"
));
printf
(
_
(
" -E, --encrypted encrypt stored password
\n
"
));
printf
(
_
(
" -E, --encrypted encrypt stored password
\n
"
));
printf
(
_
(
" -N, --unencrypted do not encrypt stored password
\n
"
));
printf
(
_
(
" -N, --unencrypted do not encrypt stored password
\n
"
));
printf
(
_
(
" -i, --sysid=SYSID select sysid for new user
\n
"
));
printf
(
_
(
" -e, --echo show the commands being sent to the server
\n
"
));
printf
(
_
(
" -e, --echo show the commands being sent to the server
\n
"
));
printf
(
_
(
" -q, --quiet don't write any messages
\n
"
));
printf
(
_
(
" -q, --quiet don't write any messages
\n
"
));
printf
(
_
(
" --help show this help, then exit
\n
"
));
printf
(
_
(
" --help show this help, then exit
\n
"
));
...
@@ -257,7 +328,7 @@ help(const char *progname)
...
@@ -257,7 +328,7 @@ help(const char *progname)
printf
(
_
(
" -p, --port=PORT database server port
\n
"
));
printf
(
_
(
" -p, --port=PORT database server port
\n
"
));
printf
(
_
(
" -U, --username=USERNAME user name to connect as (not the one to create)
\n
"
));
printf
(
_
(
" -U, --username=USERNAME user name to connect as (not the one to create)
\n
"
));
printf
(
_
(
" -W, --password prompt for password to connect
\n
"
));
printf
(
_
(
" -W, --password prompt for password to connect
\n
"
));
printf
(
_
(
"
\n
If one of -
a, -A, -d, -D, and USERNAME is not specified, you will
\n
"
printf
(
_
(
"
\n
If one of -
s, -S, -d, -D, -r, -R and USERNAME is not specified,
\n
"
"be prompted interactively.
\n
"
));
"
you will
be prompted interactively.
\n
"
));
printf
(
_
(
"
\n
Report bugs to <pgsql-bugs@postgresql.org>.
\n
"
));
printf
(
_
(
"
\n
Report bugs to <pgsql-bugs@postgresql.org>.
\n
"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment