diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2000-01-20 21:51:09 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2000-01-20 21:51:09 +0000 |
commit | 13f88750178ced2b948a3d2b8370f5231534577d (patch) | |
tree | e9f1abb294831f1bea568ad35ba0b0817031c445 /src | |
parent | a959e3f7c04d2f8cca3e7895c3bb460d40de2280 (diff) | |
download | postgresql-13f88750178ced2b948a3d2b8370f5231534577d.tar.gz postgresql-13f88750178ced2b948a3d2b8370f5231534577d.zip |
Added new pg_id to fix initdb problems
New INSTALL file
Fixed a copyright notice
Diffstat (limited to 'src')
-rw-r--r-- | src/GNUmakefile.in | 7 | ||||
-rw-r--r-- | src/backend/access/heap/tuptoaster.c | 4 | ||||
-rw-r--r-- | src/bin/Makefile | 4 | ||||
-rw-r--r-- | src/bin/initdb/initdb.sh | 65 | ||||
-rw-r--r-- | src/bin/pg_id/Makefile | 33 | ||||
-rw-r--r-- | src/bin/pg_id/pg_id.c | 91 | ||||
-rw-r--r-- | src/bin/psql/copy.c | 5 | ||||
-rwxr-xr-x | src/mkinstalldirs | 36 |
8 files changed, 198 insertions, 47 deletions
diff --git a/src/GNUmakefile.in b/src/GNUmakefile.in index 95a28c11142..ea65315199c 100644 --- a/src/GNUmakefile.in +++ b/src/GNUmakefile.in @@ -7,7 +7,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.48 2000/01/16 20:04:51 petere Exp $ +# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.49 2000/01/20 21:50:56 petere Exp $ # #------------------------------------------------------------------------- @@ -33,7 +33,7 @@ all: echo All of PostgreSQL is successfully made. Ready to install. ;\ fi -install: +install: installdirs $(MAKE) -C utils install $(MAKE) -C backend install $(MAKE) -C interfaces install @@ -41,6 +41,9 @@ install: $(MAKE) -C pl install cat ../register.txt +installdirs: mkinstalldirs + $(SRCDIR)/mkinstalldirs $(BINDIR) $(LIBDIR) $(INCLUDEDIR) + clean: $(MAKE) -C utils clean $(MAKE) -C backend clean diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index c351c4cc177..9176521a5fc 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -4,11 +4,11 @@ * Support routines for external and compressed storage of * variable size attributes. * - * Copyright (c) 2000, PostgreSQL Development Team + * Copyright (c) 2000, PostgreSQL Global Development Group * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.1 1999/12/21 00:06:40 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.2 2000/01/20 21:50:59 petere Exp $ * * * INTERFACE ROUTINES diff --git a/src/bin/Makefile b/src/bin/Makefile index 451fab4bff3..9aaec450917 100644 --- a/src/bin/Makefile +++ b/src/bin/Makefile @@ -7,14 +7,14 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.24 2000/01/19 20:08:23 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.25 2000/01/20 21:51:02 petere Exp $ # #------------------------------------------------------------------------- SRCDIR= .. include ../Makefile.global -DIRS = pg_version psql pg_dump pg_passwd \ +DIRS = pg_id pg_version psql pg_dump pg_passwd \ scripts initdb initlocation ipcclean \ pg_ctl diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 6db416e1c1a..52a66507e8c 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -26,7 +26,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.81 2000/01/19 20:08:24 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.82 2000/01/20 21:51:05 petere Exp $ # #------------------------------------------------------------------------- @@ -47,14 +47,7 @@ exit_nicely(){ CMDNAME=`basename $0` -if [ "$USER" = 'root' -o "$LOGNAME" = 'root' ] -then - echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" - echo "as the (unprivileged) user that will own the server process." - exit 1 -fi -EffectiveUser=`id -n -u 2>/dev/null || whoami 2>/dev/null` if [ "$TMPDIR" ]; then TEMPFILE="$TMPDIR/initdb.$$" else @@ -95,7 +88,7 @@ else fi # Check if needed programs actually exist in path -for prog in postgres pg_version +for prog in postgres pg_version pg_id do if [ ! -x "$PGPATH/$prog" ] then @@ -109,6 +102,22 @@ do fi done + +# Gotta wait for pg_id existence check above +EffectiveUser=`$PGPATH/pg_id -n -u` +if [ -z "$EffectiveUser" ]; then + echo "Could not determine current user name. You are really hosed." + exit 1 +fi + +if [ `$PGPATH/pg_id -u` -eq 0 ] +then + echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" + echo "as the (unprivileged) user that will own the server process." + exit 1 +fi + + # 0 is the default (non-)encoding MULTIBYTEID=0 # This is placed here by configure --enable-multibyte[=XXX]. @@ -124,12 +133,9 @@ template_only=0 # superuser be the same as the Unix user owning the server process: # The single user postgres backend will only connect as the database # user with the same name as the Unix user running it. That's -# a security measure. It might change in the future (why?), but for -# now the --username option is only a fallback if both id and whoami -# fail, and in that case the argument _must_ be the name of the effective -# user. +# a security measure. POSTGRES_SUPERUSERNAME="$EffectiveUser" -POSTGRES_SUPERUSERID="`id -u 2>/dev/null || echo 0`" +POSTGRES_SUPERUSERID=`$PGPATH/pg_id -u` while [ "$#" -gt 0 ] do @@ -150,17 +156,7 @@ do template_only=1 echo "Updating template1 database only." ;; -# The database superuser. See comments above. - --username|-u) - POSTGRES_SUPERUSERNAME="$2" - shift;; - --username=*) - POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^--username=//'` - ;; - -u*) - POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^-u//'` - ;; -# The sysid of the database superuser. See comments above. +# The sysid of the database superuser. Can be freely changed. --sysid|-i) POSTGRES_SUPERUSERID="$2" shift;; @@ -284,21 +280,6 @@ then exit 1 fi -#--------------------------------------------------------------------------- -# Figure out who the Postgres superuser for the new database system will be. -#--------------------------------------------------------------------------- - -# This means they have neither 'id' nor 'whoami'! -if [ -z "$POSTGRES_SUPERUSERNAME" ] -then - echo "$CMDNAME: Could not the determine current username. Please use the -u option." - exit 1 -fi - -echo "This database system will be initialized with username \"$POSTGRES_SUPERUSERNAME\"." -echo "This user will own all the data files and must also own the server process." -echo - #------------------------------------------------------------------------- # Find the input files @@ -355,6 +336,10 @@ fi trap 'echo "Caught signal." ; exit_nicely' 1 2 3 15 +# Let's go +echo "This database system will be initialized with username \"$POSTGRES_SUPERUSERNAME\"." +echo "This user will own all the data files and must also own the server process." +echo # ----------------------------------------------------------------------- # Create the data directory if necessary diff --git a/src/bin/pg_id/Makefile b/src/bin/pg_id/Makefile new file mode 100644 index 00000000000..1801becbe56 --- /dev/null +++ b/src/bin/pg_id/Makefile @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------- +# +# Makefile +# Makefile for bin/pg_id +# +# Copyright (C) 2000 by PostgreSQL Global Development Team +# +# $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/Makefile,v 1.14 2000/01/20 21:51:07 petere Exp $ +# +#------------------------------------------------------------------------- + +SRCDIR= ../.. +include ../../Makefile.global + +OBJS= pg_id.o + +all: pg_id + +pg_id: $(OBJS) + $(CC) -o pg_id $(OBJS) $(LDFLAGS) + +install: pg_id + $(INSTALL) $(INSTL_EXE_OPTS) pg_id$(X) $(BINDIR)/pg_id + +depend dep: + $(CC) -MM $(CFLAGS) *.c >depend + +clean: + rm -f pg_id $(OBJS) + +ifeq (depend,$(wildcard depend)) +include depend +endif diff --git a/src/bin/pg_id/pg_id.c b/src/bin/pg_id/pg_id.c new file mode 100644 index 00000000000..fcba3b3e3c5 --- /dev/null +++ b/src/bin/pg_id/pg_id.c @@ -0,0 +1,91 @@ +/* + * pg_id.c + * + * A crippled id utility for use in various shell scripts in use by PostgreSQL + * (in particular initdb) + * + * Copyright (C) 2000 by PostgreSQL Global Development Group + * + * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.11 2000/01/20 21:51:07 petere Exp $ + */ +#include <c.h> + +#include <pwd.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> + +int main(int argc, char * argv[]) +{ + int c; + int nameflag = 0, + realflag = 0, + userflag = 0; + const char * username = NULL; + + struct passwd * pw; + + while ((c = getopt(argc, argv, "nru")) != -1) + { + switch(c) + { + case 'n': + nameflag = 1; + break; + case 'r': + realflag = 1; + break; + case 'u': + userflag = 1; + break; + default: + fprintf(stderr, "Usage: %s [-n] [-r] [-u] [username]\n", argv[0]); + exit(1); + } + } + + if (argc - optind >= 1) + username = argv[optind]; + + if (nameflag && !userflag) + { + fprintf(stderr, "%s: -n must be used together with -u\n", argv[0]); + exit(1); + } + if (username && realflag) + { + fprintf(stderr, "%s: -r cannot be used when a user name is given\n", argv[0]); + exit(1); + } + + + if (username) + { + pw = getpwnam(username); + if (!pw) + { + fprintf(stderr, "%s: %s: no such user\n", argv[0], username); + exit(1); + } + } + else if (realflag) + pw = getpwuid(getuid()); + else + pw = getpwuid(geteuid()); + + if (!pw) + { + perror(argv[0]); + exit(1); + } + + if (!userflag) + printf("uid=%d(%s)\n", (int)pw->pw_uid, pw->pw_name); + else if (nameflag) + puts(pw->pw_name); + else + printf("%d\n", (int)pw->pw_uid); + + return 0; +} diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 8f46e65b4c3..140aa983fa6 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Team * - * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.6 2000/01/18 23:30:23 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.7 2000/01/20 21:51:09 petere Exp $ */ #include <c.h> #include "copy.h" @@ -423,7 +423,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt) if (firstload) { if (!strcmp(copybuf, "\\.")) + { copydone = true; + break; + } firstload = false; } } diff --git a/src/mkinstalldirs b/src/mkinstalldirs new file mode 100755 index 00000000000..cc8783edce3 --- /dev/null +++ b/src/mkinstalldirs @@ -0,0 +1,36 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman <friedman@prep.ai.mit.edu> +# Created: 1993-05-16 +# Last modified: 1994-03-25 +# Public domain + +errstatus=0 + +for file in ${1+"$@"} ; do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d in ${1+"$@"} ; do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" 1>&2 + mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$? + fi + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# mkinstalldirs ends here |