* $Source: /usr/src/kerberosIV/kdb_init/RCS/kdb_init.c,v $
* Copyright 1987, 1988 by the Massachusetts Institute of Technology.
* For copying and distribution information, please see the file
* program to initialize the database, reports error if database file
static char rcsid_kdb_init_c
[] =
"$Header: /usr/src/kerberosIV/kdb_init/RCS/kdb_init.c,v 4.1 91/02/25 15:36:30 bostic Exp $";
#include <mit-copyright.h>
NULL_KEY
, /* setup null keys */
MASTER_KEY
, /* use master key as new key */
RANDOM_KEY
, /* choose a random key */
char *progname
, *rindex();
Key_schedule master_key_schedule
;
extern char *sys_errlist
[];
progname
= (cp
= rindex(*argv
, '/')) ? cp
+ 1 : *argv
;
fprintf(stderr
, "Usage: %s [realm-name] [database-name]\n", argv
[0]);
/* Do this first, it'll fail if the database exists */
if ((code
= kerb_db_create(database
)) != 0) {
fprintf(stderr
, "Couldn't create database: %s\n",
kerb_db_set_name(database
);
strncpy(realm
, argv
[1], REALM_SZ
);
fprintf(stderr
, "Realm name [default %s ]: ", KRB_REALM
);
if (fgets(realm
, sizeof(realm
), stdin
) == NULL
) {
fprintf(stderr
, "\nEOF reading realm\n");
if (cp
= index(realm
, '\n'))
if (!*realm
) /* no realm given */
strcpy(realm
, KRB_REALM
);
fprintf(stderr
, "%s: Bad kerberos realm name \"%s\"\n",
printf("You will be prompted for the database Master Password.\n");
printf("It is important that you NOT FORGET this password.\n");
if (kdb_get_master_key (TRUE
, master_key
, master_key_schedule
) != 0) {
fprintf (stderr
, "Couldn't read master key.\n");
add_principal(KERB_M_NAME
, KERB_M_INST
, MASTER_KEY
) ||
add_principal(KERB_DEFAULT_NAME
, KERB_DEFAULT_INST
, NULL_KEY
) ||
add_principal("krbtgt", realm
, RANDOM_KEY
) ||
add_principal("changepw", KRB_MASTER
, RANDOM_KEY
)
fprintf(stderr
, "\n%s: couldn't initialize database.\n",
bzero (master_key
, sizeof (C_Block
));
bzero (master_key_schedule
, sizeof (Key_schedule
));
/* use a return code to indicate success or failure. check the return */
/* values of the routines called by this routine. */
add_principal(name
, instance
, aap_op
)
struct tm
*tm
, *localtime();
bzero(&principal
, sizeof(principal
));
strncpy(principal
.name
, name
, ANAME_SZ
);
strncpy(principal
.instance
, instance
, INST_SZ
);
bzero(new_key
, sizeof(C_Block
));
kdb_encrypt_key (new_key
, new_key
, master_key
, master_key_schedule
,
bcopy(new_key
, &principal
.key_low
, 4);
bcopy(((long *) new_key
) + 1, &principal
.key_high
, 4);
bcopy (master_key
, new_key
, sizeof (C_Block
));
kdb_encrypt_key (new_key
, new_key
, master_key
, master_key_schedule
,
bcopy(new_key
, &principal
.key_low
, 4);
bcopy(((long *) new_key
) + 1, &principal
.key_high
, 4);
principal
.exp_date
= 946702799; /* Happy new century */
strncpy(principal
.exp_date_txt
, "12/31/99", DATE_SZ
);
principal
.mod_date
= time(0);
tm
= localtime((time_t *)&principal
.mod_date
);
principal
.attributes
= 0;
principal
.max_life
= 255;
principal
.kdc_key_ver
= 1;
principal
.key_version
= 1;
strncpy(principal
.mod_name
, "db_creation", ANAME_SZ
);
strncpy(principal
.mod_instance
, "", INST_SZ
);
kerb_db_put_principal(&principal
, 1);
bzero (new_key
, sizeof (C_Block
));
bzero (&principal
.key_low
, 4);
bzero (&principal
.key_high
, 4);