Make the DB/DBM routines generic (ifdef FreeBSD considered evil), and

also fix a string allocation bug.

Submitted by: Havard Eidnes
This commit is contained in:
Paul Traina 1995-08-02 23:08:18 +00:00
parent 670173822b
commit 278022fad4
6 changed files with 72 additions and 56 deletions

View File

@ -4,15 +4,15 @@
* <Copyright.MIT>.
*
* from: krb_dbm.c,v 4.9 89/04/18 16:15:13 wesommer Exp $
* $Id: krb_dbm.c,v 1.2 1995/01/25 19:45:25 ache Exp $
* $Id: krb_dbm.c,v 1.3 1995/05/30 06:40:38 rgrimes Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: krb_dbm.c,v 1.2 1995/01/25 19:45:25 ache Exp $";
"$Id: krb_dbm.c,v 1.3 1995/05/30 06:40:38 rgrimes Exp $";
#endif lint
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__NetBSD__)
#define NDBM
#endif
@ -36,6 +36,10 @@ static char rcsid[] =
#include <krb.h>
#include <krb_db.h>
#ifdef dbm_pagfno
#define DB
#endif
#define KERB_DB_MAX_RETRY 5
#ifdef DEBUG
@ -343,38 +347,38 @@ kerb_db_rename(from, to)
char *from;
char *to;
{
#ifndef __FreeBSD__
#ifdef DB
char *fromdb = gen_dbsuffix (from, ".db");
char *todb = gen_dbsuffix (to, ".db");
#else
char *fromdir = gen_dbsuffix (from, ".dir");
char *todir = gen_dbsuffix (to, ".dir");
char *frompag = gen_dbsuffix (from , ".pag");
char *topag = gen_dbsuffix (to, ".pag");
#else
char *fromdb = gen_dbsuffix (from, ".db");
char *todb = gen_dbsuffix (to, ".db");
#endif
char *fromok = gen_dbsuffix(from, ".ok");
long trans = kerb_start_update(to);
int ok;
#ifndef __FreeBSD__
#ifdef DB
if (rename (fromdb, todb) == 0) {
#else
if ((rename (fromdir, todir) == 0)
&& (rename (frompag, topag) == 0)) {
#else
if (rename (fromdb, todb) == 0) {
#endif
(void) unlink (fromok);
ok = 1;
}
free (fromok);
#ifndef __FreeBSD__
#ifdef DB
free (fromdb);
free (todb);
#else
free (fromdir);
free (todir);
free (frompag);
free (topag);
#else
free(fromdb);
free(todb);
#endif
if (ok)
return kerb_end_update(to, trans);

View File

@ -4,12 +4,12 @@
* <Copyright.MIT>.
*
* from: kdb_destroy.c,v 4.0 89/01/24 21:49:02 jtkohl Exp $
* $Id: kdb_destroy.c,v 1.1.1.1 1994/09/30 14:49:56 csgr Exp $
* $Id: kdb_destroy.c,v 1.2 1995/01/25 19:57:27 ache Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: kdb_destroy.c,v 1.1.1.1 1994/09/30 14:49:56 csgr Exp $";
"$Id: kdb_destroy.c,v 1.2 1995/01/25 19:57:27 ache Exp $";
#endif lint
#include <strings.h>
@ -17,24 +17,28 @@ static char rcsid[] =
#include "krb.h"
#include "krb_db.h"
#ifdef dbm_pagfno
#define DB
#endif
main()
{
char answer[10]; /* user input */
char dbm[256]; /* database path and name */
char dbm1[256]; /* database path and name */
#ifndef __FreeBSD__
char *file1, *file2; /* database file names */
#else
#ifdef DB
char *file; /* database file names */
#else
char *file1, *file2; /* database file names */
#endif
strcpy(dbm, DBM_FILE);
#ifndef __FreeBSD__
#ifdef __FreeBSD__
file = strcat(dbm, ".db");
#else
strcpy(dbm1, DBM_FILE);
file1 = strcat(dbm, ".dir");
file2 = strcat(dbm1, ".pag");
#else
file = strcat(dbm, ".db");
#endif
printf("You are about to destroy the Kerberos database ");
@ -43,10 +47,10 @@ main()
fgets(answer, sizeof(answer), stdin);
if (answer[0] == 'y' || answer[0] == 'Y') {
#ifndef __FreeBSD__
if (unlink(file1) == 0 && unlink(file2) == 0)
#else
#ifdef DB
if (unlink(file) == 0)
#else
if (unlink(file1) == 0 && unlink(file2) == 0)
#endif
fprintf(stderr, "Database deleted at %s\n", DBM_FILE);
else

View File

@ -12,12 +12,12 @@
* Written July 9, 1987 by Jeffrey I. Schiller
*
* from: kdb_util.c,v 4.4 90/01/09 15:57:20 raeburn Exp $
* $Id: kdb_util.c,v 1.1.1.1 1994/09/30 14:49:57 csgr Exp $
* $Id: kdb_util.c,v 1.2 1995/05/30 06:40:44 rgrimes Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: kdb_util.c,v 1.1.1.1 1994/09/30 14:49:57 csgr Exp $";
"$Id: kdb_util.c,v 1.2 1995/05/30 06:40:44 rgrimes Exp $";
#endif lint
#include <stdio.h>
@ -220,7 +220,7 @@ load_db (db_file, input_file)
long time_explode();
int code;
char *temp_db_file;
temp1 = strlen(db_file+2);
temp1 = strlen(db_file)+2;
temp_db_file = malloc (temp1);
strcpy(temp_db_file, db_file);
strcat(temp_db_file, "~");

View File

@ -4,15 +4,15 @@
* <Copyright.MIT>.
*
* from: krb_dbm.c,v 4.9 89/04/18 16:15:13 wesommer Exp $
* $Id: krb_dbm.c,v 1.2 1995/01/25 19:45:25 ache Exp $
* $Id: krb_dbm.c,v 1.3 1995/05/30 06:40:38 rgrimes Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: krb_dbm.c,v 1.2 1995/01/25 19:45:25 ache Exp $";
"$Id: krb_dbm.c,v 1.3 1995/05/30 06:40:38 rgrimes Exp $";
#endif lint
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__NetBSD__)
#define NDBM
#endif
@ -36,6 +36,10 @@ static char rcsid[] =
#include <krb.h>
#include <krb_db.h>
#ifdef dbm_pagfno
#define DB
#endif
#define KERB_DB_MAX_RETRY 5
#ifdef DEBUG
@ -343,38 +347,38 @@ kerb_db_rename(from, to)
char *from;
char *to;
{
#ifndef __FreeBSD__
#ifdef DB
char *fromdb = gen_dbsuffix (from, ".db");
char *todb = gen_dbsuffix (to, ".db");
#else
char *fromdir = gen_dbsuffix (from, ".dir");
char *todir = gen_dbsuffix (to, ".dir");
char *frompag = gen_dbsuffix (from , ".pag");
char *topag = gen_dbsuffix (to, ".pag");
#else
char *fromdb = gen_dbsuffix (from, ".db");
char *todb = gen_dbsuffix (to, ".db");
#endif
char *fromok = gen_dbsuffix(from, ".ok");
long trans = kerb_start_update(to);
int ok;
#ifndef __FreeBSD__
#ifdef DB
if (rename (fromdb, todb) == 0) {
#else
if ((rename (fromdir, todir) == 0)
&& (rename (frompag, topag) == 0)) {
#else
if (rename (fromdb, todb) == 0) {
#endif
(void) unlink (fromok);
ok = 1;
}
free (fromok);
#ifndef __FreeBSD__
#ifdef DB
free (fromdb);
free (todb);
#else
free (fromdir);
free (todir);
free (frompag);
free (topag);
#else
free(fromdb);
free(todb);
#endif
if (ok)
return kerb_end_update(to, trans);

View File

@ -4,12 +4,12 @@
* <Copyright.MIT>.
*
* from: kdb_destroy.c,v 4.0 89/01/24 21:49:02 jtkohl Exp $
* $Id: kdb_destroy.c,v 1.1.1.1 1994/09/30 14:49:56 csgr Exp $
* $Id: kdb_destroy.c,v 1.2 1995/01/25 19:57:27 ache Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: kdb_destroy.c,v 1.1.1.1 1994/09/30 14:49:56 csgr Exp $";
"$Id: kdb_destroy.c,v 1.2 1995/01/25 19:57:27 ache Exp $";
#endif lint
#include <strings.h>
@ -17,24 +17,28 @@ static char rcsid[] =
#include "krb.h"
#include "krb_db.h"
#ifdef dbm_pagfno
#define DB
#endif
main()
{
char answer[10]; /* user input */
char dbm[256]; /* database path and name */
char dbm1[256]; /* database path and name */
#ifndef __FreeBSD__
char *file1, *file2; /* database file names */
#else
#ifdef DB
char *file; /* database file names */
#else
char *file1, *file2; /* database file names */
#endif
strcpy(dbm, DBM_FILE);
#ifndef __FreeBSD__
#ifdef __FreeBSD__
file = strcat(dbm, ".db");
#else
strcpy(dbm1, DBM_FILE);
file1 = strcat(dbm, ".dir");
file2 = strcat(dbm1, ".pag");
#else
file = strcat(dbm, ".db");
#endif
printf("You are about to destroy the Kerberos database ");
@ -43,10 +47,10 @@ main()
fgets(answer, sizeof(answer), stdin);
if (answer[0] == 'y' || answer[0] == 'Y') {
#ifndef __FreeBSD__
if (unlink(file1) == 0 && unlink(file2) == 0)
#else
#ifdef DB
if (unlink(file) == 0)
#else
if (unlink(file1) == 0 && unlink(file2) == 0)
#endif
fprintf(stderr, "Database deleted at %s\n", DBM_FILE);
else

View File

@ -12,12 +12,12 @@
* Written July 9, 1987 by Jeffrey I. Schiller
*
* from: kdb_util.c,v 4.4 90/01/09 15:57:20 raeburn Exp $
* $Id: kdb_util.c,v 1.1.1.1 1994/09/30 14:49:57 csgr Exp $
* $Id: kdb_util.c,v 1.2 1995/05/30 06:40:44 rgrimes Exp $
*/
#ifndef lint
static char rcsid[] =
"$Id: kdb_util.c,v 1.1.1.1 1994/09/30 14:49:57 csgr Exp $";
"$Id: kdb_util.c,v 1.2 1995/05/30 06:40:44 rgrimes Exp $";
#endif lint
#include <stdio.h>
@ -220,7 +220,7 @@ load_db (db_file, input_file)
long time_explode();
int code;
char *temp_db_file;
temp1 = strlen(db_file+2);
temp1 = strlen(db_file)+2;
temp_db_file = malloc (temp1);
strcpy(temp_db_file, db_file);
strcat(temp_db_file, "~");