head 1.14; access; symbols release_4_2:1.14 aix_ok:1.13 Version_2_1:1.9 C_Demo_1:1.7; locks; strict; comment @ * @; 1.14 date 94.06.16.03.23.06; author aoki; state Exp; branches; next 1.13; 1.13 date 92.12.18.21.12.51; author mao; state Exp; branches; next 1.12; 1.12 date 92.09.05.23.42.29; author mao; state Exp; branches; next 1.11; 1.11 date 91.11.12.20.20.29; author mer; state Exp; branches; next 1.10; 1.10 date 91.10.16.16.58.23; author hong; state Exp; branches; next 1.9; 1.9 date 90.09.25.16.53.06; author kemnitz; state Exp; branches; next 1.8; 1.8 date 89.09.15.15.58.19; author hirohama; state Exp; branches; next 1.7; 1.7 date 89.09.05.17.28.39; author mao; state C_Demo_1; branches; next 1.6; 1.6 date 89.07.17.14.44.39; author dillon; state Exp; branches; next 1.5; 1.5 date 89.06.17.01.53.18; author hirohama; state Exp; branches; next 1.4; 1.4 date 89.02.26.22.37.07; author hirohama; state Stab; branches; next 1.3; 1.3 date 89.02.23.17.04.12; author aoki; state Exp; branches; next 1.2; 1.2 date 89.02.02.18.17.43; author aoki; state Exp; branches; next 1.1; 1.1 date 89.01.17.05.58.53; author cimarron; state Exp; branches; next ; desc @@ 1.14 log @O_ flag @ text @/* * magic.c - magic number management routines * * XXX eventually, should be able to handle version identifiers * of length != 4. * * STANDALONE CODE - do not use error routines as this code is linked with * stuff that does not cinterface.a */ #include #include #include #include #include #include "tmp/postgres.h" RcsId("$Header: /import/faerie/aoki/postgres/src/backend/utils/init/RCS/magic.c,v 1.13 1992/12/18 21:12:51 mao Exp aoki $"); #include "utils/log.h" #include "tmp/miscadmin.h" #include "storage/fd.h" /* for O_ */ static char Pg_verfile[] = PG_VERFILE; extern char *DataDir; /* * private function prototypes */ static PathSetVersionFilePath ARGS ((char path[], char filepathbuf[])); /* * Noversion moved to globals.c */ /* * DatabaseMetaGunkIsConsistent * * Returns 1 iff all version numbers and ownerships are consistent. * * Note that we have to go through the whole rigmarole of generating the path * and checking the existence of the database whether Noversion is set or not. */ int DatabaseMetaGunkIsConsistent(database, path) char database[], path[]; { int isValid; struct stat statbuf; isValid = ValidPgVersion(DataDir); sprintf(path, "%s/base/%s\0", DataDir, database); isValid = ValidPgVersion(path) || isValid; if (stat(path, &statbuf) < 0) elog(FATAL, "database %s does not exist, bailing out...", database); return(isValid); } /* * ValidPgVersion - verifies the consistency of the database * * Returns 1 iff the catalog version number (from the version number file * in the directory specified in "path") is consistent with the backend * version number. */ int ValidPgVersion(path) char path[]; { int fd; char version[4], buf[MAXPGPATH+1]; struct stat statbuf; u_short my_euid = geteuid(); PathSetVersionFilePath(path, buf); if (stat(buf, &statbuf) >= 0) { if (statbuf.st_uid != my_euid && my_euid != 0) elog(FATAL, "process userid (%d) != database owner (%d)", my_euid, statbuf.st_uid); } else return(0); if ((fd = open(buf, O_RDONLY, 0)) < 0) { if (!Noversion) elog(DEBUG, "ValidPgVersion: %s: %m", buf); return(0); } if (read(fd, version, 4) < 4 || !isascii(version[0]) || !isdigit(version[0]) || version[1] != '.' || !isascii(version[2]) || !isdigit(version[2]) || version[3] != '\n') elog(FATAL, "ValidPgVersion: %s: bad format", buf); if (version[2] != '0' + PG_VERSION || version[0] != '0' + PG_RELEASE) { if (!Noversion) elog(DEBUG, "ValidPgVersion: should be %d.%d not %c.%c", PG_RELEASE, PG_VERSION, version[0], version[2]); close(fd); return(0); } close(fd); return(1); } /* * SetPgVersion - writes the version to a database directory */ SetPgVersion(path) char path[]; { int fd; char version[4], buf[MAXPGPATH+1]; PathSetVersionFilePath(path, buf); if ((fd = open(buf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) elog(FATAL, "SetPgVersion: %s: %m", buf); version[0] = '0' + PG_RELEASE; version[1] = '.'; version[2] = '0' + PG_VERSION; version[3] = '\n'; if (write(fd, version, 4) != 4) elog(WARN, "SetPgVersion: %s: %m", buf); close(fd); } /* * PathSetVersionFilePath * * Destructively change "filepathbuf" to contain the concatenation of "path" * and the name of the version file name. */ static PathSetVersionFilePath(path, filepathbuf) char path[], filepathbuf[]; { if (strlen(path) > (MAXPGPATH - sizeof(Pg_verfile) - 1)) elog(FATAL, "PathSetVersionFilePath: %s: path too long"); (void) sprintf(filepathbuf, "%s/%s\0", path, Pg_verfile); } @ 1.13 log @don't extern char *GetDataHome(); it's not used in this routine @ text @d19 1 a19 1 RcsId("$Header: /private/src/postgres/src/backend/utils/init/RCS/magic.c,v 1.12 1992/09/05 23:42:29 mao Exp mao $"); d24 2 @ 1.12 log @allow location of data/ to be supplied in environment or on command line @ text @d19 1 a19 1 RcsId("$Header: /private/mao/postgres/src/utils/init/RCS/magic.c,v 1.11 1991/11/12 20:20:29 mer Exp mao $"); a49 1 extern char *GetDataHome(); @ 1.11 log @prototyping changes @ text @d19 1 a19 1 RcsId("$Header: /users/mer/postgres/src/utils/init/RCS/magic.c,v 1.10 1991/10/16 16:58:23 hong Exp $"); d25 1 a50 1 char *home = GetDataHome(); d53 2 a54 3 sprintf(path, "%s/data\0", home); isValid = ValidPgVersion(path); sprintf(path, "%s/data/base/%s\0", home, database); d60 1 a60 1 @ 1.10 log @allow root to access everybody's database. @ text @d19 1 a19 1 RcsId("$Header: RCS/magic.c,v 1.9 90/09/25 16:53:06 kemnitz Exp $"); d25 5 @ 1.9 log @Updating from revision 1.8 to revision 1.11 @ text @d19 1 a19 1 RcsId("$Header: RCS/magic.c,v 1.11 90/08/18 00:42:36 cimarron Exp Locker: kemnitz $"); d81 1 a81 1 if (statbuf.st_uid != my_euid) @ 1.8 log @fixed error message @ text @d6 3 a15 4 #include "magic.h" #include "postgres.h" #include "log.h" #include "globals.h" d17 6 a22 1 RcsId("$Header: RCS/magic.c,v 1.7 89/09/05 17:28:39 mao C_Demo_1 Locker: hirohama $"); @ 1.7 log @Working version of C-only demo @ text @d18 1 a18 1 RcsId("$Header: /usr6/postgres/mao/postgres/src/utils/init/RCS/magic.c,v 1.6 89/07/17 14:44:39 dillon Exp $"); d80 1 a80 1 statbuf.st_uid, my_euid); @ 1.6 log @globals removed to globals.c @ text @d18 1 a18 1 RcsId("$Header: /usr6/postgres/dillon/tree/src/utils/init/RCS/magic.c,v 1.5 89/06/17 01:53:18 hirohama Exp $"); @ 1.5 log @*** empty log message *** @ text @d16 1 d18 1 a18 1 RcsId("$Header: /usr6/postgres/hirohama/postgres/src/utils/init/RCS/magic.c,v 1.4 89/02/26 22:37:07 hirohama Stab $"); d22 3 a24 2 /* Noversion is used as a global variable to disable checking. */ int Noversion = 0; @ 1.4 log @now compares the effective user id with the owner of the database files. @ text @a14 1 #include "context.h" d17 1 a17 1 RcsId("$Header: magic.c,v 1.3 89/02/23 17:04:12 hirohama Locked $"); @ 1.3 log @fixes for owner check, version check @ text @d18 1 a18 1 RcsId("$Header: magic.c,v 1.2 89/02/02 18:17:43 aoki Locked $"); d71 1 a71 1 u_short my_uid = getuid(); d76 1 a76 1 if (statbuf.st_uid != my_uid) d79 1 a79 1 statbuf.st_uid, my_uid); @ 1.2 log @MERGE WITH OLD TREE @ text @d1 6 a6 1 static char magic_c[] = "$Header: magic.c,v 2.3 87/11/05 16:34:47 aoki Locked $"; d9 3 d18 7 d26 1 a26 1 * magic.c - magic number management routines d28 1 a28 2 * Currently, only POSTGRES versioning is handled. Eventually, * routines to load the magic numbers should go here. d30 2 a31 4 * XXX eventually, should be able to handle version identifiers * of length != 4. * * Noversion is used as a global variable to disable checking. d34 8 a41 2 static char Pg_verfile[] = PG_VERFILE; int Noversion = 0; d43 13 d59 3 a61 4 * Currently, only checks for the existence. Eventually, * should check that the version numbers are proper. * * Returns 1 iff the catalog version is consistent. d66 1 a66 1 char path[]; d68 15 a82 12 int fd, len, retval; char *cp, version[4], buf[MAXPGPATH]; int open(), read(); extern close(), bcopy(); if ((len = strlen(path)) > MAXPGPATH - sizeof Pg_verfile - 1) elog(FATAL, "ValidPgVersion(%s): path too long"); retval = 0; bcopy(path, buf, len); cp = buf + len; *cp++ = '/'; bcopy(Pg_verfile, cp, sizeof Pg_verfile); d88 6 a93 1 if (read(fd, version, 4) < 4 || version[1] != '.' || version[3] != '\n') d95 2 a96 1 if (version[2] != '0' + PG_VERSION || version[0] != '0' + PG_RELEASE) { d98 3 a100 2 elog(DEBUG, "ValidPgVersion: should be %d.%d not %c.%c", PG_RELEASE, PG_VERSION, version[0], version[2]); d108 1 d114 1 a114 1 char path[]; d116 2 a117 3 int fd, len; char *cp, version[4], buf[MAXPGPATH]; int open(), write(); d119 2 a120 6 if ((len = strlen(path)) > MAXPGPATH - sizeof Pg_verfile - 1) elog(FATAL, "ValidPgVersion(%s): path too long"); bcopy(path, buf, len); cp = buf + len; *cp++ = '/'; bcopy(Pg_verfile, cp, sizeof Pg_verfile); d123 1 d130 1 d132 17 @ 1.1 log @Initial revision @ text @d1 1 a1 28 /* * * POSTGRES Data Base Management System * * Copyright (c) 1988 Regents of the University of California * * Permission to use, copy, modify, and distribute this software and its * documentation for educational, research, and non-profit purposes and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of the University of California not be used in advertising * or publicity pertaining to distribution of the software without * specific, written prior permission. Permission to incorporate this * software into commercial products can be obtained from the Campus * Software Office, 295 Evans Hall, University of California, Berkeley, * Ca., 94720 provided only that the the requestor give the University * of California a free licence to any derived software for educational * and research purposes. The University of California makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ static char magic_c[] = "$Header: magic.c,v 1.1 88/11/11 16:42:19 postgres Exp $"; @